[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 13/21] block/copy-before-write: introduce cbw_init()
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH 13/21] block/copy-before-write: introduce cbw_init() |
Date: |
Mon, 17 May 2021 09:44:20 +0300 |
Move part of bdrv_cbw_append() to new function cbw_open(). It's an
intermediate step for adding noramal .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>
---
block/copy-before-write.c | 73 +++++++++++++++++++++++----------------
1 file changed, 43 insertions(+), 30 deletions(-)
diff --git a/block/copy-before-write.c b/block/copy-before-write.c
index 35a9aa163d..94b1357fd8 100644
--- a/block/copy-before-write.c
+++ b/block/copy-before-write.c
@@ -144,6 +144,47 @@ 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: ");
+ bdrv_unref(target);
+ 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: ");
+ bdrv_unref(source);
+ 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,38 +222,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: ");
- bdrv_unref(target);
- 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: ");
- bdrv_unref(source);
- 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 12/21] block/copy-before-write: bdrv_cbw_append(): replace child at last, (continued)
- [PATCH 12/21] block/copy-before-write: bdrv_cbw_append(): replace child at last, Vladimir Sementsov-Ogievskiy, 2021/05/17
- [PATCH 11/21] block/copy-before-write: use file child instead of backing, Vladimir Sementsov-Ogievskiy, 2021/05/17
- [PATCH 07/21] block-copy: always set BDRV_REQ_SERIALISING flag, Vladimir Sementsov-Ogievskiy, 2021/05/17
- [PATCH 18/21] block/block-copy: make setting progress optional, Vladimir Sementsov-Ogievskiy, 2021/05/17
- [PATCH 13/21] block/copy-before-write: introduce cbw_init(),
Vladimir Sementsov-Ogievskiy <=
- [PATCH 08/21] block/backup: stricter backup_calculate_cluster_size(), Vladimir Sementsov-Ogievskiy, 2021/05/17
- [PATCH 14/21] block/copy-before-write: cbw_init(): rename variables, Vladimir Sementsov-Ogievskiy, 2021/05/17
- [PATCH 17/21] block/block-copy: switch to fully set bitmap by default, Vladimir Sementsov-Ogievskiy, 2021/05/17
- [PATCH 09/21] block/backup: move cluster size calculation to block-copy, Vladimir Sementsov-Ogievskiy, 2021/05/17