Blame SOURCES/libvirt-qemu-domain-Improve-vCPU-data-checking-in-qemuDomainRefreshVcpu.patch

6ae9ed
From f2826631e6353ae913c2434f22ad553fb8524f95 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <f2826631e6353ae913c2434f22ad553fb8524f95@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Wed, 24 Aug 2016 16:11:08 -0400
6ae9ed
Subject: [PATCH] qemu: domain: Improve vCPU data checking in
6ae9ed
 qemuDomainRefreshVcpu
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
6ae9ed
6ae9ed
Validate the presence of the thread id according to state of the vCPU
6ae9ed
rather than just checking the vCPU count. Additionally put the new
6ae9ed
validation code into a separate function so that the information
6ae9ed
retrieval can be split from the validation.
6ae9ed
6ae9ed
(cherry picked from commit 2bdc300a34f07a43cc1362e785c2bfdcfc73bf31)
6ae9ed
---
6ae9ed
 src/qemu/qemu_domain.c | 49 +++++++++++++++++++++++++++++++++++++++++++------
6ae9ed
 src/qemu/qemu_domain.h |  1 +
6ae9ed
 2 files changed, 44 insertions(+), 6 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
6ae9ed
index 93dd3f6..e087fe6 100644
6ae9ed
--- a/src/qemu/qemu_domain.c
6ae9ed
+++ b/src/qemu/qemu_domain.c
6ae9ed
@@ -5629,6 +5629,48 @@ qemuDomainGetVcpuPid(virDomainObjPtr vm,
6ae9ed
 
6ae9ed
 
6ae9ed
 /**
6ae9ed
+ * qemuDomainValidateVcpuInfo:
6ae9ed
+ *
6ae9ed
+ * Validates vcpu thread information. If vcpu thread IDs are reported by qemu,
6ae9ed
+ * this function validates that online vcpus have thread info present and
6ae9ed
+ * offline vcpus don't.
6ae9ed
+ *
6ae9ed
+ * Returns 0 on success -1 on error.
6ae9ed
+ */
6ae9ed
+int
6ae9ed
+qemuDomainValidateVcpuInfo(virDomainObjPtr vm)
6ae9ed
+{
6ae9ed
+    size_t maxvcpus = virDomainDefGetVcpusMax(vm->def);
6ae9ed
+    virDomainVcpuDefPtr vcpu;
6ae9ed
+    qemuDomainVcpuPrivatePtr vcpupriv;
6ae9ed
+    size_t i;
6ae9ed
+
6ae9ed
+    if (!qemuDomainHasVcpuPids(vm))
6ae9ed
+        return 0;
6ae9ed
+
6ae9ed
+    for (i = 0; i < maxvcpus; i++) {
6ae9ed
+        vcpu = virDomainDefGetVcpu(vm->def, i);
6ae9ed
+        vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu);
6ae9ed
+
6ae9ed
+        if (vcpu->online && vcpupriv->tid == 0) {
6ae9ed
+            virReportError(VIR_ERR_INTERNAL_ERROR,
6ae9ed
+                           _("qemu didn't report thread id for vcpu '%zu'"), i);
6ae9ed
+            return -1;
6ae9ed
+        }
6ae9ed
+
6ae9ed
+        if (!vcpu->online && vcpupriv->tid != 0) {
6ae9ed
+            virReportError(VIR_ERR_INTERNAL_ERROR,
6ae9ed
+                           _("qemu reported thread id for inactive vcpu '%zu'"),
6ae9ed
+                           i);
6ae9ed
+            return -1;
6ae9ed
+        }
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    return 0;
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
+/**
6ae9ed
  * qemuDomainRefreshVcpuInfo:
6ae9ed
  * @driver: qemu driver data
6ae9ed
  * @vm: domain object
6ae9ed
@@ -5708,13 +5750,8 @@ qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
6ae9ed
             QEMU_DOMAIN_VCPU_PRIVATE(vcpu)->tid = 0;
6ae9ed
     }
6ae9ed
 
6ae9ed
-    if (ncpupids != virDomainDefGetVcpus(vm->def)) {
6ae9ed
-        virReportError(VIR_ERR_INTERNAL_ERROR,
6ae9ed
-                       _("got wrong number of vCPU pids from QEMU monitor. "
6ae9ed
-                         "got %d, wanted %d"),
6ae9ed
-                       ncpupids, virDomainDefGetVcpus(vm->def));
6ae9ed
+    if (qemuDomainValidateVcpuInfo(vm) < 0)
6ae9ed
         goto cleanup;
6ae9ed
-    }
6ae9ed
 
6ae9ed
     ret = ncpupids;
6ae9ed
 
6ae9ed
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
6ae9ed
index be61535..a7176c4 100644
6ae9ed
--- a/src/qemu/qemu_domain.h
6ae9ed
+++ b/src/qemu/qemu_domain.h
6ae9ed
@@ -649,6 +649,7 @@ int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
6ae9ed
 
6ae9ed
 bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
6ae9ed
 pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
6ae9ed
+int qemuDomainValidateVcpuInfo(virDomainObjPtr vm);
6ae9ed
 int qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
6ae9ed
                               virDomainObjPtr vm,
6ae9ed
                               int asyncJob);
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed