From: Pavel Butsykin <pbutsy...@virtuozzo.com> Added implementation of the vmdk_co_pwritev_compressed function that will allow us to safely use compressed writes for the vmdk from running VMs.
Signed-off-by: Pavel Butsykin <pbutsy...@virtuozzo.com> Reviewed-by: Stefan Hajnoczi <stefa...@redhat.com> Signed-off-by: Denis V. Lunev <d...@openvz.org> CC: Jeff Cody <jc...@redhat.com> CC: Markus Armbruster <arm...@redhat.com> CC: Eric Blake <ebl...@redhat.com> CC: John Snow <js...@redhat.com> CC: Stefan Hajnoczi <stefa...@redhat.com> CC: Kevin Wolf <kw...@redhat.com> --- block/vmdk.c | 55 +++++-------------------------------------------------- 1 file changed, 5 insertions(+), 50 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 2901692..18bebd6 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1649,56 +1649,11 @@ vmdk_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, return ret; } -typedef struct VmdkWriteCompressedCo { - BlockDriverState *bs; - int64_t sector_num; - const uint8_t *buf; - int nb_sectors; - int ret; -} VmdkWriteCompressedCo; - -static void vmdk_co_write_compressed(void *opaque) -{ - VmdkWriteCompressedCo *co = opaque; - QEMUIOVector local_qiov; - uint64_t offset = co->sector_num * BDRV_SECTOR_SIZE; - uint64_t bytes = co->nb_sectors * BDRV_SECTOR_SIZE; - - struct iovec iov = (struct iovec) { - .iov_base = (uint8_t*) co->buf, - .iov_len = bytes, - }; - qemu_iovec_init_external(&local_qiov, &iov, 1); - - co->ret = vmdk_pwritev(co->bs, offset, bytes, &local_qiov, false, false); -} - -static int vmdk_write_compressed(BlockDriverState *bs, - int64_t sector_num, - const uint8_t *buf, - int nb_sectors) +static int coroutine_fn +vmdk_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, QEMUIOVector *qiov) { - BDRVVmdkState *s = bs->opaque; - - if (s->num_extents == 1 && s->extents[0].compressed) { - Coroutine *co; - AioContext *aio_context = bdrv_get_aio_context(bs); - VmdkWriteCompressedCo data = { - .bs = bs, - .sector_num = sector_num, - .buf = buf, - .nb_sectors = nb_sectors, - .ret = -EINPROGRESS, - }; - co = qemu_coroutine_create(vmdk_co_write_compressed); - qemu_coroutine_enter(co, &data); - while (data.ret == -EINPROGRESS) { - aio_poll(aio_context, true); - } - return data.ret; - } else { - return -ENOTSUP; - } + return vmdk_co_pwritev(bs, offset, bytes, qiov, 0); } static int coroutine_fn vmdk_co_pwrite_zeroes(BlockDriverState *bs, @@ -2397,7 +2352,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_reopen_prepare = vmdk_reopen_prepare, .bdrv_co_preadv = vmdk_co_preadv, .bdrv_co_pwritev = vmdk_co_pwritev, - .bdrv_write_compressed = vmdk_write_compressed, + .bdrv_co_pwritev_compressed = vmdk_co_pwritev_compressed, .bdrv_co_pwrite_zeroes = vmdk_co_pwrite_zeroes, .bdrv_close = vmdk_close, .bdrv_create = vmdk_create, -- 2.1.4