qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/2] convert -m to QemuOpts
@ 2014-03-05 16:10 Igor Mammedov
  2014-03-05 16:10 ` [Qemu-devel] [PATCH v3 1/2] qemu-option: introduce qemu_find_opts_singleton Igor Mammedov
  2014-03-05 16:10 ` [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts Igor Mammedov
  0 siblings, 2 replies; 7+ messages in thread
From: Igor Mammedov @ 2014-03-05 16:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, stefanha, qemu-trivial, coreyb, mjt, mreitz, aliguori,
	pbonzini, lcapitulino, imammedo, akong, lersek, afaerber


changes since v2 suggested by Andreas Färber:
 - s/fprintf/error_report/
 - rename 'mem' option to 'size'
 - CCing to qemu-trivial

changes since v1:
 - check for overflow
 - check for empty mem="" case
 - reshuffle code to avoid conflicts with another series on list
 - some style/typo fixes

changes since RFC:
 - resolved conflict with error_abort change
   in qemu_get_machine_opts()


Igor Mammedov (1):
  vl: convert -m to QemuOpts

Paolo Bonzini (1):
  qemu-option: introduce qemu_find_opts_singleton

 include/qemu/config-file.h |    2 +
 qemu-options.hx            |    9 +++--
 util/qemu-config.c         |   14 +++++++
 vl.c                       |   82 +++++++++++++++++++++++++++++++-------------
 4 files changed, 80 insertions(+), 27 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH v3 1/2] qemu-option: introduce qemu_find_opts_singleton
  2014-03-05 16:10 [Qemu-devel] [PATCH v3 0/2] convert -m to QemuOpts Igor Mammedov
@ 2014-03-05 16:10 ` Igor Mammedov
  2014-03-05 16:10 ` [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts Igor Mammedov
  1 sibling, 0 replies; 7+ messages in thread
From: Igor Mammedov @ 2014-03-05 16:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, stefanha, qemu-trivial, coreyb, mjt, mreitz, aliguori,
	pbonzini, lcapitulino, imammedo, akong, lersek, afaerber

From: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 include/qemu/config-file.h |    2 ++
 util/qemu-config.c         |   14 ++++++++++++++
 vl.c                       |   11 +----------
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h
index dbd97c4..d4ba20e 100644
--- a/include/qemu/config-file.h
+++ b/include/qemu/config-file.h
@@ -8,6 +8,8 @@
 
 QemuOptsList *qemu_find_opts(const char *group);
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
+QemuOpts *qemu_find_opts_singleton(const char *group);
+
 void qemu_add_opts(QemuOptsList *list);
 void qemu_add_drive_opts(QemuOptsList *list);
 int qemu_set_option(const char *str);
diff --git a/util/qemu-config.c b/util/qemu-config.c
index f610101..60051df 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -39,6 +39,20 @@ QemuOptsList *qemu_find_opts(const char *group)
     return ret;
 }
 
+QemuOpts *qemu_find_opts_singleton(const char *group)
+{
+    QemuOptsList *list;
+    QemuOpts *opts;
+
+    list = qemu_find_opts(group);
+    assert(list);
+    opts = qemu_opts_find(list, NULL);
+    if (!opts) {
+        opts = qemu_opts_create(list, NULL, 0, &error_abort);
+    }
+    return opts;
+}
+
 static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
 {
     CommandLineParameterInfoList *param_list = NULL, *entry;
diff --git a/vl.c b/vl.c
index 685a7a9..7eb3b73 100644
--- a/vl.c
+++ b/vl.c
@@ -482,16 +482,7 @@ static QemuOptsList qemu_msg_opts = {
  */
 QemuOpts *qemu_get_machine_opts(void)
 {
-    QemuOptsList *list;
-    QemuOpts *opts;
-
-    list = qemu_find_opts("machine");
-    assert(list);
-    opts = qemu_opts_find(list, NULL);
-    if (!opts) {
-        opts = qemu_opts_create(list, NULL, 0, &error_abort);
-    }
-    return opts;
+    return qemu_find_opts_singleton("machine");
 }
 
 const char *qemu_get_vm_name(void)
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts
  2014-03-05 16:10 [Qemu-devel] [PATCH v3 0/2] convert -m to QemuOpts Igor Mammedov
  2014-03-05 16:10 ` [Qemu-devel] [PATCH v3 1/2] qemu-option: introduce qemu_find_opts_singleton Igor Mammedov
@ 2014-03-05 16:10 ` Igor Mammedov
  2014-03-05 17:04   ` Andreas Färber
  2014-03-05 20:33   ` Eric Blake
  1 sibling, 2 replies; 7+ messages in thread
From: Igor Mammedov @ 2014-03-05 16:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, stefanha, qemu-trivial, coreyb, mjt, mreitz, aliguori,
	pbonzini, lcapitulino, imammedo, akong, lersek, afaerber

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 <imammedo@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
v2:
 - suggested by Andreas Färber <afaerber@suse.de>
    * s/fprintf/error_report/
    * rename 'mem' option to 'size'
 - fix conflict with missing numa QemuOpts
---
 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 56e5fdf..5e89e0d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -210,10 +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 [size=]megs\n"
+    "                configure guest RAM\n"
+    "                size: initial amount of guest memory (default: "
+    stringify(DEFAULT_RAM_SIZE) "MiB)\n",
+    QEMU_ARCH_ALL)
 STEXI
-@item -m @var{megs}
+@item -m [size=]@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 7eb3b73..72235c5 100644
--- a/vl.c
+++ b/vl.c
@@ -475,6 +475,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
  *
@@ -2835,6 +2849,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]);
@@ -2866,6 +2882,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);
@@ -2889,7 +2906,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;
@@ -3176,20 +3193,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, "mem");
+                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, "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) {
+                        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;
             }
