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