]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodeinfo: remove sysfs_prefix from all methods
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 13 Apr 2016 14:28:55 +0000 (15:28 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 9 Jun 2016 17:00:18 +0000 (18:00 +0100)
Nearly all the methods in the nodeinfo file are given a
'const char *sysfs_prefix' parameter to override the
default sysfs path (/sys/devices/system). Every single
caller passes in NULL for this, except one use in the
unit tests. Furthermore this parameter is totally
Linux-specific, when the APIs are intended to be cross
platform portable.

This removes the sysfs_prefix parameter and instead gives
a new method linuxNodeInfoSetSysFSSystemPath for use by
the test suite.

For two of the methods this hardcodes use of the constant
SYSFS_SYSTEM_PATH, since the test suite does not need to
override the path for thos methods.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
24 files changed:
src/bhyve/bhyve_capabilities.c
src/bhyve/bhyve_driver.c
src/libvirt_linux.syms
src/lxc/lxc_conf.c
src/lxc/lxc_controller.c
src/lxc/lxc_driver.c
src/nodeinfo.c
src/nodeinfo.h
src/nodeinfopriv.h
src/openvz/openvz_conf.c
src/openvz/openvz_driver.c
src/phyp/phyp_driver.c
src/qemu/qemu_capabilities.c
src/qemu/qemu_driver.c
src/qemu/qemu_process.c
src/uml/uml_conf.c
src/uml/uml_driver.c
src/util/vircgroup.c
src/vbox/vbox_common.c
src/vmware/vmware_conf.c
src/vz/vz_driver.c
src/vz/vz_sdk.c
tests/nodeinfotest.c
tests/vircgrouptest.c

index 93faaed82b63708b0aa14d6fc3e5362e89649f1b..d0af4d9dced3b9dce58915f3e292385c2f164900 100644 (file)
@@ -51,7 +51,7 @@ virBhyveCapsInitCPU(virCapsPtr caps,
 
     cpu->arch = arch;
 
-    if (nodeGetInfo(NULL, &nodeinfo))
+    if (nodeGetInfo(&nodeinfo))
         goto error;
 
     cpu->type = VIR_CPU_TYPE_HOST;
index a629038b466665fc6b3717c2c92fb03054e1959b..6cb3aacbf88b7c0b43937e4d8febad98e9180c08 100644 (file)
@@ -1175,7 +1175,7 @@ bhyveNodeGetMemoryStats(virConnectPtr conn,
     if (virNodeGetMemoryStatsEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags);
+    return nodeGetMemoryStats(cellNum, params, nparams, flags);
 }
 
 static int
@@ -1185,7 +1185,7 @@ bhyveNodeGetInfo(virConnectPtr conn,
     if (virNodeGetInfoEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetInfo(NULL, nodeinfo);
+    return nodeGetInfo(nodeinfo);
 }
 
 static int
@@ -1361,7 +1361,7 @@ bhyveNodeGetCPUMap(virConnectPtr conn,
     if (virNodeGetCPUMapEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetCPUMap(NULL, cpumap, online, flags);
+    return nodeGetCPUMap(cpumap, online, flags);
 }
 
 static int
index 1a7f263fba731d86d684100b07d21b28750024b4..f569a2349b820895dc21ab65e4d9877082bd37a2 100644 (file)
@@ -5,6 +5,7 @@
 # nodeinfo.h
 linuxNodeGetCPUStats;
 linuxNodeInfoCPUPopulate;
+linuxNodeInfoSetSysFSSystemPath;
 
 # Let emacs know we want case-insensitive sorting
 # Local Variables:
index 8ada5311de3cb54ea29fafcc3a11e9581fa7bc8c..96a0f47dc46997e9ef88de5c50280676ba65f49d 100644 (file)
@@ -77,7 +77,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
      * unexpected failures. We don't want to break the lxc
      * driver in this scenario, so log errors & carry on
      */
-    if (nodeCapsInitNUMA(NULL, caps) < 0) {
+    if (nodeCapsInitNUMA(caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
index 8b428036cadcca5f7afac822d952c635498bb5d6..ed0ae782f73624456fb20b24814f8b0d16b53f6b 100644 (file)
@@ -730,7 +730,7 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
 
     /* setaffinity fails if you set bits for CPUs which
      * aren't present, so we have to limit ourselves */
-    if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
+    if ((hostcpus = nodeGetCPUCount()) < 0)
         return -1;
 
     if (maxcpu > hostcpus)
index 626c754bab88351fc690cfb3e1045d2401a4bfc1..7d3c02b21a4f93a08c5ef473b90414b20a5573d2 100644 (file)
@@ -5154,7 +5154,7 @@ lxcNodeGetInfo(virConnectPtr conn,
     if (virNodeGetInfoEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetInfo(NULL, nodeinfo);
+    return nodeGetInfo(nodeinfo);
 }
 
 
@@ -5246,7 +5246,7 @@ lxcNodeGetMemoryStats(virConnectPtr conn,
     if (virNodeGetMemoryStatsEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags);
+    return nodeGetMemoryStats(cellNum, params, nparams, flags);
 }
 
 
@@ -5313,7 +5313,7 @@ lxcNodeGetCPUMap(virConnectPtr conn,
     if (virNodeGetCPUMapEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetCPUMap(NULL, cpumap, online, flags);
+    return nodeGetCPUMap(cpumap, online, flags);
 }
 
 
index 77ea15502ad3f66c2285176fc33aa1522e214aa0..1288543d8475ece8381dbce52c3fbbbfdc227d06 100644 (file)
@@ -65,7 +65,6 @@
 
 VIR_LOG_INIT("nodeinfo");
 
-#define SYSFS_SYSTEM_PATH "/sys/devices/system"
 
 #if defined(__FreeBSD__) || defined(__APPLE__)
 static int
@@ -290,6 +289,7 @@ freebsdNodeGetMemoryStats(virNodeMemoryStatsPtr params,
 #endif /* __FreeBSD__ */
 
 #ifdef __linux__
+# define SYSFS_SYSTEM_PATH "/sys/devices/system"
 # define CPUINFO_PATH "/proc/cpuinfo"
 # define PROCSTAT_PATH "/proc/stat"
 # define MEMINFO_PATH "/proc/meminfo"
@@ -300,6 +300,16 @@ freebsdNodeGetMemoryStats(virNodeMemoryStatsPtr params,
 # define LINUX_NB_MEMORY_STATS_ALL 4
 # define LINUX_NB_MEMORY_STATS_CELL 2
 
+static const char *sysfs_system_path = SYSFS_SYSTEM_PATH;
+
+void linuxNodeInfoSetSysFSSystemPath(const char *path)
+{
+    if (path)
+        sysfs_system_path = path;
+    else
+        sysfs_system_path = SYSFS_SYSTEM_PATH;
+}
+
 /* Return the positive decimal contents of the given
  * DIR/cpu%u/FILE, or -1 on error.  If DEFAULT_VALUE is non-negative
  * and the file could not be found, return that instead of an error;
@@ -593,8 +603,7 @@ virNodeParseNode(const char *node,
  * A valid configuration is one where no secondary thread is online;
  * the primary thread in a subcore is always the first one */
 static bool
-nodeHasValidSubcoreConfiguration(const char *sysfs_prefix,
-                                 int threads_per_subcore)
+nodeHasValidSubcoreConfiguration(int threads_per_subcore)
 {
     virBitmapPtr online_cpus = NULL;
     int cpu = -1;
@@ -604,7 +613,7 @@ nodeHasValidSubcoreConfiguration(const char *sysfs_prefix,
     if (threads_per_subcore <= 0)
         goto cleanup;
 
-    if (!(online_cpus = nodeGetOnlineCPUBitmap(sysfs_prefix)))
+    if (!(online_cpus = nodeGetOnlineCPUBitmap()))
         goto cleanup;
 
     while ((cpu = virBitmapNextSetBit(online_cpus, cpu)) >= 0) {
@@ -624,12 +633,10 @@ nodeHasValidSubcoreConfiguration(const char *sysfs_prefix,
 }
 
 int
-linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
-                         FILE *cpuinfo,
+linuxNodeInfoCPUPopulate(FILE *cpuinfo,
                          virArch arch,
                          virNodeInfoPtr nodeinfo)
 {
-    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
     virBitmapPtr present_cpus_map = NULL;
     virBitmapPtr online_cpus_map = NULL;
     char line[1024];
@@ -726,17 +733,17 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
 
     /* Get information about what CPUs are present in the host and what
      * CPUs are online, so that we don't have to so for each node */
-    present_cpus_map = nodeGetPresentCPUBitmap(sysfs_prefix);
+    present_cpus_map = nodeGetPresentCPUBitmap();
     if (!present_cpus_map)
         goto cleanup;
-    online_cpus_map = nodeGetOnlineCPUBitmap(sysfs_prefix);
+    online_cpus_map = nodeGetOnlineCPUBitmap();
     if (!online_cpus_map)
         goto cleanup;
 
     /* OK, we've parsed clock speed out of /proc/cpuinfo. Get the
      * core, node, socket, thread and topology information from /sys
      */
-    if (virAsprintf(&sysfs_nodedir, "%s/node", prefix) < 0)
+    if (virAsprintf(&sysfs_nodedir, "%s/node", sysfs_system_path) < 0)
         goto cleanup;
 
     if (!(nodedir = opendir(sysfs_nodedir))) {
@@ -771,7 +778,7 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
 
     /* If the subcore configuration is not valid, just pretend subcores
      * are not in use and count threads one by one */
-    if (!nodeHasValidSubcoreConfiguration(sysfs_prefix, threads_per_subcore))
+    if (!nodeHasValidSubcoreConfiguration(threads_per_subcore))
         threads_per_subcore = 0;
 
     while ((direrr = virDirRead(nodedir, &nodedirent, sysfs_nodedir)) > 0) {
@@ -781,7 +788,7 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
         nodeinfo->nodes++;
 
         if (virAsprintf(&sysfs_cpudir, "%s/node/%s",
-                        prefix, nodedirent->d_name) < 0)
+                        sysfs_system_path, nodedirent->d_name) < 0)
             goto cleanup;
 
         if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
@@ -815,7 +822,7 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
  fallback:
     VIR_FREE(sysfs_cpudir);
 
-    if (virAsprintf(&sysfs_cpudir, "%s/cpu", prefix) < 0)
+    if (virAsprintf(&sysfs_cpudir, "%s/cpu", sysfs_system_path) < 0)
         goto cleanup;
 
     if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
@@ -1079,28 +1086,26 @@ linuxNodeGetMemoryStats(FILE *meminfo,
 }
 
 static char *
-linuxGetCPUGlobalPath(const char *sysfs_prefix,
-                      const char *file)
+linuxGetCPUGlobalPath(const char *file)
 {
-    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
     char *path = NULL;
 
-    if (virAsprintf(&path, "%s/cpu/%s", prefix, file) < 0)
+    if (virAsprintf(&path, "%s/cpu/%s", sysfs_system_path, file) < 0)
         return NULL;
 
     return path;
 }
 
 static char *
-linuxGetCPUPresentPath(const char *sysfs_prefix)
+linuxGetCPUPresentPath(void)
 {
-    return linuxGetCPUGlobalPath(sysfs_prefix, "present");
+    return linuxGetCPUGlobalPath("present");
 }
 
 static char *
-linuxGetCPUOnlinePath(const char *sysfs_prefix)
+linuxGetCPUOnlinePath(void)
 {
-    return linuxGetCPUGlobalPath(sysfs_prefix, "online");
+    return linuxGetCPUGlobalPath("online");
 }
 
 /* Determine the number of CPUs (maximum CPU id + 1) from a file containing
@@ -1184,8 +1189,7 @@ virNodeGetSiblingsList(const char *dir, int cpu_id)
 #endif
 
 int
-nodeGetInfo(const char *sysfs_prefix ATTRIBUTE_UNUSED,
-            virNodeInfoPtr nodeinfo)
+nodeGetInfo(virNodeInfoPtr nodeinfo)
 {
     virArch hostarch = virArchFromHost();
 
@@ -1205,8 +1209,7 @@ nodeGetInfo(const char *sysfs_prefix ATTRIBUTE_UNUSED,
         return -1;
     }
 
-    ret = linuxNodeInfoCPUPopulate(sysfs_prefix, cpuinfo,
-                                   hostarch, nodeinfo);
+    ret = linuxNodeInfoCPUPopulate(cpuinfo, hostarch, nodeinfo);
     if (ret < 0)
         goto cleanup;
 
@@ -1293,8 +1296,7 @@ nodeGetCPUStats(int cpuNum ATTRIBUTE_UNUSED,
 }
 
 int
-nodeGetMemoryStats(const char *sysfs_prefix ATTRIBUTE_UNUSED,
-                   int cellNum ATTRIBUTE_UNUSED,
+nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED,
                    virNodeMemoryStatsPtr params ATTRIBUTE_UNUSED,
                    int *nparams ATTRIBUTE_UNUSED,
                    unsigned int flags)
@@ -1304,7 +1306,6 @@ nodeGetMemoryStats(const char *sysfs_prefix ATTRIBUTE_UNUSED,
 #ifdef __linux__
     {
         int ret;
-        const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
         char *meminfo_path = NULL;
         FILE *meminfo;
         int max_node;
@@ -1323,8 +1324,9 @@ nodeGetMemoryStats(const char *sysfs_prefix ATTRIBUTE_UNUSED,
                 return -1;
             }
 
-            if (virAsprintf(&meminfo_path, "%s/node/node%d/meminfo",
-                            prefix, cellNum) < 0)
+            if (virAsprintf(&meminfo_path,
+                            SYSFS_SYSTEM_PATH "/node/node%d/meminfo",
+                            cellNum) < 0)
                 return -1;
         }
         meminfo = fopen(meminfo_path, "r");
@@ -1351,7 +1353,7 @@ nodeGetMemoryStats(const char *sysfs_prefix ATTRIBUTE_UNUSED,
 }
 
 int
-nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
+nodeGetCPUCount(void)
 {
 #if defined(__linux__)
     /* To support older kernels that lack cpu/present, such as 2.6.18
@@ -1360,11 +1362,10 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
      * will be consecutive.
      */
     char *present_path = NULL;
-    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
     char *cpupath = NULL;
     int ncpu = -1;
 
-    if (!(present_path = linuxGetCPUPresentPath(sysfs_prefix)))
+    if (!(present_path = linuxGetCPUPresentPath()))
         return -1;
 
     if (virFileExists(present_path)) {
@@ -1372,7 +1373,7 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
         goto cleanup;
     }
 
-    if (virAsprintf(&cpupath, "%s/cpu/cpu0", prefix) < 0)
+    if (virAsprintf(&cpupath, "%s/cpu/cpu0", sysfs_system_path) < 0)
         goto cleanup;
     if (virFileExists(cpupath)) {
         ncpu = 0;
@@ -1380,7 +1381,7 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
             ncpu++;
             VIR_FREE(cpupath);
             if (virAsprintf(&cpupath, "%s/cpu/cpu%d",
-                            prefix, ncpu) < 0) {
+                            sysfs_system_path, ncpu) < 0) {
                 ncpu = -1;
                 goto cleanup;
             }
@@ -1405,17 +1406,17 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
 }
 
 virBitmapPtr
-nodeGetPresentCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
+nodeGetPresentCPUBitmap(void)
 {
 #ifdef __linux__
     virBitmapPtr present_cpus = NULL;
     char *present_path = NULL;
     int npresent_cpus;
 
-    if ((npresent_cpus = nodeGetCPUCount(sysfs_prefix)) < 0)
+    if ((npresent_cpus = nodeGetCPUCount()) < 0)
         goto cleanup;
 
-    if (!(present_path = linuxGetCPUPresentPath(sysfs_prefix)))
+    if (!(present_path = linuxGetCPUPresentPath()))
         goto cleanup;
 
     /* If the cpu/present file is available, parse it and exit */
@@ -1443,20 +1444,19 @@ nodeGetPresentCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
 }
 
 virBitmapPtr
-nodeGetOnlineCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
+nodeGetOnlineCPUBitmap(void)
 {
 #ifdef __linux__
-    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
     char *online_path = NULL;
     char *cpudir = NULL;
     virBitmapPtr cpumap;
     int present;
 
-    present = nodeGetCPUCount(sysfs_prefix);
+    present = nodeGetCPUCount();
     if (present < 0)
         return NULL;
 
-    if (!(online_path = linuxGetCPUOnlinePath(sysfs_prefix)))
+    if (!(online_path = linuxGetCPUOnlinePath()))
         return NULL;
     if (virFileExists(online_path)) {
         cpumap = linuxParseCPUmap(present, online_path);
@@ -1467,7 +1467,7 @@ nodeGetOnlineCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
         if (!cpumap)
             goto cleanup;
 
-        if (virAsprintf(&cpudir, "%s/cpu", prefix) < 0)
+        if (virAsprintf(&cpudir, "%s/cpu", sysfs_system_path) < 0)
             goto cleanup;
 
         for (i = 0; i < present; i++) {
@@ -1796,8 +1796,7 @@ nodeGetMemoryParameters(virTypedParameterPtr params ATTRIBUTE_UNUSED,
 }
 
 int
-nodeGetCPUMap(const char *sysfs_prefix,
-              unsigned char **cpumap,
+nodeGetCPUMap(unsigned char **cpumap,
               unsigned int *online,
               unsigned int flags)
 {
@@ -1808,9 +1807,9 @@ nodeGetCPUMap(const char *sysfs_prefix,
     virCheckFlags(0, -1);
 
     if (!cpumap && !online)
-        return nodeGetCPUCount(sysfs_prefix);
+        return nodeGetCPUCount();
 
-    if (!(cpus = nodeGetOnlineCPUBitmap(sysfs_prefix)))
+    if (!(cpus = nodeGetOnlineCPUBitmap()))
         goto cleanup;
 
     if (cpumap && virBitmapToData(cpus, cpumap, &dummy) < 0)
@@ -1828,8 +1827,7 @@ nodeGetCPUMap(const char *sysfs_prefix,
 }
 
 static int
-nodeCapsInitNUMAFake(const char *sysfs_prefix,
-                     const char *cpupath ATTRIBUTE_UNUSED,
+nodeCapsInitNUMAFake(const char *cpupath ATTRIBUTE_UNUSED,
                      virCapsPtr caps ATTRIBUTE_UNUSED)
 {
     virNodeInfo nodeinfo;
@@ -1839,7 +1837,7 @@ nodeCapsInitNUMAFake(const char *sysfs_prefix,
     int id, cid;
     int onlinecpus ATTRIBUTE_UNUSED;
 
-    if (nodeGetInfo(sysfs_prefix, &nodeinfo) < 0)
+    if (nodeGetInfo(&nodeinfo) < 0)
         return -1;
 
     ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
@@ -2088,11 +2086,8 @@ virNodeCapsGetPagesInfo(int node,
 }
 
 int
-nodeCapsInitNUMA(const char *sysfs_prefix,
-                 virCapsPtr caps)
+nodeCapsInitNUMA(virCapsPtr caps)
 {
-    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
-    char *cpupath;
     int n;
     unsigned long long memory;
     virCapsHostNUMACellCPUPtr cpus = NULL;
@@ -2107,11 +2102,8 @@ nodeCapsInitNUMA(const char *sysfs_prefix,
     bool topology_failed = false;
     int max_node;
 
-    if (virAsprintf(&cpupath, "%s/cpu", prefix) < 0)
-        return -1;
-
     if (!virNumaIsAvailable()) {
-        ret = nodeCapsInitNUMAFake(sysfs_prefix, cpupath, caps);
+        ret = nodeCapsInitNUMAFake(SYSFS_SYSTEM_PATH "/cpu", caps);
         goto cleanup;
     }
 
@@ -2134,7 +2126,8 @@ nodeCapsInitNUMA(const char *sysfs_prefix,
 
         for (i = 0; i < virBitmapSize(cpumap); i++) {
             if (virBitmapIsBitSet(cpumap, i)) {
-                if (virNodeCapsFillCPUInfo(cpupath, i, cpus + cpu++) < 0) {
+                if (virNodeCapsFillCPUInfo(SYSFS_SYSTEM_PATH "/cpu",
+                                           i, cpus + cpu++) < 0) {
                     topology_failed = true;
                     virResetLastError();
                 }
@@ -2174,7 +2167,6 @@ nodeCapsInitNUMA(const char *sysfs_prefix,
     VIR_FREE(cpus);
     VIR_FREE(siblings);
     VIR_FREE(pageinfo);
-    VIR_FREE(cpupath);
     return ret;
 }
 
index ac96dca82655a61ece16314ef4d07d62185a1073..b4f434ed58394f117c4e295dc8cfedeb9c80c3c9 100644 (file)
 
 # include "capabilities.h"
 
-int nodeGetInfo(const char *sysfs_prefix, virNodeInfoPtr nodeinfo);
-int nodeCapsInitNUMA(const char *sysfs_prefix, virCapsPtr caps);
+int nodeGetInfo(virNodeInfoPtr nodeinfo);
+int nodeCapsInitNUMA(virCapsPtr caps);
 
 int nodeGetCPUStats(int cpuNum,
                     virNodeCPUStatsPtr params,
                     int *nparams,
                     unsigned int flags);
-int nodeGetMemoryStats(const char *sysfs_prefix,
-                       int cellNum,
+int nodeGetMemoryStats(int cellNum,
                        virNodeMemoryStatsPtr params,
                        int *nparams,
                        unsigned int flags);
@@ -44,9 +43,9 @@ int nodeGetCellsFreeMemory(unsigned long long *freeMems,
 int nodeGetMemory(unsigned long long *mem,
                   unsigned long long *freeMem);
 
-virBitmapPtr nodeGetPresentCPUBitmap(const char *sysfs_prefix);
-virBitmapPtr nodeGetOnlineCPUBitmap(const char *sysfs_prefix);
-int nodeGetCPUCount(const char *sysfs_prefix);
+virBitmapPtr nodeGetPresentCPUBitmap(void);
+virBitmapPtr nodeGetOnlineCPUBitmap(void);
+int nodeGetCPUCount(void);
 int nodeGetThreadsPerSubcore(virArch arch);
 
 int nodeGetMemoryParameters(virTypedParameterPtr params,
@@ -57,8 +56,7 @@ int nodeSetMemoryParameters(virTypedParameterPtr params,
                             int nparams,
                             unsigned int flags);
 
-int nodeGetCPUMap(const char *sysfs_prefix,
-                  unsigned char **cpumap,
+int nodeGetCPUMap(unsigned char **cpumap,
                   unsigned int *online,
                   unsigned int flags);
 
index 1aab4ad3733fcaebeb4f831338431e68e73cbeea..4fe489a5c9974e628d53270b56e09a952a4ade38 100644 (file)
@@ -25,8 +25,9 @@
 # include "nodeinfo.h"
 
 # ifdef __linux__
-int linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
-                             FILE *cpuinfo,
+void linuxNodeInfoSetSysFSSystemPath(const char *path);
+
+int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
                              virArch arch,
                              virNodeInfoPtr nodeinfo);
 
index 4103d6998d0de61bd91d3ae5336872ee416de550..820dc2291088a2000aa9939fffa7068fb6dd5d75 100644 (file)
@@ -165,7 +165,7 @@ virCapsPtr openvzCapsInit(void)
                                    false, false)) == NULL)
         goto no_memory;
 
-    if (nodeCapsInitNUMA(NULL, caps) < 0)
+    if (nodeCapsInitNUMA(caps) < 0)
         goto no_memory;
 
     if ((guest = virCapabilitiesAddGuest(caps,
@@ -633,7 +633,7 @@ openvzGetNodeCPUs(void)
 {
     virNodeInfo nodeinfo;
 
-    if (nodeGetInfo(NULL, &nodeinfo) < 0)
+    if (nodeGetInfo(&nodeinfo) < 0)
         return 0;
 
     return nodeinfo.cpus;
index 823e0c2356169581fc02d079b9387aadcbc57998..817a16254abfbbf25068c4156ccdda8be4dddc67 100644 (file)
@@ -2157,7 +2157,7 @@ static int
 openvzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
                   virNodeInfoPtr nodeinfo)
 {
-    return nodeGetInfo(NULL, nodeinfo);
+    return nodeGetInfo(nodeinfo);
 }
 
 
@@ -2179,7 +2179,7 @@ openvzNodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
                          int *nparams,
                          unsigned int flags)
 {
-    return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags);
+    return nodeGetMemoryStats(cellNum, params, nparams, flags);
 }
 
 
@@ -2209,7 +2209,7 @@ openvzNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED,
                     unsigned int *online,
                     unsigned int flags)
 {
-    return nodeGetCPUMap(NULL, cpumap, online, flags);
+    return nodeGetCPUMap(cpumap, online, flags);
 }
 
 
index 0521540b0aec7b4a40aa8ec216fa9d3ba5c58d6d..dce20bc77f68c6b595753b4a4d8bb404d31f6638 100644 (file)
@@ -335,7 +335,7 @@ phypCapsInit(void)
      * unexpected failures. We don't want to break the QEMU
      * driver in this scenario, so log errors & carry on
      */
-    if (nodeCapsInitNUMA(NULL, caps) < 0) {
+    if (nodeCapsInitNUMA(caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN
             ("Failed to query host NUMA topology, disabling NUMA capabilities");
index 00f6b40687ae5b17d088926115ee955e66b0b595..d9f04c8d3aada2a15d26830d3537cfb99503e5c3 100644 (file)
@@ -1013,7 +1013,7 @@ virQEMUCapsInitCPU(virCapsPtr caps,
 
     cpu->arch = arch;
 
-    if (nodeGetInfo(NULL, &nodeinfo))
+    if (nodeGetInfo(&nodeinfo))
         goto error;
 
     cpu->type = VIR_CPU_TYPE_HOST;
@@ -1076,7 +1076,7 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
      * unexpected failures. We don't want to break the QEMU
      * driver in this scenario, so log errors & carry on
      */
-    if (nodeCapsInitNUMA(NULL, caps) < 0) {
+    if (nodeCapsInitNUMA(caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
index 433968a0bfaa4ad3cf8c0acdc89d9e5bcc4e6645..387ba2e635ede697db55f5ec910ffe43d5dfb6a8 100644 (file)
@@ -5152,7 +5152,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
     priv = vm->privateData;
 
     ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
-                                           nodeGetCPUCount(NULL),
+                                           nodeGetCPUCount(),
                                            priv->autoCpuset);
  cleanup:
     virDomainObjEndAPI(&vm);
@@ -5297,7 +5297,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
     if (!(def = virDomainObjGetOneDef(vm, flags)))
         goto cleanup;
 
-    if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
+    if ((hostcpus = nodeGetCPUCount()) < 0)
         goto cleanup;
 
     priv = vm->privateData;
@@ -5545,7 +5545,7 @@ qemuDomainGetIOThreadsConfig(virDomainDefPtr targetDef,
     if (targetDef->niothreadids == 0)
         return 0;
 
-    if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
+    if ((hostcpus = nodeGetCPUCount()) < 0)
         goto cleanup;
 
     if (VIR_ALLOC_N(info_ret, targetDef->niothreadids) < 0)
@@ -18081,7 +18081,7 @@ qemuNodeGetInfo(virConnectPtr conn,
     if (virNodeGetInfoEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetInfo(NULL, nodeinfo);
+    return nodeGetInfo(nodeinfo);
 }
 
 
@@ -18109,7 +18109,7 @@ qemuNodeGetMemoryStats(virConnectPtr conn,
     if (virNodeGetMemoryStatsEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags);
+    return nodeGetMemoryStats(cellNum, params, nparams, flags);
 }
 
 
@@ -18176,7 +18176,7 @@ qemuNodeGetCPUMap(virConnectPtr conn,
     if (virNodeGetCPUMapEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetCPUMap(NULL, cpumap, online, flags);
+    return nodeGetCPUMap(cpumap, online, flags);
 }
 
 
index 7d61ecde79dd5dd82d2d921dc8d22f2458a61fe7..b1e86a7ec17836fad66abbcb8787e2975ffbe1d5 100644 (file)
@@ -2229,7 +2229,7 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm)
 
             /* setaffinity fails if you set bits for CPUs which
              * aren't present, so we have to limit ourselves */
-            if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
+            if ((hostcpus = nodeGetCPUCount()) < 0)
                 goto cleanup;
 
             if (hostcpus > QEMUD_CPUMASK_LEN)
index afc0375d81aa196033fe952f00a4fd2528c239fc..a97ae64507b6f913ac873977e26d79150c8d209c 100644 (file)
@@ -65,7 +65,7 @@ virCapsPtr umlCapsInit(void)
      * unexpected failures. We don't want to break the QEMU
      * driver in this scenario, so log errors & carry on
      */
-    if (nodeCapsInitNUMA(NULL, caps) < 0) {
+    if (nodeCapsInitNUMA(caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
index 20eef317ef14f8c3f106e7e84199ffea9c089d29..fa00ef17d88e53a4d12c7e386dd3fff281697b16 100644 (file)
@@ -2774,7 +2774,7 @@ umlNodeGetInfo(virConnectPtr conn,
     if (virNodeGetInfoEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetInfo(NULL, nodeinfo);
+    return nodeGetInfo(nodeinfo);
 }
 
 
@@ -2802,7 +2802,7 @@ umlNodeGetMemoryStats(virConnectPtr conn,
     if (virNodeGetMemoryStatsEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags);
+    return nodeGetMemoryStats(cellNum, params, nparams, flags);
 }
 
 
@@ -2869,7 +2869,7 @@ umlNodeGetCPUMap(virConnectPtr conn,
     if (virNodeGetCPUMapEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetCPUMap(NULL, cpumap, online, flags);
+    return nodeGetCPUMap(cpumap, online, flags);
 }
 
 
index ff83ab0055dd3684626f0708987af0c0cb5dc210..6a8f904b5a1885afc88e73053bc05c63b7ccb4bf 100644 (file)
@@ -3147,7 +3147,7 @@ virCgroupGetPercpuStats(virCgroupPtr group,
     }
 
     /* To parse account file, we need to know how many cpus are present.  */
-    if (!(cpumap = nodeGetPresentCPUBitmap(NULL)))
+    if (!(cpumap = nodeGetPresentCPUBitmap()))
         return -1;
 
     total_cpus = virBitmapSize(cpumap);
index 921eb8604994bf08a0c05fed365b1299180dc988..84807e616b7b6e492ff98706c4bfa397cd8af3f7 100644 (file)
@@ -318,7 +318,7 @@ static virCapsPtr vboxCapsInit(void)
                                    false, false)) == NULL)
         goto no_memory;
 
-    if (nodeCapsInitNUMA(NULL, caps) < 0)
+    if (nodeCapsInitNUMA(caps) < 0)
         goto no_memory;
 
     if ((guest = virCapabilitiesAddGuest(caps,
@@ -7527,7 +7527,7 @@ static int
 vboxNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
                 virNodeInfoPtr nodeinfo)
 {
-    return nodeGetInfo(NULL, nodeinfo);
+    return nodeGetInfo(nodeinfo);
 }
 
 static int
index b30b5de35b61b8bf4cd20492c45b2986eb5db7ca..873697601cac606e3f45f80f1e6f8aca9e0a2e80 100644 (file)
@@ -68,7 +68,7 @@ vmwareCapsInit(void)
                                    false, false)) == NULL)
         goto error;
 
-    if (nodeCapsInitNUMA(NULL, caps) < 0)
+    if (nodeCapsInitNUMA(caps) < 0)
         goto error;
 
     /* i686 guests are always supported */
index 26d4bf095f0d99ad02af1120bd7770fc8004166a..b2ddc9b0f0d269f3c691b16491eba23725bc2f99 100644 (file)
@@ -115,7 +115,7 @@ vzBuildCapabilities(void)
                                    false, false)) == NULL)
         return NULL;
 
-    if (nodeCapsInitNUMA(NULL, caps) < 0)
+    if (nodeCapsInitNUMA(caps) < 0)
         goto error;
 
     for (i = 0; i < 2; i++)
@@ -125,7 +125,7 @@ vzBuildCapabilities(void)
                                          emulators[k], virt_types[k]) < 0)
                     goto error;
 
-    if (nodeGetInfo(NULL, &nodeinfo))
+    if (nodeGetInfo(&nodeinfo))
         goto error;
 
     if (VIR_ALLOC(cpu) < 0)
@@ -832,7 +832,7 @@ static int
 vzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
               virNodeInfoPtr nodeinfo)
 {
-    return nodeGetInfo(NULL, nodeinfo);
+    return nodeGetInfo(nodeinfo);
 }
 
 static int vzConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
@@ -919,7 +919,7 @@ vzNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED,
                 unsigned int *online,
                 unsigned int flags)
 {
-    return nodeGetCPUMap(NULL, cpumap, online, flags);
+    return nodeGetCPUMap(cpumap, online, flags);
 }
 
 static int
@@ -1487,7 +1487,7 @@ vzNodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
                      int *nparams,
                      unsigned int flags)
 {
-    return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags);
+    return nodeGetMemoryStats(cellNum, params, nparams, flags);
 }
 
 static int
index dc0a44945b9af6386203d846007b5c06c84abbed..a330c062f508e7c9c50716ac00a6502cc6ffb883 100644 (file)
@@ -1151,7 +1151,7 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
     PRL_RESULT pret;
     int ret = -1;
 
-    if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
+    if ((hostcpus = nodeGetCPUCount()) < 0)
         goto cleanup;
 
     /* get number of CPUs */
index 9eab2f689c93a817a3d9f4f1223fa7aa9807da81..b1ab2388265e618b85c74d12f106337b8e6f4459 100644 (file)
@@ -24,8 +24,7 @@ main(void)
 #else
 
 static int
-linuxTestCompareFiles(char *sysfs_prefix,
-                      const char *cpuinfofile,
+linuxTestCompareFiles(const char *cpuinfofile,
                       virArch arch,
                       const char *outputfile)
 {
@@ -42,7 +41,7 @@ linuxTestCompareFiles(char *sysfs_prefix,
     }
 
     memset(&nodeinfo, 0, sizeof(nodeinfo));
-    if (linuxNodeInfoCPUPopulate(sysfs_prefix, cpuinfo, arch, &nodeinfo) < 0) {
+    if (linuxNodeInfoCPUPopulate(cpuinfo, arch, &nodeinfo) < 0) {
         if (virTestGetDebug()) {
             if (virGetLastError())
                 VIR_TEST_DEBUG("\n%s\n", virGetLastErrorMessage());
@@ -175,7 +174,9 @@ linuxTestNodeInfo(const void *opaque)
         goto cleanup;
     }
 
-    result = linuxTestCompareFiles(sysfs_prefix, cpuinfo, data->arch, output);
+    linuxNodeInfoSetSysFSSystemPath(sysfs_prefix);
+    result = linuxTestCompareFiles(cpuinfo, data->arch, output);
+    linuxNodeInfoSetSysFSSystemPath(NULL);
 
  cleanup:
     VIR_FREE(cpuinfo);
index 9578e3aef51b2f8593684433408edd6a9a4a083b..28db6b760aa30d172d2bd5371d232a27be52aa71 100644 (file)
@@ -649,8 +649,8 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED)
         goto cleanup;
     }
 
-    if (nodeGetCPUCount(NULL) != EXPECTED_NCPUS) {
-        fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount(NULL));
+    if (nodeGetCPUCount() != EXPECTED_NCPUS) {
+        fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount());
         goto cleanup;
     }