[PATCH 05/10] nodeinfo: Add out parameter to nodeGetPresentCPUBitmap()

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

 



This aligns it with nodeGetCPUBitmap(), which already has a
similar out parameters, and relieves users of this API from the
need to call virBitmapSize() on the returned bitmap.
---
 src/nodeinfo.c       | 8 ++++++--
 src/nodeinfo.h       | 6 ++++--
 src/util/vircgroup.c | 4 +---
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 5aa0607..7aecc8f 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -440,7 +440,7 @@ virNodeParseNode(const char *sysfs_prefix,
         goto cleanup;
     }
 
-    present_cpumap = nodeGetPresentCPUBitmap(sysfs_prefix);
+    present_cpumap = nodeGetPresentCPUBitmap(sysfs_prefix, NULL);
     if (!present_cpumap)
         goto cleanup;
 
@@ -1280,7 +1280,8 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
 }
 
 virBitmapPtr
-nodeGetPresentCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
+nodeGetPresentCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED,
+                        int *size ATTRIBUTE_UNUSED)
 {
 #ifdef __linux__
     virBitmapPtr present_cpus = NULL;
@@ -1313,6 +1314,9 @@ nodeGetPresentCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
  cleanup:
     VIR_FREE(present_path);
 
+    if (present_cpus && size)
+        *size = npresent_cpus;
+
     return present_cpus;
 #endif
     virReportError(VIR_ERR_NO_SUPPORT, "%s",
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
index 4f983c2..e83db7b 100644
--- a/src/nodeinfo.h
+++ b/src/nodeinfo.h
@@ -44,8 +44,10 @@ int nodeGetCellsFreeMemory(unsigned long long *freeMems,
 int nodeGetMemory(unsigned long long *mem,
                   unsigned long long *freeMem);
 
-virBitmapPtr nodeGetPresentCPUBitmap(const char *sysfs_prefix);
-virBitmapPtr nodeGetCPUBitmap(const char *sysfs_prefix, int *max_id);
+virBitmapPtr nodeGetPresentCPUBitmap(const char *sysfs_prefix,
+                                     int *size);
+virBitmapPtr nodeGetCPUBitmap(const char *sysfs_prefix,
+                              int *size);
 int nodeGetCPUCount(const char *sysfs_prefix);
 
 int nodeGetMemoryParameters(virTypedParameterPtr params,
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 0ef2d29..5011f9c 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -3043,11 +3043,9 @@ virCgroupGetPercpuStats(virCgroupPtr group,
     }
 
     /* To parse account file, we need to know how many cpus are present.  */
-    if (!(cpumap = nodeGetPresentCPUBitmap(NULL)))
+    if (!(cpumap = nodeGetPresentCPUBitmap(NULL, &total_cpus)))
         return rv;
 
-    total_cpus = virBitmapSize(cpumap);
-
     if (ncpus == 0) {
         rv = total_cpus;
         goto cleanup;
-- 
2.4.3

--
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]