[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/14] file-posix: Drop s->lock_fd
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 07/14] file-posix: Drop s->lock_fd |
Date: |
Mon, 12 Nov 2018 18:05:56 +0100 |
From: Fam Zheng <address@hidden>
The lock_fd field is not strictly necessary because transferring locked
bytes from old fd to the new one shouldn't fail anyway. This spares the
user one fd per image.
Signed-off-by: Fam Zheng <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/file-posix.c | 37 +++++++++++++------------------------
1 file changed, 13 insertions(+), 24 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 1b4ff8de00..58c86a01ea 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -142,7 +142,6 @@ do { \
typedef struct BDRVRawState {
int fd;
- int lock_fd;
bool use_lock;
int type;
int open_flags;
@@ -153,7 +152,7 @@ typedef struct BDRVRawState {
uint64_t shared_perm;
/* The perms bits whose corresponding bytes are already locked in
- * s->lock_fd. */
+ * s->fd. */
uint64_t locked_perm;
uint64_t locked_shared_perm;
@@ -551,18 +550,6 @@ static int raw_open_common(BlockDriverState *bs, QDict
*options,
}
s->fd = fd;
- s->lock_fd = -1;
- if (s->use_lock) {
- fd = qemu_open(filename, s->open_flags);
- if (fd < 0) {
- ret = -errno;
- error_setg_errno(errp, errno, "Could not open '%s' for locking",
- filename);
- qemu_close(s->fd);
- goto fail;
- }
- s->lock_fd = fd;
- }
s->perm = 0;
s->shared_perm = BLK_PERM_ALL;
@@ -823,15 +810,13 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
return 0;
}
- assert(s->lock_fd > 0);
-
switch (op) {
case RAW_PL_PREPARE:
- ret = raw_apply_lock_bytes(s, s->lock_fd, s->perm | new_perm,
+ ret = raw_apply_lock_bytes(s, s->fd, s->perm | new_perm,
~s->shared_perm | ~new_shared,
false, errp);
if (!ret) {
- ret = raw_check_lock_bytes(s->lock_fd, new_perm, new_shared, errp);
+ ret = raw_check_lock_bytes(s->fd, new_perm, new_shared, errp);
if (!ret) {
return 0;
}
@@ -842,7 +827,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
op = RAW_PL_ABORT;
/* fall through to unlock bytes. */
case RAW_PL_ABORT:
- raw_apply_lock_bytes(s, s->lock_fd, s->perm, ~s->shared_perm,
+ raw_apply_lock_bytes(s, s->fd, s->perm, ~s->shared_perm,
true, &local_err);
if (local_err) {
/* Theoretically the above call only unlocks bytes and it cannot
@@ -852,7 +837,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
}
break;
case RAW_PL_COMMIT:
- raw_apply_lock_bytes(s, s->lock_fd, new_perm, ~new_shared,
+ raw_apply_lock_bytes(s, s->fd, new_perm, ~new_shared,
true, &local_err);
if (local_err) {
/* Theoretically the above call only unlocks bytes and it cannot
@@ -967,10 +952,18 @@ static void raw_reopen_commit(BDRVReopenState *state)
{
BDRVRawReopenState *rs = state->opaque;
BDRVRawState *s = state->bs->opaque;
+ Error *local_err = NULL;
s->check_cache_dropped = rs->check_cache_dropped;
s->open_flags = rs->open_flags;
+ /* Copy locks to the new fd before closing the old one. */
+ raw_apply_lock_bytes(NULL, rs->fd, s->locked_perm,
+ ~s->locked_shared_perm, false, &local_err);
+ if (local_err) {
+ /* shouldn't fail in a sane host, but report it just in case. */
+ error_report_err(local_err);
+ }
qemu_close(s->fd);
s->fd = rs->fd;
@@ -1963,10 +1956,6 @@ static void raw_close(BlockDriverState *bs)
qemu_close(s->fd);
s->fd = -1;
}
- if (s->lock_fd >= 0) {
- qemu_close(s->lock_fd);
- s->lock_fd = -1;
- }
}
/**
--
2.19.1
- [Qemu-devel] [PULL 03/14] blockdev: Consistently use snapshot_node_name in external_snapshot_prepare(), (continued)
- [Qemu-devel] [PULL 03/14] blockdev: Consistently use snapshot_node_name in external_snapshot_prepare(), Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 02/14] blockdev: handle error on block latency histogram set error, Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 04/14] nvme: don't unref ctrl_mem when device unrealized, Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 05/14] nvme: free cmbuf in nvme_exit, Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 06/14] file-posix: Skip effectiveless OFD lock operations, Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 09/14] block: Make more block drivers compile-time configurable, Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 13/14] block: Fix potential Null pointer dereferences in vvfat.c, Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 10/14] job: Fix off-by-one assert checks for JobSTT and JobVerbTable, Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 11/14] block: Null pointer dereference in blk_root_get_parent_desc(), Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 14/14] qcow2: Read outside array bounds in qcow2_pre_write_overlap_check(), Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 07/14] file-posix: Drop s->lock_fd,
Kevin Wolf <=
- [Qemu-devel] [PULL 08/14] tests: Add unit tests for image locking, Kevin Wolf, 2018/11/12
- [Qemu-devel] [PULL 12/14] qemu-img: assert block_job_get() does not return NULL in img_commit(), Kevin Wolf, 2018/11/12
- Re: [Qemu-devel] [PULL 00/14] Block layer patches, Peter Maydell, 2018/11/13