* [PATCH] block/rbd: report a better error when namespace does not exist
@ 2022-05-16 10:03 Stefano Garzarella
2022-05-16 18:26 ` Ilya Dryomov
0 siblings, 1 reply; 3+ messages in thread
From: Stefano Garzarella @ 2022-05-16 10:03 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Lieven, Ilya Dryomov, Tingting Mao, Hanna Reitz, Kevin Wolf,
qemu-block, Stefano Garzarella
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>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
meson.build | 6 ++++++
block/rbd.c | 24 ++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/meson.build b/meson.build
index 9b20dcd143..e6c0afd62b 100644
--- a/meson.build
+++ b/meson.build
@@ -1828,6 +1828,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',
diff --git a/block/rbd.c b/block/rbd.c
index 6caf35cbba..0ff23c5b26 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:
--
2.35.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block/rbd: report a better error when namespace does not exist
2022-05-16 10:03 [PATCH] block/rbd: report a better error when namespace does not exist Stefano Garzarella
@ 2022-05-16 18:26 ` Ilya Dryomov
2022-05-17 6:59 ` Stefano Garzarella
0 siblings, 1 reply; 3+ messages in thread
From: Ilya Dryomov @ 2022-05-16 18:26 UTC (permalink / raw)
To: Stefano Garzarella
Cc: qemu-devel, Peter Lieven, Tingting Mao, Hanna Reitz, Kevin Wolf,
qemu block
On Mon, May 16, 2022 at 12:03 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
>
> 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>
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
> meson.build | 6 ++++++
> block/rbd.c | 24 ++++++++++++++++++++++++
> 2 files changed, 30 insertions(+)
>
> diff --git a/meson.build b/meson.build
> index 9b20dcd143..e6c0afd62b 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1828,6 +1828,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',
> diff --git a/block/rbd.c b/block/rbd.c
> index 6caf35cbba..0ff23c5b26 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) {
Nit: r < 0 for consistency (librbd errors are always negative).
> + 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:
> --
> 2.35.3
>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Thanks,
Ilya
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block/rbd: report a better error when namespace does not exist
2022-05-16 18:26 ` Ilya Dryomov
@ 2022-05-17 6:59 ` Stefano Garzarella
0 siblings, 0 replies; 3+ messages in thread
From: Stefano Garzarella @ 2022-05-17 6:59 UTC (permalink / raw)
To: Ilya Dryomov
Cc: qemu-devel, Peter Lieven, Tingting Mao, Hanna Reitz, Kevin Wolf,
qemu block
On Mon, May 16, 2022 at 08:26:53PM +0200, Ilya Dryomov wrote:
>On Mon, May 16, 2022 at 12:03 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
>>
>> 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>
>> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>> ---
>> meson.build | 6 ++++++
>> block/rbd.c | 24 ++++++++++++++++++++++++
>> 2 files changed, 30 insertions(+)
>>
>> diff --git a/meson.build b/meson.build
>> index 9b20dcd143..e6c0afd62b 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -1828,6 +1828,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',
>> diff --git a/block/rbd.c b/block/rbd.c
>> index 6caf35cbba..0ff23c5b26 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) {
>
>Nit: r < 0 for consistency (librbd errors are always negative).
Yep, also error_setg_errno(errp, -r, ...) makes sense only if r is
negative.
>
>> + 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:
>> --
>> 2.35.3
>>
>
>Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Thanks, I'll send a v2 with the fix and your R-b tag.
Stefano
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-05-17 7:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-16 10:03 [PATCH] block/rbd: report a better error when namespace does not exist Stefano Garzarella
2022-05-16 18:26 ` Ilya Dryomov
2022-05-17 6:59 ` Stefano Garzarella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).