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

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