[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V5 07/12] NUMA: split out the common range parser
From: |
Wanlong Gao |
Subject: |
[Qemu-devel] [PATCH V5 07/12] NUMA: split out the common range parser |
Date: |
Wed, 17 Jul 2013 17:29:28 +0800 |
Since cpus parser and hostnode parser have the common range parser
part, split it out to the common range parser to avoid the duplicate
code.
Reviewed-by: Bandan Das <address@hidden>
Signed-off-by: Wanlong Gao <address@hidden>
---
numa.c | 86 ++++++++++++++++++++++++++++--------------------------------------
1 file changed, 37 insertions(+), 49 deletions(-)
diff --git a/numa.c b/numa.c
index a2eceb1..736acbb 100644
--- a/numa.c
+++ b/numa.c
@@ -36,48 +36,59 @@ QemuOptsList qemu_numa_opts = {
.desc = { { 0 } } /* validated with OptsVisitor */
};
-static int numa_node_parse_cpus(int nodenr, const char *cpus)
+static int numa_range_parse(const char *str,
+ unsigned long long *value,
+ unsigned long long *endvalue)
{
char *endptr;
- unsigned long long value, endvalue;
- /* Empty CPU range strings will be considered valid, they will simply
- * not set any bit in the CPU bitmap.
- */
- if (!*cpus) {
- return 0;
+ if (parse_uint(str, value, &endptr, 10) < 0) {
+ return -1;
}
- if (parse_uint(cpus, &value, &endptr, 10) < 0) {
- goto error;
- }
if (*endptr == '-') {
- if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) {
- goto error;
+ if (parse_uint_full(endptr + 1, endvalue, 10) < 0) {
+ return -1;
}
} else if (*endptr == '\0') {
- endvalue = value;
+ *endvalue = *value;
} else {
- goto error;
+ return -1;
}
- if (endvalue >= MAX_CPUMASK_BITS) {
- endvalue = MAX_CPUMASK_BITS - 1;
+ if (*endvalue >= MAX_CPUMASK_BITS) {
+ *endvalue = MAX_CPUMASK_BITS - 1;
fprintf(stderr,
- "qemu: NUMA: A max of %d VCPUs are supported\n",
+ "qemu: NUMA: A max of %d VCPUs/Nodes are supported\n",
MAX_CPUMASK_BITS);
}
- if (endvalue < value) {
- goto error;
+ if (*endvalue < *value) {
+ return -1;
}
- bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1);
return 0;
+}
-error:
- fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus);
- return -1;
+
+static int numa_node_parse_cpus(int nodenr, const char *cpus)
+{
+ unsigned long long value, endvalue;
+
+ /* Empty CPU range strings will be considered valid, they will simply
+ * not set any bit in the CPU bitmap.
+ */
+ if (!*cpus) {
+ return 0;
+ }
+
+ if (numa_range_parse(cpus, &value, &endvalue) < 0) {
+ fprintf(stderr, "Invalid NUMA CPU range: %s", cpus);
+ return -1;
+ }
+
+ bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1);
+ return 0;
}
static int numa_node_parse(NumaNodeOptions *opts)
@@ -115,7 +126,6 @@ static int numa_mem_parse_policy(int nodenr, const char
*policy)
static int numa_mem_parse_hostnodes(int nodenr, const char *hostnodes)
{
unsigned long long value, endvalue;
- char *endptr;
bool clear = false;
unsigned long *bm = numa_info[nodenr].host_mem;
@@ -134,27 +144,9 @@ static int numa_mem_parse_hostnodes(int nodenr, const char
*hostnodes)
return 0;
}
- if (parse_uint(hostnodes, &value, &endptr, 10) < 0)
- goto error;
- if (*endptr == '-') {
- if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) {
- goto error;
- }
- } else if (*endptr == '\0') {
- endvalue = value;
- } else {
- goto error;
- }
-
- if (endvalue >= MAX_CPUMASK_BITS) {
- endvalue = MAX_CPUMASK_BITS - 1;
- fprintf(stderr,
- "qemu: NUMA: A max of %d host nodes are supported\n",
- MAX_CPUMASK_BITS);
- }
-
- if (endvalue < value) {
- goto error;
+ if (numa_range_parse(hostnodes, &value, &endvalue) < 0) {
+ fprintf(stderr, "Invalid host NUMA nodes range: %s", hostnodes);
+ return -1;
}
if (clear)
@@ -163,10 +155,6 @@ static int numa_mem_parse_hostnodes(int nodenr, const char
*hostnodes)
bitmap_set(bm, value, endvalue - value + 1);
return 0;
-
-error:
- fprintf(stderr, "qemu: Invalid host NUMA nodes range: %s\n", hostnodes);
- return -1;
}
static int numa_mem_parse(NumaMemOptions *opts)
--
1.8.3.2.634.g7a3187e
- [Qemu-devel] [PATCH V5 00/12] Add support for binding guest numa nodes to host numa nodes, Wanlong Gao, 2013/07/17
- [Qemu-devel] [PATCH V5 03/12] NUMA: move numa related code to numa.c, Wanlong Gao, 2013/07/17
- [Qemu-devel] [PATCH V5 05/12] NUMA: Add Linux libnuma detection, Wanlong Gao, 2013/07/17
- [Qemu-devel] [PATCH V5 07/12] NUMA: split out the common range parser,
Wanlong Gao <=
- [Qemu-devel] [PATCH V5 02/12] NUMA: split -numa option, Wanlong Gao, 2013/07/17
- [Qemu-devel] [PATCH V5 06/12] NUMA: parse guest numa nodes memory policy, Wanlong Gao, 2013/07/17
- [Qemu-devel] [PATCH V5 04/12] NUMA: Add numa_info structure to contain numa nodes info, Wanlong Gao, 2013/07/17
- [Qemu-devel] [PATCH V5 08/12] NUMA: set guest numa nodes memory policy, Wanlong Gao, 2013/07/17
- [Qemu-devel] [PATCH V5 09/12] NUMA: add qmp command set-mem-policy to set memory policy for NUMA node, Wanlong Gao, 2013/07/17