From nobody Sat May 18 16:46:47 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 1488222064076832.594993769831; Mon, 27 Feb 2017 11:01:04 -0800 (PST) Received: from localhost ([::1]:55814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQXc-0006VI-PA for importer@patchew.org; Mon, 27 Feb 2017 14:01:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQVe-0005BB-I2 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:58:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciQVc-0003Cl-VM for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:58:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49592) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciQVY-000360-H8; Mon, 27 Feb 2017 13:58:52 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 9B6B2369C4; Mon, 27 Feb 2017 18:58:52 +0000 (UTC) Received: from localhost (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RIwpSC022389 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 27 Feb 2017 13:58:52 -0500 From: Jeff Cody To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 13:58:44 -0500 Message-Id: <963f4d61ffcef289b8030bed4be9b9849e2056fe.1488220970.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 27 Feb 2017 18:58:52 +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 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: armbru@redhat.com, qemu-block@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. Signed-off-by: Jeff Cody Reviewed-by: Eric Blake --- 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 Sat May 18 16:46:47 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 1488222061257906.4130353245563; Mon, 27 Feb 2017 11:01:01 -0800 (PST) Received: from localhost ([::1]:55813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQXa-0006Uh-VU for importer@patchew.org; Mon, 27 Feb 2017 14:00:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQVd-0005Al-RK for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:58:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciQVc-0003Cd-SL for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:58:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41880) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciQVZ-000388-RT; Mon, 27 Feb 2017 13:58:54 -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 DE63283F45; Mon, 27 Feb 2017 18:58:53 +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 v1RIwqiV002334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 27 Feb 2017 13:58:53 -0500 From: Jeff Cody To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 13:58:45 -0500 Message-Id: <871655967d4f29e1357abe088df38270e95f5f19.1488220970.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: 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.27]); Mon, 27 Feb 2017 18:58: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 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: armbru@redhat.com, qemu-block@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. Signed-off-by: Jeff Cody Reviewed-by: Eric Blake --- block/rbd.c | 62 ++++++++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 33c21d8..ff5def4 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -357,6 +357,49 @@ 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, + }, + { + .name =3D "pool", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "image", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "snapshot", + .type =3D QEMU_OPT_STRING, + }, + { + /* maps to 'id' in rados_create() */ + .name =3D "user", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "keyvalue-pairs", + .type =3D QEMU_OPT_STRING, + }, + { /* end of list */ } + }, +}; + static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **e= rrp) { Error *local_err =3D NULL; @@ -500,25 +543,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 Sat May 18 16:46:47 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 1488222354801306.25796974894683; Mon, 27 Feb 2017 11:05:54 -0800 (PST) Received: from localhost ([::1]:55858 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQcH-00023P-Ne for importer@patchew.org; Mon, 27 Feb 2017 14:05:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQVi-0005GO-6l for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:59:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciQVg-0003Gq-6O for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:59:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34986) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciQVb-00039y-9E; Mon, 27 Feb 2017 13:58:55 -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 53CD53A768D; Mon, 27 Feb 2017 18:58:55 +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 v1RIwsWZ002348 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 27 Feb 2017 13:58:54 -0500 From: Jeff Cody To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 13:58:46 -0500 Message-Id: In-Reply-To: References: In-Reply-To: References: 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.29]); Mon, 27 Feb 2017 18:58:55 +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 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: armbru@redhat.com, qemu-block@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 empy 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. Signed-off-by: Jeff Cody Reviewed-by: Eric Blake --- block/rbd.c | 298 ++++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 148 insertions(+), 150 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index ff5def4..e04a5e1 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,129 @@ 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 { + 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 +297,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 +306,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 +315,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 +327,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 @@ -406,27 +404,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); @@ -434,35 +421,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; } @@ -493,6 +500,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 @@ -547,15 +558,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); @@ -566,44 +572,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) { @@ -1057,18 +1055,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 Sat May 18 16:46:47 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 1488222359809209.32337934685916; Mon, 27 Feb 2017 11:05:59 -0800 (PST) Received: from localhost ([::1]:55861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQcO-0002Dv-Hm for importer@patchew.org; Mon, 27 Feb 2017 14:05:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQVf-0005DD-Ly for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:59:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciQVe-0003FU-S2 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:58:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42890) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciQVc-0003Bh-F7; Mon, 27 Feb 2017 13:58:56 -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 769BA8046C; Mon, 27 Feb 2017 18:58:56 +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 v1RIwtND002362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 27 Feb 2017 13:58:56 -0500 From: Jeff Cody To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 13:58:47 -0500 Message-Id: <3d09a265f288145ddd8a0159c72ce343d32c30ff.1488220970.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: 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.28]); Mon, 27 Feb 2017 18:58:56 +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 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: armbru@redhat.com, qemu-block@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" Signed-off-by: Jeff Cody Reviewed-by: Eric Blake --- qapi/block-core.json | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 5f82d35..5b311ff 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 ## @@ -2120,7 +2121,7 @@ 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'replication', 'ssh', 'vdi', 'vhdx', 'vmdk', - 'vpc', 'vvfat' ] } + 'vpc', 'vvfat', 'rbd' ] } =20 ## # @BlockdevOptionsFile: @@ -2376,7 +2377,6 @@ 'path': 'str', '*user': 'str' } } =20 - ## # @BlkdebugEvent: # @@ -2666,6 +2666,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 +2891,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 Sat May 18 16:46:47 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 1488222359594260.81682502657793; Mon, 27 Feb 2017 11:05:59 -0800 (PST) Received: from localhost ([::1]:55860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQcM-0002BZ-4e for importer@patchew.org; Mon, 27 Feb 2017 14:05:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36535) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQVh-0005FG-0U for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:59:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciQVg-0003Gi-4f for qemu-devel@nongnu.org; Mon, 27 Feb 2017 13:59:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52958) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciQVd-0003Ct-Mt; Mon, 27 Feb 2017 13:58:57 -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 BD2DC61BA9; Mon, 27 Feb 2017 18:58:57 +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 v1RIwumN019460 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 27 Feb 2017 13:58:57 -0500 From: Jeff Cody To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 13:58:48 -0500 Message-Id: <12a16b28300f871052a49897ec7875a082fc63e3.1488220970.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: 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.39]); Mon, 27 Feb 2017 18:58:57 +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 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: armbru@redhat.com, qemu-block@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 two additional options that may be specified by QAPI in blockdev-add: mon_host: servername and port auth_supported: either 'cephx' or 'none' Signed-off-by: Jeff Cody --- block/rbd.c | 39 +++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 8 ++++++++ 2 files changed, 47 insertions(+) diff --git a/block/rbd.c b/block/rbd.c index e04a5e1..51e971e 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -394,6 +394,18 @@ static QemuOptsList runtime_opts =3D { .name =3D "keyvalue-pairs", .type =3D QEMU_OPT_STRING, }, + { + .name =3D "server.host", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "server.port", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "auth_supported", + .type =3D QEMU_OPT_STRING, + }, { /* end of list */ } }, }; @@ -559,6 +571,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *o= ptions, int flags, { BDRVRBDState *s =3D bs->opaque; const char *pool, *snap, *conf, *clientname, *name, *keypairs; + const char *host, *port, *auth_supported; const char *secretid; QemuOpts *opts; Error *local_err =3D NULL; @@ -580,6 +593,9 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *o= ptions, int flags, clientname =3D qemu_opt_get(opts, "user"); name =3D qemu_opt_get(opts, "image"); keypairs =3D qemu_opt_get(opts, "keyvalue-pairs"); + host =3D qemu_opt_get(opts, "server.host"); + port =3D qemu_opt_get(opts, "server.port"); + auth_supported =3D qemu_opt_get(opts, "auth_supported"); =20 r =3D rados_create(&s->cluster, clientname); if (r < 0) { @@ -604,6 +620,29 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *= options, int flags, goto failed_shutdown; } =20 + /* if mon_host was specified */ + if (host) { + const char *hostname =3D host; + char *mon_host =3D NULL; + + if (port) { + mon_host =3D g_strdup_printf("%s:%s", host, port); + hostname =3D mon_host; + } + r =3D rados_conf_set(s->cluster, "mon_host", hostname); + g_free(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; diff --git a/qapi/block-core.json b/qapi/block-core.json index 5b311ff..376512c 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2680,6 +2680,12 @@ # # @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. +# Either "cephx" or"none". +# # @password-secret: #optional The ID of a QCryptoSecret object providing # the password for the login. # @@ -2691,6 +2697,8 @@ '*conf': 'str', '*snapshot': 'str', '*user': 'str', + '*server': 'InetSocketAddress', + '*auth_supported': 'str', '*password-secret': 'str' } } =20 ## --=20 2.9.3