[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 08/34] vl: convert -m to QemuOpts
From: |
address@hidden |
Subject: |
[Qemu-devel] [PATCH v3 08/34] vl: convert -m to QemuOpts |
Date: |
Wed, 26 Mar 2014 10:36:58 +0000 |
From: Igor Mammedov <address@hidden>
Adds option to -m
"size" - 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 <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
qemu-options.hx | 9 +++++---
vl.c | 71 +++++++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 63 insertions(+), 17 deletions(-)
diff --git a/qemu-options.hx b/qemu-options.hx
index f66c3cf..30faa0e 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 [size=]megs\n"
+ " configure guest RAM\n"
+ " size: initial amount of guest memory (default: "
+ stringify(DEFAULT_RAM_SIZE) "MiB)\n",
+ QEMU_ARCH_ALL)
STEXI
address@hidden -m @var{megs}
address@hidden -m address@hidden
@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 d42e208..37d9973 100644
--- a/vl.c
+++ b/vl.c
@@ -509,6 +509,20 @@ static QemuOptsList qemu_name_opts = {
},
};
+static QemuOptsList qemu_mem_opts = {
+ .name = "memory",
+ .implied_opt_name = "size",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
+ .merge_lists = true,
+ .desc = {
+ {
+ .name = "size",
+ .type = QEMU_OPT_SIZE,
+ },
+ { /* end of list */ }
+ },
+};
+
/**
* Get machine options
*
@@ -2858,6 +2872,8 @@ 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]);
@@ -2881,6 +2897,7 @@ int main(int argc, char **argv, char **envp)
qemu_add_opts(&qemu_trace_opts);
qemu_add_opts(&qemu_option_rom_opts);
qemu_add_opts(&qemu_machine_opts);
+ qemu_add_opts(&qemu_mem_opts);
qemu_add_opts(&qemu_smp_opts);
qemu_add_opts(&qemu_boot_opts);
qemu_add_opts(&qemu_sandbox_opts);
@@ -2906,7 +2923,7 @@ int main(int argc, char **argv, char **envp)
module_call_init(MODULE_INIT_MACHINE);
machine_class = 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;
@@ -3196,20 +3213,48 @@ 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, "size");
+ if (!mem_str) {
+ error_report("invalid -m option, missing 'size' option");
+ exit(EXIT_FAILURE);
+ }
+ if (!*mem_str) {
+ error_report("missing 'size' option value");
+ exit(EXIT_FAILURE);
+ }
+
+ sz = qemu_opt_get_size(opts, "size", 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) {
+ error_report("too large 'size' option value");
+ 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);
+ error_report("ram size too large");
+ exit(EXIT_FAILURE);
}
break;
}
@@ -4051,10 +4096,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"), "size", ram_size);
if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
!= 0) {
--
1.8.5.2.229.g4448466
- Re: [Qemu-devel] [PATCH v3 31/34] qapi: make string output visitor parse int list, (continued)
- [Qemu-devel] [PATCH v3 02/34] NUMA: check if the total numa memory size is equal to ram_size, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 10/34] qmp: allow object-add completion handler to get canonical path, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 01/34] NUMA: move numa related code to new file numa.c, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 12/34] pc: pass QEMUMachineInitArgs to pc_memory_init, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 16/34] memory: reorganize file-based allocation, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 15/34] numa: add -numa node,memdev= option, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 09/34] vl: redo -object parsing, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 05/34] NUMA: expand MAX_NODES from 64 to 128, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 18/34] memory: add error propagation to file-based RAM allocation, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 08/34] vl: convert -m to QemuOpts,
address@hidden <=
- [Qemu-devel] [PATCH v3 14/34] add memdev backend infrastructure, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 21/34] hostmem: add file-based HostMemoryBackend, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 22/34] hostmem: separate allocation from UserCreatable complete method, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 26/34] configure: add Linux libnuma detection, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 24/34] hostmem: allow preallocation of any memory region, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 27/34] hostmem: add properties for NUMA memory policy, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 11/34] qmp: improve error reporting for -object and object-add, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 32/34] qom: introduce object_property_get_enum and object_property_get_uint16List, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 20/34] memory: move RAM_PREALLOC_MASK to exec.c, rename, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 25/34] hostmem: add property to map memory with MAP_SHARED, address@hidden, 2014/03/26