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

Michal Privoznik mprivozn at redhat.com
Mon Apr 29 14:39:40 UTC 2019


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 at 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 at 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




More information about the libvir-list mailing list