thebeanogamer / rpms / qemu-kvm

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