From patchwork Tue Mar 4 14:00:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 326348 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E189B2C00D5 for ; Wed, 5 Mar 2014 01:53:57 +1100 (EST) Received: from localhost ([::1]:45017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKpyQ-0004tr-9f for incoming@patchwork.ozlabs.org; Tue, 04 Mar 2014 09:05:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKpuh-0007cM-Qa for qemu-devel@nongnu.org; Tue, 04 Mar 2014 09:01:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WKpuZ-0001So-CX for qemu-devel@nongnu.org; Tue, 04 Mar 2014 09:01:43 -0500 Received: from mail-ea0-x232.google.com ([2a00:1450:4013:c01::232]:47559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKpuZ-0001Ro-2g for qemu-devel@nongnu.org; Tue, 04 Mar 2014 09:01:35 -0500 Received: by mail-ea0-f178.google.com with SMTP id a15so370700eae.23 for ; Tue, 04 Mar 2014 06:01:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=yGMws+HSxfDoQFkBqfCt7e7+aZ0e0dW08QKHRdtMMmA=; b=vcn86yUhDDB3z/IREyR8rmpaJmcN+lapKzMrVixAhLP549r1t5kU2//Fqs1MZUZfjK dtnQWJvvt+5Y+hwXQOJdeg3EQpoO30K0vETO/8zhj6rb/nKwdTPX/2dO70aB73CCrpKV W4HDScLphL0/6vccEVJRTB1wu4620r5eKOqYIVXQm09x0DxCsuabknbWkeC4wNmNk1ib L5x3Ik8/K+ErseMQh25mQGmmviEQzQjBl+KdU+YXvnx8Ic14rro8z7EkRt2d2ItE84Oz KY/J9dj2Pwcjh6d4yhJY7XryYp53hQU4jC4vAg9HRIbDfG0ngH/XADKkaIAIrhViP2OO 1KxA== X-Received: by 10.14.218.70 with SMTP id j46mr32983837eep.11.1393941694181; Tue, 04 Mar 2014 06:01:34 -0800 (PST) Received: from yakj.lan (net-37-117-154-249.cust.vodafonedsl.it. [37.117.154.249]) by mx.google.com with ESMTPSA id j42sm63911572eep.21.2014.03.04.06.01.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Mar 2014 06:01:33 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 4 Mar 2014 15:00:36 +0100 Message-Id: <1393941656-29068-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1393941656-29068-1-git-send-email-pbonzini@redhat.com> References: <1393941656-29068-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::232 Cc: ehabkost@redhat.com, hutao@cn.fujitsu.com, mtosatti@redhat.com, imammedo@redhat.com, a.motakis@virtualopensystems.com, gaowanlong@cn.fujitsu.com Subject: [Qemu-devel] [PATCH 2.1 08/28] vl: convert -m to QemuOpts 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 From: Igor Mammedov Adds option to -m "mem" - startup memory amount For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in Mb. Otherwise user is free to use suffixed number using suffixes b,k/K,M,G Signed-off-by: Igor Mammedov Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- qemu-options.hx | 9 +++++--- vl.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index f948f28..98e78ca 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -214,10 +214,13 @@ use is discouraged as it may be removed from future versions. ETEXI DEF("m", HAS_ARG, QEMU_OPTION_m, - "-m megs set virtual RAM size to megs MB [default=" - stringify(DEFAULT_RAM_SIZE) "]\n", QEMU_ARCH_ALL) + "-m [mem=]megs\n" + " configure guest RAM\n" + " mem: initial amount of guest memory (default: " + stringify(DEFAULT_RAM_SIZE) "MiB)\n", + QEMU_ARCH_ALL) STEXI -@item -m @var{megs} +@item -m [mem=]@var{megs} @findex -m Set virtual RAM size to @var{megs} megabytes. Default is 128 MiB. Optionally, a suffix of ``M'' or ``G'' can be used to signify a value in megabytes or diff --git a/vl.c b/vl.c index dafe6f6..ac5f425 100644 --- a/vl.c +++ b/vl.c @@ -478,6 +478,20 @@ static QemuOptsList qemu_msg_opts = { }, }; +static QemuOptsList qemu_mem_opts = { + .name = "memory", + .implied_opt_name = "mem", + .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head), + .merge_lists = true, + .desc = { + { + .name = "mem", + .type = QEMU_OPT_SIZE, + }, + { /* end of list */ } + }, +}; + /** * Get machine options * @@ -2718,6 +2732,7 @@ int main(int argc, char **argv, char **envp) }; const char *trace_events = NULL; const char *trace_file = NULL; + const ram_addr_t default_ram_size = (ram_addr_t)DEFAULT_RAM_SIZE * 1024 * 1024; atexit(qemu_run_exit_notifiers); error_set_progname(argv[0]); @@ -2758,6 +2773,7 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_realtime_opts); qemu_add_opts(&qemu_msg_opts); qemu_add_opts(&qemu_numa_opts); + qemu_add_opts(&qemu_mem_opts); runstate_init(); @@ -2773,7 +2789,7 @@ int main(int argc, char **argv, char **envp) module_call_init(MODULE_INIT_MACHINE); machine = find_default_machine(); cpu_model = NULL; - ram_size = 0; + ram_size = default_ram_size; snapshot = 0; cyls = heads = secs = 0; translation = BIOS_ATA_TRANSLATION_AUTO; @@ -3063,20 +3079,50 @@ int main(int argc, char **argv, char **envp) exit(0); break; case QEMU_OPTION_m: { - int64_t value; uint64_t sz; - char *end; + const char *mem_str; - value = strtosz(optarg, &end); - if (value < 0 || *end) { - fprintf(stderr, "qemu: invalid ram size: %s\n", optarg); - exit(1); + opts = qemu_opts_parse(qemu_find_opts("memory"), + optarg, 1); + if (!opts) { + exit(EXIT_FAILURE); + } + + mem_str = qemu_opt_get(opts, "mem"); + if (!mem_str) { + fprintf(stderr, "qemu: invalid -m option, missing " + "'mem' option\n"); + exit(EXIT_FAILURE); + } + if (!*mem_str) { + fprintf(stderr, "qemu: missing 'mem' option value\n"); + exit(EXIT_FAILURE); + } + + sz = qemu_opt_get_size(opts, "mem", ram_size); + + /* Fix up legacy suffix-less format */ + if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) { + uint64_t overflow_check = sz; + + sz <<= 20; + if ((sz >> 20) != overflow_check) { + fprintf(stderr, "qemu: too large 'mem' option " + "value\n"); + exit(EXIT_FAILURE); + } + } + + /* backward compatibility behaviour for case "-m 0" */ + if (sz == 0) { + sz = default_ram_size; } - sz = QEMU_ALIGN_UP((uint64_t)value, 8192); + + sz = QEMU_ALIGN_UP(sz, 8192); ram_size = sz; if (ram_size != sz) { fprintf(stderr, "qemu: ram size too large\n"); - exit(1); + exit(EXIT_FAILURE); } break; } @@ -3921,10 +3967,8 @@ int main(int argc, char **argv, char **envp) exit(1); } - /* init the memory */ - if (ram_size == 0) { - ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; - } + /* store value for the future use */ + qemu_opt_set_number(qemu_find_opts_singleton("memory"), "mem", ram_size); if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0) {