qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wanpeng Li <liwp@linux.vnet.ibm.com>
To: "Anthony Liguori" <aliguori@us.ibm.com>,
	"Stefan Hajnoczi" <stefanha@gmail.com>,
	"Andreas Färber" <afaerber@suse.de>,
	qemu-devel <qemu-devel@nongnu.org>
Cc: Wanpeng Li <liwp@linux.vnet.ibm.com>,
	Gavin Shan <shangw@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH] RFC: options parse in vl.c should be moduled
Date: Fri, 30 Mar 2012 20:36:43 +0800	[thread overview]
Message-ID: <1333111003-28556-1-git-send-email-liwp@linux.vnet.ibm.com> (raw)

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

             reply	other threads:[~2012-03-30 12:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-30 12:36 Wanpeng Li [this message]
2012-03-30 12:53 ` [Qemu-devel] [PATCH] RFC: options parse in vl.c should be moduled 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1333111003-28556-1-git-send-email-liwp@linux.vnet.ibm.com \
    --to=liwp@linux.vnet.ibm.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=shangw@linux.vnet.ibm.com \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).