[libvirt] [PATCH 0/9] Add sysfs_prefix to nodeinfo.c API's

This series adds/processes a sysfs_prefix for the nodeinfo.c API's. Although the nodeinfotest.c passes a local test directory path, it was never used. This was all brought to light by patch 9 in this series which is essentially Kothapally Madhu Pavan's v3 patch: http://www.redhat.com/archives/libvir-list/2015-June/msg00395.html With the adjustment to call nodeGetPresentCPUBitmap and virNodeParseNode with the sysfs prefix. Without the first 5 patches, the patch as posted caused nodeinfotest failure in my test environment which doesn't have the "larger" environments that the test tried to set up because the test environment used my present mask file. John Ferlan (8): nodeinfo: Introduce local linuxGetCPUPresentPath nodeinfo: Add sysfs_prefix to nodeGetCPUCount nodeinfo: Add sysfs_prefix to nodeGetPresentCPUBitmap nodeinfo: Add sysfs_prefix to nodeGetCPUBitmap nodeinfo: Add sysfs_prefix to nodeGetCPUMap nodeinfo: Add sysfs_prefix to nodeGetInfo nodeinfo: Add sysfs_prefix to nodeCapsInitNUMA nodeinfo: Add sysfs_prefix to nodeGetMemoryStats Kothapally Madhu Pavan (1): nodeinfo: fix to parse present cpus rather than possible cpus src/bhyve/bhyve_capabilities.c | 2 +- src/bhyve/bhyve_driver.c | 6 +- src/lxc/lxc_conf.c | 2 +- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_driver.c | 6 +- src/nodeinfo.c | 159 +++++++++++++++++++++++++++++------------ src/nodeinfo.h | 16 +++-- src/openvz/openvz_conf.c | 4 +- src/openvz/openvz_driver.c | 6 +- src/phyp/phyp_driver.c | 2 +- src/qemu/qemu_capabilities.c | 4 +- src/qemu/qemu_driver.c | 16 ++--- src/qemu/qemu_process.c | 2 +- src/uml/uml_conf.c | 2 +- src/uml/uml_driver.c | 6 +- src/util/vircgroup.c | 2 +- src/vbox/vbox_common.c | 4 +- src/vmware/vmware_conf.c | 2 +- src/vz/vz_driver.c | 10 +-- src/vz/vz_sdk.c | 2 +- tests/vircgrouptest.c | 4 +- 21 files changed, 166 insertions(+), 93 deletions(-) -- 2.1.0

The API will print the path to the /cpu/present file using the sysfs_prefix. NB: This is setup for future patches which will allow local/test sysfs paths. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/nodeinfo.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 2fafe2d..f3e3108 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1,7 +1,7 @@ /* * nodeinfo.c: Helper routines for OS specific node information * - * Copyright (C) 2006-2008, 2010-2014 Red Hat, Inc. + * Copyright (C) 2006-2008, 2010-2015 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -944,6 +944,16 @@ linuxNodeGetMemoryStats(FILE *meminfo, return ret; } +static char * +linuxGetCPUPresentPath(const char *sysfs_prefix) +{ + const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH; + char *path = NULL; + + if (virAsprintf(&path, "%s/cpu/present", prefix) < 0) + return NULL; + return path; +} /* Determine the maximum cpu id from a Linux sysfs cpu/present file. */ static int @@ -1193,27 +1203,34 @@ nodeGetCPUCount(void) * that such kernels also lack hotplug, and therefore cpu/cpuNN * will be consecutive. */ + char *present_path = NULL; char *cpupath = NULL; - int ncpu; + int ncpu = -1; + + if (!(present_path = linuxGetCPUPresentPath(NULL))) + return -1; - if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/present")) { - ncpu = linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present"); + if (virFileExists(present_path)) { + ncpu = linuxParseCPUmax(present_path); } else if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/cpu0")) { ncpu = 0; do { ncpu++; VIR_FREE(cpupath); if (virAsprintf(&cpupath, "%s/cpu/cpu%d", - SYSFS_SYSTEM_PATH, ncpu) < 0) - return -1; + SYSFS_SYSTEM_PATH, ncpu) < 0) { + ncpu = -1; + goto cleanup; + } } while (virFileExists(cpupath)); } else { /* no cpu/cpu0: we give up */ virReportError(VIR_ERR_NO_SUPPORT, "%s", _("host cpu counting not supported on this node")); - return -1; } + cleanup: + VIR_FREE(present_path); VIR_FREE(cpupath); return ncpu; #elif defined(__FreeBSD__) || defined(__APPLE__) @@ -1229,13 +1246,21 @@ virBitmapPtr nodeGetPresentCPUBitmap(void) { int max_present; +#ifdef __linux__ + char *present_path = NULL; + virBitmapPtr bitmap = NULL; +#endif if ((max_present = nodeGetCPUCount()) < 0) return NULL; #ifdef __linux__ - if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/present")) - return linuxParseCPUmap(max_present, SYSFS_SYSTEM_PATH "/cpu/present"); + if (!(present_path = linuxGetCPUPresentPath(NULL))) + return NULL; + if (virFileExists(present_path)) + bitmap = linuxParseCPUmap(max_present, present_path); + VIR_FREE(present_path); + return bitmap; #endif virReportError(VIR_ERR_NO_SUPPORT, "%s", _("non-continuous host cpu numbers not implemented on this platform")); -- 2.1.0

