qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu-img: use blk_co_pwrite_zeroes for zero sectors when compressed
@ 2017-04-20  8:38 jemmy858585
  2017-04-20  8:52 ` 858585 jemmy
  2017-04-20 10:00 ` Kevin Wolf
  0 siblings, 2 replies; 6+ messages in thread
From: jemmy858585 @ 2017-04-20  8:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, mreitz, qemu-block, Lidong Chen

From: Lidong Chen <lidongchen@tencent.com>

when the buffer is zero, blk_co_pwrite_zeroes is more effectively than
blk_co_pwritev with BDRV_REQ_WRITE_COMPRESSED. this patch can reduces
the time when converts the qcow2 image with lots of zero.

Signed-off-by: Lidong Chen <lidongchen@tencent.com>
---
 qemu-img.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index b220cf7..0256539 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1675,13 +1675,20 @@ static int coroutine_fn convert_co_write(ImgConvertState *s, int64_t sector_num,
              * write if the buffer is completely zeroed and we're allowed to
              * keep the target sparse. */
             if (s->compressed) {
-                if (s->has_zero_init && s->min_sparse &&
-                    buffer_is_zero(buf, n * BDRV_SECTOR_SIZE))
-                {
-                    assert(!s->target_has_backing);
-                    break;
+                if (buffer_is_zero(buf, n * BDRV_SECTOR_SIZE)) {
+                    if (s->has_zero_init && s->min_sparse) {
+                        assert(!s->target_has_backing);
+                        break;
+                    } else {
+                        ret = blk_co_pwrite_zeroes(s->target,
+                                           sector_num << BDRV_SECTOR_BITS,
+                                           n << BDRV_SECTOR_BITS, 0);
+                        if (ret < 0) {
+                            return ret;
+                        }
+                        break;
+                    }
                 }
-
                 iov.iov_base = buf;
                 iov.iov_len = n << BDRV_SECTOR_BITS;
                 qemu_iovec_init_external(&qiov, &iov, 1);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-04-23 12:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-20  8:38 [Qemu-devel] [PATCH] qemu-img: use blk_co_pwrite_zeroes for zero sectors when compressed jemmy858585
2017-04-20  8:52 ` 858585 jemmy
2017-04-20 10:00 ` Kevin Wolf
2017-04-21  2:58   ` 858585 jemmy
2017-04-21  5:37     ` 858585 jemmy
2017-04-23 12:53       ` 858585 jemmy

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).