vl: Clean up parsing of -boot option argument

Commit 3d3b8303 threw in some QemuOpts parsing without replacing the
existing ad hoc parser, resulting in a confusing mess.  Clean it up.

Two user-visible changes:

1. Invalid options are reported more nicely.  Before:

        qemu: unknown boot parameter 'x' in 'x=y'

   After:

        qemu-system-x86_64: -boot x=y: Invalid parameter 'x'

2. If -boot is given multiple times, options accumulate, just like for
   -machine.  Before, only options order, once and menu accumulated.
   For the other ones, all but the first -boot in non-legacy syntax
   got simply ignored.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Message-id: 1371208516-7857-2-git-send-email-armbru@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Markus Armbruster 2013-06-14 13:15:01 +02:00 committed by Anthony Liguori
parent c1990468d5
commit 6ef4716cec

82
vl.c
View File

@ -434,9 +434,10 @@ static QemuOptsList qemu_machine_opts = {
static QemuOptsList qemu_boot_opts = { static QemuOptsList qemu_boot_opts = {
.name = "boot-opts", .name = "boot-opts",
.implied_opt_name = "order",
.merge_lists = true,
.head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head), .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
.desc = { .desc = {
/* the three names below are not used now */
{ {
.name = "order", .name = "order",
.type = QEMU_OPT_STRING, .type = QEMU_OPT_STRING,
@ -445,8 +446,7 @@ static QemuOptsList qemu_boot_opts = {
.type = QEMU_OPT_STRING, .type = QEMU_OPT_STRING,
}, { }, {
.name = "menu", .name = "menu",
.type = QEMU_OPT_STRING, .type = QEMU_OPT_BOOL,
/* following are really used */
}, { }, {
.name = "splash", .name = "splash",
.type = QEMU_OPT_STRING, .type = QEMU_OPT_STRING,
@ -1157,7 +1157,7 @@ int qemu_boot_set(const char *boot_devices)
return boot_set_handler(boot_set_opaque, 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 */ /* We just do some generic consistency checks */
const char *p; const char *p;
@ -3132,70 +3132,30 @@ int main(int argc, char **argv, char **envp)
break; break;
case QEMU_OPTION_boot: 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; char *standard_boot_devices;
int legacy = 0; const char *order, *once;
if (!strchr(optarg, '=')) { opts = qemu_opts_parse(qemu_find_opts("boot-opts"),
legacy = 1; optarg, 1);
pstrcpy(buf, sizeof(buf), optarg); if (!opts) {
} else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
fprintf(stderr,
"qemu: unknown boot parameter '%s' in '%s'\n",
buf, optarg);
exit(1); exit(1);
} }
if (legacy || order = qemu_opt_get(opts, "order");
get_param_value(buf, sizeof(buf), "order", optarg)) { if (order) {
validate_bootdevices(buf); validate_bootdevices(order);
pstrcpy(boot_devices, sizeof(boot_devices), buf); pstrcpy(boot_devices, sizeof(boot_devices), order);
} }
if (!legacy) {
if (get_param_value(buf, sizeof(buf), once = qemu_opt_get(opts, "once");
"once", optarg)) { if (once) {
validate_bootdevices(buf); validate_bootdevices(once);
standard_boot_devices = g_strdup(boot_devices); standard_boot_devices = g_strdup(boot_devices);
pstrcpy(boot_devices, sizeof(boot_devices), buf); pstrcpy(boot_devices, sizeof(boot_devices), once);
qemu_register_reset(restore_boot_devices, qemu_register_reset(restore_boot_devices,
standard_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);
}
} }
boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
} }
break; break;
case QEMU_OPTION_fda: case QEMU_OPTION_fda: