]> xenbits.xensource.com Git - libvirt.git/commitdiff
virhostcpu.c: introduce virHostCPUGetAvailableCPUsBitmap()
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 26 Jun 2020 22:10:43 +0000 (19:10 -0300)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 8 Jul 2020 17:39:41 +0000 (19:39 +0200)
The idea is to have a function that calls virHostCPUGetOnlineBitmap()
but, instead of returning NULL if the host does not have CPU
offlining capabilities,  fall back to a bitmap containing all
present CPUs.

Next patch will use this helper in two other places.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/virhostcpu.c
src/util/virhostcpu.h

index d6b87b72f4bd09fae163b58302d2d9e0104acb94..5a342b9fd452af6c6b6fe8c271e68e54580722ea 100644 (file)
@@ -2223,6 +2223,7 @@ virHookPresent;
 
 
 # util/virhostcpu.h
+virHostCPUGetAvailableCPUsBitmap;
 virHostCPUGetCount;
 virHostCPUGetInfo;
 virHostCPUGetKVMMaxVCPUs;
index 615250d05ddea412e770618740899bcbc31bbc6f..8ca67e357dd919f5b409931a609933f4995a18fd 100644 (file)
@@ -1099,6 +1099,36 @@ virHostCPUGetMap(unsigned char **cpumap,
 }
 
 
+/* virHostCPUGetAvailableCPUsBitmap():
+ *
+ * Returns a virBitmap object with all available host CPUs.
+ *
+ * This is a glorified wrapper of virHostCPUGetOnlineBitmap()
+ * that, instead of returning NULL when 'ifndef __linux__' and
+ * the caller having to handle it outside the function, returns
+ * a virBitmap with all the possible CPUs in the host, up to
+ * virHostCPUGetCount(). */
+virBitmapPtr
+virHostCPUGetAvailableCPUsBitmap(void)
+{
+    g_autoptr(virBitmap) bitmap = NULL;
+
+    if (!(bitmap = virHostCPUGetOnlineBitmap())) {
+        int hostcpus;
+
+        if ((hostcpus = virHostCPUGetCount()) < 0)
+            return NULL;
+
+        if (!(bitmap = virBitmapNew(hostcpus)))
+            return NULL;
+
+        virBitmapSetAll(bitmap);
+    }
+
+    return g_steal_pointer(&bitmap);
+}
+
+
 #if HAVE_LINUX_KVM_H && defined(KVM_CAP_PPC_SMT)
 
 /* Get the number of threads per subcore.
index 48b1431ca459387d79a35cd7592041b3908e1d04..d07503857effe76d026b08320cf75876d7adb85a 100644 (file)
@@ -43,6 +43,8 @@ int virHostCPUGetStats(int cpuNum,
 bool virHostCPUHasBitmap(void);
 virBitmapPtr virHostCPUGetPresentBitmap(void);
 virBitmapPtr virHostCPUGetOnlineBitmap(void);
+virBitmapPtr virHostCPUGetAvailableCPUsBitmap(void);
+
 int virHostCPUGetCount(void);
 int virHostCPUGetThreadsPerSubcore(virArch arch) G_GNUC_NO_INLINE;