vl: rewamp -boot options parsing
PATCH 1/2 vl: rewamp -boot options parsing
This rewrites -boot option parsing to use qemu_opts_parse() with its current validation and abbreviation abilities.
Signed-off-by Michael Tokarev <[email protected]>
--- vl.c | 91 ++++++++++++++++-------------------------------------------------- 1 file changed, 21 insertions(+), 70 deletions(-)
vl.c +21 -70
@@ -434,9 +434,9 @@ static QemuOptsList qemu_machine_opts = {static QemuOptsList qemu_boot_opts = { .name ="boot-opts" , + .implied_opt_name ="order" , .head =QTAILQ_HEAD_INITIALIZER (qemu_boot_opts.head), .desc = { -/* the three names below are not used now */ { .name ="order" , .type =QEMU_OPT_STRING ,
@@ -445,8 +445,7 @@ static QemuOptsList qemu_boot_opts = { .type = QEMU_OPT_STRING, }, { .name = "menu", - .type = QEMU_OPT_STRING, - /* following are really used */ + .type = QEMU_OPT_BOOL, }, { .name = "splash", .type = QEMU_OPT_STRING,
@@ -458,7 +457,7 @@ static QemuOptsList qemu_boot_opts = { .type = QEMU_OPT_STRING, }, { .name = "strict", - .type = QEMU_OPT_STRING, + .type = QEMU_OPT_BOOL, }, {/*End of list */ } },
@@ -1157,7 +1156,7 @@ int qemu_boot_set(const char *boot_devices)return boot_set_handler (boot_set_opaque, boot_devices); } -static void validate_bootdevices (char *devices) +static void validate_bootdevices (const char *devices) {/* We just do some generic consistency checks */ const char *p;
@@ -3131,71 +3130,23 @@ int main(int argc, char **argv, char **envp)drive_add (IF_DEFAULT ,2 , optarg,CDROM_OPTS );break ;case QEMU_OPTION_boot: - { -static const char *const params[] = { -"order" ,"once" ,"menu" , -"splash" ,"splash-time" , -"reboot-timeout" ,"strict" ,NULL - }; -char buf[sizeof (boot_devices)]; -char *standard_boot_devices; -int legacy =0 ; - -if (!strchr (optarg,'=' )) { - legacy =1 ; -pstrcpy (buf,sizeof (buf), optarg); - }else if (check_params (buf,sizeof (buf), params, optarg) <0 ) { -fprintf (stderr, -"qemu: unknown boot parameter '%s' in '%s'\n" , - buf, optarg); -exit (1 ); - } - -if (legacy || -get_param_value (buf,sizeof (buf),"order" , optarg)) { -validate_bootdevices (buf); -pstrcpy (boot_devices,sizeof (boot_devices), buf); - } -if (!legacy) { -if (get_param_value (buf,sizeof (buf), -"once" , optarg)) { -validate_bootdevices (buf); - standard_boot_devices =g_strdup (boot_devices); -pstrcpy (boot_devices,sizeof (boot_devices), buf); -qemu_register_reset (restore_boot_devices, - standard_boot_devices); - } -if (get_param_value (buf,sizeof (buf), -"menu" , optarg)) { -if (!strcmp (buf,"on" )) { - boot_menu =1 ; - }else if (!strcmp (buf,"off" )) { - boot_menu =0 ; - }else { -fprintf (stderr, -"qemu: invalid option value '%s'\n" , - buf); -exit (1 ); - } - } -if (get_param_value (buf,sizeof (buf), -"strict" , optarg)) { -if (!strcmp (buf,"on" )) { - boot_strict = true; - }else if (!strcmp (buf,"off" )) { - boot_strict = false; - }else { -fprintf (stderr, -"qemu: invalid option value '%s'\n" , - buf); -exit (1 ); - } - } -if (!qemu_opts_parse (qemu_find_opts ("boot-opts" ), - optarg,0 )) { -exit (1 ); - } - } + opts =qemu_opts_parse (qemu_find_opts ("boot-opts" ), optarg,1 ); +if (!opts) { +exit (1 ); + } + boot_menu =qemu_opt_get_bool (opts,"menu" , false); + boot_strict =qemu_opt_get_bool (opts,"strict" , false); + optarg =qemu_opt_get (opts,"order" ); +if (optarg) { +validate_bootdevices (optarg); +pstrcpy (boot_devices,sizeof (boot_devices), optarg); + } + optarg =qemu_opt_get (opts,"once" ); +if (optarg) { +validate_bootdevices (optarg); +qemu_register_reset (restore_boot_devices, +g_strdup (boot_devices)); +pstrcpy (boot_devices,sizeof (boot_devices), optarg); }break ;case QEMU_OPTION_fda:
Signature · 1 line
1.7.10.4
PATCH 2/2 remove unused check_params()
last user was in -boot options processing
Signed-off-by Michael Tokarev <[email protected]>
--- include/qemu/option.h | 2 -- util/qemu-option.c | 30 ------------------------------ 2 files changed, 32 deletions(-)
include/qemu/option.h +0 -2
@@ -55,8 +55,6 @@ int get_next_param_value(char *buf, int buf_size, const char *tag, const char **pstr);int get_param_value (char *buf,int buf_size,const char *tag,const char *str); -int check_params (char *buf,int buf_size, -const char *const *params,const char *str);/*
util/qemu-option.c +0 -30
@@ -123,36 +123,6 @@ int get_param_value(char *buf, int buf_size,return get_next_param_value (buf, buf_size, tag, &str); } -int check_params (char *buf,int buf_size, -const char *const *params,const char *str) -{ -const char *p; -int i; - - p = str; -while (*p !='\0' ) { - p =get_opt_name (buf, buf_size, p,'=' ); -if (*p !='=' ) { -return -1 ; - } - p++; -for (i =0 ; params[i] !=NULL ; i++) { -if (!strcmp (params[i], buf)) { -break ; - } - } -if (params[i] ==NULL ) { -return -1 ; - } - p =get_opt_value (NULL ,0 , p); -if (*p !=',' ) { -break ; - } - p++; - } -return 0 ; -} -/* * Searches an option list for an option with the given name */
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 2/2] remove unused check_params()
Quoted 1 line · Michael Tokarev
last user was in -boot options processing
Series conflicts with my "[PATCH v3 00/16] -boot and -no-fd-bootchk fixes".
My series comes with fairly thorough tests.