Add the sysfs_prefix argument to the call to allow for setting the path for tests to something other than SYSFS_SYSTEM_PATH. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/lxc/lxc_controller.c | 2 +- src/nodeinfo.c | 20 +++++++++++++------- src/nodeinfo.h | 2 +- src/qemu/qemu_driver.c | 10 +++++----- src/qemu/qemu_process.c | 2 +- src/vz/vz_driver.c | 2 +- src/vz/vz_sdk.c | 2 +- tests/vircgrouptest.c | 4 ++-- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 828b8a8..27e2e3a 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -705,7 +705,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()) < 0) + if ((hostcpus = nodeGetCPUCount(NULL)) < 0) return -1; if (maxcpu > hostcpus) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index f3e3108..409f922 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1195,7 +1195,7 @@ int nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED, } int -nodeGetCPUCount(void) +nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED) { #if defined(__linux__) /* To support older kernels that lack cpu/present, such as 2.6.18 @@ -1204,21 +1204,27 @@ nodeGetCPUCount(void) * 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(NULL))) + if (!(present_path = linuxGetCPUPresentPath(prefix))) return -1; if (virFileExists(present_path)) { ncpu = linuxParseCPUmax(present_path); - } else if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/cpu0")) { + goto cleanup; + } + + if (virAsprintf(&cpupath, "%s/cpu/cpu0", prefix) < 0) + goto cleanup; + if (virFileExists(cpupath)) { ncpu = 0; do { ncpu++; VIR_FREE(cpupath); if (virAsprintf(&cpupath, "%s/cpu/cpu%d", - SYSFS_SYSTEM_PATH, ncpu) < 0) { + prefix, ncpu) < 0) { ncpu = -1; goto cleanup; } @@ -1251,7 +1257,7 @@ nodeGetPresentCPUBitmap(void) virBitmapPtr bitmap = NULL; #endif - if ((max_present = nodeGetCPUCount()) < 0) + if ((max_present = nodeGetCPUCount(NULL)) < 0) return NULL; #ifdef __linux__ @@ -1274,7 +1280,7 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED) virBitmapPtr cpumap; int present; - present = nodeGetCPUCount(); + present = nodeGetCPUCount(NULL); if (present < 0) return NULL; @@ -1621,7 +1627,7 @@ nodeGetCPUMap(unsigned char **cpumap, virCheckFlags(0, -1); if (!cpumap && !online) - return nodeGetCPUCount(); + return nodeGetCPUCount(NULL); if (!(cpus = nodeGetCPUBitmap(&maxpresent))) goto cleanup; diff --git a/src/nodeinfo.h b/src/nodeinfo.h index 047bd5c..4f9699e 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -45,7 +45,7 @@ int nodeGetMemory(unsigned long long *mem, virBitmapPtr nodeGetPresentCPUBitmap(void); virBitmapPtr nodeGetCPUBitmap(int *max_id); -int nodeGetCPUCount(void); +int nodeGetCPUCount(const char *sysfs_prefix); int nodeGetMemoryParameters(virTypedParameterPtr params, int *nparams, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4cfae03..6fbe68a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1422,7 +1422,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo, size_t i, v; qemuDomainObjPrivatePtr priv = vm->privateData; - if ((hostcpus = nodeGetCPUCount()) < 0) + if ((hostcpus = nodeGetCPUCount(NULL)) < 0) return -1; if (priv->vcpupids == NULL) { @@ -5237,7 +5237,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom, if (!(def = virDomainObjGetOneDef(vm, flags))) goto cleanup; - if ((hostcpus = nodeGetCPUCount()) < 0) + if ((hostcpus = nodeGetCPUCount(NULL)) < 0) goto cleanup; if (!(allcpumap = virBitmapNew(hostcpus))) @@ -5425,7 +5425,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom, if (!(def = virDomainObjGetOneDef(vm, flags))) goto cleanup; - if ((hostcpus = nodeGetCPUCount()) < 0) + if ((hostcpus = nodeGetCPUCount(NULL)) < 0) goto cleanup; if (def->cputune.emulatorpin) { @@ -5612,7 +5612,7 @@ qemuDomainGetIOThreadsLive(virQEMUDriverPtr driver, goto endjob; } - if ((hostcpus = nodeGetCPUCount()) < 0) + if ((hostcpus = nodeGetCPUCount(NULL)) < 0) goto endjob; if (VIR_ALLOC_N(info_ret, niothreads) < 0) @@ -5672,7 +5672,7 @@ qemuDomainGetIOThreadsConfig(virDomainDefPtr targetDef, if (targetDef->iothreads == 0) return 0; - if ((hostcpus = nodeGetCPUCount()) < 0) + if ((hostcpus = nodeGetCPUCount(NULL)) < 0) goto cleanup; if (VIR_ALLOC_N(info_ret, targetDef->iothreads) < 0) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ba84182..4c1b8c1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2322,7 +2322,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()) < 0) + if ((hostcpus = nodeGetCPUCount(NULL)) < 0) goto cleanup; if (hostcpus > QEMUD_CPUMASK_LEN) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 8c3c818..06fb579 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -820,7 +820,7 @@ vzDomainGetVcpus(virDomainPtr domain, goto cleanup; } - if ((hostcpus = nodeGetCPUCount()) < 0) + if ((hostcpus = nodeGetCPUCount(NULL)) < 0) goto cleanup; maxcpu = maplen * 8; diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 1b8298c..be43d53 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -1141,7 +1141,7 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom, PRL_RESULT pret; int ret = -1; - if ((hostcpus = nodeGetCPUCount()) < 0) + if ((hostcpus = nodeGetCPUCount(NULL)) < 0) goto cleanup; /* get number of CPUs */ diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index dddf33a..7a87640 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -649,8 +649,8 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED) goto cleanup; } - if (nodeGetCPUCount() != EXPECTED_NCPUS) { - fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount()); + if (nodeGetCPUCount(NULL) != EXPECTED_NCPUS) { + fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount(NULL)); goto cleanup; } -- 2.1.0

Add the sysfs_prefix argument to the call to allow for setting the path for tests to something other than SYSFS_SYSTEM_PATH. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/nodeinfo.c | 7 ++++--- src/nodeinfo.h | 2 +- src/util/vircgroup.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 409f922..34de720 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1249,19 +1249,20 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED) } virBitmapPtr -nodeGetPresentCPUBitmap(void) +nodeGetPresentCPUBitmap(const char *sysfs_prefix) { int max_present; #ifdef __linux__ char *present_path = NULL; virBitmapPtr bitmap = NULL; #endif + const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH; - if ((max_present = nodeGetCPUCount(NULL)) < 0) + if ((max_present = nodeGetCPUCount(prefix)) < 0) return NULL; #ifdef __linux__ - if (!(present_path = linuxGetCPUPresentPath(NULL))) + if (!(present_path = linuxGetCPUPresentPath(prefix))) return NULL; if (virFileExists(present_path)) bitmap = linuxParseCPUmap(max_present, present_path); diff --git a/src/nodeinfo.h b/src/nodeinfo.h index 4f9699e..3ef206b 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -43,7 +43,7 @@ int nodeGetCellsFreeMemory(unsigned long long *freeMems, int nodeGetMemory(unsigned long long *mem, unsigned long long *freeMem); -virBitmapPtr nodeGetPresentCPUBitmap(void); +virBitmapPtr nodeGetPresentCPUBitmap(const char *sysfs_prefix); virBitmapPtr nodeGetCPUBitmap(int *max_id); int nodeGetCPUCount(const char *sysfs_prefix); diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index cbe0234..0ef2d29 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3043,7 +3043,7 @@ virCgroupGetPercpuStats(virCgroupPtr group, } /* To parse account file, we need to know how many cpus are present. */ - if (!(cpumap = nodeGetPresentCPUBitmap())) + if (!(cpumap = nodeGetPresentCPUBitmap(NULL))) return rv; total_cpus = virBitmapSize(cpumap); -- 2.1.0

Add the sysfs_prefix argument to the call to allow for setting the path for tests to something other than SYSFS_SYSTEM_PATH. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/nodeinfo.c | 24 ++++++++++++++++-------- src/nodeinfo.h | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 34de720..75e0a02 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1275,29 +1275,35 @@ nodeGetPresentCPUBitmap(const char *sysfs_prefix) } virBitmapPtr -nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED) +nodeGetCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED, + int *max_id ATTRIBUTE_UNUSED) { #ifdef __linux__ + const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH; + char *online_path = NULL; virBitmapPtr cpumap; int present; - present = nodeGetCPUCount(NULL); + present = nodeGetCPUCount(prefix); if (present < 0) return NULL; - if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/online")) { - cpumap = linuxParseCPUmap(present, SYSFS_SYSTEM_PATH "/cpu/online"); + if (virAsprintf(&online_path, "%s/cpu/online", prefix) < 0) + return NULL; + if (virFileExists(online_path)) { + cpumap = linuxParseCPUmap(present, online_path); } else { size_t i; cpumap = virBitmapNew(present); if (!cpumap) - return NULL; + goto cleanup; for (i = 0; i < present; i++) { - int online = virNodeGetCpuValue(SYSFS_SYSTEM_PATH, i, "online", 1); + int online = virNodeGetCpuValue(prefix, i, "online", 1); if (online < 0) { virBitmapFree(cpumap); - return NULL; + cpumap = NULL; + goto cleanup; } if (online) ignore_value(virBitmapSetBit(cpumap, i)); @@ -1305,6 +1311,8 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED) } if (max_id && cpumap) *max_id = present; + cleanup: + VIR_FREE(online_path); return cpumap; #else virReportError(VIR_ERR_NO_SUPPORT, "%s", @@ -1630,7 +1638,7 @@ nodeGetCPUMap(unsigned char **cpumap, if (!cpumap && !online) return nodeGetCPUCount(NULL); - if (!(cpus = nodeGetCPUBitmap(&maxpresent))) + if (!(cpus = nodeGetCPUBitmap(NULL, &maxpresent))) goto cleanup; if (cpumap && virBitmapToData(cpus, cpumap, &dummy) < 0) diff --git a/src/nodeinfo.h b/src/nodeinfo.h index 3ef206b..439ef35 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -44,7 +44,7 @@ int nodeGetMemory(unsigned long long *mem, unsigned long long *freeMem); virBitmapPtr nodeGetPresentCPUBitmap(const char *sysfs_prefix); -virBitmapPtr nodeGetCPUBitmap(int *max_id); +virBitmapPtr nodeGetCPUBitmap(const char *sysfs_prefix, int *max_id); int nodeGetCPUCount(const char *sysfs_prefix); int nodeGetMemoryParameters(virTypedParameterPtr params, -- 2.1.0

Add the sysfs_prefix argument to the call to allow for setting the path for tests to something other than SYSFS_SYSTEM_PATH. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/bhyve/bhyve_driver.c | 2 +- src/lxc/lxc_driver.c | 2 +- src/nodeinfo.c | 8 +++++--- src/nodeinfo.h | 3 ++- src/openvz/openvz_driver.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/uml/uml_driver.c | 2 +- src/vz/vz_driver.c | 2 +- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index dc76cf7..68dff6c 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1299,7 +1299,7 @@ bhyveNodeGetCPUMap(virConnectPtr conn, if (virNodeGetCPUMapEnsureACL(conn) < 0) return -1; - return nodeGetCPUMap(cpumap, online, flags); + return nodeGetCPUMap(NULL, cpumap, online, flags); } static int diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index cc1277b..31201a0 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5553,7 +5553,7 @@ lxcNodeGetCPUMap(virConnectPtr conn, if (virNodeGetCPUMapEnsureACL(conn) < 0) return -1; - return nodeGetCPUMap(cpumap, online, flags); + return nodeGetCPUMap(NULL, cpumap, online, flags); } diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 75e0a02..bf4f751 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1624,10 +1624,12 @@ nodeGetMemoryParameters(virTypedParameterPtr params ATTRIBUTE_UNUSED, } int -nodeGetCPUMap(unsigned char **cpumap, +nodeGetCPUMap(const char *sysfs_prefix, + unsigned char **cpumap, unsigned int *online, unsigned int flags) { + const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH; virBitmapPtr cpus = NULL; int maxpresent; int ret = -1; @@ -1636,9 +1638,9 @@ nodeGetCPUMap(unsigned char **cpumap, virCheckFlags(0, -1); if (!cpumap && !online) - return nodeGetCPUCount(NULL); + return nodeGetCPUCount(prefix); - if (!(cpus = nodeGetCPUBitmap(NULL, &maxpresent))) + if (!(cpus = nodeGetCPUBitmap(prefix, &maxpresent))) goto cleanup; if (cpumap && virBitmapToData(cpus, cpumap, &dummy) < 0) diff --git a/src/nodeinfo.h b/src/nodeinfo.h index 439ef35..9e6904f 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -55,7 +55,8 @@ int nodeSetMemoryParameters(virTypedParameterPtr params, int nparams, unsigned int flags); -int nodeGetCPUMap(unsigned char **cpumap, +int nodeGetCPUMap(const char *sysfs_prefix, + unsigned char **cpumap, unsigned int *online, unsigned int flags); diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index d1a327c..fc6f101 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2207,7 +2207,7 @@ openvzNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned int *online, unsigned int flags) { - return nodeGetCPUMap(cpumap, online, flags); + return nodeGetCPUMap(NULL, cpumap, online, flags); } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6fbe68a..3382b9a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18472,7 +18472,7 @@ qemuNodeGetCPUMap(virConnectPtr conn, if (virNodeGetCPUMapEnsureACL(conn) < 0) return -1; - return nodeGetCPUMap(cpumap, online, flags); + return nodeGetCPUMap(NULL, cpumap, online, flags); } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 7a95458..99162f7 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -2877,7 +2877,7 @@ umlNodeGetCPUMap(virConnectPtr conn, if (virNodeGetCPUMapEnsureACL(conn) < 0) return -1; - return nodeGetCPUMap(cpumap, online, flags); + return nodeGetCPUMap(NULL, cpumap, online, flags); } diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 06fb579..bc82444 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -868,7 +868,7 @@ vzNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned int *online, unsigned int flags) { - return nodeGetCPUMap(cpumap, online, flags); + return nodeGetCPUMap(NULL, cpumap, online, flags); } static int -- 2.1.0

Add the sysfs_prefix argument to the call to allow for setting the path for tests to something other than SYSFS_SYSTEM_PATH. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/bhyve/bhyve_capabilities.c | 2 +- src/bhyve/bhyve_driver.c | 2 +- src/lxc/lxc_driver.c | 2 +- src/nodeinfo.c | 9 ++++++--- src/nodeinfo.h | 2 +- src/openvz/openvz_conf.c | 2 +- src/openvz/openvz_driver.c | 2 +- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/uml/uml_driver.c | 2 +- src/vbox/vbox_common.c | 2 +- src/vz/vz_driver.c | 4 ++-- 12 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index e6d5518..3a55879 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -51,7 +51,7 @@ virBhyveCapsInitCPU(virCapsPtr caps, cpu->arch = arch; - if (nodeGetInfo(&nodeinfo)) + if (nodeGetInfo(NULL, &nodeinfo)) goto error; cpu->type = VIR_CPU_TYPE_HOST; diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 68dff6c..ba411a0 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1131,7 +1131,7 @@ bhyveNodeGetInfo(virConnectPtr conn, if (virNodeGetInfoEnsureACL(conn) < 0) return -1; - return nodeGetInfo(nodeinfo); + return nodeGetInfo(NULL, nodeinfo); } static int diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 31201a0..e0e72ea 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5400,7 +5400,7 @@ lxcNodeGetInfo(virConnectPtr conn, if (virNodeGetInfoEnsureACL(conn) < 0) return -1; - return nodeGetInfo(nodeinfo); + return nodeGetInfo(NULL, nodeinfo); } diff --git a/src/nodeinfo.c b/src/nodeinfo.c index bf4f751..2d715fd 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1034,7 +1034,8 @@ virNodeGetSiblingsList(const char *dir, int cpu_id) } #endif -int nodeGetInfo(virNodeInfoPtr nodeinfo) +int nodeGetInfo(const char *sysfs_prefix ATTRIBUTE_UNUSED, + virNodeInfoPtr nodeinfo) { virArch hostarch = virArchFromHost(); @@ -1046,14 +1047,16 @@ int nodeGetInfo(virNodeInfoPtr nodeinfo) #ifdef __linux__ { int ret = -1; + const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH; FILE *cpuinfo = fopen(CPUINFO_PATH, "r"); + if (!cpuinfo) { virReportSystemError(errno, _("cannot open %s"), CPUINFO_PATH); return -1; } - ret = linuxNodeInfoCPUPopulate(cpuinfo, SYSFS_SYSTEM_PATH, + ret = linuxNodeInfoCPUPopulate(cpuinfo, prefix, hostarch, nodeinfo); if (ret < 0) goto cleanup; @@ -1666,7 +1669,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED) int id, cid; int onlinecpus ATTRIBUTE_UNUSED; - if (nodeGetInfo(&nodeinfo) < 0) + if (nodeGetInfo(NULL, &nodeinfo) < 0) return -1; ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo); diff --git a/src/nodeinfo.h b/src/nodeinfo.h index 9e6904f..ec53769 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -26,7 +26,7 @@ # include "capabilities.h" -int nodeGetInfo(virNodeInfoPtr nodeinfo); +int nodeGetInfo(const char *sysfs_prefix, virNodeInfoPtr nodeinfo); int nodeCapsInitNUMA(virCapsPtr caps); int nodeGetCPUStats(int cpuNum, diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 49d78c6..a4c5c31 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -637,7 +637,7 @@ openvzGetNodeCPUs(void) { virNodeInfo nodeinfo; - if (nodeGetInfo(&nodeinfo) < 0) + if (nodeGetInfo(NULL, &nodeinfo) < 0) return 0; return nodeinfo.cpus; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index fc6f101..280b998 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2155,7 +2155,7 @@ static int openvzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) { - return nodeGetInfo(nodeinfo); + return nodeGetInfo(NULL, nodeinfo); } diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 27686c3..6532011 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -960,7 +960,7 @@ virQEMUCapsInitCPU(virCapsPtr caps, cpu->arch = arch; - if (nodeGetInfo(&nodeinfo)) + if (nodeGetInfo(NULL, &nodeinfo)) goto error; cpu->type = VIR_CPU_TYPE_HOST; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3382b9a..b26b1a8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18377,7 +18377,7 @@ qemuNodeGetInfo(virConnectPtr conn, if (virNodeGetInfoEnsureACL(conn) < 0) return -1; - return nodeGetInfo(nodeinfo); + return nodeGetInfo(NULL, nodeinfo); } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 99162f7..8606616 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -2782,7 +2782,7 @@ umlNodeGetInfo(virConnectPtr conn, if (virNodeGetInfoEnsureACL(conn) < 0) return -1; - return nodeGetInfo(nodeinfo); + return nodeGetInfo(NULL, nodeinfo); } diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 813a171..5615df5 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7537,7 +7537,7 @@ static int vboxNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) { - return nodeGetInfo(nodeinfo); + return nodeGetInfo(NULL, nodeinfo); } static int diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index bc82444..938910b 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -132,7 +132,7 @@ vzBuildCapabilities(void) emulators[k], virt_types[k]) < 0) goto error; - if (nodeGetInfo(&nodeinfo)) + if (nodeGetInfo(NULL, &nodeinfo)) goto error; if (VIR_ALLOC(cpu) < 0) @@ -765,7 +765,7 @@ static int vzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) { - return nodeGetInfo(nodeinfo); + return nodeGetInfo(NULL, nodeinfo); } static int vzConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) -- 2.1.0

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 Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/lxc/lxc_conf.c | 2 +- src/nodeinfo.c | 35 +++++++++++++++++++++++------------ src/nodeinfo.h | 2 +- src/openvz/openvz_conf.c | 2 +- src/phyp/phyp_driver.c | 2 +- src/qemu/qemu_capabilities.c | 2 +- src/uml/uml_conf.c | 2 +- src/vbox/vbox_common.c | 2 +- src/vmware/vmware_conf.c | 2 +- src/vz/vz_driver.c | 2 +- 10 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index c393cb5..b689b92 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -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"); } diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 2d715fd..5ff5ce8 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -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, + 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; } diff --git a/src/nodeinfo.h b/src/nodeinfo.h index ec53769..b28aaab 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -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, diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index a4c5c31..db0a9a7 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -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, diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index ec0fde3..54dec70 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -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"); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 6532011..f395c21 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1023,7 +1023,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"); } diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index 86fbecc..90deb2a 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -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"); } diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 5615df5..91a61f8 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -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, diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 5b249f8..21cf333 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -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 */ diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 938910b..905a806 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -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++) -- 2.1.0

