qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: den@openvz.org, Pavel Butsykin <pbutsykin@virtuozzo.com>,
	Jeff Cody <jcody@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Eric Blake <eblake@redhat.com>, John Snow <jsnow@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH v5 02/15] block/io: reuse bdrv_co_pwritev() for write compressed
Date: Mon,  4 Jul 2016 15:28:13 +0300	[thread overview]
Message-ID: <1467635306-31875-3-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1467635306-31875-1-git-send-email-den@openvz.org>

From: Pavel Butsykin <pbutsykin@virtuozzo.com>

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 <pbutsykin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Jeff Cody <jcody@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
CC: Eric Blake <eblake@redhat.com>
CC: John Snow <jsnow@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
---
 block/io.c                | 57 ++++++++++++++++++++++++++++++++++-------------
 include/block/block.h     |  3 ++-
 include/block/block_int.h |  3 +++
 qemu-img.c                |  2 +-
 4 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/block/io.c b/block/io.c
index 22f20b1..49742eb 100644
--- a/block/io.c
+++ b/block/io.c
@@ -902,6 +902,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)
 {
@@ -1511,9 +1525,14 @@ int coroutine_fn bdrv_co_pwritev(BlockDriverState *bs,
         bytes = ROUND_UP(bytes, align);
     }
 
-    ret = bdrv_aligned_pwritev(bs, &req, offset, bytes,
-                               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,
+                                   use_local_qiov ? &local_qiov : qiov,
+                                   flags);
+    }
 
 fail:
 
@@ -1827,26 +1846,32 @@ int bdrv_is_allocated_above(BlockDriverState *top,
 int bdrv_pwrite_compressed(BlockDriverState *bs, int64_t offset,
                            const void *buf, int bytes)
 {
+    QEMUIOVector qiov;
+    struct iovec iov;
     BlockDriver *drv = bs->drv;
-    int ret;
 
     if (!drv) {
         return -ENOMEDIUM;
     }
-    if (!drv->bdrv_write_compressed) {
-        return -ENOTSUP;
-    }
-    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);
+    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);
 
-    return drv->bdrv_write_compressed(bs, offset >> BDRV_SECTOR_BITS, buf,
-                                      bytes >> BDRV_SECTOR_BITS);
+    return bdrv_prwv_co(bs, offset, &qiov, true, BDRV_REQ_WRITE_COMPRESSED);
 }
 
 typedef struct BdrvVmstateCo {
diff --git a/include/block/block.h b/include/block/block.h
index 60cd7d1..0d01ffd 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 2057156..17a5efe 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 5b2b8df..7bb1cfc 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2023,7 +2023,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;
-- 
2.1.4

  parent reply	other threads:[~2016-07-04 12:28 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-04 12:28 [Qemu-devel] [PATCH v5 00/15] backup compression Denis V. Lunev
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 01/15] block: switch blk_write_compressed() to byte-based interface Denis V. Lunev
2016-07-04 12:28 ` Denis V. Lunev [this message]
2016-07-14 12:17   ` [Qemu-devel] [PATCH v5 02/15] block/io: reuse bdrv_co_pwritev() for write compressed Stefan Hajnoczi
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 03/15] qcow2: add qcow2_co_pwritev_compressed Denis V. Lunev
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 04/15] qcow2: cleanup qcow2_co_pwritev_compressed to avoid the recursion Denis V. Lunev
2016-07-14 12:17   ` Stefan Hajnoczi
2016-07-14 12:35   ` Eric Blake
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 05/15] vmdk: add vmdk_co_pwritev_compressed Denis V. Lunev
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 06/15] qcow: add qcow_co_pwritev_compressed Denis V. Lunev
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 07/15] qcow: cleanup qcow_co_pwritev_compressed to avoid the recursion Denis V. Lunev
2016-07-14 12:17   ` Stefan Hajnoczi
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 08/15] block: remove BlockDriver.bdrv_write_compressed Denis V. Lunev
2016-07-14 12:17   ` Stefan Hajnoczi
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 09/15] block/io: turn on dirty_bitmaps for the compressed writes Denis V. Lunev
2016-07-14 12:17   ` Stefan Hajnoczi
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 10/15] block: simplify drive-backup Denis V. Lunev
2016-07-14 12:17   ` Stefan Hajnoczi
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 11/15] block: simplify blockdev-backup Denis V. Lunev
2016-07-14 12:17   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-07-14 12:37   ` [Qemu-devel] " Eric Blake
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 12/15] drive-backup: added support for data compression Denis V. Lunev
2016-07-14 12:17   ` Stefan Hajnoczi
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 13/15] blockdev-backup: " Denis V. Lunev
2016-07-14 12:17   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 14/15] qemu-iotests: test backup compression in 055 Denis V. Lunev
2016-07-14 12:17   ` Stefan Hajnoczi
2016-07-04 12:28 ` [Qemu-devel] [PATCH v5 15/15] qemu-iotests: add vmdk for " Denis V. Lunev
2016-07-08 13:13 ` [Qemu-devel] [PATCH v5 00/15] backup compression Denis V. Lunev
2016-07-14 12:17   ` Stefan Hajnoczi
2016-07-19 21:58 ` Jeff Cody
2016-07-20  9:55   ` Pavel Butsykin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467635306-31875-3-git-send-email-den@openvz.org \
    --to=den@openvz.org \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jcody@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbutsykin@virtuozzo.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).