qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] RFC: options parse in vl.c should be moduled
@ 2012-03-30 12:36 Wanpeng Li
  2012-03-30 12:53 ` Daniel P. Berrange
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Wanpeng Li @ 2012-03-30 12:36 UTC (permalink / raw)
  To: Anthony Liguori, Stefan Hajnoczi, Andreas Färber, qemu-devel
  Cc: Wanpeng Li, Gavin Shan

Consider of the options parse process in main function of vl.c is too
long.It should be module into single function to clear ideas, strengthen
the source code management, and increase code readability.So I module the 
process of options parse as function options_parse, and expose some variables
in order to not influence command-line invocations.

Signed-off-by: Wanpeng Li <liwp@linux.vnet.ibm.com>
---
 vl.c |  159 ++++++++++++++++++++++++++++++++++-------------------------------
 1 files changed, 83 insertions(+), 76 deletions(-)

diff --git a/vl.c b/vl.c
index 0fccf50..fa4d0a9 100644
--- a/vl.c
+++ b/vl.c
@@ -2251,84 +2251,40 @@ int qemu_init_main_loop(void)
     return main_loop_init();
 }
 
-int main(int argc, char **argv, char **envp)
-{
-    int i;
-    int snapshot, linux_boot;
-    const char *icount_option = NULL;
-    const char *initrd_filename;
-    const char *kernel_filename, *kernel_cmdline;
-    char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
-    DisplayState *ds;
-    DisplayChangeListener *dcl;
-    int cyls, heads, secs, translation;
-    QemuOpts *hda_opts = NULL, *opts, *machine_opts;
-    QemuOptsList *olist;
-    int optind;
-    const char *optarg;
-    const char *loadvm = NULL;
-    QEMUMachine *machine;
-    const char *cpu_model;
-    const char *vga_model = NULL;
-    const char *pid_file = NULL;
-    const char *incoming = NULL;
+int snapshot, linux_boot;
+const char *icount_option;
+const char *initrd_filename;
+const char *kernel_filename, *kernel_cmdline;
+char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
+DisplayState *ds;
+DisplayChangeListener *dcl;
+int cyls, heads, secs, translation;
+QemuOpts *hda_opts , *opts, *machine_opts;
+QemuOptsList *olist;
+int optind;
+const char *loadvm;
+QEMUMachine *machine;
+const char *cpu_model;
+const char *vga_model;
+const char *pid_file;
+const char *incoming;
 #ifdef CONFIG_VNC
-    int show_vnc_port = 0;
+int show_vnc_port;
 #endif
-    int defconfig = 1;
-    const char *log_mask = NULL;
-    const char *log_file = NULL;
-    GMemVTable mem_trace = {
-        .malloc = malloc_and_trace,
-        .realloc = realloc_and_trace,
-        .free = free_and_trace,
-    };
-    const char *trace_events = NULL;
-    const char *trace_file = NULL;
-
-    atexit(qemu_run_exit_notifiers);
-    error_set_progname(argv[0]);
-
-    g_mem_set_vtable(&mem_trace);
-    if (!g_thread_supported()) {
-#if !GLIB_CHECK_VERSION(2, 31, 0)
-        g_thread_init(NULL);
-#else
-        fprintf(stderr, "glib threading failed to initialize.\n");
-        exit(1);
-#endif
-    }
-
-    module_call_init(MODULE_INIT_QOM);
-
-    runstate_init();
-
-    init_clocks();
-    rtc_clock = host_clock;
-
-    qemu_cache_utils_init(envp);
-
-    QLIST_INIT (&vm_change_state_head);
-    os_setup_early_signal_handling();
-
-    module_call_init(MODULE_INIT_MACHINE);
-    machine = find_default_machine();
-    cpu_model = NULL;
-    ram_size = 0;
-    snapshot = 0;
-    cyls = heads = secs = 0;
-    translation = BIOS_ATA_TRANSLATION_AUTO;
-
-    for (i = 0; i < MAX_NODES; i++) {
-        node_mem[i] = 0;
-        node_cpumask[i] = 0;
-    }
-
-    nb_numa_nodes = 0;
-    nb_nics = 0;
-
-    autostart= 1;
+int defconfig = 1;
+const char *log_mask;
+const char *log_file;
+GMemVTable mem_trace = {
+    .malloc = malloc_and_trace,
+    .realloc = realloc_and_trace,
+    .free = free_and_trace,
+};
+const char *trace_events;
+const char *trace_file;
 
+static void options_parse(int argc, char **argv)
+{
+    const char *optarg;
     /* first pass of option parsing */
     optind = 1;
     while (optind < argc) {
@@ -2867,7 +2823,7 @@ int main(int argc, char **argv, char **envp)
                 if (watchdog) {
                     fprintf(stderr,
                             "qemu: only one watchdog option may be given\n");
-                    return 1;
+                    exit(1);
                 }
                 watchdog = optarg;
                 break;
@@ -3186,6 +3142,57 @@ int main(int argc, char **argv, char **envp)
             }
         }
     }
+}
+
+int main(int argc, char **argv, char **envp)
+{
+    int i;
+
+    atexit(qemu_run_exit_notifiers);
+    error_set_progname(argv[0]);
+
+    g_mem_set_vtable(&mem_trace);
+    if (!g_thread_supported()) {
+#if !GLIB_CHECK_VERSION(2, 31, 0)
+        g_thread_init(NULL);
+#else
+        fprintf(stderr, "glib threading failed to initialize.\n");
+        exit(1);
+#endif
+    }
+
+    module_call_init(MODULE_INIT_QOM);
+
+    runstate_init();
+
+    init_clocks();
+    rtc_clock = host_clock;
+
+    qemu_cache_utils_init(envp);
+
+    QLIST_INIT(&vm_change_state_head);
+    os_setup_early_signal_handling();
+
+    module_call_init(MODULE_INIT_MACHINE);
+    machine = find_default_machine();
+    cpu_model = NULL;
+    ram_size = 0;
+    snapshot = 0;
+    cyls = heads = secs = 0;
+    translation = BIOS_ATA_TRANSLATION_AUTO;
+
+    for (i = 0; i < MAX_NODES; i++) {
+        node_mem[i] = 0;
+        node_cpumask[i] = 0;
+    }
+
+    nb_numa_nodes = 0;
+    nb_nics = 0;
+
+    autostart = 1;
+
+    options_parse(argc, argv);
+
     loc_set_none();
 
     /* Init CPU def lists, based on config
-- 
1.7.5.4

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

end of thread, other threads:[~2012-03-30 17:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-30 12:36 [Qemu-devel] [PATCH] RFC: options parse in vl.c should be moduled Wanpeng Li
2012-03-30 12:53 ` Daniel P. Berrange
2012-03-30 13:25   ` Wanpeng Li
     [not found]   ` <4f75b5f3.2235b60a.302d.ffffa586SMTPIN_ADDED@mx.google.com>
2012-03-30 15:55     ` Michael Roth
2012-03-30 13:10 ` Anthony Liguori
2012-03-30 15:59 ` Lluís Vilanova
2012-03-30 16:09   ` Anthony Liguori
2012-03-30 16:31     ` Anthony Liguori
2012-03-30 17:52       ` Lluís Vilanova

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