thebeanogamer / rpms / qemu-kvm

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