From: Miklos Szeredi <mszeredi@redhat.com>
To: fuse-devel@lists.linux.dev, linux-fsdevel@vger.kernel.org
Subject: [PATCH 23/32] fuse: split out filesystem part of request sending
Date: Thu, 16 Apr 2026 11:16:47 +0200 [thread overview]
Message-ID: <20260416091658.462783-24-mszeredi@redhat.com> (raw)
In-Reply-To: <20260416091658.462783-1-mszeredi@redhat.com>
Create 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.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
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
diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile
index 30dd1bee931d..08be6817a1cc 100644
--- a/fs/fuse/Makefile
+++ b/fs/fuse/Makefile
@@ -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
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 5b74bd4d7cc3..95b8de20542a 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -101,75 +101,44 @@ static void fuse_drop_waiting(struct fuse_chan *fch)
static void fuse_put_request(struct fuse_req *req);
-static struct fuse_req *fuse_get_req(struct mnt_idmap *idmap,
- struct fuse_mount *fm,
- bool for_background)
+static struct fuse_req *fuse_get_req(struct fuse_chan *fch, bool for_background)
{
- struct fuse_conn *fc = fm->fc;
struct fuse_req *req;
- bool no_idmap = !fm->sb || (fm->sb->s_iflags & SB_I_NOIDMAP);
- kuid_t fsuid;
- kgid_t fsgid;
int err;
- atomic_inc(&fc->chan->num_waiting);
+ atomic_inc(&fch->num_waiting);
- if (fuse_block_alloc(fc, for_background)) {
+ if (fuse_block_alloc(fch->conn, for_background)) {
err = -EINTR;
- if (wait_event_state_exclusive(fc->chan->blocked_waitq,
- !fuse_block_alloc(fc, for_background),
+ if (wait_event_state_exclusive(fch->blocked_waitq,
+ !fuse_block_alloc(fch->conn, for_background),
(TASK_KILLABLE | TASK_FREEZABLE)))
goto out;
}
+
/* Matches smp_wmb() in fuse_chan_set_initialized() */
smp_rmb();
err = -ENOTCONN;
- if (!fc->chan->connected)
- goto out;
-
- err = -ECONNREFUSED;
- if (fc->conn_error)
+ if (!fch->connected)
goto out;
- req = fuse_request_alloc(fc->chan, GFP_KERNEL);
+ req = fuse_request_alloc(fch, GFP_KERNEL);
err = -ENOMEM;
if (!req) {
if (for_background)
- wake_up(&fc->chan->blocked_waitq);
+ wake_up(&fch->blocked_waitq);
goto out;
}
- req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns);
-
__set_bit(FR_WAITING, &req->flags);
if (for_background)
__set_bit(FR_BACKGROUND, &req->flags);
- /*
- * Keep the old behavior when idmappings support was not
- * declared by a FUSE server.
- *
- * For those FUSE servers who support idmapped mounts,
- * we send UID/GID only along with "inode creation"
- * fuse requests, otherwise idmap == &invalid_mnt_idmap and
- * req->in.h.{u,g}id will be equal to FUSE_INVALID_UIDGID.
- */
- fsuid = no_idmap ? current_fsuid() : mapped_fsuid(idmap, fc->user_ns);
- fsgid = no_idmap ? current_fsgid() : mapped_fsgid(idmap, fc->user_ns);
- req->in.h.uid = from_kuid(fc->user_ns, fsuid);
- req->in.h.gid = from_kgid(fc->user_ns, fsgid);
-
- if (no_idmap && unlikely(req->in.h.uid == ((uid_t)-1) ||
- req->in.h.gid == ((gid_t)-1))) {
- fuse_put_request(req);
- return ERR_PTR(-EOVERFLOW);
- }
-
return req;
out:
- fuse_drop_waiting(fc->chan);
+ fuse_drop_waiting(fch);
return ERR_PTR(err);
}
@@ -775,25 +744,13 @@ static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args)
}
}
-static void fuse_force_creds(struct fuse_mount *fm, struct fuse_req *req)
-{
- struct fuse_conn *fc = fm->fc;
-
- 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 {
- req->in.h.uid = FUSE_INVALID_UIDGID;
- req->in.h.gid = FUSE_INVALID_UIDGID;
- }
-
- req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns);
-}
-
static void fuse_args_to_req(struct fuse_req *req, struct fuse_args *args)
{
req->in.h.opcode = args->opcode;
req->in.h.nodeid = args->nodeid;
+ req->in.h.uid = args->uid;
+ req->in.h.gid = args->gid;
+ req->in.h.pid = args->pid;
req->args = args;
if (args->is_ext)
req->in.h.total_extlen = args->in_args[args->ext_idx].size / 8;
@@ -801,33 +758,26 @@ static void fuse_args_to_req(struct fuse_req *req, struct fuse_args *args)
__set_bit(FR_ASYNC, &req->flags);
}
-ssize_t __fuse_simple_request(struct mnt_idmap *idmap,
- struct fuse_mount *fm,
- struct fuse_args *args)
+ssize_t fuse_chan_send(struct fuse_chan *fch, struct fuse_args *args)
{
- struct fuse_conn *fc = fm->fc;
struct fuse_req *req;
ssize_t ret;
if (args->force) {
- atomic_inc(&fc->chan->num_waiting);
- req = fuse_request_alloc(fc->chan, GFP_KERNEL | __GFP_NOFAIL);
-
- if (!args->nocreds)
- fuse_force_creds(fm, req);
+ atomic_inc(&fch->num_waiting);
+ req = fuse_request_alloc(fch, GFP_KERNEL | __GFP_NOFAIL);
__set_bit(FR_WAITING, &req->flags);
if (!args->abort_on_kill)
__set_bit(FR_FORCE, &req->flags);
} else {
- WARN_ON(args->nocreds);
- req = fuse_get_req(idmap, fm, false);
+ req = fuse_get_req(fch, false);
if (IS_ERR(req))
return PTR_ERR(req);
}
/* Needs to be done after fuse_get_req() so that fc->minor is valid */
- fuse_adjust_compat(fc, args);
+ fuse_adjust_compat(fch->conn, args);
fuse_args_to_req(req, args);
if (!args->noreply)
@@ -891,20 +841,17 @@ static int fuse_request_queue_background(struct fuse_req *req)
return queued;
}
-int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args,
- gfp_t gfp_flags)
+int fuse_chan_send_bg(struct fuse_chan *fch, struct fuse_args *args, gfp_t gfp_flags)
{
struct fuse_req *req;
if (args->force) {
- WARN_ON(!args->nocreds);
- req = fuse_request_alloc(fm->fc->chan, gfp_flags);
+ req = fuse_request_alloc(fch, gfp_flags);
if (!req)
return -ENOMEM;
__set_bit(FR_BACKGROUND, &req->flags);
} else {
- WARN_ON(args->nocreds);
- req = fuse_get_req(&invalid_mnt_idmap, fm, true);
+ req = fuse_get_req(fch, true);
if (IS_ERR(req))
return PTR_ERR(req);
}
@@ -918,15 +865,13 @@ int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args,
return 0;
}
-EXPORT_SYMBOL_GPL(fuse_simple_background);
-static int fuse_simple_notify_reply(struct fuse_mount *fm,
- struct fuse_args *args, u64 unique)
+int fuse_chan_send_notify_reply(struct fuse_chan *fch, struct fuse_args *args, u64 unique)
{
struct fuse_req *req;
- struct fuse_iqueue *fiq = &fm->fc->chan->iq;
+ struct fuse_iqueue *fiq = &fch->iq;
- req = fuse_get_req(&invalid_mnt_idmap, fm, false);
+ req = fuse_get_req(fch, false);
if (IS_ERR(req))
return PTR_ERR(req);
diff --git a/fs/fuse/dev.h b/fs/fuse/dev.h
index a0c1212573d6..fb814a0b6782 100644
--- a/fs/fuse/dev.h
+++ b/fs/fuse/dev.h
@@ -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,
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 22a6d58678ad..f7a9c7cedd39 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -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);
diff --git a/fs/fuse/req.c b/fs/fuse/req.c
new file mode 100644
index 000000000000..a01ee743d31e
--- /dev/null
+++ b/fs/fuse/req.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include "dev.h"
+#include "fuse_i.h"
+
+static int fuse_fill_creds(struct fuse_mount *fm, struct fuse_args *args, struct mnt_idmap *idmap)
+{
+ struct fuse_conn *fc = fm->fc;
+ bool no_idmap = !fm->sb || (fm->sb->s_iflags & SB_I_NOIDMAP);
+ kuid_t fsuid = mapped_fsuid(idmap, fc->user_ns);
+ kgid_t fsgid = mapped_fsgid(idmap, fc->user_ns);
+
+ args->pid = pid_nr_ns(task_pid(current), fc->pid_ns);
+
+ if (args->force) {
+ if (args->nocreds)
+ return 0;
+
+ if (no_idmap) {
+ args->uid = from_kuid_munged(fc->user_ns, current_fsuid());
+ args->gid = from_kgid_munged(fc->user_ns, current_fsgid());
+ } else {
+ args->uid = FUSE_INVALID_UIDGID;
+ args->gid = FUSE_INVALID_UIDGID;
+ }
+ return 0;
+ }
+
+ WARN_ON(args->nocreds);
+ /*
+ * Keep the old behavior when idmappings support was not
+ * declared by a FUSE server.
+ *
+ * For those FUSE servers who support idmapped mounts, we send UID/GID
+ * only along with "inode creation" fuse requests, otherwise idmap ==
+ * &invalid_mnt_idmap and req->in.h.{u,g}id will be equal to
+ * FUSE_INVALID_UIDGID.
+ */
+ if (no_idmap) {
+ fsuid = current_fsuid();
+ fsgid = current_fsgid();
+ }
+ args->uid = from_kuid(fc->user_ns, fsuid);
+ args->gid = from_kgid(fc->user_ns, fsgid);
+
+ if (no_idmap && unlikely(args->uid == ((uid_t)-1) || args->gid == ((gid_t)-1)))
+ return -EOVERFLOW;
+
+ return 0;
+}
+
+static int fuse_req_prep(struct fuse_mount *fm, struct fuse_args *args, struct mnt_idmap *idmap)
+{
+ if (!args->force && fm->fc->conn_error)
+ return -ECONNREFUSED;
+
+ return fuse_fill_creds(fm, args, idmap);
+}
+
+ssize_t __fuse_simple_request(struct mnt_idmap *idmap, struct fuse_mount *fm,
+ struct fuse_args *args)
+{
+ struct fuse_conn *fc = fm->fc;
+ int err = fuse_req_prep(fm, args, idmap);
+
+ if (err)
+ return err;
+
+ return fuse_chan_send(fc->chan, args);
+}
+
+int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args, gfp_t gfp_flags)
+{
+ struct fuse_conn *fc = fm->fc;
+ int err;
+
+ WARN_ON(args->force && !args->nocreds);
+
+ err = fuse_req_prep(fm, args, &invalid_mnt_idmap);
+ if (err)
+ return err;
+
+ return fuse_chan_send_bg(fc->chan, args, gfp_flags);
+}
+EXPORT_SYMBOL_GPL(fuse_simple_background);
+
+int fuse_simple_notify_reply(struct fuse_mount *fm, struct fuse_args *args, u64 unique)
+{
+ struct fuse_conn *fc = fm->fc;
+ int err;
+
+ WARN_ON(args->force && !args->nocreds);
+
+ err = fuse_req_prep(fm, args, &invalid_mnt_idmap);
+ if (err)
+ return err;
+
+ return fuse_chan_send_notify_reply(fc->chan, args, unique);
+}
--
2.53.0
next prev parent reply other threads:[~2026-04-16 9:17 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 9:16 [PATCH 00/32] fuse: improve transport and fs layer separation Miklos Szeredi
2026-04-16 9:16 ` [PATCH 01/32] fuse: move request timeout code to a new source file Miklos Szeredi
2026-04-16 9:16 ` [PATCH 02/32] fuse: add struct fuse_chan Miklos Szeredi
2026-04-16 9:16 ` [PATCH 03/32] fuse: move fuse_iqueue to fuse_chan Miklos Szeredi
2026-04-16 9:16 ` [PATCH 04/32] fuse: move fuse_dev and fuse_pqueue to dev.c Miklos Szeredi
2026-04-16 9:16 ` [PATCH 05/32] fuse: move 'devices' member from fuse_conn to fuse_chan Miklos Szeredi
2026-04-16 9:16 ` [PATCH 06/32] fuse: move background queuing related members " Miklos Szeredi
2026-04-22 17:53 ` Joanne Koong
2026-04-23 7:20 ` Miklos Szeredi
2026-04-16 9:16 ` [PATCH 07/32] fuse: move request blocking " Miklos Szeredi
2026-04-16 9:16 ` [PATCH 08/32] fuse: move io_uring " Miklos Szeredi
2026-04-16 9:16 ` [PATCH 09/32] fuse: move interrupt " Miklos Szeredi
2026-04-16 9:16 ` [PATCH 10/32] fuse: split off fch->lock from fc->lock Miklos Szeredi
2026-04-16 9:16 ` [PATCH 11/32] fuse: add back pointer from fuse_chan to fuse_conn Miklos Szeredi
2026-04-16 9:16 ` [PATCH 12/32] fuse: move request timeout to fuse_chan Miklos Szeredi
2026-04-16 9:16 ` [PATCH 13/32] fuse: move struct fuse_req and related to fuse_dev_i.h Miklos Szeredi
2026-04-16 9:16 ` [PATCH 14/32] fuse: don't access transport layer structs directly from the fs layer Miklos Szeredi
2026-04-16 9:16 ` [PATCH 15/32] fuse: move forget related struct and helpers Miklos Szeredi
2026-04-16 9:16 ` [PATCH 16/32] fuse: move fuse_dev_waitq to dev.c Miklos Szeredi
2026-04-16 9:16 ` [PATCH 17/32] fuse: remove #include "fuse_i.h" from "dev_uring_i.h" Miklos Szeredi
2026-04-16 9:16 ` [PATCH 18/32] fuse: remove #include "fuse_i.h" from "req_timeout.c" Miklos Szeredi
2026-04-16 9:16 ` [PATCH 19/32] fuse: abort related layering cleanup Miklos Szeredi
2026-04-16 9:16 ` [PATCH 20/32] fuse: split off fuse_args and related definitions into a separate header Miklos Szeredi
2026-04-17 21:52 ` Joanne Koong
2026-04-20 10:14 ` Miklos Szeredi
2026-04-16 9:16 ` [PATCH 21/32] fuse: remove fm arg of args->end callback Miklos Szeredi
2026-04-16 9:16 ` [PATCH 22/32] fuse: change req->fm to req->chan Miklos Szeredi
2026-04-16 9:16 ` Miklos Szeredi [this message]
2026-04-16 9:16 ` [PATCH 24/32] fuse: change fud->fc to fud->chan Miklos Szeredi
2026-04-16 9:16 ` [PATCH 25/32] fuse: create poll.c Miklos Szeredi
2026-04-16 9:16 ` [PATCH 26/32] fuse: create notify.c Miklos Szeredi
2026-04-16 9:16 ` [PATCH 27/32] fuse: set params in fuse_chan_set_initialized() Miklos Szeredi
2026-04-22 17:41 ` Joanne Koong
2026-04-23 7:19 ` Miklos Szeredi
2026-04-16 9:16 ` [PATCH 28/32] fuse: remove fuse_mutex protection from fuse_dev_ioctl_sync_init() Miklos Szeredi
2026-04-16 9:16 ` [PATCH 29/32] fuse: change ring->fc to ring->chan Miklos Szeredi
2026-04-16 9:16 ` [PATCH 30/32] fuse: remove #include "fuse_i.h" from dev.c and dev_uring.c Miklos Szeredi
2026-04-16 9:16 ` [PATCH 31/32] fuse: alloc pqueue before installing fch in fuse_dev Miklos Szeredi
2026-04-22 19:30 ` Joanne Koong
2026-04-16 9:16 ` [PATCH 32/32] fuse: simplify fuse_dev_ioctl_clone() Miklos Szeredi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260416091658.462783-24-mszeredi@redhat.com \
--to=mszeredi@redhat.com \
--cc=fuse-devel@lists.linux.dev \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox