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