|
|
7711c0 |
From 1787cd88f968426a3f8a447408ed03f7778dc18a Mon Sep 17 00:00:00 2001
|
|
|
7711c0 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
7711c0 |
Date: Fri, 15 Mar 2019 18:10:06 +0100
|
|
|
7711c0 |
Subject: [PATCH 010/163] file-posix: Factor out raw_reconfigure_getfd()
|
|
|
7711c0 |
|
|
|
7711c0 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
7711c0 |
Message-id: <20190315181010.14964-11-kwolf@redhat.com>
|
|
|
7711c0 |
Patchwork-id: 84887
|
|
|
7711c0 |
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 10/14] file-posix: Factor out raw_reconfigure_getfd()
|
|
|
7711c0 |
Bugzilla: 1685989
|
|
|
7711c0 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
7711c0 |
(cherry picked from commit 5cec28702587d8dc9792f8274bfc6bb91f07d672)
|
|
|
7711c0 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
7711c0 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
---
|
|
|
7711c0 |
block/file-posix.c | 87 ++++++++++++++++++++++++++++++++----------------------
|
|
|
7711c0 |
1 file changed, 52 insertions(+), 35 deletions(-)
|
|
|
7711c0 |
|
|
|
7711c0 |
diff --git a/block/file-posix.c b/block/file-posix.c
|
|
|
7711c0 |
index 419781c..e50eb0e 100644
|
|
|
7711c0 |
--- a/block/file-posix.c
|
|
|
7711c0 |
+++ b/block/file-posix.c
|
|
|
7711c0 |
@@ -834,35 +834,24 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
|
|
|
7711c0 |
return ret;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
-static int raw_reopen_prepare(BDRVReopenState *state,
|
|
|
7711c0 |
- BlockReopenQueue *queue, Error **errp)
|
|
|
7711c0 |
+static int raw_reconfigure_getfd(BlockDriverState *bs, int flags,
|
|
|
7711c0 |
+ int *open_flags, Error **errp)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
- BDRVRawState *s;
|
|
|
7711c0 |
- BDRVRawReopenState *rs;
|
|
|
7711c0 |
- int ret = 0;
|
|
|
7711c0 |
- Error *local_err = NULL;
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- assert(state != NULL);
|
|
|
7711c0 |
- assert(state->bs != NULL);
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- s = state->bs->opaque;
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- state->opaque = g_new0(BDRVRawReopenState, 1);
|
|
|
7711c0 |
- rs = state->opaque;
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- if (s->type == FTYPE_CD) {
|
|
|
7711c0 |
- rs->open_flags |= O_NONBLOCK;
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- raw_parse_flags(state->flags, &rs->open_flags);
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- rs->fd = -1;
|
|
|
7711c0 |
-
|
|
|
7711c0 |
+ BDRVRawState *s = bs->opaque;
|
|
|
7711c0 |
+ int fd = -1;
|
|
|
7711c0 |
+ int ret;
|
|
|
7711c0 |
int fcntl_flags = O_APPEND | O_NONBLOCK;
|
|
|
7711c0 |
#ifdef O_NOATIME
|
|
|
7711c0 |
fcntl_flags |= O_NOATIME;
|
|
|
7711c0 |
#endif
|
|
|
7711c0 |
|
|
|
7711c0 |
+ *open_flags = 0;
|
|
|
7711c0 |
+ if (s->type == FTYPE_CD) {
|
|
|
7711c0 |
+ *open_flags |= O_NONBLOCK;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ raw_parse_flags(flags, open_flags);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
#ifdef O_ASYNC
|
|
|
7711c0 |
/* Not all operating systems have O_ASYNC, and those that don't
|
|
|
7711c0 |
* will not let us track the state into rs->open_flags (typically
|
|
|
7711c0 |
@@ -872,32 +861,59 @@ static int raw_reopen_prepare(BDRVReopenState *state,
|
|
|
7711c0 |
assert((s->open_flags & O_ASYNC) == 0);
|
|
|
7711c0 |
#endif
|
|
|
7711c0 |
|
|
|
7711c0 |
- if ((rs->open_flags & ~fcntl_flags) == (s->open_flags & ~fcntl_flags)) {
|
|
|
7711c0 |
+ if ((*open_flags & ~fcntl_flags) == (s->open_flags & ~fcntl_flags)) {
|
|
|
7711c0 |
/* dup the original fd */
|
|
|
7711c0 |
- rs->fd = qemu_dup(s->fd);
|
|
|
7711c0 |
- if (rs->fd >= 0) {
|
|
|
7711c0 |
- ret = fcntl_setfl(rs->fd, rs->open_flags);
|
|
|
7711c0 |
+ fd = qemu_dup(s->fd);
|
|
|
7711c0 |
+ if (fd >= 0) {
|
|
|
7711c0 |
+ ret = fcntl_setfl(fd, *open_flags);
|
|
|
7711c0 |
if (ret) {
|
|
|
7711c0 |
- qemu_close(rs->fd);
|
|
|
7711c0 |
- rs->fd = -1;
|
|
|
7711c0 |
+ qemu_close(fd);
|
|
|
7711c0 |
+ fd = -1;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
}
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
/* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */
|
|
|
7711c0 |
- if (rs->fd == -1) {
|
|
|
7711c0 |
- const char *normalized_filename = state->bs->filename;
|
|
|
7711c0 |
+ if (fd == -1) {
|
|
|
7711c0 |
+ const char *normalized_filename = bs->filename;
|
|
|
7711c0 |
ret = raw_normalize_devicepath(&normalized_filename, errp);
|
|
|
7711c0 |
if (ret >= 0) {
|
|
|
7711c0 |
- assert(!(rs->open_flags & O_CREAT));
|
|
|
7711c0 |
- rs->fd = qemu_open(normalized_filename, rs->open_flags);
|
|
|
7711c0 |
- if (rs->fd == -1) {
|
|
|
7711c0 |
+ assert(!(*open_flags & O_CREAT));
|
|
|
7711c0 |
+ fd = qemu_open(normalized_filename, *open_flags);
|
|
|
7711c0 |
+ if (fd == -1) {
|
|
|
7711c0 |
error_setg_errno(errp, errno, "Could not reopen file");
|
|
|
7711c0 |
- ret = -1;
|
|
|
7711c0 |
+ return -1;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
}
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
+ return fd;
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+static int raw_reopen_prepare(BDRVReopenState *state,
|
|
|
7711c0 |
+ BlockReopenQueue *queue, Error **errp)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ BDRVRawState *s;
|
|
|
7711c0 |
+ BDRVRawReopenState *rs;
|
|
|
7711c0 |
+ int ret = 0;
|
|
|
7711c0 |
+ Error *local_err = NULL;
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ assert(state != NULL);
|
|
|
7711c0 |
+ assert(state->bs != NULL);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ s = state->bs->opaque;
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ state->opaque = g_new0(BDRVRawReopenState, 1);
|
|
|
7711c0 |
+ rs = state->opaque;
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ rs->fd = raw_reconfigure_getfd(state->bs, state->flags, &rs->open_flags,
|
|
|
7711c0 |
+ &local_err);
|
|
|
7711c0 |
+ if (local_err) {
|
|
|
7711c0 |
+ error_propagate(errp, local_err);
|
|
|
7711c0 |
+ ret = -1;
|
|
|
7711c0 |
+ goto out;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+
|
|
|
7711c0 |
/* Fail already reopen_prepare() if we can't get a working O_DIRECT
|
|
|
7711c0 |
* alignment with the new fd. */
|
|
|
7711c0 |
if (rs->fd != -1) {
|
|
|
7711c0 |
@@ -910,6 +926,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,
|
|
|
7711c0 |
}
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
+out:
|
|
|
7711c0 |
return ret;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
--
|
|
|
7711c0 |
1.8.3.1
|
|
|
7711c0 |
|