[PATCHv2 1/3] util: split the virNumaGetHugePageInfoPath into separate function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



https://bugzilla.redhat.com/show_bug.cgi?id=1265114

When pass 0 page_size to virNumaGetHugePageInfoPath function, we will
get fail like this:

 error : virFileReadAll:1358 : Failed to read file '/sys/devices/system/node/node0/hugepages/': Is a directory

Because when the page_size is 0 the virNumaGetHugePageInfoPath will
build the directory of system path, but we don't want that.

Introduce a new helper to build the dir path could avoid this issue.

Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx>
---
 src/util/virnuma.c | 51 +++++++++++++++++++--------------------------------
 1 file changed, 19 insertions(+), 32 deletions(-)

diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index 1a62d62..cb80972 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -493,44 +493,31 @@ virNumaGetHugePageInfoPath(char **path,
                            unsigned int page_size,
                            const char *suffix)
 {
-
-    int ret = -1;
-
     if (node == -1) {
         /* We are aiming at overall system info */
-        if (page_size) {
-            /* And even on specific huge page size */
-            if (virAsprintf(path,
-                            HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
-                            page_size, suffix ? suffix : "") < 0)
-                goto cleanup;
-        } else {
-            if (VIR_STRDUP(*path, HUGEPAGES_SYSTEM_PREFIX) < 0)
-                goto cleanup;
-        }
-
+        return virAsprintf(path,
+                           HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
+                           page_size, suffix ? suffix : "");
     } else {
         /* We are aiming on specific NUMA node */
-        if (page_size) {
-            /* And even on specific huge page size */
-            if (virAsprintf(path,
-                            HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
-                            HUGEPAGES_PREFIX "%ukB/%s",
-                            node, page_size, suffix ? suffix : "") < 0)
-                goto cleanup;
-        } else {
-            if (virAsprintf(path,
-                            HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
-                            node) < 0)
-                goto cleanup;
-        }
+        return virAsprintf(path,
+                           HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
+                           HUGEPAGES_PREFIX "%ukB/%s",
+                           node, page_size, suffix ? suffix : "");
     }
-
-    ret = 0;
- cleanup:
-    return ret;
 }
 
+static int
+virNumaGetHugePageInfoDir(char **path, int node)
+{
+    if (node == -1) {
+        return VIR_STRDUP(*path, HUGEPAGES_SYSTEM_PREFIX);
+    } else {
+        return virAsprintf(path,
+                           HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
+                           node);
+    }
+}
 
 /**
  * virNumaGetHugePageInfo:
@@ -724,7 +711,7 @@ virNumaGetPages(int node,
      * is always shown as used memory. Here, however, we want to report
      * slightly different information. So we take the total memory on a node
      * and subtract memory taken by the huge pages. */
-    if (virNumaGetHugePageInfoPath(&path, node, 0, NULL) < 0)
+    if (virNumaGetHugePageInfoDir(&path, node) < 0)
         goto cleanup;
 
     if (!(dir = opendir(path))) {
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]