Blame SOURCES/kvm-block-qdict-Tweak-qdict_flatten_qdict-qdict_flatten_.patch

26ba25
From c756588134a48f4d1e33c62117aadc749544c5e7 Mon Sep 17 00:00:00 2001
26ba25
From: Markus Armbruster <armbru@redhat.com>
26ba25
Date: Mon, 18 Jun 2018 08:43:23 +0200
26ba25
Subject: [PATCH 025/268] block-qdict: Tweak qdict_flatten_qdict(),
26ba25
 qdict_flatten_qlist()
26ba25
26ba25
RH-Author: Markus Armbruster <armbru@redhat.com>
26ba25
Message-id: <20180618084330.30009-17-armbru@redhat.com>
26ba25
Patchwork-id: 80725
26ba25
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 16/23] block-qdict: Tweak qdict_flatten_qdict(), qdict_flatten_qlist()
26ba25
Bugzilla: 1557995
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
26ba25
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
26ba25
26ba25
qdict_flatten_qdict() skips copying scalars from @qdict to @target
26ba25
when the two are the same.  Fair enough, but it uses a non-obvious
26ba25
test for "same".  Replace it by the obvious one.  While there, improve
26ba25
comments.
26ba25
26ba25
Signed-off-by: Markus Armbruster <armbru@redhat.com>
26ba25
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit f1b34a248e9785e8cc0d28a1685d2cf4460bb256)
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 qobject/block-qdict.c | 14 +++++++++-----
26ba25
 1 file changed, 9 insertions(+), 5 deletions(-)
26ba25
26ba25
diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c
26ba25
index f32df34..a4e1c8d 100644
26ba25
--- a/qobject/block-qdict.c
26ba25
+++ b/qobject/block-qdict.c
26ba25
@@ -71,12 +71,15 @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix)
26ba25
         value = qlist_entry_obj(entry);
26ba25
         new_key = g_strdup_printf("%s.%i", prefix, i);
26ba25
 
26ba25
+        /*
26ba25
+         * Flatten non-empty QDict and QList recursively into @target,
26ba25
+         * copy other objects to @target
26ba25
+         */
26ba25
         if (qobject_type(value) == QTYPE_QDICT) {
26ba25
             qdict_flatten_qdict(qobject_to(QDict, value), target, new_key);
26ba25
         } else if (qobject_type(value) == QTYPE_QLIST) {
26ba25
             qdict_flatten_qlist(qobject_to(QList, value), target, new_key);
26ba25
         } else {
26ba25
-            /* All other types are moved to the target unchanged. */
26ba25
             qdict_put_obj(target, new_key, qobject_ref(value));
26ba25
         }
26ba25
 
26ba25
@@ -101,9 +104,11 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
26ba25
             new_key = g_strdup_printf("%s.%s", prefix, entry->key);
26ba25
         }
26ba25
 
26ba25
+        /*
26ba25
+         * Flatten non-empty QDict and QList recursively into @target,
26ba25
+         * copy other objects to @target
26ba25
+         */
26ba25
         if (qobject_type(value) == QTYPE_QDICT) {
26ba25
-            /* Entries of QDicts are processed recursively, the QDict object
26ba25
-             * itself disappears. */
26ba25
             qdict_flatten_qdict(qobject_to(QDict, value), target,
26ba25
                                 new_key ? new_key : entry->key);
26ba25
             qdict_del(qdict, entry->key);
26ba25
@@ -111,8 +116,7 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
26ba25
             qdict_flatten_qlist(qobject_to(QList, value), target,
26ba25
                                 new_key ? new_key : entry->key);
26ba25
             qdict_del(qdict, entry->key);
26ba25
-        } else if (prefix) {
26ba25
-            /* All other objects are moved to the target unchanged. */
26ba25
+        } else if (target != qdict) {
26ba25
             qdict_put_obj(target, new_key, qobject_ref(value));
26ba25
             qdict_del(qdict, entry->key);
26ba25
         }
26ba25
-- 
26ba25
1.8.3.1
26ba25