]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: domain: Prepare for VCPUs vanishing while libvirt is not running
authorPeter Krempa <pkrempa@redhat.com>
Fri, 5 Aug 2016 12:48:27 +0000 (14:48 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 24 Aug 2016 19:44:47 +0000 (15:44 -0400)
Similarly to devices the guest may allow unplug of the VCPU if libvirt
is down. To avoid problems, refresh the vcpu state on reconnect. Don't
mess with the vcpu state otherwise.

src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_driver.c
src/qemu/qemu_process.c

index f0ae84e09dc76d69ca481719b466ff0944c9dc68..d4f472ba282cedf1068488fe43bedd37190d3e2b 100644 (file)
@@ -5764,16 +5764,20 @@ qemuDomainSupportsNewVcpuHotplug(virDomainObjPtr vm)
  * @driver: qemu driver data
  * @vm: domain object
  * @asyncJob: current asynchronous job type
+ * @state: refresh vcpu state
  *
  * Updates vCPU information private data of @vm. Due to historical reasons this
  * function returns success even if some data were not reported by qemu.
  *
+ * If @state is true, the vcpu state is refreshed as reported by the monitor.
+ *
  * Returns 0 on success and -1 on fatal error.
  */
 int
 qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
-                          int asyncJob)
+                          int asyncJob,
+                          bool state)
 {
     virDomainVcpuDefPtr vcpu;
     qemuDomainVcpuPrivatePtr vcpupriv;
@@ -5841,6 +5845,9 @@ qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
         VIR_FREE(vcpupriv->alias);
         VIR_STEAL_PTR(vcpupriv->alias, info[i].alias);
         vcpupriv->enable_id = info[i].id;
+
+        if (hotplug && state)
+            vcpu->online = !!info[i].qom_path;
     }
 
     ret = 0;
index c95acdfa6d55741548df0c9f135baec0be163907..b4b3daef36fc973d113c44c657adb3086b6d3747 100644 (file)
@@ -660,7 +660,8 @@ pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
 int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
 int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
-                              int asyncJob);
+                              int asyncJob,
+                              bool state);
 
 bool qemuDomainSupportsNicdev(virDomainDefPtr def,
                               virDomainNetDefPtr net);
index a0ac2ef7f5a17b8a1fcb5be10c87e1e93841aef2..8ff95f6681c6926a8a13a811a2b074a932031109 100644 (file)
@@ -4640,7 +4640,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
 
     vcpuinfo->online = true;
 
-    if (qemuDomainRefreshVcpuInfo(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
+    if (qemuDomainRefreshVcpuInfo(driver, vm, QEMU_ASYNC_JOB_NONE, false) < 0)
         goto cleanup;
 
     if (qemuDomainValidateVcpuInfo(vm) < 0)
@@ -4689,7 +4689,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
         goto cleanup;
     }
 
-    if (qemuDomainRefreshVcpuInfo(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
+    if (qemuDomainRefreshVcpuInfo(driver, vm, QEMU_ASYNC_JOB_NONE, false) < 0)
         goto cleanup;
 
     if (qemuDomainValidateVcpuInfo(vm) < 0) {
index 907da3045a6ede2f83de77607893bbd69495e7cf..3cf9d8cd97ceef528f0db1bae02e62b10c37544a 100644 (file)
@@ -3354,6 +3354,9 @@ qemuProcessReconnect(void *opaque)
     ignore_value(virSecurityManagerCheckAllLabel(driver->securityManager,
                                                  obj->def));
 
+    if (qemuDomainRefreshVcpuInfo(driver, obj, QEMU_ASYNC_JOB_NONE, true) < 0)
+        goto error;
+
     if (virSecurityManagerReserveLabel(driver->securityManager, obj->def, obj->pid) < 0)
         goto error;
 
@@ -5234,7 +5237,7 @@ qemuProcessLaunch(virConnectPtr conn,
         goto cleanup;
 
     VIR_DEBUG("Refreshing VCPU info");
-    if (qemuDomainRefreshVcpuInfo(driver, vm, asyncJob) < 0)
+    if (qemuDomainRefreshVcpuInfo(driver, vm, asyncJob, false) < 0)
         goto cleanup;
 
     if (qemuDomainValidateVcpuInfo(vm) < 0)
@@ -6029,7 +6032,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
     }
 
     VIR_DEBUG("Detecting VCPU PIDs");
-    if (qemuDomainRefreshVcpuInfo(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
+    if (qemuDomainRefreshVcpuInfo(driver, vm, QEMU_ASYNC_JOB_NONE, false) < 0)
         goto error;
 
     if (qemuDomainValidateVcpuInfo(vm) < 0)