9ae3a8
From c4ffa69bdec932cf674d92355967ce2876296893 Mon Sep 17 00:00:00 2001
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
Date: Tue, 6 Aug 2013 13:17:01 +0200
9ae3a8
Subject: [PATCH 08/28] qemu-option: Fix qemu_opts_set_defaults() for corner cases
9ae3a8
9ae3a8
RH-Author: Markus Armbruster <armbru@redhat.com>
9ae3a8
Message-id: <1375795025-28674-3-git-send-email-armbru@redhat.com>
9ae3a8
Patchwork-id: 52990
9ae3a8
O-Subject: [PATCH 7.0 qemu-kvm 2/6] qemu-option: Fix qemu_opts_set_defaults() for corner cases
9ae3a8
Bugzilla: 980782
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
9ae3a8
9ae3a8
Commit 4f6dd9a changed the initialization of opts in opts_parse() to
9ae3a8
this:
9ae3a8
9ae3a8
    if (defaults) {
9ae3a8
        if (!id && !QTAILQ_EMPTY(&list->head)) {
9ae3a8
            opts = qemu_opts_find(list, NULL);
9ae3a8
        } else {
9ae3a8
            opts = qemu_opts_create(list, id, 0);
9ae3a8
        }
9ae3a8
    } else {
9ae3a8
        opts = qemu_opts_create(list, id, 1);
9ae3a8
    }
9ae3a8
9ae3a8
Same as before for !defaults.
9ae3a8
9ae3a8
If defaults is true, and params has no ID, and options exist, we use
9ae3a8
the first assignment.  It sets opts to null if all options have an ID.
9ae3a8
opts_parse() then returns null.  qemu_opts_set_defaults() asserts the
9ae3a8
value is non-null.  It's the only caller that passes true for
9ae3a8
defaults.
9ae3a8
9ae3a8
To reproduce, try "-M xenpv -machine id=foo" (yes, "id=foo" is silly,
9ae3a8
but it shouldn't crash).
9ae3a8
9ae3a8
I believe the function attempts to do the following:
9ae3a8
9ae3a8
    If options don't yet exist, create new options
9ae3a8
    Else, if defaults, modify the existing options
9ae3a8
    Else, if list->merge_lists, modify the existing options
9ae3a8
    Else, fail
9ae3a8
9ae3a8
A straightforward call of qemu_opts_create() does exactly that.
9ae3a8
9ae3a8
Cc: Jan Kiszka <jan.kiszka@siemens.com>
9ae3a8
Signed-off-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Message-id: 1372943363-24081-3-git-send-email-armbru@redhat.com
9ae3a8
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9ae3a8
(cherry picked from commit 6d4cd408686f5ae60b2b3b94b79f48ddedc2f39d)
9ae3a8
9ae3a8
The upstream commit message's claim that a "straightforward call of
9ae3a8
qemu_opts_create() does exactly that" is wrong.  When
9ae3a8
!list->merge_lists, and the option string doesn't contain id=, and
9ae3a8
options without ID exist, then we don't actually modify the existing
9ae3a8
options, we create new ones.
9ae3a8
9ae3a8
Not reachable, because we never pass lists with !list->merge_lists to
9ae3a8
qemu_opts_set_defaults().
9ae3a8
9ae3a8
Patch adding a suitable assertion pending upstream.
9ae3a8
---
9ae3a8
 util/qemu-option.c | 10 +---------
9ae3a8
 1 file changed, 1 insertion(+), 9 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 util/qemu-option.c |   10 +---------
9ae3a8
 1 files changed, 1 insertions(+), 9 deletions(-)
9ae3a8
9ae3a8
diff --git a/util/qemu-option.c b/util/qemu-option.c
9ae3a8
index b6d2ac0..bdfbdb4 100644
9ae3a8
--- a/util/qemu-option.c
9ae3a8
+++ b/util/qemu-option.c
9ae3a8
@@ -944,15 +944,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
9ae3a8
         get_opt_value(value, sizeof(value), p+4);
9ae3a8
         id = value;
9ae3a8
     }
9ae3a8
-    if (defaults) {
9ae3a8
-        if (!id && !QTAILQ_EMPTY(&list->head)) {
9ae3a8
-            opts = qemu_opts_find(list, NULL);
9ae3a8
-        } else {
9ae3a8
-            opts = qemu_opts_create(list, id, 0, &local_err);
9ae3a8
-        }
9ae3a8
-    } else {
9ae3a8
-        opts = qemu_opts_create(list, id, 1, &local_err);
9ae3a8
-    }
9ae3a8
+    opts = qemu_opts_create(list, id, !defaults, &local_err);
9ae3a8
     if (opts == NULL) {
9ae3a8
         if (error_is_set(&local_err)) {
9ae3a8
             qerror_report_err(local_err);
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8