@@ -4034,10 +4079,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) {
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts
  2014-03-05 16:10 ` [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts Igor Mammedov
@ 2014-03-05 17:04   ` Andreas Färber
  2014-03-06  9:37     ` Igor Mammedov
  2014-03-05 20:33   ` Eric Blake
  1 sibling, 1 reply; 7+ messages in thread
From: Andreas Färber @ 2014-03-05 17:04 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel
  Cc: kwolf, aliguori, qemu-trivial, coreyb, mjt, mreitz, stefanha,
	lcapitulino, pbonzini, akong, lersek

Am 05.03.2014 17:10, schrieb Igor Mammedov:
> 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 <imammedo@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> v2:
>  - suggested by Andreas Färber <afaerber@suse.de>
>     * s/fprintf/error_report/
>     * rename 'mem' option to 'size'
>  - fix conflict with missing numa QemuOpts
> ---
>  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 56e5fdf..5e89e0d 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -210,10 +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 [size=]megs\n"
> +    "                configure guest RAM\n"
> +    "                size: initial amount of guest memory (default: "
> +    stringify(DEFAULT_RAM_SIZE) "MiB)\n",
> +    QEMU_ARCH_ALL)
>  STEXI
> -@item -m @var{megs}
> +@item -m [size=]@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 7eb3b73..72235c5 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -475,6 +475,20 @@ static QemuOptsList qemu_msg_opts = {
>      },
>  };
>  
> +static QemuOptsList qemu_mem_opts = {
> +    .name = "memory",
> +    .implied_opt_name = "mem",

"size"

> +    .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
> +    .merge_lists = true,
> +    .desc = {
> +        {
> +            .name = "mem",

"size"

> +            .type = QEMU_OPT_SIZE,
> +        },
> +        { /* end of list */ }
> +    },
> +};
> +
>  /**
>   * Get machine options
>   *
> @@ -2835,6 +2849,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]);
> @@ -2866,6 +2882,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);
> @@ -2889,7 +2906,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;
> @@ -3176,20 +3193,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, "mem");

"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, "mem", ram_size);

"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;
>              }
> @@ -4034,10 +4079,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);

"size"

>  
>      if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
>          != 0) {

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts
  2014-03-05 16:10 ` [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts Igor Mammedov
  2014-03-05 17:04   ` Andreas Färber
@ 2014-03-05 20:33   ` Eric Blake
  2014-03-06  9:37     ` Igor Mammedov
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Blake @ 2014-03-05 20:33 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel
  Cc: kwolf, aliguori, qemu-trivial, coreyb, mjt, mreitz, stefanha,
	lcapitulino, pbonzini, akong, lersek, afaerber

[-- Attachment #1: Type: text/plain, Size: 982 bytes --]

On 03/05/2014 09:10 AM, Igor Mammedov wrote:
> 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 <imammedo@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> v2:
>  - suggested by Andreas Färber <afaerber@suse.de>
>     * s/fprintf/error_report/
>     * rename 'mem' option to 'size'
>  - fix conflict with missing numa QemuOpts

Given the amount of rework in v2, it may have been smarter to drop my
R-b tag.  But beyond Andreas' findings of missing s/mem/size/ instances,
I'm not spotting any problems, so if that's the only fix you make for
v4, you can keep my R-b.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts
  2014-03-05 17:04   ` Andreas Färber
@ 2014-03-06  9:37     ` Igor Mammedov
  0 siblings, 0 replies; 7+ messages in thread
From: Igor Mammedov @ 2014-03-06  9:37 UTC (permalink / raw)
  To: Andreas Färber
  Cc: kwolf, akong, stefanha, qemu-trivial, coreyb, mjt, qemu-devel,
	mreitz, aliguori, pbonzini, lcapitulino, lersek

On Wed, 05 Mar 2014 18:04:23 +0100
Andreas Färber <afaerber@suse.de> wrote:

> Am 05.03.2014 17:10, schrieb Igor Mammedov:
> > 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 <imammedo@redhat.com>
> > Reviewed-by: Eric Blake <eblake@redhat.com>
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> > v2:
> >  - suggested by Andreas Färber <afaerber@suse.de>
> >     * s/fprintf/error_report/
> >     * rename 'mem' option to 'size'
> >  - fix conflict with missing numa QemuOpts
> > ---
> >  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 56e5fdf..5e89e0d 100644
> > --- a/qemu-options.hx
> > +++ b/qemu-options.hx
> > @@ -210,10 +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 [size=]megs\n"
> > +    "                configure guest RAM\n"
> > +    "                size: initial amount of guest memory (default: "
> > +    stringify(DEFAULT_RAM_SIZE) "MiB)\n",
> > +    QEMU_ARCH_ALL)
> >  STEXI
> > -@item -m @var{megs}
> > +@item -m [size=]@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 7eb3b73..72235c5 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -475,6 +475,20 @@ static QemuOptsList qemu_msg_opts = {
> >      },
> >  };
> >  
> > +static QemuOptsList qemu_mem_opts = {
> > +    .name = "memory",
> > +    .implied_opt_name = "mem",
> 
> "size"
> 
> > +    .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
> > +    .merge_lists = true,
> > +    .desc = {
> > +        {
> > +            .name = "mem",
> 
> "size"
> 
> > +            .type = QEMU_OPT_SIZE,
> > +        },
> > +        { /* end of list */ }
> > +    },
> > +};
> > +
> >  /**
> >   * Get machine options
> >   *
> > @@ -2835,6 +2849,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]);
> > @@ -2866,6 +2882,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);
> > @@ -2889,7 +2906,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;
> > @@ -3176,20 +3193,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, "mem");
> 
> "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, "mem", ram_size);
> 
> "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;
> >              }
> > @@ -4034,10 +4079,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);
> 
> "size"
> 
> >  
> >      if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
> >          != 0) {

Thanks for review and I'm sorry for silly mistakes,
I'll fix and resubmit it as v4 (tested this time).

> Regards,
> Andreas
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts
  2014-03-05 20:33   ` Eric Blake
@ 2014-03-06  9:37     ` Igor Mammedov
  0 siblings, 0 replies; 7+ messages in thread
From: Igor Mammedov @ 2014-03-06  9:37 UTC (permalink / raw)
  To: Eric Blake
  Cc: kwolf, akong, stefanha, qemu-trivial, coreyb, mjt, qemu-devel,
	mreitz, aliguori, pbonzini, lcapitulino, lersek, afaerber

On Wed, 05 Mar 2014 13:33:43 -0700
Eric Blake <eblake@redhat.com> wrote:

> On 03/05/2014 09:10 AM, Igor Mammedov wrote:
> > 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 <imammedo@redhat.com>
> > Reviewed-by: Eric Blake <eblake@redhat.com>
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> > v2:
> >  - suggested by Andreas Färber <afaerber@suse.de>
> >     * s/fprintf/error_report/
> >     * rename 'mem' option to 'size'
> >  - fix conflict with missing numa QemuOpts
> 
> Given the amount of rework in v2, it may have been smarter to drop my
> R-b tag.  But beyond Andreas' findings of missing s/mem/size/ instances,
> I'm not spotting any problems, so if that's the only fix you make for
> v4, you can keep my R-b.
> 
Thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-03-06 10:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-05 16:10 [Qemu-devel] [PATCH v3 0/2] convert -m to QemuOpts Igor Mammedov
2014-03-05 16:10 ` [Qemu-devel] [PATCH v3 1/2] qemu-option: introduce qemu_find_opts_singleton Igor Mammedov
2014-03-05 16:10 ` [Qemu-devel] [PATCH v3 2/2] vl: convert -m to QemuOpts Igor Mammedov
2014-03-05 17:04   ` Andreas Färber
2014-03-06  9:37     ` Igor Mammedov
2014-03-05 20:33   ` Eric Blake
2014-03-06  9:37     ` Igor Mammedov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).