From nobody Sat Apr 12 02:54:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529073001029919.3650665266848; Fri, 15 Jun 2018 07:30:01 -0700 (PDT) Received: from localhost ([::1]:47169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTpjg-00051f-Lb for importer@patchew.org; Fri, 15 Jun 2018 10:29:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTpbW-00063A-9P for qemu-devel@nongnu.org; Fri, 15 Jun 2018 10:21:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTpbU-0003fO-9x for qemu-devel@nongnu.org; Fri, 15 Jun 2018 10:21:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54408 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fTpbP-0003Yy-6C; Fri, 15 Jun 2018 10:21:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE6E340122CE; Fri, 15 Jun 2018 14:21:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-70.ams2.redhat.com [10.36.117.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2943263A51; Fri, 15 Jun 2018 14:21:22 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 15 Jun 2018 16:20:54 +0200 Message-Id: <20180615142108.27814-13-kwolf@redhat.com> In-Reply-To: <20180615142108.27814-1-kwolf@redhat.com> References: <20180615142108.27814-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 15 Jun 2018 14:21:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 15 Jun 2018 14:21:22 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 12/26] block: Factor out qobject_input_visitor_new_flat_confused() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Markus Armbruster Signed-off-by: Markus Armbruster Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/qdict.h | 3 ++- block/nbd.c | 7 ++----- block/nfs.c | 7 ++----- block/parallels.c | 7 ++----- block/qcow.c | 7 ++----- block/qcow2.c | 7 ++----- block/qed.c | 7 ++----- block/rbd.c | 7 ++----- block/sheepdog.c | 14 ++++---------- block/ssh.c | 7 ++----- block/vhdx.c | 7 ++----- block/vpc.c | 7 ++----- qobject/block-qdict.c | 28 +++++++++++++++++++++++++++- 13 files changed, 53 insertions(+), 62 deletions(-) diff --git a/include/block/qdict.h b/include/block/qdict.h index 47d9638c37..d8cb502d7d 100644 --- a/include/block/qdict.h +++ b/include/block/qdict.h @@ -21,7 +21,6 @@ void qdict_extract_subqdict(QDict *src, QDict **dst, cons= t char *start); void qdict_array_split(QDict *src, QList **dst); int qdict_array_entries(QDict *src, const char *subqdict); QObject *qdict_crumple(const QDict *src, Error **errp); -QObject *qdict_crumple_for_keyval_qiv(QDict *qdict, Error **errp); void qdict_flatten(QDict *qdict); =20 typedef struct QDictRenames { @@ -30,4 +29,6 @@ typedef struct QDictRenames { } QDictRenames; bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **= errp); =20 +Visitor *qobject_input_visitor_new_flat_confused(QDict *qdict, + Error **errp); #endif diff --git a/block/nbd.c b/block/nbd.c index 614dd9fec0..13db4030e6 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -263,7 +263,6 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict= *options, { SocketAddress *saddr =3D NULL; QDict *addr =3D NULL; - QObject *crumpled_addr =3D NULL; Visitor *iv =3D NULL; Error *local_err =3D NULL; =20 @@ -273,12 +272,11 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDi= ct *options, goto done; } =20 - crumpled_addr =3D qdict_crumple_for_keyval_qiv(addr, errp); - if (!crumpled_addr) { + iv =3D qobject_input_visitor_new_flat_confused(addr, errp); + if (!iv) { goto done; } =20 - iv =3D qobject_input_visitor_new_keyval(crumpled_addr); visit_type_SocketAddress(iv, NULL, &saddr, &local_err); if (local_err) { error_propagate(errp, local_err); @@ -287,7 +285,6 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict= *options, =20 done: qobject_unref(addr); - qobject_unref(crumpled_addr); visit_free(iv); return saddr; } diff --git a/block/nfs.c b/block/nfs.c index 6935b611cc..743ca0450e 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -556,20 +556,17 @@ static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(= QDict *options, Error **errp) { BlockdevOptionsNfs *opts =3D NULL; - QObject *crumpled =3D NULL; Visitor *v; const QDictEntry *e; Error *local_err =3D NULL; =20 - crumpled =3D qdict_crumple_for_keyval_qiv(options, errp); - if (crumpled =3D=3D NULL) { + v =3D qobject_input_visitor_new_flat_confused(options, errp); + if (!v) { return NULL; } =20 - v =3D qobject_input_visitor_new_keyval(crumpled); visit_type_BlockdevOptionsNfs(v, NULL, &opts, &local_err); visit_free(v); - qobject_unref(crumpled); =20 if (local_err) { error_propagate(errp, local_err); diff --git a/block/parallels.c b/block/parallels.c index ceb7a15d62..fd215e202a 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -617,7 +617,6 @@ static int coroutine_fn parallels_co_create_opts(const = char *filename, Error *local_err =3D NULL; BlockDriverState *bs =3D NULL; QDict *qdict; - QObject *qobj; Visitor *v; int ret; =20 @@ -653,14 +652,12 @@ static int coroutine_fn parallels_co_create_opts(cons= t char *filename, qdict_put_str(qdict, "driver", "parallels"); qdict_put_str(qdict, "file", bs->node_name); =20 - qobj =3D qdict_crumple_for_keyval_qiv(qdict, errp); - if (!qobj) { + v =3D qobject_input_visitor_new_flat_confused(qdict, errp); + if (!v) { ret =3D -EINVAL; goto done; } =20 - v =3D qobject_input_visitor_new_keyval(qobj); - qobject_unref(qobj); visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_free(v); =20 diff --git a/block/qcow.c b/block/qcow.c index 2f81f081fd..5532731b9f 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -947,7 +947,6 @@ static int coroutine_fn qcow_co_create_opts(const char = *filename, BlockdevCreateOptions *create_options =3D NULL; BlockDriverState *bs =3D NULL; QDict *qdict; - QObject *qobj; Visitor *v; const char *val; Error *local_err =3D NULL; @@ -997,14 +996,12 @@ static int coroutine_fn qcow_co_create_opts(const cha= r *filename, qdict_put_str(qdict, "driver", "qcow"); qdict_put_str(qdict, "file", bs->node_name); =20 - qobj =3D qdict_crumple_for_keyval_qiv(qdict, errp); - if (!qobj) { + v =3D qobject_input_visitor_new_flat_confused(qdict, errp); + if (!v) { ret =3D -EINVAL; goto fail; } =20 - v =3D qobject_input_visitor_new_keyval(qobj); - qobject_unref(qobj); visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_free(v); =20 diff --git a/block/qcow2.c b/block/qcow2.c index 8c338661db..945132f692 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3081,7 +3081,6 @@ static int coroutine_fn qcow2_co_create_opts(const ch= ar *filename, QemuOpts *opt { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; - QObject *qobj; Visitor *v; BlockDriverState *bs =3D NULL; Error *local_err =3D NULL; @@ -3152,14 +3151,12 @@ static int coroutine_fn qcow2_co_create_opts(const = char *filename, QemuOpts *opt qdict_put_str(qdict, "file", bs->node_name); =20 /* Now get the QAPI type BlockdevCreateOptions */ - qobj =3D qdict_crumple_for_keyval_qiv(qdict, errp); - if (!qobj) { + v =3D qobject_input_visitor_new_flat_confused(qdict, errp); + if (!v) { ret =3D -EINVAL; goto finish; } =20 - v =3D qobject_input_visitor_new_keyval(qobj); - qobject_unref(qobj); visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_free(v); =20 diff --git a/block/qed.c b/block/qed.c index fcec760b26..2363814538 100644 --- a/block/qed.c +++ b/block/qed.c @@ -723,7 +723,6 @@ static int coroutine_fn bdrv_qed_co_create_opts(const c= har *filename, { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; - QObject *qobj; Visitor *v; BlockDriverState *bs =3D NULL; Error *local_err =3D NULL; @@ -763,14 +762,12 @@ static int coroutine_fn bdrv_qed_co_create_opts(const= char *filename, qdict_put_str(qdict, "driver", "qed"); qdict_put_str(qdict, "file", bs->node_name); =20 - qobj =3D qdict_crumple_for_keyval_qiv(qdict, errp); - if (!qobj) { + v =3D qobject_input_visitor_new_flat_confused(qdict, errp); + if (!v) { ret =3D -EINVAL; goto fail; } =20 - v =3D qobject_input_visitor_new_keyval(qobj); - qobject_unref(qobj); visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_free(v); =20 diff --git a/block/rbd.c b/block/rbd.c index 09720e97c0..82346a2a5e 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -630,7 +630,6 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *o= ptions, int flags, BDRVRBDState *s =3D bs->opaque; BlockdevOptionsRbd *opts =3D NULL; Visitor *v; - QObject *crumpled =3D NULL; const QDictEntry *e; Error *local_err =3D NULL; char *keypairs, *secretid; @@ -647,16 +646,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict = *options, int flags, } =20 /* Convert the remaining options into a QAPI object */ - crumpled =3D qdict_crumple_for_keyval_qiv(options, errp); - if (crumpled =3D=3D NULL) { + v =3D qobject_input_visitor_new_flat_confused(options, errp); + if (!v) { r =3D -EINVAL; goto out; } =20 - v =3D qobject_input_visitor_new_keyval(crumpled); visit_type_BlockdevOptionsRbd(v, NULL, &opts, &local_err); visit_free(v); - qobject_unref(crumpled); =20 if (local_err) { error_propagate(errp, local_err); diff --git a/block/sheepdog.c b/block/sheepdog.c index 29e3e1eaaa..665b1763eb 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -539,19 +539,17 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVShee= pdogState *s, static SocketAddress *sd_server_config(QDict *options, Error **errp) { QDict *server =3D NULL; - QObject *crumpled_server =3D NULL; Visitor *iv =3D NULL; SocketAddress *saddr =3D NULL; Error *local_err =3D NULL; =20 qdict_extract_subqdict(options, &server, "server."); =20 - crumpled_server =3D qdict_crumple_for_keyval_qiv(server, errp); - if (!crumpled_server) { + iv =3D qobject_input_visitor_new_flat_confused(server, errp); + if (!iv) { goto done; } =20 - iv =3D qobject_input_visitor_new_keyval(crumpled_server); visit_type_SocketAddress(iv, NULL, &saddr, &local_err); if (local_err) { error_propagate(errp, local_err); @@ -560,7 +558,6 @@ static SocketAddress *sd_server_config(QDict *options, = Error **errp) =20 done: visit_free(iv); - qobject_unref(crumpled_server); qobject_unref(server); return saddr; } @@ -2173,7 +2170,6 @@ static int coroutine_fn sd_co_create_opts(const char = *filename, QemuOpts *opts, { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict, *location_qdict; - QObject *crumpled; Visitor *v; char *redundancy; Error *local_err =3D NULL; @@ -2209,16 +2205,14 @@ static int coroutine_fn sd_co_create_opts(const cha= r *filename, QemuOpts *opts, } =20 /* Get the QAPI object */ - crumpled =3D qdict_crumple_for_keyval_qiv(qdict, errp); - if (crumpled =3D=3D NULL) { + v =3D qobject_input_visitor_new_flat_confused(qdict, errp); + if (!v) { ret =3D -EINVAL; goto fail; } =20 - v =3D qobject_input_visitor_new_keyval(crumpled); visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_free(v); - qobject_unref(crumpled); =20 if (local_err) { error_propagate(errp, local_err); diff --git a/block/ssh.c b/block/ssh.c index bd85d989d5..da7bbf73e2 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -606,7 +606,6 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *opt= ions, Error **errp) BlockdevOptionsSsh *result =3D NULL; QemuOpts *opts =3D NULL; Error *local_err =3D NULL; - QObject *crumpled; const QDictEntry *e; Visitor *v; =20 @@ -623,15 +622,13 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *o= ptions, Error **errp) } =20 /* Create the QAPI object */ - crumpled =3D qdict_crumple_for_keyval_qiv(options, errp); - if (crumpled =3D=3D NULL) { + v =3D qobject_input_visitor_new_flat_confused(options, errp); + if (!v) { goto fail; } =20 - v =3D qobject_input_visitor_new_keyval(crumpled); visit_type_BlockdevOptionsSsh(v, NULL, &result, &local_err); visit_free(v); - qobject_unref(crumpled); =20 if (local_err) { error_propagate(errp, local_err); diff --git a/block/vhdx.c b/block/vhdx.c index f2aec3d2cd..a677703a9e 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1966,7 +1966,6 @@ static int coroutine_fn vhdx_co_create_opts(const cha= r *filename, { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; - QObject *qobj; Visitor *v; BlockDriverState *bs =3D NULL; Error *local_err =3D NULL; @@ -2005,14 +2004,12 @@ static int coroutine_fn vhdx_co_create_opts(const c= har *filename, qdict_put_str(qdict, "driver", "vhdx"); qdict_put_str(qdict, "file", bs->node_name); =20 - qobj =3D qdict_crumple_for_keyval_qiv(qdict, errp); - if (!qobj) { + v =3D qobject_input_visitor_new_flat_confused(qdict, errp); + if (!v) { ret =3D -EINVAL; goto fail; } =20 - v =3D qobject_input_visitor_new_keyval(qobj); - qobject_unref(qobj); visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_free(v); =20 diff --git a/block/vpc.c b/block/vpc.c index a9bb04149d..bf294abfa7 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1082,7 +1082,6 @@ static int coroutine_fn vpc_co_create_opts(const char= *filename, { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; - QObject *qobj; Visitor *v; BlockDriverState *bs =3D NULL; Error *local_err =3D NULL; @@ -1119,14 +1118,12 @@ static int coroutine_fn vpc_co_create_opts(const ch= ar *filename, qdict_put_str(qdict, "driver", "vpc"); qdict_put_str(qdict, "file", bs->node_name); =20 - qobj =3D qdict_crumple_for_keyval_qiv(qdict, errp); - if (!qobj) { + v =3D qobject_input_visitor_new_flat_confused(qdict, errp); + if (!v) { ret =3D -EINVAL; goto fail; } =20 - v =3D qobject_input_visitor_new_keyval(qobj); - qobject_unref(qobj); visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_free(v); =20 diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c index aba372c2eb..41f39abc4a 100644 --- a/qobject/block-qdict.c +++ b/qobject/block-qdict.c @@ -13,6 +13,7 @@ #include "qapi/qmp/qlist.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" #include "qemu/cutils.h" #include "qapi/error.h" =20 @@ -529,7 +530,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp) * used for anything else, and it should go away once the block * subsystem has been cleaned up. */ -QObject *qdict_crumple_for_keyval_qiv(QDict *src, Error **errp) +static QObject *qdict_crumple_for_keyval_qiv(QDict *src, Error **errp) { QDict *tmp =3D NULL; char *buf; @@ -695,3 +696,28 @@ bool qdict_rename_keys(QDict *qdict, const QDictRename= s *renames, Error **errp) } return true; } + +/* + * Create a QObject input visitor for flat @qdict with possibly + * confused scalar types. + * + * The block subsystem uses this function to visit its flat QDict with + * possibly confused scalar types. It should not be used for anything + * else, and it should go away once the block subsystem has been + * cleaned up. + */ +Visitor *qobject_input_visitor_new_flat_confused(QDict *qdict, + Error **errp) +{ + QObject *crumpled; + Visitor *v; + + crumpled =3D qdict_crumple_for_keyval_qiv(qdict, errp); + if (!crumpled) { + return NULL; + } + + v =3D qobject_input_visitor_new_keyval(crumpled); + qobject_unref(crumpled); + return v; +} --=20 2.13.6