From patchwork Thu Jul 4 09:53:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanlong Gao X-Patchwork-Id: 256852 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4680D2C009E for ; Thu, 4 Jul 2013 19:54:24 +1000 (EST) Received: from localhost ([::1]:44915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UugF4-0004F0-0h for incoming@patchwork.ozlabs.org; Thu, 04 Jul 2013 05:54:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UugEV-00048J-3k for qemu-devel@nongnu.org; Thu, 04 Jul 2013 05:53:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UugET-0002Kw-Qp for qemu-devel@nongnu.org; Thu, 04 Jul 2013 05:53:46 -0400 Received: from [222.73.24.84] (port=36263 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UugET-0002KJ-7O for qemu-devel@nongnu.org; Thu, 04 Jul 2013 05:53:45 -0400 X-IronPort-AV: E=Sophos;i="4.87,993,1363104000"; d="scan'208";a="7782336" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 04 Jul 2013 17:50:40 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r649rYpT017313; Thu, 4 Jul 2013 17:53:35 +0800 Received: from G08FNSTD121251.fnst.cn.fujitsu.com ([10.167.233.84]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013070417520594-2711617 ; Thu, 4 Jul 2013 17:52:05 +0800 From: Wanlong Gao To: qemu-devel@nongnu.org Date: Thu, 4 Jul 2013 17:53:13 +0800 Message-Id: <1372931597-28115-7-git-send-email-gaowanlong@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.2.634.g7a3187e In-Reply-To: <1372931597-28115-1-git-send-email-gaowanlong@cn.fujitsu.com> References: <1372931597-28115-1-git-send-email-gaowanlong@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/04 17:52:05, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/04 17:52:07, Serialize complete at 2013/07/04 17:52:07 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: aliguori@us.ibm.com, ehabkost@redhat.com, lcapitulino@redhat.com, bsd@redhat.com, y-goto@jp.fujitsu.com, pbonzini@redhat.com, afaerber@suse.de, gaowanlong@cn.fujitsu.com Subject: [Qemu-devel] [PATCH V4 06/10] NUMA: split out the common range parser X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Wanlong Gao --- vl.c | 89 ++++++++++++++++++++++++++++---------------------------------------- 1 file changed, 37 insertions(+), 52 deletions(-) diff --git a/vl.c b/vl.c index 38e0d3d..6e86dcf 100644 --- a/vl.c +++ b/vl.c @@ -1338,47 +1338,55 @@ char *get_boot_devices_list(size_t *size) return list; } -static void numa_node_parse_cpus(int nodenr, const char *cpus, Error **errp) +static int numa_node_parse_common(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; + 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; - fprintf(stderr, - "qemu: NUMA: A max of %d VCPUs are supported\n", - MAX_CPUMASK_BITS); + if (*endvalue >= MAX_CPUMASK_BITS) { + *endvalue = MAX_CPUMASK_BITS - 1; + fprintf(stderr, "qemu: NUMA: A max number %d is 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; + return 0; +} -error: - error_setg(errp, "Invalid NUMA CPU range: %s\n", cpus); +static void numa_node_parse_cpus(int nodenr, const char *cpus, Error **errp) +{ + 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; + } + + if (numa_node_parse_common(cpus, &value, &endvalue) < 0) { + error_setg(errp, "Invalid NUMA CPU range: %s", cpus); + return; + } + + bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1); return; } @@ -1403,7 +1411,6 @@ void numa_node_parse_mpol(int nodenr, const char *mpol, Error **errp) void numa_node_parse_hostnode(int nodenr, const char *hostnode, Error **errp) { unsigned long long value, endvalue; - char *endptr; bool clear = false; unsigned long *bm = numa_info[nodenr].host_mem; @@ -1422,27 +1429,9 @@ void numa_node_parse_hostnode(int nodenr, const char *hostnode, Error **errp) return; } - if (parse_uint(hostnode, &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_node_parse_common(hostnode, &value, &endvalue) < 0) { + error_setg(errp, "Invalid host NUMA ndoes range: %s", hostnode); + return; } if (clear) @@ -1451,10 +1440,6 @@ void numa_node_parse_hostnode(int nodenr, const char *hostnode, Error **errp) bitmap_set(bm, value, endvalue - value + 1); return; - -error: - error_setg(errp, "Invalid host NUMA nodes range: %s", hostnode); - return; } static int numa_add_cpus(const char *name, const char *value, void *opaque)