[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse()
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse() |
Date: |
Mon, 25 Nov 2013 13:51:03 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130923 Thunderbird/17.0.9 |
Il 21/11/2013 03:38, Igor Mammedov ha scritto:
> Along with conversion extend -m option to support following parameters:
> "mem" - startup memory amount
> "slots" - total number of hotplug memory slots
> "maxmem" - maximum possible memory
>
> "slots" and "maxmem" should go in pair and "maxmem" should be greater
> than "mem" for memory hotplug to be usable.
Strictly speaking, slots and maxmem should be added later, not in this
patch. Not a blocker, though.
Paolo
> v2:
> make sure maxmem is not less than ram size
>
> Signed-off-by: Igor Mammedov <address@hidden>
> ---
> qemu-options.hx | 9 +++++-
> vl.c | 73
> ++++++++++++++++++++++++++++++++++++++++++++++---------
> 2 files changed, 68 insertions(+), 14 deletions(-)
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 8b94264..fe4559b 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -210,8 +210,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[,slots=n,maxmem=size]\n"
> + " set virtual RAM size to megs MB [default="
> + stringify(DEFAULT_RAM_SIZE) "]\n"
> + " mem=start-up memory amount\n"
> + " slots=maximum number of hotplug slots\n"
> + " maxmem=maximum total amount of memory\n",
> + QEMU_ARCH_ALL)
> STEXI
> @item -m @var{megs}
> @findex -m
> diff --git a/vl.c b/vl.c
> index f28674f..5974f0f 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -529,6 +529,28 @@ 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,
> + },
> + {
> + .name = "slots",
> + .type = QEMU_OPT_NUMBER,
> + },
> + {
> + .name = "maxmem",
> + .type = QEMU_OPT_SIZE,
> + },
> + { /* end of list */ }
> + },
> +};
> +
> /**
> * Get machine options
> *
> @@ -2816,6 +2838,14 @@ static int object_create(QemuOpts *opts, void *opaque)
> return 0;
> }
>
> +static void qemu_init_default_mem_opts(uint64_t size)
> +{
> + QemuOpts *opts = qemu_opts_create_nofail(&qemu_mem_opts);
> + qemu_opt_set_number(opts, "mem", size);
> + qemu_opt_set_number(opts, "maxmem", size);
> + qemu_opt_set_number(opts, "slots", 0);
> +}
> +
> int main(int argc, char **argv, char **envp)
> {
> int i;
> @@ -2887,6 +2917,7 @@ 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);
>
> runstate_init();
>
> @@ -2901,7 +2932,8 @@ 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 * 1024 * 1024;
> + qemu_init_default_mem_opts(ram_size);
> snapshot = 0;
> cyls = heads = secs = 0;
> translation = BIOS_ATA_TRANSLATION_AUTO;
> @@ -3178,21 +3210,43 @@ 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 *end;
> + char *s;
>
> - 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);
> + if (!opts) {
> exit(1);
> }
> - sz = QEMU_ALIGN_UP((uint64_t)value, 8192);
> +
> + /* fixup legacy sugffix-less format */
> + end = qemu_opt_get(opts, "mem");
> + if (g_ascii_isdigit(end[strlen(end) - 1])) {
> + s = g_strconcat(end, "M", NULL);
> + qemu_opt_set(opts, "mem", s);
> + g_free(s);
> + }
> +
> + sz = QEMU_ALIGN_UP(qemu_opt_get_size(opts, "mem", ram_size),
> + 8192);
> + /* compatibility behaviour for case "-m 0" */
> + if (sz == 0) {
> + sz = DEFAULT_RAM_SIZE * 1024 * 1024;
> + }
> +
> ram_size = sz;
> if (ram_size != sz) {
> fprintf(stderr, "qemu: ram size too large\n");
> exit(1);
> }
> + /* store aligned value for future use */
> + qemu_opt_set_number(opts, "mem", ram_size);
> +
> + sz = qemu_opt_get_size(opts, "maxmem", ram_size);
> + if (sz < ram_size) {
> + qemu_opt_set_number(opts, "maxmem", ram_size);
> + }
> break;
> }
> #ifdef CONFIG_TPM
> @@ -4029,11 +4083,6 @@ int main(int argc, char **argv, char **envp)
> exit(1);
> }
>
> - /* init the memory */
> - if (ram_size == 0) {
> - ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
> - }
> -
> if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL,
> 0)
> != 0) {
> exit(0);
>
- [Qemu-devel] [PATCH 03/27] pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS, (continued)
- [Qemu-devel] [PATCH 03/27] pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS, Igor Mammedov, 2013/11/20
- [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse(), Igor Mammedov, 2013/11/20
- Re: [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse(), Li Guang, 2013/11/21
- Re: [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse(), Markus Armbruster, 2013/11/21
- Re: [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse(), Igor Mammedov, 2013/11/26
- Re: [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse(), Markus Armbruster, 2013/11/26
- Re: [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse(), Igor Mammedov, 2013/11/26
- [Qemu-devel] [PATCH 04/28] vl: convert -m to QemuOpts, Igor Mammedov, 2013/11/26
- [Qemu-devel] [PATCH 05/28] vl.c: extend -m option to support options for memory hotplug, Igor Mammedov, 2013/11/26
Re: [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse(),
Paolo Bonzini <=
[Qemu-devel] [PATCH 02/27] rename pci_hotplug_fn to hotplug_fn and make it available for other devices, Igor Mammedov, 2013/11/20
[Qemu-devel] [PATCH 05/27] qapi: add SIZE type parser to string_input_visitor, Igor Mammedov, 2013/11/20