Blame SOURCES/kvm-file-posix-Unlock-FD-after-creation.patch

357786
From 1375d18f600b29111c7d8e6e5a2c73d01afe994b Mon Sep 17 00:00:00 2001
357786
From: Max Reitz <mreitz@redhat.com>
357786
Date: Mon, 9 Jul 2018 15:11:22 +0200
357786
Subject: [PATCH 30/89] file-posix: Unlock FD after creation
357786
357786
RH-Author: Max Reitz <mreitz@redhat.com>
357786
Message-id: <20180709151122.27541-3-mreitz@redhat.com>
357786
Patchwork-id: 81269
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 2/2] file-posix: Unlock FD after creation
357786
Bugzilla: 1599335
357786
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
357786
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
357786
RH-Acked-by: John Snow <jsnow@redhat.com>
357786
357786
Closing the FD does not necessarily mean that it is unlocked.  Fix this
357786
by relinquishing all permission locks before qemu_close().
357786
357786
Reported-by: Kevin Wolf <kwolf@redhat.com>
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
357786
(cherry picked from commit 7c20c808a5cbf5d244735bc78fc3138c739c1946)
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 block/file-posix.c | 17 ++++++++++++++---
357786
 1 file changed, 14 insertions(+), 3 deletions(-)
357786
357786
diff --git a/block/file-posix.c b/block/file-posix.c
357786
index e876770..cbf7c11 100644
357786
--- a/block/file-posix.c
357786
+++ b/block/file-posix.c
357786
@@ -2051,6 +2051,7 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
357786
 static int raw_co_create(BlockdevCreateOptions *options, Error **errp)
357786
 {
357786
     BlockdevCreateOptionsFile *file_opts;
357786
+    Error *local_err = NULL;
357786
     int fd;
357786
     uint64_t perm, shared;
357786
     int result = 0;
357786
@@ -2096,13 +2097,13 @@ static int raw_co_create(BlockdevCreateOptions *options, Error **errp)
357786
     /* Step two: Check that nobody else has taken conflicting locks */
357786
     result = raw_check_lock_bytes(fd, perm, shared, errp);
357786
     if (result < 0) {
357786
-        goto out_close;
357786
+        goto out_unlock;
357786
     }
357786
 
357786
     /* Clear the file by truncating it to 0 */
357786
     result = raw_regular_truncate(fd, 0, PREALLOC_MODE_OFF, errp);
357786
     if (result < 0) {
357786
-        goto out_close;
357786
+        goto out_unlock;
357786
     }
357786
 
357786
     if (file_opts->nocow) {
357786
@@ -2125,7 +2126,17 @@ static int raw_co_create(BlockdevCreateOptions *options, Error **errp)
357786
     result = raw_regular_truncate(fd, file_opts->size, file_opts->preallocation,
357786
                                   errp);
357786
     if (result < 0) {
357786
-        goto out_close;
357786
+        goto out_unlock;
357786
+    }
357786
+
357786
+out_unlock:
357786
+    raw_apply_lock_bytes(fd, 0, 0, true, &local_err);
357786
+    if (local_err) {
357786
+        /* The above call should not fail, and if it does, that does
357786
+         * not mean the whole creation operation has failed.  So
357786
+         * report it the user for their convenience, but do not report
357786
+         * it to the caller. */
357786
+        error_report_err(local_err);
357786
     }
357786
 
357786
 out_close:
357786
-- 
357786
1.8.3.1
357786