]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: domain: Improve vCPU data checking in qemuDomainRefreshVcpu
authorPeter Krempa <pkrempa@redhat.com>
Fri, 8 Jul 2016 13:39:32 +0000 (15:39 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 4 Aug 2016 06:08:31 +0000 (08:08 +0200)
Validate the presence of the thread id according to state of the vCPU
rather than just checking the vCPU count. Additionally put the new
validation code into a separate function so that the information
retrieval can be split from the validation.

src/qemu/qemu_domain.c
src/qemu/qemu_domain.h

index 5cde84103cf2667d348c489949877dd78165d068..77fa27c78ad1ba18e0d324dd27c985e9ae681e82 100644 (file)
@@ -5623,6 +5623,48 @@ qemuDomainGetVcpuPid(virDomainObjPtr vm,
 }
 
 
+/**
+ * qemuDomainValidateVcpuInfo:
+ *
+ * Validates vcpu thread information. If vcpu thread IDs are reported by qemu,
+ * this function validates that online vcpus have thread info present and
+ * offline vcpus don't.
+ *
+ * Returns 0 on success -1 on error.
+ */
+int
+qemuDomainValidateVcpuInfo(virDomainObjPtr vm)
+{
+    size_t maxvcpus = virDomainDefGetVcpusMax(vm->def);
+    virDomainVcpuDefPtr vcpu;
+    qemuDomainVcpuPrivatePtr vcpupriv;
+    size_t i;
+
+    if (!qemuDomainHasVcpuPids(vm))
+        return 0;
+
+    for (i = 0; i < maxvcpus; i++) {
+        vcpu = virDomainDefGetVcpu(vm->def, i);
+        vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu);
+
+        if (vcpu->online && vcpupriv->tid == 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("qemu didn't report thread id for vcpu '%zu'"), i);
+            return -1;
+        }
+
+        if (!vcpu->online && vcpupriv->tid != 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("qemu reported thread id for inactive vcpu '%zu'"),
+                           i);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 /**
  * qemuDomainRefreshVcpuInfo:
  * @driver: qemu driver data
@@ -5703,13 +5745,8 @@ qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
             QEMU_DOMAIN_VCPU_PRIVATE(vcpu)->tid = 0;
     }
 
-    if (ncpupids != virDomainDefGetVcpus(vm->def)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("got wrong number of vCPU pids from QEMU monitor. "
-                         "got %d, wanted %d"),
-                       ncpupids, virDomainDefGetVcpus(vm->def));
+    if (qemuDomainValidateVcpuInfo(vm) < 0)
         goto cleanup;
-    }
 
     ret = ncpupids;
 
index 31934273b55d6728188b7dfd8e94e86a162a67fd..06130937dd6ddc14bd2dffae35bde93266cc878f 100644 (file)
@@ -647,6 +647,7 @@ int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
 
 bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
 pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
+int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
 int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               int asyncJob);