[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 16/35] block/copy-before-write: introduce cbw_init()
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 16/35] block/copy-before-write: introduce cbw_init() |
Date: |
Tue, 1 Jun 2021 19:50:07 +0300 |
Move part of bdrv_cbw_append() to new function cbw_open(). It's an
intermediate step for adding normal .bdrv_open() handler to the
filter. With this commit no logic is changed, but we have a function
which will be turned into .bdrv_open() handler in future commit.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
block/copy-before-write.c | 69 +++++++++++++++++++++++----------------
1 file changed, 41 insertions(+), 28 deletions(-)
diff --git a/block/copy-before-write.c b/block/copy-before-write.c
index adbbc64aa9..a4fee645fd 100644
--- a/block/copy-before-write.c
+++ b/block/copy-before-write.c
@@ -144,6 +144,45 @@ static void cbw_child_perm(BlockDriverState *bs, BdrvChild
*c,
}
}
+static int cbw_init(BlockDriverState *top, BlockDriverState *source,
+ BlockDriverState *target, bool compress, Error **errp)
+{
+ BDRVCopyBeforeWriteState *state = top->opaque;
+
+ top->total_sectors = source->total_sectors;
+ top->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED |
+ (BDRV_REQ_FUA & source->supported_write_flags);
+ top->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED |
+ ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) &
+ source->supported_zero_flags);
+
+ bdrv_ref(target);
+ state->target = bdrv_attach_child(top, target, "target", &child_of_bds,
+ BDRV_CHILD_DATA, errp);
+ if (!state->target) {
+ error_prepend(errp, "Cannot attach target child: ");
+ return -EINVAL;
+ }
+
+ bdrv_ref(source);
+ top->file = bdrv_attach_child(top, source, "file", &child_of_bds,
+ BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
+ errp);
+ if (!top->file) {
+ error_prepend(errp, "Cannot attach file child: ");
+ return -EINVAL;
+ }
+
+ state->bcs = block_copy_state_new(top->file, state->target, false,
compress,
+ errp);
+ if (!state->bcs) {
+ error_prepend(errp, "Cannot create block-copy-state: ");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
BlockDriver bdrv_cbw_filter = {
.format_name = "copy-before-write",
.instance_size = sizeof(BDRVCopyBeforeWriteState),
@@ -181,36 +220,10 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState
*source,
error_prepend(errp, "Cannot open driver: ");
return NULL;
}
-
state = top->opaque;
- top->total_sectors = source->total_sectors;
- top->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED |
- (BDRV_REQ_FUA & source->supported_write_flags);
- top->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED |
- ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) &
- source->supported_zero_flags);
-
- bdrv_ref(target);
- state->target = bdrv_attach_child(top, target, "target", &child_of_bds,
- BDRV_CHILD_DATA, errp);
- if (!state->target) {
- error_prepend(errp, "Cannot attach target child: ");
- goto fail;
- }
- bdrv_ref(source);
- top->file = bdrv_attach_child(top, source, "file", &child_of_bds,
- BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
- errp);
- if (!top->file) {
- error_prepend(errp, "Cannot attach file child: ");
- goto fail;
- }
-
- state->bcs = block_copy_state_new(top->file, state->target, false,
compress,
- errp);
- if (!state->bcs) {
- error_prepend(errp, "Cannot create block-copy-state: ");
+ ret = cbw_init(top, source, target, compress, errp);
+ if (ret < 0) {
goto fail;
}
--
2.29.2
- [PATCH v3 10/35] block/backup: set copy_range and compress after filter insertion, (continued)
- [PATCH v3 10/35] block/backup: set copy_range and compress after filter insertion, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 05/35] qdev-properties: PropertyInfo: add realized_set_allowed field, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 06/35] qdev: allow setting drive property for realized device, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 07/35] block: rename backup-top to copy-before-write, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 11/35] block/backup: move cluster size calculation to block-copy, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 08/35] block-copy: always set BDRV_REQ_SERIALISING flag, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 14/35] block/copy-before-write: use file child instead of backing, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 13/35] block/copy-before-write: drop extra bdrv_unref on failure path, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 15/35] block/copy-before-write: bdrv_cbw_append(): replace child at last, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 12/35] block/copy-before-write: relax permission requirements when no parents, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 16/35] block/copy-before-write: introduce cbw_init(),
Vladimir Sementsov-Ogievskiy <=
- [PATCH v3 17/35] block/copy-before-write: cbw_init(): rename variables, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 19/35] block/copy-before-write: bdrv_cbw_append(): drop unused compress arg, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 18/35] block/copy-before-write: cbw_init(): use file child after attaching, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 21/35] block/copy-before-write: initialize block-copy bitmap, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 20/35] block/copy-before-write: cbw_init(): use options, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 22/35] block/block-copy: make setting progress optional, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 28/35] iotests/222: fix pylint and mypy complains, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 23/35] block/copy-before-write: make public block driver, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 24/35] qapi: publish copy-before-write filter, Vladimir Sementsov-Ogievskiy, 2021/06/01
- [PATCH v3 29/35] iotests/222: constantly use single quotes for strings, Vladimir Sementsov-Ogievskiy, 2021/06/01