|
Pablo Greco |
e6a3ae |
From 47a21881507f1bba1cf2fbabb0f8efce57ee7fb9 Mon Sep 17 00:00:00 2001
|
|
Pablo Greco |
e6a3ae |
From: Max Reitz <mreitz@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Date: Wed, 3 Apr 2019 17:13:11 +0100
|
|
Pablo Greco |
e6a3ae |
Subject: [PATCH 04/11] file-posix: Drop s->lock_fd
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Message-id: <20190403171315.20841-5-mreitz@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Patchwork-id: 85403
|
|
Pablo Greco |
e6a3ae |
O-Subject: [RHEL-8.1 qemu-kvm PATCH 4/8] file-posix: Drop s->lock_fd
|
|
Pablo Greco |
e6a3ae |
Bugzilla: 1694148
|
|
Pablo Greco |
e6a3ae |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
Pablo Greco |
e6a3ae |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
Pablo Greco |
e6a3ae |
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
From: Fam Zheng <famz@redhat.com>
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
The lock_fd field is not strictly necessary because transferring locked
|
|
Pablo Greco |
e6a3ae |
bytes from old fd to the new one shouldn't fail anyway. This spares the
|
|
Pablo Greco |
e6a3ae |
user one fd per image.
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
Pablo Greco |
e6a3ae |
(cherry picked from commit f2e3af29b70624659a50903bd075e1663b64c9da)
|
|
Pablo Greco |
e6a3ae |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
Pablo Greco |
e6a3ae |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
Pablo Greco |
e6a3ae |
---
|
|
Pablo Greco |
e6a3ae |
block/file-posix.c | 37 +++++++++++++------------------------
|
|
Pablo Greco |
e6a3ae |
1 file changed, 13 insertions(+), 24 deletions(-)
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
diff --git a/block/file-posix.c b/block/file-posix.c
|
|
Pablo Greco |
e6a3ae |
index 2a05193..97e7ff2 100644
|
|
Pablo Greco |
e6a3ae |
--- a/block/file-posix.c
|
|
Pablo Greco |
e6a3ae |
+++ b/block/file-posix.c
|
|
Pablo Greco |
e6a3ae |
@@ -142,7 +142,6 @@ do { \
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
typedef struct BDRVRawState {
|
|
Pablo Greco |
e6a3ae |
int fd;
|
|
Pablo Greco |
e6a3ae |
- int lock_fd;
|
|
Pablo Greco |
e6a3ae |
bool use_lock;
|
|
Pablo Greco |
e6a3ae |
int type;
|
|
Pablo Greco |
e6a3ae |
int open_flags;
|
|
Pablo Greco |
e6a3ae |
@@ -153,7 +152,7 @@ typedef struct BDRVRawState {
|
|
Pablo Greco |
e6a3ae |
uint64_t shared_perm;
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
/* The perms bits whose corresponding bytes are already locked in
|
|
Pablo Greco |
e6a3ae |
- * s->lock_fd. */
|
|
Pablo Greco |
e6a3ae |
+ * s->fd. */
|
|
Pablo Greco |
e6a3ae |
uint64_t locked_perm;
|
|
Pablo Greco |
e6a3ae |
uint64_t locked_shared_perm;
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
@@ -545,18 +544,6 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
s->fd = fd;
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
- s->lock_fd = -1;
|
|
Pablo Greco |
e6a3ae |
- if (s->use_lock) {
|
|
Pablo Greco |
e6a3ae |
- fd = qemu_open(filename, s->open_flags);
|
|
Pablo Greco |
e6a3ae |
- if (fd < 0) {
|
|
Pablo Greco |
e6a3ae |
- ret = -errno;
|
|
Pablo Greco |
e6a3ae |
- error_setg_errno(errp, errno, "Could not open '%s' for locking",
|
|
Pablo Greco |
e6a3ae |
- filename);
|
|
Pablo Greco |
e6a3ae |
- qemu_close(s->fd);
|
|
Pablo Greco |
e6a3ae |
- goto fail;
|
|
Pablo Greco |
e6a3ae |
- }
|
|
Pablo Greco |
e6a3ae |
- s->lock_fd = fd;
|
|
Pablo Greco |
e6a3ae |
- }
|
|
Pablo Greco |
e6a3ae |
s->perm = 0;
|
|
Pablo Greco |
e6a3ae |
s->shared_perm = BLK_PERM_ALL;
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
@@ -811,15 +798,13 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
|
|
Pablo Greco |
e6a3ae |
return 0;
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
- assert(s->lock_fd > 0);
|
|
Pablo Greco |
e6a3ae |
-
|
|
Pablo Greco |
e6a3ae |
switch (op) {
|
|
Pablo Greco |
e6a3ae |
case RAW_PL_PREPARE:
|
|
Pablo Greco |
e6a3ae |
- ret = raw_apply_lock_bytes(s, s->lock_fd, s->perm | new_perm,
|
|
Pablo Greco |
e6a3ae |
+ ret = raw_apply_lock_bytes(s, s->fd, s->perm | new_perm,
|
|
Pablo Greco |
e6a3ae |
~s->shared_perm | ~new_shared,
|
|
Pablo Greco |
e6a3ae |
false, errp);
|
|
Pablo Greco |
e6a3ae |
if (!ret) {
|
|
Pablo Greco |
e6a3ae |
- ret = raw_check_lock_bytes(s->lock_fd, new_perm, new_shared, errp);
|
|
Pablo Greco |
e6a3ae |
+ ret = raw_check_lock_bytes(s->fd, new_perm, new_shared, errp);
|
|
Pablo Greco |
e6a3ae |
if (!ret) {
|
|
Pablo Greco |
e6a3ae |
return 0;
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
@@ -830,7 +815,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
|
|
Pablo Greco |
e6a3ae |
op = RAW_PL_ABORT;
|
|
Pablo Greco |
e6a3ae |
/* fall through to unlock bytes. */
|
|
Pablo Greco |
e6a3ae |
case RAW_PL_ABORT:
|
|
Pablo Greco |
e6a3ae |
- raw_apply_lock_bytes(s, s->lock_fd, s->perm, ~s->shared_perm,
|
|
Pablo Greco |
e6a3ae |
+ raw_apply_lock_bytes(s, s->fd, s->perm, ~s->shared_perm,
|
|
Pablo Greco |
e6a3ae |
true, &local_err);
|
|
Pablo Greco |
e6a3ae |
if (local_err) {
|
|
Pablo Greco |
e6a3ae |
/* Theoretically the above call only unlocks bytes and it cannot
|
|
Pablo Greco |
e6a3ae |
@@ -840,7 +825,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
break;
|
|
Pablo Greco |
e6a3ae |
case RAW_PL_COMMIT:
|
|
Pablo Greco |
e6a3ae |
- raw_apply_lock_bytes(s, s->lock_fd, new_perm, ~new_shared,
|
|
Pablo Greco |
e6a3ae |
+ raw_apply_lock_bytes(s, s->fd, new_perm, ~new_shared,
|
|
Pablo Greco |
e6a3ae |
true, &local_err);
|
|
Pablo Greco |
e6a3ae |
if (local_err) {
|
|
Pablo Greco |
e6a3ae |
/* Theoretically the above call only unlocks bytes and it cannot
|
|
Pablo Greco |
e6a3ae |
@@ -938,9 +923,17 @@ static void raw_reopen_commit(BDRVReopenState *state)
|
|
Pablo Greco |
e6a3ae |
{
|
|
Pablo Greco |
e6a3ae |
BDRVRawReopenState *rs = state->opaque;
|
|
Pablo Greco |
e6a3ae |
BDRVRawState *s = state->bs->opaque;
|
|
Pablo Greco |
e6a3ae |
+ Error *local_err = NULL;
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
s->open_flags = rs->open_flags;
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
+ /* Copy locks to the new fd before closing the old one. */
|
|
Pablo Greco |
e6a3ae |
+ raw_apply_lock_bytes(NULL, rs->fd, s->locked_perm,
|
|
Pablo Greco |
e6a3ae |
+ ~s->locked_shared_perm, false, &local_err);
|
|
Pablo Greco |
e6a3ae |
+ if (local_err) {
|
|
Pablo Greco |
e6a3ae |
+ /* shouldn't fail in a sane host, but report it just in case. */
|
|
Pablo Greco |
e6a3ae |
+ error_report_err(local_err);
|
|
Pablo Greco |
e6a3ae |
+ }
|
|
Pablo Greco |
e6a3ae |
qemu_close(s->fd);
|
|
Pablo Greco |
e6a3ae |
s->fd = rs->fd;
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
@@ -1903,10 +1896,6 @@ static void raw_close(BlockDriverState *bs)
|
|
Pablo Greco |
e6a3ae |
qemu_close(s->fd);
|
|
Pablo Greco |
e6a3ae |
s->fd = -1;
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
- if (s->lock_fd >= 0) {
|
|
Pablo Greco |
e6a3ae |
- qemu_close(s->lock_fd);
|
|
Pablo Greco |
e6a3ae |
- s->lock_fd = -1;
|
|
Pablo Greco |
e6a3ae |
- }
|
|
Pablo Greco |
e6a3ae |
}
|
|
Pablo Greco |
e6a3ae |
|
|
Pablo Greco |
e6a3ae |
/**
|
|
Pablo Greco |
e6a3ae |
--
|
|
Pablo Greco |
e6a3ae |
1.8.3.1
|
|
Pablo Greco |
e6a3ae |
|