Blame SOURCES/kvm-block-Factor-out-qobject_input_visitor_new_flat_conf.patch

26ba25
From ec12a6f04d0ecf97a8e200d360f3375def1433d5 Mon Sep 17 00:00:00 2001
26ba25
From: Markus Armbruster <armbru@redhat.com>
26ba25
Date: Mon, 18 Jun 2018 08:43:20 +0200
26ba25
Subject: [PATCH 022/268] block: Factor out
26ba25
 qobject_input_visitor_new_flat_confused()
26ba25
26ba25
RH-Author: Markus Armbruster <armbru@redhat.com>
26ba25
Message-id: <20180618084330.30009-14-armbru@redhat.com>
26ba25
Patchwork-id: 80728
26ba25
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 13/23] block: Factor out qobject_input_visitor_new_flat_confused()
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
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 af91062ee1408f7f5bb58389d355d29a5040c648)
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 block/nbd.c           |  7 ++-----
26ba25
 block/nfs.c           |  7 ++-----
26ba25
 block/parallels.c     |  7 ++-----
26ba25
 block/qcow.c          |  7 ++-----
26ba25
 block/qcow2.c         |  7 ++-----
26ba25
 block/qed.c           |  7 ++-----
26ba25
 block/rbd.c           |  7 ++-----
26ba25
 block/sheepdog.c      | 14 ++++----------
26ba25
 block/ssh.c           |  7 ++-----
26ba25
 block/vhdx.c          |  7 ++-----
26ba25
 block/vpc.c           |  7 ++-----
26ba25
 include/block/qdict.h |  3 ++-
26ba25
 qobject/block-qdict.c | 28 +++++++++++++++++++++++++++-
26ba25
 13 files changed, 53 insertions(+), 62 deletions(-)
26ba25
26ba25
diff --git a/block/nbd.c b/block/nbd.c
26ba25
index b0be357..10912c3 100644
26ba25
--- a/block/nbd.c
26ba25
+++ b/block/nbd.c
26ba25
@@ -263,7 +263,6 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
26ba25
 {
26ba25
     SocketAddress *saddr = NULL;
26ba25
     QDict *addr = NULL;
26ba25
-    QObject *crumpled_addr = NULL;
26ba25
     Visitor *iv = NULL;
26ba25
     Error *local_err = NULL;
26ba25
 
26ba25
@@ -273,12 +272,11 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
26ba25
         goto done;
26ba25
     }
26ba25
 
26ba25
-    crumpled_addr = qdict_crumple_for_keyval_qiv(addr, errp);
26ba25
-    if (!crumpled_addr) {
26ba25
+    iv = qobject_input_visitor_new_flat_confused(addr, errp);
26ba25
+    if (!iv) {
26ba25
         goto done;
26ba25
     }
26ba25
 
26ba25
-    iv = qobject_input_visitor_new_keyval(crumpled_addr);
26ba25
     visit_type_SocketAddress(iv, NULL, &saddr, &local_err);
26ba25
     if (local_err) {
26ba25
         error_propagate(errp, local_err);
26ba25
@@ -287,7 +285,6 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
26ba25
 
26ba25
 done:
26ba25
     qobject_unref(addr);
26ba25
-    qobject_unref(crumpled_addr);
26ba25
     visit_free(iv);
26ba25
     return saddr;
26ba25
 }
26ba25
diff --git a/block/nfs.c b/block/nfs.c
26ba25
index 4090d28..1e12958 100644
26ba25
--- a/block/nfs.c
26ba25
+++ b/block/nfs.c
26ba25
@@ -556,19 +556,16 @@ static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options,
26ba25
                                                      Error **errp)
