From patchwork Thu Mar 2 03:46:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9599509 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6DAD660453 for ; Thu, 2 Mar 2017 03:49:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E272267EC for ; Thu, 2 Mar 2017 03:49:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5279528402; Thu, 2 Mar 2017 03:49:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B46F5267EC for ; Thu, 2 Mar 2017 03:49:42 +0000 (UTC) Received: from localhost ([::1]:50196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjHkL-0005qt-Pi for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Mar 2017 22:49:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjHhC-0003k6-Ml for qemu-devel@nongnu.org; Wed, 01 Mar 2017 22:46:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjHhB-0004GG-Fc for qemu-devel@nongnu.org; Wed, 01 Mar 2017 22:46:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cjHh8-0004DK-BW; Wed, 01 Mar 2017 22:46:22 -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 753A713AA1; Thu, 2 Mar 2017 03:46:22 +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 v223kLXJ015766 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 1 Mar 2017 22:46:22 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 1 Mar 2017 22:46:13 -0500 Message-Id: <20170302034613.21609-6-jcody@redhat.com> In-Reply-To: <20170302034613.21609-1-jcody@redhat.com> References: <20170302034613.21609-1-jcody@redhat.com> 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.29]); Thu, 02 Mar 2017 03:46:22 +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 v3 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 29 +++++++++++ 2 files changed, 164 insertions(+) diff --git a/block/rbd.c b/block/rbd.c index cc43f42..ee13f3d 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -405,6 +405,19 @@ static QemuOptsList runtime_opts = { .type = QEMU_OPT_STRING, .help = "Legacy rados key/value option parameters", }, + { + .name = "host", + .type = QEMU_OPT_STRING, + }, + { + .name = "port", + .type = QEMU_OPT_STRING, + }, + { + .name = "auth", + .type = QEMU_OPT_STRING, + .help = "Supported authentication method, either cephx or none", + }, { /* end of list */ } }, }; @@ -565,6 +578,94 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb) qemu_aio_unref(acb); } +#define RBD_MON_HOST 0 +#define RBD_AUTH_SUPPORTED 1 + +static char *qemu_rbd_array_opts(QDict *options, const char *prefix, int type, + Error **errp) +{ + int num_entries; + QemuOpts *opts = NULL; + QDict *sub_options; + const char *host; + const char *port; + char *str; + char *rados_str = NULL; + Error *local_err = NULL; + int i; + + assert(type == RBD_MON_HOST || type == RBD_AUTH_SUPPORTED); + + num_entries = qdict_array_entries(options, prefix); + + if (num_entries < 0) { + error_setg(errp, "Parse error on RBD QDict array"); + return NULL; + } + + for (i = 0; i < num_entries; i++) { + char *strbuf = NULL; + const char *value; + char *rados_str_tmp; + + str = g_strdup_printf("%s%d.", prefix, i); + qdict_extract_subqdict(options, &sub_options, str); + g_free(str); + + opts = 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 = NULL; + goto exit; + } + + if (type == RBD_MON_HOST) { + host = qemu_opt_get(opts, "host"); + port = qemu_opt_get(opts, "port"); + + value = host; + if (port) { + /* check for ipv6 */ + if (strchr(host, ':')) { + strbuf = g_strdup_printf("[%s]:%s", host, port); + } else { + strbuf = g_strdup_printf("%s:%s", host, port); + } + value = strbuf; + } else if (strchr(host, ':')) { + strbuf = g_strdup_printf("[%s]", host); + value = strbuf; + } + } else { + value = 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 = rados_str; + rados_str = g_strdup_printf("%s;%s", rados_str_tmp, value); + g_free(rados_str_tmp); + } else { + rados_str = g_strdup(value); + } + + g_free(strbuf); + qemu_opts_del(opts); + opts = NULL; + } + +exit: + qemu_opts_del(opts); + return rados_str; +} + static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { @@ -573,6 +674,8 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, const char *secretid; QemuOpts *opts; Error *local_err = NULL; + char *mon_host = NULL; + char *auth_supported = NULL; int r; opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); @@ -583,6 +686,22 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, return -EINVAL; } + auth_supported = qemu_rbd_array_opts(options, "auth-supported.", + RBD_AUTH_SUPPORTED, &local_err); + if (local_err) { + error_propagate(errp, local_err); + r = -EINVAL; + goto failed_opts; + } + + mon_host = qemu_rbd_array_opts(options, "server.", + RBD_MON_HOST, &local_err); + if (local_err) { + error_propagate(errp, local_err); + r = -EINVAL; + goto failed_opts; + } + secretid = qemu_opt_get(opts, "password-secret"); pool = qemu_opt_get(opts, "pool"); @@ -615,6 +734,20 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, goto failed_shutdown; } + if (mon_host) { + r = rados_conf_set(s->cluster, "mon_host", mon_host); + if (r < 0) { + goto failed_shutdown; + } + } + + if (auth_supported) { + r = 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 = -EIO; goto failed_shutdown; @@ -663,6 +796,8 @@ failed_shutdown: g_free(s->snap); failed_opts: qemu_opts_del(opts); + g_free(mon_host); + g_free(auth_supported); return r; } 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' } } + +## +# @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' } } ##