[PATCH v2 2/5] fuse: don't wait for a sync-init mount in non-blocking reads
From: Yun Wang
Date: Sun Nov 22 2026 - 10:26:42 EST
From: Yun Wang <arsenova@xxxxxxxxx>
Since commit dfb84c330794 ("fuse: allow synchronous FUSE_INIT"),
fuse_get_dev() waits until the mount has installed the channel when
FUSE_DEV_IOC_SYNC_INIT was used on the device. fuse_dev_read() and
fuse_dev_splice_read() call it before fuse_dev_do_read() looks at
O_NONBLOCK, so read(2) or splice(2) on an O_NONBLOCK sync-init device
that is not mounted yet sleeps until the mount or a signal, instead of
returning -EAGAIN. Commit 9f6f44aa5a58 ("fuse: don't block in
fuse_get_dev() for non-sync_init case") fixed the same hang for
devices without sync init, which LTP's read_all hit with O_NONBLOCK
reads of /dev/fuse.
Rename fuse_get_dev() to _fuse_get_dev() and add
fuse_get_dev_nowait(), which returns -EAGAIN instead of waiting for
the mount. The new fuse_get_dev() uses the latter for O_NONBLOCK
files and is called from fuse_dev_read() and fuse_dev_splice_read().
The other callers still wait whether or not the file is O_NONBLOCK
and call _fuse_get_dev(); fuse_uring_cmd() and ->poll are fixed in
the next patches.
A non-blocking read before the mount now gets -EAGAIN, the same as
after the mount while no request is queued. Blocking reads still wait
for the mount.
Fixes: dfb84c330794 ("fuse: allow synchronous FUSE_INIT")
Reviewed-by: Bernd Schubert <bernd@xxxxxxxxxxx>
Signed-off-by: Yun Wang <arsenova@xxxxxxxxx>
---
fs/fuse/dev.c | 10 +++++-----
fs/fuse/dev_uring.c | 2 +-
fs/fuse/fuse_dev_i.h | 30 ++++++++++++++++++++++++++++--
3 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 2f6991d0e959..7cb93885cd0a 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1687,7 +1687,7 @@ static int fuse_dev_open(struct inode *inode, struct file *file)
return 0;
}
-struct fuse_dev *fuse_get_dev(struct file *file)
+struct fuse_dev *_fuse_get_dev(struct file *file)
{
struct fuse_dev *fud = fuse_file_to_fud(file);
int err;
@@ -2106,7 +2106,7 @@ static __poll_t fuse_dev_poll(struct file *file, poll_table *wait)
{
__poll_t mask = EPOLLOUT | EPOLLWRNORM;
struct fuse_iqueue *fiq;
- struct fuse_dev *fud = fuse_get_dev(file);
+ struct fuse_dev *fud = _fuse_get_dev(file);
if (IS_ERR(fud))
return EPOLLERR;
@@ -2293,7 +2293,7 @@ static int fuse_dev_fasync(int fd, struct file *file, int on)
if (!fud)
return 0;
} else {
- fud = fuse_get_dev(file);
+ fud = _fuse_get_dev(file);
if (IS_ERR(fud))
return PTR_ERR(fud);
}
@@ -2322,7 +2322,7 @@ static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp)
if (fd_file(f)->f_op != file->f_op)
return -EINVAL;
- fud = fuse_get_dev(fd_file(f));
+ fud = _fuse_get_dev(fd_file(f));
if (IS_ERR(fud))
return PTR_ERR(fud);
@@ -2339,7 +2339,7 @@ static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp)
static struct fuse_conn *fuse_get_conn_for_passthrough(struct file *file)
{
- struct fuse_dev *fud = fuse_get_dev(file);
+ struct fuse_dev *fud = _fuse_get_dev(file);
if (IS_ERR(fud))
return ERR_CAST(fud);
diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
index 460776cd69cd..92240ab76e45 100644
--- a/fs/fuse/dev_uring.c
+++ b/fs/fuse/dev_uring.c
@@ -1664,7 +1664,7 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
if (!(issue_flags & IO_URING_F_SQE128))
return -EINVAL;
- fud = fuse_get_dev(cmd->file);
+ fud = _fuse_get_dev(cmd->file);
if (IS_ERR(fud)) {
pr_info_ratelimited("No fuse device found\n");
return PTR_ERR(fud);
diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h
index 4b412a76225f..808152b75792 100644
--- a/fs/fuse/fuse_dev_i.h
+++ b/fs/fuse/fuse_dev_i.h
@@ -367,9 +367,35 @@ static inline struct fuse_dev *__fuse_get_dev(struct file *file)
return fud;
}
-void fuse_iqueue_init(struct fuse_iqueue *fiq, const struct fuse_iqueue_ops *ops, void *priv);
+/* Get the device, waiting for the mount of a sync-init device */
+struct fuse_dev *_fuse_get_dev(struct file *file);
+
+/*
+ * Like _fuse_get_dev(), but don't wait for the mount of a sync-init device:
+ * return -EAGAIN instead.
+ */
+static inline struct fuse_dev *fuse_get_dev_nowait(struct file *file)
+{
+ struct fuse_dev *fud = fuse_file_to_fud(file);
+
+ if (unlikely(!fuse_dev_chan_get(fud)))
+ return ERR_PTR(fud->sync_init ? -EAGAIN : -EPERM);
+
+ return fud;
+}
+
+/*
+ * For read(2) and splice(2): an O_NONBLOCK device doesn't wait for the
+ * mount of a sync-init device.
+ */
+static inline struct fuse_dev *fuse_get_dev(struct file *file)
+{
+ if (file->f_flags & O_NONBLOCK)
+ return fuse_get_dev_nowait(file);
+ return _fuse_get_dev(file);
+}
-struct fuse_dev *fuse_get_dev(struct file *file);
+void fuse_iqueue_init(struct fuse_iqueue *fiq, const struct fuse_iqueue_ops *ops, void *priv);
unsigned int fuse_req_hash(u64 unique);
struct fuse_req *fuse_request_find(struct fuse_pqueue *fpq, u64 unique);
--
2.56.1