2bc292
From f035b5250529eed8d12e0b93b1b6d6f2c50003f6 Mon Sep 17 00:00:00 2001
2bc292
From: Peter Lieven <pl@kamp.de>
2bc292
Date: Thu, 13 Jan 2022 15:44:26 +0100
2bc292
Subject: [PATCH 5/5] block/rbd: workaround for ceph issue #53784
2bc292
2bc292
RH-Author: Stefano Garzarella <sgarzare@redhat.com>
2bc292
RH-MergeRequest: 68: block/rbd: fix handling of holes in .bdrv_co_block_status
2bc292
RH-Commit: [2/2] 5feaa2e20a77886cc1a84cdf212ade3dcda28289 (sgarzarella/qemu-kvm-c-9-s)
2bc292
RH-Bugzilla: 2034791
2bc292
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
2bc292
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
2bc292
RH-Acked-by: Hanna Reitz <hreitz@redhat.com>
2bc292
2bc292
librbd had a bug until early 2022 that affected all versions of ceph that
2bc292
supported fast-diff. This bug results in reporting of incorrect offsets
2bc292
if the offset parameter to rbd_diff_iterate2 is not object aligned.
2bc292
2bc292
This patch works around this bug for pre Quincy versions of librbd.
2bc292
2bc292
Fixes: 0347a8fd4c3faaedf119be04c197804be40a384b
2bc292
Cc: qemu-stable@nongnu.org
2bc292
Signed-off-by: Peter Lieven <pl@kamp.de>
2bc292
Message-Id: <20220113144426.4036493-3-pl@kamp.de>
2bc292
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
2bc292
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
2bc292
Tested-by: Stefano Garzarella <sgarzare@redhat.com>
2bc292
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2bc292
(cherry picked from commit fc176116cdea816ceb8dd969080b2b95f58edbc0)
2bc292
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2bc292
---
2bc292
 block/rbd.c | 42 ++++++++++++++++++++++++++++++++++++++++--
2bc292
 1 file changed, 40 insertions(+), 2 deletions(-)
2bc292
2bc292
diff --git a/block/rbd.c b/block/rbd.c
2bc292
index 20bb896c4a..8f183eba2a 100644
2bc292
--- a/block/rbd.c
2bc292
+++ b/block/rbd.c
2bc292
@@ -1320,6 +1320,7 @@ static int coroutine_fn qemu_rbd_co_block_status(BlockDriverState *bs,
2bc292
     int status, r;
2bc292
     RBDDiffIterateReq req = { .offs = offset };
2bc292
     uint64_t features, flags;
2bc292
+    uint64_t head = 0;
2bc292
 
2bc292
     assert(offset + bytes <= s->image_size);
2bc292
 
2bc292
@@ -1347,7 +1348,43 @@ static int coroutine_fn qemu_rbd_co_block_status(BlockDriverState *bs,
2bc292
         return status;
2bc292
     }
2bc292
 
2bc292
-    r = rbd_diff_iterate2(s->image, NULL, offset, bytes, true, true,
2bc292
+#if LIBRBD_VERSION_CODE < LIBRBD_VERSION(1, 17, 0)
2bc292
+    /*
2bc292
+     * librbd had a bug until early 2022 that affected all versions of ceph that
2bc292
+     * supported fast-diff. This bug results in reporting of incorrect offsets
2bc292
+     * if the offset parameter to rbd_diff_iterate2 is not object aligned.
2bc292
+     * Work around this bug by rounding down the offset to object boundaries.
2bc292
+     * This is OK because we call rbd_diff_iterate2 with whole_object = true.
2bc292
+     * However, this workaround only works for non cloned images with default
2bc292
+     * striping.
2bc292
+     *
2bc292
+     * See: https://tracker.ceph.com/issues/53784
2bc292
+     */
2bc292
+
2bc292
+    /* check if RBD image has non-default striping enabled */
2bc292
+    if (features & RBD_FEATURE_STRIPINGV2) {
2bc292
+        return status;
2bc292
+    }
2bc292
+
2bc292
+#pragma GCC diagnostic push
2bc292
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2bc292
+    /*
2bc292
+     * check if RBD image is a clone (= has a parent).
2bc292
+     *
2bc292
+     * rbd_get_parent_info is deprecated from Nautilus onwards, but the
2bc292
+     * replacement rbd_get_parent is not present in Luminous and Mimic.
2bc292
+     */
2bc292
+    if (rbd_get_parent_info(s->image, NULL, 0, NULL, 0, NULL, 0) != -ENOENT) {
2bc292
+        return status;
2bc292
+    }
2bc292
+#pragma GCC diagnostic pop
2bc292
+
2bc292
+    head = req.offs & (s->object_size - 1);
2bc292
+    req.offs -= head;
2bc292
+    bytes += head;
2bc292
+#endif
2bc292
+
2bc292
+    r = rbd_diff_iterate2(s->image, NULL, req.offs, bytes, true, true,
2bc292
                           qemu_rbd_diff_iterate_cb, &req;;
2bc292
     if (r < 0 && r != QEMU_RBD_EXIT_DIFF_ITERATE2) {
2bc292
         return status;
2bc292
@@ -1366,7 +1403,8 @@ static int coroutine_fn qemu_rbd_co_block_status(BlockDriverState *bs,
2bc292
         status = BDRV_BLOCK_ZERO | BDRV_BLOCK_OFFSET_VALID;
2bc292
     }
2bc292
 
2bc292
-    *pnum = req.bytes;
2bc292
+    assert(req.bytes > head);
2bc292
+    *pnum = req.bytes - head;
2bc292
     return status;
2bc292
 }
2bc292
 
2bc292
-- 
2bc292
2.27.0
2bc292