qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: Peter Lieven <pl@kamp.de>, Ilya Dryomov <idryomov@gmail.com>,
	Hanna Reitz <hreitz@redhat.com>, Tingting Mao <timao@redhat.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH v2] block/rbd: report a better error when namespace does not exist
Date: Mon, 30 May 2022 10:32:00 +0200	[thread overview]
Message-ID: <20220530083200.a76fctmgr2serfcn@sgarzare-redhat> (raw)
In-Reply-To: <20220517071012.6120-1-sgarzare@redhat.com>

Gentle ping :-)

@Kevin, can this patch go with your tree?
Ilya already reviewed it.

Thanks,
Stefano

On Tue, May 17, 2022 at 09:10:12AM +0200, Stefano Garzarella 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>
>Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
>Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>---
>v2:
>- check r < 0 for consistency (librbd errors are always negative) [Ilya]
>---
> 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..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:
>-- 
>2.35.3
>



  reply	other threads:[~2022-05-30  8:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-17  7:10 [PATCH v2] block/rbd: report a better error when namespace does not exist Stefano Garzarella
2022-05-30  8:32 ` Stefano Garzarella [this message]
2022-05-30 11:21 ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220530083200.a76fctmgr2serfcn@sgarzare-redhat \
    --to=sgarzare@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=idryomov@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=timao@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).