mirror of https://gitee.com/openkylin/qemu.git
block/copy-before-write: introduce cbw_init()
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> Message-Id: <20210824083856.17408-15-vsementsov@virtuozzo.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
This commit is contained in:
parent
7ddbce2dec
commit
1f0cacb967
|
@ -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 = {
|
BlockDriver bdrv_cbw_filter = {
|
||||||
.format_name = "copy-before-write",
|
.format_name = "copy-before-write",
|
||||||
.instance_size = sizeof(BDRVCopyBeforeWriteState),
|
.instance_size = sizeof(BDRVCopyBeforeWriteState),
|
||||||
|
@ -181,36 +220,10 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState *source,
|
||||||
error_prepend(errp, "Cannot open driver: ");
|
error_prepend(errp, "Cannot open driver: ");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = top->opaque;
|
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);
|
ret = cbw_init(top, source, target, compress, errp);
|
||||||
state->target = bdrv_attach_child(top, target, "target", &child_of_bds,
|
if (ret < 0) {
|
||||||
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: ");
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue