From nobody Wed Nov 5 02:34:11 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 1532531530483120.23495123959071; Wed, 25 Jul 2018 08:12:10 -0700 (PDT) Received: from localhost ([::1]:52053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiLSS-0007Uh-P2 for importer@patchew.org; Wed, 25 Jul 2018 11:12:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiLQo-00066R-6D for qemu-devel@nongnu.org; Wed, 25 Jul 2018 11:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fiLQl-0003Fx-3U for qemu-devel@nongnu.org; Wed, 25 Jul 2018 11:10:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40418 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 1fiLQe-0003At-EL; Wed, 25 Jul 2018 11:10:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0BD877886; Wed, 25 Jul 2018 15:10:15 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-135.ams2.redhat.com [10.36.116.135]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CEA92026D68; Wed, 25 Jul 2018 15:10:15 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1053D1138648; Wed, 25 Jul 2018 17:10:11 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 25 Jul 2018 17:10:11 +0200 Message-Id: <20180725151011.25951-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 25 Jul 2018 15:10:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 25 Jul 2018 15:10:15 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@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] [RFC PATCH] rbd: Don't convert keypairs to JSON and back 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, jdurgin@redhat.com, jcody@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com 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" qemu_rbd_parse_filename() builds a keypairs QList, converts it to JSON, and stores the resulting QString in a QDict. qemu_rbd_co_create_opts() and qemu_rbd_open() get the QString from the QDict, pass it to qemu_rbd_set_keypairs(), which converts it back into a QList. Drop both conversions, store the QList instead. This affects output of qemu-img info. Before this patch: $ qemu-img info rbd:rbd/testimg.raw:mon_host=3D192.168.15.180:rbd_cache= =3Dtrue:conf=3D/tmp/ceph.conf [junk printed by Ceph library code...] image: json:{"driver": "raw", "file": {"pool": "rbd", "image": "testimg= .raw", "conf": "/tmp/ceph.conf", "driver": "rbd", "=3Dkeyvalue-pairs": "[\"= mon_host\", \"192.168.15.180\", \"rbd_cache\", \"true\"]"}} [more output, not interesting here] After this patch, we get image: json:{"driver": "raw", "file": {"pool": "rbd", "image": "testimg= .raw", "conf": "/tmp/ceph.conf", "driver": "rbd", "=3Dkeyvalue-pairs": ["mo= n_host", "192.168.15.180", "rbd_cache", "true"]}} The value of member "=3Dkeyvalue-pairs" changes from a string containing a JSON array to that JSON array. That's an improvement of sorts. However: * Should "=3Dkeyvalue-pairs" even be visible here? It's supposed to be purely internal... * Is this a stable interface we need to preserve, warts and all? Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- block/rbd.c | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index ca8e5bbace..ddc59e1c7a 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -23,7 +23,6 @@ #include "qemu/cutils.h" #include "qapi/qmp/qstring.h" #include "qapi/qmp/qdict.h" -#include "qapi/qmp/qjson.h" #include "qapi/qmp/qlist.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qapi-visit-block-core.h" @@ -106,7 +105,7 @@ typedef struct BDRVRBDState { =20 static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx, BlockdevOptionsRbd *opts, bool cache, - const char *keypairs, const char *secretid, + QList *keypairs, const char *secretid, Error **errp); =20 static char *qemu_rbd_next_tok(char *src, char delim, char **p) @@ -221,13 +220,11 @@ static void qemu_rbd_parse_filename(const char *filen= ame, QDict *options, } =20 if (keypairs) { - qdict_put(options, "=3Dkeyvalue-pairs", - qobject_to_json(QOBJECT(keypairs))); + qdict_put(options, "=3Dkeyvalue-pairs", keypairs); } =20 done: g_free(buf); - qobject_unref(keypairs); return; } =20 @@ -281,42 +278,36 @@ static int qemu_rbd_set_auth(rados_t cluster, Blockde= vOptionsRbd *opts, return 0; } =20 -static int qemu_rbd_set_keypairs(rados_t cluster, const char *keypairs_jso= n, +static int qemu_rbd_set_keypairs(rados_t cluster, QList *keypairs, Error **errp) { - QList *keypairs; + const QListEntry *entry1, *entry2; QString *name; QString *value; const char *key; - size_t remaining; int ret =3D 0; =20 - if (!keypairs_json) { + if (!keypairs) { return ret; } - keypairs =3D qobject_to(QList, - qobject_from_json(keypairs_json, &error_abort)); - remaining =3D qlist_size(keypairs) / 2; - assert(remaining); =20 - while (remaining--) { - name =3D qobject_to(QString, qlist_pop(keypairs)); - value =3D qobject_to(QString, qlist_pop(keypairs)); + entry1 =3D qlist_first(keypairs); + do { + entry2 =3D qlist_next(entry1); + name =3D qobject_to(QString, qlist_entry_obj(entry1)); + value =3D qobject_to(QString, qlist_entry_obj(entry2)); assert(name && value); key =3D qstring_get_str(name); =20 ret =3D rados_conf_set(cluster, key, qstring_get_str(value)); - qobject_unref(value); if (ret < 0) { error_setg_errno(errp, -ret, "invalid conf option %s", key); - qobject_unref(name); ret =3D -EINVAL; break; } - qobject_unref(name); - } + entry1 =3D qlist_next(entry2); + } while(entry1); =20 - qobject_unref(keypairs); return ret; } =20 @@ -370,7 +361,7 @@ static QemuOptsList runtime_opts =3D { =20 /* FIXME Deprecate and remove keypairs or make it available in QMP. */ static int qemu_rbd_do_create(BlockdevCreateOptions *options, - const char *keypairs, const char *password_s= ecret, + QList *keypairs, const char *password_secret, Error **errp) { BlockdevCreateOptionsRbd *opts =3D &options->u.rbd; @@ -430,7 +421,8 @@ static int coroutine_fn qemu_rbd_co_create_opts(const c= har *filename, BlockdevCreateOptionsRbd *rbd_opts; BlockdevOptionsRbd *loc; Error *local_err =3D NULL; - const char *keypairs, *password_secret; + const char *password_secret; + QList *keypairs; QDict *options =3D NULL; int ret =3D 0; =20 @@ -470,7 +462,8 @@ static int coroutine_fn qemu_rbd_co_create_opts(const c= har *filename, loc->user =3D g_strdup(qdict_get_try_str(options, "user")); loc->has_user =3D !!loc->user; loc->image =3D g_strdup(qdict_get_try_str(options, "image")); - keypairs =3D qdict_get_try_str(options, "=3Dkeyvalue-pairs"); + /* non-string type, but it comes from qemu_rbd_parse_filename() */ + keypairs =3D qdict_get_qlist(options, "=3Dkeyvalue-pairs"); =20 ret =3D qemu_rbd_do_create(create_options, keypairs, password_secret, = errp); if (ret < 0) { @@ -567,7 +560,7 @@ static char *qemu_rbd_mon_host(BlockdevOptionsRbd *opts= , Error **errp) =20 static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx, BlockdevOptionsRbd *opts, bool cache, - const char *keypairs, const char *secretid, + QList *keypairs, const char *secretid, Error **errp) { char *mon_host =3D NULL; @@ -663,10 +656,11 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict = *options, int flags, Visitor *v; const QDictEntry *e; Error *local_err =3D NULL; - char *keypairs, *secretid; + QList *keypairs; + char *secretid; int r; =20 - keypairs =3D g_strdup(qdict_get_try_str(options, "=3Dkeyvalue-pairs")); + keypairs =3D qobject_ref(qdict_get_qlist(options, "=3Dkeyvalue-pairs")= ); if (keypairs) { qdict_del(options, "=3Dkeyvalue-pairs"); } @@ -741,7 +735,7 @@ failed_open: rados_shutdown(s->cluster); out: qapi_free_BlockdevOptionsRbd(opts); - g_free(keypairs); + qobject_unref(keypairs); g_free(secretid); return r; } --=20 2.17.1