fuse: improve transport and fs layer separation
Subsystems (5)
cover fuse: improve transport and fs layer separation
This series is based on fuse-update-7.1 ingit://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git#for-next
The transport layer encompasses:
- request queuing
- request timeout
- data marshaling
- device I/O
The filesystem layer handles the rest:
- VFS <-> fuse API translation
- caching
- notifications
There are misc functionalities, like tracing and control filesystem, that don't belong to either layer. Also cuse.c and virtio_fs.c still have both transport layer and fs layer parts.
To aid separation, the fields used by the transport layer are split out from struct fuse_conn and added to a new fuse_chan structure.
Transport layer internal headers:
- fuse_dev_i.h
- dev_uring_i.h
Filesystem layer internal header:
- fuse_i.h
Headers describing the API between the layers:
- dev.h
- args.h
Next up: impelement a stripped-down local-only fusex (experimental/ extended) client that can be the base of further work without risking stability of the main one.
---
Miklos Szeredi (32):
fuse: move request timeout code to a new source file
fuse: add struct fuse_chan
fuse: move fuse_iqueue to fuse_chan
fuse: move fuse_dev and fuse_pqueue to dev.c
fuse: move 'devices' member from fuse_conn to fuse_chan
fuse: move background queuing related members to fuse_chan
fuse: move request blocking related members to fuse_chan
fuse: move io_uring related members to fuse_chan
fuse: move interrupt related members to fuse_chan
fuse: split off fch->lock from fc->lock
fuse: add back pointer from fuse_chan to fuse_conn
fuse: move request timeout to fuse_chan
fuse: move struct fuse_req and related to fuse_dev_i.h
fuse: don't access transport layer structs directly from the fs layer
fuse: move forget related struct and helpers
fuse: move fuse_dev_waitq to dev.c
fuse: remove #include "fuse_i.h" from "dev_uring_i.h"
fuse: remove #include "fuse_i.h" from "req_timeout.c"
fuse: abort related layering cleanup
fuse: split off fuse_args and related definitions into a separate
header
fuse: remove fm arg of args->end callback
fuse: change req->fm to req->chan
fuse: split out filesystem part of request sending
fuse: change fud->fc to fud->chan
fuse: create poll.c
fuse: create notify.c
fuse: set params in fuse_chan_set_initialized()
fuse: remove fuse_mutex protection from fuse_dev_ioctl_sync_init()
fuse: change ring->fc to ring->chan
fuse: remove #include "fuse_i.h" from dev.c and dev_uring.c
fuse: alloc pqueue before installing fch in fuse_dev
fuse: simplify fuse_dev_ioctl_clone()
fs/fuse/Makefile | 3 +- fs/fuse/args.h | 65 +++ fs/fuse/backing.c | 1 + fs/fuse/control.c | 16 +- fs/fuse/cuse.c | 28 +- fs/fuse/dev.c | 1239 +++++++++++++++-------------------------- fs/fuse/dev.h | 110 ++++ fs/fuse/dev_uring.c | 139 +++-- fs/fuse/dev_uring_i.h | 37 +- fs/fuse/dir.c | 9 +- fs/fuse/file.c | 146 +---- fs/fuse/fuse_dev_i.h | 342 +++++++++++- fs/fuse/fuse_i.h | 412 +------------- fs/fuse/fuse_trace.h | 4 +- fs/fuse/inode.c | 255 ++------- fs/fuse/notify.c | 434 +++++++++++++++ fs/fuse/poll.c | 141 +++++ fs/fuse/req.c | 99 ++++ fs/fuse/req_timeout.c | 148 +++++ fs/fuse/sysctl.c | 1 + fs/fuse/sysctl.h | 9 + fs/fuse/virtio_fs.c | 21 +- 22 files changed, 1995 insertions(+), 1664 deletions(-) create mode 100644 fs/fuse/args.h create mode 100644 fs/fuse/dev.h create mode 100644 fs/fuse/notify.c create mode 100644 fs/fuse/poll.c create mode 100644 fs/fuse/req.c create mode 100644 fs/fuse/req_timeout.c create mode 100644 fs/fuse/sysctl.h
Signature · 1 line
2.53.0
PATCH 1/32 fuse: move request timeout code to a new source file
This marks the first step in cleanly separating the transport layer from the filesystem layer.
Add "dev.h", which will contain the interface definition for the transport layer.
--- fs/fuse/Makefile | 2 +- fs/fuse/dev.c | 94 -------------------------- fs/fuse/dev.h | 10 +++ fs/fuse/fuse_i.h | 19 ------ fs/fuse/inode.c | 33 +--------- fs/fuse/req_timeout.c | 150 ++++++++++++++++++++++++++++++++++++++++++ fs/fuse/sysctl.c | 1 + fs/fuse/sysctl.h | 9 +++ 8 files changed, 173 insertions(+), 145 deletions(-) create mode 100644 fs/fuse/dev.h create mode 100644 fs/fuse/req_timeout.c create mode 100644 fs/fuse/sysctl.h
fs/fuse/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-$(CONFIG_CUSE) += cuse.o obj-$(CONFIG_VIRTIO_FS) += virtiofs.o fuse-y := trace.o # put trace.o first so we see ftrace errors sooner -fuse-y += dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o ioctl.o +fuse-y += dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o ioctl.o req_timeout.o fuse-y += iomode.o fuse-$(CONFIG_FUSE_DAX) += dax.o fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o backing.o
fs/fuse/dev.c +0 -94
100 lines not on this page · raw message
fs/fuse/dev.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _FS_FUSE_DEV_H +#define _FS_FUSE_DEV_H + +struct fuse_conn ; + +void fuse_init_server_timeout (struct fuse_conn *fc,unsigned int timeout); + +#endif /* _FS_FUSE_DEV_H */
fs/fuse/fuse_i.h +0 -19
@@ -48,12 +48,6 @@/** Number of dentries for each connection in the control filesystem */ #define FUSE_CTL_NUM_DENTRIES 5 -/* Frequency (in seconds) of request timeout checks, if opted into */ -#define FUSE_TIMEOUT_TIMER_FREQ 15 - -/** Frequency (in jiffies) of request timeout checks, if opted into */ -extern const unsigned long fuse_timeout_timer_freq; -/* * Dentries invalidation workqueue period, in seconds. The value of this * parameter shall be >= FUSE_DENTRY_INVAL_FREQ_MIN seconds, or 0 (zero), in
@@ -63,16 +57,6 @@ extern unsigned inval_wq __read_mostly;/** Maximum of max_pages received in init_out */ extern unsigned int fuse_max_pages_limit; -/* -* Default timeout (in seconds) for the server to reply to a request -* before the connection is aborted, if no timeout was specified on mount. -*/ -extern unsigned int fuse_default_req_timeout; -/* -* Max timeout (in seconds) for the server to reply to a request before -* the connection is aborted. -*/ -extern unsigned int fuse_max_req_timeout;/** List of active connections */ extern struct list_head fuse_conn_list;
@@ -1286,9 +1270,6 @@ void fuse_request_end(struct fuse_req *req);void fuse_abort_conn (struct fuse_conn *fc);void fuse_wait_aborted (struct fuse_conn *fc); -/* Check if any requests timed out */ -void fuse_check_timeout (struct work_struct *work); -void fuse_dentry_tree_init (void );void fuse_dentry_tree_cleanup (void );
fs/fuse/inode.c +2 -31
@@ -6,6 +6,7 @@See the file COPYING. */ +#include "dev.h" #include "fuse_i.h" #include "fuse_dev_i.h" #include "dev_uring_i.h"
@@ -41,8 +42,6 @@ static int set_global_limit(const char *val, const struct kernel_param *kp);unsigned int fuse_max_pages_limit =256 ;/* default is no timeout */ -unsigned int fuse_default_req_timeout; -unsigned int fuse_max_req_timeout;unsigned int max_user_bgreq; module_param_call(max_user_bgreq, set_global_limit, param_get_uint,
@@ -1311,34 +1310,6 @@ static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg)spin_unlock (&fc->bg_lock); } -static void set_request_timeout (struct fuse_conn *fc,unsigned int timeout) -{ - fc->timeout.req_timeout =secs_to_jiffies (timeout); -INIT_DELAYED_WORK (&fc->timeout.work, fuse_check_timeout); -queue_delayed_work (system_percpu_wq, &fc->timeout.work, - fuse_timeout_timer_freq); -} - -static void init_server_timeout (struct fuse_conn *fc,unsigned int timeout) -{ -if (!timeout && !fuse_max_req_timeout && !fuse_default_req_timeout) -return ; - -if (!timeout) - timeout = fuse_default_req_timeout; - -if (fuse_max_req_timeout) { -if (timeout) - timeout =min (fuse_max_req_timeout, timeout); -else - timeout = fuse_max_req_timeout; - } - - timeout =max (FUSE_TIMEOUT_TIMER_FREQ , timeout); - -set_request_timeout (fc, timeout); -} -struct fuse_init_args {struct fuse_args args;struct fuse_init_in in;
@@ -1491,7 +1462,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, fc->no_flock =1 ; } -init_server_timeout (fc, timeout); +fuse_init_server_timeout (fc, timeout); fm->sb->s_bdi->ra_pages =min (fm->sb->s_bdi->ra_pages, ra_pages);
fs/fuse/req_timeout.c new file +150 -0
150 lines not on this page · raw message
fs/fuse/sysctl.c +1 -0
@@ -6,6 +6,7 @@*/ #include <linux/sysctl.h> +#include "sysctl.h" #include "fuse_i.h" static struct ctl_table_header *fuse_table_header;
fs/fuse/sysctl.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _FS_FUSE_SYSCTL_H +#define _FS_FUSE_SYSCTL_H + +extern unsigned int fuse_default_req_timeout; +extern unsigned int fuse_max_req_timeout; + +#endif /* _FS_FUSE_SYSCTL_H */
Signature · 1 line
2.53.0
PATCH 2/32 fuse: add struct fuse_chan
In reply to Miklos SzerediThe goal is to separate transport layer stuff out from struct fuse_conn, leaving just the filesystem related members.
Add a new object referenced from fuse_conn. This patch just implements the allocation and freeing of this object.
Following patches will move transport related members from fuse_conn to fuse_chan.
--- fs/fuse/cuse.c | 7 ++++++- fs/fuse/dev.c | 13 +++++++++++++ fs/fuse/dev.h | 7 +++++++ fs/fuse/fuse_dev_i.h | 4 ++++ fs/fuse/fuse_i.h | 6 +++++- fs/fuse/inode.c | 10 ++++++++-- fs/fuse/virtio_fs.c | 8 +++++++- 7 files changed, 50 insertions(+), 5 deletions(-)
fs/fuse/cuse.c +6 -1
@@ -51,6 +51,7 @@#include <linux/uio.h> #include <linux/user_namespace.h> +#include "dev.h" #include "fuse_i.h" #include "fuse_dev_i.h"
@@ -502,8 +503,12 @@ static int cuse_channel_open(struct inode *inode, struct file *file) {struct fuse_dev *fud;struct cuse_conn *cc; + struct fuse_chan *fch __free(fuse_chan_free) = fuse_chan_new();int rc; +if (!fch) +return -ENOMEM ; +/* set up cuse_conn */ cc =kzalloc_obj (*cc);if (!cc)
@@ -514,7 +519,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)* be represented in file->f_cred->user_ns. */ fuse_conn_init (&cc->fc, &cc->fm, file->f_cred->user_ns, - &fuse_dev_fiq_ops,NULL ); + &fuse_dev_fiq_ops,NULL ,no_free_ptr (fch)); cc->fc.release = cuse_fc_release; fud =fuse_dev_alloc_install (&cc->fc);
fs/fuse/dev.c +13 -0
@@ -6,6 +6,7 @@See the file COPYING. */ +#include "dev.h" #include "dev_uring_i.h" #include "fuse_i.h" #include "fuse_dev_i.h"
@@ -319,6 +320,18 @@ const struct fuse_iqueue_ops fuse_dev_fiq_ops = { };EXPORT_SYMBOL_GPL (fuse_dev_fiq_ops); +void fuse_chan_free (struct fuse_chan *fch) +{ +kfree (fch); +} +EXPORT_SYMBOL_GPL (fuse_chan_free); + +struct fuse_chan *fuse_chan_new (void ) +{ + return kzalloc_obj(struct fuse_chan); +} +EXPORT_SYMBOL_GPL (fuse_chan_new); +static void fuse_send_one (struct fuse_iqueue *fiq,struct fuse_req *req) { req->in.h.len = sizeof(struct fuse_in_header) +
fs/fuse/dev.h +7 -0
@@ -3,7 +3,14 @@#ifndef _FS_FUSE_DEV_H#define _FS_FUSE_DEV_H +#include <linux/cleanup.h> +struct fuse_conn ; +struct fuse_chan ; + +struct fuse_chan *fuse_chan_new (void ); +void fuse_chan_free (struct fuse_chan *fch); +DEFINE_FREE(fuse_chan_free, struct fuse_chan *, if (_T) fuse_chan_free(_T))void fuse_init_server_timeout (struct fuse_conn *fc,unsigned int timeout);
fs/fuse/fuse_dev_i.h +4 -0
@@ -21,6 +21,10 @@ struct fuse_req;struct fuse_iqueue ;struct fuse_forget_link ; +struct fuse_chan { +/* will move stuff from struct fuse_conn */ +}; +struct fuse_copy_state {struct fuse_req *req;struct iov_iter *iter;
fs/fuse/fuse_i.h +5 -1
@@ -668,6 +668,9 @@ struct fuse_conn {/** Input queue */ struct fuse_iqueue iq; +/* transport layer object */ +struct fuse_chan *chan; +/** The next unique kernel file handle */ atomic64_t khctr;
@@ -1313,7 +1316,8 @@ void fuse_pqueue_init(struct fuse_pqueue *fpq);*/ void fuse_conn_init (struct fuse_conn *fc,struct fuse_mount *fm,struct user_namespace *user_ns, -const struct fuse_iqueue_ops *fiq_ops,void *fiq_priv); +const struct fuse_iqueue_ops *fiq_ops,void *fiq_priv, +struct fuse_chan *fch);/** * Release reference to fuse_conn
fs/fuse/inode.c +8 -2
@@ -997,7 +997,7 @@ void fuse_pqueue_init(struct fuse_pqueue *fpq)void fuse_conn_init (struct fuse_conn *fc,struct fuse_mount *fm,struct user_namespace *user_ns, -const struct fuse_iqueue_ops *fiq_ops,void *fiq_priv) +const struct fuse_iqueue_ops *fiq_ops,void *fiq_priv,struct fuse_chan *fch) {memset (fc,0 ,sizeof (*fc));spin_lock_init (&fc->lock);
@@ -1035,6 +1035,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,INIT_LIST_HEAD (&fc->mounts);list_add (&fm->fc_entry, &fc->mounts); fm->fc = fc; + fc->chan = fch; }EXPORT_SYMBOL_GPL (fuse_conn_init);
@@ -1043,6 +1044,7 @@ static void delayed_release(struct rcu_head *p) struct fuse_conn *fc = container_of(p, struct fuse_conn, rcu);fuse_uring_destruct (fc); +fuse_chan_free (fc->chan);put_user_ns (fc->user_ns); fc->release (fc);
@@ -1982,8 +1984,12 @@ static int fuse_get_tree(struct fs_context *fsc)struct fuse_conn *fc;struct fuse_mount *fm;struct super_block *sb; + struct fuse_chan *fch __free(fuse_chan_free) = fuse_chan_new();int err; +if (!fch) +return -ENOMEM ; + fc =kmalloc_obj (*fc);if (!fc)return -ENOMEM ;
@@ -1994,7 +2000,7 @@ static int fuse_get_tree(struct fs_context *fsc)return -ENOMEM ; } -fuse_conn_init (fc, fm, fsc->user_ns, &fuse_dev_fiq_ops,NULL ); +fuse_conn_init (fc, fm, fsc->user_ns, &fuse_dev_fiq_ops,NULL ,no_free_ptr (fch)); fc->release = fuse_free_conn; fsc->s_fs_info = fm;
fs/fuse/virtio_fs.c +7 -1
@@ -19,6 +19,7 @@#include <linux/highmem.h> #include <linux/cleanup.h> #include <linux/uio.h> +#include "dev.h" #include "fuse_i.h" #include "fuse_dev_i.h"
@@ -1683,8 +1684,12 @@ static int virtio_fs_get_tree(struct fs_context *fsc)struct fuse_conn *fc =NULL ;struct fuse_mount *fm;unsigned int virtqueue_size; + struct fuse_chan *fch __free(fuse_chan_free) = fuse_chan_new();int err = -EIO ; +if (!fch) +return -ENOMEM ; +if (!fsc->source)return invalf (fsc,"No source specified" );
@@ -1711,7 +1716,8 @@ static int virtio_fs_get_tree(struct fs_context *fsc)if (!fm) goto out_err; -fuse_conn_init (fc, fm, fsc->user_ns, &virtio_fs_fiq_ops, fs); +fuse_conn_init (fc, fm, fsc->user_ns, &virtio_fs_fiq_ops, fs,no_free_ptr (fch)); + fc->release = fuse_free_conn; fc->delete_stale = true; fc->auto_submounts = true;
Signature · 1 line
2.53.0
PATCH 3/32 fuse: move fuse_iqueue to fuse_chan
In reply to Miklos SzerediMove the 'fiq' member from fuse_conn to fuse_chan.
Move iqueue related structure definitions and function declarations from "fuse_i.h" to "fuse_dev_i.h".
Add a fuse_dev_chan_new() helper, that returns a fuse_chan initialized with the fuse_dev_fiq_ops.
Add a fuse_chan_release() function, that calls fiq->ops->release().
--- fs/fuse/cuse.c | 6 +-- fs/fuse/dev.c | 64 +++++++++++++++++++++++-------- fs/fuse/dev.h | 2 + fs/fuse/dev_uring.c | 2 +- fs/fuse/dev_uring_i.h | 1 + fs/fuse/fuse_dev_i.h | 81 +++++++++++++++++++++++++++++++++++++++- fs/fuse/fuse_i.h | 87 +------------------------------------------ fs/fuse/inode.c | 27 ++------------ fs/fuse/req_timeout.c | 2 +- fs/fuse/virtio_fs.c | 11 +++--- 10 files changed, 146 insertions(+), 137 deletions(-)
fs/fuse/cuse.c +2 -4
@@ -503,7 +503,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file) {struct fuse_dev *fud;struct cuse_conn *cc; - struct fuse_chan *fch __free(fuse_chan_free) = fuse_chan_new(); + struct fuse_chan *fch __free(fuse_chan_free) = fuse_dev_chan_new();int rc;if (!fch)
@@ -518,9 +518,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)* Limit the cuse channel to requests that can * be represented in file->f_cred->user_ns. */ -fuse_conn_init (&cc->fc, &cc->fm, file->f_cred->user_ns, - &fuse_dev_fiq_ops,NULL ,no_free_ptr (fch)); - +fuse_conn_init (&cc->fc, &cc->fm, file->f_cred->user_ns,no_free_ptr (fch)); cc->fc.release = cuse_fc_release; fud =fuse_dev_alloc_install (&cc->fc);fuse_conn_put (&cc->fc);
fs/fuse/dev.c +48 -16
164 lines not on this page · raw message
fs/fuse/dev.h +2 -0
@@ -9,6 +9,8 @@ struct fuse_conn;struct fuse_chan ;struct fuse_chan *fuse_chan_new (void ); +struct fuse_chan *fuse_dev_chan_new (void ); +void fuse_chan_release (struct fuse_chan *fch);void fuse_chan_free (struct fuse_chan *fch); DEFINE_FREE(fuse_chan_free, struct fuse_chan *, if (_T) fuse_chan_free(_T))
fs/fuse/dev_uring.c +1 -1
@@ -982,7 +982,7 @@ static void fuse_uring_do_register(struct fuse_ring_ent *ent,struct fuse_ring_queue *queue = ent->queue;struct fuse_ring *ring = queue->ring;struct fuse_conn *fc = ring->fc; -struct fuse_iqueue *fiq = &fc->iq; +struct fuse_iqueue *fiq = &fc->chan->iq;fuse_uring_prepare_cancel (cmd, issue_flags, ent);
fs/fuse/dev_uring_i.h +1 -0
@@ -8,6 +8,7 @@#define _FS_FUSE_DEV_URING_I_H#include "fuse_i.h" +#include "fuse_dev_i.h" #ifdef CONFIG_FUSE_IO_URING
fs/fuse/fuse_dev_i.h +80 -1
99 lines not on this page · raw message
fs/fuse/fuse_i.h +1 -86
117 lines not on this page · raw message
fs/fuse/inode.c +4 -23
@@ -969,21 +969,6 @@ static int fuse_show_options(struct seq_file *m, struct dentry *root)return 0 ; } -static void fuse_iqueue_init (struct fuse_iqueue *fiq, -const struct fuse_iqueue_ops *ops, -void *priv) -{ -memset (fiq,0 ,sizeof (struct fuse_iqueue )); -spin_lock_init (&fiq->lock); -init_waitqueue_head (&fiq->waitq); -INIT_LIST_HEAD (&fiq->pending); -INIT_LIST_HEAD (&fiq->interrupts); - fiq->forget_list_tail = &fiq->forget_list_head; - fiq->connected =1 ; - fiq->ops = ops; - fiq->priv = priv; -} -void fuse_pqueue_init (struct fuse_pqueue *fpq) {unsigned int i;
@@ -996,8 +981,7 @@ void fuse_pqueue_init(struct fuse_pqueue *fpq) }void fuse_conn_init (struct fuse_conn *fc,struct fuse_mount *fm, -struct user_namespace *user_ns, -const struct fuse_iqueue_ops *fiq_ops,void *fiq_priv,struct fuse_chan *fch) +struct user_namespace *user_ns,struct fuse_chan *fch) {memset (fc,0 ,sizeof (*fc));spin_lock_init (&fc->lock);
@@ -1007,7 +991,6 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,atomic_set (&fc->epoch,1 );INIT_WORK (&fc->epoch_work, fuse_epoch_work);init_waitqueue_head (&fc->blocked_waitq); -fuse_iqueue_init (&fc->iq, fiq_ops, fiq_priv);INIT_LIST_HEAD (&fc->bg_queue);INIT_LIST_HEAD (&fc->entry);INIT_LIST_HEAD (&fc->devices);
@@ -1052,7 +1035,6 @@ static void delayed_release(struct rcu_head *p)void fuse_conn_put (struct fuse_conn *fc) { -struct fuse_iqueue *fiq = &fc->iq;struct fuse_sync_bucket *bucket;if (!refcount_dec_and_test (&fc->count))
@@ -1063,8 +1045,7 @@ void fuse_conn_put(struct fuse_conn *fc)if (fc->timeout.req_timeout)cancel_delayed_work_sync (&fc->timeout.work);cancel_work_sync (&fc->epoch_work); -if (fiq->ops->release) - fiq->ops->release (fiq); +fuse_chan_release (fc->chan);put_pid_ns (fc->pid_ns); bucket =rcu_dereference_protected (fc->curr_bucket,1 );if (bucket) {
@@ -1984,7 +1965,7 @@ static int fuse_get_tree(struct fs_context *fsc)struct fuse_conn *fc;struct fuse_mount *fm;struct super_block *sb; - struct fuse_chan *fch __free(fuse_chan_free) = fuse_chan_new(); + struct fuse_chan *fch __free(fuse_chan_free) = fuse_dev_chan_new();int err;if (!fch)
@@ -2000,7 +1981,7 @@ static int fuse_get_tree(struct fs_context *fsc)return -ENOMEM ; } -fuse_conn_init (fc, fm, fsc->user_ns, &fuse_dev_fiq_ops,NULL ,no_free_ptr (fch)); +fuse_conn_init (fc, fm, fsc->user_ns,no_free_ptr (fch)); fc->release = fuse_free_conn; fsc->s_fs_info = fm;
fs/fuse/req_timeout.c +1 -1
@@ -69,7 +69,7 @@ static void fuse_check_timeout(struct work_struct *work)struct delayed_work *dwork =to_delayed_work (work); struct fuse_conn *fc = container_of(dwork, struct fuse_conn, timeout.work); -struct fuse_iqueue *fiq = &fc->iq; +struct fuse_iqueue *fiq = &fc->chan->iq;struct fuse_dev *fud;struct fuse_pqueue *fpq;bool expired = false;
fs/fuse/virtio_fs.c +6 -5
@@ -1563,7 +1563,7 @@ static int virtio_fs_fill_super(struct super_block *sb, struct fs_context *fsc) {struct fuse_mount *fm =get_fuse_mount_super (sb);struct fuse_conn *fc = fm->fc; -struct virtio_fs *fs = fc->iq.priv; +struct virtio_fs *fs = fc->chan->iq.priv;struct fuse_fs_context *ctx = fsc->fs_private;unsigned int i;int err;
@@ -1626,7 +1626,7 @@ static int virtio_fs_fill_super(struct super_block *sb, struct fs_context *fsc)static void virtio_fs_conn_destroy (struct fuse_mount *fm) {struct fuse_conn *fc = fm->fc; -struct virtio_fs *vfs = fc->iq.priv; +struct virtio_fs *vfs = fc->chan->iq.priv;struct virtio_fs_vq *fsvq = &vfs->vqs[VQ_HIPRIO ];/* Stop dax worker. Soon evict_inodes() will be called which
@@ -1674,7 +1674,7 @@ static int virtio_fs_test_super(struct super_block *sb,struct fuse_mount *fsc_fm = fsc->s_fs_info;struct fuse_mount *sb_fm =get_fuse_mount_super (sb); -return fsc_fm->fc->iq.priv == sb_fm->fc->iq.priv; +return fsc_fm->fc->chan->iq.priv == sb_fm->fc->chan->iq.priv; }static int virtio_fs_get_tree (struct fs_context *fsc)
@@ -1694,7 +1694,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc)return invalf (fsc,"No source specified" );/* This gets a reference on virtio_fs object. This ptr gets installed -* in fc->iq->priv. Once fuse_conn is going away, it calls ->put() +* in chan->iq->priv. Once fuse_conn is going away, it calls ->put() * to drop the reference to this object. */ fs =virtio_fs_find_instance (fsc->source);
@@ -1716,7 +1716,8 @@ static int virtio_fs_get_tree(struct fs_context *fsc)if (!fm) goto out_err; -fuse_conn_init (fc, fm, fsc->user_ns, &virtio_fs_fiq_ops, fs,no_free_ptr (fch)); +fuse_iqueue_init (&fch->iq, &virtio_fs_fiq_ops, fs); +fuse_conn_init (fc, fm, fsc->user_ns,no_free_ptr (fch)); fc->release = fuse_free_conn; fc->delete_stale = true;
Signature · 1 line
2.53.0
PATCH 4/32 fuse: move fuse_dev and fuse_pqueue to dev.c
In reply to Miklos SzerediMove function definitions to dev.c, struct definitions to fuse_dev_i.h.
--- fs/fuse/dev.c | 94 ++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dev.h | 4 ++ fs/fuse/fuse_dev_i.h | 46 ++++++++++++++++++++++ fs/fuse/fuse_i.h | 46 ---------------------- fs/fuse/inode.c | 94 -------------------------------------------- 5 files changed, 144 insertions(+), 140 deletions(-)
fs/fuse/dev.c +94 -0
@@ -364,6 +364,100 @@ struct fuse_chan *fuse_dev_chan_new(void) }EXPORT_SYMBOL_GPL (fuse_dev_chan_new); +void fuse_pqueue_init (struct fuse_pqueue *fpq) +{ +unsigned int i; + +spin_lock_init (&fpq->lock); +for (i =0 ; i <FUSE_PQ_HASH_SIZE ; i++) +INIT_LIST_HEAD (&fpq->processing[i]); +INIT_LIST_HEAD (&fpq->io); + fpq->connected =1 ; +} + +struct fuse_dev *fuse_dev_alloc (void ) +{ +struct fuse_dev *fud; +struct list_head *pq; + + fud = kzalloc_obj(struct fuse_dev); +if (!fud) +return NULL ; + +refcount_set (&fud->ref,1 ); + pq = kzalloc_objs(struct list_head, FUSE_PQ_HASH_SIZE); +if (!pq) { +kfree (fud); +return NULL ; + } + + fud->pq.processing = pq; +fuse_pqueue_init (&fud->pq); + +return fud; +} +EXPORT_SYMBOL_GPL (fuse_dev_alloc); + +void fuse_dev_install (struct fuse_dev *fud,struct fuse_conn *fc) +{ +struct fuse_conn *old_fc; + +spin_lock (&fc->lock); +/* +* Pairs with: +* - xchg() in fuse_dev_release() +* - smp_load_acquire() in fuse_dev_fc_get() +*/ + old_fc =cmpxchg (&fud->fc,NULL , fc); +if (old_fc) { +/* +* failed to set fud->fc because +* - it was already set to a different fc +* - it was set to disconneted +*/ + fc->connected =0 ; + }else { +list_add_tail (&fud->entry, &fc->devices); +fuse_conn_get (fc); + } +spin_unlock (&fc->lock); +} +EXPORT_SYMBOL_GPL (fuse_dev_install); + +struct fuse_dev *fuse_dev_alloc_install (struct fuse_conn *fc) +{ +struct fuse_dev *fud; + + fud =fuse_dev_alloc (); +if (!fud) +return NULL ; + +fuse_dev_install (fud, fc); +return fud; +} +EXPORT_SYMBOL_GPL (fuse_dev_alloc_install); + +void fuse_dev_put (struct fuse_dev *fud) +{ +struct fuse_conn *fc; + +if (!refcount_dec_and_test (&fud->ref)) +return ; + + fc =fuse_dev_fc_get (fud); +if (fc && fc !=FUSE_DEV_FC_DISCONNECTED ) { +/* This is the virtiofs case (fuse_dev_release() not called) */ +spin_lock (&fc->lock); +list_del (&fud->entry); +spin_unlock (&fc->lock); + +fuse_conn_put (fc); + } +kfree (fud->pq.processing); +kfree (fud); +} +EXPORT_SYMBOL_GPL (fuse_dev_put); +static void fuse_send_one (struct fuse_iqueue *fiq,struct fuse_req *req) { req->in.h.len = sizeof(struct fuse_in_header) +
fs/fuse/dev.h +4 -0
@@ -7,6 +7,7 @@struct fuse_conn ;struct fuse_chan ; +struct fuse_dev ;struct fuse_chan *fuse_chan_new (void );struct fuse_chan *fuse_dev_chan_new (void );
@@ -14,6 +15,9 @@ void fuse_chan_release(struct fuse_chan *fch);void fuse_chan_free (struct fuse_chan *fch); DEFINE_FREE(fuse_chan_free, struct fuse_chan *, if (_T) fuse_chan_free(_T)) +void fuse_dev_install (struct fuse_dev *fud,struct fuse_conn *fc); +void fuse_dev_put (struct fuse_dev *fud); +void fuse_init_server_timeout (struct fuse_conn *fc,unsigned int timeout);#endif /* _FS_FUSE_DEV_H */
fs/fuse/fuse_dev_i.h +46 -0
57 lines not on this page · raw message
fs/fuse/fuse_i.h +0 -46
64 lines not on this page · raw message
fs/fuse/inode.c +0 -94
106 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 5/32 fuse: move 'devices' member from fuse_conn to fuse_chan
In reply to Miklos SzerediThis belongs in the transport layer.
--- fs/fuse/dev.c | 17 ++++++++++++----- fs/fuse/fuse_dev_i.h | 5 ++++- fs/fuse/fuse_i.h | 3 --- fs/fuse/inode.c | 2 -- fs/fuse/req_timeout.c | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-)
fs/fuse/dev.c +12 -5
@@ -342,13 +342,20 @@ void fuse_chan_release(struct fuse_chan *fch)void fuse_chan_free (struct fuse_chan *fch) { +WARN_ON (!list_empty (&fch->devices));kfree (fch); }EXPORT_SYMBOL_GPL (fuse_chan_free);struct fuse_chan *fuse_chan_new (void ) { - return kzalloc_obj(struct fuse_chan); + struct fuse_chan *fch = kzalloc_obj(struct fuse_chan); +if (!fch) +return NULL ; + +INIT_LIST_HEAD (&fch->devices); + +return fch; }EXPORT_SYMBOL_GPL (fuse_chan_new);
@@ -417,7 +424,7 @@ void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc)*/ fc->connected =0 ; }else { -list_add_tail (&fud->entry, &fc->devices); +list_add_tail (&fud->entry, &fc->chan->devices);fuse_conn_get (fc); }spin_unlock (&fc->lock);
@@ -2046,7 +2053,7 @@ static void fuse_resend(struct fuse_conn *fc)return ; } -list_for_each_entry (fud, &fc->devices, entry) { +list_for_each_entry (fud, &fc->chan->devices, entry) {struct fuse_pqueue *fpq = &fud->pq;spin_lock (&fpq->lock);
@@ -2519,7 +2526,7 @@ void fuse_abort_conn(struct fuse_conn *fc)spin_unlock (&fc->bg_lock);fuse_set_initialized (fc); -list_for_each_entry (fud, &fc->devices, entry) { +list_for_each_entry (fud, &fc->chan->devices, entry) {struct fuse_pqueue *fpq = &fud->pq;spin_lock (&fpq->lock);
@@ -2605,7 +2612,7 @@ int fuse_dev_release(struct inode *inode, struct file *file)spin_lock (&fc->lock);list_del (&fud->entry);/* Are we the last open device? */ - last =list_empty (&fc->devices); + last =list_empty (&fc->chan->devices);spin_unlock (&fc->lock);if (last) {
fs/fuse/fuse_dev_i.h +4 -1
@@ -90,6 +90,9 @@ struct fuse_iqueue {struct fuse_chan {/** Input queue */ struct fuse_iqueue iq; + +/** List of device instances belonging to this connection */ +struct list_head devices; };#define FUSE_PQ_HASH_BITS 8
@@ -125,7 +128,7 @@ struct fuse_dev {/** Processing queue */ struct fuse_pqueue pq; -/** list entry on fc->devices */ +/** list entry on fch->devices */ struct list_head entry; };
fs/fuse/fuse_i.h +0 -3
@@ -835,9 +835,6 @@ struct fuse_conn {*/ struct rw_semaphore killsb; -/** List of device instances belonging to this connection */ -struct list_head devices; -#ifdef CONFIG_FUSE_DAX /* Dax mode */ enum fuse_dax_mode dax_mode;
fs/fuse/inode.c +0 -2
@@ -982,7 +982,6 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,init_waitqueue_head (&fc->blocked_waitq);INIT_LIST_HEAD (&fc->bg_queue);INIT_LIST_HEAD (&fc->entry); -INIT_LIST_HEAD (&fc->devices);atomic_set (&fc->num_waiting,0 ); fc->max_background =FUSE_DEFAULT_MAX_BACKGROUND ; fc->congestion_threshold =FUSE_DEFAULT_CONGESTION_THRESHOLD ;
@@ -1543,7 +1542,6 @@ EXPORT_SYMBOL_GPL(fuse_send_init);void fuse_free_conn (struct fuse_conn *fc) { -WARN_ON (!list_empty (&fc->devices));kfree (fc); }EXPORT_SYMBOL_GPL (fuse_free_conn);
fs/fuse/req_timeout.c +1 -1
@@ -94,7 +94,7 @@ static void fuse_check_timeout(struct work_struct *work)spin_unlock (&fc->lock);return ; } -list_for_each_entry (fud, &fc->devices, entry) { +list_for_each_entry (fud, &fc->chan->devices, entry) { fpq = &fud->pq;spin_lock (&fpq->lock); if (fuse_request_expired(fc, &fpq->io) ||
Signature · 1 line
2.53.0
PATCH 6/32 fuse: move background queuing related members to fuse_chan
In reply to Miklos SzerediMove:
- max_background
- num_background
- active_background
- bg_queue
- bg_lock
--- fs/fuse/control.c | 11 ++++++----- fs/fuse/dev.c | 45 +++++++++++++++++++++++-------------------- fs/fuse/dev.h | 3 +++ fs/fuse/dev_uring.c | 24 +++++++++++------------ fs/fuse/file.c | 5 +++-- fs/fuse/fuse_dev_i.h | 16 +++++++++++++++ fs/fuse/fuse_i.h | 16 --------------- fs/fuse/inode.c | 16 +++++---------- fs/fuse/req_timeout.c | 6 +++--- fs/fuse/virtio_fs.c | 2 +- 10 files changed, 73 insertions(+), 71 deletions(-)
fs/fuse/control.c +6 -5
@@ -7,6 +7,7 @@*/ #include "fuse_i.h" +#include "fuse_dev_i.h" #include <linux/init.h> #include <linux/module.h>
@@ -111,7 +112,7 @@ static ssize_t fuse_conn_max_background_read(struct file *file,if (!fc)return 0 ; - val =READ_ONCE (fc->max_background); + val =READ_ONCE (fc->chan->max_background);fuse_conn_put (fc);return fuse_conn_limit_read (file, buf, len, ppos, val);
@@ -129,12 +130,12 @@ static ssize_t fuse_conn_max_background_write(struct file *file,if (ret >0 ) {struct fuse_conn *fc =fuse_ctl_file_conn_get (file);if (fc) { -spin_lock (&fc->bg_lock); - fc->max_background = val; - fc->blocked = fc->num_background >= fc->max_background; +spin_lock (&fc->chan->bg_lock); + fc->chan->max_background = val; + fc->blocked = fc->chan->num_background >= fc->chan->max_background;if (!fc->blocked)wake_up (&fc->blocked_waitq); -spin_unlock (&fc->bg_lock); +spin_unlock (&fc->chan->bg_lock);fuse_conn_put (fc); } }
fs/fuse/dev.c +24 -21
108 lines not on this page · raw message
fs/fuse/dev.h +3 -0
@@ -5,6 +5,9 @@#include <linux/cleanup.h> +/** Maximum number of outstanding background requests */ +#define FUSE_DEFAULT_MAX_BACKGROUND 12 +struct fuse_conn ;struct fuse_chan ;struct fuse_dev ;
fs/fuse/dev_uring.c +12 -12
@@ -54,7 +54,7 @@ static void fuse_uring_flush_bg(struct fuse_ring_queue *queue)struct fuse_conn *fc = ring->fc;lockdep_assert_held (&queue->lock); -lockdep_assert_held (&fc->bg_lock); +lockdep_assert_held (&fc->chan->bg_lock);/* * Allow one bg request per queue, ignoring global fc limits.
@@ -62,14 +62,14 @@ static void fuse_uring_flush_bg(struct fuse_ring_queue *queue)* eliminates the need for remote queue wake-ups when global * limits are met but this queue has no more waiting requests. */ -while ((fc->active_background < fc->max_background || +while ((fc->chan->active_background < fc->chan->max_background || !queue->active_background) && (!list_empty (&queue->fuse_req_bg_queue))) {struct fuse_req *req; req =list_first_entry (&queue->fuse_req_bg_queue, struct fuse_req, list); - fc->active_background++; + fc->chan->active_background++; queue->active_background++;list_move_tail (&req->list, &queue->fuse_req_queue);
@@ -89,9 +89,9 @@ static void fuse_uring_req_end(struct fuse_ring_ent *ent, struct fuse_req *req,list_del_init (&req->list);if (test_bit (FR_BACKGROUND , &req->flags)) { queue->active_background--; -spin_lock (&fc->bg_lock); +spin_lock (&fc->chan->bg_lock);fuse_uring_flush_bg (queue); -spin_unlock (&fc->bg_lock); +spin_unlock (&fc->chan->bg_lock); }spin_unlock (&queue->lock);
@@ -132,11 +132,11 @@ void fuse_uring_abort_end_requests(struct fuse_ring *ring) queue->stopped = true; -WARN_ON_ONCE (ring->fc->max_background !=UINT_MAX ); +WARN_ON_ONCE (ring->fc->chan->max_background !=UINT_MAX );spin_lock (&queue->lock); -spin_lock (&fc->bg_lock); +spin_lock (&fc->chan->bg_lock);fuse_uring_flush_bg (queue); -spin_unlock (&fc->bg_lock); +spin_unlock (&fc->chan->bg_lock);spin_unlock (&queue->lock);fuse_uring_abort_end_queue_requests (queue); }
@@ -1325,12 +1325,12 @@ bool fuse_uring_queue_bq_req(struct fuse_req *req) ent =list_first_entry_or_null (&queue->ent_avail_queue, struct fuse_ring_ent, list); -spin_lock (&fc->bg_lock); - fc->num_background++; -if (fc->num_background == fc->max_background) +spin_lock (&fc->chan->bg_lock); + fc->chan->num_background++; +if (fc->chan->num_background == fc->chan->max_background) fc->blocked =1 ;fuse_uring_flush_bg (queue); -spin_unlock (&fc->bg_lock); +spin_unlock (&fc->chan->bg_lock);/* * Due to bg_queue flush limits there might be other bg requests
fs/fuse/file.c +3 -2
@@ -7,6 +7,7 @@*/ #include "fuse_i.h" +#include "fuse_dev_i.h" #include <linux/pagemap.h> #include <linux/slab.h>
@@ -902,7 +903,7 @@ static int fuse_handle_readahead(struct folio *folio, ia =NULL ; }if (!ia) { -if (fc->num_background >= fc->congestion_threshold && +if (fc->chan->num_background >= fc->congestion_threshold && rac->ra->async_size >=readahead_count (rac))/* * Congested and only async pages left, so skip the
@@ -2293,7 +2294,7 @@ static int fuse_writepages(struct address_space *mapping,return -EIO ;if (wbc->sync_mode ==WB_SYNC_NONE && - fc->num_background >= fc->congestion_threshold) + fc->chan->num_background >= fc->congestion_threshold)return 0 ;return iomap_writepages (&wpc);
fs/fuse/fuse_dev_i.h +16 -0
@@ -93,6 +93,22 @@ struct fuse_chan {/** List of device instances belonging to this connection */ struct list_head devices; + +/** Maximum number of outstanding background requests */ +unsigned max_background; + +/** Number of requests currently in the background */ +unsigned num_background; + +/** Number of background requests currently queued for userspace */ +unsigned active_background; + +/** The list of background requests set aside for later queuing */ +struct list_head bg_queue; + +/** Protects: max_background, congestion_threshold, num_background, +* active_background, bg_queue, blocked */ +spinlock_t bg_lock; };#define FUSE_PQ_HASH_BITS 8
fs/fuse/fuse_i.h +0 -16
@@ -566,25 +566,9 @@ struct fuse_conn {/** rbtree of fuse_files waiting for poll events indexed by ph */ struct rb_root polled_files; -/** Maximum number of outstanding background requests */ -unsigned max_background; -/** Number of background requests at which congestion starts */ unsigned congestion_threshold; -/** Number of requests currently in the background */ -unsigned num_background; - -/** Number of background requests currently queued for userspace */ -unsigned active_background; - -/** The list of background requests set aside for later queuing */ -struct list_head bg_queue; - -/** Protects: max_background, congestion_threshold, num_background, -* active_background, bg_queue, blocked */ -spinlock_t bg_lock; -/** Flag indicating that INIT reply has been received. Allocating * any fuse request will be suspended until the flag is set */ int initialized;
fs/fuse/inode.c +5 -11
@@ -61,9 +61,6 @@ MODULE_PARM_DESC(max_user_congthresh,#define FUSE_DEFAULT_BLKSIZE 512 -/** Maximum number of outstanding background requests */ -#define FUSE_DEFAULT_MAX_BACKGROUND 12 -/** Congestion starts at 75% of maximum */ #define FUSE_DEFAULT_CONGESTION_THRESHOLD (FUSE_DEFAULT_MAX_BACKGROUND * 3 / 4)
@@ -974,16 +971,13 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm, {memset (fc,0 ,sizeof (*fc));spin_lock_init (&fc->lock); -spin_lock_init (&fc->bg_lock);init_rwsem (&fc->killsb);refcount_set (&fc->count,1 );atomic_set (&fc->epoch,1 );INIT_WORK (&fc->epoch_work, fuse_epoch_work);init_waitqueue_head (&fc->blocked_waitq); -INIT_LIST_HEAD (&fc->bg_queue);INIT_LIST_HEAD (&fc->entry);atomic_set (&fc->num_waiting,0 ); - fc->max_background =FUSE_DEFAULT_MAX_BACKGROUND ; fc->congestion_threshold =FUSE_DEFAULT_CONGESTION_THRESHOLD ;atomic64_set (&fc->khctr,0 ); fc->polled_files =RB_ROOT ;
@@ -1264,12 +1258,12 @@ static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg)sanitize_global_limit (&max_user_bgreq);sanitize_global_limit (&max_user_congthresh); -spin_lock (&fc->bg_lock); +spin_lock (&fc->chan->bg_lock);if (arg->max_background) { - fc->max_background = arg->max_background; + fc->chan->max_background = arg->max_background; -if (!cap_sys_admin && fc->max_background > max_user_bgreq) - fc->max_background = max_user_bgreq; +if (!cap_sys_admin && fc->chan->max_background > max_user_bgreq) + fc->chan->max_background = max_user_bgreq; }if (arg->congestion_threshold) { fc->congestion_threshold = arg->congestion_threshold;
@@ -1278,7 +1272,7 @@ static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg) fc->congestion_threshold > max_user_congthresh) fc->congestion_threshold = max_user_congthresh; } -spin_unlock (&fc->bg_lock); +spin_unlock (&fc->chan->bg_lock); }struct fuse_init_args {
fs/fuse/req_timeout.c +3 -3
@@ -83,9 +83,9 @@ static void fuse_check_timeout(struct work_struct *work)if (expired) goto abort_conn; -spin_lock (&fc->bg_lock); - expired =fuse_request_expired (fc, &fc->bg_queue); -spin_unlock (&fc->bg_lock); +spin_lock (&fc->chan->bg_lock); + expired =fuse_request_expired (fc, &fc->chan->bg_queue); +spin_unlock (&fc->chan->bg_lock);if (expired) goto abort_conn;
fs/fuse/virtio_fs.c +1 -1
@@ -1520,7 +1520,7 @@ static void virtio_fs_send_req(struct fuse_iqueue *fiq, struct fuse_req *req)if (ret == -ENOSPC ) {/* * Virtqueue full. Retry submission from worker -* context as we might be holding fc->bg_lock. +* context as we might be holding fc->chan->bg_lock. */ spin_lock (&fsvq->lock);list_add_tail (&req->list, &fsvq->queued_reqs);
Signature · 1 line
2.53.0
Joanne Koong
maintainerRe: [PATCH 06/32] fuse: move background queuing related members to fuse_chan
Quoted 35 lines · Miklos Szeredi
Move:
-
max_background
-num_background
-active_background
-bg_queue
-bg_lockSigned-off-by Miklos Szeredi <[email protected]>--- fs/fuse/control.c | 11 ++++++----- fs/fuse/dev.c | 45 +++++++++++++++++++++++-------------------- fs/fuse/dev.h | 3 +++ fs/fuse/dev_uring.c | 24 +++++++++++------------ fs/fuse/file.c | 5 +++-- fs/fuse/fuse_dev_i.h | 16 +++++++++++++++ fs/fuse/fuse_i.h | 16 --------------- fs/fuse/inode.c | 16 +++++---------- fs/fuse/req_timeout.c | 6 +++--- fs/fuse/virtio_fs.c | 2 +- 10 files changed, 73 insertions(+), 71 deletions(-)fs/fuse/fuse_dev_i.h +4
-0@@ -93,6 +93,22 @@ struct fuse_chan {/** List of device instances belonging to this connection */ struct list_head devices; + +/** Maximum number of outstanding background requests */ +unsigned max_background; +
fs/fuse/fuse_dev_i.h struct fuse_chan { · line 109
Quoted 10 lines
fs/fuse/fuse_dev_i.h +10
-0+/** Number of requests currently in the background */ +unsigned num_background; + +/** Number of background requests currently queued for userspace */ +unsigned active_background; + +/** The list of background requests set aside for later queuing */ +struct list_head bg_queue; + +/** Protects: max_background, congestion_threshold, num_background,
nit: should this comment be updated to remove "congestion_threshold" from the list? congestion threshold is accessed locklessly.
Thanks,
Joanne
Quoted 35 lines
fs/fuse/fuse_dev_i.h +2
-0+* active_background, bg_queue, blocked */ +spinlock_t bg_lock; };#define FUSE_PQ_HASH_BITS 8fs/fuse/fuse_i.h +0
-16@@ -566,25 +566,9 @@ struct fuse_conn {/** rbtree of fuse_files waiting for poll events indexed by ph */ struct rb_root polled_files; -/** Maximum number of outstanding background requests */ -unsigned max_background; -/** Number of background requests at which congestion starts */ unsigned congestion_threshold; -/** Number of requests currently in the background */ -unsigned num_background; - -/** Number of background requests currently queued for userspace */ -unsigned active_background; - -/** The list of background requests set aside for later queuing */ -struct list_head bg_queue; - -/** Protects: max_background, congestion_threshold, num_background, -* active_background, bg_queue, blocked */ -spinlock_t bg_lock; -/** Flag indicating that INIT reply has been received. Allocating * any fuse request will be suspended until the flag is set */ int initialized;
Miklos Szeredi
maintainerRe: [PATCH 06/32] fuse: move background queuing related members to fuse_chan
Quoted 4 lines · Joanne Koong
Quoted 1 line
+ /** Protects:
max_background,congestion_threshold,num_background,nit: should this comment be updated to remove "
congestion_threshold" from the list? congestion threshold is accessed locklessly.
Agreed, fixed.
Thanks,
Miklos
PATCH 7/32 fuse: move request blocking related members to fuse_chan
In reply to Miklos SzerediMove:
- initialized
- blocked
- blocked_waitq
- connected
- num_waiting
--- fs/fuse/control.c | 8 ++--- fs/fuse/cuse.c | 4 +-- fs/fuse/dev.c | 69 +++++++++++++++++++++++-------------------- fs/fuse/dev_uring.c | 12 ++++---- fs/fuse/fuse_dev_i.h | 19 ++++++++++++ fs/fuse/fuse_i.h | 19 ------------ fs/fuse/inode.c | 7 +---- fs/fuse/req_timeout.c | 4 +-- 8 files changed, 71 insertions(+), 71 deletions(-)
fs/fuse/control.c +4 -4
@@ -58,7 +58,7 @@ static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,if (!fc)return 0 ; - value =atomic_read (&fc->num_waiting); + value =atomic_read (&fc->chan->num_waiting); file->private_data = (void *)value;fuse_conn_put (fc); }
@@ -132,9 +132,9 @@ static ssize_t fuse_conn_max_background_write(struct file *file,if (fc) {spin_lock (&fc->chan->bg_lock); fc->chan->max_background = val; - fc->blocked = fc->chan->num_background >= fc->chan->max_background; -if (!fc->blocked) -wake_up (&fc->blocked_waitq); + fc->chan->blocked = fc->chan->num_background >= fc->chan->max_background; +if (!fc->chan->blocked) +wake_up (&fc->chan->blocked_waitq);spin_unlock (&fc->chan->bg_lock);fuse_conn_put (fc); }
fs/fuse/cuse.c +2 -2
@@ -527,7 +527,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)INIT_LIST_HEAD (&cc->list); - cc->fc.initialized =1 ; + cc->fc.chan->initialized =1 ; rc =cuse_send_init (cc);if (rc) {fuse_dev_put (fud);
@@ -584,7 +584,7 @@ static ssize_t cuse_class_waiting_show(struct device *dev, {struct cuse_conn *cc =dev_get_drvdata (dev); -return sprintf (buf,"%d\n" ,atomic_read (&cc->fc.num_waiting)); +return sprintf (buf,"%d\n" ,atomic_read (&cc->fc.chan->num_waiting)); } static DEVICE_ATTR(waiting, 0400, cuse_class_waiting_show, NULL);
fs/fuse/dev.c +37 -32
202 lines not on this page · raw message
fs/fuse/dev_uring.c +6 -6
@@ -898,7 +898,7 @@ static int fuse_uring_commit_fetch(struct io_uring_cmd *cmd, int issue_flags,return err; fpq = &queue->fpq; -if (!READ_ONCE (fc->connected) ||READ_ONCE (queue->stopped)) +if (!READ_ONCE (fc->chan->connected) ||READ_ONCE (queue->stopped))return err;spin_lock (&queue->lock);
@@ -997,7 +997,7 @@ static void fuse_uring_do_register(struct fuse_ring_ent *ent,if (ready) {WRITE_ONCE (fiq->ops, &fuse_io_uring_ops);WRITE_ONCE (ring->ready, true); -wake_up_all (&fc->blocked_waitq); +wake_up_all (&fc->chan->blocked_waitq); } } }
@@ -1156,14 +1156,14 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)if (fc->aborted)return -ECONNABORTED ; -if (!fc->connected) +if (!fc->chan->connected)return -ENOTCONN ;/* * fuse_uring_register() needs the ring to be initialized, * we need to know the max payload size */ -if (!fc->initialized) +if (!fc->chan->initialized)return -EAGAIN ;switch (cmd_op) {
@@ -1173,7 +1173,7 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)pr_info_once ("FUSE_IO_URING_CMD_REGISTER failed err=%d\n" , err); fc->io_uring =0 ; -wake_up_all (&fc->blocked_waitq); +wake_up_all (&fc->chan->blocked_waitq);return err; }break ;
@@ -1328,7 +1328,7 @@ bool fuse_uring_queue_bq_req(struct fuse_req *req)spin_lock (&fc->chan->bg_lock); fc->chan->num_background++;if (fc->chan->num_background == fc->chan->max_background) - fc->blocked =1 ; + fc->chan->blocked =1 ;fuse_uring_flush_bg (queue);spin_unlock (&fc->chan->bg_lock);
fs/fuse/fuse_dev_i.h +19 -0
@@ -109,6 +109,25 @@ struct fuse_chan {/** Protects: max_background, congestion_threshold, num_background, * active_background, bg_queue, blocked */ spinlock_t bg_lock; + +/** Flag indicating that INIT reply has been received. Allocating +* any fuse request will be suspended until the flag is set */ +int initialized; + +/** Flag indicating if connection is blocked. This will be +the case before the INIT reply is received, and if there +are too many outstading backgrounds requests */ +int blocked; + +/** waitq for blocked connection */ +wait_queue_head_t blocked_waitq; + +/** Connection established, cleared on umount, connection +abort and device release */ +unsigned connected; + +/** The number of requests waiting for completion */ +atomic_t num_waiting; };#define FUSE_PQ_HASH_BITS 8
fs/fuse/fuse_i.h +0 -19
@@ -569,22 +569,6 @@ struct fuse_conn {/** Number of background requests at which congestion starts */ unsigned congestion_threshold; -/** Flag indicating that INIT reply has been received. Allocating -* any fuse request will be suspended until the flag is set */ -int initialized; - -/** Flag indicating if connection is blocked. This will be -the case before the INIT reply is received, and if there -are too many outstading backgrounds requests */ -int blocked; - -/** waitq for blocked connection */ -wait_queue_head_t blocked_waitq; - -/** Connection established, cleared on umount, connection -abort and device release */ -unsigned connected; -/** Connection aborted via sysfs */ bool aborted;
@@ -786,9 +770,6 @@ struct fuse_conn {/** Maximum stack depth for passthrough backing files */ int max_stack_depth; -/** The number of requests waiting for completion */ -atomic_t num_waiting; -/** Negotiated minor version */ unsigned minor;
fs/fuse/inode.c +1 -6
@@ -975,15 +975,10 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,refcount_set (&fc->count,1 );atomic_set (&fc->epoch,1 );INIT_WORK (&fc->epoch_work, fuse_epoch_work); -init_waitqueue_head (&fc->blocked_waitq);INIT_LIST_HEAD (&fc->entry); -atomic_set (&fc->num_waiting,0 ); fc->congestion_threshold =FUSE_DEFAULT_CONGESTION_THRESHOLD ;atomic64_set (&fc->khctr,0 ); fc->polled_files =RB_ROOT ; - fc->blocked =0 ; - fc->initialized =0 ; - fc->connected =1 ;atomic64_set (&fc->attr_version,1 );atomic64_set (&fc->evict_ctr,1 );get_random_bytes (&fc->scramble_key,sizeof (fc->scramble_key));
@@ -1444,7 +1439,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, }fuse_set_initialized (fc); -wake_up_all (&fc->blocked_waitq); +wake_up_all (&fc->chan->blocked_waitq); }static struct fuse_init_args *fuse_new_init (struct fuse_mount *fm)
fs/fuse/req_timeout.c +2 -2
@@ -74,7 +74,7 @@ static void fuse_check_timeout(struct work_struct *work)struct fuse_pqueue *fpq;bool expired = false; -if (!atomic_read (&fc->num_waiting)) +if (!atomic_read (&fc->chan->num_waiting)) goto out;spin_lock (&fiq->lock);
@@ -90,7 +90,7 @@ static void fuse_check_timeout(struct work_struct *work) goto abort_conn;spin_lock (&fc->lock); -if (!fc->connected) { +if (!fc->chan->connected) {spin_unlock (&fc->lock);return ; }
Signature · 1 line
2.53.0
PATCH 8/32 fuse: move io_uring related members to fuse_chan
In reply to Miklos SzerediMove:
- io_uring
- ring
--- fs/fuse/dev.c | 2 +- fs/fuse/dev_uring.c | 26 +++++++++++++------------- fs/fuse/dev_uring_i.h | 6 +++--- fs/fuse/fuse_dev_i.h | 8 ++++++++ fs/fuse/fuse_i.h | 8 -------- fs/fuse/inode.c | 2 +- 6 files changed, 26 insertions(+), 26 deletions(-)
fs/fuse/dev.c +1 -1
@@ -79,7 +79,7 @@ void fuse_set_initialized(struct fuse_conn *fc)static bool fuse_block_alloc (struct fuse_conn *fc,bool for_background) {return !fc->chan->initialized || (for_background && fc->chan->blocked) || - (fc->io_uring && fc->chan->connected && !fuse_uring_ready (fc)); + (fc->chan->io_uring && fc->chan->connected && !fuse_uring_ready (fc)); }static void fuse_drop_waiting (struct fuse_conn *fc)
fs/fuse/dev_uring.c +13 -13
@@ -159,7 +159,7 @@ static bool ent_list_request_expired(struct fuse_conn *fc, struct list_head *lisbool fuse_uring_request_expired (struct fuse_conn *fc) { -struct fuse_ring *ring = fc->ring; +struct fuse_ring *ring = fc->chan->ring;struct fuse_ring_queue *queue;int qid;
@@ -187,7 +187,7 @@ bool fuse_uring_request_expired(struct fuse_conn *fc)void fuse_uring_destruct (struct fuse_conn *fc) { -struct fuse_ring *ring = fc->ring; +struct fuse_ring *ring = fc->chan->ring;int qid;if (!ring)
@@ -218,7 +218,7 @@ void fuse_uring_destruct(struct fuse_conn *fc)kfree (ring->queues);kfree (ring); - fc->ring =NULL ; + fc->chan->ring =NULL ; }/*
@@ -231,7 +231,7 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc)struct fuse_ring *res =NULL ;size_t max_payload_size; - ring =kzalloc_obj (*fc->ring,GFP_KERNEL_ACCOUNT ); + ring =kzalloc_obj (*fc->chan->ring,GFP_KERNEL_ACCOUNT );if (!ring)return NULL ;
@@ -244,10 +244,10 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc) max_payload_size =max (max_payload_size, fc->max_pages *PAGE_SIZE );spin_lock (&fc->lock); -if (fc->ring) { +if (fc->chan->ring) {/* race, another thread created the ring in the meantime */ spin_unlock (&fc->lock); - res = fc->ring; + res = fc->chan->ring; goto out_err; }
@@ -256,7 +256,7 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc) ring->nr_queues = nr_queues; ring->fc = fc; ring->max_payload_sz = max_payload_size; -smp_store_release (&fc->ring, ring); +smp_store_release (&fc->chan->ring, ring);spin_unlock (&fc->lock);return ring;
@@ -879,7 +879,7 @@ static int fuse_uring_commit_fetch(struct io_uring_cmd *cmd, int issue_flags, struct fuse_uring_cmd_req);struct fuse_ring_ent *ent;int err; -struct fuse_ring *ring = fc->ring; +struct fuse_ring *ring = fc->chan->ring;struct fuse_ring_queue *queue;uint64_t commit_id =READ_ONCE (cmd_req->commit_id);unsigned int qid =READ_ONCE (cmd_req->qid);
@@ -1082,7 +1082,7 @@ static int fuse_uring_register(struct io_uring_cmd *cmd, {const struct fuse_uring_cmd_req *cmd_req =io_uring_sqe128_cmd (cmd->sqe, struct fuse_uring_cmd_req); -struct fuse_ring *ring =smp_load_acquire (&fc->ring); +struct fuse_ring *ring =smp_load_acquire (&fc->chan->ring);struct fuse_ring_queue *queue;struct fuse_ring_ent *ent;int err;
@@ -1149,7 +1149,7 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) fc = fud->fc;/* Once a connection has io-uring enabled on it, it can't be disabled */ -if (!enable_uring && !fc->io_uring) { +if (!enable_uring && !fc->chan->io_uring) {pr_info_ratelimited ("fuse-io-uring is disabled\n" );return -EOPNOTSUPP ; }
@@ -1172,7 +1172,7 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)if (err) {pr_info_once ("FUSE_IO_URING_CMD_REGISTER failed err=%d\n" , err); - fc->io_uring =0 ; + fc->chan->io_uring =0 ;wake_up_all (&fc->chan->blocked_waitq);return err; }
@@ -1262,7 +1262,7 @@ static void fuse_uring_dispatch_ent(struct fuse_ring_ent *ent)void fuse_uring_queue_fuse_req (struct fuse_iqueue *fiq,struct fuse_req *req) {struct fuse_conn *fc = req->fm->fc; -struct fuse_ring *ring = fc->ring; +struct fuse_ring *ring = fc->chan->ring;struct fuse_ring_queue *queue;struct fuse_ring_ent *ent =NULL ;int err;
@@ -1305,7 +1305,7 @@ void fuse_uring_queue_fuse_req(struct fuse_iqueue *fiq, struct fuse_req *req)bool fuse_uring_queue_bq_req (struct fuse_req *req) {struct fuse_conn *fc = req->fm->fc; -struct fuse_ring *ring = fc->ring; +struct fuse_ring *ring = fc->chan->ring;struct fuse_ring_queue *queue;struct fuse_ring_ent *ent =NULL ;
fs/fuse/dev_uring_i.h +3 -3
@@ -148,7 +148,7 @@ bool fuse_uring_request_expired(struct fuse_conn *fc);static inline void fuse_uring_abort (struct fuse_conn *fc) { -struct fuse_ring *ring = fc->ring; +struct fuse_ring *ring = fc->chan->ring;if (ring ==NULL )return ;
@@ -161,7 +161,7 @@ static inline void fuse_uring_abort(struct fuse_conn *fc)static inline void fuse_uring_wait_stopped_queues (struct fuse_conn *fc) { -struct fuse_ring *ring = fc->ring; +struct fuse_ring *ring = fc->chan->ring;if (ring) wait_event(ring->stop_waitq,
@@ -170,7 +170,7 @@ static inline void fuse_uring_wait_stopped_queues(struct fuse_conn *fc)static inline bool fuse_uring_ready (struct fuse_conn *fc) { -return fc->ring && fc->ring->ready; +return fc->chan->ring && fc->chan->ring->ready; }#else /* CONFIG_FUSE_IO_URING */
fs/fuse/fuse_dev_i.h +8 -0
@@ -128,6 +128,14 @@ struct fuse_chan {/** The number of requests waiting for completion */ atomic_t num_waiting; + +/* Use io_uring for communication */ +unsigned int io_uring; + +#ifdef CONFIG_FUSE_IO_URING +/** uring connection information*/ +struct fuse_ring *ring; +#endif };#define FUSE_PQ_HASH_BITS 8
fs/fuse/fuse_i.h +0 -8
@@ -764,9 +764,6 @@ struct fuse_conn {/* Is synchronous FUSE_INIT allowed? */ unsigned int sync_init:1; -/* Use io_uring for communication */ -unsigned int io_uring; -/** Maximum stack depth for passthrough backing files */ int max_stack_depth;
@@ -819,11 +816,6 @@ struct fuse_conn {struct idr backing_files_map;#endif -#ifdef CONFIG_FUSE_IO_URING -/** uring connection information*/ -struct fuse_ring *ring; -#endif -/** Only used if the connection opts into request timeouts */ struct {/* Worker for checking if any requests have timed out */
fs/fuse/inode.c +1 -1
@@ -1412,7 +1412,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, ok = false; }if (flags &FUSE_OVER_IO_URING &&fuse_uring_enabled ()) - fc->io_uring =1 ; + fc->chan->io_uring =1 ;if (flags &FUSE_REQUEST_TIMEOUT ) timeout = arg->request_timeout;
Signature · 1 line
2.53.0
PATCH 9/32 fuse: move interrupt related members to fuse_chan
In reply to Miklos SzerediMove:
- no_interrupt
--- fs/fuse/dev.c | 4 ++-- fs/fuse/fuse_dev_i.h | 3 +++ fs/fuse/fuse_i.h | 3 --- 3 files changed, 5 insertions(+), 5 deletions(-)
fs/fuse/dev.c +2 -2
@@ -607,7 +607,7 @@ static void request_wait_answer(struct fuse_req *req)struct fuse_iqueue *fiq = &fc->chan->iq;int err; -if (!fc->no_interrupt) { +if (!fc->chan->no_interrupt) {/* Any signal may interrupt this */ err =wait_event_interruptible (req->waitq,test_bit (FR_FINISHED , &req->flags));
@@ -2295,7 +2295,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,if (nbytes !=sizeof (struct fuse_out_header )) err = -EINVAL ;else if (oh.error == -ENOSYS ) - fc->no_interrupt =1 ; + fc->chan->no_interrupt = true;else if (oh.error == -EAGAIN ) err =queue_interrupt (req);
fs/fuse/fuse_dev_i.h +3 -0
@@ -129,6 +129,9 @@ struct fuse_chan {/** The number of requests waiting for completion */ atomic_t num_waiting; +/** Is interrupt not implemented by fs? */ +bool no_interrupt; +/* Use io_uring for communication */ unsigned int io_uring;
fs/fuse/fuse_i.h +0 -3
@@ -659,9 +659,6 @@ struct fuse_conn {/** Is create not implemented by fs? */ unsigned no_create:1; -/** Is interrupt not implemented by fs? */ - unsigned no_interrupt:1; -/** Is bmap not implemented by fs? */ unsigned no_bmap:1;
Signature · 1 line
2.53.0
PATCH 10/32 fuse: split off fch->lock from fc->lock
In reply to Miklos SzerediAnd document which members they protect.
end_polls() is called with both, outer fch->lock is probably unnecessary, but doesn't hurt for now.
--- fs/fuse/dev.c | 29 ++++++++++++++++------------- fs/fuse/dev_uring.c | 12 ++++++------ fs/fuse/fuse_dev_i.h | 8 ++++++++ fs/fuse/fuse_i.h | 8 ++++++-- fs/fuse/req_timeout.c | 8 ++++---- 5 files changed, 40 insertions(+), 25 deletions(-)
fs/fuse/dev.c +16 -13
@@ -353,6 +353,7 @@ struct fuse_chan *fuse_chan_new(void)if (!fch)return NULL ; +spin_lock_init (&fch->lock);INIT_LIST_HEAD (&fch->devices);spin_lock_init (&fch->bg_lock);INIT_LIST_HEAD (&fch->bg_queue);
@@ -417,7 +418,7 @@ void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc) {struct fuse_conn *old_fc; -spin_lock (&fc->lock); +spin_lock (&fc->chan->lock);/* * Pairs with: * - xchg() in fuse_dev_release()
@@ -435,7 +436,7 @@ void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc)list_add_tail (&fud->entry, &fc->chan->devices);fuse_conn_get (fc); } -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock); }EXPORT_SYMBOL_GPL (fuse_dev_install);
@@ -462,9 +463,9 @@ void fuse_dev_put(struct fuse_dev *fud) fc =fuse_dev_fc_get (fud);if (fc && fc !=FUSE_DEV_FC_DISCONNECTED ) {/* This is the virtiofs case (fuse_dev_release() not called) */ -spin_lock (&fc->lock); +spin_lock (&fc->chan->lock);list_del (&fud->entry); -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);fuse_conn_put (fc); }
@@ -2055,9 +2056,9 @@ static void fuse_resend(struct fuse_conn *fc)LIST_HEAD (to_queue);unsigned int i; -spin_lock (&fc->lock); +spin_lock (&fc->chan->lock);if (!fc->chan->connected) { -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);return ; }
@@ -2069,7 +2070,7 @@ static void fuse_resend(struct fuse_conn *fc)list_splice_tail_init (&fpq->processing[i], &to_queue);spin_unlock (&fpq->lock); } -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);list_for_each_entry_safe (req, next, &to_queue, list) {set_bit (FR_PENDING , &req->flags);
@@ -2485,6 +2486,7 @@ static void end_polls(struct fuse_conn *fc) {struct rb_node *p; +spin_lock (&fc->lock); p =rb_first (&fc->polled_files);while (p) {
@@ -2494,6 +2496,7 @@ static void end_polls(struct fuse_conn *fc) p =rb_next (p); } +spin_unlock (&fc->lock); }/*
@@ -2518,7 +2521,7 @@ void fuse_abort_conn(struct fuse_conn *fc) {struct fuse_iqueue *fiq = &fc->chan->iq; -spin_lock (&fc->lock); +spin_lock (&fc->chan->lock);if (fc->chan->connected) {struct fuse_dev *fud;struct fuse_req *req, *next;
@@ -2573,17 +2576,17 @@ void fuse_abort_conn(struct fuse_conn *fc)kill_fasync (&fiq->fasync,SIGIO ,POLL_IN );end_polls (fc);wake_up_all (&fc->chan->blocked_waitq); -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);fuse_dev_end_requests (&to_end);/* -* fc->lock must not be taken to avoid conflicts with io-uring +* fc->chan->lock must not be taken to avoid conflicts with io-uring * locks */ fuse_uring_abort (fc); }else { -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock); } }EXPORT_SYMBOL_GPL (fuse_abort_conn);
@@ -2617,11 +2620,11 @@ int fuse_dev_release(struct inode *inode, struct file *file)fuse_dev_end_requests (&to_end); -spin_lock (&fc->lock); +spin_lock (&fc->chan->lock);list_del (&fud->entry);/* Are we the last open device? */ last =list_empty (&fc->chan->devices); -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);if (last) {WARN_ON (fc->chan->iq.fasync !=NULL );
fs/fuse/dev_uring.c +6 -6
@@ -243,10 +243,10 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc) max_payload_size =max (FUSE_MIN_READ_BUFFER , fc->max_write); max_payload_size =max (max_payload_size, fc->max_pages *PAGE_SIZE ); -spin_lock (&fc->lock); +spin_lock (&fc->chan->lock);if (fc->chan->ring) {/* race, another thread created the ring in the meantime */ -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock); res = fc->chan->ring; goto out_err; }
@@ -258,7 +258,7 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc) ring->max_payload_sz = max_payload_size;smp_store_release (&fc->chan->ring, ring); -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);return ring; out_err:
@@ -298,9 +298,9 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, queue->fpq.processing = pq;fuse_pqueue_init (&queue->fpq); -spin_lock (&fc->lock); +spin_lock (&fc->chan->lock);if (ring->queues[qid]) { -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);kfree (queue->fpq.processing);kfree (queue);return ring->queues[qid];
@@ -310,7 +310,7 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring,* write_once and lock as the caller mostly doesn't take the lock at all */ WRITE_ONCE (ring->queues[qid], queue); -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);return queue; }
fs/fuse/fuse_dev_i.h +8 -0
@@ -88,6 +88,14 @@ struct fuse_iqueue { };struct fuse_chan { +/** Lock protecting: +- devices +- connected +- ring +- ring->queues[qid] +*/ +spinlock_t lock; +/** Input queue */ struct fuse_iqueue iq;
fs/fuse/fuse_i.h +6 -2
@@ -421,7 +421,7 @@ enum fuse_req_flag {* * .waitq.lock protects the following fields: * - FR_ABORTED -* - FR_LOCKED (may also be modified under fc->lock, tested under both) +* - FR_LOCKED (may also be modified under fpq->lock, tested under both) */ struct fuse_req {/** This can be on either pending processing or io lists in
@@ -520,7 +520,11 @@ struct fuse_sync_bucket {* fuse_mount is destroyed. */ struct fuse_conn { -/** Lock protecting accessess to members of this structure */ +/** Lock protecting: +- polled_files +- backing_files_map +- curr_bucket +*/ spinlock_t lock;/** Refcount */
fs/fuse/req_timeout.c +4 -4
@@ -89,9 +89,9 @@ static void fuse_check_timeout(struct work_struct *work)if (expired) goto abort_conn; -spin_lock (&fc->lock); +spin_lock (&fc->chan->lock);if (!fc->chan->connected) { -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);return ; }list_for_each_entry (fud, &fc->chan->devices, entry) {
@@ -100,13 +100,13 @@ static void fuse_check_timeout(struct work_struct *work)if (fuse_request_expired (fc, &fpq->io) ||fuse_fpq_processing_expired (fc, fpq->processing)) {spin_unlock (&fpq->lock); -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock); goto abort_conn; }spin_unlock (&fpq->lock); } -spin_unlock (&fc->lock); +spin_unlock (&fc->chan->lock);if (fuse_uring_request_expired (fc)) goto abort_conn;
Signature · 1 line
2.53.0
PATCH 11/32 fuse: add back pointer from fuse_chan to fuse_conn
In reply to Miklos SzerediWill be needed by callbacks from the transport layer to the fs layer.
--- fs/fuse/fuse_dev_i.h | 3 +++ fs/fuse/inode.c | 1 + 2 files changed, 4 insertions(+)
fs/fuse/fuse_dev_i.h +3 -0
@@ -96,6 +96,9 @@ struct fuse_chan {*/ spinlock_t lock; +/* back pointer: fc->chan->conn == fc */ +struct fuse_conn *conn; +/** Input queue */ struct fuse_iqueue iq;
fs/fuse/inode.c +1 -0
@@ -995,6 +995,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,INIT_LIST_HEAD (&fc->mounts);list_add (&fm->fc_entry, &fc->mounts); fm->fc = fc; + fch->conn = fc; fc->chan = fch; }EXPORT_SYMBOL_GPL (fuse_conn_init);
Signature · 1 line
2.53.0
PATCH 12/32 fuse: move request timeout to fuse_chan
In reply to Miklos SzerediMove:
- timeout
--- fs/fuse/dev.c | 5 ++-- fs/fuse/dev.h | 2 +- fs/fuse/dev_uring.c | 16 ++++++------ fs/fuse/dev_uring_i.h | 4 +-- fs/fuse/fuse_dev_i.h | 11 ++++++++- fs/fuse/fuse_i.h | 9 ------- fs/fuse/inode.c | 7 +++--- fs/fuse/req_timeout.c | 57 +++++++++++++++++++++---------------------- 8 files changed, 55 insertions(+), 56 deletions(-)
fs/fuse/dev.c +3 -2
@@ -363,6 +363,7 @@ struct fuse_chan *fuse_chan_new(void) fch->initialized =0 ; fch->blocked =0 ; fch->connected =1 ; + fch->timeout.req_timeout =0 ;return fch; }
@@ -2528,8 +2529,8 @@ void fuse_abort_conn(struct fuse_conn *fc)LIST_HEAD (to_end);unsigned int i; -if (fc->timeout.req_timeout) -cancel_delayed_work (&fc->timeout.work); +if (fc->chan->timeout.req_timeout) +cancel_delayed_work (&fc->chan->timeout.work);/* Background queuing checks fc->chan->connected under bg_lock */ spin_lock (&fc->chan->bg_lock);
fs/fuse/dev.h +1 -1
@@ -21,6 +21,6 @@ DEFINE_FREE(fuse_chan_free, struct fuse_chan *, if (_T) fuse_chan_free(_T))void fuse_dev_install (struct fuse_dev *fud,struct fuse_conn *fc);void fuse_dev_put (struct fuse_dev *fud); -void fuse_init_server_timeout (struct fuse_conn *fc,unsigned int timeout); +void fuse_init_server_timeout (struct fuse_chan *fch,unsigned int timeout);#endif /* _FS_FUSE_DEV_H */
fs/fuse/dev_uring.c +8 -8
@@ -142,7 +142,7 @@ void fuse_uring_abort_end_requests(struct fuse_ring *ring) } } -static bool ent_list_request_expired (struct fuse_conn *fc,struct list_head *list) +static bool ent_list_request_expired (struct fuse_chan *fch,struct list_head *list) {struct fuse_ring_ent *ent;struct fuse_req *req;
@@ -154,12 +154,12 @@ static bool ent_list_request_expired(struct fuse_conn *fc, struct list_head *lis req = ent->fuse_req;return time_is_before_jiffies (req->create_time + - fc->timeout.req_timeout); + fch->timeout.req_timeout); } -bool fuse_uring_request_expired (struct fuse_conn *fc) +bool fuse_uring_request_expired (struct fuse_chan *fch) { -struct fuse_ring *ring = fc->chan->ring; +struct fuse_ring *ring = fch->ring;struct fuse_ring_queue *queue;int qid;
@@ -172,10 +172,10 @@ bool fuse_uring_request_expired(struct fuse_conn *fc)continue ;spin_lock (&queue->lock); -if (fuse_request_expired (fc, &queue->fuse_req_queue) || -fuse_request_expired (fc, &queue->fuse_req_bg_queue) || -ent_list_request_expired (fc, &queue->ent_w_req_queue) || -ent_list_request_expired (fc, &queue->ent_in_userspace)) { +if (fuse_request_expired (fch, &queue->fuse_req_queue) || +fuse_request_expired (fch, &queue->fuse_req_bg_queue) || +ent_list_request_expired (fch, &queue->ent_w_req_queue) || +ent_list_request_expired (fch, &queue->ent_in_userspace)) {spin_unlock (&queue->lock);return true; }
fs/fuse/dev_uring_i.h +2 -2
@@ -144,7 +144,7 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags);void fuse_uring_queue_fuse_req (struct fuse_iqueue *fiq,struct fuse_req *req);bool fuse_uring_queue_bq_req (struct fuse_req *req);bool fuse_uring_remove_pending_req (struct fuse_req *req); -bool fuse_uring_request_expired (struct fuse_conn *fc); +bool fuse_uring_request_expired (struct fuse_chan *fch);static inline void fuse_uring_abort (struct fuse_conn *fc) {
@@ -202,7 +202,7 @@ static inline bool fuse_uring_remove_pending_req(struct fuse_req *req)return false; } -static inline bool fuse_uring_request_expired (struct fuse_conn *fc) +static inline bool fuse_uring_request_expired (struct fuse_chan *fch) {return false; }
fs/fuse/fuse_dev_i.h +10 -1
@@ -150,6 +150,15 @@ struct fuse_chan {/** uring connection information*/ struct fuse_ring *ring;#endif + +/** Only used if the connection opts into request timeouts */ +struct { +/* Worker for checking if any requests have timed out */ +struct delayed_work work; + +/* Request timeout (in jiffies). 0 = no timeout */ +unsigned int req_timeout; + } timeout; };#define FUSE_PQ_HASH_BITS 8
@@ -261,7 +270,7 @@ void fuse_dev_queue_forget(struct fuse_iqueue *fiq,void fuse_dev_queue_interrupt (struct fuse_iqueue *fiq,struct fuse_req *req);bool fuse_remove_pending_req (struct fuse_req *req,spinlock_t *lock); -bool fuse_request_expired (struct fuse_conn *fc,struct list_head *list); +bool fuse_request_expired (struct fuse_chan *fch,struct list_head *list);/** * Assign a unique id to a fuse request
fs/fuse/fuse_i.h +0 -9
@@ -816,15 +816,6 @@ struct fuse_conn {/** IDR for backing files ids */ struct idr backing_files_map;#endif - -/** Only used if the connection opts into request timeouts */ -struct { -/* Worker for checking if any requests have timed out */ -struct delayed_work work; - -/* Request timeout (in jiffies). 0 = no timeout */ -unsigned int req_timeout; - } timeout; };/*
fs/fuse/inode.c +3 -4
@@ -987,7 +987,6 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm, fc->max_pages =FUSE_DEFAULT_MAX_PAGES_PER_REQ ; fc->max_pages_limit = fuse_max_pages_limit; fc->name_max =FUSE_NAME_LOW_MAX ; - fc->timeout.req_timeout =0 ;if (IS_ENABLED (CONFIG_FUSE_PASSTHROUGH ))fuse_backing_files_init (fc);
@@ -1020,8 +1019,8 @@ void fuse_conn_put(struct fuse_conn *fc)if (IS_ENABLED (CONFIG_FUSE_DAX ))fuse_dax_conn_free (fc); -if (fc->timeout.req_timeout) -cancel_delayed_work_sync (&fc->timeout.work); +if (fc->chan->timeout.req_timeout) +cancel_delayed_work_sync (&fc->chan->timeout.work);cancel_work_sync (&fc->epoch_work);fuse_chan_release (fc->chan);put_pid_ns (fc->pid_ns);
@@ -1423,7 +1422,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, fc->no_flock =1 ; } -fuse_init_server_timeout (fc, timeout); +fuse_init_server_timeout (fc->chan, timeout); fm->sb->s_bdi->ra_pages =min (fm->sb->s_bdi->ra_pages, ra_pages);
fs/fuse/req_timeout.c +28 -29
124 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 13/32 fuse: move struct fuse_req and related to fuse_dev_i.h
In reply to Miklos Szeredi--- fs/fuse/fuse_dev_i.h | 91 +++++++++++++++++++++++++++++++++++++++++++- fs/fuse/fuse_i.h | 91 -------------------------------------------- 2 files changed, 90 insertions(+), 92 deletions(-)
fs/fuse/fuse_dev_i.h +90 -1
@@ -17,10 +17,95 @@ extern struct wait_queue_head fuse_dev_waitq;struct fuse_arg ;struct fuse_args ;struct fuse_pqueue ; -struct fuse_req ;struct fuse_iqueue ;struct fuse_forget_link ; +/** +* Request flags +* +* FR_ISREPLY: set if the request has reply +* FR_FORCE: force sending of the request even if interrupted +* FR_BACKGROUND: request is sent in the background +* FR_WAITING: request is counted as "waiting" +* FR_ABORTED: the request was aborted +* FR_INTERRUPTED: the request has been interrupted +* FR_LOCKED: data is being copied to/from the request +* FR_PENDING: request is not yet in userspace +* FR_SENT: request is in userspace, waiting for an answer +* FR_FINISHED: request is finished +* FR_PRIVATE: request is on private list +* FR_ASYNC: request is asynchronous +* FR_URING: request is handled through fuse-io-uring +*/ +enum fuse_req_flag { +FR_ISREPLY , +FR_FORCE , +FR_BACKGROUND , +FR_WAITING , +FR_ABORTED , +FR_INTERRUPTED , +FR_LOCKED , +FR_PENDING , +FR_SENT , +FR_FINISHED , +FR_PRIVATE , +FR_ASYNC , +FR_URING , +}; + +/** +* A request to the client +* +* .waitq.lock protects the following fields: +* - FR_ABORTED +* - FR_LOCKED (may also be modified under fpq->lock, tested under both) +*/ +struct fuse_req { +/** This can be on either pending processing or io lists in +fuse_conn */ +struct list_head list; + +/** Entry on the interrupts list */ +struct list_head intr_entry; + +/* Input/output arguments */ +struct fuse_args *args; + +/** refcount */ +refcount_t count; + +/* Request flags, updated with test/set/clear_bit() */ +unsigned long flags; + +/* The request input header */ +struct { +struct fuse_in_header h; + } in; + +/* The request output header */ +struct { +struct fuse_out_header h; + } out; + +/** Used to wake up the task waiting for completion of request*/ +wait_queue_head_t waitq; + +#if IS_ENABLED (CONFIG_VIRTIO_FS ) +/** virtio-fs's physically contiguous buffer for in and out args */ +void *argbuf; +#endif + +/** fuse_mount this request belongs to */ +struct fuse_mount *fm; + +#ifdef CONFIG_FUSE_IO_URING +void *ring_entry; +void *ring_queue; +#endif +/** When (in jiffies) the request was created */ +unsigned long create_time; +}; +/** * Input queue callbacks *
@@ -290,6 +375,10 @@ struct fuse_dev *fuse_dev_alloc(void);*/ void fuse_pqueue_init (struct fuse_pqueue *fpq); +/** +* End a finished request +*/ +void fuse_request_end (struct fuse_req *req);#endif
fs/fuse/fuse_i.h +0 -91
103 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 14/32 fuse: don't access transport layer structs directly from the fs layer
In reply to Miklos SzerediAdd helpers (get and set functions mainly) that cleanly separate the layers.
Remove #include "fuse_dev_i.h" from:
- inode.c
- file.c
- control.c
Remove #include "dev_uring_i.h" from inode.c.
--- fs/fuse/control.c | 13 +++----- fs/fuse/dev.c | 77 ++++++++++++++++++++++++++++++++++++++++--- fs/fuse/dev.h | 27 +++++++++++++++ fs/fuse/dev_uring.c | 7 ++-- fs/fuse/dev_uring_i.h | 11 ------- fs/fuse/file.c | 6 ++-- fs/fuse/fuse_i.h | 2 -- fs/fuse/inode.c | 36 ++++++++------------ 8 files changed, 124 insertions(+), 55 deletions(-)
fs/fuse/control.c +4 -9
@@ -7,7 +7,7 @@*/ #include "fuse_i.h" -#include "fuse_dev_i.h" +#include "dev.h" #include <linux/init.h> #include <linux/module.h>
@@ -58,7 +58,7 @@ static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,if (!fc)return 0 ; - value =atomic_read (&fc->chan->num_waiting); + value =fuse_chan_num_waiting (fc->chan); file->private_data = (void *)value;fuse_conn_put (fc); }
@@ -112,7 +112,7 @@ static ssize_t fuse_conn_max_background_read(struct file *file,if (!fc)return 0 ; - val =READ_ONCE (fc->chan->max_background); + val =fuse_chan_max_background (fc->chan);fuse_conn_put (fc);return fuse_conn_limit_read (file, buf, len, ppos, val);
@@ -130,12 +130,7 @@ static ssize_t fuse_conn_max_background_write(struct file *file,if (ret >0 ) {struct fuse_conn *fc =fuse_ctl_file_conn_get (file);if (fc) { -spin_lock (&fc->chan->bg_lock); - fc->chan->max_background = val; - fc->chan->blocked = fc->chan->num_background >= fc->chan->max_background; -if (!fc->chan->blocked) -wake_up (&fc->chan->blocked_waitq); -spin_unlock (&fc->chan->bg_lock); +fuse_chan_max_background_set (fc->chan, val);fuse_conn_put (fc); } }
fs/fuse/dev.c +72 -5
122 lines not on this page · raw message
fs/fuse/dev.h +27 -0
@@ -11,16 +11,43 @@struct fuse_conn ;struct fuse_chan ;struct fuse_dev ; +struct file ;struct fuse_chan *fuse_chan_new (void );struct fuse_chan *fuse_dev_chan_new (void );void fuse_chan_release (struct fuse_chan *fch);void fuse_chan_free (struct fuse_chan *fch); +unsigned int fuse_chan_num_background (struct fuse_chan *fch); +unsigned int fuse_chan_max_background (struct fuse_chan *fch); +void fuse_chan_max_background_set (struct fuse_chan *fch,unsigned int val); +unsigned int fuse_chan_num_waiting (struct fuse_chan *fch); +void fuse_chan_set_fc (struct fuse_chan *fch,struct fuse_conn *fc); +void fuse_chan_set_initialized (struct fuse_chan *fch); +void fuse_chan_io_uring_enable (struct fuse_chan *fch); + DEFINE_FREE(fuse_chan_free, struct fuse_chan *, if (_T) fuse_chan_free(_T))void fuse_dev_install (struct fuse_dev *fud,struct fuse_conn *fc); +bool fuse_dev_verify (struct fuse_dev *fud,struct fuse_conn *fc);void fuse_dev_put (struct fuse_dev *fud); +bool fuse_dev_is_installed (struct fuse_dev *fud); +bool fuse_dev_is_sync_init (struct fuse_dev *fud); +struct fuse_dev *fuse_dev_grab (struct file *file);void fuse_init_server_timeout (struct fuse_chan *fch,unsigned int timeout); +#ifdef CONFIG_FUSE_IO_URING +bool fuse_uring_enabled (void ); +void fuse_uring_destruct (struct fuse_chan *fch); +#else /* CONFIG_FUSE_IO_URING */ +static inline bool fuse_uring_enabled (void ) +{ +return false; +} + +static inline void fuse_uring_destruct (struct fuse_chan *fch) +{ +} +#endif /* CONFIG_FUSE_IO_URING */ +#endif /* _FS_FUSE_DEV_H */
fs/fuse/dev_uring.c +4 -3
@@ -4,6 +4,7 @@* Copyright (c) 2023-2024 DataDirect Networks. */ +#include "dev.h" #include "fuse_i.h" #include "dev_uring_i.h" #include "fuse_dev_i.h"
@@ -185,9 +186,9 @@ bool fuse_uring_request_expired(struct fuse_chan *fch)return false; } -void fuse_uring_destruct (struct fuse_conn *fc) +void fuse_uring_destruct (struct fuse_chan *fch) { -struct fuse_ring *ring = fc->chan->ring; +struct fuse_ring *ring = fch->ring;int qid;if (!ring)
@@ -218,7 +219,7 @@ void fuse_uring_destruct(struct fuse_conn *fc)kfree (ring->queues);kfree (ring); - fc->chan->ring =NULL ; + fch->ring =NULL ; }/*
fs/fuse/dev_uring_i.h +0 -11
@@ -136,8 +136,6 @@ struct fuse_ring {bool ready; }; -bool fuse_uring_enabled (void ); -void fuse_uring_destruct (struct fuse_conn *fc);void fuse_uring_stop_queues (struct fuse_ring *ring);void fuse_uring_abort_end_requests (struct fuse_ring *ring);int fuse_uring_cmd (struct io_uring_cmd *cmd,unsigned int issue_flags);
@@ -175,15 +173,6 @@ static inline bool fuse_uring_ready(struct fuse_conn *fc)#else /* CONFIG_FUSE_IO_URING */ -static inline void fuse_uring_destruct (struct fuse_conn *fc) -{ -} - -static inline bool fuse_uring_enabled (void ) -{ -return false; -} -static inline void fuse_uring_abort (struct fuse_conn *fc) { }
fs/fuse/file.c +3 -3
@@ -7,7 +7,7 @@*/ #include "fuse_i.h" -#include "fuse_dev_i.h" +#include "dev.h" #include <linux/pagemap.h> #include <linux/slab.h>
@@ -903,7 +903,7 @@ static int fuse_handle_readahead(struct folio *folio, ia =NULL ; }if (!ia) { -if (fc->chan->num_background >= fc->congestion_threshold && +if (fuse_chan_num_background (fc->chan) >= fc->congestion_threshold && rac->ra->async_size >=readahead_count (rac))/* * Congested and only async pages left, so skip the
@@ -2294,7 +2294,7 @@ static int fuse_writepages(struct address_space *mapping,return -EIO ;if (wbc->sync_mode ==WB_SYNC_NONE && - fc->chan->num_background >= fc->congestion_threshold) +fuse_chan_num_background (fc->chan) >= fc->congestion_threshold)return 0 ;return iomap_writepages (&wpc);
fs/fuse/fuse_i.h +0 -2
@@ -1184,8 +1184,6 @@ int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);int fuse_do_setattr (struct mnt_idmap *idmap,struct dentry *dentry,struct iattr *attr,struct file *file); -void fuse_set_initialized (struct fuse_conn *fc); -void fuse_unlock_inode (struct inode *inode,bool locked);bool fuse_lock_inode (struct inode *inode);
fs/fuse/inode.c +14 -22
@@ -8,8 +8,6 @@#include "dev.h" #include "fuse_i.h" -#include "fuse_dev_i.h" -#include "dev_uring_i.h" #include <linux/dax.h> #include <linux/pagemap.h>
@@ -812,8 +810,7 @@ static int fuse_opt_fd(struct fs_context *fsc, struct file *file)if (file->f_cred->user_ns != fsc->user_ns)return invalfc (fsc,"wrong user namespace for fuse device" ); - ctx->fud = file->private_data; -refcount_inc (&ctx->fud->ref); + ctx->fud =fuse_dev_grab (file);return 0 ; }
@@ -994,7 +991,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,INIT_LIST_HEAD (&fc->mounts);list_add (&fm->fc_entry, &fc->mounts); fm->fc = fc; - fch->conn = fc; +fuse_chan_set_fc (fch, fc); fc->chan = fch; }EXPORT_SYMBOL_GPL (fuse_conn_init);
@@ -1003,7 +1000,7 @@ static void delayed_release(struct rcu_head *p) { struct fuse_conn *fc = container_of(p, struct fuse_conn, rcu); -fuse_uring_destruct (fc); +fuse_uring_destruct (fc->chan);fuse_chan_free (fc->chan);put_user_ns (fc->user_ns);
@@ -1019,8 +1016,6 @@ void fuse_conn_put(struct fuse_conn *fc)if (IS_ENABLED (CONFIG_FUSE_DAX ))fuse_dax_conn_free (fc); -if (fc->chan->timeout.req_timeout) -cancel_delayed_work_sync (&fc->chan->timeout.work);cancel_work_sync (&fc->epoch_work);fuse_chan_release (fc->chan);put_pid_ns (fc->pid_ns);
@@ -1253,12 +1248,13 @@ static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg)sanitize_global_limit (&max_user_bgreq);sanitize_global_limit (&max_user_congthresh); -spin_lock (&fc->chan->bg_lock);if (arg->max_background) { - fc->chan->max_background = arg->max_background; +unsigned int max_background = max_background = arg->max_background; -if (!cap_sys_admin && fc->chan->max_background > max_user_bgreq) - fc->chan->max_background = max_user_bgreq; +if (!cap_sys_admin && max_background > max_user_bgreq) + max_background = max_user_bgreq; + +fuse_chan_max_background_set (fc->chan, max_background); }if (arg->congestion_threshold) { fc->congestion_threshold = arg->congestion_threshold;
@@ -1267,7 +1263,6 @@ static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg) fc->congestion_threshold > max_user_congthresh) fc->congestion_threshold = max_user_congthresh; } -spin_unlock (&fc->chan->bg_lock); }struct fuse_init_args {
@@ -1412,7 +1407,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, ok = false; }if (flags &FUSE_OVER_IO_URING &&fuse_uring_enabled ()) - fc->chan->io_uring =1 ; +fuse_chan_io_uring_enable (fc->chan);if (flags &FUSE_REQUEST_TIMEOUT ) timeout = arg->request_timeout;
@@ -1438,8 +1433,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, fc->conn_error =1 ; } -fuse_set_initialized (fc); -wake_up_all (&fc->chan->blocked_waitq); +fuse_chan_set_initialized (fc->chan); }static struct fuse_init_args *fuse_new_init (struct fuse_mount *fm)
@@ -1787,9 +1781,9 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)mutex_lock (&fuse_mutex); err = -EINVAL ;if (fud) { -if (fuse_dev_fc_get (fud)) +if (fuse_dev_is_installed (fud)) goto err_unlock; -if (fud->sync_init) +if (fuse_dev_is_sync_init (fud)) fc->sync_init =1 ; }
@@ -1847,9 +1841,7 @@ static int fuse_set_no_super(struct super_block *sb, struct fs_context *fsc)static int fuse_test_super (struct super_block *sb,struct fs_context *fsc) { -struct fuse_dev *fud = fsc->sget_key; - -return fuse_dev_fc_get (fud) ==get_fuse_conn_super (sb); +return fuse_dev_verify (fsc->sget_key,get_fuse_conn_super (sb)); }static int fuse_get_tree (struct fs_context *fsc)
@@ -1895,7 +1887,7 @@ static int fuse_get_tree(struct fs_context *fsc)* Allow creating a fuse mount with an already initialized fuse * connection */ -if (fuse_dev_fc_get (ctx->fud)) { +if (fuse_dev_is_installed (ctx->fud)) { fsc->sget_key = ctx->fud; sb =sget_fc (fsc, fuse_test_super, fuse_set_no_super); err =PTR_ERR_OR_ZERO (sb);
Signature · 1 line
2.53.0
PATCH 15/32 fuse: move forget related struct and helpers
In reply to Miklos SzerediMove:
- struct fuse_forget_link to fuse_dev_i.h
- fuse_alloc_forget() to dev.c/dev.h
Rename:
- fuse_queue_forget -> fuse_chan_queue_forget
--- fs/fuse/dev.c | 11 ++++++++--- fs/fuse/dev.h | 5 +++++ fs/fuse/dir.c | 9 +++++---- fs/fuse/fuse_dev_i.h | 8 +++++++- fs/fuse/fuse_i.h | 14 +------------- fs/fuse/inode.c | 11 +++-------- 6 files changed, 29 insertions(+), 29 deletions(-)
fs/fuse/dev.c +8 -3
@@ -243,6 +243,11 @@ __releases(fiq->lock)spin_unlock (&fiq->lock); } +struct fuse_forget_link *fuse_alloc_forget (void ) +{ + return kzalloc_obj(struct fuse_forget_link, GFP_KERNEL_ACCOUNT); +} +void fuse_dev_queue_forget (struct fuse_iqueue *fiq,struct fuse_forget_link *forget) {
@@ -550,10 +555,10 @@ static void fuse_send_one(struct fuse_iqueue *fiq, struct fuse_req *req) fiq->ops->send_req (fiq, req); } -void fuse_queue_forget (struct fuse_conn *fc,struct fuse_forget_link *forget, -u64 nodeid,u64 nlookup) +void fuse_chan_queue_forget (struct fuse_chan *fch,struct fuse_forget_link *forget, +u64 nodeid,u64 nlookup) { -struct fuse_iqueue *fiq = &fc->chan->iq; +struct fuse_iqueue *fiq = &fch->iq; forget->forget_one.nodeid = nodeid; forget->forget_one.nlookup = nlookup;
fs/fuse/dev.h +5 -0
@@ -25,6 +25,11 @@ void fuse_chan_set_fc(struct fuse_chan *fch, struct fuse_conn *fc);void fuse_chan_set_initialized (struct fuse_chan *fch);void fuse_chan_io_uring_enable (struct fuse_chan *fch); +struct fuse_forget_link *fuse_alloc_forget (void ); +void fuse_chan_queue_forget (struct fuse_chan *fch,struct fuse_forget_link *forget, +u64 nodeid,u64 nlookup); + + DEFINE_FREE(fuse_chan_free, struct fuse_chan *, if (_T) fuse_chan_free(_T))void fuse_dev_install (struct fuse_dev *fud,struct fuse_conn *fc);
fs/fuse/dir.c +5 -4
@@ -6,6 +6,7 @@See the file COPYING. */ +#include "dev.h" #include "fuse_i.h" #include <linux/pagemap.h>
@@ -430,7 +431,7 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name, fi =get_fuse_inode (inode);if (outarg.nodeid !=get_node_id (inode) || (bool )IS_AUTOMOUNT (inode) != (bool ) (outarg.attr.flags &FUSE_ATTR_SUBMOUNT )) { -fuse_queue_forget (fm->fc, forget, +fuse_chan_queue_forget (fm->fc->chan, forget, outarg.nodeid,1 ); goto invalid; }
@@ -593,7 +594,7 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name attr_version, evict_ctr); err = -ENOMEM ;if (!*inode) { -fuse_queue_forget (fm->fc, forget, outarg->nodeid,1 ); +fuse_chan_queue_forget (fm->fc->chan, forget, outarg->nodeid,1 ); goto out; } err =0 ;
@@ -894,7 +895,7 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,if (!inode) { flags &= ~(O_CREAT |O_EXCL |O_TRUNC );fuse_sync_release (NULL , ff, flags); -fuse_queue_forget (fm->fc, forget, outentry.nodeid,1 ); +fuse_chan_queue_forget (fm->fc->chan, forget, outentry.nodeid,1 ); err = -ENOMEM ; goto out_err; }
@@ -1019,7 +1020,7 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun inode =fuse_iget (dir->i_sb, outarg.nodeid, outarg.generation, &outarg.attr,ATTR_TIMEOUT (&outarg),0 ,0 );if (!inode) { -fuse_queue_forget (fm->fc, forget, outarg.nodeid,1 ); +fuse_chan_queue_forget (fm->fc->chan, forget, outarg.nodeid,1 );return ERR_PTR (-ENOMEM ); }kfree (forget);
fs/fuse/fuse_dev_i.h +7 -1
@@ -6,6 +6,7 @@#ifndef _FS_FUSE_DEV_I_H#define _FS_FUSE_DEV_I_H +#include <linux/fuse.h> #include <linux/types.h> /* Ordinary requests have even IDs, while interrupts IDs are odd */
@@ -18,7 +19,6 @@ struct fuse_arg;struct fuse_args ;struct fuse_pqueue ;struct fuse_iqueue ; -struct fuse_forget_link ;/** * Request flags
@@ -106,6 +106,12 @@ struct fuse_req {unsigned long create_time; }; +/* One forget request */ +struct fuse_forget_link { +struct fuse_forget_one forget_one; +struct fuse_forget_link *next; +}; +/** * Input queue callbacks *
fs/fuse/fuse_i.h +1 -13
@@ -68,11 +68,7 @@ extern struct mutex fuse_mutex;extern unsigned int max_user_bgreq;extern unsigned int max_user_congthresh; -/* One forget request */ -struct fuse_forget_link { -struct fuse_forget_one forget_one; -struct fuse_forget_link *next; -}; +struct fuse_forget_link ;/* Submount lookup tracking */ struct fuse_submount_lookup {
@@ -883,14 +879,6 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,int fuse_lookup_name (struct super_block *sb,u64 nodeid,const struct qstr *name,struct fuse_entry_out *outarg,struct inode **inode); -/** -* Send FORGET command -*/ -void fuse_queue_forget (struct fuse_conn *fc,struct fuse_forget_link *forget, -u64 nodeid,u64 nlookup); - -struct fuse_forget_link *fuse_alloc_forget (void ); -/* * Initialize READ or READDIR request */
fs/fuse/inode.c +3 -8
@@ -66,11 +66,6 @@ MODULE_PARM_DESC(max_user_congthresh,static struct file_system_type fuseblk_fs_type;#endif -struct fuse_forget_link *fuse_alloc_forget (void ) -{ - return kzalloc_obj(struct fuse_forget_link, GFP_KERNEL_ACCOUNT); -} -static struct fuse_submount_lookup *fuse_alloc_submount_lookup (void ) {struct fuse_submount_lookup *sl;
@@ -144,7 +139,7 @@ static void fuse_cleanup_submount_lookup(struct fuse_conn *fc,if (!refcount_dec_and_test (&sl->count))return ; -fuse_queue_forget (fc, sl->forget, sl->nodeid,1 ); +fuse_chan_queue_forget (fc->chan, sl->forget, sl->nodeid,1 ); sl->forget =NULL ;kfree (sl); }
@@ -167,8 +162,8 @@ static void fuse_evict_inode(struct inode *inode)if (FUSE_IS_DAX (inode))fuse_dax_inode_cleanup (inode);if (fi->nlookup) { -fuse_queue_forget (fc, fi->forget, fi->nodeid, - fi->nlookup); +fuse_chan_queue_forget (fc->chan, fi->forget, fi->nodeid, + fi->nlookup); fi->forget =NULL ; }
Signature · 1 line
2.53.0
PATCH 16/32 fuse: move fuse_dev_waitq to dev.c
In reply to Miklos SzerediMove wake_up_all(&fuse_dev_waitq) into fuse_dev_install() where it logically belongs.
--- fs/fuse/dev.c | 3 +++ fs/fuse/fuse_dev_i.h | 2 -- fs/fuse/inode.c | 6 ++---- 3 files changed, 5 insertions(+), 6 deletions(-)
fs/fuse/dev.c +3 -0
@@ -31,6 +31,8 @@MODULE_ALIAS_MISCDEV (FUSE_MINOR );MODULE_ALIAS ("devname:fuse" ); +static DECLARE_WAIT_QUEUE_HEAD (fuse_dev_waitq); +static struct kmem_cache *fuse_req_cachep;static void fuse_request_init (struct fuse_mount *fm,struct fuse_req *req)
@@ -480,6 +482,7 @@ void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc) }else {list_add_tail (&fud->entry, &fc->chan->devices);fuse_conn_get (fc); +wake_up_all (&fuse_dev_waitq); }spin_unlock (&fc->chan->lock); }
fs/fuse/fuse_dev_i.h +0 -2
@@ -13,8 +13,6 @@#define FUSE_INT_REQ_BIT (1ULL << 0)#define FUSE_REQ_ID_STEP (1ULL << 1) -extern struct wait_queue_head fuse_dev_waitq; -struct fuse_arg ;struct fuse_args ;struct fuse_pqueue ;
fs/fuse/inode.c +2 -4
@@ -34,7 +34,6 @@ MODULE_LICENSE("GPL");static struct kmem_cache *fuse_inode_cachep;struct list_head fuse_conn_list;DEFINE_MUTEX (fuse_mutex); -DECLARE_WAIT_QUEUE_HEAD (fuse_dev_waitq);static int set_global_limit (const char *val,const struct kernel_param *kp);
@@ -1788,10 +1787,9 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)list_add_tail (&fc->entry, &fuse_conn_list); sb->s_root = root_dentry; -if (fud) { +if (fud)fuse_dev_install (fud, fc); -wake_up_all (&fuse_dev_waitq); - } +mutex_unlock (&fuse_mutex);return 0 ;
Signature · 1 line
2.53.0
PATCH 17/32 fuse: remove #include "fuse_i.h" from "dev_uring_i.h"
In reply to Miklos SzerediStart getting rid of fs layer stuff from transport layer files.
--- fs/fuse/dev.c | 8 ++++---- fs/fuse/dev_uring_i.h | 19 +++++++++---------- fs/fuse/fuse_dev_i.h | 4 ++++ 3 files changed, 17 insertions(+), 14 deletions(-)
fs/fuse/dev.c +4 -4
@@ -82,7 +82,7 @@ void fuse_chan_set_initialized(struct fuse_chan *fch)static bool fuse_block_alloc (struct fuse_conn *fc,bool for_background) {return !fc->chan->initialized || (for_background && fc->chan->blocked) || - (fc->chan->io_uring && fc->chan->connected && !fuse_uring_ready (fc)); + (fc->chan->io_uring && fc->chan->connected && !fuse_uring_ready (fc->chan)); }static void fuse_drop_waiting (struct fuse_conn *fc)
@@ -876,7 +876,7 @@ static int fuse_request_queue_background(struct fuse_req *req)__set_bit (FR_ISREPLY , &req->flags);#ifdef CONFIG_FUSE_IO_URING -if (fuse_uring_ready (fc)) +if (fuse_uring_ready (fc->chan))return fuse_request_queue_background_uring (fc, req);#endif
@@ -2660,7 +2660,7 @@ void fuse_abort_conn(struct fuse_conn *fc)* fc->chan->lock must not be taken to avoid conflicts with io-uring * locks */ -fuse_uring_abort (fc); +fuse_uring_abort (fc->chan); }else {spin_unlock (&fc->chan->lock); }
@@ -2673,7 +2673,7 @@ void fuse_wait_aborted(struct fuse_conn *fc)smp_mb ();wait_event (fc->chan->blocked_waitq,fuse_chan_num_waiting (fc->chan) ==0 ); -fuse_uring_wait_stopped_queues (fc); +fuse_uring_wait_stopped_queues (fc->chan); }int fuse_dev_release (struct inode *inode,struct file *file)
fs/fuse/dev_uring_i.h +9 -10
@@ -7,7 +7,6 @@#ifndef _FS_FUSE_DEV_URING_I_H#define _FS_FUSE_DEV_URING_I_H -#include "fuse_i.h" #include "fuse_dev_i.h" #ifdef CONFIG_FUSE_IO_URING
@@ -144,9 +143,9 @@ bool fuse_uring_queue_bq_req(struct fuse_req *req);bool fuse_uring_remove_pending_req (struct fuse_req *req);bool fuse_uring_request_expired (struct fuse_chan *fch); -static inline void fuse_uring_abort (struct fuse_conn *fc) +static inline void fuse_uring_abort (struct fuse_chan *fch) { -struct fuse_ring *ring = fc->chan->ring; +struct fuse_ring *ring = fch->ring;if (ring ==NULL )return ;
@@ -157,31 +156,31 @@ static inline void fuse_uring_abort(struct fuse_conn *fc) } } -static inline void fuse_uring_wait_stopped_queues (struct fuse_conn *fc) +static inline void fuse_uring_wait_stopped_queues (struct fuse_chan *fch) { -struct fuse_ring *ring = fc->chan->ring; +struct fuse_ring *ring = fch->ring;if (ring)wait_event (ring->stop_waitq,atomic_read (&ring->queue_refs) ==0 ); } -static inline bool fuse_uring_ready (struct fuse_conn *fc) +static inline bool fuse_uring_ready (struct fuse_chan *fch) { -return fc->chan->ring && fc->chan->ring->ready; +return fch->ring && fch->ring->ready; }#else /* CONFIG_FUSE_IO_URING */ -static inline void fuse_uring_abort (struct fuse_conn *fc) +static inline void fuse_uring_abort (struct fuse_chan *fch) { } -static inline void fuse_uring_wait_stopped_queues (struct fuse_conn *fc) +static inline void fuse_uring_wait_stopped_queues (struct fuse_chan *fch) { } -static inline bool fuse_uring_ready (struct fuse_conn *fc) +static inline bool fuse_uring_ready (struct fuse_chan *fch) {return false; }
fs/fuse/fuse_dev_i.h +4 -0
@@ -8,6 +8,10 @@#include <linux/fuse.h> #include <linux/types.h> +#include <linux/refcount.h> +#include <linux/wait.h> +#include <linux/workqueue.h> +#include <linux/fs.h> /* Ordinary requests have even IDs, while interrupts IDs are odd */ #define FUSE_INT_REQ_BIT (1ULL << 0)
Signature · 1 line
2.53.0
PATCH 18/32 fuse: remove #include "fuse_i.h" from "req_timeout.c"
In reply to Miklos SzerediJust need to move fuse_abort_conn().
--- fs/fuse/dev.h | 3 +++ fs/fuse/fuse_i.h | 2 -- fs/fuse/req_timeout.c | 1 - 3 files changed, 3 insertions(+), 3 deletions(-)
fs/fuse/dev.h +3 -0
@@ -41,6 +41,9 @@ struct fuse_dev *fuse_dev_grab(struct file *file);void fuse_init_server_timeout (struct fuse_chan *fch,unsigned int timeout); +/* Abort all requests */ +void fuse_abort_conn (struct fuse_conn *fc); +#ifdef CONFIG_FUSE_IO_URING bool fuse_uring_enabled (void );void fuse_uring_destruct (struct fuse_chan *fch);
fs/fuse/fuse_i.h +0 -2
@@ -996,8 +996,6 @@ static inline ssize_t fuse_simple_idmap_request(struct mnt_idmap *idmap,int fuse_simple_background (struct fuse_mount *fm,struct fuse_args *args,gfp_t gfp_flags); -/* Abort all requests */ -void fuse_abort_conn (struct fuse_conn *fc);void fuse_wait_aborted (struct fuse_conn *fc);void fuse_dentry_tree_init (void );
fs/fuse/req_timeout.c +0 -1
@@ -2,7 +2,6 @@#include "dev.h" #include "sysctl.h" -#include "fuse_i.h" #include "fuse_dev_i.h" #include "dev_uring_i.h"
Signature · 1 line
2.53.0
PATCH 19/32 fuse: abort related layering cleanup
In reply to Miklos Szeredi - rename fuse_abort_conn() to fuse_chan_abort(), pass fuse_chan pointer instead of fuse_conn
- pass an abort_with_err argument that tells fuse_dev_(read|write) to return with ECONNABORTED instead of ENODEV
- move fc->aborted to fch->abort_with_err
- rename fuse_wait_aborted() to fuse_chan_wait_aborted()
--- fs/fuse/control.c | 4 +-- fs/fuse/cuse.c | 4 +-- fs/fuse/dev.c | 84 ++++++++++++++++++++++--------------------- fs/fuse/dev.h | 3 +- fs/fuse/dev_uring.c | 2 +- fs/fuse/fuse_dev_i.h | 3 ++ fs/fuse/fuse_i.h | 5 --- fs/fuse/inode.c | 6 ++-- fs/fuse/req_timeout.c | 12 +++---- 9 files changed, 61 insertions(+), 62 deletions(-)
fs/fuse/control.c +1 -3
@@ -38,9 +38,7 @@ static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf, {struct fuse_conn *fc =fuse_ctl_file_conn_get (file);if (fc) { -if (fc->abort_err) - fc->aborted = true; -fuse_abort_conn (fc); +fuse_chan_abort (fc->chan, fc->abort_err);fuse_conn_put (fc); }return count;
fs/fuse/cuse.c +2 -2
@@ -424,7 +424,7 @@ static void cuse_process_init_reply(struct fuse_mount *fm, err_region:unregister_chrdev_region (devt,1 ); err: -fuse_abort_conn (fc); +fuse_chan_abort (fc->chan, false); goto out; }
@@ -594,7 +594,7 @@ static ssize_t cuse_class_abort_store(struct device *dev, {struct cuse_conn *cc =dev_get_drvdata (dev); -fuse_abort_conn (&cc->fc); +fuse_chan_abort (cc->fc.chan, false);return count; } static DEVICE_ATTR(abort, 0200, NULL, cuse_class_abort_store);
fs/fuse/dev.c +43 -41
184 lines not on this page · raw message
fs/fuse/dev.h +2 -1
@@ -42,7 +42,8 @@ struct fuse_dev *fuse_dev_grab(struct file *file);void fuse_init_server_timeout (struct fuse_chan *fch,unsigned int timeout);/* Abort all requests */ -void fuse_abort_conn (struct fuse_conn *fc); +void fuse_chan_abort (struct fuse_chan *fch,bool abort_with_err); +void fuse_chan_wait_aborted (struct fuse_chan *fch);#ifdef CONFIG_FUSE_IO_URING bool fuse_uring_enabled (void );
fs/fuse/dev_uring.c +1 -1
@@ -1155,7 +1155,7 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)return -EOPNOTSUPP ; } -if (fc->aborted) +if (fc->chan->abort_with_err)return -ECONNABORTED ;if (!fc->chan->connected)return -ENOTCONN ;
fs/fuse/fuse_dev_i.h +3 -0
@@ -239,6 +239,9 @@ struct fuse_chan {/* Use io_uring for communication */ unsigned int io_uring; +/** Connection aborted via sysfs, respond with ECONNABORTED on device I/O */ +bool abort_with_err; +#ifdef CONFIG_FUSE_IO_URING /** uring connection information*/ struct fuse_ring *ring;
fs/fuse/fuse_i.h +0 -5
@@ -483,9 +483,6 @@ struct fuse_conn {/** Number of background requests at which congestion starts */ unsigned congestion_threshold; -/** Connection aborted via sysfs */ -bool aborted; -/** Connection failed (version mismatch). Cannot race with setting other bitfields since it is only set once in INIT reply, before any other request, and never cleared */
@@ -996,8 +993,6 @@ static inline ssize_t fuse_simple_idmap_request(struct mnt_idmap *idmap,int fuse_simple_background (struct fuse_mount *fm,struct fuse_args *args,gfp_t gfp_flags); -void fuse_wait_aborted (struct fuse_conn *fc); -void fuse_dentry_tree_init (void );void fuse_dentry_tree_cleanup (void );
fs/fuse/inode.c +3 -3
@@ -612,7 +612,7 @@ static void fuse_umount_begin(struct super_block *sb)if (fc->no_force_umount)return ; -fuse_abort_conn (fc); +fuse_chan_abort (fc->chan, false);// Only retire block-device-based superblocks. if (sb->s_bdev !=NULL )
@@ -1951,8 +1951,8 @@ void fuse_conn_destroy(struct fuse_mount *fm)if (fc->destroy)fuse_send_destroy (fm); -fuse_abort_conn (fc); -fuse_wait_aborted (fc); +fuse_chan_abort (fc->chan, false); +fuse_chan_wait_aborted (fc->chan);if (!list_empty (&fc->entry)) {mutex_lock (&fuse_mutex);
fs/fuse/req_timeout.c +6 -6
@@ -79,13 +79,13 @@ static void fuse_check_timeout(struct work_struct *work) expired =fuse_request_expired (fch, &fiq->pending);spin_unlock (&fiq->lock);if (expired) - goto abort_conn; + goto chan_abort;spin_lock (&fch->bg_lock); expired =fuse_request_expired (fch, &fch->bg_queue);spin_unlock (&fch->bg_lock);if (expired) - goto abort_conn; + goto chan_abort;spin_lock (&fch->lock);if (!fch->connected) {
@@ -99,7 +99,7 @@ static void fuse_check_timeout(struct work_struct *work) fuse_fpq_processing_expired(fch, fpq->processing)) {spin_unlock (&fpq->lock);spin_unlock (&fch->lock); - goto abort_conn; + goto chan_abort; }spin_unlock (&fpq->lock);
@@ -107,15 +107,15 @@ static void fuse_check_timeout(struct work_struct *work)spin_unlock (&fch->lock);if (fuse_uring_request_expired (fch)) - goto abort_conn; + goto chan_abort; out:queue_delayed_work (system_percpu_wq, &fch->timeout.work, fuse_timeout_timer_freq);return ; -abort_conn: -fuse_abort_conn (fch->conn); +chan_abort: +fuse_chan_abort (fch, false); }static void set_request_timeout (struct fuse_chan *fch,unsigned int timeout)
Signature · 1 line
2.53.0
PATCH 20/32 fuse: split off fuse_args and related definitions into a separate header
In reply to Miklos SzerediThis is going to be used by both layers (transport and filesystem)
--- fs/fuse/args.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/fuse_i.h | 53 +-------------------------------------- 2 files changed, 66 insertions(+), 52 deletions(-) create mode 100644 fs/fuse/args.h
fs/fuse/args.h new file +65 -0
@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _FS_FUSE_ARGS_H +#define _FS_FUSE_ARGS_H + +#include <linux/types.h> + +struct fuse_mount ; + +/** One input argument of a request */ +struct fuse_in_arg { +unsigned size; +const void *value; +}; + +/** One output argument of a request */ +struct fuse_arg { +unsigned size; +void *value; +}; + +struct fuse_args { +u64 nodeid; +u32 opcode; +u32 uid; +u32 gid; +u32 pid; +u8 in_numargs; +u8 out_numargs; +u8 ext_idx; +bool force:1 ; +bool noreply:1 ; +bool nocreds:1 ; +bool in_pages:1 ; +bool out_pages:1 ; +bool user_pages:1 ; +bool out_argvar:1 ; +bool page_zeroing:1 ; +bool page_replace:1 ; +bool may_block:1 ; +bool is_ext:1 ; +bool is_pinned:1 ; +bool invalidate_vmap:1 ; +bool abort_on_kill:1 ; +struct fuse_in_arg in_args[4 ]; +struct fuse_arg out_args[2 ]; +void (*end)(struct fuse_args *args,int error); +/* Used for kvec iter backed by vmalloc address */ +void *vmap_base; +}; + +/** FUSE folio descriptor */ +struct fuse_folio_desc { +unsigned int length; +unsigned int offset; +}; + +struct fuse_args_pages { +struct fuse_args args; +struct folio **folios; +struct fuse_folio_desc *descs; +unsigned int num_folios; +}; + +#endif /* _FS_FUSE_ARGS_H */
fs/fuse/fuse_i.h +1 -52
65 lines not on this page · raw message
Signature · 1 line
2.53.0
Joanne Koong
maintainerRe: [PATCH 20/32] fuse: split off fuse_args and related definitions into a separate header
Quoted 53 lines · Miklos Szeredi
This is going to be used by both layers (transport and filesystem)
Signed-off-by Miklos Szeredi <[email protected]>--- fs/fuse/args.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/fuse_i.h | 53 +-------------------------------------- 2 files changed, 66 insertions(+), 52 deletions(-) create mode 100644 fs/fuse/args.hfs/fuse/args.h new file +37
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _FS_FUSE_ARGS_H +#define _FS_FUSE_ARGS_H + +#include <linux/types.h> + +struct fuse_mount; + +/** One input argument of a request */ +struct fuse_in_arg { + unsigned size; + const void *value; +}; + +/** One output argument of a request */ +struct fuse_arg { + unsigned size; + void *value; +}; + +struct fuse_args { + u64 nodeid; + u32 opcode; + u32 uid; + u32 gid; + u32 pid; + u8 in_numargs; + u8 out_numargs; + u8 ext_idx; + bool force:1; + bool noreply:1; + bool nocreds:1; + bool in_pages:1; + bool out_pages:1; + bool user_pages:1; + bool out_argvar:1;
fs/fuse/args.h line 47
Quoted 10 lines
fs/fuse/args.h new file +10
-0+ bool page_zeroing:1; + bool page_replace:1; + bool may_block:1; + bool is_ext:1; + bool is_pinned:1; + bool invalidate_vmap:1; + bool abort_on_kill:1; +struct fuse_in_arg in_args[4 ]; +struct fuse_arg out_args[2 ]; +void (*end)(struct fuse_args *args,int error);
I think you accidentally dropped the first arg (struct fuse_mount *fm) when moving this over?
Thanks,
Joanne
Quoted 93 lines
fs/fuse/args.h new file +18
-0+/* Used for kvec iter backed by vmalloc address */ + void *vmap_base; +}; + +/** FUSE folio descriptor */ +struct fuse_folio_desc { +unsigned int length; +unsigned int offset; +}; + +struct fuse_args_pages { +struct fuse_args args; +struct folio **folios; +struct fuse_folio_desc *descs; +unsigned int num_folios; +}; + +#endif /* _FS_FUSE_ARGS_H */ fs/fuse/fuse_i.h +1
-53@@ -13,6 +13,7 @@# define pr_fmt (fmt) "fuse: " fmt#endif +#include "args.h" #include <linux/fuse.h> #include <linux/fs.h> #include <linux/mount.h> @@ -288,58 +289,6 @@ struct fuse_file { bool flock:1; }; -/** One input argument of a request */ -struct fuse_in_arg { -unsigned size; -const void *value; -}; - -/** One output argument of a request */ -struct fuse_arg { -unsigned size; -void *value; -}; - -/** FUSE folio descriptor */ -struct fuse_folio_desc { -unsigned int length; -unsigned int offset; -}; - -struct fuse_args { -uint64_t nodeid; -uint32_t opcode; -uint8_t in_numargs; -uint8_t out_numargs; -uint8_t ext_idx; -bool force:1 ; -bool noreply:1 ; -bool nocreds:1 ; -bool in_pages:1 ; -bool out_pages:1 ; -bool user_pages:1 ; -bool out_argvar:1 ; -bool page_zeroing:1 ; -bool page_replace:1 ; -bool may_block:1 ; -bool is_ext:1 ; -bool is_pinned:1 ; -bool invalidate_vmap:1 ; -bool abort_on_kill:1 ; -struct fuse_in_arg in_args[4 ]; -struct fuse_arg out_args[2 ]; -void (*end)(struct fuse_mount *fm,struct fuse_args *args,int error); -/* Used for kvec iter backed by vmalloc address */ -void *vmap_base; -}; - -struct fuse_args_pages { -struct fuse_args args; -struct folio **folios; -struct fuse_folio_desc *descs; -unsigned int num_folios; -}; -struct fuse_release_args {struct fuse_args args;struct fuse_release_in inarg; --2.53.0
Miklos Szeredi
maintainerRe: [PATCH 20/32] fuse: split off fuse_args and related definitions into a separate header
Quoted 7 lines · Joanne Koong
Quoted 1 line · Miklos Szeredi
+ void (*end)(struct
fuse_args*args, int error);I think you accidentally dropped the first arg (struct
fuse_mount*fm) when moving this over?
Fixed, thanks.
Miklos
PATCH 21/32 fuse: remove fm arg of args->end callback
In reply to Miklos SzerediOnly used by FUSE_INIT and CUSE_INIT, these can store the relevant pointer in their structs derived from fuse_args.
--- fs/fuse/cuse.c | 7 ++++--- fs/fuse/dev.c | 7 +++---- fs/fuse/file.c | 22 +++++++++------------- fs/fuse/inode.c | 10 ++++++---- 4 files changed, 22 insertions(+), 24 deletions(-)
fs/fuse/cuse.c +4 -3
@@ -307,6 +307,7 @@ struct cuse_init_args {struct cuse_init_out out;struct folio *folio;struct fuse_folio_desc desc; +struct fuse_conn *fc; };/**
@@ -320,11 +321,10 @@ struct cuse_init_args {* required data structures for it. Please read the comment at the * top of this file for high level overview. */ -static void cuse_process_init_reply (struct fuse_mount *fm, -struct fuse_args *args,int error) +static void cuse_process_init_reply (struct fuse_args *args,int error) { -struct fuse_conn *fc = fm->fc;struct cuse_init_args *ia =container_of (args,typeof (*ia), ap.args); +struct fuse_conn *fc = ia->fc;struct fuse_args_pages *ap = &ia->ap;struct cuse_conn *cc =fc_to_cc (fc), *pos;struct cuse_init_out *arg = &ia->out;
@@ -467,6 +467,7 @@ static int cuse_send_init(struct cuse_conn *cc) ap->descs = &ia->desc; ia->folio = folio; ia->desc.length = ap->args.out_args[1 ].size; + ia->fc = &cc->fc; ap->args.end = cuse_process_init_reply; rc =fuse_simple_background (fm, &ap->args,GFP_KERNEL );
fs/fuse/dev.c +3 -4
@@ -641,7 +641,7 @@ void fuse_request_end(struct fuse_req *req) }if (test_bit (FR_ASYNC , &req->flags)) - req->args->end (fm, req->args, req->out.h.error); + req->args->end (req->args, req->out.h.error); put_request:fuse_put_request (req); }
@@ -1983,8 +1983,7 @@ struct fuse_retrieve_args {struct fuse_notify_retrieve_in inarg; }; -static void fuse_retrieve_end (struct fuse_mount *fm,struct fuse_args *args, -int error) +static void fuse_retrieve_end (struct fuse_args *args,int error) {struct fuse_retrieve_args *ra =container_of (args,typeof (*ra), ap.args);
@@ -2071,7 +2070,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode, err =fuse_simple_notify_reply (fm, args, outarg->notify_unique);if (err) -fuse_retrieve_end (fm, args, err); +fuse_retrieve_end (args, err);return err; }
fs/fuse/file.c +9 -13
@@ -92,8 +92,7 @@ static struct fuse_file *fuse_file_get(struct fuse_file *ff)return ff; } -static void fuse_release_end (struct fuse_mount *fm,struct fuse_args *args, -int error) +static void fuse_release_end (struct fuse_args *args,int error) {struct fuse_release_args *ra =container_of (args,typeof (*ra), args);
@@ -113,10 +112,10 @@ static void fuse_file_put(struct fuse_file *ff, bool sync)if (!args) {/* Do nothing when server does not implement 'opendir' */ }else if (args->opcode ==FUSE_RELEASE && ff->fm->fc->no_open) { -fuse_release_end (ff->fm, args,0 ); +fuse_release_end (args,0 ); }else if (sync) {fuse_simple_request (ff->fm, args); -fuse_release_end (ff->fm, args,0 ); +fuse_release_end (args,0 ); }else {/* * DAX inodes may need to issue a number of synchronous
@@ -127,7 +126,7 @@ static void fuse_file_put(struct fuse_file *ff, bool sync) args->end = fuse_release_end;if (fuse_simple_background (ff->fm, args,GFP_KERNEL | __GFP_NOFAIL)) -fuse_release_end (ff->fm, args, -ENOTCONN ); +fuse_release_end (args, -ENOTCONN ); }kfree (ff); }
@@ -710,8 +709,7 @@ static void fuse_io_free(struct fuse_io_args *ia)kfree (ia); } -static void fuse_aio_complete_req (struct fuse_mount *fm,struct fuse_args *args, -int err) +static void fuse_aio_complete_req (struct fuse_args *args,int err) {struct fuse_io_args *ia =container_of (args,typeof (*ia), ap.args);struct fuse_io_priv *io = ia->io;
@@ -759,7 +757,7 @@ static ssize_t fuse_async_req_send(struct fuse_mount *fm, ia->ap.args.may_block = io->should_dirty; err =fuse_simple_background (fm, &ia->ap.args,GFP_KERNEL );if (err) -fuse_aio_complete_req (fm, &ia->ap.args, err); +fuse_aio_complete_req (&ia->ap.args, err);return num_bytes; }
@@ -1001,8 +999,7 @@ static int fuse_iomap_read_folio_range(const struct iomap_iter *iter,return fuse_do_readfolio (file, folio, off, len); } -static void fuse_readpages_end (struct fuse_mount *fm,struct fuse_args *args, -int err) +static void fuse_readpages_end (struct fuse_args *args,int err) {int i;struct fuse_io_args *ia =container_of (args,typeof (*ia), ap.args);
@@ -1068,7 +1065,7 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file, res =fuse_simple_request (fm, &ap->args); err = res <0 ? res :0 ; } -fuse_readpages_end (fm, &ap->args, err); +fuse_readpages_end (&ap->args, err); }static void fuse_readahead (struct readahead_control *rac)
@@ -1985,8 +1982,7 @@ __acquires(fi->lock) } } -static void fuse_writepage_end (struct fuse_mount *fm,struct fuse_args *args, -int error) +static void fuse_writepage_end (struct fuse_args *args,int error) {struct fuse_writepage_args *wpa =container_of (args,typeof (*wpa), ia.ap.args);
fs/fuse/inode.c +6 -4
@@ -1263,13 +1263,14 @@ struct fuse_init_args {struct fuse_args args;struct fuse_init_in in;struct fuse_init_out out; +struct fuse_mount *fm; }; -static void process_init_reply (struct fuse_mount *fm,struct fuse_args *args, -int error) +static void process_init_reply (struct fuse_args *args,int error) { -struct fuse_conn *fc = fm->fc;struct fuse_init_args *ia =container_of (args,typeof (*ia), args); +struct fuse_mount *fm = ia->fm; +struct fuse_conn *fc = fm->fc;struct fuse_init_out *arg = &ia->out;bool ok = true;
@@ -1437,6 +1438,7 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm) ia =kzalloc_obj (*ia,GFP_KERNEL | __GFP_NOFAIL); + ia->fm = fm; ia->in.major =FUSE_KERNEL_VERSION ; ia->in.minor =FUSE_KERNEL_MINOR_VERSION ; ia->in.max_readahead = fm->sb->s_bdi->ra_pages *PAGE_SIZE ;
@@ -1510,7 +1512,7 @@ int fuse_send_init(struct fuse_mount *fm)if (!err)return 0 ; } -process_init_reply (fm, &ia->args, err); +process_init_reply (&ia->args, err);if (fm->fc->conn_error)return -ENOTCONN ;return 0 ;
Signature · 1 line
2.53.0
PATCH 22/32 fuse: change req->fm to req->chan
In reply to Miklos SzerediStore a struct fuse_chan pointer in fuse_req instead of a struct fuse_mount pointer.
--- fs/fuse/dev.c | 117 +++++++++++++++++++++---------------------- fs/fuse/dev_uring.c | 17 +++---- fs/fuse/fuse_dev_i.h | 4 +- fs/fuse/fuse_trace.h | 4 +- 4 files changed, 69 insertions(+), 73 deletions(-)
fs/fuse/dev.c +57 -60
@@ -35,22 +35,22 @@ static DECLARE_WAIT_QUEUE_HEAD(fuse_dev_waitq);static struct kmem_cache *fuse_req_cachep; -static void fuse_request_init (struct fuse_mount *fm,struct fuse_req *req) +static void fuse_request_init (struct fuse_chan *fch,struct fuse_req *req) {INIT_LIST_HEAD (&req->list);INIT_LIST_HEAD (&req->intr_entry);init_waitqueue_head (&req->waitq);refcount_set (&req->count,1 );__set_bit (FR_PENDING , &req->flags); - req->fm = fm; + req->chan = fch; req->create_time = jiffies; } -static struct fuse_req *fuse_request_alloc (struct fuse_mount *fm,gfp_t flags) +static struct fuse_req *fuse_request_alloc (struct fuse_chan *fch,gfp_t flags) {struct fuse_req *req =kmem_cache_zalloc (fuse_req_cachep, flags);if (req) -fuse_request_init (fm, req); +fuse_request_init (fch, req);return req; }
@@ -85,17 +85,17 @@ static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background) (fc->chan->io_uring && fc->chan->connected && !fuse_uring_ready (fc->chan)); } -static void fuse_drop_waiting (struct fuse_conn *fc) +static void fuse_drop_waiting (struct fuse_chan *fch) {/* -* lockess check of fc->chan->connected is okay, because atomic_dec_and_test() +* lockess check of fch->connected is okay, because atomic_dec_and_test() * provides a memory barrier matched with the one in fuse_chan_wait_aborted() * to ensure no wake-up is missed. */ -if (atomic_dec_and_test (&fc->chan->num_waiting) && - !READ_ONCE (fc->chan->connected)) { +if (atomic_dec_and_test (&fch->num_waiting) && + !READ_ONCE (fch->connected)) {/* wake up aborters */ -wake_up_all (&fc->chan->blocked_waitq); +wake_up_all (&fch->blocked_waitq); } }
@@ -132,7 +132,7 @@ static struct fuse_req *fuse_get_req(struct mnt_idmap *idmap,if (fc->conn_error) goto out; - req =fuse_request_alloc (fm,GFP_KERNEL ); + req =fuse_request_alloc (fc->chan,GFP_KERNEL ); err = -ENOMEM ;if (!req) {if (for_background)
@@ -169,13 +169,13 @@ static struct fuse_req *fuse_get_req(struct mnt_idmap *idmap,return req; out: -fuse_drop_waiting (fc); +fuse_drop_waiting (fc->chan);return ERR_PTR (err); }static void fuse_put_request (struct fuse_req *req) { -struct fuse_conn *fc = req->fm->fc; +struct fuse_chan *fch = req->chan;if (refcount_dec_and_test (&req->count)) {if (test_bit (FR_BACKGROUND , &req->flags)) {
@@ -183,15 +183,15 @@ static void fuse_put_request(struct fuse_req *req)* We get here in the unlikely case that a background * request was allocated but not sent */ -spin_lock (&fc->chan->bg_lock); -if (!fc->chan->blocked) -wake_up (&fc->chan->blocked_waitq); -spin_unlock (&fc->chan->bg_lock); +spin_lock (&fch->bg_lock); +if (!fch->blocked) +wake_up (&fch->blocked_waitq); +spin_unlock (&fch->bg_lock); }if (test_bit (FR_WAITING , &req->flags)) {__clear_bit (FR_WAITING , &req->flags); -fuse_drop_waiting (fc); +fuse_drop_waiting (fch); }fuse_request_free (req);
@@ -594,9 +594,8 @@ static void flush_bg_queue(struct fuse_chan *fch)*/ void fuse_request_end (struct fuse_req *req) { -struct fuse_mount *fm = req->fm; -struct fuse_conn *fc = fm->fc; -struct fuse_iqueue *fiq = &fc->chan->iq; +struct fuse_chan *fch = req->chan; +struct fuse_iqueue *fiq = &fch->iq;if (test_and_set_bit (FR_FINISHED , &req->flags)) goto put_request;
@@ -615,26 +614,26 @@ void fuse_request_end(struct fuse_req *req)WARN_ON (test_bit (FR_PENDING , &req->flags));WARN_ON (test_bit (FR_SENT , &req->flags));if (test_bit (FR_BACKGROUND , &req->flags)) { -spin_lock (&fc->chan->bg_lock); +spin_lock (&fch->bg_lock);clear_bit (FR_BACKGROUND , &req->flags); -if (fc->chan->num_background == fc->chan->max_background) { - fc->chan->blocked =0 ; -wake_up (&fc->chan->blocked_waitq); - }else if (!fc->chan->blocked) { +if (fch->num_background == fch->max_background) { + fch->blocked =0 ; +wake_up (&fch->blocked_waitq); + }else if (!fch->blocked) {/* * Wake up next waiter, if any. It's okay to use * waitqueue_active(), as we've already synced up -* fc->chan->blocked with waiters with the wake_up() call +* fch->blocked with waiters with the wake_up() call * above. */ -if (waitqueue_active (&fc->chan->blocked_waitq)) -wake_up (&fc->chan->blocked_waitq); +if (waitqueue_active (&fch->blocked_waitq)) +wake_up (&fch->blocked_waitq); } - fc->chan->num_background--; - fc->chan->active_background--; -flush_bg_queue (fc->chan); -spin_unlock (&fc->chan->bg_lock); + fch->num_background--; + fch->active_background--; +flush_bg_queue (fch); +spin_unlock (&fch->bg_lock); }else {/* Wake up waiter sleeping in request_wait_answer() */ wake_up (&req->waitq);
@@ -649,7 +648,7 @@ EXPORT_SYMBOL_GPL(fuse_request_end);static int queue_interrupt (struct fuse_req *req) { -struct fuse_iqueue *fiq = &req->fm->fc->chan->iq; +struct fuse_iqueue *fiq = &req->chan->iq;/* Check for we've sent request to interrupt this req */ if (unlikely (!test_bit (FR_INTERRUPTED , &req->flags)))
@@ -680,11 +679,11 @@ bool fuse_remove_pending_req(struct fuse_req *req, spinlock_t *lock)static void request_wait_answer (struct fuse_req *req) { -struct fuse_conn *fc = req->fm->fc; -struct fuse_iqueue *fiq = &fc->chan->iq; +struct fuse_chan *fch = req->chan; +struct fuse_iqueue *fiq = &fch->iq;int err; -if (!fc->chan->no_interrupt) { +if (!fch->no_interrupt) {/* Any signal may interrupt this */ err =wait_event_interruptible (req->waitq,test_bit (FR_FINISHED , &req->flags));
@@ -708,7 +707,7 @@ static void request_wait_answer(struct fuse_req *req)return ;if (req->args->abort_on_kill) { -fuse_chan_abort (fc->chan, false); +fuse_chan_abort (fch, false);return ; }
@@ -729,7 +728,7 @@ static void request_wait_answer(struct fuse_req *req)static void __fuse_request_send (struct fuse_req *req) { -struct fuse_iqueue *fiq = &req->fm->fc->chan->iq; +struct fuse_iqueue *fiq = &req->chan->iq;BUG_ON (test_bit (FR_BACKGROUND , &req->flags));
@@ -776,11 +775,11 @@ static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args) } } -static void fuse_force_creds (struct fuse_req *req) +static void fuse_force_creds (struct fuse_mount *fm,struct fuse_req *req) { -struct fuse_conn *fc = req->fm->fc; +struct fuse_conn *fc = fm->fc; -if (!req->fm->sb || req->fm->sb->s_iflags &SB_I_NOIDMAP ) { +if (!fm->sb || fm->sb->s_iflags &SB_I_NOIDMAP ) { req->in.h.uid =from_kuid_munged (fc->user_ns,current_fsuid ()); req->in.h.gid =from_kgid_munged (fc->user_ns,current_fsgid ()); }else {
@@ -812,10 +811,10 @@ ssize_t __fuse_simple_request(struct mnt_idmap *idmap,if (args->force) {atomic_inc (&fc->chan->num_waiting); - req =fuse_request_alloc (fm,GFP_KERNEL | __GFP_NOFAIL); + req =fuse_request_alloc (fc->chan,GFP_KERNEL | __GFP_NOFAIL);if (!args->nocreds) -fuse_force_creds (req); +fuse_force_creds (fm, req);__set_bit (FR_WAITING , &req->flags);if (!args->abort_on_kill)
@@ -845,10 +844,9 @@ ssize_t __fuse_simple_request(struct mnt_idmap *idmap, }#ifdef CONFIG_FUSE_IO_URING -static bool fuse_request_queue_background_uring (struct fuse_conn *fc, -struct fuse_req *req) +static bool fuse_request_queue_background_uring (struct fuse_req *req) { -struct fuse_iqueue *fiq = &fc->chan->iq; +struct fuse_iqueue *fiq = &req->chan->iq; req->in.h.len =sizeof (struct fuse_in_header ) + fuse_len_args(req->args->in_numargs,
@@ -864,32 +862,31 @@ static bool fuse_request_queue_background_uring(struct fuse_conn *fc,*/ static int fuse_request_queue_background (struct fuse_req *req) { -struct fuse_mount *fm = req->fm; -struct fuse_conn *fc = fm->fc; +struct fuse_chan *fch = req->chan;bool queued = false;WARN_ON (!test_bit (FR_BACKGROUND , &req->flags));if (!test_bit (FR_WAITING , &req->flags)) {__set_bit (FR_WAITING , &req->flags); -atomic_inc (&fc->chan->num_waiting); +atomic_inc (&fch->num_waiting); }__set_bit (FR_ISREPLY , &req->flags);#ifdef CONFIG_FUSE_IO_URING -if (fuse_uring_ready (fc->chan)) -return fuse_request_queue_background_uring (fc, req); +if (fuse_uring_ready (fch)) +return fuse_request_queue_background_uring (req);#endif -spin_lock (&fc->chan->bg_lock); -if (likely (fc->chan->connected)) { - fc->chan->num_background++; -if (fc->chan->num_background == fc->chan->max_background) - fc->chan->blocked =1 ; -list_add_tail (&req->list, &fc->chan->bg_queue); -flush_bg_queue (fc->chan); +spin_lock (&fch->bg_lock); +if (likely (fch->connected)) { + fch->num_background++; +if (fch->num_background == fch->max_background) + fch->blocked =1 ; +list_add_tail (&req->list, &fch->bg_queue); +flush_bg_queue (fch); queued = true; } -spin_unlock (&fc->chan->bg_lock); +spin_unlock (&fch->bg_lock);return queued; }
@@ -901,7 +898,7 @@ int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args,if (args->force) {WARN_ON (!args->nocreds); - req =fuse_request_alloc (fm, gfp_flags); + req =fuse_request_alloc (fm->fc->chan, gfp_flags);if (!req)return -ENOMEM ;__set_bit (FR_BACKGROUND , &req->flags);
fs/fuse/dev_uring.c +8 -9
@@ -1262,8 +1262,7 @@ static void fuse_uring_dispatch_ent(struct fuse_ring_ent *ent)/* queue a fuse request and send it if a ring entry is available */ void fuse_uring_queue_fuse_req (struct fuse_iqueue *fiq,struct fuse_req *req) { -struct fuse_conn *fc = req->fm->fc; -struct fuse_ring *ring = fc->chan->ring; +struct fuse_ring *ring = req->chan->ring;struct fuse_ring_queue *queue;struct fuse_ring_ent *ent =NULL ;int err;
@@ -1305,8 +1304,8 @@ void fuse_uring_queue_fuse_req(struct fuse_iqueue *fiq, struct fuse_req *req)bool fuse_uring_queue_bq_req (struct fuse_req *req) { -struct fuse_conn *fc = req->fm->fc; -struct fuse_ring *ring = fc->chan->ring; +struct fuse_chan *fch = req->chan; +struct fuse_ring *ring = fch->ring;struct fuse_ring_queue *queue;struct fuse_ring_ent *ent =NULL ;
@@ -1326,12 +1325,12 @@ bool fuse_uring_queue_bq_req(struct fuse_req *req) ent =list_first_entry_or_null (&queue->ent_avail_queue, struct fuse_ring_ent, list); -spin_lock (&fc->chan->bg_lock); - fc->chan->num_background++; -if (fc->chan->num_background == fc->chan->max_background) - fc->chan->blocked =1 ; +spin_lock (&fch->bg_lock); + fch->num_background++; +if (fch->num_background == fch->max_background) + fch->blocked =1 ;fuse_uring_flush_bg (queue); -spin_unlock (&fc->chan->bg_lock); +spin_unlock (&fch->bg_lock);/* * Due to bg_queue flush limits there might be other bg requests
fs/fuse/fuse_dev_i.h +2 -2
@@ -97,8 +97,8 @@ struct fuse_req {void *argbuf;#endif -/** fuse_mount this request belongs to */ -struct fuse_mount *fm; +/** fuse_chan this request belongs to */ +struct fuse_chan *chan;#ifdef CONFIG_FUSE_IO_URING void *ring_entry;
fs/fuse/fuse_trace.h +2 -2
@@ -90,7 +90,7 @@ TRACE_EVENT(fuse_request_send, ), TP_fast_assign( - __entry->connection = req->fm->fc->dev; + __entry->connection = req->chan->conn->dev; __entry->unique = req->in.h.unique; __entry->opcode = req->in.h.opcode; __entry->len = req->in.h.len;
@@ -114,7 +114,7 @@ TRACE_EVENT(fuse_request_end, ), TP_fast_assign( - __entry->connection = req->fm->fc->dev; + __entry->connection = req->chan->conn->dev; __entry->unique = req->in.h.unique; __entry->len = req->out.h.len; __entry->error = req->out.h.error;
Signature · 1 line
2.53.0
PATCH 23/32 fuse: split out filesystem part of request sending
In reply to Miklos SzerediCreate a new source file: req.c and add the request sending entry functions:
__fuse_simple_request()
fuse_simple_background()
fuse_simple_notify_reply()
Introduce transport layer sending functions that are called by the respective fs layer function:
fuse_chan_send()
fuse_chan_send_bg()
fuse_chan_send_notify_reply()
Move calculation of request header fields uid, gid and pid from fuse_get_req() and fuse_force_creads() to a new helper: fuse_fill_creds().
These fileds are now passed to the transport layer via struct fuse_args.
--- fs/fuse/Makefile | 2 +- fs/fuse/dev.c | 103 +++++++++++------------------------------------ fs/fuse/dev.h | 4 ++ fs/fuse/fuse_i.h | 1 + fs/fuse/req.c | 99 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 80 deletions(-) create mode 100644 fs/fuse/req.c
fs/fuse/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-$(CONFIG_CUSE) += cuse.o obj-$(CONFIG_VIRTIO_FS) += virtiofs.o fuse-y := trace.o # put trace.o first so we see ftrace errors sooner -fuse-y += dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o ioctl.o req_timeout.o +fuse-y += dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o ioctl.o req_timeout.o req.o fuse-y += iomode.o fuse-$(CONFIG_FUSE_DAX) += dax.o fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o backing.o
fs/fuse/dev.c +24 -79
192 lines not on this page · raw message
fs/fuse/dev.h +4 -0
@@ -11,6 +11,7 @@struct fuse_conn ;struct fuse_chan ;struct fuse_dev ; +struct fuse_args ;struct file ;struct fuse_chan *fuse_chan_new (void );
@@ -24,6 +25,9 @@ unsigned int fuse_chan_num_waiting(struct fuse_chan *fch);void fuse_chan_set_fc (struct fuse_chan *fch,struct fuse_conn *fc);void fuse_chan_set_initialized (struct fuse_chan *fch);void fuse_chan_io_uring_enable (struct fuse_chan *fch); +ssize_t fuse_chan_send (struct fuse_chan *fch,struct fuse_args *args); +int fuse_chan_send_bg (struct fuse_chan *fch,struct fuse_args *args,gfp_t gfp_flags); +int fuse_chan_send_notify_reply (struct fuse_chan *fch,struct fuse_args *args,u64 unique);struct fuse_forget_link *fuse_alloc_forget (void ); void fuse_chan_queue_forget(struct fuse_chan *fch, struct fuse_forget_link *forget,
fs/fuse/fuse_i.h +1 -0
@@ -941,6 +941,7 @@ static inline ssize_t fuse_simple_idmap_request(struct mnt_idmap *idmap,int fuse_simple_background (struct fuse_mount *fm,struct fuse_args *args,gfp_t gfp_flags); +int fuse_simple_notify_reply (struct fuse_mount *fm,struct fuse_args *args,u64 unique);void fuse_dentry_tree_init (void );void fuse_dentry_tree_cleanup (void );
fs/fuse/req.c new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 24/32 fuse: change fud->fc to fud->chan
In reply to Miklos SzerediStore pointer to struct fuse_chan instead of struct fuse_conn in fuse_dev.
--- fs/fuse/cuse.c | 4 +- fs/fuse/dev.c | 96 ++++++++++++++++++++++---------------------- fs/fuse/dev.h | 4 +- fs/fuse/dev_uring.c | 54 ++++++++++++------------- fs/fuse/fuse_dev_i.h | 20 ++++----- fs/fuse/inode.c | 4 +- fs/fuse/virtio_fs.c | 2 +- 7 files changed, 92 insertions(+), 92 deletions(-)
fs/fuse/cuse.c +2 -2
@@ -521,7 +521,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)*/ fuse_conn_init (&cc->fc, &cc->fm, file->f_cred->user_ns,no_free_ptr (fch)); cc->fc.release = cuse_fc_release; - fud =fuse_dev_alloc_install (&cc->fc); + fud =fuse_dev_alloc_install (cc->fc.chan);fuse_conn_put (&cc->fc);if (!fud)return -ENOMEM ;
@@ -553,7 +553,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)static int cuse_channel_release (struct inode *inode,struct file *file) {struct fuse_dev *fud =__fuse_get_dev (file); -struct cuse_conn *cc =fc_to_cc (fud->fc); +struct cuse_conn *cc =fc_to_cc (fud->chan->conn);/* remove from the conntbl, no more access from this point on */ mutex_lock (&cuse_lock);
fs/fuse/dev.c +48 -48
267 lines not on this page · raw message
fs/fuse/dev.h +2 -2
@@ -36,8 +36,8 @@ void fuse_chan_queue_forget(struct fuse_chan *fch, struct fuse_forget_link *forg DEFINE_FREE(fuse_chan_free, struct fuse_chan *, if (_T) fuse_chan_free(_T)) -void fuse_dev_install (struct fuse_dev *fud,struct fuse_conn *fc); -bool fuse_dev_verify (struct fuse_dev *fud,struct fuse_conn *fc); +void fuse_dev_install (struct fuse_dev *fud,struct fuse_chan *fch); +bool fuse_dev_verify (struct fuse_dev *fud,struct fuse_chan *fch);void fuse_dev_put (struct fuse_dev *fud);bool fuse_dev_is_installed (struct fuse_dev *fud);bool fuse_dev_is_sync_init (struct fuse_dev *fud);
fs/fuse/dev_uring.c +27 -27
150 lines not on this page · raw message
fs/fuse/fuse_dev_i.h +10 -10
@@ -284,8 +284,8 @@ struct fuse_dev {/** Issue FUSE_INIT synchronously */ bool sync_init; -/** Fuse connection for this device */ -struct fuse_conn *fc; +/** Fuse channel for this device */ +struct fuse_chan *chan;/** Processing queue */ struct fuse_pqueue pq;
@@ -312,21 +312,21 @@ struct fuse_copy_state { } ring; }; -/* fud->fc gets assigned to this value when /dev/fuse is closed */ -#define FUSE_DEV_FC_DISCONNECTED ((struct fuse_conn *) 1) +/* fud->chan gets assigned to this value when /dev/fuse is closed */ +#define FUSE_DEV_CHAN_DISCONNECTED ((struct fuse_chan *) 1)/* -* Lockless access is OK, because fud->fc is set once during mount and is valid +* Lockless access is OK, because fud->chan is set once during mount and is valid * until the file is released. * -* fud->fc is set to FUSE_DEV_FC_DISCONNECTED only after the containing file is +* fud->chan is set to FUSE_DEV_CHAN_DISCONNECTED only after the containing file is * released, so result is safe to dereference in most cases. Exceptions are: * fuse_dev_put() and fuse_fill_super_common(). */ -static inline struct fuse_conn *fuse_dev_fc_get (struct fuse_dev *fud) +static inline struct fuse_chan *fuse_dev_chan_get (struct fuse_dev *fud) {/* Pairs with xchg() in fuse_dev_install() */ -return smp_load_acquire (&fud->fc); +return smp_load_acquire (&fud->chan); }static inline struct fuse_dev *fuse_file_to_fud (struct file *file)
@@ -338,7 +338,7 @@ static inline struct fuse_dev *__fuse_get_dev(struct file *file) {struct fuse_dev *fud =fuse_file_to_fud (file); -if (!fuse_dev_fc_get (fud)) +if (!fuse_dev_chan_get (fud))return NULL ;return fud;
@@ -378,7 +378,7 @@ void fuse_request_assign_unique(struct fuse_iqueue *fiq, struct fuse_req *req);*/ u64 fuse_get_unique (struct fuse_iqueue *fiq); -struct fuse_dev *fuse_dev_alloc_install (struct fuse_conn *fc); +struct fuse_dev *fuse_dev_alloc_install (struct fuse_chan *fch);struct fuse_dev *fuse_dev_alloc (void );/**
fs/fuse/inode.c +2 -2
@@ -1790,7 +1790,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)list_add_tail (&fc->entry, &fuse_conn_list); sb->s_root = root_dentry;if (fud) -fuse_dev_install (fud, fc); +fuse_dev_install (fud, fc->chan);mutex_unlock (&fuse_mutex);return 0 ;
@@ -1836,7 +1836,7 @@ static int fuse_set_no_super(struct super_block *sb, struct fs_context *fsc)static int fuse_test_super (struct super_block *sb,struct fs_context *fsc) { -return fuse_dev_verify (fsc->sget_key,get_fuse_conn_super (sb)); +return fuse_dev_verify (fsc->sget_key,get_fuse_conn_super (sb)->chan); }static int fuse_get_tree (struct fs_context *fsc)
fs/fuse/virtio_fs.c +1 -1
@@ -1607,7 +1607,7 @@ static int virtio_fs_fill_super(struct super_block *sb, struct fs_context *fsc)for (i =0 ; i < fs->nvqs; i++) {struct virtio_fs_vq *fsvq = &fs->vqs[i]; -fuse_dev_install (fsvq->fud, fc); +fuse_dev_install (fsvq->fud, fc->chan); }/* Previous unmount will stop all queues. Start these again */
Signature · 1 line
2.53.0
PATCH 25/32 fuse: create poll.c
In reply to Miklos SzerediMove f_op->poll related functions to the new source file.
--- fs/fuse/Makefile | 1 + fs/fuse/dev.c | 45 +++++---------- fs/fuse/dev.h | 2 + fs/fuse/file.c | 119 --------------------------------------- fs/fuse/poll.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+), 150 deletions(-) create mode 100644 fs/fuse/poll.c
fs/fuse/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_VIRTIO_FS) += virtiofs.o fuse-y := trace.o # put trace.o first so we see ftrace errors sooner fuse-y += dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o ioctl.o req_timeout.o req.o +fuse-y += poll.o fuse-y += iomode.o fuse-$(CONFIG_FUSE_DAX) += dax.o fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o backing.o
fs/fuse/dev.c +14 -31
99 lines not on this page · raw message
fs/fuse/dev.h +2 -0
@@ -49,6 +49,8 @@ void fuse_init_server_timeout(struct fuse_chan *fch, unsigned int timeout);void fuse_chan_abort (struct fuse_chan *fch,bool abort_with_err);void fuse_chan_wait_aborted (struct fuse_chan *fch); +void fuse_end_polls (struct fuse_conn *fc); +#ifdef CONFIG_FUSE_IO_URING bool fuse_uring_enabled (void );void fuse_uring_destruct (struct fuse_chan *fch);
fs/fuse/file.c +0 -119
125 lines not on this page · raw message
fs/fuse/poll.c new file +141 -0
141 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 26/32 fuse: create notify.c
In reply to Miklos SzerediMove FUSE_NOTIFY_* handling into a separate source file.
--- fs/fuse/Makefile | 2 +- fs/fuse/dev.c | 458 ++----------------------------------------- fs/fuse/dev.h | 12 +- fs/fuse/fuse_dev_i.h | 1 - fs/fuse/notify.c | 434 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 461 insertions(+), 446 deletions(-) create mode 100644 fs/fuse/notify.c
fs/fuse/Makefile +1 -1
@@ -12,7 +12,7 @@ obj-$(CONFIG_VIRTIO_FS) += virtiofs.o fuse-y := trace.o # put trace.o first so we see ftrace errors sooner fuse-y += dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o ioctl.o req_timeout.o req.o -fuse-y += poll.o +fuse-y += poll.o notify.o fuse-y += iomode.o fuse-$(CONFIG_FUSE_DAX) += dax.o fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o backing.o
fs/fuse/dev.c +15 -443
494 lines not on this page · raw message
fs/fuse/dev.h +11 -1
@@ -12,7 +12,10 @@ struct fuse_conn;struct fuse_chan ;struct fuse_dev ;struct fuse_args ; +struct fuse_copy_state ;struct file ; +struct folio ; +enum fuse_notify_code ;struct fuse_chan *fuse_chan_new (void );struct fuse_chan *fuse_dev_chan_new (void );
@@ -28,12 +31,12 @@ void fuse_chan_io_uring_enable(struct fuse_chan *fch);ssize_t fuse_chan_send (struct fuse_chan *fch,struct fuse_args *args);int fuse_chan_send_bg (struct fuse_chan *fch,struct fuse_args *args,gfp_t gfp_flags);int fuse_chan_send_notify_reply (struct fuse_chan *fch,struct fuse_args *args,u64 unique); +void fuse_chan_resend (struct fuse_chan *fch);struct fuse_forget_link *fuse_alloc_forget (void );void fuse_chan_queue_forget (struct fuse_chan *fch,struct fuse_forget_link *forget,u64 nodeid,u64 nlookup); - DEFINE_FREE(fuse_chan_free, struct fuse_chan *, if (_T) fuse_chan_free(_T))void fuse_dev_install (struct fuse_dev *fud,struct fuse_chan *fch);
@@ -50,6 +53,13 @@ void fuse_chan_abort(struct fuse_chan *fch, bool abort_with_err);void fuse_chan_wait_aborted (struct fuse_chan *fch);void fuse_end_polls (struct fuse_conn *fc); +int fuse_notify (struct fuse_conn *fc,enum fuse_notify_code code, +unsigned int size,struct fuse_copy_state *cs); + +int fuse_copy_one (struct fuse_copy_state *cs,void *val,unsigned size); +int fuse_copy_folio (struct fuse_copy_state *cs,struct folio **foliop, +unsigned offset,unsigned count,int zeroing); +void fuse_copy_finish (struct fuse_copy_state *cs);#ifdef CONFIG_FUSE_IO_URING bool fuse_uring_enabled (void );
fs/fuse/fuse_dev_i.h +0 -1
@@ -355,7 +355,6 @@ void fuse_dev_end_requests(struct list_head *head);void fuse_copy_init (struct fuse_copy_state *cs,bool write,struct iov_iter *iter); -void fuse_copy_finish (struct fuse_copy_state *cs);int fuse_copy_args (struct fuse_copy_state *cs,unsigned int numargs,unsigned int argpages,struct fuse_arg *args,int zeroing);
fs/fuse/notify.c new file +434 -0
434 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 27/32 fuse: set params in fuse_chan_set_initialized()
In reply to Miklos SzerediSet minor, max_write and max_pages in the fuse_chan. These match the same fields in fuse_conn but are needed in both layers.
--- fs/fuse/dev.c | 30 ++++++++++++++++++------------ fs/fuse/dev.h | 8 +++++++- fs/fuse/dev_uring.c | 4 ++-- fs/fuse/fuse_dev_i.h | 9 +++++++++ fs/fuse/inode.c | 10 ++++++++-- 5 files changed, 44 insertions(+), 17 deletions(-)
fs/fuse/dev.c +18 -12
@@ -71,11 +71,17 @@ static void __fuse_put_request(struct fuse_req *req)refcount_dec (&req->count); } -void fuse_chan_set_initialized (struct fuse_chan *fch) +void fuse_chan_set_initialized (struct fuse_chan *fch,struct fuse_chan_param *param) {/* Make sure stores before this are seen on another CPU */ smp_wmb (); fch->initialized =1 ; +if (param) { + fch->minor = param->minor; + fch->max_write = param->max_write; + fch->max_pages = param->max_pages; + } +wake_up_all (&fch->blocked_waitq); }
@@ -711,12 +717,12 @@ static void __fuse_request_send(struct fuse_req *req)smp_rmb (); } -static void fuse_adjust_compat (struct fuse_conn *fc,struct fuse_args *args) +static void fuse_adjust_compat (struct fuse_chan *fch,struct fuse_args *args) { -if (fc->minor <4 && args->opcode ==FUSE_STATFS ) +if (fch->minor <4 && args->opcode ==FUSE_STATFS ) args->out_args[0 ].size =FUSE_COMPAT_STATFS_SIZE ; -if (fc->minor <9 ) { +if (fch->minor <9 ) {switch (args->opcode) {case FUSE_LOOKUP :case FUSE_CREATE :
@@ -732,7 +738,7 @@ static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args)break ; } } -if (fc->minor <12 ) { +if (fch->minor <12 ) {switch (args->opcode) {case FUSE_CREATE : args->in_args[0 ].size =sizeof (struct fuse_open_in );
@@ -776,8 +782,8 @@ ssize_t fuse_chan_send(struct fuse_chan *fch, struct fuse_args *args)return PTR_ERR (req); } -/* Needs to be done after fuse_get_req() so that fc->minor is valid */ -fuse_adjust_compat (fch->conn, args); +/* Needs to be done after fuse_get_req() so that fch->minor is valid */ +fuse_adjust_compat (fch, args);fuse_args_to_req (req, args);if (!args->noreply)
@@ -1467,12 +1473,12 @@ __releases(fiq->lock)return ih.len; } -static int fuse_read_forget (struct fuse_conn *fc,struct fuse_iqueue *fiq, +static int fuse_read_forget (struct fuse_chan *fch,struct fuse_iqueue *fiq,struct fuse_copy_state *cs,size_t nbytes) __releases(fiq->lock) { -if (fc->minor <16 || fiq->forget_list_head.next->next ==NULL ) +if (fch->minor <16 || fiq->forget_list_head.next->next ==NULL )return fuse_read_single_forget (fiq, cs, nbytes);else return fuse_read_batch_forget (fiq, cs, nbytes);
@@ -1514,7 +1520,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,if (nbytes <max_t (size_t,FUSE_MIN_READ_BUFFER ,sizeof (struct fuse_in_header ) +sizeof (struct fuse_write_in ) + - fch->conn->max_write)) + fch->max_write))return -EINVAL ; restart:
@@ -1545,7 +1551,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,if (forget_pending (fiq)) {if (list_empty (&fiq->pending) || fiq->forget_batch-- >0 ) -return fuse_read_forget (fch->conn, fiq, cs, nbytes); +return fuse_read_forget (fch, fiq, cs, nbytes);if (fiq->forget_batch <=-8 ) fiq->forget_batch =16 ;
@@ -2110,7 +2116,7 @@ void fuse_chan_abort(struct fuse_chan *fch, bool abort_with_err) fch->connected =0 ;spin_unlock (&fch->bg_lock); -fuse_chan_set_initialized (fch); +fuse_chan_set_initialized (fch,0 );list_for_each_entry (fud, &fch->devices, entry) {struct fuse_pqueue *fpq = &fud->pq;
fs/fuse/dev.h +7 -1
@@ -17,6 +17,12 @@ struct file;struct folio ;enum fuse_notify_code ; +struct fuse_chan_param { +unsigned int minor; +unsigned int max_write; +unsigned int max_pages; +}; +struct fuse_chan *fuse_chan_new (void );struct fuse_chan *fuse_dev_chan_new (void );void fuse_chan_release (struct fuse_chan *fch);
@@ -26,7 +32,7 @@ unsigned int fuse_chan_max_background(struct fuse_chan *fch);void fuse_chan_max_background_set (struct fuse_chan *fch,unsigned int val);unsigned int fuse_chan_num_waiting (struct fuse_chan *fch);void fuse_chan_set_fc (struct fuse_chan *fch,struct fuse_conn *fc); -void fuse_chan_set_initialized (struct fuse_chan *fch); +void fuse_chan_set_initialized (struct fuse_chan *fch,struct fuse_chan_param *param);void fuse_chan_io_uring_enable (struct fuse_chan *fch);ssize_t fuse_chan_send (struct fuse_chan *fch,struct fuse_args *args);int fuse_chan_send_bg (struct fuse_chan *fch,struct fuse_args *args,gfp_t gfp_flags);
fs/fuse/dev_uring.c +2 -2
@@ -241,8 +241,8 @@ static struct fuse_ring *fuse_uring_create(struct fuse_chan *fch)if (!ring->queues) goto out_err; - max_payload_size =max (FUSE_MIN_READ_BUFFER , fch->conn->max_write); - max_payload_size =max (max_payload_size, fch->conn->max_pages *PAGE_SIZE ); + max_payload_size =max (FUSE_MIN_READ_BUFFER , fch->max_write); + max_payload_size =max (max_payload_size, fch->max_pages *PAGE_SIZE );spin_lock (&fch->lock);if (fch->ring) {
fs/fuse/fuse_dev_i.h +9 -0
@@ -239,6 +239,15 @@ struct fuse_chan {/* Use io_uring for communication */ unsigned int io_uring; +/* Negotiated minor version */ +unsigned int minor; + +/* Maximum write size */ +unsigned int max_write; + +/* Maximum number of pages that can be used in a single request */ +unsigned int max_pages; +/** Connection aborted via sysfs, respond with ECONNABORTED on device I/O */ bool abort_with_err;
fs/fuse/inode.c +8 -2
@@ -1426,9 +1426,15 @@ static void process_init_reply(struct fuse_args *args, int error)if (!ok) { fc->conn_init =0 ; fc->conn_error =1 ; +fuse_chan_set_initialized (fc->chan,NULL ); + }else { +struct fuse_chan_param cp = { + .minor = fc->minor, + .max_write = fc->max_write, + .max_pages = fc->max_pages, + }; +fuse_chan_set_initialized (fc->chan, &cp); } - -fuse_chan_set_initialized (fc->chan); }static struct fuse_init_args *fuse_new_init (struct fuse_mount *fm)
Signature · 1 line
2.53.0
Joanne Koong
maintainerRe: [PATCH 27/32] fuse: set params in fuse_chan_set_initialized()
Quoted 22 lines · Miklos Szeredi
Set minor,
max_writeandmax_pagesin thefuse_chan. These match the same fields infuse_connbut are needed in both layers.Signed-off-by Miklos Szeredi <[email protected]>--- fs/fuse/dev.c | 30 ++++++++++++++++++------------ fs/fuse/dev.h | 8 +++++++- fs/fuse/dev_uring.c | 4 ++-- fs/fuse/fuse_dev_i.h | 9 +++++++++ fs/fuse/inode.c | 10 ++++++++-- 5 files changed, 44 insertions(+), 17 deletions(-)fs/fuse/dev.c +0
-1@@ -71,11 +71,17 @@ static void __fuse_put_request(struct fuse_req *req)refcount_dec (&req->count); } -void fuse_chan_set_initialized (struct fuse_chan *fch)
fs/fuse/dev.c static void __fuse_put_request(struct fuse_req *req) · line 83
Quoted 10 lines
fs/fuse/dev.c +6
-0+void fuse_chan_set_initialized (struct fuse_chan *fch,struct fuse_chan_param *param) {/* Make sure stores before this are seen on another CPU */ smp_wmb (); fch->initialized =1 ; +if (param) { + fch->minor = param->minor; + fch->max_write = param->max_write; + fch->max_pages = param->max_pages; + }
I don't think this actually matters in practice, but should this be moved to before the fch->initialized = 1, ideally before the smp_wmb() write barrier?
Thanks,
Joanne
Quoted 4 lines
fs/fuse/dev.c +1
-0+wake_up_all (&fch->blocked_waitq); }
Miklos Szeredi
maintainerRe: [PATCH 27/32] fuse: set params in fuse_chan_set_initialized()
Quoted 7 lines · Joanne Koong
Quoted 7 lines
fs/fuse/dev.c +2
-1-void fuse_chan_set_initialized (struct fuse_chan *fch) +void fuse_chan_set_initialized (struct fuse_chan *fch,struct fuse_chan_param *param) {/* Make sure stores before this are seen on another CPU */ smp_wmb (); fch->initialized =1 ; +if (param) {
Quoted 8 lines
fs/fuse/dev.c static void __fuse_put_request(struct fuse_req *req) · line 83
Quoted 4 lines
fs/fuse/dev.c +4
-0+ fch->minor = param->minor; + fch->max_write = param->max_write; + fch->max_pages = param->max_pages; + }I don't think this actually matters in practice, but should this be moved to before the
fch->initialized= 1, ideally before thesmp_wmb()write barrier?
Makes sense, fixed.
Thanks,
Miklos
PATCH 28/32 fuse: remove fuse_mutex protection from fuse_dev_ioctl_sync_init()
In reply to Miklos SzerediIn normal use ioctl(FUSE_DEV_IOC_SYNC_INIT) comes before the mount() or fsconfig() syscalls, they are executed strictly serially.
If ioctl and mount are performed in parallel, the behavior is nondeterministic. Removing the mutex does not change this.
--- fs/fuse/dev.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
fs/fuse/dev.c +5 -8
@@ -2297,16 +2297,13 @@ static long fuse_dev_ioctl_backing_close(struct file *file, __u32 __user *argp)static long fuse_dev_ioctl_sync_init (struct file *file) { -int err = -EINVAL ;struct fuse_dev *fud =fuse_file_to_fud (file); -mutex_lock (&fuse_mutex); -if (!fuse_dev_chan_get (fud)) { - fud->sync_init = true; - err =0 ; - } -mutex_unlock (&fuse_mutex); -return err; +if (fuse_dev_chan_get (fud)) +return -EINVAL ; + + fud->sync_init = true; +return 0 ; } static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
Signature · 1 line
2.53.0
PATCH 29/32 fuse: change ring->fc to ring->chan
In reply to Miklos SzerediStore pointer to struct fuse_chan instead of struct fuse_conn in fuse_ring.
--- fs/fuse/dev_uring.c | 44 +++++++++++++++++++++---------------------- fs/fuse/dev_uring_i.h | 2 +- 2 files changed, 22 insertions(+), 24 deletions(-)
fs/fuse/dev_uring.c +21 -23
@@ -52,10 +52,10 @@ static struct fuse_ring_ent *uring_cmd_to_ring_ent(struct io_uring_cmd *cmd)static void fuse_uring_flush_bg (struct fuse_ring_queue *queue) {struct fuse_ring *ring = queue->ring; -struct fuse_conn *fc = ring->fc; +struct fuse_chan *fch = ring->chan;lockdep_assert_held (&queue->lock); -lockdep_assert_held (&fc->chan->bg_lock); +lockdep_assert_held (&fch->bg_lock);/* * Allow one bg request per queue, ignoring global fc limits.
@@ -63,14 +63,14 @@ static void fuse_uring_flush_bg(struct fuse_ring_queue *queue)* eliminates the need for remote queue wake-ups when global * limits are met but this queue has no more waiting requests. */ -while ((fc->chan->active_background < fc->chan->max_background || +while ((fch->active_background < fch->max_background || !queue->active_background) && (!list_empty (&queue->fuse_req_bg_queue))) {struct fuse_req *req; req =list_first_entry (&queue->fuse_req_bg_queue, struct fuse_req, list); - fc->chan->active_background++; + fch->active_background++; queue->active_background++;list_move_tail (&req->list, &queue->fuse_req_queue);
@@ -82,7 +82,7 @@ static void fuse_uring_req_end(struct fuse_ring_ent *ent, struct fuse_req *req, {struct fuse_ring_queue *queue = ent->queue;struct fuse_ring *ring = queue->ring; -struct fuse_conn *fc = ring->fc; +struct fuse_chan *fch = ring->chan;lockdep_assert_not_held (&queue->lock);spin_lock (&queue->lock);
@@ -90,9 +90,9 @@ static void fuse_uring_req_end(struct fuse_ring_ent *ent, struct fuse_req *req,list_del_init (&req->list);if (test_bit (FR_BACKGROUND , &req->flags)) { queue->active_background--; -spin_lock (&fc->chan->bg_lock); +spin_lock (&fch->bg_lock);fuse_uring_flush_bg (queue); -spin_unlock (&fc->chan->bg_lock); +spin_unlock (&fch->bg_lock); }spin_unlock (&queue->lock);
@@ -124,7 +124,7 @@ void fuse_uring_abort_end_requests(struct fuse_ring *ring) {int qid;struct fuse_ring_queue *queue; -struct fuse_conn *fc = ring->fc; +struct fuse_chan *fch = ring->chan;for (qid =0 ; qid < ring->nr_queues; qid++) { queue =READ_ONCE (ring->queues[qid]);
@@ -133,11 +133,11 @@ void fuse_uring_abort_end_requests(struct fuse_ring *ring) queue->stopped = true; -WARN_ON_ONCE (ring->fc->chan->max_background !=UINT_MAX ); +WARN_ON_ONCE (fch->max_background !=UINT_MAX );spin_lock (&queue->lock); -spin_lock (&fc->chan->bg_lock); +spin_lock (&fch->bg_lock);fuse_uring_flush_bg (queue); -spin_unlock (&fc->chan->bg_lock); +spin_unlock (&fch->bg_lock);spin_unlock (&queue->lock);fuse_uring_abort_end_queue_requests (queue); }
@@ -255,7 +255,7 @@ static struct fuse_ring *fuse_uring_create(struct fuse_chan *fch)init_waitqueue_head (&ring->stop_waitq); ring->nr_queues = nr_queues; - ring->fc = fch->conn; + ring->chan = fch; ring->max_payload_sz = max_payload_size;smp_store_release (&fch->ring, ring);
@@ -271,7 +271,7 @@ static struct fuse_ring *fuse_uring_create(struct fuse_chan *fch)static struct fuse_ring_queue *fuse_uring_create_queue (struct fuse_ring *ring,int qid) { -struct fuse_conn *fc = ring->fc; +struct fuse_chan *fch = ring->chan;struct fuse_ring_queue *queue;struct list_head *pq;
@@ -299,9 +299,9 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, queue->fpq.processing = pq;fuse_pqueue_init (&queue->fpq); -spin_lock (&fc->chan->lock); +spin_lock (&fch->lock);if (ring->queues[qid]) { -spin_unlock (&fc->chan->lock); +spin_unlock (&fch->lock);kfree (queue->fpq.processing);kfree (queue);return ring->queues[qid];
@@ -311,7 +311,7 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring,* write_once and lock as the caller mostly doesn't take the lock at all */ WRITE_ONCE (ring->queues[qid], queue); -spin_unlock (&fc->chan->lock); +spin_unlock (&fch->lock);return queue; }
@@ -532,8 +532,7 @@ static void fuse_uring_prepare_cancel(struct io_uring_cmd *cmd, int issue_flags,* Checks for errors and stores it into the request */ static int fuse_uring_out_header_has_err (struct fuse_out_header *oh, -struct fuse_req *req, -struct fuse_conn *fc) +struct fuse_req *req) {int err;
@@ -813,7 +812,6 @@ static void fuse_uring_commit(struct fuse_ring_ent *ent, struct fuse_req *req, unsigned int issue_flags) {struct fuse_ring *ring = ent->queue->ring; -struct fuse_conn *fc = ring->fc;ssize_t err =0 ; err = copy_from_user(&req->out.h, &ent->headers->in_out,
@@ -823,7 +821,7 @@ static void fuse_uring_commit(struct fuse_ring_ent *ent, struct fuse_req *req, goto out; } - err =fuse_uring_out_header_has_err (&req->out.h, req, fc); + err =fuse_uring_out_header_has_err (&req->out.h, req);if (err) {/* req->out.h.error already set */ goto out;
@@ -982,8 +980,8 @@ static void fuse_uring_do_register(struct fuse_ring_ent *ent, {struct fuse_ring_queue *queue = ent->queue;struct fuse_ring *ring = queue->ring; -struct fuse_conn *fc = ring->fc; -struct fuse_iqueue *fiq = &fc->chan->iq; +struct fuse_chan *fch = ring->chan; +struct fuse_iqueue *fiq = &fch->iq;fuse_uring_prepare_cancel (cmd, issue_flags, ent);
@@ -998,7 +996,7 @@ static void fuse_uring_do_register(struct fuse_ring_ent *ent,if (ready) {WRITE_ONCE (fiq->ops, &fuse_io_uring_ops);WRITE_ONCE (ring->ready, true); -wake_up_all (&fc->chan->blocked_waitq); +wake_up_all (&fch->blocked_waitq); } } }
fs/fuse/dev_uring_i.h +1 -1
@@ -107,7 +107,7 @@ struct fuse_ring_queue {*/ struct fuse_ring {/* back pointer */ -struct fuse_conn *fc; +struct fuse_chan *chan;/* number of ring queues */ size_t nr_queues;
Signature · 1 line
2.53.0
PATCH 30/32 fuse: remove #include "fuse_i.h" from dev.c and dev_uring.c
In reply to Miklos SzerediMove a couple of function declarations from fuse_i.h to dev.h and fuse_dev_i.h.
Add fuse_conn_get_id() helper that retrieves the connection ID (s_dev) from fuse_conn.
With the exception of cuse.c, virtio_fs.c and trace.c source files now either include fuse_i.h or fuse_dev_i/dev_uring_i.h but not both.
--- fs/fuse/backing.c | 1 + fs/fuse/dev.c | 5 ++--- fs/fuse/dev.h | 26 ++++++++++++++++++++++++++ fs/fuse/dev_uring.c | 3 +-- fs/fuse/fuse_dev_i.h | 7 +++++++ fs/fuse/fuse_i.h | 28 ---------------------------- fs/fuse/inode.c | 5 +++++ 7 files changed, 42 insertions(+), 33 deletions(-)
fs/fuse/backing.c +1 -0
@@ -5,6 +5,7 @@* Copyright (c) 2023 CTERA Networks. */ +#include "dev.h" #include "fuse_i.h" #include <linux/file.h>
fs/fuse/dev.c +2 -3
@@ -7,9 +7,8 @@*/ #include "dev.h" +#include "args.h" #include "dev_uring_i.h" -#include "fuse_i.h" -#include "fuse_dev_i.h" #include <linux/init.h> #include <linux/module.h>
@@ -2336,7 +2335,7 @@ static void fuse_dev_show_fdinfo(struct seq_file *seq, struct file *file)if (!fud)return ; - seq_printf(seq, "fuse_connection:\t%u\n", fud->chan->conn->dev); + seq_printf(seq, "fuse_connection:\t%u\n", fuse_conn_get_id(fud->chan->conn)); }#endif
fs/fuse/dev.h +26 -0
@@ -13,6 +13,7 @@ struct fuse_chan;struct fuse_dev ;struct fuse_args ;struct fuse_copy_state ; +struct fuse_backing_map ;struct file ;struct folio ;enum fuse_notify_code ;
@@ -45,6 +46,16 @@ void fuse_chan_queue_forget(struct fuse_chan *fch, struct fuse_forget_link *forg DEFINE_FREE(fuse_chan_free, struct fuse_chan *, if (_T) fuse_chan_free(_T)) +/** +* Initialize the client device + */ +int fuse_dev_init (void ); + +/** +* Cleanup the client device +*/ +void fuse_dev_cleanup (void ); +void fuse_dev_install (struct fuse_dev *fud,struct fuse_chan *fch);bool fuse_dev_verify (struct fuse_dev *fud,struct fuse_chan *fch);void fuse_dev_put (struct fuse_dev *fud);
@@ -58,10 +69,25 @@ void fuse_init_server_timeout(struct fuse_chan *fch, unsigned int timeout);void fuse_chan_abort (struct fuse_chan *fch,bool abort_with_err);void fuse_chan_wait_aborted (struct fuse_chan *fch); +/** +* Acquire reference to fuse_conn +*/ +struct fuse_conn *fuse_conn_get (struct fuse_conn *fc); + +/** +* Release reference to fuse_conn +*/ +void fuse_conn_put (struct fuse_conn *fc); + +dev_t fuse_conn_get_id (struct fuse_conn *fc); +void fuse_end_polls (struct fuse_conn *fc);int fuse_notify (struct fuse_conn *fc,enum fuse_notify_code code,unsigned int size,struct fuse_copy_state *cs); +int fuse_backing_open (struct fuse_conn *fc,struct fuse_backing_map *map); +int fuse_backing_close (struct fuse_conn *fc,int backing_id); +int fuse_copy_one (struct fuse_copy_state *cs,void *val,unsigned size);int fuse_copy_folio (struct fuse_copy_state *cs,struct folio **foliop,unsigned offset,unsigned count,int zeroing);
fs/fuse/dev_uring.c +1 -2
@@ -5,9 +5,8 @@*/ #include "dev.h" -#include "fuse_i.h" +#include "args.h" #include "dev_uring_i.h" -#include "fuse_dev_i.h" #include "fuse_trace.h" #include <linux/fs.h>
fs/fuse/fuse_dev_i.h +7 -0
@@ -364,6 +364,11 @@ void fuse_dev_end_requests(struct list_head *head);void fuse_copy_init (struct fuse_copy_state *cs,bool write,struct iov_iter *iter); +/** +* Return the number of bytes in an arguments list +*/ +unsigned int fuse_len_args (unsigned int numargs,struct fuse_arg *args); +int fuse_copy_args (struct fuse_copy_state *cs,unsigned int numargs,unsigned int argpages,struct fuse_arg *args,int zeroing);
@@ -389,6 +394,8 @@ u64 fuse_get_unique(struct fuse_iqueue *fiq);struct fuse_dev *fuse_dev_alloc_install (struct fuse_chan *fch);struct fuse_dev *fuse_dev_alloc (void ); +int fuse_dev_release (struct inode *inode,struct file *file); +/** * Initialize the fuse processing queue */
fs/fuse/fuse_i.h +0 -28
@@ -907,16 +907,6 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,u32 fuse_get_cache_mask (struct inode *inode); -/** -* Initialize the client device -*/ -int fuse_dev_init (void ); - -/** -* Cleanup the client device -*/ -void fuse_dev_cleanup (void ); -int fuse_ctl_init (void ); void __exit fuse_ctl_cleanup(void);
@@ -971,22 +961,12 @@ u64 fuse_time_to_jiffies(u64 sec, u32 nsec);void fuse_change_entry_timeout (struct dentry *entry,struct fuse_entry_out *o); -/** -* Acquire reference to fuse_conn -*/ -struct fuse_conn *fuse_conn_get (struct fuse_conn *fc); -/** * Initialize fuse_conn */ void fuse_conn_init (struct fuse_conn *fc,struct fuse_mount *fm,struct user_namespace *user_ns,struct fuse_chan *fch); -/** -* Release reference to fuse_conn -*/ -void fuse_conn_put (struct fuse_conn *fc); -int fuse_send_init (struct fuse_mount *fm);/**
@@ -1105,7 +1085,6 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,long fuse_ioctl_common (struct file *file,unsigned int cmd,unsigned long arg,unsigned int flags);__poll_t fuse_file_poll (struct file *file,poll_table *wait); -int fuse_dev_release (struct inode *inode,struct file *file);bool fuse_write_update_attr (struct inode *inode,loff_t pos,ssize_t written);
@@ -1136,11 +1115,6 @@ int fuse_set_acl(struct mnt_idmap *, struct dentry *dentry,/* readdir.c */ int fuse_readdir (struct file *file,struct dir_context *ctx); -/** -* Return the number of bytes in an arguments list -*/ -unsigned int fuse_len_args (unsigned int numargs,struct fuse_arg *args); -void fuse_free_conn (struct fuse_conn *fc);/* dax.c */
@@ -1208,8 +1182,6 @@ static inline struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,void fuse_backing_files_init (struct fuse_conn *fc);void fuse_backing_files_free (struct fuse_conn *fc); -int fuse_backing_open (struct fuse_conn *fc,struct fuse_backing_map *map); -int fuse_backing_close (struct fuse_conn *fc,int backing_id);/* passthrough.c */ static inline struct fuse_backing *fuse_inode_backing (struct fuse_inode *fi)
fs/fuse/inode.c +5 -0
@@ -1031,6 +1031,11 @@ struct fuse_conn *fuse_conn_get(struct fuse_conn *fc) }EXPORT_SYMBOL_GPL (fuse_conn_get); +dev_t fuse_conn_get_id (struct fuse_conn *fc) +{ +return fc->dev; +} +static struct inode *fuse_get_root_inode (struct super_block *sb,unsigned int mode) {struct fuse_attr attr;
Signature · 1 line
2.53.0
PATCH 31/32 fuse: alloc pqueue before installing fch in fuse_dev
In reply to Miklos SzerediPrior to this patchset, fuse_dev (containing fuse_pqueue) was allocated on mount. But now fuse_dev is allocated when opening /dev/fuse, even though the queues are not needed at that time.
Delay allocation of the pqueue (4k worth of list_head) just before mounting or cloning a device.
Various distributions (e.g. Debian/Fedora) configure /dev/fuse as world writable, so the pqueue allocation should be deferred to a privileged operation (mount) to prevent unprivileged userspace from consuming pinned kernel memory.
--- fs/fuse/dev.c | 75 +++++++++++++++++++++++++++++++++----------- fs/fuse/fuse_dev_i.h | 3 ++ 2 files changed, 59 insertions(+), 19 deletions(-)
fs/fuse/dev.c +56 -19
@@ -328,6 +328,7 @@ void fuse_chan_release(struct fuse_chan *fch)void fuse_chan_free (struct fuse_chan *fch) {WARN_ON (!list_empty (&fch->devices)); +kfree (fch->pq_prealloc);kfree (fch); }EXPORT_SYMBOL_GPL (fuse_chan_free);
@@ -354,15 +355,30 @@ struct fuse_chan *fuse_chan_new(void) }EXPORT_SYMBOL_GPL (fuse_chan_new); +static struct list_head *fuse_pqueue_alloc (void ) +{ + struct list_head *pq = kzalloc_objs(struct list_head, FUSE_PQ_HASH_SIZE); + +if (pq) { +for (int i =0 ; i <FUSE_PQ_HASH_SIZE ; i++) +INIT_LIST_HEAD (&pq[i]); + } +return pq; +} +struct fuse_chan *fuse_dev_chan_new (void ) { -struct fuse_chan *fch =fuse_chan_new (); + struct fuse_chan *fch __free(kfree) = fuse_chan_new();if (!fch)return NULL ; + fch->pq_prealloc =fuse_pqueue_alloc (); +if (!fch->pq_prealloc) +return NULL ; +fuse_iqueue_init (&fch->iq, &fuse_dev_fiq_ops,NULL ); -return fch; +return no_free_ptr (fch); }EXPORT_SYMBOL_GPL (fuse_dev_chan_new);
@@ -403,39 +419,42 @@ void fuse_chan_io_uring_enable(struct fuse_chan *fch)void fuse_pqueue_init (struct fuse_pqueue *fpq) { -unsigned int i; -spin_lock_init (&fpq->lock); -for (i =0 ; i <FUSE_PQ_HASH_SIZE ; i++) -INIT_LIST_HEAD (&fpq->processing[i]);INIT_LIST_HEAD (&fpq->io); fpq->connected =1 ; + fpq->processing =NULL ; } -struct fuse_dev *fuse_dev_alloc (void ) +static struct fuse_dev *fuse_dev_alloc_no_pq (void ) {struct fuse_dev *fud; -struct list_head *pq; fud = kzalloc_obj(struct fuse_dev);if (!fud)return NULL ;refcount_set (&fud->ref,1 ); - pq = kzalloc_objs(struct list_head, FUSE_PQ_HASH_SIZE); -if (!pq) { -kfree (fud); -return NULL ; - } - - fud->pq.processing = pq;fuse_pqueue_init (&fud->pq);return fud; } + +struct fuse_dev *fuse_dev_alloc (void ) +{ + struct fuse_dev *fud __free(kfree) = fuse_dev_alloc_no_pq(); +if (!fud) +return NULL ; + + fud->pq.processing =fuse_pqueue_alloc (); +if (!fud->pq.processing) +return NULL ; + +return no_free_ptr (fud); +}EXPORT_SYMBOL_GPL (fuse_dev_alloc); -void fuse_dev_install (struct fuse_dev *fud,struct fuse_chan *fch) +static void fuse_dev_install_with_pq (struct fuse_dev *fud,struct fuse_chan *fch, +struct list_head *pq) {struct fuse_chan *old_fch;
@@ -453,20 +472,33 @@ void fuse_dev_install(struct fuse_dev *fud, struct fuse_chan *fch)* - it was set to disconneted */ fch->connected =0 ; +kfree (pq); }else { +if (pq) { +WARN_ON (fud->pq.processing); + fud->pq.processing = pq; + }list_add_tail (&fud->entry, &fch->devices);fuse_conn_get (fch->conn);wake_up_all (&fuse_dev_waitq); }spin_unlock (&fch->lock); } + +void fuse_dev_install (struct fuse_dev *fud,struct fuse_chan *fch) +{ +struct list_head *pq = fch->pq_prealloc; + + fch->pq_prealloc =NULL ; +fuse_dev_install_with_pq (fud, fch, pq); +}EXPORT_SYMBOL_GPL (fuse_dev_install);struct fuse_dev *fuse_dev_alloc_install (struct fuse_chan *fch) {struct fuse_dev *fud; - fud =fuse_dev_alloc (); + fud =fuse_dev_alloc_no_pq ();if (!fud)return NULL ;
@@ -1632,7 +1664,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,static int fuse_dev_open (struct inode *inode,struct file *file) { -struct fuse_dev *fud =fuse_dev_alloc (); +struct fuse_dev *fud =fuse_dev_alloc_no_pq ();if (!fud)return -ENOMEM ;
@@ -2231,6 +2263,7 @@ static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp) {int oldfd;struct fuse_dev *fud, *new_fud; +struct list_head *pq;if (get_user (oldfd, argp))return -EFAULT ;
@@ -2254,7 +2287,11 @@ static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp)if (fuse_dev_chan_get (new_fud))return -EINVAL ; -fuse_dev_install (new_fud, fud->chan); + pq =fuse_pqueue_alloc (); +if (!pq) +return -ENOMEM ; + +fuse_dev_install_with_pq (new_fud, fud->chan, pq);return 0 ; }
fs/fuse/fuse_dev_i.h +3 -0
@@ -248,6 +248,9 @@ struct fuse_chan {/* Maximum number of pages that can be used in a single request */ unsigned int max_pages; +/* Before being installed into fud, contains the preallocated pq array*/ +struct list_head *pq_prealloc; +/** Connection aborted via sysfs, respond with ECONNABORTED on device I/O */ bool abort_with_err;
Signature · 1 line
2.53.0
Joanne Koong
maintainerRe: [PATCH 31/32] fuse: alloc pqueue before installing fch in fuse_dev
Quoted 13 lines · Miklos Szeredi
Prior to this patchset,
fuse_dev(containingfuse_pqueue) was allocated on mount. But nowfuse_devis allocated when opening/dev/fuse, even though the queues are not needed at that time.Delay allocation of the pqueue (4k worth of
list_head) just before mounting or cloning a device.Various distributions (e.g. Debian/Fedora) configure
/dev/fuseas world writable, so the pqueue allocation should be deferred to a privileged operation (mount) to prevent unprivileged userspace from consuming pinned kernel memory.
Quoted 6 lines
Signed-off-by Miklos Szeredi <[email protected]>--- fs/fuse/dev.c | 75 +++++++++++++++++++++++++++++++++----------- fs/fuse/fuse_dev_i.h | 3 ++ 2 files changed, 59 insertions(+), 19 deletions(-)
Li reported [1] some missing uring side changes
Thanks,
Joanne
[1] https://lore.kernel.org/fuse-devel/[email protected]/T/#u
PATCH 32/32 fuse: simplify fuse_dev_ioctl_clone()
In reply to Miklos SzerediDon't need to check if the new device file is already initialized, since fuse_dev_install_with_pq() will do that anyway.
Make fuse_dev_install_with_pq() return a boolean value indicating success so that fuse_dev_ioctl_clone() can return an error in case of failure.
--- fs/fuse/dev.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
fs/fuse/dev.c +17 -16
@@ -453,12 +453,15 @@ struct fuse_dev *fuse_dev_alloc(void) }EXPORT_SYMBOL_GPL (fuse_dev_alloc); -static void fuse_dev_install_with_pq (struct fuse_dev *fud,struct fuse_chan *fch, +/* +* Installs @fch into @fud, return true on success. "Consumes" @pq in either case. +*/ +static bool fuse_dev_install_with_pq (struct fuse_dev *fud,struct fuse_chan *fch,struct list_head *pq) {struct fuse_chan *old_fch; -spin_lock (&fch->lock); +guard (spinlock)(&fch->lock);/* * Pairs with: * - xchg() in fuse_dev_release()
@@ -473,16 +476,16 @@ static void fuse_dev_install_with_pq(struct fuse_dev *fud, struct fuse_chan *fch*/ fch->connected =0 ;kfree (pq); - }else { -if (pq) { -WARN_ON (fud->pq.processing); - fud->pq.processing = pq; - } -list_add_tail (&fud->entry, &fch->devices); -fuse_conn_get (fch->conn); -wake_up_all (&fuse_dev_waitq); +return false; } -spin_unlock (&fch->lock); +if (pq) { +WARN_ON (fud->pq.processing); + fud->pq.processing = pq; + } +list_add_tail (&fud->entry, &fch->devices); +fuse_conn_get (fch->conn); +wake_up_all (&fuse_dev_waitq); +return true; }void fuse_dev_install (struct fuse_dev *fud,struct fuse_chan *fch)
@@ -2283,15 +2286,13 @@ static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp)if (IS_ERR (fud))return PTR_ERR (fud); - new_fud =fuse_file_to_fud (file); -if (fuse_dev_chan_get (new_fud)) -return -EINVAL ; - pq =fuse_pqueue_alloc ();if (!pq)return -ENOMEM ; -fuse_dev_install_with_pq (new_fud, fud->chan, pq); + new_fud =fuse_file_to_fud (file); +if (!fuse_dev_install_with_pq (new_fud, fud->chan, pq)) +return -EINVAL ;return 0 ; }
Signature · 1 line
2.53.0