[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 11/19] block/copy-before-write: support fleecing block driver
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v2 11/19] block/copy-before-write: support fleecing block driver |
Date: |
Fri, 27 Aug 2021 21:18:00 +0300 |
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 e3456ad6aa..686a085861 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,
@@ -149,6 +162,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,
@@ -162,6 +176,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"))
@@ -203,6 +218,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;
}
@@ -210,6 +233,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.29.2
- [PATCH v2 00/19] Make image fleecing more usable, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 01/19] block/block-copy: move copy_bitmap initialization to block_copy_state_new(), Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 03/19] block/block-copy: block_copy_state_new(): add bitmap parameter, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 02/19] block/dirty-bitmap: bdrv_merge_dirty_bitmap(): add return value, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 04/19] block/copy-before-write: add bitmap open parameter, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 05/19] block/block-copy: add block_copy_reset(), Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 13/19] block/copy-before-write: use write-unchanged in fleecing mode, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 06/19] block: intoduce reqlist, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 07/19] block/dirty-bitmap: introduce bdrv_dirty_bitmap_status(), Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 11/19] block/copy-before-write: support fleecing block driver,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v2 09/19] block: introduce FleecingState class, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 16/19] iotests/image-fleecing: add test case with bitmap, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 14/19] iotests/image-fleecing: add test-case for fleecing format node, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 18/19] qapi: backup: add immutable-source parameter, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 19/19] iotests/image-fleecing: test push backup with fleecing, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 15/19] iotests.py: add qemu_io_pipe_and_status(), Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 10/19] block: introduce fleecing block driver, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 12/19] block/block-copy: add write-unchanged mode, Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 08/19] block/reqlist: add reqlist_wait_all(), Vladimir Sementsov-Ogievskiy, 2021/08/27
- [PATCH v2 17/19] block: blk_root(): return non-const pointer, Vladimir Sementsov-Ogievskiy, 2021/08/27