9ae3a8
From 5575e0aec51f40ebec46e98ec085cda053283aba Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <5575e0aec51f40ebec46e98ec085cda053283aba.1383564115.git.minovotn@redhat.com>
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
Date: Fri, 27 Sep 2013 13:31:11 +0200
9ae3a8
Subject: [PATCH 01/14] vl: Clean up parsing of -boot option argument
9ae3a8
9ae3a8
RH-Author: Markus Armbruster <armbru@redhat.com>
9ae3a8
Message-id: <1380288680-26645-2-git-send-email-armbru@redhat.com>
9ae3a8
Patchwork-id: 54560
9ae3a8
O-Subject: [PATCH 7.0 qemu-kvm 01/10] vl: Clean up parsing of -boot option argument
9ae3a8
Bugzilla: 997817
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
9ae3a8
Commit 3d3b8303 threw in some QemuOpts parsing without replacing the
9ae3a8
existing ad hoc parser, resulting in a confusing mess.  Clean it up.
9ae3a8
9ae3a8
Two user-visible changes:
9ae3a8
9ae3a8
1. Invalid options are reported more nicely.  Before:
9ae3a8
9ae3a8
        qemu: unknown boot parameter 'x' in 'x=y'
9ae3a8
9ae3a8
   After:
9ae3a8
9ae3a8
        qemu-system-x86_64: -boot x=y: Invalid parameter 'x'
9ae3a8
9ae3a8
2. If -boot is given multiple times, options accumulate, just like for
9ae3a8
   -machine.  Before, only options order, once and menu accumulated.
9ae3a8
   For the other ones, all but the first -boot in non-legacy syntax
9ae3a8
   got simply ignored.
9ae3a8
9ae3a8
Signed-off-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
9ae3a8
Message-id: 1371208516-7857-2-git-send-email-armbru@redhat.com
9ae3a8
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9ae3a8
(cherry picked from commit 6ef4716cecdfa1b3794c1a33edba9840e1aa6b5f)
9ae3a8
---
9ae3a8
 vl.c | 84 ++++++++++++++++++--------------------------------------------------
9ae3a8
 1 file changed, 22 insertions(+), 62 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 vl.c | 84 ++++++++++++++++++--------------------------------------------------
9ae3a8
 1 file changed, 22 insertions(+), 62 deletions(-)
