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