aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-02-16 18:48:25 +0100
committerKevin Wolf <kwolf@redhat.com>2018-03-09 15:17:47 +0100
commitaa045c2d37c831541607c0a81212f9d3f2dacad9 (patch)
treeb6b2d35e54d93c2dede670fd505bd4528e7b2a9f /block
parentd41a55885de18f4fe8dddb8ae88be80497f8eb05 (diff)
rbd: Use qemu_rbd_connect() in qemu_rbd_do_create()
This is almost exactly the same code. The differences are that qemu_rbd_connect() supports BlockdevOptionsRbd.server and that the cache mode is set explicitly. Supporting 'server' is a welcome new feature for image creation. Caching is disabled by default, so leave it that way. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/rbd.c54
1 files changed, 10 insertions, 44 deletions
diff --git a/block/rbd.c b/block/rbd.c
index 2ac7ffca42..294ed07ac4 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -103,6 +103,11 @@ typedef struct BDRVRBDState {
char *snap;
} BDRVRBDState;
+static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,
+ BlockdevOptionsRbd *opts, bool cache,
+ const char *keypairs, const char *secretid,
+ Error **errp);
+
static char *qemu_rbd_next_tok(char *src, char delim, char **p)
{
char *end;
@@ -351,12 +356,6 @@ static int qemu_rbd_do_create(BlockdevCreateOptions *options,
return -EINVAL;
}
- /* TODO Remove the limitation */
- if (opts->location->has_server) {
- error_setg(errp, "Can't specify server for image creation");
- return -EINVAL;
- }
-
if (opts->has_cluster_size) {
int64_t objsize = opts->cluster_size;
if ((objsize - 1) & objsize) { /* not a power of 2? */
@@ -370,54 +369,21 @@ static int qemu_rbd_do_create(BlockdevCreateOptions *options,
obj_order = ctz32(objsize);
}
- ret = rados_create(&cluster, opts->location->user);
+ ret = qemu_rbd_connect(&cluster, &io_ctx, opts->location, false, keypairs,
+ password_secret, errp);
if (ret < 0) {
- error_setg_errno(errp, -ret, "error initializing");
return ret;
}
- /* try default location when conf=NULL, but ignore failure */
- ret = rados_conf_read_file(cluster, opts->location->conf);
- if (opts->location->conf && ret < 0) {
- error_setg_errno(errp, -ret, "error reading conf file %s",
- opts->location->conf);
- ret = -EIO;
- goto shutdown;
- }
-
- ret = qemu_rbd_set_keypairs(cluster, keypairs, errp);
- if (ret < 0) {
- ret = -EIO;
- goto shutdown;
- }
-
- if (qemu_rbd_set_auth(cluster, password_secret, errp) < 0) {
- ret = -EIO;
- goto shutdown;
- }
-
- ret = rados_connect(cluster);
- if (ret < 0) {
- error_setg_errno(errp, -ret, "error connecting");
- goto shutdown;
- }
-
- ret = rados_ioctx_create(cluster, opts->location->pool, &io_ctx);
- if (ret < 0) {
- error_setg_errno(errp, -ret, "error opening pool %s",
- opts->location->pool);
- goto shutdown;
- }
-
ret = rbd_create(io_ctx, opts->location->image, opts->size, &obj_order);
if (ret < 0) {
error_setg_errno(errp, -ret, "error rbd create");
+ goto out;
}
- rados_ioctx_destroy(io_ctx);
-
ret = 0;
-shutdown:
+out:
+ rados_ioctx_destroy(io_ctx);
rados_shutdown(cluster);
return ret;
}