render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
7a3408
From 007cca58b412fbc476d6bebed0f1fbc7e9fa194e Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <007cca58b412fbc476d6bebed0f1fbc7e9fa194e@dist-git>
7a3408
From: John Ferlan <jferlan@redhat.com>
7a3408
Date: Wed, 5 Aug 2015 18:18:10 +0200
7a3408
Subject: [PATCH] nodeinfo: Add sysfs_prefix to nodeGetCPUBitmap
7a3408
7a3408
Add the sysfs_prefix argument to the call to allow for setting the
7a3408
path for tests to something other than SYSFS_SYSTEM_PATH.
7a3408
7a3408
(cherry picked from commit f220a3e5a883035d609f81d481bf52bb1c0b4974)
7a3408
7a3408
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1213713
7a3408
7a3408
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/nodeinfo.c | 24 ++++++++++++++++--------
7a3408
 src/nodeinfo.h |  2 +-
7a3408
 2 files changed, 17 insertions(+), 9 deletions(-)
7a3408
7a3408
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
7a3408
index 34de720..75e0a02 100644
7a3408
--- a/src/nodeinfo.c
7a3408
+++ b/src/nodeinfo.c
7a3408
@@ -1275,29 +1275,35 @@ nodeGetPresentCPUBitmap(const char *sysfs_prefix)
7a3408
 }
7a3408
 
7a3408
 virBitmapPtr
7a3408
-nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED)
7a3408
+nodeGetCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED,
7a3408
+                 int *max_id ATTRIBUTE_UNUSED)
7a3408
 {
7a3408
 #ifdef __linux__
7a3408
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
7a3408
+    char *online_path = NULL;
7a3408
     virBitmapPtr cpumap;
7a3408
     int present;
7a3408
 
7a3408
-    present = nodeGetCPUCount(NULL);
7a3408
+    present = nodeGetCPUCount(prefix);
7a3408
     if (present < 0)
7a3408
         return NULL;
7a3408
 
7a3408
-    if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/online")) {
7a3408
-        cpumap = linuxParseCPUmap(present, SYSFS_SYSTEM_PATH "/cpu/online");
7a3408
+    if (virAsprintf(&online_path, "%s/cpu/online", prefix) < 0)
7a3408
+        return NULL;
7a3408
+    if (virFileExists(online_path)) {
7a3408
+        cpumap = linuxParseCPUmap(present, online_path);
7a3408
     } else {
7a3408
         size_t i;
7a3408
 
7a3408
         cpumap = virBitmapNew(present);
7a3408
         if (!cpumap)
7a3408
-            return NULL;
7a3408
+            goto cleanup;
7a3408
         for (i = 0; i < present; i++) {
7a3408
-            int online = virNodeGetCpuValue(SYSFS_SYSTEM_PATH, i, "online", 1);
7a3408
+            int online = virNodeGetCpuValue(prefix, i, "online", 1);
7a3408
             if (online < 0) {
7a3408
                 virBitmapFree(cpumap);
7a3408
-                return NULL;
7a3408
+                cpumap = NULL;
7a3408
+                goto cleanup;
7a3408
             }
7a3408
             if (online)
7a3408
                 ignore_value(virBitmapSetBit(cpumap, i));
7a3408
@@ -1305,6 +1311,8 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED)
7a3408
     }
7a3408
     if (max_id && cpumap)
7a3408
         *max_id = present;
7a3408
+ cleanup:
7a3408
+    VIR_FREE(online_path);
7a3408
     return cpumap;
7a3408
 #else
7a3408
     virReportError(VIR_ERR_NO_SUPPORT, "%s",
7a3408
@@ -1630,7 +1638,7 @@ nodeGetCPUMap(unsigned char **cpumap,
7a3408
     if (!cpumap && !online)
7a3408
         return nodeGetCPUCount(NULL);
7a3408
 
7a3408
-    if (!(cpus = nodeGetCPUBitmap(&maxpresent)))
7a3408
+    if (!(cpus = nodeGetCPUBitmap(NULL, &maxpresent)))
7a3408
         goto cleanup;
7a3408
 
7a3408
     if (cpumap && virBitmapToData(cpus, cpumap, &dummy) < 0)
7a3408
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
7a3408
index 3ef206b..439ef35 100644
7a3408
--- a/src/nodeinfo.h
7a3408
+++ b/src/nodeinfo.h
7a3408
@@ -44,7 +44,7 @@ int nodeGetMemory(unsigned long long *mem,
7a3408
                   unsigned long long *freeMem);
7a3408
 
7a3408
 virBitmapPtr nodeGetPresentCPUBitmap(const char *sysfs_prefix);
7a3408
-virBitmapPtr nodeGetCPUBitmap(int *max_id);
7a3408
+virBitmapPtr nodeGetCPUBitmap(const char *sysfs_prefix, int *max_id);
7a3408
 int nodeGetCPUCount(const char *sysfs_prefix);
7a3408
 
7a3408
 int nodeGetMemoryParameters(virTypedParameterPtr params,
7a3408
-- 
7a3408
2.5.0
7a3408