9ae3a8
9ae3a8
diff --git a/vl.c b/vl.c
9ae3a8
index a40ab13..a5663ad 100644
9ae3a8
--- a/vl.c
9ae3a8
+++ b/vl.c
9ae3a8
@@ -436,9 +436,10 @@ static QemuOptsList qemu_machine_opts = {
9ae3a8
 
9ae3a8
 static QemuOptsList qemu_boot_opts = {
9ae3a8
     .name = "boot-opts",
9ae3a8
+    .implied_opt_name = "order",
9ae3a8
+    .merge_lists = true,
9ae3a8
     .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
9ae3a8
     .desc = {
9ae3a8
-        /* the three names below are not used now */
9ae3a8
         {
9ae3a8
             .name = "order",
9ae3a8
             .type = QEMU_OPT_STRING,
9ae3a8
@@ -447,8 +448,7 @@ static QemuOptsList qemu_boot_opts = {
9ae3a8
             .type = QEMU_OPT_STRING,
9ae3a8
         }, {
9ae3a8
             .name = "menu",
9ae3a8
-            .type = QEMU_OPT_STRING,
9ae3a8
-        /* following are really used */
9ae3a8
+            .type = QEMU_OPT_BOOL,
9ae3a8
         }, {
9ae3a8
             .name = "splash",
9ae3a8
             .type = QEMU_OPT_STRING,
9ae3a8
@@ -1114,7 +1114,7 @@ int qemu_boot_set(const char *boot_devices)
9ae3a8
     return boot_set_handler(boot_set_opaque, boot_devices);
9ae3a8
 }
9ae3a8
 
9ae3a8
-static void validate_bootdevices(char *devices)
9ae3a8
+static void validate_bootdevices(const char *devices)
9ae3a8
 {
9ae3a8
     /* We just do some generic consistency checks */
9ae3a8
     const char *p;
9ae3a8
@@ -3087,70 +3087,30 @@ int main(int argc, char **argv, char **envp)
9ae3a8
                 break;
9ae3a8
             case QEMU_OPTION_boot:
9ae3a8
                 {
9ae3a8
-                    static const char * const params[] = {
9ae3a8
-                        "order", "once", "menu",
9ae3a8
-                        "splash", "splash-time",
9ae3a8
-                        "reboot-timeout", "strict", NULL
9ae3a8
-                    };
9ae3a8
-                    char buf[sizeof(boot_devices)];
9ae3a8
                     char *standard_boot_devices;
9ae3a8
-                    int legacy = 0;
9ae3a8
-
9ae3a8
-                    if (!strchr(optarg, '=')) {
9ae3a8
-                        legacy = 1;
9ae3a8
-                        pstrcpy(buf, sizeof(buf), optarg);
9ae3a8
-                    } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
9ae3a8
-                        fprintf(stderr,
9ae3a8
-                                "qemu: unknown boot parameter '%s' in '%s'\n",
9ae3a8
-                                buf, optarg);
9ae3a8
+                    const char *order, *once;
9ae3a8
+
9ae3a8
+                    opts = qemu_opts_parse(qemu_find_opts("boot-opts"),
9ae3a8
+                                           optarg, 1);
9ae3a8
+                    if (!opts) {
9ae3a8
                         exit(1);
9ae3a8
                     }
9ae3a8
 
9ae3a8
-                    if (legacy ||
9ae3a8
-                        get_param_value(buf, sizeof(buf), "order", optarg)) {
9ae3a8
-                        validate_bootdevices(buf);
9ae3a8
-                        pstrcpy(boot_devices, sizeof(boot_devices), buf);
9ae3a8
+                    order = qemu_opt_get(opts, "order");
9ae3a8
+                    if (order) {
9ae3a8
+                        validate_bootdevices(order);
9ae3a8
+                        pstrcpy(boot_devices, sizeof(boot_devices), order);
9ae3a8
                     }
9ae3a8
-                    if (!legacy) {
9ae3a8
-                        if (get_param_value(buf, sizeof(buf),
9ae3a8
-                                            "once", optarg)) {
9ae3a8
-                            validate_bootdevices(buf);
9ae3a8
-                            standard_boot_devices = g_strdup(boot_devices);
9ae3a8
-                            pstrcpy(boot_devices, sizeof(boot_devices), buf);
9ae3a8
-                            qemu_register_reset(restore_boot_devices,
9ae3a8
-                                                standard_boot_devices);
9ae3a8
-                        }
9ae3a8
-                        if (get_param_value(buf, sizeof(buf),
9ae3a8
-                                            "menu", optarg)) {
9ae3a8
-                            if (!strcmp(buf, "on")) {
9ae3a8
-                                boot_menu = 1;
9ae3a8
-                            } else if (!strcmp(buf, "off")) {
9ae3a8
-                                boot_menu = 0;
9ae3a8
-                            } else {
9ae3a8
-                                fprintf(stderr,
9ae3a8
-                                        "qemu: invalid option value '%s'\n",
9ae3a8
-                                        buf);
9ae3a8
-                                exit(1);
9ae3a8
-                            }
9ae3a8
-                        }
9ae3a8
-                        if (get_param_value(buf, sizeof(buf),
9ae3a8
-                                            "strict", optarg)) {
9ae3a8
-                            if (!strcmp(buf, "on")) {
9ae3a8
-                                boot_strict = true;
9ae3a8
-                            } else if (!strcmp(buf, "off")) {
9ae3a8
-                                boot_strict = false;
9ae3a8
-                            } else {
9ae3a8
-                                fprintf(stderr,
9ae3a8
-                                        "qemu: invalid option value '%s'\n",
9ae3a8
-                                        buf);
9ae3a8
-                                exit(1);
9ae3a8
-                            }
9ae3a8
-                        }
9ae3a8
-                        if (!qemu_opts_parse(qemu_find_opts("boot-opts"),
9ae3a8
-                                             optarg, 0)) {
9ae3a8
-                            exit(1);
9ae3a8
-                        }
9ae3a8
+
9ae3a8
+                    once = qemu_opt_get(opts, "once");
9ae3a8
+                    if (once) {
9ae3a8
+                        validate_bootdevices(once);
9ae3a8
+                        standard_boot_devices = g_strdup(boot_devices);
9ae3a8
+                        pstrcpy(boot_devices, sizeof(boot_devices), once);
9ae3a8
+                        qemu_register_reset(restore_boot_devices,
9ae3a8
+                                            standard_boot_devices);
9ae3a8
                     }
9ae3a8
+                    boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
9ae3a8
                 }
9ae3a8
                 break;
9ae3a8
             case QEMU_OPTION_fda:
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8