qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] RFC: options parse in vl.c should be moduled


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH] RFC: options parse in vl.c should be moduled
Date: Fri, 30 Mar 2012 11:09:29 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120310 Thunderbird/11.0

On 03/30/2012 10:59 AM, Lluís Vilanova wrote:
Wanpeng Li writes:

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.

Another approach would be to use something similar to QOM type registration.

In order to keep code to a minimum, you can define an array of pointers to
QParameter structures, instead of an array of function pointers (what
__attribute__((constructors)) does).

So, for example:

     static void opt_icount_handler(const char *args)
     {
         if (kvm_enabled() || xen_enabled()) {
             fprintf(stderr, "-icount is not allowed with kvm or xen\n");
             exit(1);
         }
         /* ... contents of configure_icount ... */
     }

     static QEMUOption opt_icount = {
        .name = "icount",
        .signature = "[N|auto]",
        .help = "enable virtual instruction counter with 2^N clock ticks per 
instruction",
        .mode = QEMU_MODE_SYSTEM,
        .priority = QEMU_OPT_PRIO_BEFORE_DEVICES,
        .section = QEMU_OPT_SECTION_DEBUG,
        .handler = opt_icount_handler
     };

     param_register(opt_icount);


Here, param_register would define an array of pointers to QEMUOption structures,
although I'm not sure how this can be handled on formats other than ELF.

My plan is to have a -query-capabilities so we can change the help text, then use GOptionContext.

It would take a small function that goes through and promotes any option in the format '-foo' to '--foo'. But that's not too hard.

Then we can completely rip out the option parsing, qemu-options.hx, and all of that other junk.

Regards,

Anthony Liguori



reply via email to

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