qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH V4 05/10] NUMA: handle Error in cpus, mpol and hostn


From: Wanlong Gao
Subject: [Qemu-devel] [PATCH V4 05/10] NUMA: handle Error in cpus, mpol and hostnode parser
Date: Thu, 4 Jul 2013 17:53:12 +0800

As Paolo pointed out that, handle Error in mpol and hostnode parser
will make it easier to be used for example in mem-hotplug in the future.
And this will be used later in set-mpol QMP command.
Also handle Error in cpus parser to be consistent with others.

Signed-off-by: Wanlong Gao <address@hidden>
---
 include/sysemu/sysemu.h |  4 ++++
 vl.c                    | 42 ++++++++++++++++++++++++++++++++----------
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 993b8e0..0f135fe 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -144,6 +144,10 @@ struct node_info {
     unsigned int flags;
 };
 extern struct node_info numa_info[MAX_NODES];
+extern void numa_node_parse_mpol(int nodenr, const char *hostnode,
+                                 Error **errp);
+extern void numa_node_parse_hostnode(int nodenr, const char *hostnode,
+                                     Error **errp);
 
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
diff --git a/vl.c b/vl.c
index 495b3a8..38e0d3d 100644
--- a/vl.c
+++ b/vl.c
@@ -1338,7 +1338,7 @@ char *get_boot_devices_list(size_t *size)
     return list;
 }
 
-static void numa_node_parse_cpus(int nodenr, const char *cpus)
+static void numa_node_parse_cpus(int nodenr, const char *cpus, Error **errp)
 {
     char *endptr;
     unsigned long long value, endvalue;
@@ -1378,13 +1378,14 @@ static void numa_node_parse_cpus(int nodenr, const char 
*cpus)
     return;
 
 error:
-    fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus);
-    exit(1);
+    error_setg(errp, "Invalid NUMA CPU range: %s\n", cpus);
+    return;
 }
 
-static void numa_node_parse_mpol(int nodenr, const char *mpol)
+void numa_node_parse_mpol(int nodenr, const char *mpol, Error **errp)
 {
     if (!mpol) {
+        error_setg(errp, "Should specify memory policy");
         return;
     }
 
@@ -1395,11 +1396,11 @@ static void numa_node_parse_mpol(int nodenr, const char 
*mpol)
     } else if (!strcmp(mpol, "membind")) {
         numa_info[nodenr].flags |= NODE_HOST_BIND;
     } else {
-        fprintf(stderr, "qemu: Invalid memory policy: %s\n", mpol);
+        error_setg(errp, "Invalid memory policy: %s", mpol);
     }
 }
 
-static void numa_node_parse_hostnode(int nodenr, const char *hostnode)
+void numa_node_parse_hostnode(int nodenr, const char *hostnode, Error **errp)
 {
     unsigned long long value, endvalue;
     char *endptr;
@@ -1452,16 +1453,22 @@ static void numa_node_parse_hostnode(int nodenr, const 
char *hostnode)
     return;
 
 error:
-    fprintf(stderr, "qemu: Invalid host NUMA nodes range: %s\n", hostnode);
+    error_setg(errp, "Invalid host NUMA nodes range: %s", hostnode);
     return;
 }
 
 static int numa_add_cpus(const char *name, const char *value, void *opaque)
 {
     int *nodenr = opaque;
+    Error *err = NULL;
 
     if (!strcmp(name, "cpu")) {
-        numa_node_parse_cpus(*nodenr, value);
+        numa_node_parse_cpus(*nodenr, value, &err);
+    }
+    if (error_is_set(&err)) {
+        fprintf(stderr, "qemu: %s\n", error_get_pretty(err));
+        error_free(err);
+        return -1;
     }
     return 0;
 }
@@ -1469,19 +1476,34 @@ static int numa_add_cpus(const char *name, const char 
*value, void *opaque)
 static int numa_add_mpol(const char *name, const char *value, void *opaque)
 {
     int *nodenr = opaque;
+    Error *err = NULL;
 
     if (!strcmp(name, "mem-policy")) {
-        numa_node_parse_mpol(*nodenr, value);
+        numa_node_parse_mpol(*nodenr, value, &err);
+    }
+    if (error_is_set(&err)) {
+        fprintf(stderr, "qemu: %s\n", error_get_pretty(err));
+        error_free(err);
+        return -1;
     }
+
     return 0;
 }
 
 static int numa_add_hostnode(const char *name, const char *value, void *opaque)
 {
     int *nodenr = opaque;
+    Error *err = NULL;
+
     if (!strcmp(name, "mem-hostnode")) {
-        numa_node_parse_hostnode(*nodenr, value);
+        numa_node_parse_hostnode(*nodenr, value, &err);
     }
+    if (error_is_set(&err)) {
+        fprintf(stderr, "qemu: %s\n", error_get_pretty(err));
+        error_free(err);
+        return -1;
+    }
+
     return 0;
 }
 
-- 
1.8.3.2.634.g7a3187e




reply via email to

[Prev in Thread] Current Thread [Next in Thread]