From nobody Wed May 8 16:24:03 2024 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490266647939842.4079098664632; Thu, 23 Mar 2017 03:57:27 -0700 (PDT) Received: from localhost ([::1]:55485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0Qo-0007pt-NM for importer@patchew.org; Thu, 23 Mar 2017 06:57:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0PL-0006rl-5K for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cr0PH-0005j1-Tc for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43790) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cr0PH-0005iP-M1 for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A26623D941 for ; Thu, 23 Mar 2017 10:55:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 422D11853E; Thu, 23 Mar 2017 10:55:51 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9C4981138648; Thu, 23 Mar 2017 11:55:48 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A26623D941 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A26623D941 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 23 Mar 2017 11:55:44 +0100 Message-Id: <1490266548-22500-2-git-send-email-armbru@redhat.com> In-Reply-To: <1490266548-22500-1-git-send-email-armbru@redhat.com> References: <1490266548-22500-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 23 Mar 2017 10:55:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 1/5] rbd: Clean up runtime_opts 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, 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" runtime_opts is used for three different purposes: * qemu_rbd_open() uses it to accept options it recognizes, such as "pool" and "image". Other .bdrv_open() methods do it similarly. * qemu_rbd_open() accepts additional list-valued options auth-supported and server, with the help of qemu_rbd_array_opts(). The list elements are again dictionaries. qemu_rbd_array_opts() uses runtime_opts to accept their members. Thus, runtime_opts contains recognized sub-sub-options "auth", "host", "port" in addition to recognized options. No other block driver does that. * qemu_rbd_create() uses it to converts the QDict produced by qemu_rbd_parse_filename() to QemuOpts. No other block driver does that. The keys produced by qemu_rbd_parse_filename() are "pool", "image", "snapshot", "conf", "user" and "keyvalue-pairs". qemu_rbd_open() accepts these, so no additional ones here. This is a confusing mess. Dates back to commit 0f9d252. First step to clean it up is documenting runtime_opts.desc[]: * Reorder entries to match the QAPI schema, like we do in other block drivers. * Document why the schema's "server" and "auth-supported" aren't in .desc[]. * Document why "keyvalue-pairs", "host", "port" and "auth" are in .desc[], but not the schema. * Delete "filename", because none of the three users actually uses it. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- block/rbd.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index ee13f3d..6562fbd 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -365,21 +365,6 @@ static QemuOptsList runtime_opts =3D { .head =3D QTAILQ_HEAD_INITIALIZER(runtime_opts.head), .desc =3D { { - .name =3D "filename", - .type =3D QEMU_OPT_STRING, - .help =3D "Specification of the rbd image", - }, - { - .name =3D "password-secret", - .type =3D QEMU_OPT_STRING, - .help =3D "ID of secret providing the password", - }, - { - .name =3D "conf", - .type =3D QEMU_OPT_STRING, - .help =3D "Rados config file location", - }, - { .name =3D "pool", .type =3D QEMU_OPT_STRING, .help =3D "Rados pool name", @@ -390,6 +375,11 @@ static QemuOptsList runtime_opts =3D { .help =3D "Image name in the pool", }, { + .name =3D "conf", + .type =3D QEMU_OPT_STRING, + .help =3D "Rados config file location", + }, + { .name =3D "snapshot", .type =3D QEMU_OPT_STRING, .help =3D "Ceph snapshot name", @@ -400,11 +390,30 @@ static QemuOptsList runtime_opts =3D { .type =3D QEMU_OPT_STRING, .help =3D "Rados id name", }, + /* + * server.* and auth-supported.* extracted manually, see + * qemu_rbd_array_opts() + */ + { + .name =3D "password-secret", + .type =3D QEMU_OPT_STRING, + .help =3D "ID of secret providing the password", + }, + /* + * Legacy keys accepted by qemu_rbd_parse_filename(), not in + * the QAPI schema + */ { .name =3D "keyvalue-pairs", .type =3D QEMU_OPT_STRING, .help =3D "Legacy rados key/value option parameters", }, + /* + * The remainder aren't option keys, but option sub-sub-keys, + * so that qemu_rbd_array_opts() can abuse runtime_opts for + * its own purposes + * TODO clean this up + */ { .name =3D "host", .type =3D QEMU_OPT_STRING, --=20 2.7.4 From nobody Wed May 8 16:24:03 2024 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490266814624926.9125119832427; Thu, 23 Mar 2017 04:00:14 -0700 (PDT) Received: from localhost ([::1]:55494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0TV-0001Ox-G6 for importer@patchew.org; Thu, 23 Mar 2017 07:00:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0PL-0006rn-5X for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cr0PH-0005iv-SY for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cr0PH-0005iH-N0 for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B186883A4 for ; Thu, 23 Mar 2017 10:55:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4243E7752A; Thu, 23 Mar 2017 10:55:51 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9EE8E113864C; Thu, 23 Mar 2017 11:55:48 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7B186883A4 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7B186883A4 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 23 Mar 2017 11:55:45 +0100 Message-Id: <1490266548-22500-3-git-send-email-armbru@redhat.com> In-Reply-To: <1490266548-22500-1-git-send-email-armbru@redhat.com> References: <1490266548-22500-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 23 Mar 2017 10:55:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 2/5] rbd: Clean up qemu_rbd_create()'s detour through QemuOpts 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, 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" The conversion from QDict to QemuOpts is pointless. Simply get the stuff straight from the QDict. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- block/rbd.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 6562fbd..59c822a 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -442,7 +442,6 @@ static int qemu_rbd_create(const char *filename, QemuOp= ts *opts, Error **errp) rados_t cluster; rados_ioctx_t io_ctx; QDict *options =3D NULL; - QemuOpts *rbd_opts =3D NULL; int ret =3D 0; =20 secretid =3D qemu_opt_get(opts, "password-secret"); @@ -473,19 +472,11 @@ static int qemu_rbd_create(const char *filename, Qemu= Opts *opts, Error **errp) goto exit; } =20 - rbd_opts =3D qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); - qemu_opts_absorb_qdict(rbd_opts, options, &local_err); - if (local_err) { - error_propagate(errp, local_err); - ret =3D -EINVAL; - goto exit; - } - - pool =3D qemu_opt_get(rbd_opts, "pool"); - conf =3D qemu_opt_get(rbd_opts, "conf"); - clientname =3D qemu_opt_get(rbd_opts, "user"); - name =3D qemu_opt_get(rbd_opts, "image"); - keypairs =3D qemu_opt_get(rbd_opts, "keyvalue-pairs"); + pool =3D qdict_get_str(options, "pool"); + conf =3D qdict_get_str(options, "conf"); + clientname =3D qdict_get_str(options, "user"); + name =3D qdict_get_str(options, "image"); + keypairs =3D qdict_get_str(options, "keyvalue-pairs"); =20 ret =3D rados_create(&cluster, clientname); if (ret < 0) { @@ -536,7 +527,6 @@ shutdown: =20 exit: QDECREF(options); - qemu_opts_del(rbd_opts); return ret; } =20 --=20 2.7.4 From nobody Wed May 8 16:24:03 2024 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490266748069134.4301253675602; Thu, 23 Mar 2017 03:59:08 -0700 (PDT) Received: from localhost ([::1]:55489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0SQ-0000hG-N0 for importer@patchew.org; Thu, 23 Mar 2017 06:59:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0PL-0006ro-5Z for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cr0PH-0005j7-V1 for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56070) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cr0PH-0005iU-N3 for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7BB119D23B for ; Thu, 23 Mar 2017 10:55:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 429F07E49F; Thu, 23 Mar 2017 10:55:51 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A1F5D1138651; Thu, 23 Mar 2017 11:55:48 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A7BB119D23B Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A7BB119D23B From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 23 Mar 2017 11:55:46 +0100 Message-Id: <1490266548-22500-4-git-send-email-armbru@redhat.com> In-Reply-To: <1490266548-22500-1-git-send-email-armbru@redhat.com> References: <1490266548-22500-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 23 Mar 2017 10:55:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 3/5] rbd: Rewrite the code to extract list-valued options 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, 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" We have two list-values options: * "server" is a list of InetSocketAddress. We use members "host" and "port", and silently ignore the rest. * "auth-supported" is a list of RbdAuthMethod. We use its only member "auth". Since qemu_rbd_open() takes options as a flattened QDict, options has keys of the form server.%d.host, server.%d.port and auth-supported.%d.auth, where %d counts up from zero. qemu_rbd_array_opts() extracts these values as follows. First, it calls qdict_array_entries() to find the list's length. For each list element, it first formats the list's key prefix (e.g. "server.0."), then creates a new QDict holding the options with that key prefix, then converts that to a QemuOpts, so it can finally get the member values from there. If there's one surefire way to make code using QDict more awkward, it's creating more of them and mixing in QemuOpts for good measure. The conversion to QemuOpts abuses runtime_opts, as described in the commit before previous. Rewrite to simply get the values straight from the options QDict. This removes the abuse of runtime_opts, so clean it up. Signed-off-by: Markus Armbruster --- block/rbd.c | 151 +++++++++++++++++---------------------------------------= ---- 1 file changed, 42 insertions(+), 109 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 59c822a..8ba0f79 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" =20 +#include #include "qapi/error.h" #include "qemu/error-report.h" #include "block/block_int.h" @@ -20,8 +21,6 @@ #include "qemu/cutils.h" #include "qapi/qmp/qstring.h" =20 -#include - /* * When specifying the image filename use: * @@ -408,25 +407,6 @@ static QemuOptsList runtime_opts =3D { .type =3D QEMU_OPT_STRING, .help =3D "Legacy rados key/value option parameters", }, - /* - * The remainder aren't option keys, but option sub-sub-keys, - * so that qemu_rbd_array_opts() can abuse runtime_opts for - * its own purposes - * TODO clean this up - */ - { - .name =3D "host", - .type =3D QEMU_OPT_STRING, - }, - { - .name =3D "port", - .type =3D QEMU_OPT_STRING, - }, - { - .name =3D "auth", - .type =3D QEMU_OPT_STRING, - .help =3D "Supported authentication method, either cephx or no= ne", - }, { /* end of list */ } }, }; @@ -577,91 +557,59 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb) qemu_aio_unref(acb); } =20 -#define RBD_MON_HOST 0 -#define RBD_AUTH_SUPPORTED 1 - -static char *qemu_rbd_array_opts(QDict *options, const char *prefix, int t= ype, - Error **errp) +static char *rbd_auth(QDict *options) { - int num_entries; - QemuOpts *opts =3D NULL; - QDict *sub_options; - const char *host; - const char *port; - char *str; - char *rados_str =3D NULL; - Error *local_err =3D NULL; + const char **vals =3D g_new(const char *, qdict_size(options)); + char keybuf[32]; + QObject *val; + char *rados_str; int i; =20 - assert(type =3D=3D RBD_MON_HOST || type =3D=3D RBD_AUTH_SUPPORTED); - - num_entries =3D qdict_array_entries(options, prefix); + for (i =3D 0;; i++) { + sprintf(keybuf, "auth-supported.%d.auth", i); + val =3D qdict_get(options, keybuf); + if (!val) { + break; + } =20 - if (num_entries < 0) { - error_setg(errp, "Parse error on RBD QDict array"); - return NULL; + vals[i] =3D qstring_get_str(qobject_to_qstring(val)); } + vals[i] =3D NULL; =20 - for (i =3D 0; i < num_entries; i++) { - char *strbuf =3D NULL; - const char *value; - char *rados_str_tmp; - - str =3D g_strdup_printf("%s%d.", prefix, i); - qdict_extract_subqdict(options, &sub_options, str); - g_free(str); - - opts =3D qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); - qemu_opts_absorb_qdict(opts, sub_options, &local_err); - QDECREF(sub_options); - if (local_err) { - error_propagate(errp, local_err); - g_free(rados_str); - rados_str =3D NULL; - goto exit; - } + rados_str =3D g_strjoinv(";", (char **)vals); + g_free(vals); + return rados_str; +} =20 - if (type =3D=3D RBD_MON_HOST) { - host =3D qemu_opt_get(opts, "host"); - port =3D qemu_opt_get(opts, "port"); +static char *rbd_mon_host(QDict *options) +{ + const char **vals =3D g_new(const char *, qdict_size(options)); + char keybuf[32]; + QObject *val; + const char *host, *port; + char *rados_str; + int i; =20 - value =3D host; - if (port) { - /* check for ipv6 */ - if (strchr(host, ':')) { - strbuf =3D g_strdup_printf("[%s]:%s", host, port); - } else { - strbuf =3D g_strdup_printf("%s:%s", host, port); - } - value =3D strbuf; - } else if (strchr(host, ':')) { - strbuf =3D g_strdup_printf("[%s]", host); - value =3D strbuf; - } - } else { - value =3D qemu_opt_get(opts, "auth"); + for (i =3D 0;; i++) { + sprintf(keybuf, "server.%d.host", i); + val =3D qdict_get(options, keybuf); + if (!val) { + break; } + host =3D qstring_get_str(qobject_to_qstring(val)); + sprintf(keybuf, "server.%d.port", i); + port =3D qdict_get_str(options, keybuf); =20 - - /* each iteration in the for loop will build upon the string, and = if - * rados_str is NULL then it is our first pass */ - if (rados_str) { - /* separate options with ';', as that is what rados_conf_set() - * requires */ - rados_str_tmp =3D rados_str; - rados_str =3D g_strdup_printf("%s;%s", rados_str_tmp, value); - g_free(rados_str_tmp); + if (strchr(host, ':')) { + vals[i] =3D g_strdup_printf("[%s]:%s", host, port); } else { - rados_str =3D g_strdup(value); + vals[i] =3D g_strdup_printf("%s:%s", host, port); } - - g_free(strbuf); - qemu_opts_del(opts); - opts =3D NULL; } + vals[i] =3D NULL; =20 -exit: - qemu_opts_del(opts); + rados_str =3D g_strjoinv(";", (char **)vals); + g_strfreev((char **)vals); return rados_str; } =20 @@ -685,24 +633,9 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *= options, int flags, return -EINVAL; } =20 - auth_supported =3D qemu_rbd_array_opts(options, "auth-supported.", - RBD_AUTH_SUPPORTED, &local_err); - if (local_err) { - error_propagate(errp, local_err); - r =3D -EINVAL; - goto failed_opts; - } - - mon_host =3D qemu_rbd_array_opts(options, "server.", - RBD_MON_HOST, &local_err); - if (local_err) { - error_propagate(errp, local_err); - r =3D -EINVAL; - goto failed_opts; - } - + auth_supported =3D rbd_auth(options); + mon_host =3D rbd_mon_host(options); secretid =3D qemu_opt_get(opts, "password-secret"); - pool =3D qemu_opt_get(opts, "pool"); conf =3D qemu_opt_get(opts, "conf"); snap =3D qemu_opt_get(opts, "snapshot"); --=20 2.7.4 From nobody Wed May 8 16:24:03 2024 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149026664577147.539710281789894; Thu, 23 Mar 2017 03:57:25 -0700 (PDT) Received: from localhost ([::1]:55484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0Qm-0007oY-6Q for importer@patchew.org; Thu, 23 Mar 2017 06:57:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0PL-0006rp-5e for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cr0PH-0005ik-Sf for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cr0PH-0005iO-ME for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:51 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9226AC04B93D for ; Thu, 23 Mar 2017 10:55:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 423AE19625; Thu, 23 Mar 2017 10:55:51 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A5DCC11386CB; Thu, 23 Mar 2017 11:55:48 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9226AC04B93D Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9226AC04B93D From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 23 Mar 2017 11:55:47 +0100 Message-Id: <1490266548-22500-5-git-send-email-armbru@redhat.com> In-Reply-To: <1490266548-22500-1-git-send-email-armbru@redhat.com> References: <1490266548-22500-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 23 Mar 2017 10:55:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 4/5] rbd: Peel off redundant RbdAuthMethod wrapper struct 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, 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" BlockdevOptionsRbd member auth-supported is a list of struct RbdAuthMethod, whose only member is enum RbdAuthSupport. There is no reason for wrapping the enum in a struct. Delete the wrapper, and rename the enum. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- block/rbd.c | 2 +- qapi/block-core.json | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 8ba0f79..f460d71 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -566,7 +566,7 @@ static char *rbd_auth(QDict *options) int i; =20 for (i =3D 0;; i++) { - sprintf(keybuf, "auth-supported.%d.auth", i); + sprintf(keybuf, "auth-supported.%d", i); val =3D qdict_get(options, keybuf); if (!val) { break; diff --git a/qapi/block-core.json b/qapi/block-core.json index 0f132fc..fe1e40f 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2601,25 +2601,14 @@ =20 =20 ## -# @RbdAuthSupport: -# -# An enumeration of RBD auth support -# -# Since: 2.9 -## -{ 'enum': 'RbdAuthSupport', - 'data': [ 'cephx', 'none' ] } - - -## # @RbdAuthMethod: # # An enumeration of rados auth_supported types # # Since: 2.9 ## -{ 'struct': 'RbdAuthMethod', - 'data': { 'auth': 'RbdAuthSupport' } } +{ 'enum': 'RbdAuthMethod', + 'data': [ 'cephx', 'none' ] } =20 ## # @BlockdevOptionsRbd: --=20 2.7.4 From nobody Wed May 8 16:24:03 2024 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490266645832239.96785814998316; Thu, 23 Mar 2017 03:57:25 -0700 (PDT) Received: from localhost ([::1]:55483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0Qk-0007nO-MT for importer@patchew.org; Thu, 23 Mar 2017 06:57:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr0PL-0006rk-4B for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cr0PJ-0005jp-Jy for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34436) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cr0PJ-0005jQ-DT for qemu-devel@nongnu.org; Thu, 23 Mar 2017 06:55:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D6C54E03F for ; Thu, 23 Mar 2017 10:55:53 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C83957752A; Thu, 23 Mar 2017 10:55:52 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A8AAF11385E2; Thu, 23 Mar 2017 11:55:48 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3D6C54E03F Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3D6C54E03F From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 23 Mar 2017 11:55:48 +0100 Message-Id: <1490266548-22500-6-git-send-email-armbru@redhat.com> In-Reply-To: <1490266548-22500-1-git-send-email-armbru@redhat.com> References: <1490266548-22500-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 23 Mar 2017 10:55:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 5/5] rbd: Reject options server.*.{numeric, to, ipv4, ipv6} 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, 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" We use InetSocketAddress in the QAPI schema. However, the code doesn't use inet_connect_saddr(), but formats "host" and "port" into a configuration string for rados_conf_set(). Thus, members "numeric", "to", "ipv4" and "ipv6" are silently ignored. Not nice. Factor a suitable InetSocketAddressBase out of InetSocketAddress, and use that. "numeric", "to", "ipv4" and "ipv6" are now rejected. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi-schema.json | 21 ++++++++++++++------- qapi/block-core.json | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 68a4327..b921994 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4051,19 +4051,27 @@ 'data': [ 'all', 'rx', 'tx' ] } =20 ## +# @InetSocketAddressBase: +# +# @host: host part of the address +# @port: port part of the address +## +{ 'struct': 'InetSocketAddressBase', + 'data': { + 'host': 'str', + 'port': 'str' } } + +## # @InetSocketAddress: # # Captures a socket address or address range in the Internet namespace. # -# @host: host part of the address -# -# @port: port part of the address, or lowest port if @to is present -# # @numeric: true if the host/port are guaranteed to be numeric, # false if name resolution should be attempted. Defaults to fals= e. # (Since 2.9) # -# @to: highest port to try +# @to: If present, this is range of possible addresses, with port +# between @port and @to. # # @ipv4: whether to accept IPv4 addresses, default try both IPv4 and IPv6 # @@ -4072,9 +4080,8 @@ # Since: 1.3 ## { 'struct': 'InetSocketAddress', + 'base': 'InetSocketAddressBase', 'data': { - 'host': 'str', - 'port': 'str', '*numeric': 'bool', '*to': 'uint16', '*ipv4': 'bool', diff --git a/qapi/block-core.json b/qapi/block-core.json index fe1e40f..a57c9e8 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2641,7 +2641,7 @@ '*conf': 'str', '*snapshot': 'str', '*user': 'str', - '*server': ['InetSocketAddress'], + '*server': ['InetSocketAddressBase'], '*auth-supported': ['RbdAuthMethod'], '*password-secret': 'str' } } =20 --=20 2.7.4