Patchwork [v2,02/14] cmdline: implement -m with QemuOpts

login
register
mail settings
Submitter Paolo Bonzini
Date April 11, 2012, 9:34 p.m.
Message ID <1334180081-6172-3-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/151922/
State New
Headers show

Comments

Paolo Bonzini - April 11, 2012, 9:34 p.m.
This becomes -machine ram_size.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-config.c |    4 ++++
 vl.c          |   41 ++++++++++++-----------------------------
 2 files changed, 16 insertions(+), 29 deletions(-)

Patch

diff --git a/qemu-config.c b/qemu-config.c
index be84a03..6569acd 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -582,6 +582,10 @@  static QemuOptsList qemu_machine_opts = {
             .name = "dtb",
             .type = QEMU_OPT_STRING,
             .help = "Linux kernel device tree file",
+        }, {
+            .name = "ram_size",
+            .type = QEMU_OPT_SIZE,
+            .help = "RAM size",
         },
         { /* End of list */ }
     },
diff --git a/vl.c b/vl.c
index 0fccf50..ca5d5ec 100644
--- a/vl.c
+++ b/vl.c
@@ -2645,20 +2645,7 @@  int main(int argc, char **argv, char **envp)
                 exit(0);
                 break;
             case QEMU_OPTION_m: {
-                int64_t value;
-                char *end;
-
-                value = strtosz(optarg, &end);
-                if (value < 0 || *end) {
-                    fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
-                    exit(1);
-                }
-
-                if (value != (uint64_t)(ram_addr_t)value) {
-                    fprintf(stderr, "qemu: ram size too large\n");
-                    exit(1);
-                }
-                ram_size = value;
+                qemu_opts_set(qemu_find_opts("machine"), 0, "ram_size", optarg);
                 break;
             }
             case QEMU_OPTION_mempath:
@@ -3320,26 +3307,14 @@  int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
-    /* init the memory */
-    if (ram_size == 0) {
-        ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
-    }
-
-    configure_accelerator();
-
-    qemu_init_cpu_loop();
-    if (qemu_init_main_loop()) {
-        fprintf(stderr, "qemu_init_main_loop failed\n");
-        exit(1);
-    }
-
     machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
+    kernel_filename = initrd_filename = kernel_cmdline = NULL;
+    ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     if (machine_opts) {
+        ram_size = qemu_opt_get_size(machine_opts, "ram_size", ram_size);
         kernel_filename = qemu_opt_get(machine_opts, "kernel");
         initrd_filename = qemu_opt_get(machine_opts, "initrd");
         kernel_cmdline = qemu_opt_get(machine_opts, "append");
-    } else {
-        kernel_filename = initrd_filename = kernel_cmdline = NULL;
     }
 
     if (!kernel_cmdline) {
@@ -3363,6 +3338,14 @@  int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    configure_accelerator();
+
+    qemu_init_cpu_loop();
+    if (qemu_init_main_loop()) {
+        fprintf(stderr, "qemu_init_main_loop failed\n");
+        exit(1);
+    }
+
     os_set_line_buffering();
 
     if (init_timer_alarm() < 0) {