[libvirt] [PATCH 2/2] util: Produce friendlier error message to user

Luyao Huang lhuang at redhat.com
Wed Sep 30 04:01:30 UTC 2015


Commit 1c24cfe9 fix the problem in virNumaSetPagePoolSize,
this patch just like it and fix the issue in another function.

when user use freepages and specify a invalid node or page size,
will get error like this:

 # virsh freepages 0 1
 error: Failed to open file '/sys/devices/system/node/node0/hugepages/hugepages-1kB/free_hugepages': No such file or directory

Add two checks to catch this and therefore produce much more
friendlier error messages.

Signed-off-by: Luyao Huang <lhuang at redhat.com>
---
 src/util/virnuma.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index 8577bd8..c8beade 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -560,6 +560,12 @@ virNumaGetHugePageInfo(int node,
                                        page_size, "nr_hugepages") < 0)
             goto cleanup;
 
+        if (!virFileExists(path)) {
+            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                           _("page size or NUMA node not available"));
+            goto cleanup;
+        }
+
         if (virFileReadAll(path, 1024, &buf) < 0)
             goto cleanup;
 
@@ -579,6 +585,12 @@ virNumaGetHugePageInfo(int node,
                                        page_size, "free_hugepages") < 0)
             goto cleanup;
 
+        if (!virFileExists(path)) {
+            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                           _("page size or NUMA node not available"));
+            goto cleanup;
+        }
+
         if (virFileReadAll(path, 1024, &buf) < 0)
             goto cleanup;
 
-- 
1.8.3.1




More information about the libvir-list mailing list