From patchwork Wed Sep 7 16:28:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sage Weil X-Patchwork-Id: 1127922 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p87Gtvwh025873 for ; Wed, 7 Sep 2011 16:55:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753564Ab1IGQz6 (ORCPT ); Wed, 7 Sep 2011 12:55:58 -0400 Received: from cobra.newdream.net ([66.33.216.30]:38880 "EHLO cobra.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753320Ab1IGQz6 (ORCPT ); Wed, 7 Sep 2011 12:55:58 -0400 Received: from vapre.ww.newdream.net (dsl092-035-022.lax1.dsl.speakeasy.net [66.92.35.22]) by cobra.newdream.net (Postfix) with ESMTPA id A28EEBC89C; Wed, 7 Sep 2011 10:01:29 -0700 (PDT) From: Sage Weil To: qemu-devel@nongnu.org, kwolf@redhat.com Cc: ceph-devel@vger.kernel.org, Sage Weil Subject: [PATCH 1/3] rbd: allow client id to be specified in config string Date: Wed, 7 Sep 2011 09:28:04 -0700 Message-Id: <1315412886-21092-1-git-send-email-sage@newdream.net> X-Mailer: git-send-email 1.7.2.5 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 07 Sep 2011 16:55:59 +0000 (UTC) Allow the client id to be specified in the config string via 'id=' so that users can control who they authenticate as. Currently they are stuck with the default ('admin'). This is necessary for anyone using authentication in their environment. Signed-off-by: Sage Weil Reviewed-by: Stefan Hajnoczi --- block/rbd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 44 insertions(+), 8 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index ce0f6ef..6135fc1 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -169,6 +169,34 @@ done: return ret; } +static char *qemu_rbd_parse_clientname(const char *conf, char *clientname) +{ + const char *p = conf; + + while (*p) { + int len; + const char *end = strchr(p, ':'); + + if (end) { + len = end - p; + } else { + len = strlen(p); + } + + if (strncmp(p, "id=", 3) == 0) { + len -= 3; + strncpy(clientname, p + 3, len); + clientname[len] = '\0'; + return clientname; + } + if (end == NULL) { + break; + } + p = end + 1; + } + return NULL; +} + static int qemu_rbd_set_conf(rados_t cluster, const char *conf) { char *p, *buf; @@ -198,17 +226,19 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf) break; } - if (strcmp(name, "conf")) { - ret = rados_conf_set(cluster, name, value); + if (strcmp(name, "conf") == 0) { + ret = rados_conf_read_file(cluster, value); if (ret < 0) { - error_report("invalid conf option %s", name); - ret = -EINVAL; + error_report("error reading conf file %s", value); break; } + } else if (strcmp(name, "id") == 0) { + /* ignore, this is parsed by qemu_rbd_parse_clientname() */ } else { - ret = rados_conf_read_file(cluster, value); + ret = rados_conf_set(cluster, name, value); if (ret < 0) { - error_report("error reading conf file %s", value); + error_report("invalid conf option %s", name); + ret = -EINVAL; break; } } @@ -227,6 +257,8 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options) 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; rados_t cluster; rados_ioctx_t io_ctx; int ret; @@ -259,7 +291,8 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options) options++; } - if (rados_create(&cluster, NULL) < 0) { + clientname = qemu_rbd_parse_clientname(conf, clientname_buf); + if (rados_create(&cluster, clientname) < 0) { error_report("error initializing"); return -EIO; } @@ -385,6 +418,8 @@ static int qemu_rbd_open(BlockDriverState *bs, const char *filename, int flags) 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; int r; if (qemu_rbd_parsename(filename, pool, sizeof(pool), @@ -398,7 +433,8 @@ static int qemu_rbd_open(BlockDriverState *bs, const char *filename, int flags) s->snap = g_strdup(snap_buf); } - r = rados_create(&s->cluster, NULL); + clientname = qemu_rbd_parse_clientname(conf, clientname_buf); + r = rados_create(&s->cluster, clientname); if (r < 0) { error_report("error initializing"); return r;