[PATCH 1/3] qemu, lxc: Change host CPU detection logic.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The drivers for QEMU and LXC use virNodeGetInfo to determine the
number of host CPUs. This approach can lead to a wrong (too small)
number if one or more CPUs are offline.
It is better to use virNodeGetCPUMap if available, which is the
case here.

Signed-off-by: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx>
---
 src/lxc/lxc_controller.c |  8 +++-----
 src/qemu/qemu_driver.c   | 12 +++---------
 src/qemu/qemu_process.c  | 10 ++++------
 3 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index a41c903..e9720bc 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -492,17 +492,15 @@ static int virLXCControllerSetupNUMAPolicy(virLXCControllerPtr ctrl)
 static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
 {
     int hostcpus, maxcpu = CPU_SETSIZE;
-    virNodeInfo nodeinfo;
     virBitmapPtr cpumap, cpumapToSet;
 
     VIR_DEBUG("Setting CPU affinity");
 
-    if (nodeGetInfo(NULL, &nodeinfo) < 0)
-        return -1;
-
     /* setaffinity fails if you set bits for CPUs which
      * aren't present, so we have to limit ourselves */
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
+    if ((hostcpus = nodeGetCPUMap(NULL, NULL, NULL, 0)) < 0)
+        return -1;
+
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 18be7d9..84f015f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4089,7 +4089,6 @@ qemudDomainGetVcpuPinInfo(virDomainPtr dom,
 
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm = NULL;
-    virNodeInfo nodeinfo;
     virDomainDefPtr targetDef = NULL;
     int ret = -1;
     int maxcpu, hostcpus, vcpu, pcpu;
@@ -4125,9 +4124,8 @@ qemudDomainGetVcpuPinInfo(virDomainPtr dom,
     /* Coverity didn't realize that targetDef must be set if we got here.  */
     sa_assert(targetDef);
 
-    if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
+    if ((hostcpus = nodeGetCPUMap(dom->conn, NULL, NULL, 0)) < 0)
         goto cleanup;
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
     maxcpu = maplen * 8;
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
@@ -4340,7 +4338,6 @@ qemudDomainGetEmulatorPinInfo(virDomainPtr dom,
 {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm = NULL;
-    virNodeInfo nodeinfo;
     virDomainDefPtr targetDef = NULL;
     int ret = -1;
     int maxcpu, hostcpus, pcpu;
@@ -4373,9 +4370,8 @@ qemudDomainGetEmulatorPinInfo(virDomainPtr dom,
     /* Coverity didn't realize that targetDef must be set if we got here. */
     sa_assert(targetDef);
 
-    if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
+    if ((hostcpus = nodeGetCPUMap(dom->conn, NULL, NULL, 0)) < 0)
         goto cleanup;
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
     maxcpu = maplen * 8;
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
@@ -4417,7 +4413,6 @@ qemudDomainGetVcpus(virDomainPtr dom,
                     int maplen) {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
-    virNodeInfo nodeinfo;
     int i, v, maxcpu, hostcpus;
     int ret = -1;
     qemuDomainObjPrivatePtr priv;
@@ -4443,10 +4438,9 @@ qemudDomainGetVcpus(virDomainPtr dom,
 
     priv = vm->privateData;
 
-    if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
+    if ((hostcpus = nodeGetCPUMap(dom->conn, NULL, NULL, 0)) < 0)
         goto cleanup;
 
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
     maxcpu = maplen * 8;
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 5004e9b..64206cb 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1899,15 +1899,13 @@ qemuPrepareCpumap(struct qemud_driver *driver,
                   virBitmapPtr nodemask)
 {
     int i, hostcpus, maxcpu = QEMUD_CPUMASK_LEN;
-    virNodeInfo nodeinfo;
     virBitmapPtr cpumap = NULL;
 
-    if (nodeGetInfo(NULL, &nodeinfo) < 0)
-        return NULL;
-
     /* setaffinity fails if you set bits for CPUs which
      * aren't present, so we have to limit ourselves */
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
+    if ((hostcpus = nodeGetCPUMap(NULL, NULL, NULL, 0)) < 0)
+        return NULL;
+
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
 
@@ -1923,7 +1921,7 @@ qemuPrepareCpumap(struct qemud_driver *driver,
             bool result;
             if (virBitmapGetBit(nodemask, i, &result) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("Failed to covert nodeset to cpuset"));
+                               _("Failed to convert nodeset to cpuset"));
                 virBitmapFree(cpumap);
                 return NULL;
             }
-- 
1.7.12.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]