]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: fix detection of available host CPUs for vcpupin
authorPavel Hrdina <phrdina@redhat.com>
Fri, 7 Aug 2020 13:48:27 +0000 (15:48 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Sat, 8 Aug 2020 09:07:02 +0000 (11:07 +0200)
Commit <2020c6af8a8e4bb04acb629d089142be984484c8> fixed an issue with
QEMU driver by reporting offline CPUs as well. However, doing so it
introduced a regression into libxl and test drivers by completely
ignoring the passed `hostcpus` variable.

Move the virHostCPUGetAvailableCPUsBitmap() out of the helper into QEMU
driver so it will not affect other drivers which gets the number of host
CPUs differently.

This was uncovered by running libvirt-dbus test suite which counts on
the fact that test driver has hard-coded host definition and must not
depend on the host at all.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libxl/libxl_driver.c
src/qemu/qemu_driver.c
src/test/test_driver.c

index ef67efa1da65e245017755f6fd9983ce822b5b19..8e7981bf2558f6ad5e75e6fc262fb1e1c54b50ce 100644 (file)
@@ -2090,33 +2090,25 @@ virDomainDefHasVcpuPin(const virDomainDef *def)
  * @maplen: length of one cpumap passed from caller (@cpumaps)
  * @ncpumaps: count of cpumaps of @maplen length in @cpumaps
  * @cpumaps: array of pinning information bitmaps to be filled
- * @hostcpus: number of cpus in the host
+ * @hostcpus: default CPU pinning bitmap based on host CPUs
  * @autoCpuset: Cpu pinning bitmap used in case of automatic cpu pinning
  *
  * Fills the @cpumaps array as documented by the virDomainGetVcpuPinInfo API.
  * In case when automatic cpu pinning is supported, the bitmap should be passed
- * as @autoCpuset. If @hostcpus is < 0 no error is reported (to pass through
- * error message).
+ * as @autoCpuset.
  *
- * Returns number of filled entries or -1 on error.
+ * Returns number of filled entries.
  */
 int
 virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
                                  int maplen,
                                  int ncpumaps,
                                  unsigned char *cpumaps,
-                                 int hostcpus,
+                                 virBitmapPtr hostcpus,
                                  virBitmapPtr autoCpuset)
 {
     int maxvcpus = virDomainDefGetVcpusMax(def);
     size_t i;
-    g_autoptr(virBitmap) allcpumap = NULL;
-
-    if (hostcpus < 0)
-        return -1;
-
-    if (!(allcpumap = virHostCPUGetAvailableCPUsBitmap()))
-        return -1;
 
     for (i = 0; i < maxvcpus && i < ncpumaps; i++) {
         virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i);
@@ -2130,7 +2122,7 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
         else if (def->cpumask)
             bitmap = def->cpumask;
         else
-            bitmap = allcpumap;
+            bitmap = hostcpus;
 
         virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen);
     }
index 011bf66cb40c0c44deec6ad9d4aa66ddf17be29f..68be32614c2aef629cf593bb44593227943f25c8 100644 (file)
@@ -3741,9 +3741,9 @@ int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
                                      int maplen,
                                      int ncpumaps,
                                      unsigned char *cpumaps,
-                                     int hostcpus,
+                                     virBitmapPtr hostcpus,
                                      virBitmapPtr autoCpuset)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) G_GNUC_WARN_UNUSED_RESULT;
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) G_GNUC_WARN_UNUSED_RESULT;
 
 bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(1);
 
index 4db3c0782e42ccfa68a5d966ef08af7173a2e679..dc602ea1624aad908f86ca40babe6d628bb38bbb 100644 (file)
@@ -2547,6 +2547,7 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
     libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm = NULL;
     virDomainDefPtr targetDef = NULL;
+    g_autoptr(virBitmap) hostcpus = NULL;
     int ret = -1;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -2568,8 +2569,12 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
     /* Make sure coverity knows targetDef is valid at this point. */
     sa_assert(targetDef);
 
+    if (!(hostcpus = virBitmapNew(libxl_get_max_cpus(cfg->ctx))))
+        goto cleanup;
+    virBitmapSetAll(hostcpus);
+
     ret = virDomainDefGetVcpuPinInfoHelper(targetDef, maplen, ncpumaps, cpumaps,
-                                           libxl_get_max_cpus(cfg->ctx), NULL);
+                                           hostcpus, NULL);
 
  cleanup:
     virDomainObjEndAPI(&vm);
index 0f98243fe4b7711c5be9ae84855fdfe45b2ab469..9eaea8d61340da04943c1122bf13ff5144a15880 100644 (file)
@@ -5288,6 +5288,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
     virDomainDefPtr def;
     bool live;
     int ret = -1;
+    g_autoptr(virBitmap) hostcpus = NULL;
     virBitmapPtr autoCpuset = NULL;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -5302,11 +5303,14 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
     if (!(def = virDomainObjGetOneDefState(vm, flags, &live)))
         goto cleanup;
 
+    if (!(hostcpus = virHostCPUGetAvailableCPUsBitmap()))
+        goto cleanup;
+
     if (live)
         autoCpuset = QEMU_DOMAIN_PRIVATE(vm)->autoCpuset;
 
     ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
-                                           virHostCPUGetCount(), autoCpuset);
+                                           hostcpus, autoCpuset);
  cleanup:
     virDomainObjEndAPI(&vm);
     return ret;
index 01c4675c3089a307f874ccb59fb04e9eb77d8d9f..a75c992af1f667220e4c686f2dd29d6f20834cb8 100644 (file)
@@ -3072,6 +3072,7 @@ testDomainGetVcpuPinInfo(virDomainPtr dom,
     testDriverPtr driver = dom->conn->privateData;
     virDomainObjPtr privdom;
     virDomainDefPtr def;
+    g_autoptr(virBitmap) hostcpus = NULL;
     int ret = -1;
 
     if (!(privdom = testDomObjFromDomain(dom)))
@@ -3080,9 +3081,12 @@ testDomainGetVcpuPinInfo(virDomainPtr dom,
     if (!(def = virDomainObjGetOneDef(privdom, flags)))
         goto cleanup;
 
+    if (!(hostcpus = virBitmapNew(VIR_NODEINFO_MAXCPUS(driver->nodeInfo))))
+        goto cleanup;
+    virBitmapSetAll(hostcpus);
+
     ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
-                                           VIR_NODEINFO_MAXCPUS(driver->nodeInfo),
-                                           NULL);
+                                           hostcpus, NULL);
 
  cleanup:
     virDomainObjEndAPI(&privdom);