Blame SOURCES/kvm-block-file-posix-Fix-problem-with-fallocate-PUNCH_HO.patch

f7c9e9
From 8c339c3535728179acc94deb5b922aebcfac9ab6 Mon Sep 17 00:00:00 2001
f7c9e9
From: Thomas Huth <thuth@redhat.com>
f7c9e9
Date: Thu, 3 Jun 2021 16:13:34 -0400
f7c9e9
Subject: [PATCH 2/4] block/file-posix: Fix problem with fallocate(PUNCH_HOLE)
f7c9e9
 on GPFS
f7c9e9
f7c9e9
RH-Author: Thomas Huth <thuth@redhat.com>
f7c9e9
Message-id: <20210603161334.607005-2-thuth@redhat.com>
f7c9e9
Patchwork-id: 101673
f7c9e9
O-Subject: [RHEL-8.5.0 qemu-kvm PATCH 1/1] block/file-posix: Fix problem with fallocate(PUNCH_HOLE) on GPFS
f7c9e9
Bugzilla: 1944861
f7c9e9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
f7c9e9
RH-Acked-by: Max Reitz <mreitz@redhat.com>
f7c9e9
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
f7c9e9
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
f7c9e9
f7c9e9
A customer reported that running
f7c9e9
f7c9e9
 qemu-img convert -t none -O qcow2 -f qcow2 input.qcow2 output.qcow2
f7c9e9
f7c9e9
fails for them with the following error message when the images are
f7c9e9
stored on a GPFS file system :
f7c9e9
f7c9e9
 qemu-img: error while writing sector 0: Invalid argument
f7c9e9
f7c9e9
After analyzing the strace output, it seems like the problem is in
f7c9e9
handle_aiocb_write_zeroes(): The call to fallocate(FALLOC_FL_PUNCH_HOLE)
f7c9e9
returns EINVAL, which can apparently happen if the file system has
f7c9e9
a different idea of the granularity of the operation. It's arguably
f7c9e9
a bug in GPFS, since the PUNCH_HOLE mode should not result in EINVAL
f7c9e9
according to the man-page of fallocate(), but the file system is out
f7c9e9
there in production and so we have to deal with it. In commit 294682cc3a
f7c9e9
("block: workaround for unaligned byte range in fallocate()") we also
f7c9e9
already applied the a work-around for the same problem to the earlier
f7c9e9
fallocate(FALLOC_FL_ZERO_RANGE) call, so do it now similar with the
f7c9e9
PUNCH_HOLE call. But instead of silently catching and returning
f7c9e9
-ENOTSUP (which causes the caller to fall back to writing zeroes),
f7c9e9
let's rather inform the user once about the buggy file system and
f7c9e9
try the other fallback instead.
f7c9e9
f7c9e9
Signed-off-by: Thomas Huth <thuth@redhat.com>
f7c9e9
Message-Id: <20210527172020.847617-2-thuth@redhat.com>
f7c9e9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
f7c9e9
(cherry picked from commit 73ebf29729d1a40feaa9f8ab8951b6ee6dbfbede)
f7c9e9
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1944861
f7c9e9
Signed-off-by: Thomas Huth <thuth@redhat.com>
f7c9e9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
f7c9e9
---
f7c9e9
 block/file-posix.c | 11 +++++++++++
f7c9e9
 1 file changed, 11 insertions(+)
f7c9e9
f7c9e9
diff --git a/block/file-posix.c b/block/file-posix.c
f7c9e9
index 62a463229f..371572f1b0 100644
f7c9e9
--- a/block/file-posix.c
f7c9e9
+++ b/block/file-posix.c
f7c9e9
@@ -1587,6 +1587,17 @@ static int handle_aiocb_write_zeroes(void *opaque)
f7c9e9
                 return ret;
f7c9e9
             }
f7c9e9
             s->has_fallocate = false;
f7c9e9
+        } else if (ret == -EINVAL) {
f7c9e9
+            /*
f7c9e9
+             * Some file systems like older versions of GPFS do not like un-
f7c9e9
+             * aligned byte ranges, and return EINVAL in such a case, though
f7c9e9
+             * they should not do it according to the man-page of fallocate().
f7c9e9
+             * Warn about the bad filesystem and try the final fallback instead.
f7c9e9
+             */
f7c9e9
+            warn_report_once("Your file system is misbehaving: "
f7c9e9
+                             "fallocate(FALLOC_FL_PUNCH_HOLE) returned EINVAL. "
f7c9e9
+                             "Please report this bug to your file sytem "
f7c9e9
+                             "vendor.");
f7c9e9
         } else if (ret != -ENOTSUP) {
f7c9e9
             return ret;
f7c9e9
         } else {
f7c9e9
-- 
f7c9e9
2.27.0
f7c9e9