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