[PATCHv2 7/9] virNodeGetCPUMapFlags: Implement support function in nodeinfo

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

 



Added an implemention of virNodeGetCPUMapFlags to nodeinfo.c,
(nodeGetCPUMapFlags) which can be used by all drivers for a Linux
hypervisor host.

Signed-off-by: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx>
---
 src/libvirt_private.syms |    1 +
 src/nodeinfo.c           |   49 ++++++++++++++++++++++++++++++++++++++++++++++
 src/nodeinfo.h           |    6 +++++
 3 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index fe31bbe..44d5927 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -900,6 +900,7 @@ virNodeDeviceObjUnlock;
 # nodeinfo.h
 nodeCapsInitNUMA;
 nodeGetCPUmap;
+nodeGetCPUMapFlags;
 nodeGetCPUStats;
 nodeGetCellsFreeMemory;
 nodeGetFreeMemory;
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index c0e60d8..84cf796 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -1203,6 +1203,55 @@ nodeGetMemoryParameters(virConnectPtr conn ATTRIBUTE_UNUSED,
 #endif
 }
 
+int nodeGetCPUMapFlags(virConnectPtr conn,
+                       unsigned char **cpumap,
+                       unsigned int *online,
+                       unsigned int flags)
+{
+    virBitmapPtr cpusPresent = NULL;
+    virBitmapPtr cpusOnline = NULL;
+    int maxpresent, maxonline, i;
+    int ret = -1;
+
+    virCheckFlags(0, 1);
+
+    if (!(cpusPresent = nodeGetCPUmap(conn, &maxpresent, "present"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to retrieve 'present' CPU map"));
+        goto cleanup;
+    }
+
+    if (!(cpusOnline = nodeGetCPUmap(conn, &maxonline, "online"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to retrieve 'online' CPU map"));
+        goto cleanup;
+    }
+
+    if (cpumap && VIR_ALLOC_N(*cpumap, VIR_CPU_MAPLEN(maxpresent)) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if (online)
+        *online = 0;
+
+    i = -1;
+    while ((i=virBitmapNextSetBit(cpusOnline, i)) >= 0) {
+        if (online)
+            (*online)++;
+
+        if (cpumap)
+            VIR_USE_CPU(*cpumap,i);
+    }
+
+    ret = maxpresent + 1;
+
+cleanup:
+    virBitmapFree(cpusPresent);
+    virBitmapFree(cpusOnline);
+    return ret;
+}
+
 #if HAVE_NUMACTL
 # if LIBNUMA_API_VERSION <= 1
 #  define NUMA_MAX_N_CPUS 4096
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
index 2eda846..e210e6b 100644
--- a/src/nodeinfo.h
+++ b/src/nodeinfo.h
@@ -59,4 +59,10 @@ int nodeSetMemoryParameters(virConnectPtr conn,
                             virTypedParameterPtr params,
                             int nparams,
                             unsigned int flags);
+
+int nodeGetCPUMapFlags(virConnectPtr conn,
+                       unsigned char **cpumap,
+                       unsigned int *online,
+                       unsigned int flags);
+
 #endif /* __VIR_NODEINFO_H__*/
-- 
1.7.0.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]