render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7a3408
From 2260b45485085ceacb2d07554165289b275b816b Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <2260b45485085ceacb2d07554165289b275b816b@dist-git>
7a3408
From: John Ferlan <jferlan@redhat.com>
7a3408
Date: Wed, 5 Aug 2015 18:18:13 +0200
7a3408
Subject: [PATCH] nodeinfo: Add sysfs_prefix to nodeCapsInitNUMA
7a3408
7a3408
Add the sysfs_prefix argument to the call to allow for setting the
7a3408
path for tests to something other than SYSFS_CPU_PATH which is a
7a3408
derivative of SYSFS_SYSTEM_PATH
7a3408
7a3408
Use cpupath for nodeCapsInitNUMAFake and remove SYSFS_CPU_PATH
7a3408
7a3408
(cherry picked from commit b97b30480d0fc529a9ea27b1c8b3cb0b120ea1e3)
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/lxc/lxc_conf.c           |  2 +-
7a3408
 src/nodeinfo.c               | 35 +++++++++++++++++++++++------------
7a3408
 src/nodeinfo.h               |  2 +-
7a3408
 src/openvz/openvz_conf.c     |  2 +-
7a3408
 src/phyp/phyp_driver.c       |  2 +-
7a3408
 src/qemu/qemu_capabilities.c |  2 +-
7a3408
 src/uml/uml_conf.c           |  2 +-
7a3408
 src/vbox/vbox_common.c       |  2 +-
7a3408
 src/vmware/vmware_conf.c     |  2 +-
7a3408
 src/vz/vz_driver.c           |  2 +-
7a3408
 10 files changed, 32 insertions(+), 21 deletions(-)
7a3408
7a3408
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
7a3408
index c393cb5..b689b92 100644
7a3408
--- a/src/lxc/lxc_conf.c
7a3408
+++ b/src/lxc/lxc_conf.c
7a3408
@@ -77,7 +77,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
7a3408
      * unexpected failures. We don't want to break the lxc
7a3408
      * driver in this scenario, so log errors & carry on
7a3408
      */
