]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodeinfo: Add sysfs_prefix to nodeCapsInitNUMA
authorJohn Ferlan <jferlan@redhat.com>
Tue, 7 Jul 2015 21:22:28 +0000 (17:22 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 13 Jul 2015 19:59:32 +0000 (15:59 -0400)
Add the sysfs_prefix argument to the call to allow for setting the
path for tests to something other than SYSFS_CPU_PATH which is a
derivative of SYSFS_SYSTEM_PATH

Use cpupath for nodeCapsInitNUMAFake and remove SYSFS_CPU_PATH

src/lxc/lxc_conf.c
src/nodeinfo.c
src/nodeinfo.h
src/openvz/openvz_conf.c
src/phyp/phyp_driver.c
src/qemu/qemu_capabilities.c
src/uml/uml_conf.c
src/vbox/vbox_common.c
src/vmware/vmware_conf.c
src/vz/vz_driver.c

index c393cb59d40296246199c03fbd8bfd2bd1f1858d..b689b92d95f2eecc34d78d7b26d121652663057d 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(caps) < 0) {
+    if (nodeCapsInitNUMA(NULL, caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
index 2d715fdb722ca64a8b0033d85d08247923225510..a71d05ef554bb99d811822096174ef0f2b2cd93d 100644 (file)
@@ -283,7 +283,6 @@ freebsdNodeGetMemoryStats(virNodeMemoryStatsPtr params,
 #ifdef __linux__
 # define CPUINFO_PATH "/proc/cpuinfo"
 # define SYSFS_SYSTEM_PATH "/sys/devices/system"
-# define SYSFS_CPU_PATH SYSFS_SYSTEM_PATH"/cpu"
 # define PROCSTAT_PATH "/proc/stat"
 # define MEMINFO_PATH "/proc/meminfo"
 # define SYSFS_MEMORY_SHARED_PATH "/sys/kernel/mm/ksm"
@@ -1660,7 +1659,9 @@ nodeGetCPUMap(const char *sysfs_prefix,
 }
 
 static int
-nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
+nodeCapsInitNUMAFake(const char *prefix,
+                     const char *cpupath ATTRIBUTE_UNUSED,
+                     virCapsPtr caps ATTRIBUTE_UNUSED)
 {
     virNodeInfo nodeinfo;
     virCapsHostNUMACellCPUPtr cpus;
@@ -1669,7 +1670,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
     int id, cid;
     int onlinecpus ATTRIBUTE_UNUSED;
 
-    if (nodeGetInfo(NULL, &nodeinfo) < 0)
+    if (nodeGetInfo(prefix, &nodeinfo) < 0)
         return -1;
 
     ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
@@ -1683,7 +1684,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
         for (c = 0; c < nodeinfo.cores; c++) {
             for (t = 0; t < nodeinfo.threads; t++) {
 #ifdef __linux__
-                if (virNodeGetCpuValue(SYSFS_CPU_PATH, id, "online", 1)) {
+                if (virNodeGetCpuValue(cpupath, id, "online", 1)) {
 #endif
                     cpus[cid].id = id;
                     cpus[cid].socket_id = s;
@@ -1810,26 +1811,27 @@ nodeGetMemoryFake(unsigned long long *mem,
 
 /* returns 1 on success, 0 if the detection failed and -1 on hard error */
 static int
-virNodeCapsFillCPUInfo(int cpu_id ATTRIBUTE_UNUSED,
+virNodeCapsFillCPUInfo(const char *cpupath ATTRIBUTE_UNUSED,
+                       int cpu_id ATTRIBUTE_UNUSED,
                        virCapsHostNUMACellCPUPtr cpu ATTRIBUTE_UNUSED)
 {
 #ifdef __linux__
     int tmp;
     cpu->id = cpu_id;
 
-    if ((tmp = virNodeGetCpuValue(SYSFS_CPU_PATH, cpu_id,
+    if ((tmp = virNodeGetCpuValue(cpupath, cpu_id,
                                   "topology/physical_package_id", -1)) < 0)
         return 0;
 
     cpu->socket_id = tmp;
 
-    if ((tmp = virNodeGetCpuValue(SYSFS_CPU_PATH, cpu_id,
+    if ((tmp = virNodeGetCpuValue(cpupath, cpu_id,
                                   "topology/core_id", -1)) < 0)
         return 0;
 
     cpu->core_id = tmp;
 
-    if (!(cpu->siblings = virNodeGetSiblingsList(SYSFS_CPU_PATH, cpu_id)))
+    if (!(cpu->siblings = virNodeGetSiblingsList(cpupath, cpu_id)))
         return -1;
 
     return 0;
@@ -1917,8 +1919,11 @@ virNodeCapsGetPagesInfo(int node,
 }
 
 int
-nodeCapsInitNUMA(virCapsPtr caps)
+nodeCapsInitNUMA(const char *sysfs_prefix,
+                 virCapsPtr caps)
 {
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
+    char *cpupath;
     int n;
     unsigned long long memory;
     virCapsHostNUMACellCPUPtr cpus = NULL;
@@ -1933,8 +1938,13 @@ nodeCapsInitNUMA(virCapsPtr caps)
     bool topology_failed = false;
     int max_node;
 
-    if (!virNumaIsAvailable())
-        return nodeCapsInitNUMAFake(caps);
+    if (virAsprintf(&cpupath, "%s/cpu", prefix) < 0)
+        return -1;
+
+    if (!virNumaIsAvailable()) {
+        ret = nodeCapsInitNUMAFake(prefix, cpupath, caps);
+        goto cleanup;
+    }
 
     if ((max_node = virNumaGetMaxNode()) < 0)
         goto cleanup;
@@ -1955,7 +1965,7 @@ nodeCapsInitNUMA(virCapsPtr caps)
 
         for (i = 0; i < virBitmapSize(cpumap); i++) {
             if (virBitmapIsBitSet(cpumap, i)) {
-                if (virNodeCapsFillCPUInfo(i, cpus + cpu++) < 0) {
+                if (virNodeCapsFillCPUInfo(cpupath, i, cpus + cpu++) < 0) {
                     topology_failed = true;
                     virResetLastError();
                 }
@@ -1995,6 +2005,7 @@ nodeCapsInitNUMA(virCapsPtr caps)
     VIR_FREE(cpus);
     VIR_FREE(siblings);
     VIR_FREE(pageinfo);
+    VIR_FREE(cpupath);
     return ret;
 }
 
index ec537697e75b55a02003d07c4755405cc6699edb..b28aaab2ea625dbdf20052334bd3e576dcd5e111 100644 (file)
@@ -27,7 +27,7 @@
 # include "capabilities.h"
 
 int nodeGetInfo(const char *sysfs_prefix, virNodeInfoPtr nodeinfo);
-int nodeCapsInitNUMA(virCapsPtr caps);
+int nodeCapsInitNUMA(const char *sysfs_prefix, virCapsPtr caps);
 
 int nodeGetCPUStats(int cpuNum,
                     virNodeCPUStatsPtr params,
index a4c5c31dfdd67abe05225c191ec38f0cac637798..db0a9a777620ddee57ba03010f5100b423716874 100644 (file)
@@ -175,7 +175,7 @@ virCapsPtr openvzCapsInit(void)
                                    false, false)) == NULL)
         goto no_memory;
 
-    if (nodeCapsInitNUMA(caps) < 0)
+    if (nodeCapsInitNUMA(NULL, caps) < 0)
         goto no_memory;
 
     if ((guest = virCapabilitiesAddGuest(caps,
index ec0fde3c1e95b7ec468c14e8bd0a641968764a0a..54dec70b7e7ea0175a97e26cd691f8b355f6266e 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(caps) < 0) {
+    if (nodeCapsInitNUMA(NULL, caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN
             ("Failed to query host NUMA topology, disabling NUMA capabilities");
index 81e680539fe112688f7903cb4973ea435cb0f153..d8cb32d777617904b025467209a01ba9c1d5d9d4 100644 (file)
@@ -1024,7 +1024,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(caps) < 0) {
+    if (nodeCapsInitNUMA(NULL, caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
index 86fbecc584c107b751d56e9675b9f6576882c010..90deb2a2443353a8c62942fab015e082f4cc3fcd 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(caps) < 0) {
+    if (nodeCapsInitNUMA(NULL, caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
index 5615df539117b898a3a00521e55697390bc31222..91a61f8854c5aa3b48cb693f9ef7ba0def4c2c83 100644 (file)
@@ -318,7 +318,7 @@ static virCapsPtr vboxCapsInit(void)
                                    false, false)) == NULL)
         goto no_memory;
 
-    if (nodeCapsInitNUMA(caps) < 0)
+    if (nodeCapsInitNUMA(NULL, caps) < 0)
         goto no_memory;
 
     if ((guest = virCapabilitiesAddGuest(caps,
index 5b249f83de8e21cee3ec1cbf7b84b1977a6e5443..21cf333a4f3088d7a29c873068254e5f12235516 100644 (file)
@@ -68,7 +68,7 @@ vmwareCapsInit(void)
                                    false, false)) == NULL)
         goto error;
 
-    if (nodeCapsInitNUMA(caps) < 0)
+    if (nodeCapsInitNUMA(NULL, caps) < 0)
         goto error;
 
     /* i686 guests are always supported */
index 254fcbd4d27a5bf8a509c94e734d84e4d4b6f0f3..8fa79578e3651453fb2605f314d9b1f4a2f1013f 100644 (file)
@@ -122,7 +122,7 @@ vzBuildCapabilities(void)
                                    false, false)) == NULL)
         return NULL;
 
-    if (nodeCapsInitNUMA(caps) < 0)
+    if (nodeCapsInitNUMA(NULL, caps) < 0)
         goto error;
 
     for (i = 0; i < 2; i++)