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