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.

v2:
  make sure maxmem is not less than ram size

Signed-off-by: Igor Mammedov <imamm...@redhat.com>
---
 qemu-options.hx |    9 +++++++--
 vl.c            |   53 +++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 137a39b..f799b3d 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 bf0c658..16c6f1e 100644
--- a/vl.c
+++ b/vl.c
@@ -516,6 +516,27 @@ static QemuOptsList qemu_realtime_opts = {
     },
 };
 
+static QemuOptsList qemu_mem_opts = {
+    .name = "memory-opts",
+    .implied_opt_name = "mem",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
+    .desc = {
+        {
+            .name = "mem",
+            .type = QEMU_OPT_SIZE,
+        },
+        {
+            .name = "slots",
+            .type = QEMU_OPT_NUMBER,
+        },
+        {
+            .name = "maxmem",
+            .type = QEMU_OPT_SIZE,
+        },
+        { /* end of list */ }
+    },
+};
+
 const char *qemu_get_vm_name(void)
 {
     return qemu_name;
@@ -2933,6 +2954,7 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_object_opts);
     qemu_add_opts(&qemu_tpmdev_opts);
     qemu_add_opts(&qemu_realtime_opts);
+    qemu_add_opts(&qemu_mem_opts);
 
     runstate_init();
 
@@ -3224,21 +3246,40 @@ 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", 0), 8192);
                 ram_size = sz;
                 if (ram_size != sz) {
                     fprintf(stderr, "qemu: ram size too large\n");
                     exit(1);
                 }
+                /* store aligned value for future use */
+                s = g_strdup_printf("%" PRIu64, sz);
+                qemu_opt_set(opts, "mem", s);
+                g_free(s);
+
+                sz = qemu_opt_get_size(opts, "maxmem", ram_size);
+                if (sz < ram_size) {
+                    fprintf(stderr, "qemu: maxmem must be > initial memory\n");
+                    exit(1);
+                }
                 break;
             }
 #ifdef CONFIG_TPM
-- 
1.7.1


Reply via email to