b38b0f
From 87240c5fcfb3e3ba68c5c87d2175f2dd98921a7e Mon Sep 17 00:00:00 2001
b38b0f
From: Max Reitz <mreitz@redhat.com>
b38b0f
Date: Wed, 3 Apr 2019 17:13:15 +0100
b38b0f
Subject: [PATCH 08/11] block/file-posix: do not fail on unlock bytes
b38b0f
b38b0f
RH-Author: Max Reitz <mreitz@redhat.com>
b38b0f
Message-id: <20190403171315.20841-9-mreitz@redhat.com>
b38b0f
Patchwork-id: 85406
b38b0f
O-Subject: [RHEL-8.1 qemu-kvm PATCH 8/8] block/file-posix: do not fail on unlock bytes
b38b0f
Bugzilla: 1694148
b38b0f
RH-Acked-by: John Snow <jsnow@redhat.com>
b38b0f
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
b38b0f
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
b38b0f
b38b0f
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
b38b0f
b38b0f
bdrv_replace_child() calls bdrv_check_perm() with error_abort on
b38b0f
loosening permissions. However file-locking operations may fail even
b38b0f
in this case, for example on NFS. And this leads to Qemu crash.
b38b0f
b38b0f
Let's avoid such errors. Note, that we ignore such things anyway on
b38b0f
permission update commit and abort.
b38b0f
b38b0f
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
b38b0f
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
b38b0f
(cherry picked from commit 696aaaed579ac5bf5fa336216909b46d3d8f07a8)
b38b0f
Signed-off-by: Max Reitz <mreitz@redhat.com>
b38b0f
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
b38b0f
---
b38b0f
 block/file-posix.c | 12 ++++++++++++
b38b0f
 1 file changed, 12 insertions(+)
b38b0f
b38b0f
diff --git a/block/file-posix.c b/block/file-posix.c
b38b0f
index deecf58..5fb5a9a 100644
b38b0f
--- a/block/file-posix.c
b38b0f
+++ b/block/file-posix.c
b38b0f
@@ -800,6 +800,18 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
b38b0f
 
b38b0f
     switch (op) {
b38b0f
     case RAW_PL_PREPARE:
b38b0f
+        if ((s->perm | new_perm) == s->perm &&
b38b0f
+            (s->shared_perm & new_shared) == s->shared_perm)
b38b0f
+        {
b38b0f
+            /*
b38b0f
+             * We are going to unlock bytes, it should not fail. If it fail due
b38b0f
+             * to some fs-dependent permission-unrelated reasons (which occurs
b38b0f
+             * sometimes on NFS and leads to abort in bdrv_replace_child) we
b38b0f
+             * can't prevent such errors by any check here. And we ignore them
b38b0f
+             * anyway in ABORT and COMMIT.
b38b0f
+             */
b38b0f
+            return 0;
b38b0f
+        }
b38b0f
         ret = raw_apply_lock_bytes(s, s->fd, s->perm | new_perm,
b38b0f
                                    ~s->shared_perm | ~new_shared,
b38b0f
                                    false, errp);
b38b0f
-- 
b38b0f
1.8.3.1
b38b0f