Blame SOURCES/kvm-block-qdict-Clean-up-qdict_crumple-a-bit.patch

383d26
From 096bb1ca93a22a0ca874b76c3ad03385a5667f41 Mon Sep 17 00:00:00 2001
383d26
From: Markus Armbruster <armbru@redhat.com>
383d26
Date: Mon, 18 Jun 2018 08:43:24 +0200
383d26
Subject: [PATCH 17/54] block-qdict: Clean up qdict_crumple() a bit
383d26
383d26
RH-Author: Markus Armbruster <armbru@redhat.com>
383d26
Message-id: <20180618084330.30009-18-armbru@redhat.com>
383d26
Patchwork-id: 80729
383d26
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 17/23] block-qdict: Clean up qdict_crumple() a bit
383d26
Bugzilla: 1557995
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
383d26
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
383d26
383d26
When you mix scalar and non-scalar keys, whether you get an "already
383d26
set as scalar" or an "already set as dict" error depends on qdict
383d26
iteration order.  Neither message makes much sense.  Replace by
383d26
""Cannot mix scalar and non-scalar keys".  This is similar to the
383d26
message we get for mixing list and non-list keys.
383d26
383d26
I find qdict_crumple()'s first loop hard to understand.  Rearrange it
383d26
and add a comment.
383d26
383d26
Signed-off-by: Markus Armbruster <armbru@redhat.com>
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
(cherry picked from commit 3692b5d76819e573dedc9004c4b2b0e3dad83530)
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 qobject/block-qdict.c | 32 ++++++++++++++++----------------
383d26
 1 file changed, 16 insertions(+), 16 deletions(-)
383d26
383d26
diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c
383d26
index a4e1c8d..36cf58a 100644
383d26
--- a/qobject/block-qdict.c
383d26
+++ b/qobject/block-qdict.c
383d26
@@ -403,7 +403,7 @@ static int qdict_is_list(QDict *maybe_list, Error **errp)
383d26
 QObject *qdict_crumple(const QDict *src, Error **errp)
383d26
 {
383d26
     const QDictEntry *ent;
383d26
-    QDict *two_level, *multi_level = NULL;
383d26
+    QDict *two_level, *multi_level = NULL, *child_dict;
383d26
     QObject *dst = NULL, *child;
383d26
     size_t i;
383d26
     char *prefix = NULL;
383d26
@@ -422,28 +422,28 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
383d26
         }
383d26
 
383d26
         qdict_split_flat_key(ent->key, &prefix, &suffix);
383d26
-
383d26
         child = qdict_get(two_level, prefix);
383d26
+        child_dict = qobject_to(QDict, child);
383d26
+
383d26
+        if (child) {
383d26
+            /*
383d26
+             * If @child_dict, then all previous keys with this prefix
383d26
+             * had a suffix.  If @suffix, this one has one as well,
383d26
+             * and we're good, else there's a clash.
383d26
+             */
383d26
+            if (!child_dict || !suffix) {
383d26
+                error_setg(errp, "Cannot mix scalar and non-scalar keys");
383d26
+                goto error;
383d26
+            }
383d26
+        }
383d26
+
383d26
         if (suffix) {
383d26
-            QDict *child_dict = qobject_to(QDict, child);
383d26
             if (!child_dict) {
383d26
-                if (child) {
383d26
-                    error_setg(errp, "Key %s prefix is already set as a scalar",
383d26
-                               prefix);
383d26
-                    goto error;
383d26
-                }
383d26
-
383d26
                 child_dict = qdict_new();
383d26
-                qdict_put_obj(two_level, prefix, QOBJECT(child_dict));
383d26
+                qdict_put(two_level, prefix, child_dict);
383d26
             }
383d26
-
383d26
             qdict_put_obj(child_dict, suffix, qobject_ref(ent->value));
383d26
         } else {
383d26
-            if (child) {
383d26
-                error_setg(errp, "Key %s prefix is already set as a dict",
383d26
-                           prefix);
383d26
-                goto error;
383d26
-            }
383d26
             qdict_put_obj(two_level, prefix, qobject_ref(ent->value));
383d26
         }
383d26
 
383d26
-- 
383d26
1.8.3.1
383d26