From nobody Thu May 2 08:34:57 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 1488300407630283.7799103407061; Tue, 28 Feb 2017 08:46:47 -0800 (PST) Received: from localhost ([::1]:35426 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikvF-0005mP-S1 for importer@patchew.org; Tue, 28 Feb 2017 11:46:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikjb-0004ML-Dp for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cikja-0001ss-5f for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14419) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cikjX-0001rI-Dv; Tue, 28 Feb 2017 11:34:39 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90990C05B1F4; Tue, 28 Feb 2017 16:34:39 +0000 (UTC) Received: from localhost (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SGYcWD001381 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Feb 2017 11:34:39 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 28 Feb 2017 11:34:32 -0500 Message-Id: <20170228163436.31357-2-jcody@redhat.com> In-Reply-To: <20170228163436.31357-1-jcody@redhat.com> References: <20170228163436.31357-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 28 Feb 2017 16:34:39 +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] [PULL v2 1/5] block/rbd: don't copy strings in qemu_rbd_next_tok() 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: peter.maydell@linaro.org, jcody@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" This patch is prep work for parsing options for .bdrv_parse_filename, and using QDict options. The function qemu_rbd_next_tok() searched for various key/value pairs, and copied them into buffers. This will soon be an unnecessary extra step, so we will now return found strings by reference only, and offload the responsibility for safely handling/coping these strings to the caller. This also cleans up error handling some, as the callers now rely on the Error object to determine if there is a parse error. Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster Signed-off-by: Jeff Cody --- block/rbd.c | 99 +++++++++++++++++++++++++++++++++++++++------------------= ---- 1 file changed, 64 insertions(+), 35 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 22e8e69..33c21d8 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -102,10 +102,10 @@ typedef struct BDRVRBDState { char *snap; } BDRVRBDState; =20 -static int qemu_rbd_next_tok(char *dst, int dst_len, - char *src, char delim, - const char *name, - char **p, Error **errp) +static char *qemu_rbd_next_tok(int max_len, + char *src, char delim, + const char *name, + char **p, Error **errp) { int l; char *end; @@ -127,17 +127,15 @@ static int qemu_rbd_next_tok(char *dst, int dst_len, } } l =3D strlen(src); - if (l >=3D dst_len) { + if (l >=3D max_len) { error_setg(errp, "%s too long", name); - return -EINVAL; + return NULL; } else if (l =3D=3D 0) { error_setg(errp, "%s too short", name); - return -EINVAL; + return NULL; } =20 - pstrcpy(dst, dst_len, src); - - return 0; + return src; } =20 static void qemu_rbd_unescape(char *src) @@ -162,7 +160,9 @@ static int qemu_rbd_parsename(const char *filename, { const char *start; char *p, *buf; - int ret; + int ret =3D 0; + char *found_str; + Error *local_err =3D NULL; =20 if (!strstart(filename, "rbd:", &start)) { error_setg(errp, "File name must start with 'rbd:'"); @@ -174,36 +174,60 @@ static int qemu_rbd_parsename(const char *filename, *snap =3D '\0'; *conf =3D '\0'; =20 - ret =3D qemu_rbd_next_tok(pool, pool_len, p, - '/', "pool name", &p, errp); - if (ret < 0 || !p) { + found_str =3D qemu_rbd_next_tok(pool_len, p, + '/', "pool name", &p, &local_err); + if (local_err) { + goto done; + } + if (!p) { ret =3D -EINVAL; + error_setg(errp, "Pool name is required"); goto done; } - qemu_rbd_unescape(pool); + qemu_rbd_unescape(found_str); + g_strlcpy(pool, found_str, pool_len); =20 if (strchr(p, '@')) { - ret =3D qemu_rbd_next_tok(name, name_len, p, - '@', "object name", &p, errp); - if (ret < 0) { + found_str =3D qemu_rbd_next_tok(name_len, p, + '@', "object name", &p, &local_err); + if (local_err) { goto done; } - ret =3D qemu_rbd_next_tok(snap, snap_len, p, - ':', "snap name", &p, errp); - qemu_rbd_unescape(snap); + qemu_rbd_unescape(found_str); + g_strlcpy(name, found_str, name_len); + + found_str =3D qemu_rbd_next_tok(snap_len, p, + ':', "snap name", &p, &local_err); + if (local_err) { + goto done; + } + qemu_rbd_unescape(found_str); + g_strlcpy(snap, found_str, snap_len); } else { - ret =3D qemu_rbd_next_tok(name, name_len, p, - ':', "object name", &p, errp); + found_str =3D qemu_rbd_next_tok(name_len, p, + ':', "object name", &p, &local_err); + if (local_err) { + goto done; + } + qemu_rbd_unescape(found_str); + g_strlcpy(name, found_str, name_len); } - qemu_rbd_unescape(name); - if (ret < 0 || !p) { + if (!p) { goto done; } =20 - ret =3D qemu_rbd_next_tok(conf, conf_len, p, - '\0', "configuration", &p, errp); + found_str =3D qemu_rbd_next_tok(conf_len, p, + '\0', "configuration", &p, &local_err); + if (local_err) { + goto done; + } + g_strlcpy(conf, found_str, conf_len); =20 done: + if (local_err) { + ret =3D -EINVAL; + error_propagate(errp, local_err); + } g_free(buf); return ret; } @@ -262,17 +286,18 @@ static int qemu_rbd_set_conf(rados_t cluster, const c= har *conf, Error **errp) { char *p, *buf; - char name[RBD_MAX_CONF_NAME_SIZE]; - char value[RBD_MAX_CONF_VAL_SIZE]; + char *name; + char *value; + Error *local_err =3D NULL; int ret =3D 0; =20 buf =3D g_strdup(conf); p =3D buf; =20 while (p) { - ret =3D qemu_rbd_next_tok(name, sizeof(name), p, - '=3D', "conf option name", &p, errp); - if (ret < 0) { + name =3D qemu_rbd_next_tok(RBD_MAX_CONF_NAME_SIZE, p, + '=3D', "conf option name", &p, &local_err= ); + if (local_err) { break; } qemu_rbd_unescape(name); @@ -283,9 +308,9 @@ static int qemu_rbd_set_conf(rados_t cluster, const cha= r *conf, break; } =20 - ret =3D qemu_rbd_next_tok(value, sizeof(value), p, - ':', "conf option value", &p, errp); - if (ret < 0) { + value =3D qemu_rbd_next_tok(RBD_MAX_CONF_VAL_SIZE, p, + ':', "conf option value", &p, &local_err= ); + if (local_err) { break; } qemu_rbd_unescape(value); @@ -313,6 +338,10 @@ static int qemu_rbd_set_conf(rados_t cluster, const ch= ar *conf, } } =20 + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + } g_free(buf); return ret; } --=20 2.9.3 From nobody Thu May 2 08:34:57 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 1488300138084613.0862881201756; Tue, 28 Feb 2017 08:42:18 -0800 (PST) Received: from localhost ([::1]:35390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikqt-0001YS-RM for importer@patchew.org; Tue, 28 Feb 2017 11:42:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikjc-0004N6-1n for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cikjb-0001tP-7F for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56298) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cikjY-0001rj-K3; Tue, 28 Feb 2017 11:34:40 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0E2681127; Tue, 28 Feb 2017 16:34:40 +0000 (UTC) Received: from localhost (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SGYdbe011358 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Feb 2017 11:34:40 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 28 Feb 2017 11:34:33 -0500 Message-Id: <20170228163436.31357-3-jcody@redhat.com> In-Reply-To: <20170228163436.31357-1-jcody@redhat.com> References: <20170228163436.31357-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 28 Feb 2017 16:34:40 +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] [PULL v2 2/5] block/rbd: add all the currently supported 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: peter.maydell@linaro.org, jcody@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" This adds all the currently supported runtime opts, which are the options as parsed from the filename. All of these options are explicitly checked for during during runtime, with an exception to the "keyvalue-pairs" option. This option contains all the key/value pairs that the QEMU rbd driver merely unescapes, and passes along blindly to rados. This option is a "legacy" option, and will not be exposed in the QAPI or available for introspection. Reviewed-by: Eric Blake Signed-off-by: Jeff Cody --- block/rbd.c | 68 ++++++++++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 33c21d8..67d680c 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -357,6 +357,55 @@ static void qemu_rbd_memset(RADOSCB *rcb, int64_t offs) } } =20 +static QemuOptsList runtime_opts =3D { + .name =3D "rbd", + .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", + }, + { + .name =3D "image", + .type =3D QEMU_OPT_STRING, + .help =3D "Image name in the pool", + }, + { + .name =3D "snapshot", + .type =3D QEMU_OPT_STRING, + .help =3D "Ceph snapshot name", + }, + { + /* maps to 'id' in rados_create() */ + .name =3D "user", + .type =3D QEMU_OPT_STRING, + .help =3D "Rados id name", + }, + { + .name =3D "keyvalue-pairs", + .type =3D QEMU_OPT_STRING, + .help =3D "Legacy rados key/value option parameters", + }, + { /* end of list */ } + }, +}; + static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **e= rrp) { Error *local_err =3D NULL; @@ -500,25 +549,6 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb) qemu_aio_unref(acb); } =20 -/* TODO Convert to fine grained options */ -static QemuOptsList runtime_opts =3D { - .name =3D "rbd", - .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", - }, - { /* end of list */ } - }, -}; - static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { --=20 2.9.3 From nobody Thu May 2 08:34:57 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 1488300534765885.6061775677899; Tue, 28 Feb 2017 08:48:54 -0800 (PST) Received: from localhost ([::1]:35438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikxH-0007Y2-9t for importer@patchew.org; Tue, 28 Feb 2017 11:48:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikjh-0004VD-6R for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cikje-0001vo-Il for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42146) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cikjZ-0001sF-TX; Tue, 28 Feb 2017 11:34:42 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 102327FB65; Tue, 28 Feb 2017 16:34:42 +0000 (UTC) Received: from localhost (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9D4B42D655; Tue, 28 Feb 2017 16:34:41 +0000 (UTC) From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 28 Feb 2017 11:34:34 -0500 Message-Id: <20170228163436.31357-4-jcody@redhat.com> In-Reply-To: <20170228163436.31357-1-jcody@redhat.com> References: <20170228163436.31357-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 28 Feb 2017 16:34:42 +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] [PULL v2 3/5] block/rbd: parse all options via bdrv_parse_filename 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: peter.maydell@linaro.org, jcody@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" Get rid of qemu_rbd_parsename in favor of bdrv_parse_filename. This simplifies a lot of the parsing as well, as we can treat everything a bit simpler since nonexistent options are simply NULL pointers instead of empty strings. An important item to note: Ceph has many extra option values that can be specified as key/value pairs. This was handled previously in the driver by extracting the values that the QEMU driver cared about, and then blindly passing all extra options to rbd after splitting them into key/value pairs, and cleaning up any special character escaping. The practice is continued in this patch; there is an option "keyvalue-pairs" that is populated with all the key/value pairs that the QEMU driver does not care about. These key/value pairs will override any settings in the 'conf' configuration file, just as they did before. Reviewed-by: Eric Blake Signed-off-by: Jeff Cody --- block/rbd.c | 303 ++++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 153 insertions(+), 150 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 67d680c..cc43f42 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -18,6 +18,7 @@ #include "block/block_int.h" #include "crypto/secret.h" #include "qemu/cutils.h" +#include "qapi/qmp/qstring.h" =20 #include =20 @@ -151,113 +152,134 @@ static void qemu_rbd_unescape(char *src) *p =3D '\0'; } =20 -static int qemu_rbd_parsename(const char *filename, - char *pool, int pool_len, - char *snap, int snap_len, - char *name, int name_len, - char *conf, int conf_len, - Error **errp) +static void qemu_rbd_parse_filename(const char *filename, QDict *options, + Error **errp) { const char *start; - char *p, *buf; - int ret =3D 0; + char *p, *buf, *keypairs; char *found_str; + size_t max_keypair_size; Error *local_err =3D NULL; =20 if (!strstart(filename, "rbd:", &start)) { error_setg(errp, "File name must start with 'rbd:'"); - return -EINVAL; + return; } =20 + max_keypair_size =3D strlen(start) + 1; buf =3D g_strdup(start); + keypairs =3D g_malloc0(max_keypair_size); p =3D buf; - *snap =3D '\0'; - *conf =3D '\0'; =20 - found_str =3D qemu_rbd_next_tok(pool_len, p, + found_str =3D qemu_rbd_next_tok(RBD_MAX_POOL_NAME_SIZE, p, '/', "pool name", &p, &local_err); if (local_err) { goto done; } if (!p) { - ret =3D -EINVAL; error_setg(errp, "Pool name is required"); goto done; } qemu_rbd_unescape(found_str); - g_strlcpy(pool, found_str, pool_len); + qdict_put(options, "pool", qstring_from_str(found_str)); =20 if (strchr(p, '@')) { - found_str =3D qemu_rbd_next_tok(name_len, p, + found_str =3D qemu_rbd_next_tok(RBD_MAX_IMAGE_NAME_SIZE, p, '@', "object name", &p, &local_err); if (local_err) { goto done; } qemu_rbd_unescape(found_str); - g_strlcpy(name, found_str, name_len); + qdict_put(options, "image", qstring_from_str(found_str)); =20 - found_str =3D qemu_rbd_next_tok(snap_len, p, + found_str =3D qemu_rbd_next_tok(RBD_MAX_SNAP_NAME_SIZE, p, ':', "snap name", &p, &local_err); if (local_err) { goto done; } qemu_rbd_unescape(found_str); - g_strlcpy(snap, found_str, snap_len); + qdict_put(options, "snapshot", qstring_from_str(found_str)); } else { - found_str =3D qemu_rbd_next_tok(name_len, p, + found_str =3D qemu_rbd_next_tok(RBD_MAX_IMAGE_NAME_SIZE, p, ':', "object name", &p, &local_err); if (local_err) { goto done; } qemu_rbd_unescape(found_str); - g_strlcpy(name, found_str, name_len); + qdict_put(options, "image", qstring_from_str(found_str)); } if (!p) { goto done; } =20 - found_str =3D qemu_rbd_next_tok(conf_len, p, + found_str =3D qemu_rbd_next_tok(RBD_MAX_CONF_NAME_SIZE, p, '\0', "configuration", &p, &local_err); if (local_err) { goto done; } - g_strlcpy(conf, found_str, conf_len); + + p =3D found_str; + + /* The following are essentially all key/value pairs, and we treat + * 'id' and 'conf' a bit special. Key/value pairs may be in any order= . */ + while (p) { + char *name, *value; + name =3D qemu_rbd_next_tok(RBD_MAX_CONF_NAME_SIZE, p, + '=3D', "conf option name", &p, &local_err= ); + if (local_err) { + break; + } + + if (!p) { + error_setg(errp, "conf option %s has no value", name); + break; + } + + qemu_rbd_unescape(name); + + value =3D qemu_rbd_next_tok(RBD_MAX_CONF_VAL_SIZE, p, + ':', "conf option value", &p, &local_err= ); + if (local_err) { + break; + } + qemu_rbd_unescape(value); + + if (!strcmp(name, "conf")) { + qdict_put(options, "conf", qstring_from_str(value)); + } else if (!strcmp(name, "id")) { + qdict_put(options, "user" , qstring_from_str(value)); + } else { + /* FIXME: This is pretty ugly, and not the right way to do thi= s. + * These should be contained in a structure, and then + * passed explicitly as individual key/value pairs to + * rados. Consider this legacy code that needs to be + * updated. */ + char *tmp =3D g_malloc0(max_keypair_size); + /* only use a delimiter if it is not the first keypair found */ + /* These are sets of unknown key/value pairs we'll pass along + * to ceph */ + if (keypairs[0]) { + snprintf(tmp, max_keypair_size, ":%s=3D%s", name, value); + pstrcat(keypairs, max_keypair_size, tmp); + } else { + snprintf(keypairs, max_keypair_size, "%s=3D%s", name, valu= e); + } + g_free(tmp); + } + } + + if (keypairs[0]) { + qdict_put(options, "keyvalue-pairs", qstring_from_str(keypairs)); + } + =20 done: if (local_err) { - ret =3D -EINVAL; error_propagate(errp, local_err); } g_free(buf); - return ret; -} - -static char *qemu_rbd_parse_clientname(const char *conf, char *clientname) -{ - const char *p =3D conf; - - while (*p) { - int len; - const char *end =3D strchr(p, ':'); - - if (end) { - len =3D end - p; - } else { - len =3D strlen(p); - } - - if (strncmp(p, "id=3D", 3) =3D=3D 0) { - len -=3D 3; - strncpy(clientname, p + 3, len); - clientname[len] =3D '\0'; - return clientname; - } - if (end =3D=3D NULL) { - break; - } - p =3D end + 1; - } - return NULL; + g_free(keypairs); + return; } =20 =20 @@ -280,10 +302,8 @@ static int qemu_rbd_set_auth(rados_t cluster, const ch= ar *secretid, return 0; } =20 - -static int qemu_rbd_set_conf(rados_t cluster, const char *conf, - bool only_read_conf_file, - Error **errp) +static int qemu_rbd_set_keypairs(rados_t cluster, const char *keypairs, + Error **errp) { char *p, *buf; char *name; @@ -291,7 +311,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const cha= r *conf, Error *local_err =3D NULL; int ret =3D 0; =20 - buf =3D g_strdup(conf); + buf =3D g_strdup(keypairs); p =3D buf; =20 while (p) { @@ -300,7 +320,6 @@ static int qemu_rbd_set_conf(rados_t cluster, const cha= r *conf, if (local_err) { break; } - qemu_rbd_unescape(name); =20 if (!p) { error_setg(errp, "conf option %s has no value", name); @@ -313,28 +332,12 @@ static int qemu_rbd_set_conf(rados_t cluster, const c= har *conf, if (local_err) { break; } - qemu_rbd_unescape(value); =20 - if (strcmp(name, "conf") =3D=3D 0) { - /* read the conf file alone, so it doesn't override more - specific settings for a particular device */ - if (only_read_conf_file) { - ret =3D rados_conf_read_file(cluster, value); - if (ret < 0) { - error_setg_errno(errp, -ret, "error reading conf file = %s", - value); - break; - } - } - } else if (strcmp(name, "id") =3D=3D 0) { - /* ignore, this is parsed by qemu_rbd_parse_clientname() */ - } else if (!only_read_conf_file) { - ret =3D rados_conf_set(cluster, name, value); - if (ret < 0) { - error_setg_errno(errp, -ret, "invalid conf option %s", nam= e); - ret =3D -EINVAL; - break; - } + ret =3D rados_conf_set(cluster, name, value); + if (ret < 0) { + error_setg_errno(errp, -ret, "invalid conf option %s", name); + ret =3D -EINVAL; + break; } } =20 @@ -412,27 +415,16 @@ static int qemu_rbd_create(const char *filename, Qemu= Opts *opts, Error **errp) int64_t bytes =3D 0; int64_t objsize; int obj_order =3D 0; - char pool[RBD_MAX_POOL_NAME_SIZE]; - char name[RBD_MAX_IMAGE_NAME_SIZE]; - char snap_buf[RBD_MAX_SNAP_NAME_SIZE]; - char conf[RBD_MAX_CONF_SIZE]; - char clientname_buf[RBD_MAX_CONF_SIZE]; - char *clientname; + const char *pool, *name, *conf, *clientname, *keypairs; const char *secretid; rados_t cluster; rados_ioctx_t io_ctx; - int ret; + QDict *options =3D NULL; + QemuOpts *rbd_opts =3D NULL; + int ret =3D 0; =20 secretid =3D qemu_opt_get(opts, "password-secret"); =20 - if (qemu_rbd_parsename(filename, pool, sizeof(pool), - snap_buf, sizeof(snap_buf), - name, sizeof(name), - conf, sizeof(conf), &local_err) < 0) { - error_propagate(errp, local_err); - return -EINVAL; - } - /* Read out options */ bytes =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), BDRV_SECTOR_SIZE); @@ -440,35 +432,55 @@ static int qemu_rbd_create(const char *filename, Qemu= Opts *opts, Error **errp) if (objsize) { if ((objsize - 1) & objsize) { /* not a power of 2? */ error_setg(errp, "obj size needs to be power of 2"); - return -EINVAL; + ret =3D -EINVAL; + goto exit; } if (objsize < 4096) { error_setg(errp, "obj size too small"); - return -EINVAL; + ret =3D -EINVAL; + goto exit; } obj_order =3D ctz32(objsize); } =20 - clientname =3D qemu_rbd_parse_clientname(conf, clientname_buf); + options =3D qdict_new(); + qemu_rbd_parse_filename(filename, options, &local_err); + if (local_err) { + ret =3D -EINVAL; + error_propagate(errp, local_err); + goto exit; + } + + 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"); + ret =3D rados_create(&cluster, clientname); if (ret < 0) { error_setg_errno(errp, -ret, "error initializing"); - return ret; + goto exit; } =20 - if (strstr(conf, "conf=3D") =3D=3D NULL) { - /* try default location, but ignore failure */ - rados_conf_read_file(cluster, NULL); - } else if (conf[0] !=3D '\0' && - qemu_rbd_set_conf(cluster, conf, true, &local_err) < 0) { - error_propagate(errp, local_err); + /* try default location when conf=3DNULL, but ignore failure */ + ret =3D rados_conf_read_file(cluster, conf); + if (conf && ret < 0) { + error_setg_errno(errp, -ret, "error reading conf file %s", conf); ret =3D -EIO; goto shutdown; } =20 - if (conf[0] !=3D '\0' && - qemu_rbd_set_conf(cluster, conf, false, &local_err) < 0) { - error_propagate(errp, local_err); + ret =3D qemu_rbd_set_keypairs(cluster, keypairs, errp); + if (ret < 0) { ret =3D -EIO; goto shutdown; } @@ -499,6 +511,10 @@ static int qemu_rbd_create(const char *filename, QemuO= pts *opts, Error **errp) =20 shutdown: rados_shutdown(cluster); + +exit: + QDECREF(options); + qemu_opts_del(rbd_opts); return ret; } =20 @@ -553,15 +569,10 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict = *options, int flags, Error **errp) { BDRVRBDState *s =3D bs->opaque; - char pool[RBD_MAX_POOL_NAME_SIZE]; - char snap_buf[RBD_MAX_SNAP_NAME_SIZE]; - char conf[RBD_MAX_CONF_SIZE]; - char clientname_buf[RBD_MAX_CONF_SIZE]; - char *clientname; + const char *pool, *snap, *conf, *clientname, *name, *keypairs; const char *secretid; QemuOpts *opts; Error *local_err =3D NULL; - const char *filename; int r; =20 opts =3D qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); @@ -572,44 +583,36 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict = *options, int flags, return -EINVAL; } =20 - filename =3D qemu_opt_get(opts, "filename"); secretid =3D qemu_opt_get(opts, "password-secret"); =20 - if (qemu_rbd_parsename(filename, pool, sizeof(pool), - snap_buf, sizeof(snap_buf), - s->name, sizeof(s->name), - conf, sizeof(conf), errp) < 0) { - r =3D -EINVAL; - goto failed_opts; - } + pool =3D qemu_opt_get(opts, "pool"); + conf =3D qemu_opt_get(opts, "conf"); + snap =3D qemu_opt_get(opts, "snapshot"); + clientname =3D qemu_opt_get(opts, "user"); + name =3D qemu_opt_get(opts, "image"); + keypairs =3D qemu_opt_get(opts, "keyvalue-pairs"); =20 - clientname =3D qemu_rbd_parse_clientname(conf, clientname_buf); r =3D rados_create(&s->cluster, clientname); if (r < 0) { error_setg_errno(errp, -r, "error initializing"); goto failed_opts; } =20 - s->snap =3D NULL; - if (snap_buf[0] !=3D '\0') { - s->snap =3D g_strdup(snap_buf); + s->snap =3D g_strdup(snap); + if (name) { + pstrcpy(s->name, RBD_MAX_IMAGE_NAME_SIZE, name); } =20 - if (strstr(conf, "conf=3D") =3D=3D NULL) { - /* try default location, but ignore failure */ - rados_conf_read_file(s->cluster, NULL); - } else if (conf[0] !=3D '\0') { - r =3D qemu_rbd_set_conf(s->cluster, conf, true, errp); - if (r < 0) { - goto failed_shutdown; - } + /* try default location when conf=3DNULL, but ignore failure */ + r =3D rados_conf_read_file(s->cluster, conf); + if (conf && r < 0) { + error_setg_errno(errp, -r, "error reading conf file %s", conf); + goto failed_shutdown; } =20 - if (conf[0] !=3D '\0') { - r =3D qemu_rbd_set_conf(s->cluster, conf, false, errp); - if (r < 0) { - goto failed_shutdown; - } + r =3D qemu_rbd_set_keypairs(s->cluster, keypairs, errp); + if (r < 0) { + goto failed_shutdown; } =20 if (qemu_rbd_set_auth(s->cluster, secretid, errp) < 0) { @@ -1063,18 +1066,18 @@ static QemuOptsList qemu_rbd_create_opts =3D { }; =20 static BlockDriver bdrv_rbd =3D { - .format_name =3D "rbd", - .instance_size =3D sizeof(BDRVRBDState), - .bdrv_needs_filename =3D true, - .bdrv_file_open =3D qemu_rbd_open, - .bdrv_close =3D qemu_rbd_close, - .bdrv_create =3D qemu_rbd_create, - .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_get_info =3D qemu_rbd_getinfo, - .create_opts =3D &qemu_rbd_create_opts, - .bdrv_getlength =3D qemu_rbd_getlength, - .bdrv_truncate =3D qemu_rbd_truncate, - .protocol_name =3D "rbd", + .format_name =3D "rbd", + .instance_size =3D sizeof(BDRVRBDState), + .bdrv_parse_filename =3D qemu_rbd_parse_filename, + .bdrv_file_open =3D qemu_rbd_open, + .bdrv_close =3D qemu_rbd_close, + .bdrv_create =3D qemu_rbd_create, + .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_get_info =3D qemu_rbd_getinfo, + .create_opts =3D &qemu_rbd_create_opts, + .bdrv_getlength =3D qemu_rbd_getlength, + .bdrv_truncate =3D qemu_rbd_truncate, + .protocol_name =3D "rbd", =20 .bdrv_aio_readv =3D qemu_rbd_aio_readv, .bdrv_aio_writev =3D qemu_rbd_aio_writev, --=20 2.9.3 From nobody Thu May 2 08:34:57 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 148830025537645.06558336945807; Tue, 28 Feb 2017 08:44:15 -0800 (PST) Received: from localhost ([::1]:35405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciksn-0003Sr-W9 for importer@patchew.org; Tue, 28 Feb 2017 11:44:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikjh-0004Vy-PP for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cikjg-0001xB-Th for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48876) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cikjb-0001tB-8V; Tue, 28 Feb 2017 11:34:43 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A42D61BAB; Tue, 28 Feb 2017 16:34:43 +0000 (UTC) Received: from localhost (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SGYgn7027021 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Feb 2017 11:34:43 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 28 Feb 2017 11:34:35 -0500 Message-Id: <20170228163436.31357-5-jcody@redhat.com> In-Reply-To: <20170228163436.31357-1-jcody@redhat.com> References: <20170228163436.31357-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 28 Feb 2017 16:34:43 +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] [PULL v2 4/5] block/rbd: add blockdev-add support 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: peter.maydell@linaro.org, jcody@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" Reviewed-by: Eric Blake Signed-off-by: Jeff Cody --- qapi/block-core.json | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index cf24c04..803edc3 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2111,6 +2111,7 @@ # @replication: Since 2.8 # @ssh: Since 2.8 # @iscsi: Since 2.9 +# @rbd: Since 2.9 # # Since: 2.0 ## @@ -2119,7 +2120,7 @@ 'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', - 'quorum', 'raw', 'replication', 'ssh', 'vdi', 'vhdx', 'vmdk', + 'quorum', 'raw', 'rbd', 'replication', 'ssh', 'vdi', 'vhdx', '= vmdk', 'vpc', 'vvfat' ] } =20 ## @@ -2666,6 +2667,34 @@ '*timeout': 'int' } } =20 ## +# @BlockdevOptionsRbd: +# +# @pool: Ceph pool name. +# +# @image: Image name in the Ceph pool. +# +# @conf: #optional path to Ceph configuration file. Values +# in the configuration file will be overridden by +# options specified via QAPI. +# +# @snapshot: #optional Ceph snapshot name. +# +# @user: #optional Ceph id name. +# +# @password-secret: #optional The ID of a QCryptoSecret object providing +# the password for the login. +# +# Since: 2.9 +## +{ 'struct': 'BlockdevOptionsRbd', + 'data': { 'pool': 'str', + 'image': 'str', + '*conf': 'str', + '*snapshot': 'str', + '*user': 'str', + '*password-secret': 'str' } } + +## # @ReplicationMode: # # An enumeration of replication modes. @@ -2863,7 +2892,7 @@ 'qed': 'BlockdevOptionsGenericCOWFormat', 'quorum': 'BlockdevOptionsQuorum', 'raw': 'BlockdevOptionsRaw', -# TODO rbd: Wait for structured options + 'rbd': 'BlockdevOptionsRbd', 'replication':'BlockdevOptionsReplication', # TODO sheepdog: Wait for structured options 'ssh': 'BlockdevOptionsSsh', --=20 2.9.3 From nobody Thu May 2 08:34:57 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 1488299852152677.9286505552307; Tue, 28 Feb 2017 08:37:32 -0800 (PST) Received: from localhost ([::1]:35363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikmH-0005kp-Pe for importer@patchew.org; Tue, 28 Feb 2017 11:37:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikji-0004WY-OA for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cikjh-0001xP-Dz for qemu-devel@nongnu.org; Tue, 28 Feb 2017 11:34:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36010) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cikjc-0001u5-EF; Tue, 28 Feb 2017 11:34:44 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CF863D956; Tue, 28 Feb 2017 16:34:44 +0000 (UTC) Received: from localhost (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SGYhg9001438 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Feb 2017 11:34:44 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 28 Feb 2017 11:34:36 -0500 Message-Id: <20170228163436.31357-6-jcody@redhat.com> In-Reply-To: <20170228163436.31357-1-jcody@redhat.com> References: <20170228163436.31357-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 28 Feb 2017 16:34:44 +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] [PULL v2 5/5] block/rbd: add support for 'mon_host', 'auth_supported' via QAPI 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: peter.maydell@linaro.org, jcody@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" This adds support for three additional options that may be specified by QAPI in blockdev-add: server: host, port auth method: either 'cephx' or 'none' The "server" and "auth-supported" QAPI parameters are arrays. To conform with the rados API, the array items are join as a single string with a ';' character as a delimiter when setting the configuration values. Reviewed-by: Markus Armbruster Signed-off-by: Jeff Cody --- block/rbd.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ qapi/block-core.json | 29 +++++++++++ 2 files changed, 163 insertions(+) diff --git a/block/rbd.c b/block/rbd.c index cc43f42..8b039fa 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -405,6 +405,19 @@ static QemuOptsList runtime_opts =3D { .type =3D QEMU_OPT_STRING, .help =3D "Legacy rados key/value option parameters", }, + { + .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 */ } }, }; @@ -565,6 +578,93 @@ 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) +{ + 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; + + assert(type =3D=3D RBD_MON_HOST || type =3D=3D RBD_AUTH_SUPPORTED); + + num_entries =3D qdict_array_entries(options, prefix); + + if (num_entries < 0) { + error_setg(errp, "Parse error on RBD QDict array"); + return NULL; + } + + for (int 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; + } + + if (type =3D=3D RBD_MON_HOST) { + host =3D qemu_opt_get(opts, "host"); + port =3D qemu_opt_get(opts, "port"); + + 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"); + } + + + /* 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); + } else { + rados_str =3D g_strdup(value); + } + + g_free(strbuf); + qemu_opts_del(opts); + opts =3D NULL; + } + +exit: + qemu_opts_del(opts); + return rados_str; +} + static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { @@ -573,6 +673,8 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *o= ptions, int flags, const char *secretid; QemuOpts *opts; Error *local_err =3D NULL; + char *mon_host =3D NULL; + char *auth_supported =3D NULL; int r; =20 opts =3D qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); @@ -583,6 +685,22 @@ 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; + } + secretid =3D qemu_opt_get(opts, "password-secret"); =20 pool =3D qemu_opt_get(opts, "pool"); @@ -615,6 +733,20 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *= options, int flags, goto failed_shutdown; } =20 + if (mon_host) { + r =3D rados_conf_set(s->cluster, "mon_host", mon_host); + if (r < 0) { + goto failed_shutdown; + } + } + + if (auth_supported) { + r =3D rados_conf_set(s->cluster, "auth_supported", auth_supported); + if (r < 0) { + goto failed_shutdown; + } + } + if (qemu_rbd_set_auth(s->cluster, secretid, errp) < 0) { r =3D -EIO; goto failed_shutdown; @@ -663,6 +795,8 @@ failed_shutdown: g_free(s->snap); failed_opts: qemu_opts_del(opts); + g_free(mon_host); + g_free(auth_supported); return r; } =20 diff --git a/qapi/block-core.json b/qapi/block-core.json index 803edc3..2e01a95 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2666,6 +2666,28 @@ '*header-digest': 'IscsiHeaderDigest', '*timeout': 'int' } } =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' } } + ## # @BlockdevOptionsRbd: # @@ -2681,6 +2703,11 @@ # # @user: #optional Ceph id name. # +# @server: #optional Monitor host address and port. This maps +# to the "mon_host" Ceph option. +# +# @auth-supported: #optional Authentication supported. +# # @password-secret: #optional The ID of a QCryptoSecret object providing # the password for the login. # @@ -2692,6 +2719,8 @@ '*conf': 'str', '*snapshot': 'str', '*user': 'str', + '*server': ['InetSocketAddress'], + '*auth-supported': ['RbdAuthMethod'], '*password-secret': 'str' } } =20 ## --=20 2.9.3