From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, armbru@redhat.com,
xiechanglong.d@gmail.com, wencongyang2@huawei.com,
eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com,
vsementsov@virtuozzo.com, jsnow@redhat.com
Subject: [PATCH v2 11/19] block/copy-before-write: support fleecing block driver
Date: Fri, 27 Aug 2021 21:18:00 +0300 [thread overview]
Message-ID: <20210827181808.311670-12-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20210827181808.311670-1-vsementsov@virtuozzo.com>
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
next prev parent reply other threads:[~2021-08-27 18:34 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-27 18:17 [PATCH v2 00/19] Make image fleecing more usable Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 01/19] block/block-copy: move copy_bitmap initialization to block_copy_state_new() Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 02/19] block/dirty-bitmap: bdrv_merge_dirty_bitmap(): add return value Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 03/19] block/block-copy: block_copy_state_new(): add bitmap parameter Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 04/19] block/copy-before-write: add bitmap open parameter Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 05/19] block/block-copy: add block_copy_reset() Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 06/19] block: intoduce reqlist Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 07/19] block/dirty-bitmap: introduce bdrv_dirty_bitmap_status() Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 08/19] block/reqlist: add reqlist_wait_all() Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 09/19] block: introduce FleecingState class Vladimir Sementsov-Ogievskiy
2021-08-27 18:17 ` [PATCH v2 10/19] block: introduce fleecing block driver Vladimir Sementsov-Ogievskiy
2021-09-01 11:44 ` Markus Armbruster
2021-09-03 13:29 ` Vladimir Sementsov-Ogievskiy
2021-08-27 18:18 ` Vladimir Sementsov-Ogievskiy [this message]
2021-08-27 18:18 ` [PATCH v2 12/19] block/block-copy: add write-unchanged mode Vladimir Sementsov-Ogievskiy
2021-08-27 18:18 ` [PATCH v2 13/19] block/copy-before-write: use write-unchanged in fleecing mode Vladimir Sementsov-Ogievskiy
2021-08-27 18:18 ` [PATCH v2 14/19] iotests/image-fleecing: add test-case for fleecing format node Vladimir Sementsov-Ogievskiy
2021-08-27 18:18 ` [PATCH v2 15/19] iotests.py: add qemu_io_pipe_and_status() Vladimir Sementsov-Ogievskiy
2021-08-27 18:18 ` [PATCH v2 16/19] iotests/image-fleecing: add test case with bitmap Vladimir Sementsov-Ogievskiy
2021-08-27 18:18 ` [PATCH v2 17/19] block: blk_root(): return non-const pointer Vladimir Sementsov-Ogievskiy
2021-08-27 18:18 ` [PATCH v2 18/19] qapi: backup: add immutable-source parameter Vladimir Sementsov-Ogievskiy
2021-09-01 11:47 ` Markus Armbruster
2021-08-27 18:18 ` [PATCH v2 19/19] iotests/image-fleecing: test push backup with fleecing Vladimir Sementsov-Ogievskiy
2021-09-22 7:45 ` [PATCH v2 00/19] Make image fleecing more usable Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210827181808.311670-12-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=wencongyang2@huawei.com \
--cc=xiechanglong.d@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).