Blame SOURCES/kvm-qemu-img-Enable-BDRV_REQ_MAY_UNMAP-in-convert.patch

8b1478
From c018040299805135af45098641391a2818ddac8a Mon Sep 17 00:00:00 2001
8b1478
From: Maxim Levitsky <mlevitsk@redhat.com>
8b1478
Date: Mon, 26 Aug 2019 09:19:44 +0200
8b1478
Subject: [PATCH 4/4] qemu-img: Enable BDRV_REQ_MAY_UNMAP in convert
8b1478
8b1478
RH-Author: Maxim Levitsky <mlevitsk@redhat.com>
8b1478
Message-id: <20190826091944.16113-2-mlevitsk@redhat.com>
8b1478
Patchwork-id: 90164
8b1478
O-Subject: [RHEL-7.7.z qemu-kvm-rhev PATCH v3 1/1] qemu-img: Enable BDRV_REQ_MAY_UNMAP in convert
8b1478
Bugzilla: 1648622
8b1478
RH-Acked-by: John Snow <jsnow@redhat.com>
8b1478
RH-Acked-by: Max Reitz <mreitz@redhat.com>
8b1478
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
8b1478
8b1478
From: Nir Soffer <nirsof@gmail.com>
8b1478
8b1478
With Kevin's "block: Fix slow pre-zeroing in qemu-img convert"[1]
8b1478
(commit c9fdcf202f, 'qemu-img: Use BDRV_REQ_NO_FALLBACK for
8b1478
pre-zeroing') we skip the pre zero step called like this:
8b1478
8b1478
    blk_make_zero(s->target, BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK)
8b1478
8b1478
And we write zeroes later using:
8b1478
8b1478
    blk_co_pwrite_zeroes(s->target,
8b1478
                         sector_num << BDRV_SECTOR_BITS,
8b1478
                         n << BDRV_SECTOR_BITS, 0);
8b1478
8b1478
Since we use flags=0, this is translated to NBD_CMD_WRITE_ZEROES with
8b1478
NBD_CMD_FLAG_NO_HOLE flag, which cause the NBD server to allocated space
8b1478
instead of punching a hole.
8b1478
8b1478
Here is an example failure:
8b1478
8b1478
$ dd if=/dev/urandom of=src.img bs=1M count=5
8b1478
$ truncate -s 50m src.img
8b1478
$ truncate -s 50m dst.img
8b1478
$ nbdkit -f -v -e '' -U nbd.sock file file=dst.img
8b1478
8b1478
$ ./qemu-img convert -n src.img nbd:unix:nbd.sock
8b1478
8b1478
We can see in nbdkit log that it received the NBD_CMD_FLAG_NO_HOLE
8b1478
(may_trim=0):
8b1478
8b1478
nbdkit: file[1]: debug: newstyle negotiation: flags: export 0x4d
8b1478
nbdkit: file[1]: debug: pwrite count=2097152 offset=0
8b1478
nbdkit: file[1]: debug: pwrite count=2097152 offset=2097152
8b1478
nbdkit: file[1]: debug: pwrite count=1048576 offset=4194304
8b1478
nbdkit: file[1]: debug: zero count=33554432 offset=5242880 may_trim=0
8b1478
nbdkit: file[1]: debug: zero count=13631488 offset=38797312 may_trim=0
8b1478
nbdkit: file[1]: debug: flush
8b1478
8b1478
And the image became fully allocated:
8b1478
8b1478
$ qemu-img info dst.img
8b1478
virtual size: 50M (52428800 bytes)
8b1478
disk size: 50M
8b1478
8b1478
With this change we see that nbdkit did not receive the
8b1478
NBD_CMD_FLAG_NO_HOLE (may_trim=1):
8b1478
8b1478
nbdkit: file[1]: debug: newstyle negotiation: flags: export 0x4d
8b1478
nbdkit: file[1]: debug: pwrite count=2097152 offset=0
8b1478
nbdkit: file[1]: debug: pwrite count=2097152 offset=2097152
8b1478
nbdkit: file[1]: debug: pwrite count=1048576 offset=4194304
8b1478
nbdkit: file[1]: debug: zero count=33554432 offset=5242880 may_trim=1
8b1478
nbdkit: file[1]: debug: zero count=13631488 offset=38797312 may_trim=1
8b1478
nbdkit: file[1]: debug: flush
8b1478
8b1478
And the file is sparse as expected:
8b1478
8b1478
$ qemu-img info dst.img
8b1478
virtual size: 50M (52428800 bytes)
8b1478
disk size: 5.0M
8b1478
8b1478
[1] http://lists.nongnu.org/archive/html/qemu-block/2019-03/msg00761.html
8b1478
8b1478
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
8b1478
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8b1478
(cherry picked from commit a3d6ae2299eaab1bced05551d0a0abfbcd9d08d0)
8b1478
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
8b1478
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8b1478
---
8b1478
 qemu-img.c | 3 ++-
8b1478
 1 file changed, 2 insertions(+), 1 deletion(-)
8b1478
8b1478
diff --git a/qemu-img.c b/qemu-img.c
8b1478
index d588183..f7c1483 100644
8b1478
--- a/qemu-img.c
8b1478
+++ b/qemu-img.c
8b1478
@@ -1738,7 +1738,8 @@ static int coroutine_fn convert_co_write(ImgConvertState *s, int64_t sector_num,
8b1478
             }
8b1478
             ret = blk_co_pwrite_zeroes(s->target,
8b1478
                                        sector_num << BDRV_SECTOR_BITS,
8b1478
-                                       n << BDRV_SECTOR_BITS, 0);
8b1478
+                                       n << BDRV_SECTOR_BITS,
8b1478
+                                       BDRV_REQ_MAY_UNMAP);
8b1478
             if (ret < 0) {
8b1478
                 return ret;
8b1478
             }
8b1478
-- 
8b1478
1.8.3.1
8b1478