[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 11/19] block/copy-before-write: support fleecing block driver
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 11/19] block/copy-before-write: support fleecing block driver |
Date: |
Wed, 22 Dec 2021 18:40:10 +0100 |
The last step to make new fleecing scheme work (see block/fleecing.h
for descritption) is to update copy-before-write filter:
If we detect that unfiltered target child is fleecing block driver, we
do:
- initialize shared FleecingState
- activate fleecing block driver with it
- do guest write synchronization with help of
fleecing_mark_done_and_wait_readers() function
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/copy-before-write.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/block/copy-before-write.c b/block/copy-before-write.c
index 4cd90d22df..2e39159a7e 100644
--- a/block/copy-before-write.c
+++ b/block/copy-before-write.c
@@ -33,10 +33,13 @@
#include "block/block-copy.h"
#include "block/copy-before-write.h"
+#include "block/fleecing.h"
typedef struct BDRVCopyBeforeWriteState {
BlockCopyState *bcs;
BdrvChild *target;
+
+ FleecingState *fleecing;
} BDRVCopyBeforeWriteState;
static coroutine_fn int cbw_co_preadv(
@@ -50,6 +53,7 @@ static coroutine_fn int
cbw_do_copy_before_write(BlockDriverState *bs,
uint64_t offset, uint64_t bytes, BdrvRequestFlags flags)
{
BDRVCopyBeforeWriteState *s = bs->opaque;
+ int ret;
uint64_t off, end;
int64_t cluster_size = block_copy_cluster_size(s->bcs);
@@ -60,7 +64,16 @@ static coroutine_fn int
cbw_do_copy_before_write(BlockDriverState *bs,
off = QEMU_ALIGN_DOWN(offset, cluster_size);
end = QEMU_ALIGN_UP(offset + bytes, cluster_size);
- return block_copy(s->bcs, off, end - off, true);
+ ret = block_copy(s->bcs, off, end - off, true);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (s->fleecing) {
+ fleecing_mark_done_and_wait_readers(s->fleecing, off, end - off);
+ }
+
+ return 0;
}
static int coroutine_fn cbw_co_pdiscard(BlockDriverState *bs,
@@ -150,6 +163,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options,
int flags,
{
BDRVCopyBeforeWriteState *s = bs->opaque;
BdrvDirtyBitmap *bitmap = NULL;
+ BlockDriverState *unfiltered_target;
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
@@ -163,6 +177,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options,
int flags,
if (!s->target) {
return -EINVAL;
}
+ unfiltered_target = bdrv_skip_filters(s->target->bs);
if (qdict_haskey(options, "bitmap.node") ||
qdict_haskey(options, "bitmap.name"))
@@ -204,6 +219,14 @@ static int cbw_open(BlockDriverState *bs, QDict *options,
int flags,
return -EINVAL;
}
+ if (is_fleecing_drv(unfiltered_target)) {
+ s->fleecing = fleecing_new(s->bcs, unfiltered_target, errp);
+ if (!s->fleecing) {
+ return -EINVAL;
+ }
+ fleecing_drv_activate(unfiltered_target, s->fleecing);
+ }
+
return 0;
}
@@ -211,6 +234,8 @@ static void cbw_close(BlockDriverState *bs)
{
BDRVCopyBeforeWriteState *s = bs->opaque;
+ fleecing_free(s->fleecing);
+ s->fleecing = NULL;
block_copy_state_free(s->bcs);
s->bcs = NULL;
}
--
2.31.1
- [PATCH v3 07/19] block/dirty-bitmap: introduce bdrv_dirty_bitmap_status(), (continued)
- [PATCH v3 07/19] block/dirty-bitmap: introduce bdrv_dirty_bitmap_status(), Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 01/19] block/block-copy: move copy_bitmap initialization to block_copy_state_new(), Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 08/19] block/reqlist: add reqlist_wait_all(), Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 02/19] block/dirty-bitmap: bdrv_merge_dirty_bitmap(): add return value, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 04/19] block/copy-before-write: add bitmap open parameter, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 03/19] block/block-copy: block_copy_state_new(): add bitmap parameter, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 05/19] block/block-copy: add block_copy_reset(), Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 12/19] block/block-copy: add write-unchanged mode, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 10/19] block: introduce fleecing block driver, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 06/19] block: intoduce reqlist, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 11/19] block/copy-before-write: support fleecing block driver,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v3 13/19] block/copy-before-write: use write-unchanged in fleecing mode, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 09/19] block: introduce FleecingState class, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 14/19] iotests/image-fleecing: add test-case for fleecing format node, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 15/19] iotests.py: add qemu_io_pipe_and_status(), Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 16/19] iotests/image-fleecing: add test case with bitmap, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 17/19] block: blk_root(): return non-const pointer, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 19/19] iotests/image-fleecing: test push backup with fleecing, Vladimir Sementsov-Ogievskiy, 2021/12/22
- [PATCH v3 18/19] qapi: backup: add immutable-source parameter, Vladimir Sementsov-Ogievskiy, 2021/12/22