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

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