yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
dc7afb
From eea45924903f03dc6d8f20576be0a4a84d5acce4 Mon Sep 17 00:00:00 2001
dc7afb
From: Kevin Wolf <kwolf@redhat.com>
dc7afb
Date: Wed, 10 Feb 2021 10:16:11 -0500
dc7afb
Subject: [PATCH 4/5] qemu-img convert: Don't pre-zero images
dc7afb
dc7afb
RH-Author: Kevin Wolf <kwolf@redhat.com>
dc7afb
Message-id: <20210210101611.137928-2-kwolf@redhat.com>
dc7afb
Patchwork-id: 101030
dc7afb
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 1/1] qemu-img convert: Don't pre-zero images
dc7afb
Bugzilla: 1855250
dc7afb
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
dc7afb
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
dc7afb
RH-Acked-by: Max Reitz <mreitz@redhat.com>
dc7afb
dc7afb
Since commit 5a37b60a61c, qemu-img create will pre-zero the target image
dc7afb
if it isn't already zero-initialised (most importantly, for host block
dc7afb
devices, but also iscsi etc.), so that writing explicit zeros wouldn't
dc7afb
be necessary later.
dc7afb
dc7afb
This could speed up the operation significantly, in particular when the
dc7afb
source image file was only sparsely populated. However, it also means
dc7afb
that some block are written twice: Once when pre-zeroing them, and then
dc7afb
when they are overwritten with actual data. On a full image, the
dc7afb
pre-zeroing is wasted work because everything will be overwritten.
dc7afb
dc7afb
In practice, write_zeroes typically turns out faster than writing
dc7afb
explicit zero buffers, but slow enough that first zeroing everything and
dc7afb
then overwriting parts can be a significant net loss.
dc7afb
dc7afb
Meanwhile, qemu-img convert was rewritten in 690c7301600 and zero blocks
dc7afb
are now written to the target using bdrv_co_pwrite_zeroes() if the
dc7afb
target could be pre-zeroed. This way we already make use of the faster
dc7afb
write_zeroes operation, but avoid writing any blocks twice.
dc7afb
dc7afb
Remove the pre-zeroing because these days this former optimisation has
dc7afb
actually turned into a pessimisation in the common case.
dc7afb
dc7afb
Reported-by: Nir Soffer <nsoffer@redhat.com>
dc7afb
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
dc7afb
Message-Id: <20200622151203.35624-1-kwolf@redhat.com>
dc7afb
Tested-by:  Nir Soffer <nsoffer@redhat.com>
dc7afb
Reviewed-by: Eric Blake <eblake@redhat.com>
dc7afb
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
dc7afb
(cherry picked from commit edafc70c0c8510862f2f213a3acf7067113bcd08)
dc7afb
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
dc7afb
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
dc7afb
---
dc7afb
 qemu-img.c | 9 ---------
dc7afb
 1 file changed, 9 deletions(-)
dc7afb
dc7afb
diff --git a/qemu-img.c b/qemu-img.c
dc7afb
index a27ad70851..b10dc5129b 100644
dc7afb
--- a/qemu-img.c
dc7afb
+++ b/qemu-img.c
dc7afb
@@ -2029,15 +2029,6 @@ static int convert_do_copy(ImgConvertState *s)
dc7afb
         s->has_zero_init = false;
dc7afb
     }
dc7afb
 
dc7afb
-    if (!s->has_zero_init && !s->target_has_backing &&
dc7afb
-        bdrv_can_write_zeroes_with_unmap(blk_bs(s->target)))
dc7afb
-    {
dc7afb
-        ret = blk_make_zero(s->target, BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK);
dc7afb
-        if (ret == 0) {
dc7afb
-            s->has_zero_init = true;
dc7afb
-        }
dc7afb
-    }
dc7afb
-
dc7afb
     /* Allocate buffer for copied data. For compressed images, only one cluster
dc7afb
      * can be copied at a time. */
dc7afb
     if (s->compressed) {
dc7afb
-- 
dc7afb
2.27.0
dc7afb