On Tue, 2015-07-07 at 20:26 -0400, John Ferlan wrote:
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
Signed-off-by: John Ferlan <jferlan@redhat.com>
Just one remark below.
@@ -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, + int cpu_id ATTRIBUTE_UNUSED, virCapsHostNUMACellCPUPtr cpu ATTRIBUTE_UNUSED)
cpupath should be marked ATTRIBUTE_UNUSED as well. Cheers. -- Andrea Bolognani Software Engineer - Virtualization Team

Add the sysfs_prefix argument to the call to allow for setting the path for tests to something other than SYSFS_SYSTEM_PATH. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/bhyve/bhyve_driver.c | 2 +- src/lxc/lxc_driver.c | 2 +- src/nodeinfo.c | 6 ++++-- src/nodeinfo.h | 3 ++- src/openvz/openvz_driver.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/uml/uml_driver.c | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index ba411a0..85b7c8f 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1121,7 +1121,7 @@ bhyveNodeGetMemoryStats(virConnectPtr conn, if (virNodeGetMemoryStatsEnsureACL(conn) < 0) return -1; - return nodeGetMemoryStats(cellNum, params, nparams, flags); + return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); } static int diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index e0e72ea..81bb711 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5486,7 +5486,7 @@ lxcNodeGetMemoryStats(virConnectPtr conn, if (virNodeGetMemoryStatsEnsureACL(conn) < 0) return -1; - return nodeGetMemoryStats(cellNum, params, nparams, flags); + return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); } diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 5ff5ce8..3c7e417 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1141,7 +1141,8 @@ int nodeGetCPUStats(int cpuNum ATTRIBUTE_UNUSED, #endif } -int nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED, +int nodeGetMemoryStats(const char *sysfs_prefix ATTRIBUTE_UNUSED, + int cellNum ATTRIBUTE_UNUSED, virNodeMemoryStatsPtr params ATTRIBUTE_UNUSED, int *nparams ATTRIBUTE_UNUSED, unsigned int flags) @@ -1151,6 +1152,7 @@ int nodeGetMemoryStats(int cellNum 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; @@ -1170,7 +1172,7 @@ int nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED, } if (virAsprintf(&meminfo_path, "%s/node/node%d/meminfo", - SYSFS_SYSTEM_PATH, cellNum) < 0) + prefix, cellNum) < 0) return -1; } meminfo = fopen(meminfo_path, "r"); diff --git a/src/nodeinfo.h b/src/nodeinfo.h index b28aaab..4f983c2 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -33,7 +33,8 @@ int nodeGetCPUStats(int cpuNum, virNodeCPUStatsPtr params, int *nparams, unsigned int flags); -int nodeGetMemoryStats(int cellNum, +int nodeGetMemoryStats(const char *sysfs_prefix, + int cellNum, virNodeMemoryStatsPtr params, int *nparams, unsigned int flags); diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 280b998..fc8db7e 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2177,7 +2177,7 @@ openvzNodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED, int *nparams, unsigned int flags) { - return nodeGetMemoryStats(cellNum, params, nparams, flags); + return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b26b1a8..8c475ef 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18405,7 +18405,7 @@ qemuNodeGetMemoryStats(virConnectPtr conn, if (virNodeGetMemoryStatsEnsureACL(conn) < 0) return -1; - return nodeGetMemoryStats(cellNum, params, nparams, flags); + return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 8606616..c3c5fa7 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -2810,7 +2810,7 @@ umlNodeGetMemoryStats(virConnectPtr conn, if (virNodeGetMemoryStatsEnsureACL(conn) < 0) return -1; - return nodeGetMemoryStats(cellNum, params, nparams, flags); + return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); } -- 2.1.0

From: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com> This patch resolves a situation where a core is defective and is not in the present mask during boot. Optionally a host can have empty sockets could be brought online if the socket is added. In this case the present mask contains the cpu's that are actually there in the sockets even though they might be offline for some reason. This patch excludes the cpu's that are offline because the socket is defective/empty by checking the present mask before reading the cpu directory. Otherwise, the nodeinfo on such hosts always displays wrong output which includes the defective/empty sockets as set of offline cpu's. Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com> Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/nodeinfo.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 3c7e417..1d8a339 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -43,6 +43,7 @@ #include "c-ctype.h" #include "viralloc.h" #include "nodeinfopriv.h" +#include "nodeinfo.h" #include "physmem.h" #include "virerror.h" #include "count-one-bits.h" @@ -403,20 +404,23 @@ CPU_COUNT(cpu_set_t *set) /* parses a node entry, returning number of processors in the node and * filling arguments */ static int -ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) +ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) -ATTRIBUTE_NONNULL(6) -virNodeParseNode(const char *node, +ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7) +virNodeParseNode(const char *sysfs_prefix, + const char *node, virArch arch, int *sockets, int *cores, int *threads, int *offline) { + const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH; int ret = -1; int processors = 0; DIR *cpudir = NULL; struct dirent *cpudirent = NULL; + virBitmapPtr present_cpumap = NULL; int sock_max = 0; cpu_set_t sock_map; int sock; @@ -437,12 +441,17 @@ virNodeParseNode(const char *node, goto cleanup; } + present_cpumap = nodeGetPresentCPUBitmap(prefix); + /* enumerate sockets in the node */ CPU_ZERO(&sock_map); while ((direrr = virDirRead(cpudir, &cpudirent, node)) > 0) { if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1) continue; + if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu))) + continue; + if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0) goto cleanup; @@ -476,6 +485,9 @@ virNodeParseNode(const char *node, if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1) continue; + if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu))) + continue; + if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0) goto cleanup; @@ -536,6 +548,7 @@ virNodeParseNode(const char *node, ret = -1; } VIR_FREE(core_maps); + virBitmapFree(present_cpumap); return ret; } @@ -657,7 +670,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, sysfs_dir, nodedirent->d_name) < 0) goto cleanup; - if ((cpus = virNodeParseNode(sysfs_cpudir, arch, + if ((cpus = virNodeParseNode(sysfs_dir, sysfs_cpudir, arch, &socks, &cores, &threads, &offline)) < 0) goto cleanup; @@ -688,7 +701,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, if (virAsprintf(&sysfs_cpudir, "%s/cpu", sysfs_dir) < 0) goto cleanup; - if ((cpus = virNodeParseNode(sysfs_cpudir, arch, + if ((cpus = virNodeParseNode(sysfs_dir, sysfs_cpudir, arch, &socks, &cores, &threads, &offline)) < 0) goto cleanup; -- 2.1.0

On Tue, 2015-07-07 at 20:26 -0400, John Ferlan wrote:
This series adds/processes a sysfs_prefix for the nodeinfo.c API's.
Although the nodeinfotest.c passes a local test directory path, it was never used.
This was all brought to light by patch 9 in this series which is essentially Kothapally Madhu Pavan's v3 patch:
http://www.redhat.com/archives/libvir-list/2015-June/msg00395.html
With the adjustment to call nodeGetPresentCPUBitmap and virNodeParseNode with the sysfs prefix.
Without the first 5 patches, the patch as posted caused nodeinfotest failure in my test environment which doesn't have the "larger" environments that the test tried to set up because the test environment used my present mask file.
Patches 1-8 look good to me. Great job splitting the changes in such a nice way! I've commented on patch 7 in a separate mail. I'll look at patch 9 on Monday. Cheers. -- Andrea Bolognani Software Engineer - Virtualization Team

On Fri, 2015-07-10 at 17:05 +0200, Andrea Bolognani wrote:
Patches 1-8 look good to me. Great job splitting the changes in such a nice way! I've commented on patch 7 in a separate mail.
I'll look at patch 9 on Monday.
Patch 9 looks good as well, so ACK series with the previously mentioned nit fixed. I've also just sent a patch introducing a test case meant to make sure patch 9 is actually fixing the issue :) Hopefully it will make it to the list despite being biggish. Cheers. -- Andrea Bolognani Software Engineer - Virtualization Team

On 07/13/2015 12:42 PM, Andrea Bolognani wrote:
On Fri, 2015-07-10 at 17:05 +0200, Andrea Bolognani wrote:
Patches 1-8 look good to me. Great job splitting the changes in such a nice way! I've commented on patch 7 in a separate mail.
I'll look at patch 9 on Monday.
Patch 9 looks good as well, so ACK series with the previously mentioned nit fixed.
I've also just sent a patch introducing a test case meant to make sure patch 9 is actually fixing the issue :)
Hopefully it will make it to the list despite being biggish.
Cheers.
It did - thanks for the collaboration! I've included it into this series as patch10 and pushed with the adjustment to patch 7. Thanks! John
participants (2)
-
Andrea Bolognani
-
John Ferlan