All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Jeff Cody <jcody@redhat.com>
Cc: qemu-devel@nongnu.org, stefanha@redhat.com, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v4 5/5] block/rbd: add support for 'mon_host', 'auth_supported' via QAPI
Date: Tue, 28 Feb 2017 17:07:09 +0100	[thread overview]
Message-ID: <8737eypadu.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <7f62442524e9b3e5c129d1d10fe01c41a0e0d4ff.1488296634.git.jcody@redhat.com> (Jeff Cody's message of "Tue, 28 Feb 2017 10:51:07 -0500")

Jeff Cody <jcody@redhat.com> writes:

> 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.
>
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
>  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 = {
>              .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,93 @@ 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;
> +
> +    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");

This error message isn't nice, but we can fix that on top.

> +        return NULL;
> +    }
> +
> +    for (int 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);
> +                }

Good enough.

> +                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 +673,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 +685,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 +733,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 +795,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' } }
>  
>  ##

Reviewed-by: Markus Armbruster <armbru@redhat.com>

  reply	other threads:[~2017-02-28 16:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28 15:51 [Qemu-devel] [PATCH v4 0/5] RBD: blockdev-add (for 2.9?) Jeff Cody
2017-02-28 15:51 ` [Qemu-devel] [PATCH v4 1/5] block/rbd: don't copy strings in qemu_rbd_next_tok() Jeff Cody
2017-02-28 15:51 ` [Qemu-devel] [PATCH v4 2/5] block/rbd: add all the currently supported runtime_opts Jeff Cody
2017-02-28 15:51 ` [Qemu-devel] [PATCH v4 3/5] block/rbd: parse all options via bdrv_parse_filename Jeff Cody
2017-02-28 15:51 ` [Qemu-devel] [PATCH v4 4/5] block/rbd: add blockdev-add support Jeff Cody
2017-02-28 15:51 ` [Qemu-devel] [PATCH v4 5/5] block/rbd: add support for 'mon_host', 'auth_supported' via QAPI Jeff Cody
2017-02-28 16:07   ` Markus Armbruster [this message]
2017-02-28 16:13 ` [Qemu-devel] [PATCH v4 0/5] RBD: blockdev-add (for 2.9?) Jeff Cody

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8737eypadu.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=jcody@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.