]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
nodeinfo: Add sysfs_prefix to nodeGetCPUCount
authorJohn Ferlan <jferlan@redhat.com>
Tue, 7 Jul 2015 23:49:10 +0000 (19:49 -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_SYSTEM_PATH.

src/lxc/lxc_controller.c
src/nodeinfo.c
src/nodeinfo.h
src/qemu/qemu_driver.c
src/qemu/qemu_process.c
src/vz/vz_sdk.c
tests/vircgrouptest.c

index 828b8a8c0ee38c39df487e12b9658de5e1a06af4..27e2e3a85a17682efde81c37da01668ea45275f5 100644 (file)
@@ -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)
index f3e31084e225dd61d53ef3723798e1f66fb818af..409f922ba8a51bdc4a6df4ed926212dbf96629dd 100644 (file)
@@ -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;
index 047bd5ca64dfd4f3ab99589bcbae2a9f10631832..4f9699ea7a49de429e581996d8b34b23ad66cd8d 100644 (file)
@@ -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,
index c8cbd570d948add5e04f3c39eaa84c1c83064c10..0ca81e1c68e87d732ccb049667d688cccc6b55a0 100644 (file)
@@ -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) {
@@ -5668,7 +5668,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)
index 087c530c0c3bfdcbaa42f0f7f74d241ce5e3ce44..9439d7ee137cdd351762f28d13b76acb8db2746f 100644 (file)
@@ -2373,7 +2373,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)
index d1bc312cb2c24f819d123bacb196521cdccb1653..744b58a229c57065ce83db422ae4967d3fd08b24 100644 (file)
@@ -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 */
index dddf33a016ed4db7ce56e4224417e910721dc7b6..7a876406adef5e6d196c7dcad4e439ac29a171aa 100644 (file)
@@ -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;
     }