Remove the bdrv_co_write_zeroes callback. Instead use the discard information from bdrv_get_info to choose between bdrv_co_discard and a normal write.
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- block.c | 12 +++++++++--- block/qed.c | 8 -------- block_int.h | 8 -------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/block.c b/block.c index e4f7782..34db914 100644 --- a/block.c +++ b/block.c @@ -1656,6 +1656,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs, int cluster_nb_sectors; size_t skip_bytes; int ret; + BlockDriverInfo bdi; /* Cover entire cluster so no additional backing file I/O is required when * allocating cluster in the image file. @@ -1676,7 +1677,8 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs, goto err; } - if (drv->bdrv_co_write_zeroes && + /* If it is worthless, do not check if the buffer is zero. */ + if (bdrv_get_info(bs, &bdi) >= 0 && bdi.discard_zeroes_data && buffer_is_zero(bounce_buffer, iov.iov_len)) { ret = bdrv_co_do_write_zeroes(bs, cluster_sector_num, cluster_nb_sectors, &bounce_qiov); @@ -1785,13 +1787,17 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BlockDriver *drv = bs->drv; + BlockDriverInfo bdi; QEMUIOVector my_qiov; struct iovec iov; int ret; /* First try the efficient write zeroes operation */ - if (drv->bdrv_co_write_zeroes) { - return drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors); + if (bdrv_get_info(bs, &bdi) >= 0 && bdi.discard_zeroes_data && + bdi.discard_granularity && + (sector_num & (bdi.discard_granularity - 1)) == 0 && + (nb_sectors & (bdi.discard_granularity - 1)) == 0) { + return bdrv_co_discard(bs, sector_num, nb_sectors); } if (qiov) { diff --git a/block/qed.c b/block/qed.c index 9944be5..33fe03f 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1395,13 +1395,6 @@ static BlockDriverAIOCB *bdrv_qed_aio_flush(BlockDriverState *bs, return bdrv_aio_flush(bs->file, cb, opaque); } -static int coroutine_fn bdrv_qed_co_write_zeroes(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors) -{ - return bdrv_co_discard(bs, sector_num, nb_sectors); -} - static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset) { BDRVQEDState *s = bs->opaque; @@ -1563,7 +1556,6 @@ static BlockDriver bdrv_qed = { .bdrv_aio_writev = bdrv_qed_aio_writev, .bdrv_aio_flush = bdrv_qed_aio_flush, .bdrv_aio_discard = bdrv_qed_aio_discard, - .bdrv_co_write_zeroes = bdrv_qed_co_write_zeroes, .bdrv_truncate = bdrv_qed_truncate, .bdrv_getlength = bdrv_qed_getlength, .bdrv_get_info = bdrv_qed_get_info, diff --git a/block_int.h b/block_int.h index b460c36..2e8cdfe 100644 --- a/block_int.h +++ b/block_int.h @@ -131,14 +131,6 @@ struct BlockDriver { int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); - /* - * Efficiently zero a region of the disk image. Typically an image format - * would use a compact metadata representation to implement this. This - * function pointer may be NULL and .bdrv_co_writev() will be called - * instead. - */ - int coroutine_fn (*bdrv_co_write_zeroes)(BlockDriverState *bs, - int64_t sector_num, int nb_sectors); int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int coroutine_fn (*bdrv_co_is_allocated)(BlockDriverState *bs, -- 1.7.7.6