Blame SOURCES/kvm-file-posix-Handle-EINVAL-fallocate-return-value.patch

6e7d01
From 94d99b13b48e922861570f043490efc966b3b445 Mon Sep 17 00:00:00 2001
6e7d01
From: Kevin Wolf <kwolf@redhat.com>
6e7d01
Date: Fri, 25 Jun 2021 17:41:04 -0400
6e7d01
Subject: [PATCH 4/4] file-posix: Handle `EINVAL` fallocate return value
6e7d01
MIME-Version: 1.0
6e7d01
Content-Type: text/plain; charset=UTF-8
6e7d01
Content-Transfer-Encoding: 8bit
6e7d01
6e7d01
RH-Author: Kevin Wolf <kwolf@redhat.com>
6e7d01
Message-id: <20210625174104.44313-3-kwolf@redhat.com>
6e7d01
Patchwork-id: 101778
6e7d01
O-Subject: [RHEL-8.5.0 qemu-kvm PATCH 2/2] file-posix: Handle `EINVAL` fallocate return value
6e7d01
Bugzilla: 1970912
6e7d01
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6e7d01
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
6e7d01
RH-Acked-by: Thomas Huth <thuth@redhat.com>
6e7d01
6e7d01
From: Antoine Damhet <antoine.damhet@blade-group.com>
6e7d01
6e7d01
The `detect-zeroes=unmap` option may issue unaligned
6e7d01
`FALLOC_FL_PUNCH_HOLE` requests, raw block devices can (and will) return
6e7d01
`EINVAL`, qemu should then write the zeroes to the blockdev instead of
6e7d01
issuing an `IO_ERROR`.
6e7d01
6e7d01
The problem can be reprodced like this:
6e7d01
6e7d01
$ qemu-io -c 'write -P 0 42 1234' --image-opts driver=host_device,filename=/dev/loop0,detect-zeroes=unmap
6e7d01
write failed: Invalid argument
6e7d01
6e7d01
Signed-off-by: Antoine Damhet <antoine.damhet@blade-group.com>
6e7d01
Message-Id: <20200717135603.51180-1-antoine.damhet@blade-group.com>
6e7d01
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6e7d01
(cherry picked from commit bae127d4dcf6158c5042e2eee9582430839a9967)
6e7d01
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6e7d01
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
6e7d01
---
6e7d01
 block/file-posix.c | 6 +++++-
6e7d01
 1 file changed, 5 insertions(+), 1 deletion(-)
6e7d01
6e7d01
diff --git a/block/file-posix.c b/block/file-posix.c
6e7d01
index 837edcf027..6cd19e6c9a 100644
6e7d01
--- a/block/file-posix.c
6e7d01
+++ b/block/file-posix.c
6e7d01
@@ -1632,7 +1632,11 @@ static int handle_aiocb_write_zeroes_unmap(void *opaque)
6e7d01
 #ifdef CONFIG_FALLOCATE_PUNCH_HOLE
6e7d01
     int ret = do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
6e7d01
                            aiocb->aio_offset, aiocb->aio_nbytes);
6e7d01
-    if (ret != -ENOTSUP) {
6e7d01
+    switch (ret) {
6e7d01
+    case -ENOTSUP:
6e7d01
+    case -EINVAL:
6e7d01
+        break;
6e7d01
+    default:
6e7d01
         return ret;
6e7d01
     }
6e7d01
 #endif
6e7d01
-- 
6e7d01
2.27.0
6e7d01