diff --git a/block/io.c b/block/io.c index c528fead1bc5de2e40a31f8447119d708a45c9f9..d402076e955674f0722e6e3ace2567f486e852a1 100644 --- a/block/io.c +++ b/block/io.c @@ -886,6 +886,20 @@ emulate_flags: return ret; } +static int coroutine_fn +bdrv_driver_pwritev_compressed(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, QEMUIOVector *qiov) +{ + BlockDriver *drv = bs->drv; + + if (!drv->bdrv_co_pwritev_compressed) { + return -ENOTSUP; + } + + assert(QLIST_EMPTY(&bs->dirty_bitmaps)); + return drv->bdrv_co_pwritev_compressed(bs, offset, bytes, qiov); +} + static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs, int64_t offset, unsigned int bytes, QEMUIOVector *qiov) { @@ -1555,9 +1569,14 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, bytes = ROUND_UP(bytes, align); } - ret = bdrv_aligned_pwritev(bs, &req, offset, bytes, align, - use_local_qiov ? &local_qiov : qiov, - flags); + if (flags & BDRV_REQ_WRITE_COMPRESSED) { + ret = bdrv_driver_pwritev_compressed( + bs, offset, bytes, use_local_qiov ? &local_qiov : qiov); + } else { + ret = bdrv_aligned_pwritev(bs, &req, offset, bytes, align, + use_local_qiov ? &local_qiov : qiov, + flags); + } fail: @@ -1873,25 +1892,30 @@ int bdrv_pwrite_compressed(BdrvChild *child, int64_t offset, { BlockDriverState *bs = child->bs; BlockDriver *drv = bs->drv; - int ret; + QEMUIOVector qiov; + struct iovec iov; if (!drv) { return -ENOMEDIUM; } - if (!drv->bdrv_write_compressed) { - return -ENOTSUP; - } - ret = bdrv_check_byte_request(bs, offset, bytes); - if (ret < 0) { - return ret; + if (drv->bdrv_write_compressed) { + int ret = bdrv_check_byte_request(bs, offset, bytes); + if (ret < 0) { + return ret; + } + assert(QLIST_EMPTY(&bs->dirty_bitmaps)); + assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); + assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); + return drv->bdrv_write_compressed(bs, offset >> BDRV_SECTOR_BITS, buf, + bytes >> BDRV_SECTOR_BITS); } + iov = (struct iovec) { + .iov_base = (void *)buf, + .iov_len = bytes, + }; + qemu_iovec_init_external(&qiov, &iov, 1); - assert(QLIST_EMPTY(&bs->dirty_bitmaps)); - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); - - return drv->bdrv_write_compressed(bs, offset >> BDRV_SECTOR_BITS, buf, - bytes >> BDRV_SECTOR_BITS); + return bdrv_prwv_co(child, offset, &qiov, true, BDRV_REQ_WRITE_COMPRESSED); } typedef struct BdrvVmstateCo { diff --git a/include/block/block.h b/include/block/block.h index 7bb5ddbf73349658496546b1b3785f98aa872a4b..d8dacd2ced7134588953b6d8d60fd51c827dfae6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -65,9 +65,10 @@ typedef enum { BDRV_REQ_MAY_UNMAP = 0x4, BDRV_REQ_NO_SERIALISING = 0x8, BDRV_REQ_FUA = 0x10, + BDRV_REQ_WRITE_COMPRESSED = 0x20, /* Mask of valid flags */ - BDRV_REQ_MASK = 0x1f, + BDRV_REQ_MASK = 0x3f, } BdrvRequestFlags; typedef struct BlockSizes { diff --git a/include/block/block_int.h b/include/block/block_int.h index 1e939de4fe5a3b04b418edb4c108e82c3c93a0f8..42f8f8443d9117c6076c639fb49a57b855954c2e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -207,6 +207,9 @@ struct BlockDriver { int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors); + int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, QEMUIOVector *qiov); + int (*bdrv_snapshot_create)(BlockDriverState *bs, QEMUSnapshotInfo *sn_info); int (*bdrv_snapshot_goto)(BlockDriverState *bs, diff --git a/qemu-img.c b/qemu-img.c index ef0157aa8ae05c05f84bb64a83443430368cc98b..c2ea4949284dcf3cf8d9913ff19c74d2f2502b45 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2034,7 +2034,7 @@ static int img_convert(int argc, char **argv) const char *preallocation = qemu_opt_get(opts, BLOCK_OPT_PREALLOC); - if (!drv->bdrv_write_compressed) { + if (!drv->bdrv_write_compressed && !drv->bdrv_co_pwritev_compressed) { error_report("Compression not supported for this file format"); ret = -1; goto out;