|
|
6e7d01 |
From c02ebc7e43f55b9423a065a7c53ba72bdb821c98 Mon Sep 17 00:00:00 2001
|
|
|
6e7d01 |
From: Jon Maloy <jmaloy@redhat.com>
|
|
|
6e7d01 |
Date: Tue, 9 Feb 2021 23:14:54 -0500
|
|
|
6e7d01 |
Subject: [PATCH 1/3] virtiofsd: extract lo_do_open() from lo_open()
|
|
|
6e7d01 |
|
|
|
6e7d01 |
RH-Author: Jon Maloy <jmaloy@redhat.com>
|
|
|
6e7d01 |
Message-id: <20210209231456.1555472-2-jmaloy@redhat.com>
|
|
|
6e7d01 |
Patchwork-id: 101024
|
|
|
6e7d01 |
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 1/3] virtiofsd: extract lo_do_open() from lo_open()
|
|
|
6e7d01 |
Bugzilla: 1919111
|
|
|
6e7d01 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
6e7d01 |
RH-Acked-by: Greg Kurz <gkurz@redhat.com>
|
|
|
6e7d01 |
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
6e7d01 |
|
|
|
6e7d01 |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
6e7d01 |
|
|
|
6e7d01 |
Both lo_open() and lo_create() have similar code to open a file. Extract
|
|
|
6e7d01 |
a common lo_do_open() function from lo_open() that will be used by
|
|
|
6e7d01 |
lo_create() in a later commit.
|
|
|
6e7d01 |
|
|
|
6e7d01 |
Since lo_do_open() does not otherwise need fuse_req_t req, convert
|
|
|
6e7d01 |
lo_add_fd_mapping() to use struct lo_data *lo instead.
|
|
|
6e7d01 |
|
|
|
6e7d01 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
6e7d01 |
Message-Id: <20210204150208.367837-2-stefanha@redhat.com>
|
|
|
6e7d01 |
Reviewed-by: Greg Kurz <groug@kaod.org>
|
|
|
6e7d01 |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
6e7d01 |
|
|
|
6e7d01 |
(cherry-picked from commit 8afaaee976965b7fb90ec225a51d60f35c5f173c)
|
|
|
6e7d01 |
|
|
|
6e7d01 |
Conflict: update_open_flags() takes fewer arguments in this version
|
|
|
6e7d01 |
than in upstream. Instead of applying commit e12a0edafeb
|
|
|
6e7d01 |
("virtiofsd: Add -o allow_direct_io|no_allow_direct_io
|
|
|
6e7d01 |
options") we keep the old signature, since this seems to
|
|
|
6e7d01 |
be an unrelated change.
|
|
|
6e7d01 |
|
|
|
6e7d01 |
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
|
|
|
6e7d01 |
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
|
|
|
6e7d01 |
---
|
|
|
6e7d01 |
tools/virtiofsd/passthrough_ll.c | 73 ++++++++++++++++++++------------
|
|
|
6e7d01 |
1 file changed, 46 insertions(+), 27 deletions(-)
|
|
|
6e7d01 |
|
|
|
6e7d01 |
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
|
|
|
6e7d01 |
index f41a6b07c8..518ba11c47 100644
|
|
|
6e7d01 |
--- a/tools/virtiofsd/passthrough_ll.c
|
|
|
6e7d01 |
+++ b/tools/virtiofsd/passthrough_ll.c
|
|
|
6e7d01 |
@@ -439,17 +439,17 @@ static void lo_map_remove(struct lo_map *map, size_t key)
|
|
|
6e7d01 |
}
|
|
|
6e7d01 |
|
|
|
6e7d01 |
/* Assumes lo->mutex is held */
|
|
|
6e7d01 |
-static ssize_t lo_add_fd_mapping(fuse_req_t req, int fd)
|
|
|
6e7d01 |
+static ssize_t lo_add_fd_mapping(struct lo_data *lo, int fd)
|
|
|
6e7d01 |
{
|
|
|
6e7d01 |
struct lo_map_elem *elem;
|
|
|
6e7d01 |
|
|
|
6e7d01 |
- elem = lo_map_alloc_elem(&lo_data(req)->fd_map);
|
|
|
6e7d01 |
+ elem = lo_map_alloc_elem(&lo->fd_map);
|
|
|
6e7d01 |
if (!elem) {
|
|
|
6e7d01 |
return -1;
|
|
|
6e7d01 |
}
|
|
|
6e7d01 |
|
|
|
6e7d01 |
elem->fd = fd;
|
|
|
6e7d01 |
- return elem - lo_data(req)->fd_map.elems;
|
|
|
6e7d01 |
+ return elem - lo->fd_map.elems;
|
|
|
6e7d01 |
}
|
|
|
6e7d01 |
|
|
|
6e7d01 |
/* Assumes lo->mutex is held */
|
|
|
6e7d01 |
@@ -1712,6 +1712,38 @@ static void update_open_flags(int writeback, struct fuse_file_info *fi)
|
|
|
6e7d01 |
fi->flags &= ~O_DIRECT;
|
|
|
6e7d01 |
}
|
|
|
6e7d01 |
|
|
|
6e7d01 |
+static int lo_do_open(struct lo_data *lo, struct lo_inode *inode,
|
|
|
6e7d01 |
+ struct fuse_file_info *fi)
|
|
|
6e7d01 |
+{
|
|
|
6e7d01 |
+ char buf[64];
|
|
|
6e7d01 |
+ ssize_t fh;
|
|
|
6e7d01 |
+ int fd;
|
|
|
6e7d01 |
+
|
|
|
6e7d01 |
+ update_open_flags(lo->writeback, fi);
|
|
|
6e7d01 |
+
|
|
|
6e7d01 |
+ sprintf(buf, "%i", inode->fd);
|
|
|
6e7d01 |
+ fd = openat(lo->proc_self_fd, buf, fi->flags & ~O_NOFOLLOW);
|
|
|
6e7d01 |
+ if (fd == -1) {
|
|
|
6e7d01 |
+ return errno;
|
|
|
6e7d01 |
+ }
|
|
|
6e7d01 |
+
|
|
|
6e7d01 |
+ pthread_mutex_lock(&lo->mutex);
|
|
|
6e7d01 |
+ fh = lo_add_fd_mapping(lo, fd);
|
|
|
6e7d01 |
+ pthread_mutex_unlock(&lo->mutex);
|
|
|
6e7d01 |
+ if (fh == -1) {
|
|
|
6e7d01 |
+ close(fd);
|
|
|
6e7d01 |
+ return ENOMEM;
|
|
|
6e7d01 |
+ }
|
|
|
6e7d01 |
+
|
|
|
6e7d01 |
+ fi->fh = fh;
|
|
|
6e7d01 |
+ if (lo->cache == CACHE_NONE) {
|
|
|
6e7d01 |
+ fi->direct_io = 1;
|
|
|
6e7d01 |
+ } else if (lo->cache == CACHE_ALWAYS) {
|
|
|
6e7d01 |
+ fi->keep_cache = 1;
|
|
|
6e7d01 |
+ }
|
|
|
6e7d01 |
+ return 0;
|
|
|
6e7d01 |
+}
|
|
|
6e7d01 |
+
|
|
|
6e7d01 |
static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
6e7d01 |
mode_t mode, struct fuse_file_info *fi)
|
|
|
6e7d01 |
{
|
|
|
6e7d01 |
@@ -1752,7 +1784,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
6e7d01 |
ssize_t fh;
|
|
|
6e7d01 |
|
|
|
6e7d01 |
pthread_mutex_lock(&lo->mutex);
|
|
|
6e7d01 |
- fh = lo_add_fd_mapping(req, fd);
|
|
|
6e7d01 |
+ fh = lo_add_fd_mapping(lo, fd);
|
|
|
6e7d01 |
pthread_mutex_unlock(&lo->mutex);
|
|
|
6e7d01 |
if (fh == -1) {
|
|
|
6e7d01 |
close(fd);
|
|
|
6e7d01 |
@@ -1943,38 +1975,25 @@ static void lo_fsyncdir(fuse_req_t req, fuse_ino_t ino, int datasync,
|
|
|
6e7d01 |
|
|
|
6e7d01 |
static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
|
|
|
6e7d01 |
{
|
|
|
6e7d01 |
- int fd;
|
|
|
6e7d01 |
- ssize_t fh;
|
|
|
6e7d01 |
- char buf[64];
|
|
|
6e7d01 |
struct lo_data *lo = lo_data(req);
|
|
|
6e7d01 |
+ struct lo_inode *inode = lo_inode(req, ino);
|
|
|
6e7d01 |
+ int err;
|
|
|
6e7d01 |
|
|
|
6e7d01 |
fuse_log(FUSE_LOG_DEBUG, "lo_open(ino=%" PRIu64 ", flags=%d)\n", ino,
|
|
|
6e7d01 |
fi->flags);
|
|
|
6e7d01 |
|
|
|
6e7d01 |
- update_open_flags(lo->writeback, fi);
|
|
|
6e7d01 |
-
|
|
|
6e7d01 |
- sprintf(buf, "%i", lo_fd(req, ino));
|
|
|
6e7d01 |
- fd = openat(lo->proc_self_fd, buf, fi->flags & ~O_NOFOLLOW);
|
|
|
6e7d01 |
- if (fd == -1) {
|
|
|
6e7d01 |
- return (void)fuse_reply_err(req, errno);
|
|
|
6e7d01 |
- }
|
|
|
6e7d01 |
-
|
|
|
6e7d01 |
- pthread_mutex_lock(&lo->mutex);
|
|
|
6e7d01 |
- fh = lo_add_fd_mapping(req, fd);
|
|
|
6e7d01 |
- pthread_mutex_unlock(&lo->mutex);
|
|
|
6e7d01 |
- if (fh == -1) {
|
|
|
6e7d01 |
- close(fd);
|
|
|
6e7d01 |
- fuse_reply_err(req, ENOMEM);
|
|
|
6e7d01 |
+ if (!inode) {
|
|
|
6e7d01 |
+ fuse_reply_err(req, EBADF);
|
|
|
6e7d01 |
return;
|
|
|
6e7d01 |
}
|
|
|
6e7d01 |
|
|
|
6e7d01 |
- fi->fh = fh;
|
|
|
6e7d01 |
- if (lo->cache == CACHE_NONE) {
|
|
|
6e7d01 |
- fi->direct_io = 1;
|
|
|
6e7d01 |
- } else if (lo->cache == CACHE_ALWAYS) {
|
|
|
6e7d01 |
- fi->keep_cache = 1;
|
|
|
6e7d01 |
+ err = lo_do_open(lo, inode, fi);
|
|
|
6e7d01 |
+ lo_inode_put(lo, &inode;;
|
|
|
6e7d01 |
+ if (err) {
|
|
|
6e7d01 |
+ fuse_reply_err(req, err);
|
|
|
6e7d01 |
+ } else {
|
|
|
6e7d01 |
+ fuse_reply_open(req, fi);
|
|
|
6e7d01 |
}
|
|
|
6e7d01 |
- fuse_reply_open(req, fi);
|
|
|
6e7d01 |
}
|
|
|
6e7d01 |
|
|
|
6e7d01 |
static void lo_release(fuse_req_t req, fuse_ino_t ino,
|
|
|
6e7d01 |
--
|
|
|
6e7d01 |
2.18.2
|
|
|
6e7d01 |
|