From patchwork Tue Aug 23 16:28:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sage Weil X-Patchwork-Id: 111145 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8BDEAB70B1 for ; Wed, 24 Aug 2011 02:34:23 +1000 (EST) Received: from localhost ([::1]:33731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvtve-00033U-1e for incoming@patchwork.ozlabs.org; Tue, 23 Aug 2011 12:34:18 -0400 Received: from eggs.gnu.org ([140.186.70.92]:37524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QvtvV-000336-Ke for qemu-devel@nongnu.org; Tue, 23 Aug 2011 12:34:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QvtvT-0000r7-Co for qemu-devel@nongnu.org; Tue, 23 Aug 2011 12:34:09 -0400 Received: from cobra.newdream.net ([66.33.216.30]:55932) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QvtvR-0000qo-63 for qemu-devel@nongnu.org; Tue, 23 Aug 2011 12:34:07 -0400 Received: from localhost.localdomain (aon.hq.newdream.net [64.111.111.107]) by cobra.newdream.net (Postfix) with ESMTPA id 8DE75BC7A1; Tue, 23 Aug 2011 09:39:03 -0700 (PDT) From: Sage Weil To: qemu-devel@nongnu.org Date: Tue, 23 Aug 2011 09:28:31 -0700 Message-Id: <1314116912-28685-2-git-send-email-sage@newdream.net> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1314116912-28685-1-git-send-email-sage@newdream.net> References: <1314116912-28685-1-git-send-email-sage@newdream.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 66.33.216.30 Cc: Sage Weil Subject: [Qemu-devel] [PATCH 2/3] rbd: allow client id to be specified in config string X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 52b79fa..e239e04 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), @@ -394,7 +429,8 @@ static int qemu_rbd_open(BlockDriverState *bs, const char *filename, int flags) return -EINVAL; } - 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;