Il 27/11/2013 01:27, Igor Mammedov ha scritto: > 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 <imamm...@redhat.com> > --- > qemu-options.hx | 7 +++++-- > vl.c | 53 ++++++++++++++++++++++++++++++++++++++++++----------- > 2 files changed, 47 insertions(+), 13 deletions(-) > > diff --git a/qemu-options.hx b/qemu-options.hx > index 8b94264..d923995 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -210,8 +210,11 @@ 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) "Mb)\n", > + QEMU_ARCH_ALL) > STEXI > @item -m @var{megs} > @findex -m > diff --git a/vl.c b/vl.c > index f28674f..44cc4ed 100644 > --- a/vl.c > +++ b/vl.c > @@ -529,6 +529,20 @@ static QemuOptsList qemu_msg_opts = { > }, > }; > > +static QemuOptsList qemu_mem_opts = { > + .name = "memory-opts", > + .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 > * > @@ -2852,6 +2866,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 = DEFAULT_RAM_SIZE * 1024 * 1024; > > atexit(qemu_run_exit_notifiers); > error_set_progname(argv[0]); > @@ -2887,6 +2902,8 @@ int main(int argc, char **argv, char **envp) > qemu_add_opts(&qemu_tpmdev_opts); > qemu_add_opts(&qemu_realtime_opts); > qemu_add_opts(&qemu_msg_opts); > + qemu_add_opts(&qemu_mem_opts); > + qemu_opts_create_nofail(&qemu_mem_opts); > > runstate_init(); > > @@ -2901,7 +2918,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; > @@ -3178,16 +3195,32 @@ 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); > + opts = qemu_opts_parse(qemu_find_opts("memory-opts"), > + optarg, 1); > + > + mem_str = qemu_opt_get(opts, "mem"); > + if (!mem_str) { > + fprintf(stderr, "qemu: invalid -m option, missing " > + " 'mem' option\n"); > exit(1); > } > - sz = QEMU_ALIGN_UP((uint64_t)value, 8192); > + > + 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])) { > + sz <<= 20; > + } > + > + /* backward compatibility behaviour for case "-m 0" */ > + if (sz == 0) { > + sz = default_ram_size; > + } > + > + sz = QEMU_ALIGN_UP(sz, 8192); > ram_size = sz; > if (ram_size != sz) { > fprintf(stderr, "qemu: ram size too large\n"); > @@ -4029,10 +4062,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(opts, "mem", ram_size); > > if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, > 0) > != 0) { >
I'm applying this patch and "qapi: add SIZE type parser to string_input_visitor", to include them in the same pull request as Wanlong Gao's first batch of NUMA patches. Paolo