7a3408
-    if (nodeCapsInitNUMA(caps) < 0) {
7a3408
+    if (nodeCapsInitNUMA(NULL, caps) < 0) {
7a3408
         virCapabilitiesFreeNUMAInfo(caps);
7a3408
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
7a3408
     }
7a3408
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
7a3408
index 2d715fd..a71d05e 100644
7a3408
--- a/src/nodeinfo.c
7a3408
+++ b/src/nodeinfo.c
7a3408
@@ -283,7 +283,6 @@ freebsdNodeGetMemoryStats(virNodeMemoryStatsPtr params,
7a3408
 #ifdef __linux__
7a3408
 # define CPUINFO_PATH "/proc/cpuinfo"
7a3408
 # define SYSFS_SYSTEM_PATH "/sys/devices/system"
7a3408
-# define SYSFS_CPU_PATH SYSFS_SYSTEM_PATH"/cpu"
7a3408
 # define PROCSTAT_PATH "/proc/stat"
7a3408
 # define MEMINFO_PATH "/proc/meminfo"
7a3408
 # define SYSFS_MEMORY_SHARED_PATH "/sys/kernel/mm/ksm"
7a3408
@@ -1660,7 +1659,9 @@ nodeGetCPUMap(const char *sysfs_prefix,
7a3408
 }
7a3408
 
7a3408
 static int
7a3408
-nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
7a3408
+nodeCapsInitNUMAFake(const char *prefix,
7a3408
+                     const char *cpupath ATTRIBUTE_UNUSED,
7a3408
+                     virCapsPtr caps ATTRIBUTE_UNUSED)
7a3408
 {
7a3408
     virNodeInfo nodeinfo;
7a3408
     virCapsHostNUMACellCPUPtr cpus;
7a3408
@@ -1669,7 +1670,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
7a3408
     int id, cid;
7a3408
     int onlinecpus ATTRIBUTE_UNUSED;
7a3408
 
7a3408
-    if (nodeGetInfo(NULL, &nodeinfo) < 0)
7a3408
+    if (nodeGetInfo(prefix, &nodeinfo) < 0)
7a3408
         return -1;
7a3408
 
7a3408
     ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
7a3408
@@ -1683,7 +1684,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
7a3408
         for (c = 0; c < nodeinfo.cores; c++) {
7a3408
             for (t = 0; t < nodeinfo.threads; t++) {
7a3408
 #ifdef __linux__
7a3408
-                if (virNodeGetCpuValue(SYSFS_CPU_PATH, id, "online", 1)) {
7a3408
+                if (virNodeGetCpuValue(cpupath, id, "online", 1)) {
7a3408
 #endif
7a3408
                     cpus[cid].id = id;
7a3408
                     cpus[cid].socket_id = s;
7a3408
@@ -1810,26 +1811,27 @@ nodeGetMemoryFake(unsigned long long *mem,
7a3408
 
7a3408
 /* returns 1 on success, 0 if the detection failed and -1 on hard error */
7a3408
 static int
7a3408
-virNodeCapsFillCPUInfo(int cpu_id ATTRIBUTE_UNUSED,
7a3408
+virNodeCapsFillCPUInfo(const char *cpupath ATTRIBUTE_UNUSED,
7a3408
+                       int cpu_id ATTRIBUTE_UNUSED,
7a3408
                        virCapsHostNUMACellCPUPtr cpu ATTRIBUTE_UNUSED)
7a3408
 {
7a3408
 #ifdef __linux__
7a3408
     int tmp;
7a3408
     cpu->id = cpu_id;
7a3408
 
7a3408
-    if ((tmp = virNodeGetCpuValue(SYSFS_CPU_PATH, cpu_id,
7a3408
+    if ((tmp = virNodeGetCpuValue(cpupath, cpu_id,
7a3408
                                   "topology/physical_package_id", -1)) < 0)
7a3408
         return 0;
7a3408
 
7a3408
     cpu->socket_id = tmp;
7a3408
 
7a3408
-    if ((tmp = virNodeGetCpuValue(SYSFS_CPU_PATH, cpu_id,
7a3408
+    if ((tmp = virNodeGetCpuValue(cpupath, cpu_id,
7a3408
                                   "topology/core_id", -1)) < 0)
7a3408
         return 0;
7a3408
 
7a3408
     cpu->core_id = tmp;
7a3408
 
7a3408
-    if (!(cpu->siblings = virNodeGetSiblingsList(SYSFS_CPU_PATH, cpu_id)))
7a3408
+    if (!(cpu->siblings = virNodeGetSiblingsList(cpupath, cpu_id)))
7a3408
         return -1;
7a3408
 
7a3408
     return 0;
7a3408
@@ -1917,8 +1919,11 @@ virNodeCapsGetPagesInfo(int node,
7a3408
 }
7a3408
 
7a3408
 int
7a3408
-nodeCapsInitNUMA(virCapsPtr caps)
7a3408
+nodeCapsInitNUMA(const char *sysfs_prefix,
7a3408
+                 virCapsPtr caps)
7a3408
 {
7a3408
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
7a3408
+    char *cpupath;
7a3408
     int n;
7a3408
     unsigned long long memory;
7a3408
     virCapsHostNUMACellCPUPtr cpus = NULL;
7a3408
@@ -1933,8 +1938,13 @@ nodeCapsInitNUMA(virCapsPtr caps)
7a3408
     bool topology_failed = false;
7a3408
     int max_node;
7a3408
 
7a3408
-    if (!virNumaIsAvailable())
7a3408
-        return nodeCapsInitNUMAFake(caps);
7a3408
+    if (virAsprintf(&cpupath, "%s/cpu", prefix) < 0)
7a3408
+        return -1;
7a3408
+
7a3408
+    if (!virNumaIsAvailable()) {
7a3408
+        ret = nodeCapsInitNUMAFake(prefix, cpupath, caps);
7a3408
+        goto cleanup;
7a3408
+    }
7a3408
 
7a3408
     if ((max_node = virNumaGetMaxNode()) < 0)
7a3408
         goto cleanup;
7a3408
@@ -1955,7 +1965,7 @@ nodeCapsInitNUMA(virCapsPtr caps)
7a3408
 
7a3408
         for (i = 0; i < virBitmapSize(cpumap); i++) {
7a3408
             if (virBitmapIsBitSet(cpumap, i)) {
7a3408
-                if (virNodeCapsFillCPUInfo(i, cpus + cpu++) < 0) {
7a3408
+                if (virNodeCapsFillCPUInfo(cpupath, i, cpus + cpu++) < 0) {
7a3408
                     topology_failed = true;
7a3408
                     virResetLastError();
7a3408
                 }
7a3408
@@ -1995,6 +2005,7 @@ nodeCapsInitNUMA(virCapsPtr caps)
7a3408
     VIR_FREE(cpus);
7a3408
     VIR_FREE(siblings);
7a3408
     VIR_FREE(pageinfo);
7a3408
+    VIR_FREE(cpupath);
7a3408
     return ret;
7a3408
 }
7a3408
 
7a3408
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
7a3408
index ec53769..b28aaab 100644
7a3408
--- a/src/nodeinfo.h
7a3408
+++ b/src/nodeinfo.h
7a3408
@@ -27,7 +27,7 @@
7a3408
 # include "capabilities.h"
7a3408
 
7a3408
 int nodeGetInfo(const char *sysfs_prefix, virNodeInfoPtr nodeinfo);
7a3408
-int nodeCapsInitNUMA(virCapsPtr caps);
7a3408
+int nodeCapsInitNUMA(const char *sysfs_prefix, virCapsPtr caps);
7a3408
 
7a3408
 int nodeGetCPUStats(int cpuNum,
7a3408
                     virNodeCPUStatsPtr params,
7a3408
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
7a3408
index a4c5c31..db0a9a7 100644
7a3408
--- a/src/openvz/openvz_conf.c
7a3408
+++ b/src/openvz/openvz_conf.c
7a3408
@@ -175,7 +175,7 @@ virCapsPtr openvzCapsInit(void)
7a3408
                                    false, false)) == NULL)
7a3408
         goto no_memory;
7a3408
 
7a3408
-    if (nodeCapsInitNUMA(caps) < 0)
7a3408
+    if (nodeCapsInitNUMA(NULL, caps) < 0)
7a3408
         goto no_memory;
7a3408
 
7a3408
     if ((guest = virCapabilitiesAddGuest(caps,
7a3408
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
7a3408
index ec0fde3..54dec70 100644
7a3408
--- a/src/phyp/phyp_driver.c
7a3408
+++ b/src/phyp/phyp_driver.c
7a3408
@@ -335,7 +335,7 @@ phypCapsInit(void)
7a3408
      * unexpected failures. We don't want to break the QEMU
7a3408
      * driver in this scenario, so log errors & carry on
7a3408
      */
7a3408
-    if (nodeCapsInitNUMA(caps) < 0) {
7a3408
+    if (nodeCapsInitNUMA(NULL, caps) < 0) {
7a3408
         virCapabilitiesFreeNUMAInfo(caps);
7a3408
         VIR_WARN
7a3408
             ("Failed to query host NUMA topology, disabling NUMA capabilities");
7a3408
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
7a3408
index 39954bc..be5384f 100644
7a3408
--- a/src/qemu/qemu_capabilities.c
7a3408
+++ b/src/qemu/qemu_capabilities.c
7a3408
@@ -1024,7 +1024,7 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
7a3408
      * unexpected failures. We don't want to break the QEMU
7a3408
      * driver in this scenario, so log errors & carry on
7a3408
      */
7a3408
-    if (nodeCapsInitNUMA(caps) < 0) {
7a3408
+    if (nodeCapsInitNUMA(NULL, caps) < 0) {
7a3408
         virCapabilitiesFreeNUMAInfo(caps);
7a3408
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
7a3408
     }
7a3408
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
7a3408
index 86fbecc..90deb2a 100644
7a3408
--- a/src/uml/uml_conf.c
7a3408
+++ b/src/uml/uml_conf.c
7a3408
@@ -65,7 +65,7 @@ virCapsPtr umlCapsInit(void)
7a3408
      * unexpected failures. We don't want to break the QEMU
7a3408
      * driver in this scenario, so log errors & carry on
7a3408
      */
7a3408
-    if (nodeCapsInitNUMA(caps) < 0) {
7a3408
+    if (nodeCapsInitNUMA(NULL, caps) < 0) {
7a3408
         virCapabilitiesFreeNUMAInfo(caps);
7a3408
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
7a3408
     }
7a3408
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
7a3408
index 5615df5..91a61f8 100644
7a3408
--- a/src/vbox/vbox_common.c
7a3408
+++ b/src/vbox/vbox_common.c
7a3408
@@ -318,7 +318,7 @@ static virCapsPtr vboxCapsInit(void)
7a3408
                                    false, false)) == NULL)
7a3408
         goto no_memory;
7a3408
 
7a3408
-    if (nodeCapsInitNUMA(caps) < 0)
7a3408
+    if (nodeCapsInitNUMA(NULL, caps) < 0)
7a3408
         goto no_memory;
7a3408
 
7a3408
     if ((guest = virCapabilitiesAddGuest(caps,
7a3408
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
7a3408
index 5b249f8..21cf333 100644
7a3408
--- a/src/vmware/vmware_conf.c
7a3408
+++ b/src/vmware/vmware_conf.c
7a3408
@@ -68,7 +68,7 @@ vmwareCapsInit(void)
7a3408
                                    false, false)) == NULL)
7a3408
         goto error;
7a3408
 
7a3408
-    if (nodeCapsInitNUMA(caps) < 0)
7a3408
+    if (nodeCapsInitNUMA(NULL, caps) < 0)
7a3408
         goto error;
7a3408
 
7a3408
     /* i686 guests are always supported */
7a3408
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
7a3408
index 61d0d62..06d9d03 100644
7a3408
--- a/src/vz/vz_driver.c
7a3408
+++ b/src/vz/vz_driver.c
7a3408
@@ -91,7 +91,7 @@ vzBuildCapabilities(void)
7a3408
                                    false, false)) == NULL)
7a3408
         return NULL;
7a3408
 
7a3408
-    if (nodeCapsInitNUMA(caps) < 0)
7a3408
+    if (nodeCapsInitNUMA(NULL, caps) < 0)
7a3408
         goto error;
7a3408
 
7a3408
     if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
7a3408
-- 
7a3408
2.5.0
7a3408