qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2.1 08/28] vl: convert -m to QemuOpts


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 2.1 08/28] vl: convert -m to QemuOpts
Date: Wed, 05 Mar 2014 11:31:59 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Il 05/03/2014 11:06, Andreas Färber ha scritto:
Am 04.03.2014 15:00, schrieb Paolo Bonzini:
From: Igor Mammedov <address@hidden>

Adds option to -m
 "mem" - startup memory amount

Sorry for jumping in late, but assuming that -m is for "memory" already,
wouldn't it make more sense to name it "size" instead of "mem"?

Sure.

Paolo


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>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
 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
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 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");

error_report(), in particular to fix "qemu: "

+                    exit(EXIT_FAILURE);
+                }
+                if (!*mem_str) {
+                    fprintf(stderr, "qemu: missing 'mem' option value\n");

error_report()

+                    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");

error_report()

+                        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");

error_report() while at it?

-                    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) {

Here's a dependency on the preceding patch - other than that, these two
could be applied independently of the rest via qemu-trivial?

Regards,
Andreas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]