[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 16/42] block/io: reuse bdrv_co_pwritev() for write co
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 16/42] block/io: reuse bdrv_co_pwritev() for write compressed |
Date: |
Mon, 5 Sep 2016 20:13:28 +0200 |
From: Pavel Butsykin <address@hidden>
For bdrv_pwrite_compressed() it looks like most of the code creating
coroutine is duplicated in bdrv_prwv_co(). So we can just add a flag
(BDRV_REQ_WRITE_COMPRESSED) and use bdrv_prwv_co() as a generic one.
In the end we get coroutine oriented function for write compressed by using
bdrv_co_pwritev/blk_co_pwritev with BDRV_REQ_WRITE_COMPRESSED flag.
Signed-off-by: Pavel Butsykin <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Denis V. Lunev <address@hidden>
CC: Jeff Cody <address@hidden>
CC: Markus Armbruster <address@hidden>
CC: Eric Blake <address@hidden>
CC: John Snow <address@hidden>
CC: Stefan Hajnoczi <address@hidden>
CC: Kevin Wolf <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/io.c | 56 +++++++++++++++++++++++++++++++++--------------
include/block/block.h | 3 ++-
include/block/block_int.h | 3 +++
qemu-img.c | 2 +-
4 files changed, 46 insertions(+), 18 deletions(-)
diff --git a/block/io.c b/block/io.c
index c528fea..d402076 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 7bb5ddb..d8dacd2 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 1e939de..42f8f84 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 ef0157a..c2ea494 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;
--
1.8.3.1
- [Qemu-devel] [PULL 02/42] scsi: scsi-cd without drive property for empty drive, (continued)
- [Qemu-devel] [PULL 02/42] scsi: scsi-cd without drive property for empty drive, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 03/42] block: Accept node-name for block-stream, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 06/42] block: Accept node-name for blockdev-mirror, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 05/42] block: Accept node-name for blockdev-backup, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 01/42] ide: ide-cd without drive property for empty drive, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 09/42] block: Accept node-name for change-backing-file, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 08/42] block: Accept node-name for blockdev-snapshot-internal-sync, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 12/42] nbd-server: Use a separate BlockBackend, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 07/42] block: Accept node-name for blockdev-snapshot-delete-internal-sync, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 15/42] block: Convert bdrv_pwrite_compressed() to BdrvChild, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 16/42] block/io: reuse bdrv_co_pwritev() for write compressed,
Kevin Wolf <=
- [Qemu-devel] [PULL 19/42] vmdk: add vmdk_co_pwritev_compressed, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 13/42] nbd-server: Allow node name for nbd-server-add, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 14/42] block: switch blk_write_compressed() to byte-based interface, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 10/42] block: Accept node-name for drive-backup, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 11/42] block: Accept node-name for drive-mirror, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 18/42] qcow2: cleanup qcow2_co_pwritev_compressed to avoid the recursion, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 20/42] qcow: add qcow_co_pwritev_compressed, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 17/42] qcow2: add qcow2_co_pwritev_compressed, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 21/42] qcow: cleanup qcow_co_pwritev_compressed to avoid the recursion, Kevin Wolf, 2016/09/05
- [Qemu-devel] [PULL 22/42] block: remove BlockDriver.bdrv_write_compressed, Kevin Wolf, 2016/09/05