[PATCH 1/2] fuse: don't wait for a sync-init mount in non-blocking reads

From: Yun Wang

Date: Thu Nov 19 2026 - 06:36:59 EST


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.

Add fuse_get_dev_nowait(), which returns -EAGAIN instead of waiting for
the mount, and fuse_get_dev_read(), which uses it for O_NONBLOCK files,
and call the latter from fuse_dev_read() and fuse_dev_splice_read().
fuse_get_dev() is unchanged and keeps waiting for its other callers.

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")
Signed-off-by: Yun Wang <arsenova@xxxxxxxxx>
---
fs/fuse/dev.c | 12 ++++++++++--
fs/fuse/fuse_dev_i.h | 14 ++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 3641abb90d..23ba4f432d 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1705,11 +1705,19 @@ struct fuse_dev *fuse_get_dev(struct file *file)
return fud;
}

+/* read(2) and splice(2) of an O_NONBLOCK device don't wait for the mount */
+static struct fuse_dev *fuse_get_dev_read(struct file *file)
+{
+ if (file->f_flags & O_NONBLOCK)
+ return fuse_get_dev_nowait(file);
+ return fuse_get_dev(file);
+}
+
static ssize_t fuse_dev_read(struct kiocb *iocb, struct iov_iter *to)
{
struct fuse_copy_state cs;
struct file *file = iocb->ki_filp;
- struct fuse_dev *fud = fuse_get_dev(file);
+ struct fuse_dev *fud = fuse_get_dev_read(file);

if (IS_ERR(fud))
return PTR_ERR(fud);
@@ -1730,7 +1738,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
int page_nr = 0;
struct pipe_buffer *bufs;
struct fuse_copy_state cs;
- struct fuse_dev *fud = fuse_get_dev(in);
+ struct fuse_dev *fud = fuse_get_dev_read(in);

if (IS_ERR(fud))
return PTR_ERR(fud);
diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h
index 4b412a7622..bb7e10656a 100644
--- a/fs/fuse/fuse_dev_i.h
+++ b/fs/fuse/fuse_dev_i.h
@@ -367,6 +367,20 @@ static inline struct fuse_dev *__fuse_get_dev(struct file *file)
return fud;
}

+/*
+ * 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;
+}
+
void fuse_iqueue_init(struct fuse_iqueue *fiq, const struct fuse_iqueue_ops *ops, void *priv);

struct fuse_dev *fuse_get_dev(struct file *file);
--
2.56.1