From 5a507426740b4d7bdd2b333cfa7f5da3e60ebad8 Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Tue, 24 Aug 2021 11:38:38 +0300 Subject: [PATCH] block/copy-before-write: cbw_init(): use file child after attaching In the next commit we'll get rid of source argument of cbw_init(). Prepare to it now, to make next commit simpler: move the code block that uses source below attaching the child and use bs->file->bs instead of source variable. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Message-Id: <20210824083856.17408-17-vsementsov@virtuozzo.com> Signed-off-by: Hanna Reitz --- block/copy-before-write.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index d7f1833efa..4858dcf8ff 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -149,13 +149,6 @@ static int cbw_init(BlockDriverState *bs, BlockDriverState *source, { BDRVCopyBeforeWriteState *s = bs->opaque; - bs->total_sectors = source->total_sectors; - bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED | - (BDRV_REQ_FUA & source->supported_write_flags); - bs->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); s->target = bdrv_attach_child(bs, target, "target", &child_of_bds, BDRV_CHILD_DATA, errp); @@ -173,6 +166,13 @@ static int cbw_init(BlockDriverState *bs, BlockDriverState *source, return -EINVAL; } + bs->total_sectors = bs->file->bs->total_sectors; + bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED | + (BDRV_REQ_FUA & bs->file->bs->supported_write_flags); + bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED | + ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) & + bs->file->bs->supported_zero_flags); + s->bcs = block_copy_state_new(bs->file, s->target, false, compress, errp); if (!s->bcs) { error_prepend(errp, "Cannot create block-copy-state: ");