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

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