26ba25
 {
26ba25
     BlockdevOptionsNfs *opts = NULL;
26ba25
-    QObject *crumpled = NULL;
26ba25
     Visitor *v;
26ba25
     Error *local_err = NULL;
26ba25
 
26ba25
-    crumpled = qdict_crumple_for_keyval_qiv(options, errp);
26ba25
-    if (crumpled == NULL) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(options, errp);
26ba25
+    if (!v) {
26ba25
         return NULL;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(crumpled);
26ba25
     visit_type_BlockdevOptionsNfs(v, NULL, &opts, &local_err);
26ba25
     visit_free(v);
26ba25
-    qobject_unref(crumpled);
26ba25
 
26ba25
     if (local_err) {
26ba25
         return NULL;
26ba25
diff --git a/block/parallels.c b/block/parallels.c
26ba25
index 1c96c39..b6ebe36 100644
26ba25
--- a/block/parallels.c
26ba25
+++ b/block/parallels.c
26ba25
@@ -615,7 +615,6 @@ static int coroutine_fn parallels_co_create_opts(const char *filename,
26ba25
     Error *local_err = NULL;
26ba25
     BlockDriverState *bs = NULL;
26ba25
     QDict *qdict;
26ba25
-    QObject *qobj;
26ba25
     Visitor *v;
26ba25
     int ret;
26ba25
 
26ba25
@@ -651,14 +650,12 @@ static int coroutine_fn parallels_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "driver", "parallels");
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
-    qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    if (!qobj) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(qdict, errp);
26ba25
+    if (!v) {
26ba25
         ret = -EINVAL;
26ba25
         goto done;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(qobj);
26ba25
-    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/qcow.c b/block/qcow.c
26ba25
index 43a595a..4b3bc31 100644
26ba25
--- a/block/qcow.c
26ba25
+++ b/block/qcow.c
26ba25
@@ -945,7 +945,6 @@ static int coroutine_fn qcow_co_create_opts(const char *filename,
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
     BlockDriverState *bs = NULL;
26ba25
     QDict *qdict;
26ba25
-    QObject *qobj;
26ba25
     Visitor *v;
26ba25
     const char *val;
26ba25
     Error *local_err = NULL;
26ba25
@@ -995,14 +994,12 @@ static int coroutine_fn qcow_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "driver", "qcow");
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
-    qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    if (!qobj) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(qdict, errp);
26ba25
+    if (!v) {
26ba25
         ret = -EINVAL;
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(qobj);
26ba25
-    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/qcow2.c b/block/qcow2.c
26ba25
index ede52a8..35842c5 100644
26ba25
--- a/block/qcow2.c
26ba25
+++ b/block/qcow2.c
26ba25
@@ -3068,7 +3068,6 @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
     QDict *qdict;
26ba25
-    QObject *qobj;
26ba25
     Visitor *v;
26ba25
     BlockDriverState *bs = NULL;
26ba25
     Error *local_err = NULL;
26ba25
@@ -3139,14 +3138,12 @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
     /* Now get the QAPI type BlockdevCreateOptions */
26ba25
-    qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    if (!qobj) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(qdict, errp);
26ba25
+    if (!v) {
26ba25
         ret = -EINVAL;
26ba25
         goto finish;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(qobj);
26ba25
-    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/qed.c b/block/qed.c
26ba25
index 3818888..4c5d7e8 100644
26ba25
--- a/block/qed.c
26ba25
+++ b/block/qed.c
26ba25
@@ -723,7 +723,6 @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename,
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
     QDict *qdict;
26ba25
-    QObject *qobj;
26ba25
     Visitor *v;
26ba25
     BlockDriverState *bs = NULL;
26ba25
     Error *local_err = NULL;
26ba25
@@ -763,14 +762,12 @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "driver", "qed");
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
-    qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    if (!qobj) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(qdict, errp);
26ba25
+    if (!v) {
26ba25
         ret = -EINVAL;
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(qobj);
26ba25
-    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/rbd.c b/block/rbd.c
26ba25
index 0b5455f..c834d72 100644
26ba25
--- a/block/rbd.c
26ba25
+++ b/block/rbd.c
26ba25
@@ -623,7 +623,6 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
26ba25
     BDRVRBDState *s = bs->opaque;
26ba25
     BlockdevOptionsRbd *opts = NULL;
26ba25
     Visitor *v;
26ba25
-    QObject *crumpled = NULL;
26ba25
     const QDictEntry *e;
26ba25
     Error *local_err = NULL;
26ba25
     char *keypairs, *secretid;
26ba25
@@ -640,16 +639,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
26ba25
     }
26ba25
 
26ba25
     /* Convert the remaining options into a QAPI object */
26ba25
-    crumpled = qdict_crumple_for_keyval_qiv(options, errp);
26ba25
-    if (crumpled == NULL) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(options, errp);
26ba25
+    if (!v) {
26ba25
         r = -EINVAL;
26ba25
         goto out;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(crumpled);
26ba25
     visit_type_BlockdevOptionsRbd(v, NULL, &opts, &local_err);
26ba25
     visit_free(v);
26ba25
-    qobject_unref(crumpled);
26ba25
 
26ba25
     if (local_err) {
26ba25
         error_propagate(errp, local_err);
26ba25
diff --git a/block/sheepdog.c b/block/sheepdog.c
26ba25
index dd582d5..d1c9bf5 100644
26ba25
--- a/block/sheepdog.c
26ba25
+++ b/block/sheepdog.c
26ba25
@@ -539,19 +539,17 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s,
26ba25
 static SocketAddress *sd_server_config(QDict *options, Error **errp)
26ba25
 {
26ba25
     QDict *server = NULL;
26ba25
-    QObject *crumpled_server = NULL;
26ba25
     Visitor *iv = NULL;
26ba25
     SocketAddress *saddr = NULL;
26ba25
     Error *local_err = NULL;
26ba25
 
26ba25
     qdict_extract_subqdict(options, &server, "server.");
26ba25
 
26ba25
-    crumpled_server = qdict_crumple_for_keyval_qiv(server, errp);
26ba25
-    if (!crumpled_server) {
26ba25
+    iv = qobject_input_visitor_new_flat_confused(server, errp);
26ba25
+    if (!iv) {
26ba25
         goto done;
26ba25
     }
26ba25
 
26ba25
-    iv = qobject_input_visitor_new_keyval(crumpled_server);
26ba25
     visit_type_SocketAddress(iv, NULL, &saddr, &local_err);
26ba25
     if (local_err) {
26ba25
         error_propagate(errp, local_err);
26ba25
@@ -560,7 +558,6 @@ static SocketAddress *sd_server_config(QDict *options, Error **errp)
26ba25
 
26ba25
 done:
26ba25
     visit_free(iv);
26ba25
-    qobject_unref(crumpled_server);
26ba25
     qobject_unref(server);
26ba25
     return saddr;
26ba25
 }
26ba25
@@ -2174,7 +2171,6 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
     QDict *qdict, *location_qdict;
26ba25
-    QObject *crumpled;
26ba25
     Visitor *v;
26ba25
     const char *redundancy;
26ba25
     Error *local_err = NULL;
26ba25
@@ -2210,16 +2206,14 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
26ba25
     }
26ba25
 
26ba25
     /* Get the QAPI object */
26ba25
-    crumpled = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    if (crumpled == NULL) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(qdict, errp);
26ba25
+    if (!v) {
26ba25
         ret = -EINVAL;
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(crumpled);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
-    qobject_unref(crumpled);
26ba25
 
26ba25
     if (local_err) {
26ba25
         error_propagate(errp, local_err);
26ba25
diff --git a/block/ssh.c b/block/ssh.c
26ba25
index 2fc7cd9..aab6996 100644
26ba25
--- a/block/ssh.c
26ba25
+++ b/block/ssh.c
26ba25
@@ -606,7 +606,6 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp)
26ba25
     BlockdevOptionsSsh *result = NULL;
26ba25
     QemuOpts *opts = NULL;
26ba25
     Error *local_err = NULL;
26ba25
-    QObject *crumpled;
26ba25
     const QDictEntry *e;
26ba25
     Visitor *v;
26ba25
 
26ba25
@@ -623,15 +622,13 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp)
26ba25
     }
26ba25
 
26ba25
     /* Create the QAPI object */
26ba25
-    crumpled = qdict_crumple_for_keyval_qiv(options, errp);
26ba25
-    if (crumpled == NULL) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(options, errp);
26ba25
+    if (!v) {
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(crumpled);
26ba25
     visit_type_BlockdevOptionsSsh(v, NULL, &result, &local_err);
26ba25
     visit_free(v);
26ba25
-    qobject_unref(crumpled);
26ba25
 
26ba25
     if (local_err) {
26ba25
         error_propagate(errp, local_err);
26ba25
diff --git a/block/vhdx.c b/block/vhdx.c
26ba25
index 728d8b3..6731298 100644
26ba25
--- a/block/vhdx.c
26ba25
+++ b/block/vhdx.c
26ba25
@@ -1964,7 +1964,6 @@ static int coroutine_fn vhdx_co_create_opts(const char *filename,
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
     QDict *qdict;
26ba25
-    QObject *qobj;
26ba25
     Visitor *v;
26ba25
     BlockDriverState *bs = NULL;
26ba25
     Error *local_err = NULL;
26ba25
@@ -2003,14 +2002,12 @@ static int coroutine_fn vhdx_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "driver", "vhdx");
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
-    qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    if (!qobj) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(qdict, errp);
26ba25
+    if (!v) {
26ba25
         ret = -EINVAL;
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(qobj);
26ba25
-    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/vpc.c b/block/vpc.c
26ba25
index a9bb041..bf294ab 100644
26ba25
--- a/block/vpc.c
26ba25
+++ b/block/vpc.c
26ba25
@@ -1082,7 +1082,6 @@ static int coroutine_fn vpc_co_create_opts(const char *filename,
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
     QDict *qdict;
26ba25
-    QObject *qobj;
26ba25
     Visitor *v;
26ba25
     BlockDriverState *bs = NULL;
26ba25
     Error *local_err = NULL;
26ba25
@@ -1119,14 +1118,12 @@ static int coroutine_fn vpc_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "driver", "vpc");
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
-    qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    if (!qobj) {
26ba25
+    v = qobject_input_visitor_new_flat_confused(qdict, errp);
26ba25
+    if (!v) {
26ba25
         ret = -EINVAL;
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(qobj);
26ba25
-    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/include/block/qdict.h b/include/block/qdict.h
26ba25
index 47d9638..d8cb502 100644
26ba25
--- a/include/block/qdict.h
26ba25
+++ b/include/block/qdict.h
26ba25
@@ -21,7 +21,6 @@ void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start);
26ba25
 void qdict_array_split(QDict *src, QList **dst);
26ba25
 int qdict_array_entries(QDict *src, const char *subqdict);
26ba25
 QObject *qdict_crumple(const QDict *src, Error **errp);
26ba25
-QObject *qdict_crumple_for_keyval_qiv(QDict *qdict, Error **errp);
26ba25
 void qdict_flatten(QDict *qdict);
26ba25
 
26ba25
 typedef struct QDictRenames {
26ba25
@@ -30,4 +29,6 @@ typedef struct QDictRenames {
26ba25
 } QDictRenames;
26ba25
 bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp);
26ba25
 
26ba25
+Visitor *qobject_input_visitor_new_flat_confused(QDict *qdict,
26ba25
+                                                 Error **errp);
26ba25
 #endif
26ba25
diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c
26ba25
index aba372c..41f39ab 100644
26ba25
--- a/qobject/block-qdict.c
26ba25
+++ b/qobject/block-qdict.c
26ba25
@@ -13,6 +13,7 @@
26ba25
 #include "qapi/qmp/qlist.h"
26ba25
 #include "qapi/qmp/qnum.h"
26ba25
 #include "qapi/qmp/qstring.h"
26ba25
+#include "qapi/qobject-input-visitor.h"
26ba25
 #include "qemu/cutils.h"
26ba25
 #include "qapi/error.h"
26ba25
 
26ba25
@@ -529,7 +530,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
26ba25
  * used for anything else, and it should go away once the block
26ba25
  * subsystem has been cleaned up.
26ba25
  */
26ba25
-QObject *qdict_crumple_for_keyval_qiv(QDict *src, Error **errp)
26ba25
+static QObject *qdict_crumple_for_keyval_qiv(QDict *src, Error **errp)
26ba25
 {
26ba25
     QDict *tmp = NULL;
26ba25
     char *buf;
26ba25
@@ -695,3 +696,28 @@ bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp)
26ba25
     }
26ba25
     return true;
26ba25
 }
26ba25
+
26ba25
+/*
26ba25
+ * Create a QObject input visitor for flat @qdict with possibly
26ba25
+ * confused scalar types.
26ba25
+ *
26ba25
+ * The block subsystem uses this function to visit its flat QDict with
26ba25
+ * possibly confused scalar types.  It should not be used for anything
26ba25
+ * else, and it should go away once the block subsystem has been
26ba25
+ * cleaned up.
26ba25
+ */
26ba25
+Visitor *qobject_input_visitor_new_flat_confused(QDict *qdict,
26ba25
+                                                 Error **errp)
26ba25
+{
26ba25
+    QObject *crumpled;
26ba25
+    Visitor *v;
26ba25
+
26ba25
+    crumpled = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
+    if (!crumpled) {
26ba25
+        return NULL;
26ba25
+    }
26ba25
+
26ba25
+    v = qobject_input_visitor_new_keyval(crumpled);
26ba25
+    qobject_unref(crumpled);
26ba25
+    return v;
26ba25
+}
26ba25
-- 
26ba25
1.8.3.1
26ba25