1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
3 Date: Thu, 11 Apr 2024 11:29:24 +0200
4 Subject: [PATCH] block/copy-before-write: create block_copy bitmap in filter
7 Currently block_copy creates copy_bitmap in source node. But that is in
8 bad relation with .independent_close=true of copy-before-write filter:
9 source node may be detached and removed before .bdrv_close() handler
10 called, which should call block_copy_state_free(), which in turn should
13 That's all not ideal: it would be better if internal bitmap of
14 block-copy object is not attached to any node. But that is not possible
17 The simplest solution is just create copy_bitmap in filter node, where
18 anyway two other bitmaps are created.
20 Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
21 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
22 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
24 block/block-copy.c | 3 +-
25 block/copy-before-write.c | 2 +-
26 include/block/block-copy.h | 1 +
27 tests/qemu-iotests/257.out | 112 ++++++++++++++++++-------------------
28 4 files changed, 60 insertions(+), 58 deletions(-)
30 diff --git a/block/block-copy.c b/block/block-copy.c
31 index e13d7bc6b6..b61685f1a2 100644
32 --- a/block/block-copy.c
33 +++ b/block/block-copy.c
34 @@ -346,6 +346,7 @@ static int64_t block_copy_calculate_cluster_size(BlockDriverState *target,
37 BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
38 + BlockDriverState *copy_bitmap_bs,
39 const BdrvDirtyBitmap *bitmap,
42 @@ -360,7 +361,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
46 - copy_bitmap = bdrv_create_dirty_bitmap(source->bs, cluster_size, NULL,
47 + copy_bitmap = bdrv_create_dirty_bitmap(copy_bitmap_bs, cluster_size, NULL,
51 diff --git a/block/copy-before-write.c b/block/copy-before-write.c
52 index 0a219c2b75..d3b95bd600 100644
53 --- a/block/copy-before-write.c
54 +++ b/block/copy-before-write.c
55 @@ -470,7 +470,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,
56 ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) &
57 bs->file->bs->supported_zero_flags);
59 - s->bcs = block_copy_state_new(bs->file, s->target, bitmap, errp);
60 + s->bcs = block_copy_state_new(bs->file, s->target, bs, bitmap, errp);
62 error_prepend(errp, "Cannot create block-copy-state: ");
64 diff --git a/include/block/block-copy.h b/include/block/block-copy.h
65 index 0700953ab8..8b41643bfa 100644
66 --- a/include/block/block-copy.h
67 +++ b/include/block/block-copy.h
68 @@ -25,6 +25,7 @@ typedef struct BlockCopyState BlockCopyState;
69 typedef struct BlockCopyCallState BlockCopyCallState;
71 BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
72 + BlockDriverState *copy_bitmap_bs,
73 const BdrvDirtyBitmap *bitmap,
76 diff --git a/tests/qemu-iotests/257.out b/tests/qemu-iotests/257.out
77 index aa76131ca9..c33dd7f3a9 100644
78 --- a/tests/qemu-iotests/257.out
79 +++ b/tests/qemu-iotests/257.out
80 @@ -120,16 +120,16 @@ write -P0x67 0x3fe0000 0x20000
101 @@ -596,16 +596,16 @@ write -P0x67 0x3fe0000 0x20000
102 "granularity": 65536,
112 "granularity": 65536,
122 @@ -865,16 +865,16 @@ write -P0x67 0x3fe0000 0x20000
123 "granularity": 65536,
133 "granularity": 65536,
143 @@ -1341,16 +1341,16 @@ write -P0x67 0x3fe0000 0x20000
144 "granularity": 65536,
154 "granularity": 65536,
164 @@ -1610,16 +1610,16 @@ write -P0x67 0x3fe0000 0x20000
165 "granularity": 65536,
175 "granularity": 65536,
185 @@ -2086,16 +2086,16 @@ write -P0x67 0x3fe0000 0x20000
186 "granularity": 65536,
196 "granularity": 65536,
206 @@ -2355,16 +2355,16 @@ write -P0x67 0x3fe0000 0x20000
207 "granularity": 65536,
217 "granularity": 65536,
227 @@ -2831,16 +2831,16 @@ write -P0x67 0x3fe0000 0x20000
228 "granularity": 65536,
238 "granularity": 65536,
248 @@ -3100,16 +3100,16 @@ write -P0x67 0x3fe0000 0x20000
249 "granularity": 65536,
259 "granularity": 65536,
269 @@ -3576,16 +3576,16 @@ write -P0x67 0x3fe0000 0x20000
270 "granularity": 65536,
280 "granularity": 65536,
290 @@ -3845,16 +3845,16 @@ write -P0x67 0x3fe0000 0x20000
291 "granularity": 65536,
301 "granularity": 65536,
311 @@ -4321,16 +4321,16 @@ write -P0x67 0x3fe0000 0x20000
312 "granularity": 65536,
322 "granularity": 65536,
332 @@ -4590,16 +4590,16 @@ write -P0x67 0x3fe0000 0x20000
333 "granularity": 65536,
343 "granularity": 65536,
353 @@ -5066,16 +5066,16 @@ write -P0x67 0x3fe0000 0x20000
354 "granularity": 65536,
364 "granularity": 65536,