qemu-options: introduce functions to parse options
PATCH 1/3 qemu-options: introduce functions to parse options
From: w00506750 <[email protected]>
All of the qemu options are parsed in qemu_init function, and make qemu_init function too long and nasty. Introduce 'parser' function pointer in QEMUOption struct to parse one option or a set of options.
Signed-off-by Hogan Wang <[email protected]>
--- qemu-options-wrapper.h | 10 +++++----- qemu-options.hx | 12 ++++++++---- softmmu/vl.c | 33 +++++++++++++++++---------------- 3 files changed, 30 insertions(+), 25 deletions(-)
qemu-options-wrapper.h +5 -5
@@ -1,15 +1,15 @@#if defined(QEMU_OPTIONS_GENERATE_ENUM ) -#define DEF (option, opt_arg, opt_enum, opt_help, arch_mask) \ +#define DEF (option, opt_arg, opt_enum, opt_help, arch_mask, ...) \ opt_enum,#define DEFHEADING (text)#define ARCHHEADING (text, arch_mask)#elif defined(QEMU_OPTIONS_GENERATE_HELP ) -#define DEF (option, opt_arg, opt_enum, opt_help, arch_mask) \ - if ((arch_mask) & arch_type) \ +#define DEF (option, opt_arg, opt_enum, opt_help, arch_mask, ...) \ + if ((arch_mask) & arch_type) \ fputs(opt_help, stdout);#define ARCHHEADING (text, arch_mask) \
@@ -20,8 +20,8 @@#elif defined(QEMU_OPTIONS_GENERATE_OPTIONS ) -#define DEF (option, opt_arg, opt_enum, opt_help, arch_mask) \ - { option, opt_arg, opt_enum, arch_mask }, +#define DEF (option, opt_arg, opt_enum, opt_help, arch_mask, ...) \ + { option, opt_arg, opt_enum, arch_mask, __VA_ARGS__},#define DEFHEADING (text)#define ARCHHEADING (text, arch_mask)
qemu-options.hx +8 -4
@@ -3352,7 +3352,8 @@ testing of various kernels. ERST DEF("kernel", HAS_ARG, QEMU_OPTION_kernel, \ - "-kernel bzImage use 'bzImage' as kernel image\n", QEMU_ARCH_ALL) + "-kernel bzImage use 'bzImage' as kernel image\n", QEMU_ARCH_ALL, \ + parse_linux_boot) SRST ``-kernel bzImage`` Use bzImage as kernel image. The kernel can be either a Linux kernel
@@ -3360,14 +3361,16 @@ SRST ERST DEF("append", HAS_ARG, QEMU_OPTION_append, \ - "-append cmdline use 'cmdline' as kernel command line\n", QEMU_ARCH_ALL) + "-append cmdline use 'cmdline' as kernel command line\n", QEMU_ARCH_ALL, \ + parse_linux_boot) SRST ``-append cmdline`` Use cmdline as kernel command line ERST DEF("initrd", HAS_ARG, QEMU_OPTION_initrd, \ - "-initrd file use 'file' as initial ram disk\n", QEMU_ARCH_ALL) + "-initrd file use 'file' as initial ram disk\n", QEMU_ARCH_ALL, \ + parse_linux_boot) SRST ``-initrd file`` Use file as initial ram disk.
@@ -3380,7 +3383,8 @@ SRST ERST DEF("dtb", HAS_ARG, QEMU_OPTION_dtb, \ - "-dtb file use 'file' as device tree image\n", QEMU_ARCH_ALL) + "-dtb file use 'file' as device tree image\n", QEMU_ARCH_ALL, \ + parse_linux_boot) SRST ``-dtb file`` Use file as a device tree binary (dtb) image and pass it to the
softmmu/vl.c +17 -16
@@ -1715,8 +1715,16 @@ typedef struct QEMUOption {int flags;int index;uint32_t arch_mask; +int (*parser)(const struct QEMUOption *popt,const char * optarg); } QEMUOption; +static int parse_linux_boot (const QEMUOption *popt,const char * optarg) +{ +qemu_opts_set (qemu_find_opts ("machine" ),NULL , popt->name, optarg, + &error_abort); +return 0 ; +} +static const QEMUOption qemu_options[] = { {"h" ,0 , QEMU_OPTION_h,QEMU_ARCH_ALL }, #define QEMU_OPTIONS_GENERATE_OPTIONS
@@ -2981,6 +2989,15 @@ void qemu_init(int argc, char **argv, char **envp)error_report ("Option not supported for this target" );exit (1 ); } + +if (popt->parser) { +if (popt->parser (popt, optarg)) { +error_report ("Parser '%s' option error" , popt->name); +exit (1 ); + } +continue ; + } +switch (popt->index) {case QEMU_OPTION_cpu:/* hw initialization will check this */
@@ -3075,22 +3092,6 @@ void qemu_init(int argc, char **argv, char **envp)exit (1 ); }break ; -case QEMU_OPTION_kernel: -qemu_opts_set (qemu_find_opts ("machine" ),NULL ,"kernel" , optarg, - &error_abort); -break ; -case QEMU_OPTION_initrd: -qemu_opts_set (qemu_find_opts ("machine" ),NULL ,"initrd" , optarg, - &error_abort); -break ; -case QEMU_OPTION_append: -qemu_opts_set (qemu_find_opts ("machine" ),NULL ,"append" , optarg, - &error_abort); -break ; -case QEMU_OPTION_dtb: -qemu_opts_set (qemu_find_opts ("machine" ),NULL ,"dtb" , optarg, - &error_abort); -break ;case QEMU_OPTION_cdrom:drive_add (IF_DEFAULT ,2 , optarg,CDROM_OPTS );break ;
Signature · 1 line
2.27.0
PATCH 2/3 qemu-options: introduce parse_net_client
From: w00506750 <[email protected]>
introduce parse_net_client to parse netdev/nic/net clients.
Signed-off-by Hogan Wang <[email protected]>
--- include/net/net.h | 1 - net/net.c | 9 --------- qemu-options.hx | 8 +++++--- softmmu/vl.c | 30 ++++++++++++------------------ 4 files changed, 17 insertions(+), 31 deletions(-)
include/net/net.h +0 -1
@@ -198,7 +198,6 @@ extern NICInfo nd_table[MAX_NICS];extern const char *host_net_devices[];/* from net.c */ -int net_client_parse (QemuOptsList *opts_list,const char *str);int net_init_clients (Error **errp);void net_check_clients (void );void net_cleanup (void );
net/net.c +0 -9
@@ -1507,15 +1507,6 @@ int net_init_clients(Error **errp)return 0 ; } -int net_client_parse (QemuOptsList *opts_list,const char *optarg) -{ -if (!qemu_opts_parse_noisily (opts_list, optarg, true)) { -return -1 ; - } - -return 0 ; -} -/* From FreeBSD */ /* XXX: optimize */ uint32_t net_crc32 (const uint8_t *p,int len)
qemu-options.hx +5 -3
@@ -2433,7 +2433,8 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, " configure a vhost-vdpa network,Establish a vhost-vdpa netdev\n" #endif "-netdev hubport,id=str,hubid=n[,netdev=nd]\n" - " configure a hub port on the hub with ID 'n'\n", QEMU_ARCH_ALL) + " configure a hub port on the hub with ID 'n'\n", QEMU_ARCH_ALL, \ + parse_net_client) DEF("nic", HAS_ARG, QEMU_OPTION_nic, "-nic [tap|bridge|" #ifdef CONFIG_SLIRP
@@ -2456,7 +2457,7 @@ DEF("nic", HAS_ARG, QEMU_OPTION_nic, " macaddr) and connect it to the given host network backend\n" "-nic none use it alone to have zero network devices (the default is to\n" " provided a 'user' network connection)\n", - QEMU_ARCH_ALL) + QEMU_ARCH_ALL, parse_net_client) DEF("net", HAS_ARG, QEMU_OPTION_net, "-net nic[,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n" " configure or create an on-board (or machine default) NIC and\n"
@@ -2475,7 +2476,8 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, #endif "socket][,option][,option][,...]\n" " old way to initialize a host network interface\n" - " (use the -netdev option if possible instead)\n", QEMU_ARCH_ALL) + " (use the -netdev option if possible instead)\n", QEMU_ARCH_ALL, \ + parse_net_client) SRST ``-nic [tap|bridge|user|l2tpv3|vde|netmap|vhost-user|socket][,...][,mac=macaddr][,model=mn]`` This option is a shortcut for configuring both the on-board
softmmu/vl.c +12 -18
@@ -1725,6 +1725,18 @@ static int parse_linux_boot(const QEMUOption *popt, const char* optarg)return 0 ; } +static int parse_net_client (const QEMUOption *popt,const char * optarg) +{ +QemuOptsList *opts; + + default_net =0 ; + opts =qemu_find_opts (popt->name); +if (!qemu_opts_parse_noisily (opts, optarg, true)) { +return -1 ; + } +return 0 ; +} +static const QEMUOption qemu_options[] = { {"h" ,0 , QEMU_OPTION_h,QEMU_ARCH_ALL }, #define QEMU_OPTIONS_GENERATE_OPTIONS
@@ -3110,24 +3122,6 @@ void qemu_init(int argc, char **argv, char **envp)case QEMU_OPTION_no_fd_bootchk: fd_bootchk =0 ;break ; -case QEMU_OPTION_netdev: - default_net =0 ; -if (net_client_parse (qemu_find_opts ("netdev" ), optarg) ==-1 ) { -exit (1 ); - } -break ; -case QEMU_OPTION_nic: - default_net =0 ; -if (net_client_parse (qemu_find_opts ("nic" ), optarg) ==-1 ) { -exit (1 ); - } -break ; -case QEMU_OPTION_net: - default_net =0 ; -if (net_client_parse (qemu_find_opts ("net" ), optarg) ==-1 ) { -exit (1 ); - } -break ;#ifdef CONFIG_LIBISCSI case QEMU_OPTION_iscsi: opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
Signature · 1 line
2.27.0
PATCH 3/3 qemu-options: introduce parse_virtfs
In reply to Hogan WangFrom: w00506750 <[email protected]>
introduce parse_virtfs to parse virtfs options.
Signed-off-by Hogan Wang <[email protected]>
--- qemu-options.hx | 2 +- softmmu/vl.c | 158 +++++++++++++++++++++++++----------------------- 2 files changed, 82 insertions(+), 78 deletions(-)
qemu-options.hx +1 -1
@@ -1542,7 +1542,7 @@ DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, "-virtfs proxy,mount_tag=tag,socket=socket[,id=id][,writeout=immediate][,readonly]\n" "-virtfs proxy,mount_tag=tag,sock_fd=sock_fd[,id=id][,writeout=immediate][,readonly]\n" "-virtfs synth,mount_tag=tag[,id=id][,readonly]\n", - QEMU_ARCH_ALL) + QEMU_ARCH_ALL, parse_virtfs) SRST ``-virtfs local,path=path,mount_tag=mount_tag ,security_model=security_model[,writeout=writeout][,readonly] [,fmode=fmode][,dmode=dmode][,multidevs=multidevs]``
softmmu/vl.c +81 -77
170 lines not on this page · raw message
Signature · 1 line
2.27.0