1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Peter Lieven <pl@kamp.de>
3 Date: Thu, 13 Jan 2022 15:44:26 +0100
4 Subject: [PATCH] block/rbd: workaround for ceph issue #53784
6 librbd had a bug until early 2022 that affected all versions of ceph that
7 supported fast-diff. This bug results in reporting of incorrect offsets
8 if the offset parameter to rbd_diff_iterate2 is not object aligned.
10 This patch works around this bug for pre Quincy versions of librbd.
12 Fixes: 0347a8fd4c3faaedf119be04c197804be40a384b
13 Cc: qemu-stable@nongnu.org
14 Signed-off-by: Peter Lieven <pl@kamp.de>
15 Message-Id: <20220113144426.4036493-3-pl@kamp.de>
16 Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
17 Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
18 Tested-by: Stefano Garzarella <sgarzare@redhat.com>
19 Signed-off-by: Kevin Wolf <kwolf@redhat.com>
21 block/rbd.c | 42 ++++++++++++++++++++++++++++++++++++++++--
22 1 file changed, 40 insertions(+), 2 deletions(-)
24 diff --git a/block/rbd.c b/block/rbd.c
25 index 20bb896c4a..8f183eba2a 100644
28 @@ -1320,6 +1320,7 @@ static int coroutine_fn qemu_rbd_co_block_status(BlockDriverState *bs,
30 RBDDiffIterateReq req = { .offs = offset };
31 uint64_t features, flags;
34 assert(offset + bytes <= s->image_size);
36 @@ -1347,7 +1348,43 @@ static int coroutine_fn qemu_rbd_co_block_status(BlockDriverState *bs,
40 - r = rbd_diff_iterate2(s->image, NULL, offset, bytes, true, true,
41 +#if LIBRBD_VERSION_CODE < LIBRBD_VERSION(1, 17, 0)
43 + * librbd had a bug until early 2022 that affected all versions of ceph that
44 + * supported fast-diff. This bug results in reporting of incorrect offsets
45 + * if the offset parameter to rbd_diff_iterate2 is not object aligned.
46 + * Work around this bug by rounding down the offset to object boundaries.
47 + * This is OK because we call rbd_diff_iterate2 with whole_object = true.
48 + * However, this workaround only works for non cloned images with default
51 + * See: https://tracker.ceph.com/issues/53784
54 + /* check if RBD image has non-default striping enabled */
55 + if (features & RBD_FEATURE_STRIPINGV2) {
59 +#pragma GCC diagnostic push
60 +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
62 + * check if RBD image is a clone (= has a parent).
64 + * rbd_get_parent_info is deprecated from Nautilus onwards, but the
65 + * replacement rbd_get_parent is not present in Luminous and Mimic.
67 + if (rbd_get_parent_info(s->image, NULL, 0, NULL, 0, NULL, 0) != -ENOENT) {
70 +#pragma GCC diagnostic pop
72 + head = req.offs & (s->object_size - 1);
77 + r = rbd_diff_iterate2(s->image, NULL, req.offs, bytes, true, true,
78 qemu_rbd_diff_iterate_cb, &req);
79 if (r < 0 && r != QEMU_RBD_EXIT_DIFF_ITERATE2) {
81 @@ -1366,7 +1403,8 @@ static int coroutine_fn qemu_rbd_co_block_status(BlockDriverState *bs,
82 status = BDRV_BLOCK_ZERO | BDRV_BLOCK_OFFSET_VALID;
86 + assert(req.bytes > head);
87 + *pnum = req.bytes - head;