* [Qemu-devel] [PATCH] rbd: allow client id to be specified in config string
@ 2011-08-22 21:38 Sage Weil
2011-08-22 21:45 ` [Qemu-devel] [PATCH v2] " Sage Weil
0 siblings, 1 reply; 3+ messages in thread
From: Sage Weil @ 2011-08-22 21:38 UTC (permalink / raw)
To: qemu-devel
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 <sage@newdream.net>
Reviewed-by: Yehuda Sadeh <yehuda@newdream.net>
---
block/rbd.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/block/rbd.c b/block/rbd.c
index d5659cd..a888da0 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -169,6 +169,38 @@ done:
return ret;
}
+static int qemu_rbd_parse_clientname(const char *conf, char *clientname,
+ size_t maxlen)
+{
+ 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;
+ if (len >= maxlen) {
+ return -ERANGE;
+ }
+ strncpy(clientname, p + 3, len);
+ clientname[len] = '\0';
+ return 0;
+ }
+ if (end == NULL) {
+ break;
+ }
+ p = end + 1;
+ }
+ return 0;
+}
+
static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
{
char *p, *buf;
@@ -198,17 +230,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 {
- ret = rados_conf_read_file(cluster, value);
+ } else if (strcmp(name, "id") == 0) {
+ /* ignore, this is parsed by qemu_rbd_parse_clientname() */
+ } else {
+ 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 +261,7 @@ 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[RBD_MAX_CONF_SIZE];
rados_t cluster;
rados_ioctx_t io_ctx;
int ret;
@@ -259,7 +294,12 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options)
options++;
}
- if (rados_create(&cluster, NULL) < 0) {
+ ret = qemu_rbd_parse_clientname(conf, clientname, sizeof(clientname));
+ if (ret < 0) {
+ error_report("rbd client name is too long");
+ return ret;
+ }
+ if (rados_create(&cluster, clientname[0] ? clientname : NULL) < 0) {
error_report("error initializing");
return -EIO;
}
@@ -385,6 +425,7 @@ 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[RBD_MAX_CONF_SIZE];
int r;
if (qemu_rbd_parsename(filename, pool, sizeof(pool),
@@ -398,7 +439,12 @@ static int qemu_rbd_open(BlockDriverState *bs, const char *filename, int flags)
s->snap = qemu_strdup(snap_buf);
}
- r = rados_create(&s->cluster, NULL);
+ r = qemu_rbd_parse_clientname(conf, clientname, sizeof(clientname));
+ if (r < 0) {
+ error_report("rbd client name is too long");
+ return r;
+ }
+ r = rados_create(&s->cluster, clientname[0] ? clientname : NULL);
if (r < 0) {
error_report("error initializing");
return r;
--
1.7.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH v2] rbd: allow client id to be specified in config string
2011-08-22 21:38 [Qemu-devel] [PATCH] rbd: allow client id to be specified in config string Sage Weil
@ 2011-08-22 21:45 ` Sage Weil
2011-08-23 7:58 ` Stefan Hajnoczi
0 siblings, 1 reply; 3+ messages in thread
From: Sage Weil @ 2011-08-22 21:45 UTC (permalink / raw)
To: qemu-devel
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 <sage@newdream.net>
---
v2: whoops, fixed default case where id= is not specified.
block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/block/rbd.c b/block/rbd.c
index d5659cd..b0cd750 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 {
- ret = rados_conf_read_file(cluster, value);
+ } else if (strcmp(name, "id") == 0) {
+ /* ignore, this is parsed by qemu_rbd_parse_clientname() */
+ } else {
+ 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 = qemu_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;
--
1.7.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] rbd: allow client id to be specified in config string
2011-08-22 21:45 ` [Qemu-devel] [PATCH v2] " Sage Weil
@ 2011-08-23 7:58 ` Stefan Hajnoczi
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2011-08-23 7:58 UTC (permalink / raw)
To: Sage Weil; +Cc: qemu-devel
On Mon, Aug 22, 2011 at 02:45:48PM -0700, Sage Weil wrote:
> diff --git a/block/rbd.c b/block/rbd.c
> index d5659cd..b0cd750 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;
> +}
Please run scripts/checkpatch.pl to check coding style. You are using
tab characters, QEMU uses 4 spaces for indentation instead of tabs.
> @@ -398,7 +433,8 @@ static int qemu_rbd_open(BlockDriverState *bs, const char *filename, int flags)
> s->snap = qemu_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;
s->snap may be leaked here. If .bdrv_file_open() fails .bdrv_close()
will not be called to clean things up.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-08-23 7:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-22 21:38 [Qemu-devel] [PATCH] rbd: allow client id to be specified in config string Sage Weil
2011-08-22 21:45 ` [Qemu-devel] [PATCH v2] " Sage Weil
2011-08-23 7:58 ` Stefan Hajnoczi
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.