[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/18] block/rbd: report a better error when namespace does not ex
From: |
Kevin Wolf |
Subject: |
[PULL 15/18] block/rbd: report a better error when namespace does not exist |
Date: |
Thu, 9 Jun 2022 19:21:46 +0200 |
From: Stefano Garzarella <sgarzare@redhat.com>
If the namespace does not exist, rbd_create() fails with -ENOENT and
QEMU reports a generic "error rbd create: No such file or directory":
$ qemu-img create rbd:rbd/namespace/image 1M
Formatting 'rbd:rbd/namespace/image', fmt=raw size=1048576
qemu-img: rbd:rbd/namespace/image: error rbd create: No such file or
directory
Unfortunately rados_ioctx_set_namespace() does not fail if the namespace
does not exist, so let's use rbd_namespace_exists() in qemu_rbd_connect()
to check if the namespace exists, reporting a more understandable error:
$ qemu-img create rbd:rbd/namespace/image 1M
Formatting 'rbd:rbd/namespace/image', fmt=raw size=1048576
qemu-img: rbd:rbd/namespace/image: namespace 'namespace' does not exist
Reported-by: Tingting Mao <timao@redhat.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20220517071012.6120-1-sgarzare@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/rbd.c | 24 ++++++++++++++++++++++++
meson.build | 6 ++++++
2 files changed, 30 insertions(+)
diff --git a/block/rbd.c b/block/rbd.c
index 6caf35cbba..f826410f40 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -831,6 +831,26 @@ static int qemu_rbd_connect(rados_t *cluster,
rados_ioctx_t *io_ctx,
error_setg_errno(errp, -r, "error opening pool %s", opts->pool);
goto failed_shutdown;
}
+
+#ifdef HAVE_RBD_NAMESPACE_EXISTS
+ if (opts->has_q_namespace && strlen(opts->q_namespace) > 0) {
+ bool exists;
+
+ r = rbd_namespace_exists(*io_ctx, opts->q_namespace, &exists);
+ if (r < 0) {
+ error_setg_errno(errp, -r, "error checking namespace");
+ goto failed_ioctx_destroy;
+ }
+
+ if (!exists) {
+ error_setg(errp, "namespace '%s' does not exist",
+ opts->q_namespace);
+ r = -ENOENT;
+ goto failed_ioctx_destroy;
+ }
+ }
+#endif
+
/*
* Set the namespace after opening the io context on the pool,
* if nspace == NULL or if nspace == "", it is just as we did nothing
@@ -840,6 +860,10 @@ static int qemu_rbd_connect(rados_t *cluster,
rados_ioctx_t *io_ctx,
r = 0;
goto out;
+#ifdef HAVE_RBD_NAMESPACE_EXISTS
+failed_ioctx_destroy:
+ rados_ioctx_destroy(*io_ctx);
+#endif
failed_shutdown:
rados_shutdown(*cluster);
out:
diff --git a/meson.build b/meson.build
index 2bb5bef65d..d76e16f87d 100644
--- a/meson.build
+++ b/meson.build
@@ -1894,6 +1894,12 @@ config_host_data.set('HAVE_GETIFADDRS',
cc.has_function('getifaddrs'))
config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies:
util))
config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul'))
config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix:
'#include <stdlib.h>'))
+if rbd.found()
+ config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS',
+ cc.has_function('rbd_namespace_exists',
+ dependencies: rbd,
+ prefix: '#include <rbd/librbd.h>'))
+endif
if rdma.found()
config_host_data.set('HAVE_IBV_ADVISE_MR',
cc.has_function('ibv_advise_mr',
--
2.35.3
- [PULL 04/18] block: improve block_dirty_bitmap_merge(): don't allocate extra bitmap, (continued)
- [PULL 04/18] block: improve block_dirty_bitmap_merge(): don't allocate extra bitmap, Kevin Wolf, 2022/06/09
- [PULL 12/18] vduse-blk: Add vduse-blk resize support, Kevin Wolf, 2022/06/09
- [PULL 06/18] block: Support passing NULL ops to blk_set_dev_ops(), Kevin Wolf, 2022/06/09
- [PULL 17/18] aio_wait_kick: add missing memory barrier, Kevin Wolf, 2022/06/09
- [PULL 05/18] block: simplify handling of try to merge different sized bitmaps, Kevin Wolf, 2022/06/09
- [PULL 11/18] vduse-blk: Implement vduse-blk export, Kevin Wolf, 2022/06/09
- [PULL 16/18] block/gluster: correctly set max_pdiscard, Kevin Wolf, 2022/06/09
- [PULL 01/18] block: drop unused bdrv_co_drain() API, Kevin Wolf, 2022/06/09
- [PULL 10/18] libvduse: Add VDUSE (vDPA Device in Userspace) library, Kevin Wolf, 2022/06/09
- [PULL 14/18] qsd: document vduse-blk exports, Kevin Wolf, 2022/06/09
- [PULL 15/18] block/rbd: report a better error when namespace does not exist,
Kevin Wolf <=
- [PULL 08/18] block/export: Abstract out the logic of virtio-blk I/O process, Kevin Wolf, 2022/06/09
- [PULL 13/18] libvduse: Add support for reconnecting, Kevin Wolf, 2022/06/09
- [PULL 03/18] block: block_dirty_bitmap_merge(): fix error path, Kevin Wolf, 2022/06/09
- [PULL 07/18] block/export: Fix incorrect length passed to vu_queue_push(), Kevin Wolf, 2022/06/09
- [PULL 18/18] nbd: Drop dead code spotted by Coverity, Kevin Wolf, 2022/06/09
- [PULL 02/18] block: get rid of blk->guest_block_size, Kevin Wolf, 2022/06/09
- Re: [PULL 00/18] Block layer patches, Richard Henderson, 2022/06/09