[libvirt] [PATCH v2 for 5.3.0] storage_backend_rbd: Ignore rbd_diff_iterate error() if needed

Michal Privoznik posted 1 patch 4 years, 11 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/4a9a9154e7f07322731ef62254aa3b811fce42d9.1556548704.git.mprivozn@redhat.com
src/storage/storage_backend_rbd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[libvirt] [PATCH v2 for 5.3.0] storage_backend_rbd: Ignore rbd_diff_iterate error() if needed
Posted by Michal Privoznik 4 years, 11 months ago
When cloning an RBD volume we try to find a snapshot which is
not different to the image we're trying to clone. This boils down
to calling rbd_diff_iterate() or rbd_diff_iterate2() on systems
with newer ceph. These two are passed a callback -
virStorageBackendRBDIterateCb() which sets @diff to 1 and returns
-1. The idea is to stop iterating as soon as possible (i.e. we're
iterating over a snapshot with some deltas). Unfortunately,
returning a negative value from the callback means that iterate()
function fails and thus we report an error:

  virsh # vol-clone --pool rbd_image_root coreos_2023 coreos00.disk
  error: Failed to clone vol from coreos_2023
  error: failed to iterate RBD snapshot coreos_2023@base: Operation not
  permitted

Therefore, report an error if and only if it doesn't originates
in the callback.

Reported on libvirt-users list:

https://www.redhat.com/archives/libvirt-users/2019-April/msg00060.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---

diff to v1:
- Ignore error as suggested by Jason as it allows us to exit iteration
early.

 src/storage/storage_backend_rbd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index f8c968e682..69f4fa2117 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -1101,7 +1101,9 @@ virStorageBackendRBDSnapshotFindNoDiff(rbd_image_t image,
                              virStorageBackendRBDIterateCb, (void *)&diff);
 #endif
 
-        if (r < 0) {
+        /* We care for errors only if the callback wasn't called at all. If it
+         * was, rbd_diff_iterate() returns an error which we have to ignore. */
+        if (r < 0 && diff == 0) {
             virReportSystemError(-r, _("failed to iterate RBD snapshot %s@%s"),
                                  imgname, snaps[i].name);
             goto cleanup;
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 for 5.3.0] storage_backend_rbd: Ignore rbd_diff_iterate error() if needed
Posted by Ján Tomko 4 years, 11 months ago
On Mon, Apr 29, 2019 at 04:39:40PM +0200, Michal Privoznik wrote:
>When cloning an RBD volume we try to find a snapshot which is
>not different to the image we're trying to clone. This boils down
>to calling rbd_diff_iterate() or rbd_diff_iterate2() on systems
>with newer ceph. These two are passed a callback -
>virStorageBackendRBDIterateCb() which sets @diff to 1 and returns
>-1. The idea is to stop iterating as soon as possible (i.e. we're
>iterating over a snapshot with some deltas). Unfortunately,
>returning a negative value from the callback means that iterate()
>function fails and thus we report an error:
>
>  virsh # vol-clone --pool rbd_image_root coreos_2023 coreos00.disk
>  error: Failed to clone vol from coreos_2023
>  error: failed to iterate RBD snapshot coreos_2023@base: Operation not
>  permitted
>
>Therefore, report an error if and only if it doesn't originates
>in the callback.
>
>Reported on libvirt-users list:
>
>https://www.redhat.com/archives/libvirt-users/2019-April/msg00060.html
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
>
>diff to v1:
>- Ignore error as suggested by Jason as it allows us to exit iteration
>early.
>
> src/storage/storage_backend_rbd.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list