From: Dion Bosschieter <dionbosschieter@gmail.com>
To: qemu-devel@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com,
Dion Bosschieter <dionbosschieter@gmail.com>
Subject: [Qemu-devel] [PATCH 1/1] block/file-posix.c: fix not reopened lock file descriptor
Date: Thu, 22 Mar 2018 18:20:53 +0100 [thread overview]
Message-ID: <20180322172053.7343-1-dionbosschieter@gmail.com> (raw)
In commit 244a5668106297378391b768e7288eb157616f64 another
file descriptor to BDRVRawState is added. When we try to issue the
reopen command only s->fd is reopened; lock_fd could still hold an old
file descriptor "possibly" pointing to another file.
- change raw_reopen_prepare so it checks use_lock from BDRVRawState and
tries to reopen lock_fd accordingly
- change raw_reopen_commit so it closes the old lock_fd on use_lock
Signed-off-by: Dion Bosschieter <dionbosschieter@gmail.com>
---
block/file-posix.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/block/file-posix.c b/block/file-posix.c
index d7fb772c14..16d83fc49e 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -167,6 +167,7 @@ typedef struct BDRVRawState {
typedef struct BDRVRawReopenState {
int fd;
+ int lock_fd;
int open_flags;
} BDRVRawReopenState;
@@ -795,6 +796,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,
raw_parse_flags(state->flags, &rs->open_flags);
rs->fd = -1;
+ rs->lock_fd = -1;
int fcntl_flags = O_APPEND | O_NONBLOCK;
#ifdef O_NOATIME
@@ -820,6 +822,17 @@ static int raw_reopen_prepare(BDRVReopenState *state,
rs->fd = -1;
}
}
+
+ if (s->use_lock) {
+ rs->lock_fd = qemu_dup(s->lock_fd);
+ if (rs->lock_fd >= 0) {
+ ret = fcntl_setfl(rs->lock_fd, rs->open_flags);
+ if (ret) {
+ qemu_close(rs->lock_fd);
+ rs->lock_fd = -1;
+ }
+ }
+ }
}
/* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */
@@ -835,6 +848,14 @@ static int raw_reopen_prepare(BDRVReopenState *state,
error_setg_errno(errp, errno, "Could not reopen file");
ret = -1;
}
+
+ if (s->use_lock) {
+ rs->lock_fd = qemu_open(normalized_filename, rs->open_flags);
+ if (rs->lock_fd == -1) {
+ error_setg_errno(errp, errno, "Could not reopen file for locking");
+ ret = -1;
+ }
+ }
}
}
@@ -861,7 +882,11 @@ static void raw_reopen_commit(BDRVReopenState *state)
s->open_flags = rs->open_flags;
qemu_close(s->fd);
+ if (s->use_lock) {
+ qemu_close(s->lock_fd);
+ }
s->fd = rs->fd;
+ s->lock_fd = rs->lock_fd;
g_free(state->opaque);
state->opaque = NULL;
--
2.14.2
next reply other threads:[~2018-03-22 17:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-22 17:20 Dion Bosschieter [this message]
2018-03-22 17:39 ` [Qemu-devel] [PATCH 1/1] block/file-posix.c: fix not reopened lock file descriptor Kevin Wolf
2018-03-22 18:08 ` Dion Bosschieter
2018-03-30 6:48 ` Fam Zheng
2018-03-30 6:47 ` Fam Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180322172053.7343-1-dionbosschieter@gmail.com \
--to=dionbosschieter@gmail.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).