thebeanogamer / rpms / qemu-kvm

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