We are going to use bdrv_co_block_status in bdrv_make_zero, so move it now down.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> Reviewed-by: Stefan Hajnoczi <stefa...@redhat.com> --- block/io.c | 82 +++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/block/io.c b/block/io.c index e6a8ead46c..3bc0daec33 100644 --- a/block/io.c +++ b/block/io.c @@ -2178,47 +2178,6 @@ int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, return 0; } -/* - * Completely zero out a block device with the help of bdrv_pwrite_zeroes. - * The operation is sped up by checking the block status and only writing - * zeroes to the device if they currently do not return zeroes. Optional - * flags are passed through to bdrv_pwrite_zeroes (e.g. BDRV_REQ_MAY_UNMAP, - * BDRV_REQ_FUA). - * - * Returns < 0 on error, 0 on success. For error codes see bdrv_write(). - */ -int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) -{ - int ret; - int64_t target_size, bytes, offset = 0; - BlockDriverState *bs = child->bs; - - target_size = bdrv_getlength(bs); - if (target_size < 0) { - return target_size; - } - - for (;;) { - bytes = MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); - if (bytes <= 0) { - return 0; - } - ret = bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL); - if (ret < 0) { - return ret; - } - if (ret & BDRV_BLOCK_ZERO) { - offset += bytes; - continue; - } - ret = bdrv_pwrite_zeroes(child, offset, bytes, flags); - if (ret < 0) { - return ret; - } - offset += bytes; - } -} - int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) { int ret; @@ -2773,6 +2732,47 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, return data.ret; } +/* + * Completely zero out a block device with the help of bdrv_pwrite_zeroes. + * The operation is sped up by checking the block status and only writing + * zeroes to the device if they currently do not return zeroes. Optional + * flags are passed through to bdrv_pwrite_zeroes (e.g. BDRV_REQ_MAY_UNMAP, + * BDRV_REQ_FUA). + * + * Returns < 0 on error, 0 on success. For error codes see bdrv_write(). + */ +int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) +{ + int ret; + int64_t target_size, bytes, offset = 0; + BlockDriverState *bs = child->bs; + + target_size = bdrv_getlength(bs); + if (target_size < 0) { + return target_size; + } + + for (;;) { + bytes = MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); + if (bytes <= 0) { + return 0; + } + ret = bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL); + if (ret < 0) { + return ret; + } + if (ret & BDRV_BLOCK_ZERO) { + offset += bytes; + continue; + } + ret = bdrv_pwrite_zeroes(child, offset, bytes, flags); + if (ret < 0) { + return ret; + } + offset += bytes; + } +} + typedef struct BdrvVmstateCo { BlockDriverState *bs; QEMUIOVector *qiov; -- 2.21.0