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.
Signed-off-by: Wanlong Gao <gaowanl...@cn.fujitsu.com> --- include/sysemu/sysemu.h | 4 ++++ vl.c | 28 ++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 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 4dbf5cc..4933d22 100644 --- a/vl.c +++ b/vl.c @@ -1382,9 +1382,10 @@ error: exit(1); } -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,7 +1453,7 @@ 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; } @@ -1469,19 +1470,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.1.448.gfb7dfaa