public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/5] fuse: implement file attributes mask for statx
  2025-10-29  0:37 [PATCHSET v6 1/8] fuse: general bug fixes Darrick J. Wong
@ 2025-10-29  0:43 ` Darrick J. Wong
  2025-11-03 18:30   ` Joanne Koong
  0 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2025-10-29  0:43 UTC (permalink / raw)
  To: djwong, miklos
  Cc: joannelkoong, joannelkoong, bernd, neal, linux-ext4,
	linux-fsdevel

From: Darrick J. Wong <djwong@kernel.org>

Actually copy the attributes/attributes_mask from userspace.  Ignore
file attributes bits that the VFS sets (or doesn't set) on its own.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/fuse_i.h |   37 +++++++++++++++++++++++++++++++++++++
 fs/fuse/dir.c    |    4 ++++
 fs/fuse/inode.c  |    4 ++++
 3 files changed, 45 insertions(+)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index a8068bee90af57..8c47d103c8ffa6 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -140,6 +140,10 @@ struct fuse_inode {
 	/** Version of last attribute change */
 	u64 attr_version;
 
+	/** statx file attributes */
+	u64 statx_attributes;
+	u64 statx_attributes_mask;
+
 	union {
 		/* read/write io cache (regular file only) */
 		struct {
@@ -1235,6 +1239,39 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
 				   u64 attr_valid, u32 cache_mask,
 				   u64 evict_ctr);
 
+/*
+ * These statx attribute flags are set by the VFS so mask them out of replies
+ * from the fuse server for local filesystems.  Nonlocal filesystems are
+ * responsible for enforcing and advertising these flags themselves.
+ */
+#define FUSE_STATX_LOCAL_VFS_ATTRIBUTES (STATX_ATTR_IMMUTABLE | \
+					 STATX_ATTR_APPEND)
+
+/*
+ * These statx attribute flags are set by the VFS so mask them out of replies
+ * from the fuse server.
+ */
+#define FUSE_STATX_VFS_ATTRIBUTES (STATX_ATTR_AUTOMOUNT | STATX_ATTR_DAX | \
+				   STATX_ATTR_MOUNT_ROOT)
+
+static inline u64 fuse_statx_attributes_mask(const struct inode *inode,
+					     const struct fuse_statx *sx)
+{
+	if (fuse_inode_is_exclusive(inode))
+		return sx->attributes_mask & ~(FUSE_STATX_VFS_ATTRIBUTES |
+					       FUSE_STATX_LOCAL_VFS_ATTRIBUTES);
+	return sx->attributes_mask & ~FUSE_STATX_VFS_ATTRIBUTES;
+}
+
+static inline u64 fuse_statx_attributes(const struct inode *inode,
+					const struct fuse_statx *sx)
+{
+	if (fuse_inode_is_exclusive(inode))
+		return sx->attributes & ~(FUSE_STATX_VFS_ATTRIBUTES |
+					  FUSE_STATX_LOCAL_VFS_ATTRIBUTES);
+	return sx->attributes & ~FUSE_STATX_VFS_ATTRIBUTES;
+}
+
 u32 fuse_get_cache_mask(struct inode *inode);
 
 /**
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index ecaec0fea3a132..636d47a5127ca1 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1271,6 +1271,8 @@ static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
 		stat->result_mask = sx->mask & (STATX_BASIC_STATS | STATX_BTIME);
 		stat->btime.tv_sec = sx->btime.tv_sec;
 		stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec, NSEC_PER_SEC - 1);
+		stat->attributes |= fuse_statx_attributes(inode, sx);
+		stat->attributes_mask |= fuse_statx_attributes_mask(inode, sx);
 		fuse_fillattr(idmap, inode, &attr, stat);
 		stat->result_mask |= STATX_TYPE;
 	}
@@ -1375,6 +1377,8 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,
 			stat->btime = fi->i_btime;
 			stat->result_mask |= STATX_BTIME;
 		}
+		stat->attributes = fi->statx_attributes;
+		stat->attributes_mask = fi->statx_attributes_mask;
 	}
 
 	return err;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index d048d634ef46f5..76e5b7f5c980c2 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -286,6 +286,10 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
 			fi->i_btime.tv_sec = sx->btime.tv_sec;
 			fi->i_btime.tv_nsec = sx->btime.tv_nsec;
 		}
+
+		fi->statx_attributes = fuse_statx_attributes(inode, sx);
+		fi->statx_attributes_mask = fuse_statx_attributes_mask(inode,
+								       sx);
 	}
 
 	if (attr->blksize)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* Re: [PATCH 3/5] fuse: implement file attributes mask for statx
  2025-10-29  0:43 ` [PATCH 3/5] fuse: implement file attributes mask for statx Darrick J. Wong
@ 2025-11-03 18:30   ` Joanne Koong
  2025-11-03 18:43     ` Joanne Koong
  0 siblings, 1 reply; 234+ messages in thread
From: Joanne Koong @ 2025-11-03 18:30 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: miklos, bernd, neal, linux-ext4, linux-fsdevel

> diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> index a8068bee90af57..8c47d103c8ffa6 100644
> --- a/fs/fuse/fuse_i.h
> +++ b/fs/fuse/fuse_i.h
> @@ -140,6 +140,10 @@ struct fuse_inode {
>         /** Version of last attribute change */
>         u64 attr_version;
>
> +       /** statx file attributes */
> +       u64 statx_attributes;
> +       u64 statx_attributes_mask;
> +
>         union {
>                 /* read/write io cache (regular file only) */
>                 struct {
> @@ -1235,6 +1239,39 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
>                                    u64 attr_valid, u32 cache_mask,
>                                    u64 evict_ctr);
>
> +/*
> + * These statx attribute flags are set by the VFS so mask them out of replies
> + * from the fuse server for local filesystems.  Nonlocal filesystems are
> + * responsible for enforcing and advertising these flags themselves.
> + */
> +#define FUSE_STATX_LOCAL_VFS_ATTRIBUTES (STATX_ATTR_IMMUTABLE | \
> +                                        STATX_ATTR_APPEND)

for STATX_ATTR_IMMUTABLE and STATX_ATTR_APPEND, I see in
generic_fill_statx_attr() that they get set if the inode has the
S_IMMUTABLE flag and the S_APPEND flag set, but I'm not seeing how
this is relevant to fuse. I'm not seeing anywhere in the vfs layer
that sets S_APPEND or STATX_ATTR_IMMUTABLE, I only see specific
filesystems setting them, which fuse doesn't do. Is there something
I'm missing?

Thanks,
Joanne

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 3/5] fuse: implement file attributes mask for statx
  2025-11-03 18:30   ` Joanne Koong
@ 2025-11-03 18:43     ` Joanne Koong
  2025-11-03 19:28       ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Joanne Koong @ 2025-11-03 18:43 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: miklos, bernd, neal, linux-ext4, linux-fsdevel

On Mon, Nov 3, 2025 at 10:30 AM Joanne Koong <joannelkoong@gmail.com> wrote:
>
> > diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> > index a8068bee90af57..8c47d103c8ffa6 100644
> > --- a/fs/fuse/fuse_i.h
> > +++ b/fs/fuse/fuse_i.h
> > @@ -140,6 +140,10 @@ struct fuse_inode {
> >         /** Version of last attribute change */
> >         u64 attr_version;
> >
> > +       /** statx file attributes */
> > +       u64 statx_attributes;
> > +       u64 statx_attributes_mask;
> > +
> >         union {
> >                 /* read/write io cache (regular file only) */
> >                 struct {
> > @@ -1235,6 +1239,39 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
> >                                    u64 attr_valid, u32 cache_mask,
> >                                    u64 evict_ctr);
> >
> > +/*
> > + * These statx attribute flags are set by the VFS so mask them out of replies
> > + * from the fuse server for local filesystems.  Nonlocal filesystems are
> > + * responsible for enforcing and advertising these flags themselves.
> > + */
> > +#define FUSE_STATX_LOCAL_VFS_ATTRIBUTES (STATX_ATTR_IMMUTABLE | \
> > +                                        STATX_ATTR_APPEND)
>
> for STATX_ATTR_IMMUTABLE and STATX_ATTR_APPEND, I see in
> generic_fill_statx_attr() that they get set if the inode has the
> S_IMMUTABLE flag and the S_APPEND flag set, but I'm not seeing how
> this is relevant to fuse. I'm not seeing anywhere in the vfs layer
> that sets S_APPEND or STATX_ATTR_IMMUTABLE, I only see specific
> filesystems setting them, which fuse doesn't do. Is there something
> I'm missing?

Ok, I see. In patchset 6/8 patch 3/9 [1],
FUSE_ATTR_SYNC/FUSE_ATTR_IMMUTABLE/FUSE_ATTR_APPEND flags get added
which signify that S_SYNC/S_IMMUTABLE/S_APPEND should get set on the
inode.  Hmm I'm confused why we would want to mask them out for local
filesystems. If FUSE_ATTR_SYNC/FUSE_ATTR_IMMUTABLE/FUSE_ATTR_APPEND
are getting passed in by the fuse server and getting enforced, why
don't we want them to show up in stax?

Thanks,
Joanne

[1] https://lore.kernel.org/linux-fsdevel/176169811656.1426244.11474449087922753694.stgit@frogsfrogsfrogs/
>
> Thanks,
> Joanne

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 3/5] fuse: implement file attributes mask for statx
  2025-11-03 18:43     ` Joanne Koong
@ 2025-11-03 19:28       ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2025-11-03 19:28 UTC (permalink / raw)
  To: Joanne Koong; +Cc: miklos, bernd, neal, linux-ext4, linux-fsdevel

On Mon, Nov 03, 2025 at 10:43:10AM -0800, Joanne Koong wrote:
> On Mon, Nov 3, 2025 at 10:30 AM Joanne Koong <joannelkoong@gmail.com> wrote:
> >
> > > diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> > > index a8068bee90af57..8c47d103c8ffa6 100644
> > > --- a/fs/fuse/fuse_i.h
> > > +++ b/fs/fuse/fuse_i.h
> > > @@ -140,6 +140,10 @@ struct fuse_inode {
> > >         /** Version of last attribute change */
> > >         u64 attr_version;
> > >
> > > +       /** statx file attributes */
> > > +       u64 statx_attributes;
> > > +       u64 statx_attributes_mask;
> > > +
> > >         union {
> > >                 /* read/write io cache (regular file only) */
> > >                 struct {
> > > @@ -1235,6 +1239,39 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
> > >                                    u64 attr_valid, u32 cache_mask,
> > >                                    u64 evict_ctr);
> > >
> > > +/*
> > > + * These statx attribute flags are set by the VFS so mask them out of replies
> > > + * from the fuse server for local filesystems.  Nonlocal filesystems are
> > > + * responsible for enforcing and advertising these flags themselves.
> > > + */
> > > +#define FUSE_STATX_LOCAL_VFS_ATTRIBUTES (STATX_ATTR_IMMUTABLE | \
> > > +                                        STATX_ATTR_APPEND)
> >
> > for STATX_ATTR_IMMUTABLE and STATX_ATTR_APPEND, I see in
> > generic_fill_statx_attr() that they get set if the inode has the
> > S_IMMUTABLE flag and the S_APPEND flag set, but I'm not seeing how
> > this is relevant to fuse. I'm not seeing anywhere in the vfs layer
> > that sets S_APPEND or STATX_ATTR_IMMUTABLE, I only see specific
> > filesystems setting them, which fuse doesn't do. Is there something
> > I'm missing?
> 
> Ok, I see. In patchset 6/8 patch 3/9 [1],
> FUSE_ATTR_SYNC/FUSE_ATTR_IMMUTABLE/FUSE_ATTR_APPEND flags get added
> which signify that S_SYNC/S_IMMUTABLE/S_APPEND should get set on the

<nod>  Originally I was going to hide /all/ of this behind the
per-fuse_inode iomap flag, but the Miklos and I started talking about
having a separate "behaves like local fs" flag for a few things so that
non-iomap fuseblk servers could take advantage of them too.  Right now
it's limited to these vfs inode flags and the posix acl transformation
functions since the assumption is that a regular fuse server either does
the transformations on its own or forwards the request to a remote node
which (presumably if it cares) does the transformation on its own.

> inode.  Hmm I'm confused why we would want to mask them out for local
> filesystems. If FUSE_ATTR_SYNC/FUSE_ATTR_IMMUTABLE/FUSE_ATTR_APPEND
> are getting passed in by the fuse server and getting enforced, why
> don't we want them to show up in stax?

We do, but the VFS sets those statx flags for us:
https://elixir.bootlin.com/linux/v6.17.7/source/fs/stat.c#L124

--D

> Thanks,
> Joanne
> 
> [1] https://lore.kernel.org/linux-fsdevel/176169811656.1426244.11474449087922753694.stgit@frogsfrogsfrogs/
> >
> > Thanks,
> > Joanne

^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
@ 2026-02-23 22:46 Darrick J. Wong
  2026-02-23 23:00 ` [PATCHSET v7 1/9] fuse: general bug fixes Darrick J. Wong
                   ` (23 more replies)
  0 siblings, 24 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 22:46 UTC (permalink / raw)
  To: linux-fsdevel, bpf, linux-ext4
  Cc: Miklos Szeredi, Bernd Schubert, Joanne Koong, Theodore Ts'o,
	Neal Gompa, Amir Goldstein, Christian Brauner, Jeff Layton, John,
	demiobenour

This is the seventh public draft of a prototype to connect the Linux
fuse driver to fs-iomap for regular file IO operations to and from files
whose contents persist to locally attached storage devices.  With this
release, I show that it's possible to build a fuse server for a real
filesystem (ext4) that runs entirely in userspace yet maintains most of
its performance.  Furthermore, I also show that the userspace program
runs with minimal privilege, which means that we no longer need to have
filesystem metadata parsing be a privileged (== risky) operation.

Why would you want to do that?  Most filesystem drivers are seriously
vulnerable to metadata parsing attacks, as syzbot has shown repeatedly
over almost a decade of its existence.  Faulty code can lead to total
kernel compromise, and I think there's a very strong incentive to move
all that parsing out to userspace where we can containerize the fuse
server process.

Demi Marie Obenour pointed out that libguestfs exists.  That project
creates a minimum rootfs, spins up a libvirt VM with a disk image
attached, and has a fuse server that can talk to the VM to provide file
access.  This provides the safety and isolation that I discussed above,
though the performance is not great, the memory and disk space
consumption are rather amazing (500MB and 350MB, respectively!), and
startup times are very slow.  This project avoids those overheads,
though I concede that libguestfs already exists and probably works in
more places than, say, lklfuse.

willy's folios conversion project (and to a certain degree RH's new
mount API) have also demonstrated that treewide changes to the core
mm/pagecache/fs code are very very difficult to pull off and take years
because you have to understand every filesystem's bespoke use of that
core code.  Eeeugh.

The fuse command plumbing is very simple -- the ->iomap_begin,
->iomap_end, and iomap ->ioend calls within iomap are turned into
upcalls to the fuse server via a trio of new fuse commands.  Pagecache
writeback is now a directio write.  The fuse server can upsert mappings
into the kernel for cached access (== zero upcalls for rereads and pure
overwrites!) and the iomap cache revalidation code works.

At this stage I still get about 95% of the kernel ext4 driver's
streaming directio performance on streaming IO, and 110% of its
streaming buffered IO performance.  Random buffered IO is about 85% as
fast as the kernel.  Random direct IO is about 80% as fast as the
kernel; see the cover letter for the fuse2fs iomap changes for more
details.  Unwritten extent conversions on random direct writes are
especially painful for fuse+iomap (~90% more overhead) due to upcall
overhead.  And that's with (now dynamic) debugging turned on!

These items have been addressed since the sixth RFC:

1. Setting current->flags didn't work for fuse servers running inside
   a systemd service, so that's now fixed.

2. Joanne and I worked together to build a prototype of allowing the
   fuse server to override the iomap ops via the BPF struct_ops device.
   This might take care of the interleaved mapping code in John Groves'
   famfs patchset.  This worked great back when my dev branch was
   based off of 6.19.

   Unfortunately it's broken in 7.0-rc1 because ... something changed
   in how BTF gets generated and now I get weird compiler warnings and
   the kernel build fails.  I don't currently know what in gcc 14.2 is
   allergic let alone how to fix this. :(

   The BPF parts of this submission are RFC because at this point I
   still have a lot of unresolved questions, such as:

   a> If you're building a file server for a distro package, there seems
      to be very little consistency as to where vmlinux.h might be
      found.

   b> Can we just compile the bpf at runtime?  That would introduce a
      lot of runtime dependencies (bpftool, clang, etc.) and precludes
      the possibility of vendor-signed bpf binaries.

   c> Are the memory protections implemented by the RFC series adequate
      to prevent data theft and/or kernel memory corruption?  struct ops
      seem to have a lot of capabilities.

   d> Does anyone else in filesystem-land think this is a good idea?

3. The mapping cache isn't invalidated at file close anymore.

4. Cleaned up the header files so that we're not just dumping tons of
   symbols in fuse_i.h.

5. Various review complaints from Chris Mason's AI reviewer.

There are some warts remaining:

a. I would like to continue the discussion about how the design review
   of this code should be structured, and how might I go about creating
   new userspace filesystem servers -- lightweight new ones based off
   the existing userspace tools?  Or by merging lklfuse?

b. ext4 doesn't support out of place writes so I don't know if that
   actually works correctly.

c. fuse2fs doesn't support the ext4 journal.  Urk.

d. There's a VERY large quantity of fuse2fs improvements that need to be
   applied before we get to the fuse-iomap parts.  I'm not sending these
   (or the fstests changes) to keep the size of the patchbomb at
   "unreasonably large". :P  As a result, the fstests and e2fsprogs
   postings are very targeted.

e. I've dropped the fstests part of the patchbomb because v6 was just
   way too long.

I would like to get the main parts of this submission reviewed for 7.1
now that this has been collecting comments and tweaks in non-rfc status
for 3.5 months.

Kernel:
https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf

libfuse:
https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git/log/?h=fuse-iomap-bpf

e2fsprogs:
https://git.kernel.org/pub/scm/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse-iomap-bpf

fstests:
https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfstests-dev.git/log/?h=fuse2fs

--Darrick

^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 1/9] fuse: general bug fixes
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
@ 2026-02-23 23:00 ` Darrick J. Wong
  2026-02-23 23:06   ` [PATCH 1/5] fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY Darrick J. Wong
                     ` (4 more replies)
  2026-02-23 23:00 ` [PATCHSET v7 2/9] iomap: cleanups ahead of adding fuse support Darrick J. Wong
                   ` (22 subsequent siblings)
  23 siblings, 5 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:00 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, stable, joannelkoong, bpf, bernd, neal,
	linux-fsdevel, linux-ext4

Hi all,

Here's a collection of fixes that I *think* are bugs in fuse, along with
some scattered improvements.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-fixes
---
Commits in this patchset:
 * fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY
 * fuse: quiet down complaints in fuse_conn_limit_write
 * fuse: implement file attributes mask for statx
 * fuse: update file mode when updating acls
 * fuse: propagate default and file acls on creation
---
 fs/fuse/fuse_i.h  |   48 ++++++++++++++++++++++++
 fs/fuse/acl.c     |  105 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 fs/fuse/control.c |    4 +-
 fs/fuse/dev.c     |   19 ++++++++++
 fs/fuse/dir.c     |  105 ++++++++++++++++++++++++++++++++++++++++-------------
 fs/fuse/inode.c   |   16 ++++++++
 6 files changed, 267 insertions(+), 30 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 2/9] iomap: cleanups ahead of adding fuse support
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
  2026-02-23 23:00 ` [PATCHSET v7 1/9] fuse: general bug fixes Darrick J. Wong
@ 2026-02-23 23:00 ` Darrick J. Wong
  2026-02-23 23:07   ` [PATCH 1/2] iomap: allow directio callers to supply _COMP_WORK Darrick J. Wong
  2026-02-23 23:08   ` [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile Darrick J. Wong
  2026-02-23 23:01 ` [PATCHSET v7 3/9] fuse: cleanups ahead of adding fuse support Darrick J. Wong
                   ` (21 subsequent siblings)
  23 siblings, 2 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:00 UTC (permalink / raw)
  To: brauner, miklos, djwong; +Cc: bpf, hch, linux-fsdevel, linux-ext4

Hi all,

In preparation for making fuse use the fs/iomap code for regular file
data IO, fix a few bugs in fuse and apply a couple of tweaks to iomap.
These patches can go in immediately.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=iomap-fuse-prep
---
Commits in this patchset:
 * iomap: allow directio callers to supply _COMP_WORK
 * iomap: allow NULL swap info bdev when activating swapfile
---
 include/linux/iomap.h |    3 +++
 fs/iomap/direct-io.c  |    5 +++--
 fs/iomap/swapfile.c   |   17 +++++++++++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 3/9] fuse: cleanups ahead of adding fuse support
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
  2026-02-23 23:00 ` [PATCHSET v7 1/9] fuse: general bug fixes Darrick J. Wong
  2026-02-23 23:00 ` [PATCHSET v7 2/9] iomap: cleanups ahead of adding fuse support Darrick J. Wong
@ 2026-02-23 23:01 ` Darrick J. Wong
  2026-02-23 23:08   ` [PATCH 1/2] fuse: move the passthrough-specific code back to passthrough.c Darrick J. Wong
  2026-02-23 23:08   ` [PATCH 2/2] fuse_trace: " Darrick J. Wong
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                   ` (20 subsequent siblings)
  23 siblings, 2 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:01 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, joannelkoong, bpf, bernd, neal, linux-fsdevel,
	linux-ext4

Hi all,

In preparation for making fuse use the fs/iomap code for regular file
data IO, fix a few bugs in fuse and apply a couple of tweaks to iomap.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-prep
---
Commits in this patchset:
 * fuse: move the passthrough-specific code back to passthrough.c
 * fuse_trace: move the passthrough-specific code back to passthrough.c
---
 fs/fuse/fuse_i.h          |   25 ++++++++++-
 fs/fuse/fuse_trace.h      |   35 ++++++++++++++++
 include/uapi/linux/fuse.h |    8 +++-
 fs/fuse/Kconfig           |    4 ++
 fs/fuse/Makefile          |    3 +
 fs/fuse/backing.c         |  101 ++++++++++++++++++++++++++++++++++-----------
 fs/fuse/dev.c             |    4 +-
 fs/fuse/inode.c           |    4 +-
 fs/fuse/passthrough.c     |   38 ++++++++++++++++-
 9 files changed, 188 insertions(+), 34 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (2 preceding siblings ...)
  2026-02-23 23:01 ` [PATCHSET v7 3/9] fuse: cleanups ahead of adding fuse support Darrick J. Wong
@ 2026-02-23 23:01 ` Darrick J. Wong
  2026-02-23 23:08   ` [PATCH 01/33] fuse: implement the basic iomap mechanisms Darrick J. Wong
                     ` (32 more replies)
  2026-02-23 23:01 ` [PATCHSET v7 5/9] fuse: allow servers to specify root node id Darrick J. Wong
                   ` (19 subsequent siblings)
  23 siblings, 33 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:01 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, joannelkoong, bpf, bernd, neal, linux-fsdevel,
	linux-ext4

Hi all,

This series connects fuse (the userspace filesystem layer) to fs-iomap
to get fuse servers out of the business of handling file I/O themselves.
By keeping the IO path mostly within the kernel, we can dramatically
improve the speed of disk-based filesystems.  This enables us to move
all the filesystem metadata parsing code out of the kernel and into
userspace, which means that we can containerize them for security
without losing a lot of performance.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-fileio
---
Commits in this patchset:
 * fuse: implement the basic iomap mechanisms
 * fuse_trace: implement the basic iomap mechanisms
 * fuse: make debugging configurable at runtime
 * fuse: adapt FUSE_DEV_IOC_BACKING_{OPEN,CLOSE} to add new iomap devices
 * fuse_trace: adapt FUSE_DEV_IOC_BACKING_{OPEN,CLOSE} to add new iomap devices
 * fuse: enable SYNCFS and ensure we flush everything before sending DESTROY
 * fuse: clean up per-file type inode initialization
 * fuse: create a per-inode flag for setting exclusive mode.
 * fuse: create a per-inode flag for toggling iomap
 * fuse_trace: create a per-inode flag for toggling iomap
 * fuse: isolate the other regular file IO paths from iomap
 * fuse: implement basic iomap reporting such as FIEMAP and SEEK_{DATA,HOLE}
 * fuse_trace: implement basic iomap reporting such as FIEMAP and SEEK_{DATA,HOLE}
 * fuse: implement direct IO with iomap
 * fuse_trace: implement direct IO with iomap
 * fuse: implement buffered IO with iomap
 * fuse_trace: implement buffered IO with iomap
 * fuse: use an unrestricted backing device with iomap pagecache io
 * fuse: implement large folios for iomap pagecache files
 * fuse: advertise support for iomap
 * fuse: query filesystem geometry when using iomap
 * fuse_trace: query filesystem geometry when using iomap
 * fuse: implement fadvise for iomap files
 * fuse: invalidate ranges of block devices being used for iomap
 * fuse_trace: invalidate ranges of block devices being used for iomap
 * fuse: implement inline data file IO via iomap
 * fuse_trace: implement inline data file IO via iomap
 * fuse: allow more statx fields
 * fuse: support atomic writes with iomap
 * fuse_trace: support atomic writes with iomap
 * fuse: disable direct fs reclaim for any fuse server that uses iomap
 * fuse: enable swapfile activation on iomap
 * fuse: implement freeze and shutdowns for iomap filesystems
---
 fs/fuse/fuse_i.h          |   73 +
 fs/fuse/fuse_iomap.h      |  109 ++
 fs/fuse/fuse_iomap_i.h    |   45 +
 fs/fuse/fuse_trace.h      |  974 ++++++++++++++++++
 include/uapi/linux/fuse.h |  235 ++++
 fs/fuse/Kconfig           |   48 +
 fs/fuse/Makefile          |    1 
 fs/fuse/backing.c         |   47 +
 fs/fuse/dev.c             |   42 +
 fs/fuse/dir.c             |  141 ++-
 fs/fuse/file.c            |  122 ++
 fs/fuse/fuse_iomap.c      | 2371 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |  180 +++
 fs/fuse/iomode.c          |    1 
 fs/fuse/trace.c           |    3 
 15 files changed, 4321 insertions(+), 71 deletions(-)
 create mode 100644 fs/fuse/fuse_iomap.h
 create mode 100644 fs/fuse/fuse_iomap_i.h
 create mode 100644 fs/fuse/fuse_iomap.c


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 5/9] fuse: allow servers to specify root node id
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (3 preceding siblings ...)
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
@ 2026-02-23 23:01 ` Darrick J. Wong
  2026-02-23 23:17   ` [PATCH 1/3] fuse: make the root nodeid dynamic Darrick J. Wong
                     ` (2 more replies)
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                   ` (18 subsequent siblings)
  23 siblings, 3 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:01 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

Hi all,

This series grants fuse servers full control over the entire node id
address space by allowing them to specify the nodeid of the root
directory.  With this new feature, fuse4fs will not have to translate
node ids.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-root-nodeid
---
Commits in this patchset:
 * fuse: make the root nodeid dynamic
 * fuse_trace: make the root nodeid dynamic
 * fuse: allow setting of root nodeid
---
 fs/fuse/fuse_i.h     |    9 +++++++--
 fs/fuse/fuse_trace.h |    6 ++++--
 fs/fuse/dir.c        |   10 ++++++----
 fs/fuse/inode.c      |   22 ++++++++++++++++++----
 fs/fuse/readdir.c    |   10 +++++-----
 5 files changed, 40 insertions(+), 17 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (4 preceding siblings ...)
  2026-02-23 23:01 ` [PATCHSET v7 5/9] fuse: allow servers to specify root node id Darrick J. Wong
@ 2026-02-23 23:01 ` Darrick J. Wong
  2026-02-23 23:18   ` [PATCH 1/9] fuse: enable caching of timestamps Darrick J. Wong
                     ` (8 more replies)
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                   ` (17 subsequent siblings)
  23 siblings, 9 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:01 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

Hi all,

When iomap is enabled for a fuse file, we try to keep as much of the
file IO path in the kernel as we possibly can.  That means no calling
out to the fuse server in the IO path when we can avoid it.  However,
the existing FUSE architecture defers all file attributes to the fuse
server -- [cm]time updates, ACL metadata management, set[ug]id removal,
and permissions checking thereof, etc.

We'd really rather do all these attribute updates in the kernel, and
only push them to the fuse server when it's actually necessary (e.g.
fsync).  Furthermore, the POSIX ACL code has the weird behavior that if
the access ACL can be represented entirely by i_mode bits, it will
change the mode and delete the ACL, which fuse servers generally don't
seem to implement.

IOWs, we want consistent and correct (as defined by fstests) behavior
of file attributes in iomap mode.  Let's make the kernel manage all that
and push the results to userspace as needed.  This improves performance
even further, since it's sort of like writeback_cache mode but more
aggressive.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-attrs
---
Commits in this patchset:
 * fuse: enable caching of timestamps
 * fuse: force a ctime update after a fileattr_set call when in iomap mode
 * fuse: allow local filesystems to set some VFS iflags
 * fuse_trace: allow local filesystems to set some VFS iflags
 * fuse: cache atime when in iomap mode
 * fuse: let the kernel handle KILL_SUID/KILL_SGID for iomap filesystems
 * fuse_trace: let the kernel handle KILL_SUID/KILL_SGID for iomap filesystems
 * fuse: update ctime when updating acls on an iomap inode
 * fuse: always cache ACLs when using iomap
---
 fs/fuse/fuse_i.h          |    1 +
 fs/fuse/fuse_trace.h      |   87 +++++++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/fuse.h |    8 ++++
 fs/fuse/acl.c             |   30 +++++++++++++---
 fs/fuse/dir.c             |   38 ++++++++++++++++----
 fs/fuse/file.c            |   18 ++++++---
 fs/fuse/fuse_iomap.c      |   12 ++++++
 fs/fuse/inode.c           |   19 +++++++---
 fs/fuse/ioctl.c           |   68 +++++++++++++++++++++++++++++++++++
 fs/fuse/readdir.c         |    5 ++-
 10 files changed, 262 insertions(+), 24 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (5 preceding siblings ...)
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
@ 2026-02-23 23:02 ` Darrick J. Wong
  2026-02-23 23:20   ` [PATCH 01/12] fuse: cache iomaps Darrick J. Wong
                     ` (11 more replies)
  2026-02-23 23:02 ` [PATCHSET v7 8/9] fuse: run fuse servers as a contained service Darrick J. Wong
                   ` (16 subsequent siblings)
  23 siblings, 12 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:02 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

Hi all,

This series improves the performance (and correctness for some
filesystems) by adding the ability to cache iomap mappings in the
kernel.  For filesystems that can change mapping states during pagecache
writeback (e.g. unwritten extent conversion) this is absolutely
necessary to deal with races with writes to the pagecache because
writeback does not take i_rwsem.  For everyone else, it simply
eliminates roundtrips to userspace.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-cache
---
Commits in this patchset:
 * fuse: cache iomaps
 * fuse_trace: cache iomaps
 * fuse: use the iomap cache for iomap_begin
 * fuse_trace: use the iomap cache for iomap_begin
 * fuse: invalidate iomap cache after file updates
 * fuse_trace: invalidate iomap cache after file updates
 * fuse: enable iomap cache management
 * fuse_trace: enable iomap cache management
 * fuse: overlay iomap inode info in struct fuse_inode
 * fuse: constrain iomap mapping cache size
 * fuse_trace: constrain iomap mapping cache size
 * fuse: enable iomap
---
 fs/fuse/fuse_i.h           |   11 
 fs/fuse/fuse_iomap.h       |   10 
 fs/fuse/fuse_iomap_cache.h |  121 +++
 fs/fuse/fuse_trace.h       |  445 +++++++++++
 include/uapi/linux/fuse.h  |   41 +
 fs/fuse/Makefile           |    2 
 fs/fuse/dev.c              |   46 +
 fs/fuse/file.c             |   18 
 fs/fuse/fuse_iomap.c       |  533 +++++++++++++
 fs/fuse/fuse_iomap_cache.c | 1797 ++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/trace.c            |    1 
 11 files changed, 3002 insertions(+), 23 deletions(-)
 create mode 100644 fs/fuse/fuse_iomap_cache.h
 create mode 100644 fs/fuse/fuse_iomap_cache.c


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 8/9] fuse: run fuse servers as a contained service
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (6 preceding siblings ...)
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
@ 2026-02-23 23:02 ` Darrick J. Wong
  2026-02-23 23:23   ` [PATCH 1/2] fuse: allow privileged mount helpers to pre-approve iomap usage Darrick J. Wong
  2026-02-23 23:24   ` [PATCH 2/2] fuse: set iomap backing device block size Darrick J. Wong
  2026-02-23 23:02 ` [PATCHSET RFC 9/9] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
                   ` (15 subsequent siblings)
  23 siblings, 2 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:02 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

Hi all,

This patchset defines the necessary communication protocols and library
code so that users can mount fuse servers that run in unprivileged
systemd service containers.  That in turn allows unprivileged untrusted
mounts, because the worst that can happen is that a malicious image
crashes the fuse server and the mount dies, instead of corrupting the
kernel.  As part of the delegation, add a new ioctl allowing any process
with an open fusedev fd to ask for permission for anyone with that
fusedev fd to use iomap.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-service-container
---
Commits in this patchset:
 * fuse: allow privileged mount helpers to pre-approve iomap usage
 * fuse: set iomap backing device block size
---
 fs/fuse/fuse_dev_i.h      |   32 ++++++++++++++++++--
 fs/fuse/fuse_i.h          |    7 ++++
 fs/fuse/fuse_iomap.h      |    5 +++
 include/uapi/linux/fuse.h |    8 +++++
 fs/fuse/dev.c             |   13 ++++----
 fs/fuse/fuse_iomap.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++-
 fs/fuse/inode.c           |   18 ++++++++---
 7 files changed, 138 insertions(+), 17 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET RFC 9/9] fuse: allow fuse servers to upload iomap BPF programs
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (7 preceding siblings ...)
  2026-02-23 23:02 ` [PATCHSET v7 8/9] fuse: run fuse servers as a contained service Darrick J. Wong
@ 2026-02-23 23:02 ` Darrick J. Wong
  2026-02-23 23:24   ` [PATCH 1/5] fuse: enable fuse servers to upload BPF programs to handle iomap requests Darrick J. Wong
                     ` (4 more replies)
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                   ` (14 subsequent siblings)
  23 siblings, 5 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:02 UTC (permalink / raw)
  To: miklos, djwong
  Cc: bpf, joannelkoong, bpf, john, bernd, neal, linux-fsdevel,
	linux-ext4

Hi all,

There are certain fuse servers that might benefit from the ability to
upload a BPF program into the kernel to respond to ->iomap_begin
requests instead of upcalling the fuse server itself.

For example, consider a fuse server that abstracts a large amount of
storage for use as intermediate storage by programs.  If the storage is
striped across hardware devices (e.g. RAID0 or interleaved memory
controllers) then the iomapping pattern will be completely regular but
the mappings themselves might be very small.

Performance for large IOs will suck if it is necessary to upcall the
fuse server every time we cross a mapping boundary.  The fuse server can
try to mitigate that hit by upserting mappings ahead of time, but
there's a better solution for this usecase: BPF programs.

In this case, the fuse server can compile a BPF program that will
compute the mapping data for a given request and upload the program.
This avoids the overhead of cache lookups and server upcalls.  Note that
the BPF verifier still imposes instruction count and complexity limits
on the uploaded programs.

Note that I embraced and extended some code from Joanne, but at this
point I've modified it so heavily that it's not really the original
anymore.  But she still gets credit for coming up with the idea and
engaging me in flinging prototypes around.

Now with kfuncs to manage the cache, and some ability to restrict
memory access from within the BPF program.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf
---
Commits in this patchset:
 * fuse: enable fuse servers to upload BPF programs to handle iomap requests
 * fuse_trace: enable fuse servers to upload BPF programs to handle iomap requests
 * fuse: prevent iomap bpf programs from writing to most of the system
 * fuse: add kfuncs for iomap bpf programs to manage the cache
 * fuse: make fuse_inode opaque to iomap bpf programs
---
 fs/fuse/fuse_i.h         |    5 
 fs/fuse/fuse_iomap_bpf.h |  123 ++++++++++++
 fs/fuse/fuse_iomap_i.h   |    6 +
 fs/fuse/fuse_trace.h     |   53 +++++
 fs/fuse/Makefile         |    4 
 fs/fuse/fuse_iomap.c     |   17 +-
 fs/fuse/fuse_iomap_bpf.c |  464 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c          |    7 +
 fs/fuse/trace.c          |    1 
 kernel/bpf/btf.c         |    1 
 10 files changed, 676 insertions(+), 5 deletions(-)
 create mode 100644 fs/fuse/fuse_iomap_bpf.h
 create mode 100644 fs/fuse/fuse_iomap_bpf.c


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (8 preceding siblings ...)
  2026-02-23 23:02 ` [PATCHSET RFC 9/9] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
@ 2026-02-23 23:02 ` Darrick J. Wong
  2026-02-23 23:25   ` [PATCH 01/25] libfuse: bump kernel and library ABI versions Darrick J. Wong
                     ` (24 more replies)
  2026-02-23 23:03 ` [PATCHSET v7 2/6] libfuse: allow servers to specify root node id Darrick J. Wong
                   ` (13 subsequent siblings)
  23 siblings, 25 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:02 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

Hi all,

This series connects libfuse to the iomap-enabled fuse driver in Linux to get
fuse servers out of the business of handling file I/O themselves.  By keeping
the IO path mostly within the kernel, we can dramatically improve the speed of
disk-based filesystems.  This enables us to move all the filesystem metadata
parsing code out of the kernel and into userspace, which means that we can
containerize them for security without losing a lot of performance.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-fileio
---
Commits in this patchset:
 * libfuse: bump kernel and library ABI versions
 * libfuse: wait in do_destroy until all open files are closed
 * libfuse: add kernel gates for FUSE_IOMAP
 * libfuse: add fuse commands for iomap_begin and end
 * libfuse: add upper level iomap commands
 * libfuse: add a lowlevel notification to add a new device to iomap
 * libfuse: add upper-level iomap add device function
 * libfuse: add iomap ioend low level handler
 * libfuse: add upper level iomap ioend commands
 * libfuse: add a reply function to send FUSE_ATTR_* to the kernel
 * libfuse: connect high level fuse library to fuse_reply_attr_iflags
 * libfuse: support enabling exclusive mode for files
 * libfuse: support direct I/O through iomap
 * libfuse: don't allow hardlinking of iomap files in the upper level fuse library
 * libfuse: allow discovery of the kernel's iomap capabilities
 * libfuse: add lower level iomap_config implementation
 * libfuse: add upper level iomap_config implementation
 * libfuse: add low level code to invalidate iomap block device ranges
 * libfuse: add upper-level API to invalidate parts of an iomap block device
 * libfuse: add atomic write support
 * libfuse: allow disabling of fs memory reclaim and write throttling
 * libfuse: create a helper to transform an open regular file into an open loopdev
 * libfuse: add swapfile support for iomap files
 * libfuse: add lower-level filesystem freeze, thaw, and shutdown requests
 * libfuse: add upper-level filesystem freeze, thaw, and shutdown events
---
 include/fuse.h          |  102 ++++++++
 include/fuse_common.h   |  143 +++++++++++
 include/fuse_kernel.h   |  147 ++++++++++++
 include/fuse_loopdev.h  |   27 ++
 include/fuse_lowlevel.h |  305 ++++++++++++++++++++++++
 lib/fuse_i.h            |    4 
 ChangeLog.rst           |    5 
 include/meson.build     |    4 
 lib/fuse.c              |  591 +++++++++++++++++++++++++++++++++++++++++++----
 lib/fuse_loopdev.c      |  403 ++++++++++++++++++++++++++++++++
 lib/fuse_lowlevel.c     |  560 +++++++++++++++++++++++++++++++++++++++++++--
 lib/fuse_versionscript  |   23 ++
 lib/meson.build         |    7 -
 meson.build             |   13 +
 14 files changed, 2251 insertions(+), 83 deletions(-)
 create mode 100644 include/fuse_loopdev.h
 create mode 100644 lib/fuse_loopdev.c


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 2/6] libfuse: allow servers to specify root node id
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (9 preceding siblings ...)
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
@ 2026-02-23 23:03 ` Darrick J. Wong
  2026-02-23 23:32   ` [PATCH 1/1] libfuse: allow root_nodeid mount option Darrick J. Wong
  2026-02-23 23:03 ` [PATCHSET v7 3/6] libfuse: implement syncfs Darrick J. Wong
                   ` (12 subsequent siblings)
  23 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:03 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

Hi all,

This series grants fuse servers full control over the entire node id
address space by allowing them to specify the nodeid of the root
directory.  With this new feature, fuse4fs will not have to translate
node ids.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-root-nodeid
---
Commits in this patchset:
 * libfuse: allow root_nodeid mount option
---
 lib/mount.c |    1 +
 1 file changed, 1 insertion(+)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 3/6] libfuse: implement syncfs
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (10 preceding siblings ...)
  2026-02-23 23:03 ` [PATCHSET v7 2/6] libfuse: allow servers to specify root node id Darrick J. Wong
@ 2026-02-23 23:03 ` Darrick J. Wong
  2026-02-23 23:32   ` [PATCH 1/2] libfuse: add strictatime/lazytime mount options Darrick J. Wong
  2026-02-23 23:32   ` [PATCH 2/2] libfuse: set sync, immutable, and append when loading files Darrick J. Wong
  2026-02-23 23:03 ` [PATCHSET v7 4/6] libfuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                   ` (11 subsequent siblings)
  23 siblings, 2 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:03 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

Hi all,

Implement syncfs in libfuse so that iomap-compatible fuse servers can
receive syncfs commands, and enable fuse servers to transmit inode
flags to the kernel so that it can enforce sync, immutable, and append.
Also enable some of the timestamp update mount options.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-attrs
---
Commits in this patchset:
 * libfuse: add strictatime/lazytime mount options
 * libfuse: set sync, immutable, and append when loading files
---
 include/fuse_common.h |    6 ++++++
 include/fuse_kernel.h |    8 ++++++++
 lib/fuse_lowlevel.c   |    6 ++++++
 lib/mount.c           |   18 ++++++++++++++++--
 4 files changed, 36 insertions(+), 2 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 4/6] libfuse: cache iomap mappings for even better file IO performance
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (11 preceding siblings ...)
  2026-02-23 23:03 ` [PATCHSET v7 3/6] libfuse: implement syncfs Darrick J. Wong
@ 2026-02-23 23:03 ` Darrick J. Wong
  2026-02-23 23:32   ` [PATCH 1/5] libfuse: enable iomap cache management for lowlevel fuse Darrick J. Wong
                     ` (4 more replies)
  2026-02-23 23:03 ` [PATCHSET v7 5/6] libfuse: run fuse servers as a contained service Darrick J. Wong
                   ` (10 subsequent siblings)
  23 siblings, 5 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:03 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

Hi all,

This series improves the performance (and correctness for some
filesystems) by adding the ability to cache iomap mappings in the
kernel.  For filesystems that can change mapping states during pagecache
writeback (e.g. unwritten extent conversion) this is absolutely
necessary to deal with races with writes to the pagecache because
writeback does not take i_rwsem.  For everyone else, it simply
eliminates roundtrips to userspace.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-cache
---
Commits in this patchset:
 * libfuse: enable iomap cache management for lowlevel fuse
 * libfuse: add upper-level iomap cache management
 * libfuse: allow constraining of iomap mapping cache size
 * libfuse: add upper-level iomap mapping cache constraint code
 * libfuse: enable iomap
---
 include/fuse.h          |   32 +++++++++++++++++
 include/fuse_common.h   |   15 ++++++++
 include/fuse_kernel.h   |   33 +++++++++++++++++
 include/fuse_lowlevel.h |   44 ++++++++++++++++++++++-
 lib/fuse.c              |   44 ++++++++++++++++++++---
 lib/fuse_lowlevel.c     |   90 ++++++++++++++++++++++++++++++++++++++++++++---
 lib/fuse_versionscript  |    4 ++
 7 files changed, 249 insertions(+), 13 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 5/6] libfuse: run fuse servers as a contained service
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (12 preceding siblings ...)
  2026-02-23 23:03 ` [PATCHSET v7 4/6] libfuse: cache iomap mappings for even better file IO performance Darrick J. Wong
@ 2026-02-23 23:03 ` Darrick J. Wong
  2026-02-23 23:34   ` [PATCH 1/5] libfuse: add systemd/inetd socket service mounting helper Darrick J. Wong
                     ` (4 more replies)
  2026-02-23 23:04 ` [PATCHSET RFC 6/6] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
                   ` (9 subsequent siblings)
  23 siblings, 5 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:03 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

Hi all,

This patchset defines the necessary communication protocols and library
code so that users can mount fuse servers that run in unprivileged
systemd service containers.  That in turn allows unprivileged untrusted
mounts, because the worst that can happen is that a malicious image
crashes the fuse server and the mount dies, instead of corrupting the
kernel.  As part of the delegation, add a new ioctl allowing any process
with an open fusedev fd to ask for permission for anyone with that
fusedev fd to use iomap.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-service-container
---
Commits in this patchset:
 * libfuse: add systemd/inetd socket service mounting helper
 * libfuse: integrate fuse services into mount.fuse3
 * libfuse: delegate iomap privilege from mount.service to fuse services
 * libfuse: enable setting iomap block device block size
 * fuservicemount: create loop devices for regular files
---
 include/fuse_kernel.h       |    8 
 include/fuse_lowlevel.h     |   22 +
 include/fuse_service.h      |  170 +++++++
 include/fuse_service_priv.h |  127 +++++
 lib/fuse_i.h                |    5 
 util/mount_service.h        |   41 ++
 doc/fuservicemount3.8       |   32 +
 doc/meson.build             |    3 
 include/meson.build         |    4 
 lib/fuse_lowlevel.c         |   16 +
 lib/fuse_service.c          |  848 +++++++++++++++++++++++++++++++++
 lib/fuse_service_stub.c     |   91 ++++
 lib/fuse_versionscript      |   15 +
 lib/helper.c                |   53 ++
 lib/meson.build             |   14 +
 lib/mount.c                 |   57 ++
 meson.build                 |   36 +
 meson_options.txt           |    6 
 util/fuservicemount.c       |   66 +++
 util/meson.build            |   13 -
 util/mount.fuse.c           |   58 +-
 util/mount_service.c        | 1100 +++++++++++++++++++++++++++++++++++++++++++
 22 files changed, 2749 insertions(+), 36 deletions(-)
 create mode 100644 include/fuse_service.h
 create mode 100644 include/fuse_service_priv.h
 create mode 100644 util/mount_service.h
 create mode 100644 doc/fuservicemount3.8
 create mode 100644 lib/fuse_service.c
 create mode 100644 lib/fuse_service_stub.c
 create mode 100644 util/fuservicemount.c
 create mode 100644 util/mount_service.c


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET RFC 6/6] fuse: allow fuse servers to upload iomap BPF programs
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (13 preceding siblings ...)
  2026-02-23 23:03 ` [PATCHSET v7 5/6] libfuse: run fuse servers as a contained service Darrick J. Wong
@ 2026-02-23 23:04 ` Darrick J. Wong
  2026-02-23 23:35   ` [PATCH 1/3] libfuse: allow fuse servers to upload bpf code for iomap functions Darrick J. Wong
                     ` (2 more replies)
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                   ` (8 subsequent siblings)
  23 siblings, 3 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:04 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, john, linux-fsdevel, bpf,
	joannelkoong

Hi all,

There are certain fuse servers that might benefit from the ability to
upload a BPF program into the kernel to respond to ->iomap_begin
requests instead of upcalling the fuse server itself.

For example, consider a fuse server that abstracts a large amount of
storage for use as intermediate storage by programs.  If the storage is
striped across hardware devices (e.g. RAID0 or interleaved memory
controllers) then the iomapping pattern will be completely regular but
the mappings themselves might be very small.

Performance for large IOs will suck if it is necessary to upcall the
fuse server every time we cross a mapping boundary.  The fuse server can
try to mitigate that hit by upserting mappings ahead of time, but
there's a better solution for this usecase: BPF programs.

In this case, the fuse server can compile a BPF program that will
compute the mapping data for a given request and upload the program.
This avoids the overhead of cache lookups and server upcalls.  Note that
the BPF verifier still imposes instruction count and complexity limits
on the uploaded programs.

Note that I embraced and extended some code from Joanne, but at this
point I've modified it so heavily that it's not really the original
anymore.  But she still gets credit for coming up with the idea and
engaging me in flinging prototypes around.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf
---
Commits in this patchset:
 * libfuse: allow fuse servers to upload bpf code for iomap functions
 * libfuse: add kfuncs for iomap bpf programs to manage the cache
 * libfuse: make fuse_inode opaque to iomap bpf programs
---
 include/fuse_iomap_bpf.h |  263 ++++++++++++++++++++++++++++++++++++++++++++++
 include/meson.build      |    3 -
 2 files changed, 265 insertions(+), 1 deletion(-)
 create mode 100644 include/fuse_iomap_bpf.h


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (14 preceding siblings ...)
  2026-02-23 23:04 ` [PATCHSET RFC 6/6] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
@ 2026-02-23 23:04 ` Darrick J. Wong
  2026-02-23 23:36   ` [PATCH 01/19] fuse2fs: implement bare minimum iomap for file mapping reporting Darrick J. Wong
                     ` (18 more replies)
  2026-02-23 23:04 ` [PATCHSET v7 2/8] fuse4fs: specify the root node id Darrick J. Wong
                   ` (7 subsequent siblings)
  23 siblings, 19 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:04 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

Hi all,

Switch fuse2fs to use the new iomap file data IO paths instead of
pushing it very slowly through the /dev/fuse connection.  For local
filesystems, all we have to do is respond to requests for file to device
mappings; the rest of the IO hot path stays within the kernel.  This
means that we can get rid of all file data block processing within
fuse2fs.

Because we're not pinning dirty pages through a potentially slow network
connection, we don't need the heavy BDI throttling for which most fuse
servers have become infamous.  Yes, mapping lookups for writeback can
stall, but mappings are small as compared to data and this situation
exists for all kernel filesystems as well.

The performance of this new data path is quite stunning: on a warm
system, streaming reads and writes through the pagecache go from
60-90MB/s to 2-2.5GB/s.  Direct IO reads and writes improve from the
same baseline to 2.5-8GB/s.  FIEMAP and SEEK_DATA/SEEK_HOLE now work
too.  The kernel ext4 driver can manage about 1.6GB/s for pagecache IO
and about 2.6-8.5GB/s, which means that fuse2fs is about as fast as the
kernel for streaming file IO.

Random 4k buffered IO is not so good: plain fuse2fs pokes along at
25-50MB/s, whereas fuse2fs with iomap manages 90-1300MB/s.  The kernel
can do 900-1300MB/s.  Random directio is worse: plain fuse2fs does
20-30MB/s, fuse-iomap does about 30-35MB/s, and the kernel does
40-55MB/s.  I suspect that metadata heavy workloads do not perform well
on fuse2fs because libext2fs wasn't designed for that and it doesn't
even have a journal to absorb all the fsync writes.  We also probably
need iomap caching really badly.

These performance numbers are slanted: my machine is 12 years old, and
fuse2fs is VERY poorly optimized for performance.  It contains a single
Big Filesystem Lock which nukes multi-threaded scalability.  There's no
inode cache nor is there a proper buffer cache, which means that fuse2fs
reads metadata in from disk and checksums it on EVERY ACCESS.  Sad!

Despite these gaps, this RFC demonstrates that it's feasible to run the
metadata parsing parts of a filesystem in userspace while not
sacrificing much performance.  We now have a vehicle to move the
filesystems out of the kernel, where they can be containerized so that
malicious filesystems can be contained, somewhat.

iomap mode also calls FUSE_DESTROY before unmounting the filesystem, so
for capable systems, fuse2fs doesn't need to run in fuseblk mode
anymore.

However, there are some major warts remaining:

1. The iomap cookie validation is not present, which can lead to subtle
races between pagecache zeroing and writeback on filesystems that
support unwritten and delalloc mappings.

2. Mappings ought to be cached in the kernel for more speed.

3. iomap doesn't support things like fscrypt or fsverity, and I haven't
yet figured out how inline data is supposed to work.

4. I would like to be able to turn on fuse+iomap on a per-inode basis,
which currently isn't possible because the kernel fuse driver will iget
inodes prior to calling FUSE_GETATTR to discover the properties of the
inode it just read.

5. ext4 doesn't support out of place writes so I don't know if that
actually works correctly.

6. iomap is an inode-based service, not a file-based service.  This
means that we /must/ push ext2's inode numbers into the kernel via
FUSE_GETATTR so that it can report those same numbers back out through
the FUSE_IOMAP_* calls.  However, the fuse kernel uses a separate nodeid
to index its incore inode, so we have to pass those too so that
notifications work properly.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

Comments and questions are, as always, welcome.

e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-iomap-fileio
---
Commits in this patchset:
 * fuse2fs: implement bare minimum iomap for file mapping reporting
 * fuse2fs: add iomap= mount option
 * fuse2fs: implement iomap configuration
 * fuse2fs: register block devices for use with iomap
 * fuse2fs: implement directio file reads
 * fuse2fs: add extent dump function for debugging
 * fuse2fs: implement direct write support
 * fuse2fs: turn on iomap for pagecache IO
 * fuse2fs: don't zero bytes in punch hole
 * fuse2fs: don't do file data block IO when iomap is enabled
 * fuse2fs: try to create loop device when ext4 device is a regular file
 * fuse2fs: enable file IO to inline data files
 * fuse2fs: set iomap-related inode flags
 * fuse2fs: configure block device block size
 * fuse4fs: separate invalidation
 * fuse2fs: implement statx
 * fuse2fs: enable atomic writes
 * fuse4fs: disable fs reclaim and write throttling
 * fuse2fs: implement freeze and shutdown requests
---
 configure            |   90 ++
 configure.ac         |   54 +
 fuse4fs/fuse4fs.1.in |    6 
 fuse4fs/fuse4fs.c    | 1917 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/config.h.in      |    6 
 misc/fuse2fs.1.in    |    6 
 misc/fuse2fs.c       | 1939 ++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 3991 insertions(+), 27 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 2/8] fuse4fs: specify the root node id
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (15 preceding siblings ...)
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
@ 2026-02-23 23:04 ` Darrick J. Wong
  2026-02-23 23:41   ` [PATCH 1/1] fuse4fs: don't use inode number translation when possible Darrick J. Wong
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                   ` (6 subsequent siblings)
  23 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:04 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

Hi all,


If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

Comments and questions are, as always, welcome.

e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-root-nodeid
---
Commits in this patchset:
 * fuse4fs: don't use inode number translation when possible
---
 fuse4fs/fuse4fs.c |   30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (16 preceding siblings ...)
  2026-02-23 23:04 ` [PATCHSET v7 2/8] fuse4fs: specify the root node id Darrick J. Wong
@ 2026-02-23 23:05 ` Darrick J. Wong
  2026-02-23 23:41   ` [PATCH 01/10] fuse2fs: add strictatime/lazytime mount options Darrick J. Wong
                     ` (9 more replies)
  2026-02-23 23:05 ` [PATCHSET v7 4/8] fuse2fs: cache iomap mappings for even better file IO performance Darrick J. Wong
                   ` (5 subsequent siblings)
  23 siblings, 10 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:05 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

Hi all,

When iomap is enabled for a fuse file, we try to keep as much of the
file IO path in the kernel as we possibly can.  That means no calling
out to the fuse server in the IO path when we can avoid it.  However,
the existing FUSE architecture defers all file attributes to the fuse
server -- [cm]time updates, ACL metadata management, set[ug]id removal,
and permissions checking thereof, etc.

We'd really rather do all these attribute updates in the kernel, and
only push them to the fuse server when it's actually necessary (e.g.
fsync).  Furthermore, the POSIX ACL code has the weird behavior that if
the access ACL can be represented entirely by i_mode bits, it will
change the mode and delete the ACL, which fuse servers generally don't
seem to implement.

IOWs, we want consistent and correct (as defined by fstests) behavior
of file attributes in iomap mode.  Let's make the kernel manage all that
and push the results to userspace as needed.  This improves performance
even further, since it's sort of like writeback_cache mode but more
aggressive.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

Comments and questions are, as always, welcome.

e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-iomap-attrs
---
Commits in this patchset:
 * fuse2fs: add strictatime/lazytime mount options
 * fuse2fs: skip permission checking on utimens when iomap is enabled
 * fuse2fs: let the kernel tell us about acl/mode updates
 * fuse2fs: better debugging for file mode updates
 * fuse2fs: debug timestamp updates
 * fuse2fs: use coarse timestamps for iomap mode
 * fuse2fs: add tracing for retrieving timestamps
 * fuse2fs: enable syncfs
 * fuse2fs: set sync, immutable, and append at file load time
 * fuse4fs: increase attribute timeout in iomap mode
---
 fuse4fs/fuse4fs.1.in |    6 +
 fuse4fs/fuse4fs.c    |  226 ++++++++++++++++++++++++++++++----------
 misc/fuse2fs.1.in    |    6 +
 misc/fuse2fs.c       |  282 +++++++++++++++++++++++++++++++++++++-------------
 4 files changed, 389 insertions(+), 131 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 4/8] fuse2fs: cache iomap mappings for even better file IO performance
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (17 preceding siblings ...)
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
@ 2026-02-23 23:05 ` Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 1/3] fuse2fs: enable caching of iomaps Darrick J. Wong
                     ` (2 more replies)
  2026-02-23 23:05 ` [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
                   ` (4 subsequent siblings)
  23 siblings, 3 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:05 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

Hi all,

This series improves the performance (and correctness for some
filesystems) by adding the ability to cache iomap mappings in the
kernel.  For filesystems that can change mapping states during pagecache
writeback (e.g. unwritten extent conversion) this is absolutely
necessary to deal with races with writes to the pagecache because
writeback does not take i_rwsem.  For everyone else, it simply
eliminates roundtrips to userspace.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

Comments and questions are, as always, welcome.

e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-iomap-cache
---
Commits in this patchset:
 * fuse2fs: enable caching of iomaps
 * fuse2fs: constrain iomap mapping cache size
 * fuse2fs: enable iomap
---
 fuse4fs/fuse4fs.c |   44 +++++++++++++++++++++++++++++++++++++-------
 misc/fuse2fs.c    |   40 ++++++++++++++++++++++++++++++++++------
 2 files changed, 71 insertions(+), 13 deletions(-)


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 5/8] fuse2fs: improve block and inode caching
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (18 preceding siblings ...)
  2026-02-23 23:05 ` [PATCHSET v7 4/8] fuse2fs: cache iomap mappings for even better file IO performance Darrick J. Wong
@ 2026-02-23 23:05 ` Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 1/6] libsupport: add caching IO manager Darrick J. Wong
                     ` (5 more replies)
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
                   ` (3 subsequent siblings)
  23 siblings, 6 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:05 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

Hi all,

This series ports the libext2fs inode cache to the new cache.c hashtable
code that was added for fuse4fs unlinked file support and improves on
the UNIX I/O manager's block cache by adding a new I/O manager that does
its own caching.  Now we no longer have statically sized buffer caching
for the two fuse servers.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

Comments and questions are, as always, welcome.

e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-caching
---
Commits in this patchset:
 * libsupport: add caching IO manager
 * iocache: add the actual buffer cache
 * iocache: bump buffer mru priority every 50 accesses
 * fuse2fs: enable caching IO manager
 * fuse2fs: increase inode cache size
 * libext2fs: improve caching for inodes
---
 lib/ext2fs/ext2fsP.h     |   13 +
 lib/support/cache.h      |    1 
 lib/support/iocache.h    |   17 +
 debugfs/Makefile.in      |    8 
 e2fsck/Makefile.in       |   12 -
 fuse4fs/Makefile.in      |   11 -
 fuse4fs/fuse4fs.c        |    8 
 lib/ext2fs/Makefile.in   |   70 ++--
 lib/ext2fs/inline_data.c |    4 
 lib/ext2fs/inode.c       |  215 ++++++++++---
 lib/ext2fs/io_manager.c  |    3 
 lib/support/Makefile.in  |    6 
 lib/support/cache.c      |   16 +
 lib/support/iocache.c    |  765 ++++++++++++++++++++++++++++++++++++++++++++++
 misc/Makefile.in         |   12 -
 misc/fuse2fs.c           |   10 +
 resize/Makefile.in       |   11 -
 tests/fuzz/Makefile.in   |    4 
 tests/progs/Makefile.in  |    4 
 19 files changed, 1068 insertions(+), 122 deletions(-)
 create mode 100644 lib/support/iocache.h
 create mode 100644 lib/support/iocache.c


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 6/8] fuse4fs: run servers as a contained service
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (19 preceding siblings ...)
  2026-02-23 23:05 ` [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
@ 2026-02-23 23:05 ` Darrick J. Wong
  2026-02-23 23:46   ` [PATCH 1/8] libext2fs: fix MMP code to work with unixfd IO manager Darrick J. Wong
                     ` (7 more replies)
  2026-02-23 23:06 ` [PATCHSET v7 7/8] fuse4fs: reclaim buffer cache under memory pressure Darrick J. Wong
                   ` (2 subsequent siblings)
  23 siblings, 8 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:05 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

Hi all,

In this series of the fuse-iomap prototype, we package the newly created
fuse4fs server into a systemd socket service.  This service can be used
by the "mount.service" helper in libfuse to implement untrusted
unprivileged mounts.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

Comments and questions are, as always, welcome.

e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse4fs-service-container
---
Commits in this patchset:
 * libext2fs: fix MMP code to work with unixfd IO manager
 * fuse4fs: enable safe service mode
 * fuse4fs: set proc title when in fuse service mode
 * fuse4fs: upsert first file mapping to kernel on open
 * fuse4fs: set iomap backing device blocksize
 * fuse4fs: ask for loop devices when opening via fuservicemount
 * fuse4fs: make MMP work correctly in safe service mode
 * debian: update packaging for fuse4fs service
---
 lib/ext2fs/ext2fs.h         |    1 
 MCONFIG.in                  |    1 
 configure                   |  190 +++++++++++++++++++
 configure.ac                |   54 ++++++
 debian/e2fsprogs.install    |    7 +
 debian/fuse4fs.install      |    3 
 debian/rules                |    3 
 fuse4fs/Makefile.in         |   42 ++++
 fuse4fs/fuse4fs.c           |  421 +++++++++++++++++++++++++++++++++++++++++--
 fuse4fs/fuse4fs.socket.in   |   17 ++
 fuse4fs/fuse4fs@.service.in |   99 ++++++++++
 lib/config.h.in             |    6 +
 lib/ext2fs/mmp.c            |   82 ++++++++
 util/subst.conf.in          |    2 
 14 files changed, 902 insertions(+), 26 deletions(-)
 mode change 100644 => 100755 debian/fuse4fs.install
 create mode 100644 fuse4fs/fuse4fs.socket.in
 create mode 100644 fuse4fs/fuse4fs@.service.in


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET v7 7/8] fuse4fs: reclaim buffer cache under memory pressure
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (20 preceding siblings ...)
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
@ 2026-02-23 23:06 ` Darrick J. Wong
  2026-02-23 23:48   ` [PATCH 1/4] libsupport: add pressure stall monitor Darrick J. Wong
                     ` (3 more replies)
  2026-02-23 23:06 ` [PATCHSET RFC 8/8] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
  2026-03-16 17:56 ` [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Joanne Koong
  23 siblings, 4 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:06 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

Hi all,

Having a static buffer cache limit of 32MB is very conservative.  When
there's plenty of free memory, evicting metadata from the cache isn't
actually a good idea, so we'd like to let it grow to handle large
working sets.  However, we also don't want to OOM the kernel or (in the
future) the fuse4fs container cgroup, so we need to listen for memory
reclamation events in the kernel.

The solution to this is to open the kernel memory pressure stall
indicator files, configure an event when too much time is spent waiting
for reclamation, and to trim the buffer cache when the events happen.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

Comments and questions are, as always, welcome.

e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse4fs-memory-reclaim
---
Commits in this patchset:
 * libsupport: add pressure stall monitor
 * fuse2fs: only reclaim buffer cache when there is memory pressure
 * fuse4fs: enable memory pressure monitoring with service containers
 * fuse2fs: flush dirty metadata periodically
---
 lib/support/psi.h       |   66 ++++++
 fuse4fs/Makefile.in     |    2 
 fuse4fs/fuse4fs.c       |  263 +++++++++++++++++++++-
 lib/support/Makefile.in |    4 
 lib/support/iocache.c   |   19 ++
 lib/support/psi.c       |  557 +++++++++++++++++++++++++++++++++++++++++++++++
 misc/Makefile.in        |    2 
 misc/fuse2fs.c          |  196 ++++++++++++++++-
 8 files changed, 1089 insertions(+), 20 deletions(-)
 create mode 100644 lib/support/psi.h
 create mode 100644 lib/support/psi.c


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCHSET RFC 8/8] fuse: allow fuse servers to upload iomap BPF programs
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (21 preceding siblings ...)
  2026-02-23 23:06 ` [PATCHSET v7 7/8] fuse4fs: reclaim buffer cache under memory pressure Darrick J. Wong
@ 2026-02-23 23:06 ` Darrick J. Wong
  2026-02-23 23:49   ` [PATCH 1/3] fuse4fs: add dynamic iomap bpf prototype which will break FIEMAP Darrick J. Wong
                     ` (2 more replies)
  2026-03-16 17:56 ` [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Joanne Koong
  23 siblings, 3 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:06 UTC (permalink / raw)
  To: tytso
  Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal,
	john

Hi all,

There are certain fuse servers that might benefit from the ability to
upload a BPF program into the kernel to respond to ->iomap_begin
requests instead of upcalling the fuse server itself.

For example, consider a fuse server that abstracts a large amount of
storage for use as intermediate storage by programs.  If the storage is
striped across hardware devices (e.g. RAID0 or interleaved memory
controllers) then the iomapping pattern will be completely regular but
the mappings themselves might be very small.

Performance for large IOs will suck if it is necessary to upcall the
fuse server every time we cross a mapping boundary.  The fuse server can
try to mitigate that hit by upserting mappings ahead of time, but
there's a better solution for this usecase: BPF programs.

In this case, the fuse server can compile a BPF program that will
compute the mapping data for a given request and upload the program.
This avoids the overhead of cache lookups and server upcalls.  Note that
the BPF verifier still imposes instruction count and complexity limits
on the uploaded programs.

Note that I embraced and extended some code from Joanne, but at this
point I've modified it so heavily that it's not really the original
anymore.  But she still gets credit for coming up with the idea and
engaging me in flinging prototypes around.

More recently, this patchset has changed strategies -- instead of
compiling a static BPF program with very limited functionality, we
instead compile it on the fly, which allows for dynamic behavior.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

Comments and questions are, as always, welcome.

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf

e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse-iomap-bpf
---
Commits in this patchset:
 * fuse4fs: add dynamic iomap bpf prototype which will break FIEMAP
 * fuse4fs: wire up caching examples to fuse iomap bpf program
 * fuse4fs: adjust test bpf program to deal with opaque inodes
---
 fuse4fs/fuse4fs_bpf.h |   54 +++++++
 MCONFIG.in            |    5 +
 configure             |  188 +++++++++++++++++++++++
 configure.ac          |   94 +++++++++++
 fuse4fs/Makefile.in   |   22 ++-
 fuse4fs/fuse4fs.c     |   92 +++++++++++
 fuse4fs/fuse4fs_bpf.c |  404 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/config.h.in       |   12 +
 8 files changed, 869 insertions(+), 2 deletions(-)
 create mode 100644 fuse4fs/fuse4fs_bpf.h
 create mode 100644 fuse4fs/fuse4fs_bpf.c


^ permalink raw reply	[flat|nested] 234+ messages in thread

* [PATCH 1/5] fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY
  2026-02-23 23:00 ` [PATCHSET v7 1/9] fuse: general bug fixes Darrick J. Wong
@ 2026-02-23 23:06   ` Darrick J. Wong
  2026-02-24 19:33     ` Joanne Koong
  2026-02-23 23:06   ` [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write Darrick J. Wong
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:06 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

generic/488 fails with fuse2fs in the following fashion:

generic/488       _check_generic_filesystem: filesystem on /dev/sdf is inconsistent
(see /var/tmp/fstests/generic/488.full for details)

This test opens a large number of files, unlinks them (which really just
renames them to fuse hidden files), closes the program, unmounts the
filesystem, and runs fsck to check that there aren't any inconsistencies
in the filesystem.

Unfortunately, the 488.full file shows that there are a lot of hidden
files left over in the filesystem, with incorrect link counts.  Tracing
fuse_request_* shows that there are a large number of FUSE_RELEASE
commands that are queued up on behalf of the unlinked files at the time
that fuse_conn_destroy calls fuse_abort_conn.  Had the connection not
aborted, the fuse server would have responded to the RELEASE commands by
removing the hidden files; instead they stick around.

For upper-level fuse servers that don't use fuseblk mode this isn't a
problem because libfuse responds to the connection going down by pruning
its inode cache and calling the fuse server's ->release for any open
files before calling the server's ->destroy function.

For fuseblk servers this is a problem, however, because the kernel sends
FUSE_DESTROY to the fuse server, and the fuse server has to write all of
its pending changes to the block device before replying to the DESTROY
request because the kernel releases its O_EXCL hold on the block device.
This means that the kernel must flush all pending FUSE_RELEASE requests
before issuing FUSE_DESTROY.

For fuse-iomap servers this will also be a problem because iomap servers
are expected to release all exclusively-held resources before unmount
returns from the kernel.

Create a function to push all the background requests to the queue
before sending FUSE_DESTROY.  That way, all the pending file release
events are processed by the fuse server before it tears itself down, and
we don't end up with a corrupt filesystem.

Note that multithreaded fuse servers will need to track the number of
open files and defer a FUSE_DESTROY request until that number reaches
zero.  An earlier version of this patch made the kernel wait for the
RELEASE acknowledgements before sending DESTROY, but the kernel people
weren't comfortable with adding blocking waits to unmount.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h |    5 +++++
 fs/fuse/dev.c    |   19 +++++++++++++++++++
 fs/fuse/inode.c  |   12 +++++++++++-
 3 files changed, 35 insertions(+), 1 deletion(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 7f16049387d15e..1d4beca5c7018d 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1287,6 +1287,11 @@ void fuse_request_end(struct fuse_req *req);
 void fuse_abort_conn(struct fuse_conn *fc);
 void fuse_wait_aborted(struct fuse_conn *fc);
 
+/**
+ * Flush all pending requests but do not wait for them.
+ */
+void fuse_flush_requests(struct fuse_conn *fc);
+
 /* Check if any requests timed out */
 void fuse_check_timeout(struct work_struct *work);
 
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 0b0241f47170d4..ac9d7a7b3f5e68 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -24,6 +24,7 @@
 #include <linux/splice.h>
 #include <linux/sched.h>
 #include <linux/seq_file.h>
+#include <linux/nmi.h>
 
 #include "fuse_trace.h"
 
@@ -2430,6 +2431,24 @@ static void end_polls(struct fuse_conn *fc)
 	}
 }
 
+/*
+ * Flush all pending requests and wait for them.  Only call this function when
+ * it is no longer possible for other threads to add requests.
+ */
+void fuse_flush_requests(struct fuse_conn *fc)
+{
+	spin_lock(&fc->lock);
+	spin_lock(&fc->bg_lock);
+	if (fc->connected) {
+		/* Push all the background requests to the queue. */
+		fc->blocked = 0;
+		fc->max_background = UINT_MAX;
+		flush_bg_queue(fc);
+	}
+	spin_unlock(&fc->bg_lock);
+	spin_unlock(&fc->lock);
+}
+
 /*
  * Abort all requests.
  *
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index e57b8af06be93e..58c3351b467221 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -2086,8 +2086,18 @@ void fuse_conn_destroy(struct fuse_mount *fm)
 {
 	struct fuse_conn *fc = fm->fc;
 
-	if (fc->destroy)
+	if (fc->destroy) {
+		/*
+		 * Flush all pending requests (most of which will be
+		 * FUSE_RELEASE) before sending FUSE_DESTROY, because the fuse
+		 * server must close the filesystem before replying to the
+		 * destroy message, because unmount is about to release its
+		 * O_EXCL hold on the block device.  We don't wait, so libfuse
+		 * has to do that for us.
+		 */
+		fuse_flush_requests(fc);
 		fuse_send_destroy(fm);
+	}
 
 	fuse_abort_conn(fc);
 	fuse_wait_aborted(fc);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write
  2026-02-23 23:00 ` [PATCHSET v7 1/9] fuse: general bug fixes Darrick J. Wong
  2026-02-23 23:06   ` [PATCH 1/5] fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY Darrick J. Wong
@ 2026-02-23 23:06   ` Darrick J. Wong
  2026-02-24  8:36     ` Horst Birthelmer
                       ` (2 more replies)
  2026-02-23 23:07   ` [PATCH 3/5] fuse: implement file attributes mask for statx Darrick J. Wong
                     ` (2 subsequent siblings)
  4 siblings, 3 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:06 UTC (permalink / raw)
  To: miklos, djwong
  Cc: stable, joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

gcc 15 complains about an uninitialized variable val that is passed by
reference into fuse_conn_limit_write:

 control.c: In function ‘fuse_conn_congestion_threshold_write’:
 include/asm-generic/rwonce.h:55:37: warning: ‘val’ may be used uninitialized [-Wmaybe-uninitialized]
    55 |         *(volatile typeof(x) *)&(x) = (val);                            \
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
 include/asm-generic/rwonce.h:61:9: note: in expansion of macro ‘__WRITE_ONCE’
    61 |         __WRITE_ONCE(x, val);                                           \
       |         ^~~~~~~~~~~~
 control.c:178:9: note: in expansion of macro ‘WRITE_ONCE’
   178 |         WRITE_ONCE(fc->congestion_threshold, val);
       |         ^~~~~~~~~~
 control.c:166:18: note: ‘val’ was declared here
   166 |         unsigned val;
       |                  ^~~

Unfortunately there's enough macro spew involved in kstrtoul_from_user
that I think gcc gives up on its analysis and sprays the above warning.
AFAICT it's not actually a bug, but we could just zero-initialize the
variable to enable using -Wmaybe-uninitialized to find real problems.

Previously we would use some weird uninitialized_var annotation to quiet
down the warnings, so clearly this code has been like this for quite
some time.

Cc: <stable@vger.kernel.org> # v5.9
Fixes: 3f649ab728cda8 ("treewide: Remove uninitialized_var() usage")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/control.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index 140bd5730d9984..073c2d8e4dfc7c 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -121,7 +121,7 @@ static ssize_t fuse_conn_max_background_write(struct file *file,
 					      const char __user *buf,
 					      size_t count, loff_t *ppos)
 {
-	unsigned val;
+	unsigned val = 0;
 	ssize_t ret;
 
 	ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
@@ -163,7 +163,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
 						    const char __user *buf,
 						    size_t count, loff_t *ppos)
 {
-	unsigned val;
+	unsigned val = 0;
 	struct fuse_conn *fc;
 	ssize_t ret;
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/5] fuse: implement file attributes mask for statx
  2026-02-23 23:00 ` [PATCHSET v7 1/9] fuse: general bug fixes Darrick J. Wong
  2026-02-23 23:06   ` [PATCH 1/5] fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY Darrick J. Wong
  2026-02-23 23:06   ` [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write Darrick J. Wong
@ 2026-02-23 23:07   ` Darrick J. Wong
  2026-03-25 18:35     ` Joanne Koong
  2026-02-23 23:07   ` [PATCH 4/5] fuse: update file mode when updating acls Darrick J. Wong
  2026-02-23 23:07   ` [PATCH 5/5] fuse: propagate default and file acls on creation Darrick J. Wong
  4 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:07 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, joannelkoong, bpf, bernd, neal, linux-fsdevel,
	linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Actually copy the attributes/attributes_mask from userspace.  Ignore
file attributes bits that the VFS sets (or doesn't set) on its own.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/fuse_i.h |   37 +++++++++++++++++++++++++++++++++++++
 fs/fuse/dir.c    |    4 ++++
 fs/fuse/inode.c  |    4 ++++
 3 files changed, 45 insertions(+)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 1d4beca5c7018d..79793db3e9a743 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -147,6 +147,10 @@ struct fuse_inode {
 	/** Version of last attribute change */
 	u64 attr_version;
 
+	/** statx file attributes */
+	u64 statx_attributes;
+	u64 statx_attributes_mask;
+
 	union {
 		/* read/write io cache (regular file only) */
 		struct {
@@ -1236,6 +1240,39 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
 				   u64 attr_valid, u32 cache_mask,
 				   u64 evict_ctr);
 
+/*
+ * These statx attribute flags are set by the VFS so mask them out of replies
+ * from the fuse server for local filesystems.  Nonlocal filesystems are
+ * responsible for enforcing and advertising these flags themselves.
+ */
+#define FUSE_STATX_LOCAL_VFS_ATTRIBUTES (STATX_ATTR_IMMUTABLE | \
+					 STATX_ATTR_APPEND)
+
+/*
+ * These statx attribute flags are set by the VFS so mask them out of replies
+ * from the fuse server.
+ */
+#define FUSE_STATX_VFS_ATTRIBUTES (STATX_ATTR_AUTOMOUNT | STATX_ATTR_DAX | \
+				   STATX_ATTR_MOUNT_ROOT)
+
+static inline u64 fuse_statx_attributes_mask(const struct inode *inode,
+					     const struct fuse_statx *sx)
+{
+	if (fuse_inode_is_exclusive(inode))
+		return sx->attributes_mask & ~(FUSE_STATX_VFS_ATTRIBUTES |
+					       FUSE_STATX_LOCAL_VFS_ATTRIBUTES);
+	return sx->attributes_mask & ~FUSE_STATX_VFS_ATTRIBUTES;
+}
+
+static inline u64 fuse_statx_attributes(const struct inode *inode,
+					const struct fuse_statx *sx)
+{
+	if (fuse_inode_is_exclusive(inode))
+		return sx->attributes & ~(FUSE_STATX_VFS_ATTRIBUTES |
+					  FUSE_STATX_LOCAL_VFS_ATTRIBUTES);
+	return sx->attributes & ~FUSE_STATX_VFS_ATTRIBUTES;
+}
+
 u32 fuse_get_cache_mask(struct inode *inode);
 
 /**
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 7ac6b232ef1232..10fa47e969292f 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1464,6 +1464,8 @@ static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
 		stat->result_mask = sx->mask & (STATX_BASIC_STATS | STATX_BTIME);
 		stat->btime.tv_sec = sx->btime.tv_sec;
 		stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec, NSEC_PER_SEC - 1);
+		stat->attributes |= fuse_statx_attributes(inode, sx);
+		stat->attributes_mask |= fuse_statx_attributes_mask(inode, sx);
 		fuse_fillattr(idmap, inode, &attr, stat);
 		stat->result_mask |= STATX_TYPE;
 	}
@@ -1568,6 +1570,8 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,
 			stat->btime = fi->i_btime;
 			stat->result_mask |= STATX_BTIME;
 		}
+		stat->attributes = fi->statx_attributes;
+		stat->attributes_mask = fi->statx_attributes_mask;
 	}
 
 	return err;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 58c3351b467221..ff8b94cb02e63c 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -286,6 +286,10 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
 			fi->i_btime.tv_sec = sx->btime.tv_sec;
 			fi->i_btime.tv_nsec = sx->btime.tv_nsec;
 		}
+
+		fi->statx_attributes = fuse_statx_attributes(inode, sx);
+		fi->statx_attributes_mask = fuse_statx_attributes_mask(inode,
+								       sx);
 	}
 
 	if (attr->blksize)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 4/5] fuse: update file mode when updating acls
  2026-02-23 23:00 ` [PATCHSET v7 1/9] fuse: general bug fixes Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:07   ` [PATCH 3/5] fuse: implement file attributes mask for statx Darrick J. Wong
@ 2026-02-23 23:07   ` Darrick J. Wong
  2026-03-25 19:39     ` Joanne Koong
  2026-02-23 23:07   ` [PATCH 5/5] fuse: propagate default and file acls on creation Darrick J. Wong
  4 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:07 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

If someone sets ACLs on a file that can be expressed fully as Unix DAC
mode bits, most local filesystems will then update the mode bits and
drop the ACL xattr to reduce inefficiency in the file access paths.
Let's do that too.  Note that means that we can setacl and end up with
no ACL xattrs, so we also need to tolerate ENODATA returns from
fuse_removexattr.

Note that here we define a "local" fuse filesystem as one that uses
fuseblk mode; we'll shortly add fuse servers that use iomap for the file
IO path to that list.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h |    2 +-
 fs/fuse/acl.c    |   43 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 2 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 79793db3e9a743..a1880599455c0a 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1051,7 +1051,7 @@ static inline struct fuse_mount *get_fuse_mount(struct inode *inode)
 	return get_fuse_mount_super(inode->i_sb);
 }
 
-static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
+static inline struct fuse_conn *get_fuse_conn(const struct inode *inode)
 {
 	return get_fuse_mount_super(inode->i_sb)->fc;
 }
diff --git a/fs/fuse/acl.c b/fs/fuse/acl.c
index cbde6ac1add35a..f2b959efd67490 100644
--- a/fs/fuse/acl.c
+++ b/fs/fuse/acl.c
@@ -11,6 +11,18 @@
 #include <linux/posix_acl.h>
 #include <linux/posix_acl_xattr.h>
 
+/*
+ * If this fuse server behaves like a local filesystem, we can implement the
+ * kernel's optimizations for ACLs for local filesystems instead of passing
+ * the ACL requests straight through to another server.
+ */
+static inline bool fuse_inode_has_local_acls(const struct inode *inode)
+{
+	const struct fuse_conn *fc = get_fuse_conn(inode);
+
+	return fc->posix_acl && fuse_inode_is_exclusive(inode);
+}
+
 static struct posix_acl *__fuse_get_acl(struct fuse_conn *fc,
 					struct inode *inode, int type, bool rcu)
 {
@@ -98,6 +110,7 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 	struct inode *inode = d_inode(dentry);
 	struct fuse_conn *fc = get_fuse_conn(inode);
 	const char *name;
+	umode_t mode = inode->i_mode;
 	int ret;
 
 	if (fuse_is_bad(inode))
@@ -113,6 +126,18 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 	else
 		return -EINVAL;
 
+	/*
+	 * If the ACL can be represented entirely with changes to the mode
+	 * bits, then most filesystems will update the mode bits and delete
+	 * the ACL xattr.
+	 */
+	if (acl && type == ACL_TYPE_ACCESS &&
+	    fuse_inode_has_local_acls(inode)) {
+		ret = posix_acl_update_mode(idmap, inode, &mode, &acl);
+		if (ret)
+			return ret;
+	}
+
 	if (acl) {
 		unsigned int extra_flags = 0;
 		/*
@@ -139,7 +164,7 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 		 * through POSIX ACLs. Such daemons don't expect setgid bits to
 		 * be stripped.
 		 */
-		if (fc->posix_acl &&
+		if (fc->posix_acl && mode == inode->i_mode &&
 		    !in_group_or_capable(idmap, inode,
 					 i_gid_into_vfsgid(idmap, inode)))
 			extra_flags |= FUSE_SETXATTR_ACL_KILL_SGID;
@@ -148,6 +173,22 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 		kfree(value);
 	} else {
 		ret = fuse_removexattr(inode, name);
+		/* If the acl didn't exist to start with that's fine. */
+		if (ret == -ENODATA)
+			ret = 0;
+	}
+
+	/* If we scheduled a mode update above, push that to userspace now. */
+	if (!ret) {
+		struct iattr attr = { };
+
+		if (mode != inode->i_mode) {
+			attr.ia_valid |= ATTR_MODE;
+			attr.ia_mode = mode;
+		}
+
+		if (attr.ia_valid)
+			ret = fuse_do_setattr(idmap, dentry, &attr, NULL);
 	}
 
 	if (fc->posix_acl) {


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 5/5] fuse: propagate default and file acls on creation
  2026-02-23 23:00 ` [PATCHSET v7 1/9] fuse: general bug fixes Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:07   ` [PATCH 4/5] fuse: update file mode when updating acls Darrick J. Wong
@ 2026-02-23 23:07   ` Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:07 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

For local filesystems, propagate the default and file access ACLs to new
children when creating them, just like the other in-kernel local
filesystems.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h |    4 ++
 fs/fuse/acl.c    |   62 +++++++++++++++++++++++++++++++++
 fs/fuse/dir.c    |  101 +++++++++++++++++++++++++++++++++++++++++-------------
 3 files changed, 142 insertions(+), 25 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index a1880599455c0a..77b581ecf48a16 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1533,6 +1533,10 @@ struct posix_acl *fuse_get_acl(struct mnt_idmap *idmap,
 			       struct dentry *dentry, int type);
 int fuse_set_acl(struct mnt_idmap *, struct dentry *dentry,
 		 struct posix_acl *acl, int type);
+int fuse_acl_create(struct inode *dir, umode_t *mode,
+		    struct posix_acl **default_acl, struct posix_acl **acl);
+int fuse_init_acls(struct inode *inode, const struct posix_acl *default_acl,
+		   const struct posix_acl *acl);
 
 /* readdir.c */
 int fuse_readdir(struct file *file, struct dir_context *ctx);
diff --git a/fs/fuse/acl.c b/fs/fuse/acl.c
index f2b959efd67490..483ddf195d40a6 100644
--- a/fs/fuse/acl.c
+++ b/fs/fuse/acl.c
@@ -10,6 +10,7 @@
 
 #include <linux/posix_acl.h>
 #include <linux/posix_acl_xattr.h>
+#include <linux/fs_struct.h>
 
 /*
  * If this fuse server behaves like a local filesystem, we can implement the
@@ -202,3 +203,64 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 
 	return ret;
 }
+
+int fuse_acl_create(struct inode *dir, umode_t *mode,
+		    struct posix_acl **default_acl, struct posix_acl **acl)
+{
+	struct fuse_conn *fc = get_fuse_conn(dir);
+
+	if (fuse_is_bad(dir))
+		return -EIO;
+
+	if (IS_POSIXACL(dir) && fuse_inode_has_local_acls(dir))
+		return posix_acl_create(dir, mode, default_acl, acl);
+
+	if (!fc->dont_mask)
+		*mode &= ~current_umask();
+
+	*default_acl = NULL;
+	*acl = NULL;
+	return 0;
+}
+
+static int __fuse_set_acl(struct inode *inode, const char *name,
+			  const struct posix_acl *acl)
+{
+	struct fuse_conn *fc = get_fuse_conn(inode);
+	size_t size;
+	void *value = posix_acl_to_xattr(fc->user_ns, acl, &size, GFP_KERNEL);
+	int ret;
+
+	if (!value)
+		return -ENOMEM;
+
+	if (size > PAGE_SIZE) {
+		kfree(value);
+		return -E2BIG;
+	}
+
+	ret = fuse_setxattr(inode, name, value, size, 0, 0);
+	kfree(value);
+	return ret;
+}
+
+int fuse_init_acls(struct inode *inode, const struct posix_acl *default_acl,
+		   const struct posix_acl *acl)
+{
+	int ret;
+
+	if (default_acl) {
+		ret = __fuse_set_acl(inode, XATTR_NAME_POSIX_ACL_DEFAULT,
+				     default_acl);
+		if (ret)
+			return ret;
+	}
+
+	if (acl) {
+		ret = __fuse_set_acl(inode, XATTR_NAME_POSIX_ACL_ACCESS, acl);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 10fa47e969292f..9abec6f072ac73 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -821,26 +821,28 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
 	struct fuse_entry_out outentry;
 	struct fuse_inode *fi;
 	struct fuse_file *ff;
+	struct posix_acl *default_acl = NULL, *acl = NULL;
 	int epoch, err;
 	bool trunc = flags & O_TRUNC;
 
 	/* Userspace expects S_IFREG in create mode */
 	BUG_ON((mode & S_IFMT) != S_IFREG);
 
+	err = fuse_acl_create(dir, &mode, &default_acl, &acl);
+	if (err)
+		return err;
+
 	epoch = atomic_read(&fm->fc->epoch);
 	forget = fuse_alloc_forget();
 	err = -ENOMEM;
 	if (!forget)
-		goto out_err;
+		goto out_acl_release;
 
 	err = -ENOMEM;
 	ff = fuse_file_alloc(fm, true);
 	if (!ff)
 		goto out_put_forget_req;
 
-	if (!fm->fc->dont_mask)
-		mode &= ~current_umask();
-
 	flags &= ~O_NOCTTY;
 	memset(&inarg, 0, sizeof(inarg));
 	memset(&outentry, 0, sizeof(outentry));
@@ -892,12 +894,17 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
 		fuse_sync_release(NULL, ff, flags);
 		fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1);
 		err = -ENOMEM;
-		goto out_err;
+		goto out_acl_release;
 	}
 	kfree(forget);
 	d_instantiate(entry, inode);
 	entry->d_time = epoch;
 	fuse_change_entry_timeout(entry, &outentry);
+
+	err = fuse_init_acls(inode, default_acl, acl);
+	if (err)
+		goto out_acl_release;
+
 	fuse_dir_changed(dir);
 	err = generic_file_open(inode, file);
 	if (!err) {
@@ -913,13 +920,17 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
 		else if (!(ff->open_flags & FOPEN_KEEP_CACHE))
 			invalidate_inode_pages2(inode->i_mapping);
 	}
+	posix_acl_release(default_acl);
+	posix_acl_release(acl);
 	return err;
 
 out_free_ff:
 	fuse_file_free(ff);
 out_put_forget_req:
 	kfree(forget);
-out_err:
+out_acl_release:
+	posix_acl_release(default_acl);
+	posix_acl_release(acl);
 	return err;
 }
 
@@ -971,7 +982,9 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
  */
 static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_mount *fm,
 				       struct fuse_args *args, struct inode *dir,
-				       struct dentry *entry, umode_t mode)
+				       struct dentry *entry, umode_t mode,
+				       struct posix_acl *default_acl,
+				       struct posix_acl *acl)
 {
 	struct fuse_entry_out outarg;
 	struct inode *inode;
@@ -979,14 +992,18 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun
 	struct fuse_forget_link *forget;
 	int epoch, err;
 
-	if (fuse_is_bad(dir))
-		return ERR_PTR(-EIO);
+	if (fuse_is_bad(dir)) {
+		err = -EIO;
+		goto out_acl_release;
+	}
 
 	epoch = atomic_read(&fm->fc->epoch);
 
 	forget = fuse_alloc_forget();
-	if (!forget)
-		return ERR_PTR(-ENOMEM);
+	if (!forget) {
+		err = -ENOMEM;
+		goto out_acl_release;
+	}
 
 	memset(&outarg, 0, sizeof(outarg));
 	args->nodeid = get_node_id(dir);
@@ -1016,14 +1033,17 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun
 			  &outarg.attr, ATTR_TIMEOUT(&outarg), 0, 0);
 	if (!inode) {
 		fuse_queue_forget(fm->fc, forget, outarg.nodeid, 1);
-		return ERR_PTR(-ENOMEM);
+		err = -ENOMEM;
+		goto out_acl_release;
 	}
 	kfree(forget);
 
 	d_drop(entry);
 	d = d_splice_alias(inode, entry);
-	if (IS_ERR(d))
-		return d;
+	if (IS_ERR(d)) {
+		err = PTR_ERR(d);
+		goto out_acl_release;
+	}
 
 	if (d) {
 		d->d_time = epoch;
@@ -1032,19 +1052,31 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun
 		entry->d_time = epoch;
 		fuse_change_entry_timeout(entry, &outarg);
 	}
+
+	err = fuse_init_acls(inode, default_acl, acl);
+	if (err)
+		goto out_acl_release;
 	fuse_dir_changed(dir);
+
+	posix_acl_release(default_acl);
+	posix_acl_release(acl);
 	return d;
 
  out_put_forget_req:
 	if (err == -EEXIST)
 		fuse_invalidate_entry(entry);
 	kfree(forget);
+ out_acl_release:
+	posix_acl_release(default_acl);
+	posix_acl_release(acl);
 	return ERR_PTR(err);
 }
 
 static int create_new_nondir(struct mnt_idmap *idmap, struct fuse_mount *fm,
 			     struct fuse_args *args, struct inode *dir,
-			     struct dentry *entry, umode_t mode)
+			     struct dentry *entry, umode_t mode,
+			     struct posix_acl *default_acl,
+			     struct posix_acl *acl)
 {
 	/*
 	 * Note that when creating anything other than a directory we
@@ -1055,7 +1087,8 @@ static int create_new_nondir(struct mnt_idmap *idmap, struct fuse_mount *fm,
 	 */
 	WARN_ON_ONCE(S_ISDIR(mode));
 
-	return PTR_ERR(create_new_entry(idmap, fm, args, dir, entry, mode));
+	return PTR_ERR(create_new_entry(idmap, fm, args, dir, entry, mode,
+					default_acl, acl));
 }
 
 static int fuse_mknod(struct mnt_idmap *idmap, struct inode *dir,
@@ -1063,10 +1096,13 @@ static int fuse_mknod(struct mnt_idmap *idmap, struct inode *dir,
 {
 	struct fuse_mknod_in inarg;
 	struct fuse_mount *fm = get_fuse_mount(dir);
+	struct posix_acl *default_acl, *acl;
 	FUSE_ARGS(args);
+	int err;
 
-	if (!fm->fc->dont_mask)
-		mode &= ~current_umask();
+	err = fuse_acl_create(dir, &mode, &default_acl, &acl);
+	if (err)
+		return err;
 
 	memset(&inarg, 0, sizeof(inarg));
 	inarg.mode = mode;
@@ -1078,7 +1114,8 @@ static int fuse_mknod(struct mnt_idmap *idmap, struct inode *dir,
 	args.in_args[0].value = &inarg;
 	args.in_args[1].size = entry->d_name.len + 1;
 	args.in_args[1].value = entry->d_name.name;
-	return create_new_nondir(idmap, fm, &args, dir, entry, mode);
+	return create_new_nondir(idmap, fm, &args, dir, entry, mode,
+				 default_acl, acl);
 }
 
 static int fuse_create(struct mnt_idmap *idmap, struct inode *dir,
@@ -1110,13 +1147,17 @@ static struct dentry *fuse_mkdir(struct mnt_idmap *idmap, struct inode *dir,
 {
 	struct fuse_mkdir_in inarg;
 	struct fuse_mount *fm = get_fuse_mount(dir);
+	struct posix_acl *default_acl, *acl;
 	FUSE_ARGS(args);
+	int err;
 
-	if (!fm->fc->dont_mask)
-		mode &= ~current_umask();
+	mode |= S_IFDIR;	/* vfs doesn't set S_IFDIR for us */
+	err = fuse_acl_create(dir, &mode, &default_acl, &acl);
+	if (err)
+		return ERR_PTR(err);
 
 	memset(&inarg, 0, sizeof(inarg));
-	inarg.mode = mode;
+	inarg.mode = mode & ~S_IFDIR;
 	inarg.umask = current_umask();
 	args.opcode = FUSE_MKDIR;
 	args.in_numargs = 2;
@@ -1124,7 +1165,8 @@ static struct dentry *fuse_mkdir(struct mnt_idmap *idmap, struct inode *dir,
 	args.in_args[0].value = &inarg;
 	args.in_args[1].size = entry->d_name.len + 1;
 	args.in_args[1].value = entry->d_name.name;
-	return create_new_entry(idmap, fm, &args, dir, entry, S_IFDIR);
+	return create_new_entry(idmap, fm, &args, dir, entry, S_IFDIR,
+				default_acl, acl);
 }
 
 static int fuse_symlink(struct mnt_idmap *idmap, struct inode *dir,
@@ -1132,7 +1174,14 @@ static int fuse_symlink(struct mnt_idmap *idmap, struct inode *dir,
 {
 	struct fuse_mount *fm = get_fuse_mount(dir);
 	unsigned len = strlen(link) + 1;
+	struct posix_acl *default_acl, *acl;
+	umode_t mode = S_IFLNK | 0777;
 	FUSE_ARGS(args);
+	int err;
+
+	err = fuse_acl_create(dir, &mode, &default_acl, &acl);
+	if (err)
+		return err;
 
 	args.opcode = FUSE_SYMLINK;
 	args.in_numargs = 3;
@@ -1141,7 +1190,8 @@ static int fuse_symlink(struct mnt_idmap *idmap, struct inode *dir,
 	args.in_args[1].value = entry->d_name.name;
 	args.in_args[2].size = len;
 	args.in_args[2].value = link;
-	return create_new_nondir(idmap, fm, &args, dir, entry, S_IFLNK);
+	return create_new_nondir(idmap, fm, &args, dir, entry, S_IFLNK,
+				 default_acl, acl);
 }
 
 void fuse_flush_time_update(struct inode *inode)
@@ -1341,7 +1391,8 @@ static int fuse_link(struct dentry *entry, struct inode *newdir,
 	args.in_args[0].value = &inarg;
 	args.in_args[1].size = newent->d_name.len + 1;
 	args.in_args[1].value = newent->d_name.name;
-	err = create_new_nondir(&invalid_mnt_idmap, fm, &args, newdir, newent, inode->i_mode);
+	err = create_new_nondir(&invalid_mnt_idmap, fm, &args, newdir, newent,
+				inode->i_mode, NULL, NULL);
 	if (!err)
 		fuse_update_ctime_in_cache(inode);
 	else if (err == -EINTR)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/2] iomap: allow directio callers to supply _COMP_WORK
  2026-02-23 23:00 ` [PATCHSET v7 2/9] iomap: cleanups ahead of adding fuse support Darrick J. Wong
@ 2026-02-23 23:07   ` Darrick J. Wong
  2026-02-24 14:00     ` Christoph Hellwig
  2026-02-23 23:08   ` [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile Darrick J. Wong
  1 sibling, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:07 UTC (permalink / raw)
  To: brauner, miklos, djwong; +Cc: bpf, hch, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Allow callers of iomap_dio_rw to specify the _COMP_WORK flag if they
require that all directio ioend completions occur in process context.
The upcoming fuse-iomap patchset needs this because fuse requests
(specifically FUSE_IOMAP_IOEND) cannot be sent from interrupt context.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/linux/iomap.h |    3 +++
 fs/iomap/direct-io.c  |    5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 99b7209dabd77c..a47befc23a8a2d 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -575,6 +575,9 @@ struct iomap_dio_ops {
  */
 #define IOMAP_DIO_BOUNCE		(1 << 4)
 
+/* Run IO completions from process context */
+#define IOMAP_DIO_COMP_WORK		(1 << 5)
+
 ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 		const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
 		unsigned int dio_flags, void *private, size_t done_before);
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index e911daedff65ae..59e6028a37d362 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -19,7 +19,6 @@
  * iomap.h:
  */
 #define IOMAP_DIO_NO_INVALIDATE	(1U << 26)
-#define IOMAP_DIO_COMP_WORK	(1U << 27)
 #define IOMAP_DIO_WRITE_THROUGH	(1U << 28)
 #define IOMAP_DIO_NEED_SYNC	(1U << 29)
 #define IOMAP_DIO_WRITE		(1U << 30)
@@ -700,7 +699,9 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 	dio->i_size = i_size_read(inode);
 	dio->dops = dops;
 	dio->error = 0;
-	dio->flags = dio_flags & (IOMAP_DIO_FSBLOCK_ALIGNED | IOMAP_DIO_BOUNCE);
+	dio->flags = dio_flags & (IOMAP_DIO_FSBLOCK_ALIGNED |
+				  IOMAP_DIO_BOUNCE |
+				  IOMAP_DIO_COMP_WORK);
 	dio->done_before = done_before;
 
 	dio->submit.iter = iter;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile
  2026-02-23 23:00 ` [PATCHSET v7 2/9] iomap: cleanups ahead of adding fuse support Darrick J. Wong
  2026-02-23 23:07   ` [PATCH 1/2] iomap: allow directio callers to supply _COMP_WORK Darrick J. Wong
@ 2026-02-23 23:08   ` Darrick J. Wong
  2026-02-24 14:01     ` Christoph Hellwig
  1 sibling, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:08 UTC (permalink / raw)
  To: brauner, miklos, djwong; +Cc: bpf, hch, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

All current users of the iomap swapfile activation mechanism are block
device filesystems.  This means that claim_swapfile will set
swap_info_struct::bdev to inode->i_sb->s_bdev of the swap file.

However, a subsequent patch to fuse will add iomap infrastructure so
that fuse servers can be asked to provide file mappings specifically for
swap files.  The fuse server isn't required to set s_bdev (by mounting
as fuseblk) so s_bdev might be null.  For this case, we want to set
sis::bdev from the first mapping.

To make this work robustly, we must explicitly check that each mapping
provides a bdev and that there's no way we can succeed at collecting
swapfile pages without a block device.

And just to be clear: fuse-iomap servers will have to respond to an
explicit request for swapfile activation.  It's not like fuseblk, where
responding to bmap means swapfiles work even if that wasn't expected.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/iomap/swapfile.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)


diff --git a/fs/iomap/swapfile.c b/fs/iomap/swapfile.c
index 0db77c449467a7..9d9f4e84437df5 100644
--- a/fs/iomap/swapfile.c
+++ b/fs/iomap/swapfile.c
@@ -112,6 +112,13 @@ static int iomap_swapfile_iter(struct iomap_iter *iter,
 	if (iomap->flags & IOMAP_F_SHARED)
 		return iomap_swapfile_fail(isi, "has shared extents");
 
+	/* Swapfiles must be backed by a block device */
+	if (!iomap->bdev)
+		return iomap_swapfile_fail(isi, "is not on a block device");
+
+	if (iter->pos == 0 && !isi->sis->bdev)
+		isi->sis->bdev = iomap->bdev;
+
 	/* Only one bdev per swap file. */
 	if (iomap->bdev != isi->sis->bdev)
 		return iomap_swapfile_fail(isi, "outside the main device");
@@ -184,6 +191,16 @@ int iomap_swapfile_activate(struct swap_info_struct *sis,
 		return -EINVAL;
 	}
 
+	/*
+	 * If this swapfile doesn't have a block device, reject this useless
+	 * swapfile to prevent confusion later on.
+	 */
+	if (sis->bdev == NULL) {
+		pr_warn(
+ "swapon: No block device for swap file but usage pages?!\n");
+		return -EINVAL;
+	}
+
 	*pagespan = 1 + isi.highest_ppage - isi.lowest_ppage;
 	sis->max = isi.nr_pages;
 	sis->pages = isi.nr_pages - 1;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/2] fuse: move the passthrough-specific code back to passthrough.c
  2026-02-23 23:01 ` [PATCHSET v7 3/9] fuse: cleanups ahead of adding fuse support Darrick J. Wong
@ 2026-02-23 23:08   ` Darrick J. Wong
  2026-02-23 23:08   ` [PATCH 2/2] fuse_trace: " Darrick J. Wong
  1 sibling, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:08 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

In preparation for iomap, move the passthrough-specific validation code
back to passthrough.c and create a new Kconfig item for conditional
compilation of backing.c.  In the next patch, iomap will share the
backing structures.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h          |   25 ++++++++++-
 include/uapi/linux/fuse.h |    8 +++-
 fs/fuse/Kconfig           |    4 ++
 fs/fuse/Makefile          |    3 +
 fs/fuse/backing.c         |   98 ++++++++++++++++++++++++++++++++++-----------
 fs/fuse/dev.c             |    4 +-
 fs/fuse/inode.c           |    4 +-
 fs/fuse/passthrough.c     |   38 +++++++++++++++++
 8 files changed, 149 insertions(+), 35 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 77b581ecf48a16..3373252ccd1678 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -103,10 +103,23 @@ struct fuse_submount_lookup {
 	struct fuse_forget_link *forget;
 };
 
+struct fuse_conn;
+
+/** Operations for subsystems that want to use a backing file */
+struct fuse_backing_ops {
+	int (*may_admin)(struct fuse_conn *fc, uint32_t flags);
+	int (*may_open)(struct fuse_conn *fc, struct file *file);
+	int (*may_close)(struct fuse_conn *fc, struct file *file);
+	unsigned int type;
+	int id_start;
+	int id_end;
+};
+
 /** Container for data related to mapping to backing file */
 struct fuse_backing {
 	struct file *file;
 	struct cred *cred;
+	const struct fuse_backing_ops *ops;
 
 	/** refcount */
 	refcount_t count;
@@ -981,7 +994,7 @@ struct fuse_conn {
 	/* New writepages go into this bucket */
 	struct fuse_sync_bucket __rcu *curr_bucket;
 
-#ifdef CONFIG_FUSE_PASSTHROUGH
+#ifdef CONFIG_FUSE_BACKING
 	/** IDR for backing files ids */
 	struct idr backing_files_map;
 #endif
@@ -1594,10 +1607,12 @@ void fuse_file_release(struct inode *inode, struct fuse_file *ff,
 		       unsigned int open_flags, fl_owner_t id, bool isdir);
 
 /* backing.c */
-#ifdef CONFIG_FUSE_PASSTHROUGH
+#ifdef CONFIG_FUSE_BACKING
 struct fuse_backing *fuse_backing_get(struct fuse_backing *fb);
 void fuse_backing_put(struct fuse_backing *fb);
-struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id);
+struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,
+					 const struct fuse_backing_ops *ops,
+					 int backing_id);
 #else
 
 static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
@@ -1652,6 +1667,10 @@ static inline struct file *fuse_file_passthrough(struct fuse_file *ff)
 #endif
 }
 
+#ifdef CONFIG_FUSE_PASSTHROUGH
+extern const struct fuse_backing_ops fuse_passthrough_backing_ops;
+#endif
+
 ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter);
 ssize_t fuse_passthrough_write_iter(struct kiocb *iocb, struct iov_iter *iter);
 ssize_t fuse_passthrough_splice_read(struct file *in, loff_t *ppos,
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index c13e1f9a2f12bd..18713cfaf09171 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1126,9 +1126,15 @@ struct fuse_notify_prune_out {
 	uint64_t	spare;
 };
 
+#define FUSE_BACKING_TYPE_MASK		(0xFF)
+#define FUSE_BACKING_TYPE_PASSTHROUGH	(0)
+#define FUSE_BACKING_MAX_TYPE		(FUSE_BACKING_TYPE_PASSTHROUGH)
+
+#define FUSE_BACKING_FLAGS_ALL		(FUSE_BACKING_TYPE_MASK)
+
 struct fuse_backing_map {
 	int32_t		fd;
-	uint32_t	flags;
+	uint32_t	flags; /* FUSE_BACKING_* */
 	uint64_t	padding;
 };
 
diff --git a/fs/fuse/Kconfig b/fs/fuse/Kconfig
index 3a4ae632c94aa8..290d1c09e0b924 100644
--- a/fs/fuse/Kconfig
+++ b/fs/fuse/Kconfig
@@ -59,12 +59,16 @@ config FUSE_PASSTHROUGH
 	default y
 	depends on FUSE_FS
 	select FS_STACK
+	select FUSE_BACKING
 	help
 	  This allows bypassing FUSE server by mapping specific FUSE operations
 	  to be performed directly on a backing file.
 
 	  If you want to allow passthrough operations, answer Y.
 
+config FUSE_BACKING
+	bool
+
 config FUSE_IO_URING
 	bool "FUSE communication over io-uring"
 	default y
diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile
index 22ad9538dfc4b8..46041228e5be2c 100644
--- a/fs/fuse/Makefile
+++ b/fs/fuse/Makefile
@@ -14,7 +14,8 @@ 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 += iomode.o
 fuse-$(CONFIG_FUSE_DAX) += dax.o
-fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o backing.o
+fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o
+fuse-$(CONFIG_FUSE_BACKING) += backing.o
 fuse-$(CONFIG_SYSCTL) += sysctl.o
 fuse-$(CONFIG_FUSE_IO_URING) += dev_uring.o
 
diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
index d95dfa48483f0a..adb4d2ebb21379 100644
--- a/fs/fuse/backing.c
+++ b/fs/fuse/backing.c
@@ -6,6 +6,7 @@
  */
 
 #include "fuse_i.h"
+#include "fuse_trace.h"
 
 #include <linux/file.h>
 
@@ -44,7 +45,8 @@ static int fuse_backing_id_alloc(struct fuse_conn *fc, struct fuse_backing *fb)
 	idr_preload(GFP_KERNEL);
 	spin_lock(&fc->lock);
 	/* FIXME: xarray might be space inefficient */
-	id = idr_alloc_cyclic(&fc->backing_files_map, fb, 1, 0, GFP_ATOMIC);
+	id = idr_alloc_cyclic(&fc->backing_files_map, fb, fb->ops->id_start,
+			      fb->ops->id_end, GFP_ATOMIC);
 	spin_unlock(&fc->lock);
 	idr_preload_end();
 
@@ -69,32 +71,53 @@ static int fuse_backing_id_free(int id, void *p, void *data)
 	struct fuse_backing *fb = p;
 
 	WARN_ON_ONCE(refcount_read(&fb->count) != 1);
+
 	fuse_backing_free(fb);
 	return 0;
 }
 
 void fuse_backing_files_free(struct fuse_conn *fc)
 {
-	idr_for_each(&fc->backing_files_map, fuse_backing_id_free, NULL);
+	idr_for_each(&fc->backing_files_map, fuse_backing_id_free, fc);
 	idr_destroy(&fc->backing_files_map);
 }
 
+static inline const struct fuse_backing_ops *
+fuse_backing_ops_from_map(const struct fuse_backing_map *map)
+{
+	switch (map->flags & FUSE_BACKING_TYPE_MASK) {
+#ifdef CONFIG_FUSE_PASSTHROUGH
+	case FUSE_BACKING_TYPE_PASSTHROUGH:
+		return &fuse_passthrough_backing_ops;
+#endif
+	default:
+		break;
+	}
+
+	return NULL;
+}
+
 int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 {
 	struct file *file;
-	struct super_block *backing_sb;
 	struct fuse_backing *fb = NULL;
+	const struct fuse_backing_ops *ops = fuse_backing_ops_from_map(map);
+	uint32_t op_flags = map->flags & ~FUSE_BACKING_TYPE_MASK;
 	int res;
 
 	pr_debug("%s: fd=%d flags=0x%x\n", __func__, map->fd, map->flags);
 
-	/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */
-	res = -EPERM;
-	if (!fc->passthrough || !capable(CAP_SYS_ADMIN))
+	res = -EOPNOTSUPP;
+	if (!ops)
+		goto out;
+	WARN_ON(ops->type != (map->flags & FUSE_BACKING_TYPE_MASK));
+
+	res = ops->may_admin ? ops->may_admin(fc, op_flags) : 0;
+	if (res)
 		goto out;
 
 	res = -EINVAL;
-	if (map->flags || map->padding)
+	if (map->padding)
 		goto out;
 
 	file = fget_raw(map->fd);
@@ -102,14 +125,8 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 	if (!file)
 		goto out;
 
-	/* read/write/splice/mmap passthrough only relevant for regular files */
-	res = d_is_dir(file->f_path.dentry) ? -EISDIR : -EINVAL;
-	if (!d_is_reg(file->f_path.dentry))
-		goto out_fput;
-
-	backing_sb = file_inode(file)->i_sb;
-	res = -ELOOP;
-	if (backing_sb->s_stack_depth >= fc->max_stack_depth)
+	res = ops->may_open ? ops->may_open(fc, file) : 0;
+	if (res)
 		goto out_fput;
 
 	fb = kmalloc_obj(struct fuse_backing);
@@ -119,14 +136,15 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 
 	fb->file = file;
 	fb->cred = prepare_creds();
+	fb->ops = ops;
 	refcount_set(&fb->count, 1);
 
 	res = fuse_backing_id_alloc(fc, fb);
 	if (res < 0) {
 		fuse_backing_free(fb);
 		fb = NULL;
+		goto out;
 	}
-
 out:
 	pr_debug("%s: fb=0x%p, ret=%i\n", __func__, fb, res);
 
@@ -137,41 +155,71 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 	goto out;
 }
 
+static struct fuse_backing *__fuse_backing_lookup(struct fuse_conn *fc,
+						  int backing_id)
+{
+	struct fuse_backing *fb;
+
+	rcu_read_lock();
+	fb = idr_find(&fc->backing_files_map, backing_id);
+	fb = fuse_backing_get(fb);
+	rcu_read_unlock();
+
+	return fb;
+}
+
 int fuse_backing_close(struct fuse_conn *fc, int backing_id)
 {
-	struct fuse_backing *fb = NULL;
+	struct fuse_backing *fb = NULL, *test_fb;
+	const struct fuse_backing_ops *ops;
 	int err;
 
 	pr_debug("%s: backing_id=%d\n", __func__, backing_id);
 
-	/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */
-	err = -EPERM;
-	if (!fc->passthrough || !capable(CAP_SYS_ADMIN))
-		goto out;
-
 	err = -EINVAL;
 	if (backing_id <= 0)
 		goto out;
 
 	err = -ENOENT;
-	fb = fuse_backing_id_remove(fc, backing_id);
+	fb = __fuse_backing_lookup(fc, backing_id);
 	if (!fb)
 		goto out;
+	ops = fb->ops;
 
-	fuse_backing_put(fb);
+	err = ops->may_admin ? ops->may_admin(fc, 0) : 0;
+	if (err)
+		goto out_fb;
+
+	err = ops->may_close ? ops->may_close(fc, fb->file) : 0;
+	if (err)
+		goto out_fb;
+
+	err = -ENOENT;
+	test_fb = fuse_backing_id_remove(fc, backing_id);
+	if (!test_fb)
+		goto out_fb;
+
+	WARN_ON(fb != test_fb);
 	err = 0;
+	fuse_backing_put(test_fb);
+out_fb:
+	fuse_backing_put(fb);
 out:
 	pr_debug("%s: fb=0x%p, err=%i\n", __func__, fb, err);
 
 	return err;
 }
 
-struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id)
+struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,
+					 const struct fuse_backing_ops *ops,
+					 int backing_id)
 {
 	struct fuse_backing *fb;
 
 	rcu_read_lock();
 	fb = idr_find(&fc->backing_files_map, backing_id);
+	if (fb && fb->ops != ops)
+		fb = NULL;
 	fb = fuse_backing_get(fb);
 	rcu_read_unlock();
 
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index ac9d7a7b3f5e68..a3d762fd4d9a86 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2646,7 +2646,7 @@ static long fuse_dev_ioctl_backing_open(struct file *file,
 	if (IS_ERR(fud))
 		return PTR_ERR(fud);
 
-	if (!IS_ENABLED(CONFIG_FUSE_PASSTHROUGH))
+	if (!IS_ENABLED(CONFIG_FUSE_BACKING))
 		return -EOPNOTSUPP;
 
 	if (copy_from_user(&map, argp, sizeof(map)))
@@ -2663,7 +2663,7 @@ static long fuse_dev_ioctl_backing_close(struct file *file, __u32 __user *argp)
 	if (IS_ERR(fud))
 		return PTR_ERR(fud);
 
-	if (!IS_ENABLED(CONFIG_FUSE_PASSTHROUGH))
+	if (!IS_ENABLED(CONFIG_FUSE_BACKING))
 		return -EOPNOTSUPP;
 
 	if (get_user(backing_id, argp))
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index ff8b94cb02e63c..9012f4e8d68338 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1005,7 +1005,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
 	fc->name_max = FUSE_NAME_LOW_MAX;
 	fc->timeout.req_timeout = 0;
 
-	if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH))
+	if (IS_ENABLED(CONFIG_FUSE_BACKING))
 		fuse_backing_files_init(fc);
 
 	INIT_LIST_HEAD(&fc->mounts);
@@ -1045,7 +1045,7 @@ void fuse_conn_put(struct fuse_conn *fc)
 		WARN_ON(atomic_read(&bucket->count) != 1);
 		kfree(bucket);
 	}
-	if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH))
+	if (IS_ENABLED(CONFIG_FUSE_BACKING))
 		fuse_backing_files_free(fc);
 	call_rcu(&fc->rcu, delayed_release);
 }
diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c
index 72de97c03d0eeb..e1619bffb5d125 100644
--- a/fs/fuse/passthrough.c
+++ b/fs/fuse/passthrough.c
@@ -162,7 +162,7 @@ struct fuse_backing *fuse_passthrough_open(struct file *file, int backing_id)
 		goto out;
 
 	err = -ENOENT;
-	fb = fuse_backing_lookup(fc, backing_id);
+	fb = fuse_backing_lookup(fc, &fuse_passthrough_backing_ops, backing_id);
 	if (!fb)
 		goto out;
 
@@ -195,3 +195,39 @@ void fuse_passthrough_release(struct fuse_file *ff, struct fuse_backing *fb)
 	put_cred(ff->cred);
 	ff->cred = NULL;
 }
+
+static int fuse_passthrough_may_admin(struct fuse_conn *fc, unsigned int flags)
+{
+	/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */
+	if (!fc->passthrough || !capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (flags)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int fuse_passthrough_may_open(struct fuse_conn *fc, struct file *file)
+{
+	struct super_block *backing_sb;
+	int res;
+
+	/* read/write/splice/mmap passthrough only relevant for regular files */
+	res = d_is_dir(file->f_path.dentry) ? -EISDIR : -EINVAL;
+	if (!d_is_reg(file->f_path.dentry))
+		return res;
+
+	backing_sb = file_inode(file)->i_sb;
+	if (backing_sb->s_stack_depth >= fc->max_stack_depth)
+		return -ELOOP;
+
+	return 0;
+}
+
+const struct fuse_backing_ops fuse_passthrough_backing_ops = {
+	.type = FUSE_BACKING_TYPE_PASSTHROUGH,
+	.id_start = 1,
+	.may_admin = fuse_passthrough_may_admin,
+	.may_open = fuse_passthrough_may_open,
+};


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/2] fuse_trace: move the passthrough-specific code back to passthrough.c
  2026-02-23 23:01 ` [PATCHSET v7 3/9] fuse: cleanups ahead of adding fuse support Darrick J. Wong
  2026-02-23 23:08   ` [PATCH 1/2] fuse: move the passthrough-specific code back to passthrough.c Darrick J. Wong
@ 2026-02-23 23:08   ` Darrick J. Wong
  1 sibling, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:08 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, joannelkoong, bpf, bernd, neal, linux-fsdevel,
	linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/fuse_trace.h |   35 +++++++++++++++++++++++++++++++++++
 fs/fuse/backing.c    |    5 +++++
 2 files changed, 40 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index bbe9ddd8c71696..286a0845dc0898 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -124,6 +124,41 @@ TRACE_EVENT(fuse_request_end,
 		  __entry->unique, __entry->len, __entry->error)
 );
 
+#ifdef CONFIG_FUSE_BACKING
+TRACE_EVENT(fuse_backing_class,
+	TP_PROTO(const struct fuse_conn *fc, unsigned int idx,
+		 const struct fuse_backing *fb),
+
+	TP_ARGS(fc, idx, fb),
+
+	TP_STRUCT__entry(
+		__field(dev_t,			connection)
+		__field(unsigned int,		idx)
+		__field(unsigned long,		ino)
+	),
+
+	TP_fast_assign(
+		struct inode *inode = file_inode(fb->file);
+
+		__entry->connection	=	fc->dev;
+		__entry->idx		=	idx;
+		__entry->ino		=	inode->i_ino;
+	),
+
+	TP_printk("connection %u idx %u ino 0x%lx",
+		  __entry->connection,
+		  __entry->idx,
+		  __entry->ino)
+);
+#define DEFINE_FUSE_BACKING_EVENT(name)		\
+DEFINE_EVENT(fuse_backing_class, name,		\
+	TP_PROTO(const struct fuse_conn *fc, unsigned int idx, \
+		 const struct fuse_backing *fb), \
+	TP_ARGS(fc, idx, fb))
+DEFINE_FUSE_BACKING_EVENT(fuse_backing_open);
+DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
+#endif /* CONFIG_FUSE_BACKING */
+
 #endif /* _TRACE_FUSE_H */
 
 #undef TRACE_INCLUDE_PATH
diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
index adb4d2ebb21379..d7e074c30f46cc 100644
--- a/fs/fuse/backing.c
+++ b/fs/fuse/backing.c
@@ -72,6 +72,7 @@ static int fuse_backing_id_free(int id, void *p, void *data)
 
 	WARN_ON_ONCE(refcount_read(&fb->count) != 1);
 
+	trace_fuse_backing_close((struct fuse_conn *)data, id, fb);
 	fuse_backing_free(fb);
 	return 0;
 }
@@ -145,6 +146,8 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 		fb = NULL;
 		goto out;
 	}
+
+	trace_fuse_backing_open(fc, res, fb);
 out:
 	pr_debug("%s: fb=0x%p, ret=%i\n", __func__, fb, res);
 
@@ -194,6 +197,8 @@ int fuse_backing_close(struct fuse_conn *fc, int backing_id)
 	if (err)
 		goto out_fb;
 
+	trace_fuse_backing_close(fc, backing_id, fb);
+
 	err = -ENOENT;
 	test_fb = fuse_backing_id_remove(fc, backing_id);
 	if (!test_fb)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 01/33] fuse: implement the basic iomap mechanisms
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
@ 2026-02-23 23:08   ` Darrick J. Wong
  2026-02-23 23:09   ` [PATCH 02/33] fuse_trace: " Darrick J. Wong
                     ` (31 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:08 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Implement functions to enable upcalling of iomap_begin and iomap_end to
userspace fuse servers.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h          |    5 -
 fs/fuse/fuse_iomap.h      |   26 +++
 fs/fuse/fuse_iomap_i.h    |   28 +++
 include/uapi/linux/fuse.h |   91 +++++++++-
 fs/fuse/Kconfig           |   32 +++
 fs/fuse/Makefile          |    1 
 fs/fuse/fuse_iomap.c      |  430 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |    9 +
 8 files changed, 620 insertions(+), 2 deletions(-)
 create mode 100644 fs/fuse/fuse_iomap.h
 create mode 100644 fs/fuse/fuse_iomap_i.h
 create mode 100644 fs/fuse/fuse_iomap.c


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 3373252ccd1678..2d62b6365fa931 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -938,6 +938,9 @@ struct fuse_conn {
 	/* Is synchronous FUSE_INIT allowed? */
 	unsigned int sync_init:1;
 
+	/* Enable fs/iomap for file operations */
+	unsigned int iomap:1;
+
 	/* Use io_uring for communication */
 	unsigned int io_uring;
 
@@ -1059,7 +1062,7 @@ static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
 	return get_fuse_mount_super(sb)->fc;
 }
 
-static inline struct fuse_mount *get_fuse_mount(struct inode *inode)
+static inline struct fuse_mount *get_fuse_mount(const struct inode *inode)
 {
 	return get_fuse_mount_super(inode->i_sb);
 }
diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
new file mode 100644
index 00000000000000..6c71318365ca82
--- /dev/null
+++ b/fs/fuse/fuse_iomap.h
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#ifndef _FS_FUSE_IOMAP_H
+#define _FS_FUSE_IOMAP_H
+
+#if IS_ENABLED(CONFIG_FUSE_IOMAP)
+enum fuse_iomap_iodir {
+	READ_MAPPING,
+	WRITE_MAPPING,
+};
+
+bool fuse_iomap_enabled(void);
+
+static inline bool fuse_has_iomap(const struct inode *inode)
+{
+	return get_fuse_conn(inode)->iomap;
+}
+#else
+# define fuse_iomap_enabled(...)		(false)
+# define fuse_has_iomap(...)			(false)
+#endif /* CONFIG_FUSE_IOMAP */
+
+#endif /* _FS_FUSE_IOMAP_H */
diff --git a/fs/fuse/fuse_iomap_i.h b/fs/fuse/fuse_iomap_i.h
new file mode 100644
index 00000000000000..2897049637fad2
--- /dev/null
+++ b/fs/fuse/fuse_iomap_i.h
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#ifndef _FS_FUSE_IOMAP_I_H
+#define _FS_FUSE_IOMAP_I_H
+
+#if IS_ENABLED(CONFIG_FUSE_IOMAP)
+#if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG)
+# define ASSERT(condition) do {						\
+	int __cond = !!(condition);					\
+	WARN(!__cond, "Assertion failed: %s, func: %s, line: %d", #condition, __func__, __LINE__); \
+} while (0)
+# define BAD_DATA(condition) ({						\
+	int __cond = !!(condition);					\
+	WARN(__cond, "Bad mapping: %s, func: %s, line: %d", #condition, __func__, __LINE__); \
+})
+#else
+# define ASSERT(condition)
+# define BAD_DATA(condition) ({						\
+	int __cond = !!(condition);					\
+	unlikely(__cond);						\
+})
+#endif /* CONFIG_FUSE_IOMAP_DEBUG */
+#endif /* CONFIG_FUSE_IOMAP */
+
+#endif /* _FS_FUSE_IOMAP_I_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 18713cfaf09171..5a58011f66f501 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -240,6 +240,10 @@
  *  - add FUSE_COPY_FILE_RANGE_64
  *  - add struct fuse_copy_file_range_out
  *  - add FUSE_NOTIFY_PRUNE
+ *
+ *  7.99
+ *  - XXX magic minor revision to make experimental code really obvious
+ *  - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations
  */
 
 #ifndef _LINUX_FUSE_H
@@ -275,7 +279,7 @@
 #define FUSE_KERNEL_VERSION 7
 
 /** Minor version number of this interface */
-#define FUSE_KERNEL_MINOR_VERSION 45
+#define FUSE_KERNEL_MINOR_VERSION 99
 
 /** The node ID of the root inode */
 #define FUSE_ROOT_ID 1
@@ -448,6 +452,7 @@ struct fuse_file_lock {
  * FUSE_OVER_IO_URING: Indicate that client supports io-uring
  * FUSE_REQUEST_TIMEOUT: kernel supports timing out requests.
  *			 init_out.request_timeout contains the timeout (in secs)
+ * FUSE_IOMAP: Client supports iomap for regular file operations.
  */
 #define FUSE_ASYNC_READ		(1 << 0)
 #define FUSE_POSIX_LOCKS	(1 << 1)
@@ -495,6 +500,7 @@ struct fuse_file_lock {
 #define FUSE_ALLOW_IDMAP	(1ULL << 40)
 #define FUSE_OVER_IO_URING	(1ULL << 41)
 #define FUSE_REQUEST_TIMEOUT	(1ULL << 42)
+#define FUSE_IOMAP		(1ULL << 43)
 
 /**
  * CUSE INIT request/reply flags
@@ -664,6 +670,9 @@ enum fuse_opcode {
 	FUSE_STATX		= 52,
 	FUSE_COPY_FILE_RANGE_64	= 53,
 
+	FUSE_IOMAP_BEGIN	= 4094,
+	FUSE_IOMAP_END		= 4095,
+
 	/* CUSE specific operations */
 	CUSE_INIT		= 4096,
 
@@ -1314,4 +1323,84 @@ struct fuse_uring_cmd_req {
 	uint8_t padding[6];
 };
 
+/* mapping types; see corresponding IOMAP_TYPE_ */
+#define FUSE_IOMAP_TYPE_HOLE		(0)
+#define FUSE_IOMAP_TYPE_DELALLOC	(1)
+#define FUSE_IOMAP_TYPE_MAPPED		(2)
+#define FUSE_IOMAP_TYPE_UNWRITTEN	(3)
+#define FUSE_IOMAP_TYPE_INLINE		(4)
+
+/* fuse-specific mapping type indicating that writes use the read mapping */
+#define FUSE_IOMAP_TYPE_PURE_OVERWRITE	(255)
+
+#define FUSE_IOMAP_DEV_NULL		(0U)	/* null device cookie */
+
+/* mapping flags passed back from iomap_begin; see corresponding IOMAP_F_ */
+#define FUSE_IOMAP_F_NEW		(1U << 0)
+#define FUSE_IOMAP_F_DIRTY		(1U << 1)
+#define FUSE_IOMAP_F_SHARED		(1U << 2)
+#define FUSE_IOMAP_F_MERGED		(1U << 3)
+#define FUSE_IOMAP_F_BOUNDARY		(1U << 4)
+#define FUSE_IOMAP_F_ANON_WRITE		(1U << 5)
+#define FUSE_IOMAP_F_ATOMIC_BIO		(1U << 6)
+
+/* fuse-specific mapping flag asking for ->iomap_end call */
+#define FUSE_IOMAP_F_WANT_IOMAP_END	(1U << 7)
+
+/* mapping flags passed to iomap_end */
+#define FUSE_IOMAP_F_SIZE_CHANGED	(1U << 8)
+#define FUSE_IOMAP_F_STALE		(1U << 9)
+
+/* operation flags from iomap; see corresponding IOMAP_* */
+#define FUSE_IOMAP_OP_WRITE		(1U << 0)
+#define FUSE_IOMAP_OP_ZERO		(1U << 1)
+#define FUSE_IOMAP_OP_REPORT		(1U << 2)
+#define FUSE_IOMAP_OP_FAULT		(1U << 3)
+#define FUSE_IOMAP_OP_DIRECT		(1U << 4)
+#define FUSE_IOMAP_OP_NOWAIT		(1U << 5)
+#define FUSE_IOMAP_OP_OVERWRITE_ONLY	(1U << 6)
+#define FUSE_IOMAP_OP_UNSHARE		(1U << 7)
+#define FUSE_IOMAP_OP_DAX		(1U << 8)
+#define FUSE_IOMAP_OP_ATOMIC		(1U << 9)
+#define FUSE_IOMAP_OP_DONTCACHE		(1U << 10)
+
+#define FUSE_IOMAP_NULL_ADDR		(-1ULL)	/* addr is not valid */
+
+struct fuse_iomap_io {
+	uint64_t offset;	/* file offset of mapping, bytes */
+	uint64_t length;	/* length of mapping, bytes */
+	uint64_t addr;		/* disk offset of mapping, bytes */
+	uint16_t type;		/* FUSE_IOMAP_TYPE_* */
+	uint16_t flags;		/* FUSE_IOMAP_F_* */
+	uint32_t dev;		/* device cookie */
+};
+
+struct fuse_iomap_begin_in {
+	uint32_t opflags;	/* FUSE_IOMAP_OP_* */
+	uint32_t reserved;	/* zero */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+	uint64_t pos;		/* file position, in bytes */
+	uint64_t count;		/* operation length, in bytes */
+};
+
+struct fuse_iomap_begin_out {
+	/* read file data from here */
+	struct fuse_iomap_io	read;
+
+	/* write file data to here, if applicable */
+	struct fuse_iomap_io	write;
+};
+
+struct fuse_iomap_end_in {
+	uint32_t opflags;	/* FUSE_IOMAP_OP_* */
+	uint32_t reserved;	/* zero */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+	uint64_t pos;		/* file position, in bytes */
+	uint64_t count;		/* operation length, in bytes */
+	int64_t written;	/* bytes processed */
+
+	/* mapping that the kernel acted upon */
+	struct fuse_iomap_io	map;
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/fs/fuse/Kconfig b/fs/fuse/Kconfig
index 290d1c09e0b924..934d48076a010c 100644
--- a/fs/fuse/Kconfig
+++ b/fs/fuse/Kconfig
@@ -69,6 +69,38 @@ config FUSE_PASSTHROUGH
 config FUSE_BACKING
 	bool
 
+config FUSE_IOMAP
+	bool "FUSE file IO over iomap"
+	default y
+	depends on FUSE_FS
+	depends on BLOCK
+	select FS_IOMAP
+	help
+	  Enable fuse servers to operate the regular file I/O path through
+	  the fs-iomap library in the kernel.  This enables higher performance
+	  userspace filesystems by keeping the performance critical parts in
+	  the kernel while delegating the difficult metadata parsing parts to
+	  an easily-contained userspace program.
+
+	  This feature is considered EXPERIMENTAL.  Use with caution!
+
+	  If unsure, say N.
+
+config FUSE_IOMAP_BY_DEFAULT
+	bool "FUSE file I/O over iomap by default"
+	default n
+	depends on FUSE_IOMAP
+	help
+	  Enable sending FUSE file I/O over iomap by default.
+
+config FUSE_IOMAP_DEBUG
+	bool "Debug FUSE file IO over iomap"
+	default y
+	depends on FUSE_IOMAP
+	help
+	  Enable debugging assertions for the fuse iomap code paths and logging
+	  of bad iomap file mapping data being sent to the kernel.
+
 config FUSE_IO_URING
 	bool "FUSE communication over io-uring"
 	default y
diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile
index 46041228e5be2c..2536bc6a71b898 100644
--- a/fs/fuse/Makefile
+++ b/fs/fuse/Makefile
@@ -18,5 +18,6 @@ fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o
 fuse-$(CONFIG_FUSE_BACKING) += backing.o
 fuse-$(CONFIG_SYSCTL) += sysctl.o
 fuse-$(CONFIG_FUSE_IO_URING) += dev_uring.o
+fuse-$(CONFIG_FUSE_IOMAP) += fuse_iomap.o
 
 virtiofs-y := virtio_fs.o
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
new file mode 100644
index 00000000000000..8785f86941a1d2
--- /dev/null
+++ b/fs/fuse/fuse_iomap.c
@@ -0,0 +1,430 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#include <linux/iomap.h>
+#include "fuse_i.h"
+#include "fuse_trace.h"
+#include "fuse_iomap.h"
+#include "fuse_iomap_i.h"
+
+static bool __read_mostly enable_iomap =
+#if IS_ENABLED(CONFIG_FUSE_IOMAP_BY_DEFAULT)
+	true;
+#else
+	false;
+#endif
+module_param(enable_iomap, bool, 0644);
+MODULE_PARM_DESC(enable_iomap, "Enable file I/O through iomap");
+
+bool fuse_iomap_enabled(void)
+{
+	/* Don't let anyone touch iomap until the end of the patchset. */
+	return false;
+
+	/*
+	 * There are fears that a fuse+iomap server could somehow DoS the
+	 * system by doing things like going out to lunch during a writeback
+	 * related iomap request.  Only allow iomap access if the fuse server
+	 * has rawio capabilities since those processes can mess things up
+	 * quite well even without our help.
+	 */
+	return enable_iomap && has_capability_noaudit(current, CAP_SYS_RAWIO);
+}
+
+/* Convert IOMAP_* mapping types to FUSE_IOMAP_TYPE_* */
+#define XMAP(word) \
+	case IOMAP_##word: \
+		return FUSE_IOMAP_TYPE_##word
+static inline uint16_t fuse_iomap_type_to_server(uint16_t iomap_type)
+{
+	switch (iomap_type) {
+	XMAP(HOLE);
+	XMAP(DELALLOC);
+	XMAP(MAPPED);
+	XMAP(UNWRITTEN);
+	XMAP(INLINE);
+	default:
+		ASSERT(0);
+	}
+	return 0;
+}
+#undef XMAP
+
+/* Convert FUSE_IOMAP_TYPE_* to IOMAP_* mapping types */
+#define XMAP(word) \
+	case FUSE_IOMAP_TYPE_##word: \
+		return IOMAP_##word
+static inline uint16_t fuse_iomap_type_from_server(uint16_t fuse_type)
+{
+	switch (fuse_type) {
+	XMAP(HOLE);
+	XMAP(DELALLOC);
+	XMAP(MAPPED);
+	XMAP(UNWRITTEN);
+	XMAP(INLINE);
+	default:
+		ASSERT(0);
+	}
+	return 0;
+}
+#undef XMAP
+
+/* Validate FUSE_IOMAP_TYPE_* */
+static inline bool fuse_iomap_check_type(uint16_t fuse_type)
+{
+	switch (fuse_type) {
+	case FUSE_IOMAP_TYPE_HOLE:
+	case FUSE_IOMAP_TYPE_DELALLOC:
+	case FUSE_IOMAP_TYPE_MAPPED:
+	case FUSE_IOMAP_TYPE_UNWRITTEN:
+	case FUSE_IOMAP_TYPE_INLINE:
+	case FUSE_IOMAP_TYPE_PURE_OVERWRITE:
+		return true;
+	}
+
+	return false;
+}
+
+#define FUSE_IOMAP_F_ALL (FUSE_IOMAP_F_NEW | \
+			  FUSE_IOMAP_F_DIRTY | \
+			  FUSE_IOMAP_F_SHARED | \
+			  FUSE_IOMAP_F_MERGED | \
+			  FUSE_IOMAP_F_BOUNDARY | \
+			  FUSE_IOMAP_F_ANON_WRITE | \
+			  FUSE_IOMAP_F_ATOMIC_BIO | \
+			  FUSE_IOMAP_F_WANT_IOMAP_END)
+
+static inline bool fuse_iomap_check_flags(uint16_t flags)
+{
+	return (flags & ~FUSE_IOMAP_F_ALL) == 0;
+}
+
+/* Convert IOMAP_F_* mapping state flags to FUSE_IOMAP_F_* */
+#define XMAP(word) \
+	if (iomap_f_flags & IOMAP_F_##word) \
+		ret |= FUSE_IOMAP_F_##word
+#define XMAP2(iword, oword) \
+	if (iomap_f_flags & IOMAP_F_##iword) \
+		ret |= FUSE_IOMAP_F_##oword
+static inline uint16_t fuse_iomap_flags_to_server(uint16_t iomap_f_flags)
+{
+	uint16_t ret = 0;
+
+	XMAP(NEW);
+	XMAP(DIRTY);
+	XMAP(SHARED);
+	XMAP(MERGED);
+	XMAP(BOUNDARY);
+	XMAP(ANON_WRITE);
+	XMAP(ATOMIC_BIO);
+	XMAP2(PRIVATE, WANT_IOMAP_END);
+
+	XMAP(SIZE_CHANGED);
+	XMAP(STALE);
+
+	return ret;
+}
+#undef XMAP2
+#undef XMAP
+
+/* Convert FUSE_IOMAP_F_* to IOMAP_F_* mapping state flags */
+#define XMAP(word) \
+	if (fuse_f_flags & FUSE_IOMAP_F_##word) \
+		ret |= IOMAP_F_##word
+#define XMAP2(iword, oword) \
+	if (fuse_f_flags & FUSE_IOMAP_F_##iword) \
+		ret |= IOMAP_F_##oword
+static inline uint16_t fuse_iomap_flags_from_server(uint16_t fuse_f_flags)
+{
+	uint16_t ret = 0;
+
+	XMAP(NEW);
+	XMAP(DIRTY);
+	XMAP(SHARED);
+	XMAP(MERGED);
+	XMAP(BOUNDARY);
+	XMAP(ANON_WRITE);
+	XMAP(ATOMIC_BIO);
+	XMAP2(WANT_IOMAP_END, PRIVATE);
+
+	return ret;
+}
+#undef XMAP2
+#undef XMAP
+
+/* Convert IOMAP_* operation flags to FUSE_IOMAP_OP_* */
+#define XMAP(word) \
+	if (iomap_op_flags & IOMAP_##word) \
+		ret |= FUSE_IOMAP_OP_##word
+static inline uint32_t fuse_iomap_op_to_server(unsigned iomap_op_flags)
+{
+	uint32_t ret = 0;
+
+	XMAP(WRITE);
+	XMAP(ZERO);
+	XMAP(REPORT);
+	XMAP(FAULT);
+	XMAP(DIRECT);
+	XMAP(NOWAIT);
+	XMAP(OVERWRITE_ONLY);
+	XMAP(UNSHARE);
+	XMAP(DAX);
+	XMAP(ATOMIC);
+	XMAP(DONTCACHE);
+
+	return ret;
+}
+#undef XMAP
+
+/* Validate an iomap mapping. */
+static inline bool fuse_iomap_check_mapping(const struct inode *inode,
+					    const struct fuse_iomap_io *map,
+					    enum fuse_iomap_iodir iodir)
+{
+	const unsigned int blocksize = i_blocksize(inode);
+	uint64_t end;
+
+	/* Type and flags must be known */
+	if (BAD_DATA(!fuse_iomap_check_type(map->type)))
+		return false;
+	if (BAD_DATA(!fuse_iomap_check_flags(map->flags)))
+		return false;
+
+	/* No zero-length mappings */
+	if (BAD_DATA(map->length == 0))
+		return false;
+
+	/* File range must be aligned to blocksize */
+	if (BAD_DATA(!IS_ALIGNED(map->offset, blocksize)))
+		return false;
+	if (BAD_DATA(!IS_ALIGNED(map->length, blocksize)))
+		return false;
+
+	/* No overflows in the file range */
+	if (BAD_DATA(check_add_overflow(map->offset, map->length, &end)))
+		return false;
+
+	/* File range cannot start past maxbytes */
+	if (BAD_DATA(map->offset >= inode->i_sb->s_maxbytes))
+		return false;
+
+	switch (map->type) {
+	case FUSE_IOMAP_TYPE_MAPPED:
+	case FUSE_IOMAP_TYPE_UNWRITTEN:
+		/* Mappings backed by space must have a device/addr */
+		if (BAD_DATA(map->dev == FUSE_IOMAP_DEV_NULL))
+			return false;
+		if (BAD_DATA(map->addr == FUSE_IOMAP_NULL_ADDR))
+			return false;
+		break;
+	case FUSE_IOMAP_TYPE_DELALLOC:
+	case FUSE_IOMAP_TYPE_HOLE:
+	case FUSE_IOMAP_TYPE_INLINE:
+		/* Mappings not backed by space cannot have a device addr. */
+		if (BAD_DATA(map->dev != FUSE_IOMAP_DEV_NULL))
+			return false;
+		if (BAD_DATA(map->addr != FUSE_IOMAP_NULL_ADDR))
+			return false;
+		break;
+	case FUSE_IOMAP_TYPE_PURE_OVERWRITE:
+		/* "Pure overwrite" only allowed for write mapping */
+		if (BAD_DATA(iodir != WRITE_MAPPING))
+			return false;
+		break;
+	default:
+		/* should have been caught already */
+		ASSERT(0);
+		return false;
+	}
+
+	/* XXX: we don't support devices yet */
+	if (BAD_DATA(map->dev != FUSE_IOMAP_DEV_NULL))
+		return false;
+
+	/* No overflows in the device range, if supplied */
+	if (map->addr != FUSE_IOMAP_NULL_ADDR &&
+	    BAD_DATA(check_add_overflow(map->addr, map->length, &end)))
+		return false;
+
+	return true;
+}
+
+/* Convert a mapping from the server into something the kernel can use */
+static inline void fuse_iomap_from_server(struct iomap *iomap,
+					  const struct fuse_iomap_io *fmap)
+{
+	iomap->addr = fmap->addr;
+	iomap->offset = fmap->offset;
+	iomap->length = fmap->length;
+	iomap->type = fuse_iomap_type_from_server(fmap->type);
+	iomap->flags = fuse_iomap_flags_from_server(fmap->flags);
+	iomap->bdev = NULL; /* XXX */
+}
+
+/* Convert a mapping from the kernel into something the server can use */
+static inline void fuse_iomap_to_server(struct fuse_iomap_io *fmap,
+					const struct iomap *iomap)
+{
+	fmap->addr = iomap->addr;
+	fmap->offset = iomap->offset;
+	fmap->length = iomap->length;
+	fmap->type = fuse_iomap_type_to_server(iomap->type);
+	fmap->flags = fuse_iomap_flags_to_server(iomap->flags);
+	fmap->dev = FUSE_IOMAP_DEV_NULL; /* XXX */
+}
+
+/* Check the incoming _begin mappings to make sure they're not nonsense. */
+static inline int
+fuse_iomap_begin_validate(const struct inode *inode,
+			  unsigned opflags, loff_t pos,
+			  const struct fuse_iomap_begin_out *outarg)
+{
+	/* Make sure the mappings aren't garbage */
+	if (!fuse_iomap_check_mapping(inode, &outarg->read, READ_MAPPING))
+		return -EFSCORRUPTED;
+
+	if (!fuse_iomap_check_mapping(inode, &outarg->write, WRITE_MAPPING))
+		return -EFSCORRUPTED;
+
+	/*
+	 * Must have returned a mapping for at least the first byte in the
+	 * range.  The main mapping check already validated that the length
+	 * is nonzero and there is no overflow in computing end.
+	 */
+	if (BAD_DATA(outarg->read.offset > pos))
+		return -EFSCORRUPTED;
+	if (BAD_DATA(outarg->write.offset > pos))
+		return -EFSCORRUPTED;
+
+	if (BAD_DATA(outarg->read.offset + outarg->read.length <= pos))
+		return -EFSCORRUPTED;
+	if (BAD_DATA(outarg->write.offset + outarg->write.length <= pos))
+		return -EFSCORRUPTED;
+
+	return 0;
+}
+
+static inline bool fuse_is_iomap_file_write(unsigned int opflags)
+{
+	return opflags & (IOMAP_WRITE | IOMAP_ZERO | IOMAP_UNSHARE);
+}
+
+static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
+			    unsigned opflags, struct iomap *iomap,
+			    struct iomap *srcmap)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_iomap_begin_in inarg = {
+		.attr_ino = fi->orig_ino,
+		.opflags = fuse_iomap_op_to_server(opflags),
+		.pos = pos,
+		.count = count,
+	};
+	struct fuse_iomap_begin_out outarg = { };
+	struct fuse_mount *fm = get_fuse_mount(inode);
+	FUSE_ARGS(args);
+	int err;
+
+	args.opcode = FUSE_IOMAP_BEGIN;
+	args.nodeid = get_node_id(inode);
+	args.in_numargs = 1;
+	args.in_args[0].size = sizeof(inarg);
+	args.in_args[0].value = &inarg;
+	args.out_numargs = 1;
+	args.out_args[0].size = sizeof(outarg);
+	args.out_args[0].value = &outarg;
+	err = fuse_simple_request(fm, &args);
+	if (err)
+		return err;
+
+	err = fuse_iomap_begin_validate(inode, opflags, pos, &outarg);
+	if (err)
+		return err;
+
+	if (fuse_is_iomap_file_write(opflags) &&
+	    outarg.write.type != FUSE_IOMAP_TYPE_PURE_OVERWRITE) {
+		/*
+		 * For an out of place write, we must supply the write mapping
+		 * via @iomap, and the read mapping via @srcmap.
+		 */
+		fuse_iomap_from_server(iomap, &outarg.write);
+		fuse_iomap_from_server(srcmap, &outarg.read);
+	} else {
+		/*
+		 * For everything else (reads, reporting, and pure overwrites),
+		 * we can return the sole mapping through @iomap and leave
+		 * @srcmap unchanged from its default (HOLE).
+		 */
+		fuse_iomap_from_server(iomap, &outarg.read);
+	}
+
+	return 0;
+}
+
+/* Decide if we send FUSE_IOMAP_END to the fuse server */
+static bool fuse_should_send_iomap_end(const struct iomap *iomap,
+				       unsigned int opflags, loff_t count,
+				       ssize_t written)
+{
+	/* fuse server demanded an iomap_end call. */
+	if (iomap->flags & FUSE_IOMAP_F_WANT_IOMAP_END)
+		return true;
+
+	/* Reads and reporting should never affect the filesystem metadata */
+	if (!fuse_is_iomap_file_write(opflags))
+		return false;
+
+	/* Appending writes get an iomap_end call */
+	if (iomap->flags & IOMAP_F_SIZE_CHANGED)
+		return true;
+
+	/* Short writes get an iomap_end call to clean up delalloc */
+	return written < count;
+}
+
+static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
+			  ssize_t written, unsigned opflags,
+			  struct iomap *iomap)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_mount *fm = get_fuse_mount(inode);
+	int err;
+
+	if (fuse_should_send_iomap_end(iomap, opflags, count, written)) {
+		struct fuse_iomap_end_in inarg = {
+			.opflags = fuse_iomap_op_to_server(opflags),
+			.attr_ino = fi->orig_ino,
+			.pos = pos,
+			.count = count,
+			.written = written,
+		};
+		FUSE_ARGS(args);
+
+		fuse_iomap_to_server(&inarg.map, iomap);
+
+		args.opcode = FUSE_IOMAP_END;
+		args.nodeid = get_node_id(inode);
+		args.in_numargs = 1;
+		args.in_args[0].size = sizeof(inarg);
+		args.in_args[0].value = &inarg;
+		err = fuse_simple_request(fm, &args);
+		if (err == -ENOSYS) {
+			/*
+			 * libfuse returns ENOSYS for servers that don't
+			 * implement iomap_end
+			 */
+			err = 0;
+		}
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+const struct iomap_ops fuse_iomap_ops = {
+	.iomap_begin		= fuse_iomap_begin,
+	.iomap_end		= fuse_iomap_end,
+};
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 9012f4e8d68338..8f01844f89b261 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -9,6 +9,7 @@
 #include "fuse_i.h"
 #include "fuse_dev_i.h"
 #include "dev_uring_i.h"
+#include "fuse_iomap.h"
 
 #include <linux/dax.h>
 #include <linux/pagemap.h>
@@ -1460,6 +1461,12 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 
 			if (flags & FUSE_REQUEST_TIMEOUT)
 				timeout = arg->request_timeout;
+
+			if ((flags & FUSE_IOMAP) && fuse_iomap_enabled()) {
+				fc->iomap = 1;
+				pr_warn(
+ "EXPERIMENTAL iomap feature enabled.  Use at your own risk!");
+			}
 		} else {
 			ra_pages = fc->max_read / PAGE_SIZE;
 			fc->no_lock = 1;
@@ -1528,6 +1535,8 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)
 	 */
 	if (fuse_uring_enabled())
 		flags |= FUSE_OVER_IO_URING;
+	if (fuse_iomap_enabled())
+		flags |= FUSE_IOMAP;
 
 	ia->in.flags = flags;
 	ia->in.flags2 = flags >> 32;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 02/33] fuse_trace: implement the basic iomap mechanisms
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
  2026-02-23 23:08   ` [PATCH 01/33] fuse: implement the basic iomap mechanisms Darrick J. Wong
@ 2026-02-23 23:09   ` Darrick J. Wong
  2026-02-23 23:09   ` [PATCH 03/33] fuse: make debugging configurable at runtime Darrick J. Wong
                     ` (30 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:09 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap_i.h |    6 +
 fs/fuse/fuse_trace.h   |  295 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c   |   15 ++
 3 files changed, 314 insertions(+), 2 deletions(-)


diff --git a/fs/fuse/fuse_iomap_i.h b/fs/fuse/fuse_iomap_i.h
index 2897049637fad2..b9ab8ce140e8e1 100644
--- a/fs/fuse/fuse_iomap_i.h
+++ b/fs/fuse/fuse_iomap_i.h
@@ -10,16 +10,22 @@
 #if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG)
 # define ASSERT(condition) do {						\
 	int __cond = !!(condition);					\
+	if (unlikely(!__cond))						\
+		trace_fuse_iomap_assert(__func__, __LINE__, #condition); \
 	WARN(!__cond, "Assertion failed: %s, func: %s, line: %d", #condition, __func__, __LINE__); \
 } while (0)
 # define BAD_DATA(condition) ({						\
 	int __cond = !!(condition);					\
+	if (unlikely(__cond))						\
+		trace_fuse_iomap_bad_data(__func__, __LINE__, #condition); \
 	WARN(__cond, "Bad mapping: %s, func: %s, line: %d", #condition, __func__, __LINE__); \
 })
 #else
 # define ASSERT(condition)
 # define BAD_DATA(condition) ({						\
 	int __cond = !!(condition);					\
+	if (unlikely(__cond))						\
+		trace_fuse_iomap_bad_data(__func__, __LINE__, #condition); \
 	unlikely(__cond);						\
 })
 #endif /* CONFIG_FUSE_IOMAP_DEBUG */
diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 286a0845dc0898..c0878253e7c6ad 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -58,6 +58,8 @@
 	EM( FUSE_SYNCFS,		"FUSE_SYNCFS")		\
 	EM( FUSE_TMPFILE,		"FUSE_TMPFILE")		\
 	EM( FUSE_STATX,			"FUSE_STATX")		\
+	EM( FUSE_IOMAP_BEGIN,		"FUSE_IOMAP_BEGIN")	\
+	EM( FUSE_IOMAP_END,		"FUSE_IOMAP_END")	\
 	EMe(CUSE_INIT,			"CUSE_INIT")
 
 /*
@@ -77,6 +79,54 @@ OPCODES
 #define EM(a, b)	{a, b},
 #define EMe(a, b)	{a, b}
 
+/* tracepoint boilerplate so we don't have to keep doing this */
+#define FUSE_INODE_FIELDS \
+		__field(dev_t,			connection) \
+		__field(uint64_t,		ino) \
+		__field(uint64_t,		nodeid) \
+		__field(loff_t,			isize)
+
+#define FUSE_INODE_ASSIGN(inode, fi, fm) \
+		const struct fuse_inode *fi = get_fuse_inode(inode); \
+		const struct fuse_mount *fm = get_fuse_mount(inode); \
+\
+		__entry->connection	=	(fm)->fc->dev; \
+		__entry->ino		=	(fi)->orig_ino; \
+		__entry->nodeid		=	(fi)->nodeid; \
+		__entry->isize		=	i_size_read(inode)
+
+#define FUSE_INODE_FMT \
+		"connection %u ino %llu nodeid %llu isize 0x%llx"
+
+#define FUSE_INODE_PRINTK_ARGS \
+		__entry->connection, \
+		__entry->ino, \
+		__entry->nodeid, \
+		__entry->isize
+
+#define FUSE_FILE_RANGE_FIELDS(prefix) \
+		__field(loff_t,			prefix##offset) \
+		__field(loff_t,			prefix##length)
+
+#define FUSE_FILE_RANGE_FMT(prefix) \
+		" " prefix "pos 0x%llx length 0x%llx"
+
+#define FUSE_FILE_RANGE_PRINTK_ARGS(prefix) \
+		__entry->prefix##offset, \
+		__entry->prefix##length
+
+/* combinations of boilerplate to reduce typing further */
+#define FUSE_IO_RANGE_FIELDS(prefix) \
+		FUSE_INODE_FIELDS \
+		FUSE_FILE_RANGE_FIELDS(prefix)
+
+#define FUSE_IO_RANGE_FMT(prefix) \
+		FUSE_INODE_FMT FUSE_FILE_RANGE_FMT(prefix)
+
+#define FUSE_IO_RANGE_PRINTK_ARGS(prefix) \
+		FUSE_INODE_PRINTK_ARGS, \
+		FUSE_FILE_RANGE_PRINTK_ARGS(prefix)
+
 TRACE_EVENT(fuse_request_send,
 	TP_PROTO(const struct fuse_req *req),
 
@@ -159,6 +209,251 @@ DEFINE_FUSE_BACKING_EVENT(fuse_backing_open);
 DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
 #endif /* CONFIG_FUSE_BACKING */
 
+#if IS_ENABLED(CONFIG_FUSE_IOMAP)
+
+/* tracepoint boilerplate so we don't have to keep doing this */
+#define FUSE_IOMAP_OPFLAGS_FIELD \
+		__field(unsigned,		opflags)
+
+#define FUSE_IOMAP_OPFLAGS_FMT \
+		" opflags (%s)"
+
+#define FUSE_IOMAP_OPFLAGS_PRINTK_ARG \
+		__print_flags(__entry->opflags, "|", FUSE_IOMAP_OP_STRINGS)
+
+#define FUSE_IOMAP_MAP_FIELDS(prefix) \
+		__field(uint64_t,		prefix##offset) \
+		__field(uint64_t,		prefix##length) \
+		__field(uint64_t,		prefix##addr) \
+		__field(uint32_t,		prefix##dev) \
+		__field(uint16_t,		prefix##type) \
+		__field(uint16_t,		prefix##flags)
+
+#define FUSE_IOMAP_MAP_FMT(prefix) \
+		" " prefix "offset 0x%llx length 0x%llx type %s dev %u addr 0x%llx mapflags (%s)"
+
+#define FUSE_IOMAP_MAP_PRINTK_ARGS(prefix) \
+		__entry->prefix##offset, \
+		__entry->prefix##length, \
+		__print_symbolic(__entry->prefix##type, FUSE_IOMAP_TYPE_STRINGS), \
+		__entry->prefix##dev, \
+		__entry->prefix##addr, \
+		__print_flags(__entry->prefix##flags, "|", FUSE_IOMAP_F_STRINGS)
+
+/* combinations of boilerplate to reduce typing further */
+#define FUSE_IOMAP_OP_FIELDS(prefix) \
+		FUSE_INODE_FIELDS \
+		FUSE_IOMAP_OPFLAGS_FIELD \
+		FUSE_FILE_RANGE_FIELDS(prefix)
+
+#define FUSE_IOMAP_OP_FMT(prefix) \
+		FUSE_INODE_FMT FUSE_IOMAP_OPFLAGS_FMT FUSE_FILE_RANGE_FMT(prefix)
+
+#define FUSE_IOMAP_OP_PRINTK_ARGS(prefix) \
+		FUSE_INODE_PRINTK_ARGS, \
+		FUSE_IOMAP_OPFLAGS_PRINTK_ARG, \
+		FUSE_FILE_RANGE_PRINTK_ARGS(prefix)
+
+/* string decoding */
+#define FUSE_IOMAP_F_STRINGS \
+	{ FUSE_IOMAP_F_NEW,			"new" }, \
+	{ FUSE_IOMAP_F_DIRTY,			"dirty" }, \
+	{ FUSE_IOMAP_F_SHARED,			"shared" }, \
+	{ FUSE_IOMAP_F_MERGED,			"merged" }, \
+	{ FUSE_IOMAP_F_BOUNDARY,		"boundary" }, \
+	{ FUSE_IOMAP_F_ANON_WRITE,		"anon_write" }, \
+	{ FUSE_IOMAP_F_ATOMIC_BIO,		"atomic" }, \
+	{ FUSE_IOMAP_F_WANT_IOMAP_END,		"iomap_end" }, \
+	{ FUSE_IOMAP_F_SIZE_CHANGED,		"append" }, \
+	{ FUSE_IOMAP_F_STALE,			"stale" }
+
+#define FUSE_IOMAP_OP_STRINGS \
+	{ FUSE_IOMAP_OP_WRITE,			"write" }, \
+	{ FUSE_IOMAP_OP_ZERO,			"zero" }, \
+	{ FUSE_IOMAP_OP_REPORT,			"report" }, \
+	{ FUSE_IOMAP_OP_FAULT,			"fault" }, \
+	{ FUSE_IOMAP_OP_DIRECT,			"direct" }, \
+	{ FUSE_IOMAP_OP_NOWAIT,			"nowait" }, \
+	{ FUSE_IOMAP_OP_OVERWRITE_ONLY,		"overwrite" }, \
+	{ FUSE_IOMAP_OP_UNSHARE,		"unshare" }, \
+	{ FUSE_IOMAP_OP_DAX,			"fsdax" }, \
+	{ FUSE_IOMAP_OP_ATOMIC,			"atomic" }, \
+	{ FUSE_IOMAP_OP_DONTCACHE,		"dontcache" }
+
+#define FUSE_IOMAP_TYPE_STRINGS \
+	{ FUSE_IOMAP_TYPE_PURE_OVERWRITE,	"overwrite" }, \
+	{ FUSE_IOMAP_TYPE_HOLE,			"hole" }, \
+	{ FUSE_IOMAP_TYPE_DELALLOC,		"delalloc" }, \
+	{ FUSE_IOMAP_TYPE_MAPPED,		"mapped" }, \
+	{ FUSE_IOMAP_TYPE_UNWRITTEN,		"unwritten" }, \
+	{ FUSE_IOMAP_TYPE_INLINE,		"inline" }
+
+DECLARE_EVENT_CLASS(fuse_iomap_check_class,
+	TP_PROTO(const char *func, int line, const char *condition),
+
+	TP_ARGS(func, line, condition),
+
+	TP_STRUCT__entry(
+		__string(func,			func)
+		__field(int,			line)
+		__string(condition,		condition)
+	),
+
+	TP_fast_assign(
+		__assign_str(func);
+		__assign_str(condition);
+		__entry->line		=	line;
+	),
+
+	TP_printk("func %s line %d condition %s", __get_str(func),
+		  __entry->line, __get_str(condition))
+);
+#define DEFINE_FUSE_IOMAP_CHECK_EVENT(name)	\
+DEFINE_EVENT(fuse_iomap_check_class, name,	\
+	TP_PROTO(const char *func, int line, const char *condition), \
+	TP_ARGS(func, line, condition))
+#if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG)
+DEFINE_FUSE_IOMAP_CHECK_EVENT(fuse_iomap_assert);
+#endif
+DEFINE_FUSE_IOMAP_CHECK_EVENT(fuse_iomap_bad_data);
+
+TRACE_EVENT(fuse_iomap_begin,
+	TP_PROTO(const struct inode *inode, loff_t pos, loff_t count,
+		 unsigned opflags),
+
+	TP_ARGS(inode, pos, count, opflags),
+
+	TP_STRUCT__entry(
+		FUSE_IOMAP_OP_FIELDS()
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	pos;
+		__entry->length		=	count;
+		__entry->opflags	=	opflags;
+	),
+
+	TP_printk(FUSE_IOMAP_OP_FMT(),
+		  FUSE_IOMAP_OP_PRINTK_ARGS())
+);
+
+TRACE_EVENT(fuse_iomap_begin_error,
+	TP_PROTO(const struct inode *inode, loff_t pos, loff_t count,
+		 unsigned opflags, int error),
+
+	TP_ARGS(inode, pos, count, opflags, error),
+
+	TP_STRUCT__entry(
+		FUSE_IOMAP_OP_FIELDS()
+		__field(int,			error)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	pos;
+		__entry->length		=	count;
+		__entry->opflags	=	opflags;
+		__entry->error		=	error;
+	),
+
+	TP_printk(FUSE_IOMAP_OP_FMT() " err %d",
+		  FUSE_IOMAP_OP_PRINTK_ARGS(),
+		  __entry->error)
+);
+
+DECLARE_EVENT_CLASS(fuse_iomap_mapping_class,
+	TP_PROTO(const struct inode *inode, const struct fuse_iomap_io *map),
+
+	TP_ARGS(inode, map),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		FUSE_IOMAP_MAP_FIELDS(map)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->mapoffset	=	map->offset;
+		__entry->maplength	=	map->length;
+		__entry->mapdev		=	map->dev;
+		__entry->mapaddr	=	map->addr;
+		__entry->maptype	=	map->type;
+		__entry->mapflags	=	map->flags;
+	),
+
+	TP_printk(FUSE_INODE_FMT FUSE_IOMAP_MAP_FMT(),
+		  FUSE_INODE_PRINTK_ARGS,
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(map))
+);
+#define DEFINE_FUSE_IOMAP_MAPPING_EVENT(name)	\
+DEFINE_EVENT(fuse_iomap_mapping_class, name,	\
+	TP_PROTO(const struct inode *inode, const struct fuse_iomap_io *map), \
+	TP_ARGS(inode, map))
+DEFINE_FUSE_IOMAP_MAPPING_EVENT(fuse_iomap_read_map);
+DEFINE_FUSE_IOMAP_MAPPING_EVENT(fuse_iomap_write_map);
+
+TRACE_EVENT(fuse_iomap_end,
+	TP_PROTO(const struct inode *inode,
+		 const struct fuse_iomap_end_in *inarg),
+
+	TP_ARGS(inode, inarg),
+
+	TP_STRUCT__entry(
+		FUSE_IOMAP_OP_FIELDS()
+		__field(size_t,			written)
+		FUSE_IOMAP_MAP_FIELDS(map)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->opflags	=	inarg->opflags;
+		__entry->written	=	inarg->written;
+		__entry->offset		=	inarg->pos;
+		__entry->length		=	inarg->count;
+
+		__entry->mapoffset	=	inarg->map.offset;
+		__entry->maplength	=	inarg->map.length;
+		__entry->mapdev		=	inarg->map.dev;
+		__entry->mapaddr	=	inarg->map.addr;
+		__entry->maptype	=	inarg->map.type;
+		__entry->mapflags	=	inarg->map.flags;
+	),
+
+	TP_printk(FUSE_IOMAP_OP_FMT() " written %zd" FUSE_IOMAP_MAP_FMT(),
+		  FUSE_IOMAP_OP_PRINTK_ARGS(),
+		  __entry->written,
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(map))
+);
+
+TRACE_EVENT(fuse_iomap_end_error,
+	TP_PROTO(const struct inode *inode,
+		 const struct fuse_iomap_end_in *inarg, int error),
+
+	TP_ARGS(inode, inarg, error),
+
+	TP_STRUCT__entry(
+		FUSE_IOMAP_OP_FIELDS()
+		__field(size_t,			written)
+		__field(int,			error)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	inarg->pos;
+		__entry->length		=	inarg->count;
+		__entry->opflags	=	inarg->opflags;
+		__entry->written	=	inarg->written;
+		__entry->error		=	error;
+	),
+
+	TP_printk(FUSE_IOMAP_OP_FMT() " written %zd error %d",
+		  FUSE_IOMAP_OP_PRINTK_ARGS(),
+		  __entry->written,
+		  __entry->error)
+);
+#endif /* CONFIG_FUSE_IOMAP */
+
 #endif /* _TRACE_FUSE_H */
 
 #undef TRACE_INCLUDE_PATH
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 8785f86941a1d2..c22c7961cc0bdc 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -327,6 +327,8 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 	FUSE_ARGS(args);
 	int err;
 
+	trace_fuse_iomap_begin(inode, pos, count, opflags);
+
 	args.opcode = FUSE_IOMAP_BEGIN;
 	args.nodeid = get_node_id(inode);
 	args.in_numargs = 1;
@@ -336,8 +338,13 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 	args.out_args[0].size = sizeof(outarg);
 	args.out_args[0].value = &outarg;
 	err = fuse_simple_request(fm, &args);
-	if (err)
+	if (err) {
+		trace_fuse_iomap_begin_error(inode, pos, count, opflags, err);
 		return err;
+	}
+
+	trace_fuse_iomap_read_map(inode, &outarg.read);
+	trace_fuse_iomap_write_map(inode, &outarg.write);
 
 	err = fuse_iomap_begin_validate(inode, opflags, pos, &outarg);
 	if (err)
@@ -404,6 +411,8 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
 
 		fuse_iomap_to_server(&inarg.map, iomap);
 
+		trace_fuse_iomap_end(inode, &inarg);
+
 		args.opcode = FUSE_IOMAP_END;
 		args.nodeid = get_node_id(inode);
 		args.in_numargs = 1;
@@ -417,8 +426,10 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
 			 */
 			err = 0;
 		}
-		if (err)
+		if (err) {
+			trace_fuse_iomap_end_error(inode, &inarg, err);
 			return err;
+		}
 	}
 
 	return 0;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 03/33] fuse: make debugging configurable at runtime
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
  2026-02-23 23:08   ` [PATCH 01/33] fuse: implement the basic iomap mechanisms Darrick J. Wong
  2026-02-23 23:09   ` [PATCH 02/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:09   ` Darrick J. Wong
  2026-02-23 23:09   ` [PATCH 04/33] fuse: adapt FUSE_DEV_IOC_BACKING_{OPEN,CLOSE} to add new iomap devices Darrick J. Wong
                     ` (29 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:09 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Use static keys so that we can configure debugging assertions and dmesg
warnings at runtime.  By default this is turned off so the cost is
merely scanning a nop sled.  However, fuse server developers can turn
it on for their debugging systems.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap_i.h |   17 ++++++++++++++---
 fs/fuse/Kconfig        |   15 +++++++++++++++
 fs/fuse/fuse_iomap.c   |   43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 3 deletions(-)


diff --git a/fs/fuse/fuse_iomap_i.h b/fs/fuse/fuse_iomap_i.h
index b9ab8ce140e8e1..c37a7c5cfc862f 100644
--- a/fs/fuse/fuse_iomap_i.h
+++ b/fs/fuse/fuse_iomap_i.h
@@ -8,17 +8,28 @@
 
 #if IS_ENABLED(CONFIG_FUSE_IOMAP)
 #if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG)
-# define ASSERT(condition) do {						\
+
+#if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG_BY_DEFAULT)
+DECLARE_STATIC_KEY_TRUE(fuse_iomap_debug);
+#else
+DECLARE_STATIC_KEY_FALSE(fuse_iomap_debug);
+#endif /* FUSE_IOMAP_DEBUG_BY_DEFAULT */
+
+# define ASSERT(condition) \
+while (static_branch_unlikely(&fuse_iomap_debug)) {			\
 	int __cond = !!(condition);					\
 	if (unlikely(!__cond))						\
 		trace_fuse_iomap_assert(__func__, __LINE__, #condition); \
 	WARN(!__cond, "Assertion failed: %s, func: %s, line: %d", #condition, __func__, __LINE__); \
-} while (0)
+	break;								\
+}
 # define BAD_DATA(condition) ({						\
 	int __cond = !!(condition);					\
 	if (unlikely(__cond))						\
 		trace_fuse_iomap_bad_data(__func__, __LINE__, #condition); \
-	WARN(__cond, "Bad mapping: %s, func: %s, line: %d", #condition, __func__, __LINE__); \
+	if (static_branch_unlikely(&fuse_iomap_debug))			\
+		WARN(__cond, "Bad mapping: %s, func: %s, line: %d", #condition, __func__, __LINE__); \
+	unlikely(__cond);								\
 })
 #else
 # define ASSERT(condition)
diff --git a/fs/fuse/Kconfig b/fs/fuse/Kconfig
index 934d48076a010c..1b8990f1c2a8f9 100644
--- a/fs/fuse/Kconfig
+++ b/fs/fuse/Kconfig
@@ -101,6 +101,21 @@ config FUSE_IOMAP_DEBUG
 	  Enable debugging assertions for the fuse iomap code paths and logging
 	  of bad iomap file mapping data being sent to the kernel.
 
+	  Say N here if you don't want any debugging code code compiled in at
+	  all.
+
+config FUSE_IOMAP_DEBUG_BY_DEFAULT
+	bool "Debug FUSE file IO over iomap at boot time"
+	default n
+	depends on FUSE_IOMAP_DEBUG
+	help
+	  At boot time, enable debugging assertions for the fuse iomap code
+	  paths and warnings about bad iomap file mapping data.  This enables
+	  fuse server authors to control debugging at runtime even on a
+	  distribution kernel while avoiding most of the overhead on production
+	  systems.  The setting can be changed at runtime via the debug_iomap
+	  module parameter.
+
 config FUSE_IO_URING
 	bool "FUSE communication over io-uring"
 	default y
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index c22c7961cc0bdc..f7a7eba8317c18 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -18,6 +18,49 @@ static bool __read_mostly enable_iomap =
 module_param(enable_iomap, bool, 0644);
 MODULE_PARM_DESC(enable_iomap, "Enable file I/O through iomap");
 
+#if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG)
+#if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG_BY_DEFAULT)
+DEFINE_STATIC_KEY_TRUE(fuse_iomap_debug);
+#else
+DEFINE_STATIC_KEY_FALSE(fuse_iomap_debug);
+#endif /* FUSE_IOMAP_DEBUG_BY_DEFAULT */
+
+static int iomap_debug_set(const char *val, const struct kernel_param *kp)
+{
+	bool now;
+	int ret;
+
+	if (!val)
+		return -EINVAL;
+
+	ret = kstrtobool(val, &now);
+	if (ret)
+		return ret;
+
+	if (now)
+		static_branch_enable(&fuse_iomap_debug);
+	else
+		static_branch_disable(&fuse_iomap_debug);
+
+	return 0;
+}
+
+static int iomap_debug_get(char *buffer, const struct kernel_param *kp)
+{
+	return sprintf(buffer, "%c\n",
+		       static_branch_unlikely(&fuse_iomap_debug) ? 'Y' : 'N');
+}
+
+static const struct kernel_param_ops iomap_debug_ops = {
+	.set = iomap_debug_set,
+	.get = iomap_debug_get,
+};
+
+module_param_cb(debug_iomap, &iomap_debug_ops, NULL, 0644);
+__MODULE_PARM_TYPE(debug_iomap, "bool");
+MODULE_PARM_DESC(debug_iomap, "Enable debugging of fuse iomap");
+#endif /* IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG) */
+
 bool fuse_iomap_enabled(void)
 {
 	/* Don't let anyone touch iomap until the end of the patchset. */


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 04/33] fuse: adapt FUSE_DEV_IOC_BACKING_{OPEN,CLOSE} to add new iomap devices
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:09   ` [PATCH 03/33] fuse: make debugging configurable at runtime Darrick J. Wong
@ 2026-02-23 23:09   ` Darrick J. Wong
  2026-02-23 23:09   ` [PATCH 05/33] fuse_trace: " Darrick J. Wong
                     ` (28 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:09 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Enable the use of the backing file open/close ioctls so that fuse
servers can register block devices for use with iomap.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h          |    7 +++
 fs/fuse/fuse_iomap.h      |    2 +
 include/uapi/linux/fuse.h |    3 +
 fs/fuse/Kconfig           |    1 
 fs/fuse/backing.c         |   47 +++++++++++++++++
 fs/fuse/fuse_iomap.c      |  126 +++++++++++++++++++++++++++++++++++++++++----
 fs/fuse/trace.c           |    1 
 7 files changed, 174 insertions(+), 13 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 2d62b6365fa931..0321be384b769e 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -104,12 +104,14 @@ struct fuse_submount_lookup {
 };
 
 struct fuse_conn;
+struct fuse_backing;
 
 /** Operations for subsystems that want to use a backing file */
 struct fuse_backing_ops {
 	int (*may_admin)(struct fuse_conn *fc, uint32_t flags);
 	int (*may_open)(struct fuse_conn *fc, struct file *file);
 	int (*may_close)(struct fuse_conn *fc, struct file *file);
+	int (*post_open)(struct fuse_conn *fc, struct fuse_backing *fb);
 	unsigned int type;
 	int id_start;
 	int id_end;
@@ -119,6 +121,7 @@ struct fuse_backing_ops {
 struct fuse_backing {
 	struct file *file;
 	struct cred *cred;
+	struct block_device *bdev;
 	const struct fuse_backing_ops *ops;
 
 	/** refcount */
@@ -1616,6 +1619,10 @@ void fuse_backing_put(struct fuse_backing *fb);
 struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,
 					 const struct fuse_backing_ops *ops,
 					 int backing_id);
+typedef bool (*fuse_match_backing_fn)(const struct fuse_backing *fb,
+				      const void *data);
+int fuse_backing_lookup_id(struct fuse_conn *fc, fuse_match_backing_fn match_fn,
+			   const void *data);
 #else
 
 static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 6c71318365ca82..43562ef23fb325 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -18,6 +18,8 @@ static inline bool fuse_has_iomap(const struct inode *inode)
 {
 	return get_fuse_conn(inode)->iomap;
 }
+
+extern const struct fuse_backing_ops fuse_iomap_backing_ops;
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 5a58011f66f501..5ae6b05de623d7 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1137,7 +1137,8 @@ struct fuse_notify_prune_out {
 
 #define FUSE_BACKING_TYPE_MASK		(0xFF)
 #define FUSE_BACKING_TYPE_PASSTHROUGH	(0)
-#define FUSE_BACKING_MAX_TYPE		(FUSE_BACKING_TYPE_PASSTHROUGH)
+#define FUSE_BACKING_TYPE_IOMAP		(1)
+#define FUSE_BACKING_MAX_TYPE		(FUSE_BACKING_TYPE_IOMAP)
 
 #define FUSE_BACKING_FLAGS_ALL		(FUSE_BACKING_TYPE_MASK)
 
diff --git a/fs/fuse/Kconfig b/fs/fuse/Kconfig
index 1b8990f1c2a8f9..3e35611c3aac07 100644
--- a/fs/fuse/Kconfig
+++ b/fs/fuse/Kconfig
@@ -75,6 +75,7 @@ config FUSE_IOMAP
 	depends on FUSE_FS
 	depends on BLOCK
 	select FS_IOMAP
+	select FUSE_BACKING
 	help
 	  Enable fuse servers to operate the regular file I/O path through
 	  the fs-iomap library in the kernel.  This enables higher performance
diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
index d7e074c30f46cc..050657a6ef1c98 100644
--- a/fs/fuse/backing.c
+++ b/fs/fuse/backing.c
@@ -6,6 +6,7 @@
  */
 
 #include "fuse_i.h"
+#include "fuse_iomap.h"
 #include "fuse_trace.h"
 
 #include <linux/file.h>
@@ -90,6 +91,10 @@ fuse_backing_ops_from_map(const struct fuse_backing_map *map)
 #ifdef CONFIG_FUSE_PASSTHROUGH
 	case FUSE_BACKING_TYPE_PASSTHROUGH:
 		return &fuse_passthrough_backing_ops;
+#endif
+#ifdef CONFIG_FUSE_IOMAP
+	case FUSE_BACKING_TYPE_IOMAP:
+		return &fuse_iomap_backing_ops;
 #endif
 	default:
 		break;
@@ -138,8 +143,16 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 	fb->file = file;
 	fb->cred = prepare_creds();
 	fb->ops = ops;
+	fb->bdev = NULL;
 	refcount_set(&fb->count, 1);
 
+	res = ops->post_open ? ops->post_open(fc, fb) : 0;
+	if (res) {
+		fuse_backing_free(fb);
+		fb = NULL;
+		goto out;
+	}
+
 	res = fuse_backing_id_alloc(fc, fb);
 	if (res < 0) {
 		fuse_backing_free(fb);
@@ -230,3 +243,37 @@ struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,
 
 	return fb;
 }
+
+struct fuse_backing_match {
+	fuse_match_backing_fn match_fn;
+	const void *data;
+};
+
+static int fuse_backing_matches(int id, void *p, void *data)
+{
+	struct fuse_backing *fb = p;
+	struct fuse_backing_match *fbm = data;
+
+	if (fb && fbm->match_fn(fb, fbm->data)) {
+		/* backing ids are always greater than zero */
+		return id;
+	}
+
+	return 0;
+}
+
+int fuse_backing_lookup_id(struct fuse_conn *fc, fuse_match_backing_fn match_fn,
+			   const void *data)
+{
+	struct fuse_backing_match fbm = {
+		.match_fn = match_fn,
+		.data = data,
+	};
+	int ret;
+
+	rcu_read_lock();
+	ret = idr_for_each(&fc->backing_files_map, fuse_backing_matches, &fbm);
+	rcu_read_unlock();
+
+	return ret;
+}
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index f7a7eba8317c18..0ac783dd312dc3 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -282,10 +282,6 @@ static inline bool fuse_iomap_check_mapping(const struct inode *inode,
 		return false;
 	}
 
-	/* XXX: we don't support devices yet */
-	if (BAD_DATA(map->dev != FUSE_IOMAP_DEV_NULL))
-		return false;
-
 	/* No overflows in the device range, if supplied */
 	if (map->addr != FUSE_IOMAP_NULL_ADDR &&
 	    BAD_DATA(check_add_overflow(map->addr, map->length, &end)))
@@ -296,6 +292,7 @@ static inline bool fuse_iomap_check_mapping(const struct inode *inode,
 
 /* Convert a mapping from the server into something the kernel can use */
 static inline void fuse_iomap_from_server(struct iomap *iomap,
+					  const struct fuse_backing *fb,
 					  const struct fuse_iomap_io *fmap)
 {
 	iomap->addr = fmap->addr;
@@ -303,11 +300,32 @@ static inline void fuse_iomap_from_server(struct iomap *iomap,
 	iomap->length = fmap->length;
 	iomap->type = fuse_iomap_type_from_server(fmap->type);
 	iomap->flags = fuse_iomap_flags_from_server(fmap->flags);
-	iomap->bdev = NULL; /* XXX */
+	iomap->bdev = fb ? fb->bdev : NULL;
+	iomap->dax_dev = NULL;
+}
+
+static bool fuse_iomap_matches_bdev(const struct fuse_backing *fb,
+				    const void *data)
+{
+	return fb->bdev == data;
+}
+
+static inline uint32_t
+fuse_iomap_find_backing_id(struct fuse_conn *fc,
+			   const struct block_device *bdev)
+{
+	int ret = -ENODEV;
+
+	if (bdev)
+		ret = fuse_backing_lookup_id(fc, fuse_iomap_matches_bdev, bdev);
+	if (ret < 0)
+		return FUSE_IOMAP_DEV_NULL;
+	return ret;
 }
 
 /* Convert a mapping from the kernel into something the server can use */
-static inline void fuse_iomap_to_server(struct fuse_iomap_io *fmap,
+static inline void fuse_iomap_to_server(struct fuse_conn *fc,
+					struct fuse_iomap_io *fmap,
 					const struct iomap *iomap)
 {
 	fmap->addr = iomap->addr;
@@ -315,7 +333,7 @@ static inline void fuse_iomap_to_server(struct fuse_iomap_io *fmap,
 	fmap->length = iomap->length;
 	fmap->type = fuse_iomap_type_to_server(iomap->type);
 	fmap->flags = fuse_iomap_flags_to_server(iomap->flags);
-	fmap->dev = FUSE_IOMAP_DEV_NULL; /* XXX */
+	fmap->dev = fuse_iomap_find_backing_id(fc, iomap->bdev);
 }
 
 /* Check the incoming _begin mappings to make sure they're not nonsense. */
@@ -354,6 +372,27 @@ static inline bool fuse_is_iomap_file_write(unsigned int opflags)
 	return opflags & (IOMAP_WRITE | IOMAP_ZERO | IOMAP_UNSHARE);
 }
 
+static inline struct fuse_backing *
+fuse_iomap_find_dev(struct fuse_conn *fc, const struct fuse_iomap_io *map)
+{
+	struct fuse_backing *ret = NULL;
+
+	if (map->dev != FUSE_IOMAP_DEV_NULL && map->dev < INT_MAX)
+		ret = fuse_backing_lookup(fc, &fuse_iomap_backing_ops,
+					  map->dev);
+
+	switch (map->type) {
+	case FUSE_IOMAP_TYPE_MAPPED:
+	case FUSE_IOMAP_TYPE_UNWRITTEN:
+		/* Mappings backed by space must have a device/addr */
+		if (BAD_DATA(ret == NULL))
+			return ERR_PTR(-EFSCORRUPTED);
+		break;
+	}
+
+	return ret;
+}
+
 static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 			    unsigned opflags, struct iomap *iomap,
 			    struct iomap *srcmap)
@@ -367,6 +406,8 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 	};
 	struct fuse_iomap_begin_out outarg = { };
 	struct fuse_mount *fm = get_fuse_mount(inode);
+	struct fuse_backing *read_dev = NULL;
+	struct fuse_backing *write_dev = NULL;
 	FUSE_ARGS(args);
 	int err;
 
@@ -393,24 +434,44 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 	if (err)
 		return err;
 
+	read_dev = fuse_iomap_find_dev(fm->fc, &outarg.read);
+	if (IS_ERR(read_dev))
+		return PTR_ERR(read_dev);
+
 	if (fuse_is_iomap_file_write(opflags) &&
 	    outarg.write.type != FUSE_IOMAP_TYPE_PURE_OVERWRITE) {
+		/* open the write device */
+		write_dev = fuse_iomap_find_dev(fm->fc, &outarg.write);
+		if (IS_ERR(write_dev)) {
+			err = PTR_ERR(write_dev);
+			goto out_read_dev;
+		}
+
 		/*
 		 * For an out of place write, we must supply the write mapping
 		 * via @iomap, and the read mapping via @srcmap.
 		 */
-		fuse_iomap_from_server(iomap, &outarg.write);
-		fuse_iomap_from_server(srcmap, &outarg.read);
+		fuse_iomap_from_server(iomap, write_dev, &outarg.write);
+		fuse_iomap_from_server(srcmap, read_dev, &outarg.read);
 	} else {
 		/*
 		 * For everything else (reads, reporting, and pure overwrites),
 		 * we can return the sole mapping through @iomap and leave
 		 * @srcmap unchanged from its default (HOLE).
 		 */
-		fuse_iomap_from_server(iomap, &outarg.read);
+		fuse_iomap_from_server(iomap, read_dev, &outarg.read);
 	}
 
-	return 0;
+	/*
+	 * XXX: if we ever want to support closing devices, we need a way to
+	 * track the fuse_backing refcount all the way through bio endios.
+	 * For now we put the refcount here because you can't remove an iomap
+	 * device until unmount time.
+	 */
+	fuse_backing_put(write_dev);
+out_read_dev:
+	fuse_backing_put(read_dev);
+	return err;
 }
 
 /* Decide if we send FUSE_IOMAP_END to the fuse server */
@@ -452,7 +513,7 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
 		};
 		FUSE_ARGS(args);
 
-		fuse_iomap_to_server(&inarg.map, iomap);
+		fuse_iomap_to_server(fm->fc, &inarg.map, iomap);
 
 		trace_fuse_iomap_end(inode, &inarg);
 
@@ -482,3 +543,44 @@ const struct iomap_ops fuse_iomap_ops = {
 	.iomap_begin		= fuse_iomap_begin,
 	.iomap_end		= fuse_iomap_end,
 };
+
+static int fuse_iomap_may_admin(struct fuse_conn *fc, unsigned int flags)
+{
+	if (!fc->iomap)
+		return -EPERM;
+
+	if (flags)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int fuse_iomap_may_open(struct fuse_conn *fc, struct file *file)
+{
+	if (!S_ISBLK(file_inode(file)->i_mode))
+		return -ENODEV;
+
+	return 0;
+}
+
+static int fuse_iomap_post_open(struct fuse_conn *fc, struct fuse_backing *fb)
+{
+	fb->bdev = I_BDEV(fb->file->f_mapping->host);
+	return 0;
+}
+
+static int fuse_iomap_may_close(struct fuse_conn *fc, struct file *file)
+{
+	/* We only support closing iomap block devices at unmount */
+	return -EBUSY;
+}
+
+const struct fuse_backing_ops fuse_iomap_backing_ops = {
+	.type = FUSE_BACKING_TYPE_IOMAP,
+	.id_start = 1,
+	.id_end = 1025,		/* maximum 1024 block devices */
+	.may_admin = fuse_iomap_may_admin,
+	.may_open = fuse_iomap_may_open,
+	.may_close = fuse_iomap_may_close,
+	.post_open = fuse_iomap_post_open,
+};
diff --git a/fs/fuse/trace.c b/fs/fuse/trace.c
index 93bd72efc98cd0..c830c1c38a833c 100644
--- a/fs/fuse/trace.c
+++ b/fs/fuse/trace.c
@@ -6,6 +6,7 @@
 #include "dev_uring_i.h"
 #include "fuse_i.h"
 #include "fuse_dev_i.h"
+#include "fuse_iomap_i.h"
 
 #include <linux/pagemap.h>
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 05/33] fuse_trace: adapt FUSE_DEV_IOC_BACKING_{OPEN,CLOSE} to add new iomap devices
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:09   ` [PATCH 04/33] fuse: adapt FUSE_DEV_IOC_BACKING_{OPEN,CLOSE} to add new iomap devices Darrick J. Wong
@ 2026-02-23 23:09   ` Darrick J. Wong
  2026-02-23 23:10   ` [PATCH 06/33] fuse: enable SYNCFS and ensure we flush everything before sending DESTROY Darrick J. Wong
                     ` (27 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:09 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Enhance the existing backing file tracepoints to report the subsystem
that's actually using the backing file.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index c0878253e7c6ad..af21654d797f45 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -175,6 +175,10 @@ TRACE_EVENT(fuse_request_end,
 );
 
 #ifdef CONFIG_FUSE_BACKING
+#define FUSE_BACKING_FLAG_STRINGS \
+	{ FUSE_BACKING_TYPE_PASSTHROUGH,	"pass" }, \
+	{ FUSE_BACKING_TYPE_IOMAP,		"iomap" }
+
 TRACE_EVENT(fuse_backing_class,
 	TP_PROTO(const struct fuse_conn *fc, unsigned int idx,
 		 const struct fuse_backing *fb),
@@ -184,7 +188,9 @@ TRACE_EVENT(fuse_backing_class,
 	TP_STRUCT__entry(
 		__field(dev_t,			connection)
 		__field(unsigned int,		idx)
+		__field(unsigned int,		type)
 		__field(unsigned long,		ino)
+		__field(dev_t,			rdev)
 	),
 
 	TP_fast_assign(
@@ -193,12 +199,19 @@ TRACE_EVENT(fuse_backing_class,
 		__entry->connection	=	fc->dev;
 		__entry->idx		=	idx;
 		__entry->ino		=	inode->i_ino;
+		__entry->type		=	fb->ops->type;
+		if (fb->ops->type == FUSE_BACKING_TYPE_IOMAP)
+			__entry->rdev	=	inode->i_rdev;
+		else
+			__entry->rdev	=	0;
 	),
 
-	TP_printk("connection %u idx %u ino 0x%lx",
+	TP_printk("connection %u idx %u type %s ino 0x%lx rdev %u:%u",
 		  __entry->connection,
 		  __entry->idx,
-		  __entry->ino)
+		  __print_symbolic(__entry->type, FUSE_BACKING_FLAG_STRINGS),
+		  __entry->ino,
+		  MAJOR(__entry->rdev), MINOR(__entry->rdev))
 );
 #define DEFINE_FUSE_BACKING_EVENT(name)		\
 DEFINE_EVENT(fuse_backing_class, name,		\
@@ -210,7 +223,6 @@ DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
 #endif /* CONFIG_FUSE_BACKING */
 
 #if IS_ENABLED(CONFIG_FUSE_IOMAP)
-
 /* tracepoint boilerplate so we don't have to keep doing this */
 #define FUSE_IOMAP_OPFLAGS_FIELD \
 		__field(unsigned,		opflags)
@@ -452,6 +464,30 @@ TRACE_EVENT(fuse_iomap_end_error,
 		  __entry->written,
 		  __entry->error)
 );
+
+TRACE_EVENT(fuse_iomap_dev_add,
+	TP_PROTO(const struct fuse_conn *fc,
+		 const struct fuse_backing_map *map),
+
+	TP_ARGS(fc, map),
+
+	TP_STRUCT__entry(
+		__field(dev_t,			connection)
+		__field(int,			fd)
+		__field(unsigned int,		flags)
+	),
+
+	TP_fast_assign(
+		__entry->connection	=	fc->dev;
+		__entry->fd		=	map->fd;
+		__entry->flags		=	map->flags;
+	),
+
+	TP_printk("connection %u fd %d flags 0x%x",
+		  __entry->connection,
+		  __entry->fd,
+		  __entry->flags)
+);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 06/33] fuse: enable SYNCFS and ensure we flush everything before sending DESTROY
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (4 preceding siblings ...)
  2026-02-23 23:09   ` [PATCH 05/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:10   ` Darrick J. Wong
  2026-02-23 23:10   ` [PATCH 07/33] fuse: clean up per-file type inode initialization Darrick J. Wong
                     ` (26 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:10 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

At unmount time, there are a few things that we need to ask a fuse iomap
server to do.  We need to send FUSE_DESTROY to the fuse server so that
it closes the filesystem and the device fds before unmount returns.
That way, a script that does something like "umount /dev/sda ; e2fsck
-fn /dev/sda" will not fail the e2fsck because the fd closure races with
e2fsck startup.  This is essential for fstests QA to work properly.

To make this happen, first, we need to flush queued events to userspace
to give the fuse server a chance to process the events.  These will all
be FUSE_RELEASE events for previously opened files.  Once the commands
are flushed, we can send the FUSE_DESTROY request to ask the server to
close the filesystem.  This depends on libfuse to hold the destroy
command until there are no unreleased files (instead of having the
kernel enforce the ordering) because the kernel fuse developers don't
like the idea of unbounded waits in unmount.

Second, to reduce the amount of metadata must be persisted to disk in
the fuse server's destroy method, enable FUSE_SYNCFS so that previous
sync_filesystem calls can flush dirty data before we get deeper in the
unmount machinery.  If a fuse command timeout is set, this reduces the
likelihood that the kernel aborts the FUSE_DESTROY command whilst the
server is busy flushing dirty metadata.

This is a major behavior change and who knows what might break existing
code, so we hide it behind iomap mode.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h     |    3 +++
 fs/fuse/fuse_iomap.h |    5 +++++
 fs/fuse/fuse_iomap.c |   32 ++++++++++++++++++++++++++++++++
 fs/fuse/inode.c      |    9 +++++++--
 4 files changed, 47 insertions(+), 2 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 0321be384b769e..6860913a89e65d 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1431,6 +1431,9 @@ int fuse_init_fs_context_submount(struct fs_context *fsc);
  */
 void fuse_conn_destroy(struct fuse_mount *fm);
 
+/* Send the FUSE_DESTROY command. */
+void fuse_send_destroy(struct fuse_mount *fm);
+
 /* Drop the connection and free the fuse mount */
 void fuse_mount_destroy(struct fuse_mount *fm);
 
diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 43562ef23fb325..129680b056ebea 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -20,9 +20,14 @@ static inline bool fuse_has_iomap(const struct inode *inode)
 }
 
 extern const struct fuse_backing_ops fuse_iomap_backing_ops;
+
+void fuse_iomap_mount(struct fuse_mount *fm);
+void fuse_iomap_unmount(struct fuse_mount *fm);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
+# define fuse_iomap_mount(...)			((void)0)
+# define fuse_iomap_unmount(...)		((void)0)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 0ac783dd312dc3..4b63bb32167877 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -584,3 +584,35 @@ const struct fuse_backing_ops fuse_iomap_backing_ops = {
 	.may_close = fuse_iomap_may_close,
 	.post_open = fuse_iomap_post_open,
 };
+
+void fuse_iomap_mount(struct fuse_mount *fm)
+{
+	struct fuse_conn *fc = fm->fc;
+
+	/*
+	 * Enable syncfs for iomap fuse servers so that we can send a final
+	 * flush at unmount time.  This also means that we can support
+	 * freeze/thaw properly.
+	 */
+	fc->sync_fs = true;
+}
+
+void fuse_iomap_unmount(struct fuse_mount *fm)
+{
+	struct fuse_conn *fc = fm->fc;
+
+	/*
+	 * Flush all pending file release commands and send a destroy command.
+	 * This gives the fuse server a chance to process all the pending
+	 * releases, write the last bits of metadata changes to disk, and close
+	 * the iomap block devices before we return from the umount call.
+	 * iomap fuse servers are expected to release all exclusive access
+	 * resources before unmount completes.
+	 *
+	 * Note that multithreaded fuse servers will have to hold the destroy
+	 * command until all release requests have completed because the kernel
+	 * maintainers do not want to introduce waits in unmount.
+	 */
+	fuse_flush_requests(fc);
+	fuse_send_destroy(fm);
+}
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 8f01844f89b261..778fdec9d81a03 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -633,7 +633,7 @@ static void fuse_umount_begin(struct super_block *sb)
 		retire_super(sb);
 }
 
-static void fuse_send_destroy(struct fuse_mount *fm)
+void fuse_send_destroy(struct fuse_mount *fm)
 {
 	if (fm->fc->conn_init) {
 		FUSE_ARGS(args);
@@ -1475,6 +1475,9 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 
 		init_server_timeout(fc, timeout);
 
+		if (fc->iomap)
+			fuse_iomap_mount(fm);
+
 		fm->sb->s_bdi->ra_pages =
 				min(fm->sb->s_bdi->ra_pages, ra_pages);
 		fc->minor = arg->minor;
@@ -2099,7 +2102,9 @@ void fuse_conn_destroy(struct fuse_mount *fm)
 {
 	struct fuse_conn *fc = fm->fc;
 
-	if (fc->destroy) {
+	if (fc->iomap) {
+		fuse_iomap_unmount(fm);
+	} else if (fc->destroy) {
 		/*
 		 * Flush all pending requests (most of which will be
 		 * FUSE_RELEASE) before sending FUSE_DESTROY, because the fuse


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 07/33] fuse: clean up per-file type inode initialization
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (5 preceding siblings ...)
  2026-02-23 23:10   ` [PATCH 06/33] fuse: enable SYNCFS and ensure we flush everything before sending DESTROY Darrick J. Wong
@ 2026-02-23 23:10   ` Darrick J. Wong
  2026-02-23 23:10   ` [PATCH 08/33] fuse: create a per-inode flag for setting exclusive mode Darrick J. Wong
                     ` (25 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:10 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Clean up the per-filetype inode initialization in fuse_init_inode before
we start adding more functionality here.  Primarily this consists of
refactoring to use a switch statement and passing the file attr struct
around.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h |    2 +-
 fs/fuse/file.c   |    5 +++--
 fs/fuse/inode.c  |   36 +++++++++++++++++++++++++-----------
 3 files changed, 29 insertions(+), 14 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 6860913a89e65d..c6d39290a7a9cf 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1230,7 +1230,7 @@ int fuse_notify_poll_wakeup(struct fuse_conn *fc,
 /**
  * Initialize file operations on a regular file
  */
-void fuse_init_file_inode(struct inode *inode, unsigned int flags);
+void fuse_init_file_inode(struct inode *inode, struct fuse_attr *attr);
 
 /**
  * Initialize inode operations on regular files and special files
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index b1bb7153cb785f..21a6f2cd7bfaa9 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -3194,11 +3194,12 @@ static const struct address_space_operations fuse_file_aops  = {
 	.direct_IO	= fuse_direct_IO,
 };
 
-void fuse_init_file_inode(struct inode *inode, unsigned int flags)
+void fuse_init_file_inode(struct inode *inode, struct fuse_attr *attr)
 {
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	struct fuse_conn *fc = get_fuse_conn(inode);
 
+	fuse_init_common(inode);
 	inode->i_fop = &fuse_file_operations;
 	inode->i_data.a_ops = &fuse_file_aops;
 	if (fc->writeback_cache) {
@@ -3214,5 +3215,5 @@ void fuse_init_file_inode(struct inode *inode, unsigned int flags)
 	init_waitqueue_head(&fi->direct_io_waitq);
 
 	if (IS_ENABLED(CONFIG_FUSE_DAX))
-		fuse_dax_inode_init(inode, flags);
+		fuse_dax_inode_init(inode, attr->flags);
 }
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 778fdec9d81a03..40450a3d32e7cb 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -422,6 +422,12 @@ static void fuse_init_submount_lookup(struct fuse_submount_lookup *sl,
 	refcount_set(&sl->count, 1);
 }
 
+static void fuse_init_special(struct inode *inode, struct fuse_attr *attr)
+{
+	fuse_init_common(inode);
+	init_special_inode(inode, inode->i_mode, new_decode_dev(attr->rdev));
+}
+
 static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr,
 			    struct fuse_conn *fc)
 {
@@ -429,20 +435,28 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr,
 	inode->i_size = attr->size;
 	inode_set_mtime(inode, attr->mtime, attr->mtimensec);
 	inode_set_ctime(inode, attr->ctime, attr->ctimensec);
-	if (S_ISREG(inode->i_mode)) {
-		fuse_init_common(inode);
-		fuse_init_file_inode(inode, attr->flags);
-	} else if (S_ISDIR(inode->i_mode))
+
+	switch (inode->i_mode & S_IFMT) {
+	case S_IFREG:
+		fuse_init_file_inode(inode, attr);
+		break;
+	case S_IFDIR:
 		fuse_init_dir(inode);
-	else if (S_ISLNK(inode->i_mode))
+		break;
+	case S_IFLNK:
 		fuse_init_symlink(inode);
-	else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
-		 S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
-		fuse_init_common(inode);
-		init_special_inode(inode, inode->i_mode,
-				   new_decode_dev(attr->rdev));
-	} else
+		break;
+	case S_IFCHR:
+	case S_IFBLK:
+	case S_IFIFO:
+	case S_IFSOCK:
+		fuse_init_special(inode, attr);
+		break;
+	default:
 		BUG();
+		break;
+	}
+
 	/*
 	 * Ensure that we don't cache acls for daemons without FUSE_POSIX_ACL
 	 * so they see the exact same behavior as before.


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 08/33] fuse: create a per-inode flag for setting exclusive mode.
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (6 preceding siblings ...)
  2026-02-23 23:10   ` [PATCH 07/33] fuse: clean up per-file type inode initialization Darrick J. Wong
@ 2026-02-23 23:10   ` Darrick J. Wong
  2026-02-23 23:11   ` [PATCH 09/33] fuse: create a per-inode flag for toggling iomap Darrick J. Wong
                     ` (24 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:10 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Create a per-inode flag to control whether or not this inode can use
exclusive mode.  This enables more aggressive use of cached file
attributes for things such as ACL inheritance and transformations.

The initial user will be iomap filesystems, where we hoist the IO path
into the kernel and need ACLs to work for regular files and directories
in the manner that most local filesystems expect.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h          |   17 +++++++++++++++++
 include/uapi/linux/fuse.h |    4 ++++
 fs/fuse/inode.c           |    5 +++++
 3 files changed, 26 insertions(+)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index c6d39290a7a9cf..46c2c660a39484 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1117,6 +1117,23 @@ static inline bool fuse_is_bad(struct inode *inode)
 	return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state));
 }
 
+static inline void fuse_inode_set_exclusive(const struct fuse_conn *fc,
+					    struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+
+	/* This flag wasn't added until kernel API 7.99 */
+	if (fc->minor >= 99)
+		set_bit(FUSE_I_EXCLUSIVE, &fi->state);
+}
+
+static inline void fuse_inode_clear_exclusive(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+
+	clear_bit(FUSE_I_EXCLUSIVE, &fi->state);
+}
+
 static inline bool fuse_inode_is_exclusive(const struct inode *inode)
 {
 	const struct fuse_inode *fi = get_fuse_inode(inode);
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 5ae6b05de623d7..2d35dcfbf8aaf5 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -244,6 +244,7 @@
  *  7.99
  *  - XXX magic minor revision to make experimental code really obvious
  *  - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations
+ *  - add FUSE_ATTR_EXCLUSIVE to enable exclusive mode for specific inodes
  */
 
 #ifndef _LINUX_FUSE_H
@@ -584,9 +585,12 @@ struct fuse_file_lock {
  *
  * FUSE_ATTR_SUBMOUNT: Object is a submount root
  * FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode
+ * FUSE_ATTR_EXCLUSIVE: This file can only be modified by this mount, so the
+ * kernel can use cached attributes more aggressively (e.g. ACL inheritance)
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 #define FUSE_ATTR_DAX		(1 << 1)
+#define FUSE_ATTR_EXCLUSIVE	(1 << 2)
 
 /**
  * Open flags
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 40450a3d32e7cb..e45b53bfce4b2d 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -197,6 +197,8 @@ static void fuse_evict_inode(struct inode *inode)
 		WARN_ON(!list_empty(&fi->write_files));
 		WARN_ON(!list_empty(&fi->queued_writes));
 	}
+
+	fuse_inode_clear_exclusive(inode);
 }
 
 static int fuse_reconfigure(struct fs_context *fsc)
@@ -436,6 +438,9 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr,
 	inode_set_mtime(inode, attr->mtime, attr->mtimensec);
 	inode_set_ctime(inode, attr->ctime, attr->ctimensec);
 
+	if (attr->flags & FUSE_ATTR_EXCLUSIVE)
+		fuse_inode_set_exclusive(fc, inode);
+
 	switch (inode->i_mode & S_IFMT) {
 	case S_IFREG:
 		fuse_init_file_inode(inode, attr);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 09/33] fuse: create a per-inode flag for toggling iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (7 preceding siblings ...)
  2026-02-23 23:10   ` [PATCH 08/33] fuse: create a per-inode flag for setting exclusive mode Darrick J. Wong
@ 2026-02-23 23:11   ` Darrick J. Wong
  2026-02-23 23:11   ` [PATCH 10/33] fuse_trace: " Darrick J. Wong
                     ` (23 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:11 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, joannelkoong, bpf, bernd, neal, linux-fsdevel,
	linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Create a per-inode flag to control whether or not this inode actually
uses iomap.  This is required for non-regular files because iomap
doesn't apply there; and enables fuse filesystems to provide some
non-iomap files if desired.

Note that more code will be added to fuse_iomap_init_inode in subsequent
patches.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/fuse_i.h          |    6 ++++--
 fs/fuse/fuse_iomap.h      |   13 ++++++++++++
 include/uapi/linux/fuse.h |    3 +++
 fs/fuse/dir.c             |   14 +++++++++++--
 fs/fuse/file.c            |    3 +++
 fs/fuse/fuse_iomap.c      |   47 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |    6 ++++--
 7 files changed, 86 insertions(+), 6 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 46c2c660a39484..011b252a437855 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -264,6 +264,8 @@ enum {
 	 * or the fuse server has an exclusive "lease" on distributed fs
 	 */
 	FUSE_I_EXCLUSIVE,
+	/* Use iomap for this inode */
+	FUSE_I_IOMAP,
 };
 
 struct fuse_conn;
@@ -1257,12 +1259,12 @@ void fuse_init_common(struct inode *inode);
 /**
  * Initialize inode and file operations on a directory
  */
-void fuse_init_dir(struct inode *inode);
+void fuse_init_dir(struct inode *inode, struct fuse_attr *attr);
 
 /**
  * Initialize inode operations on a symlink
  */
-void fuse_init_symlink(struct inode *inode);
+void fuse_init_symlink(struct inode *inode, struct fuse_attr *attr);
 
 /**
  * Change attributes of an inode
diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 129680b056ebea..34f2c75416eb62 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -23,11 +23,24 @@ extern const struct fuse_backing_ops fuse_iomap_backing_ops;
 
 void fuse_iomap_mount(struct fuse_mount *fm);
 void fuse_iomap_unmount(struct fuse_mount *fm);
+
+void fuse_iomap_init_inode(struct inode *inode, struct fuse_attr *attr);
+void fuse_iomap_evict_inode(struct inode *inode);
+
+static inline bool fuse_inode_has_iomap(const struct inode *inode)
+{
+	const struct fuse_inode *fi = get_fuse_inode(inode);
+
+	return test_bit(FUSE_I_IOMAP, &fi->state);
+}
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
 # define fuse_iomap_mount(...)			((void)0)
 # define fuse_iomap_unmount(...)		((void)0)
+# define fuse_iomap_init_inode(...)		((void)0)
+# define fuse_iomap_evict_inode(...)		((void)0)
+# define fuse_inode_has_iomap(...)		(false)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 2d35dcfbf8aaf5..88f76f4be749a7 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -245,6 +245,7 @@
  *  - XXX magic minor revision to make experimental code really obvious
  *  - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations
  *  - add FUSE_ATTR_EXCLUSIVE to enable exclusive mode for specific inodes
+ *  - add FUSE_ATTR_IOMAP to enable iomap for specific inodes
  */
 
 #ifndef _LINUX_FUSE_H
@@ -587,10 +588,12 @@ struct fuse_file_lock {
  * FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode
  * FUSE_ATTR_EXCLUSIVE: This file can only be modified by this mount, so the
  * kernel can use cached attributes more aggressively (e.g. ACL inheritance)
+ * FUSE_ATTR_IOMAP: Use iomap for this inode
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 #define FUSE_ATTR_DAX		(1 << 1)
 #define FUSE_ATTR_EXCLUSIVE	(1 << 2)
+#define FUSE_ATTR_IOMAP		(1 << 3)
 
 /**
  * Open flags
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 9abec6f072ac73..10db4dc046930f 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -7,6 +7,7 @@
 */
 
 #include "fuse_i.h"
+#include "fuse_iomap.h"
 
 #include <linux/pagemap.h>
 #include <linux/file.h>
@@ -2510,9 +2511,10 @@ void fuse_init_common(struct inode *inode)
 	inode->i_op = &fuse_common_inode_operations;
 }
 
-void fuse_init_dir(struct inode *inode)
+void fuse_init_dir(struct inode *inode, struct fuse_attr *attr)
 {
 	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_conn *fc = get_fuse_conn(inode);
 
 	inode->i_op = &fuse_dir_inode_operations;
 	inode->i_fop = &fuse_dir_operations;
@@ -2522,6 +2524,9 @@ void fuse_init_dir(struct inode *inode)
 	fi->rdc.size = 0;
 	fi->rdc.pos = 0;
 	fi->rdc.version = 0;
+
+	if (fc->iomap)
+		fuse_iomap_init_inode(inode, attr);
 }
 
 static int fuse_symlink_read_folio(struct file *null, struct folio *folio)
@@ -2540,9 +2545,14 @@ static const struct address_space_operations fuse_symlink_aops = {
 	.read_folio	= fuse_symlink_read_folio,
 };
 
-void fuse_init_symlink(struct inode *inode)
+void fuse_init_symlink(struct inode *inode, struct fuse_attr *attr)
 {
+	struct fuse_conn *fc = get_fuse_conn(inode);
+
 	inode->i_op = &fuse_symlink_inode_operations;
 	inode->i_data.a_ops = &fuse_symlink_aops;
 	inode_nohighmem(inode);
+
+	if (fc->iomap)
+		fuse_iomap_init_inode(inode, attr);
 }
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 21a6f2cd7bfaa9..4a7b0c190aa8e4 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -7,6 +7,7 @@
 */
 
 #include "fuse_i.h"
+#include "fuse_iomap.h"
 
 #include <linux/pagemap.h>
 #include <linux/slab.h>
@@ -3214,6 +3215,8 @@ void fuse_init_file_inode(struct inode *inode, struct fuse_attr *attr)
 	init_waitqueue_head(&fi->page_waitq);
 	init_waitqueue_head(&fi->direct_io_waitq);
 
+	if (fc->iomap)
+		fuse_iomap_init_inode(inode, attr);
 	if (IS_ENABLED(CONFIG_FUSE_DAX))
 		fuse_dax_inode_init(inode, attr->flags);
 }
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 4b63bb32167877..39c9239c64435a 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -616,3 +616,50 @@ void fuse_iomap_unmount(struct fuse_mount *fm)
 	fuse_flush_requests(fc);
 	fuse_send_destroy(fm);
 }
+
+static inline void fuse_inode_set_iomap(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+
+	set_bit(FUSE_I_IOMAP, &fi->state);
+}
+
+static inline void fuse_inode_clear_iomap(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+
+	clear_bit(FUSE_I_IOMAP, &fi->state);
+}
+
+void fuse_iomap_init_inode(struct inode *inode, struct fuse_attr *attr)
+{
+	ASSERT(get_fuse_conn(inode)->iomap);
+
+	if (!(attr->flags & FUSE_ATTR_IOMAP))
+		return;
+
+	/*
+	 * Any file being used in conjunction with iomap must also have the
+	 * exclusive flag set because iomap requires cached file attributes to
+	 * be correct at any time.  This applies even to non-regular files
+	 * (e.g. directories) because we need to do ACL and attribute
+	 * inheritance the same way a local filesystem would do.  If exclusive
+	 * mode isn't set, then we won't use iomap.
+	 */
+	if (!fuse_inode_is_exclusive(inode)) {
+		ASSERT(fuse_inode_is_exclusive(inode));
+		return;
+	}
+
+	if (!S_ISREG(inode->i_mode))
+		return;
+
+	fuse_inode_set_iomap(inode);
+}
+
+void fuse_iomap_evict_inode(struct inode *inode)
+{
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	fuse_inode_clear_iomap(inode);
+}
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index e45b53bfce4b2d..27699a6c11f66b 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -198,6 +198,8 @@ static void fuse_evict_inode(struct inode *inode)
 		WARN_ON(!list_empty(&fi->queued_writes));
 	}
 
+	if (fuse_inode_has_iomap(inode))
+		fuse_iomap_evict_inode(inode);
 	fuse_inode_clear_exclusive(inode);
 }
 
@@ -446,10 +448,10 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr,
 		fuse_init_file_inode(inode, attr);
 		break;
 	case S_IFDIR:
-		fuse_init_dir(inode);
+		fuse_init_dir(inode, attr);
 		break;
 	case S_IFLNK:
-		fuse_init_symlink(inode);
+		fuse_init_symlink(inode, attr);
 		break;
 	case S_IFCHR:
 	case S_IFBLK:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 10/33] fuse_trace: create a per-inode flag for toggling iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (8 preceding siblings ...)
  2026-02-23 23:11   ` [PATCH 09/33] fuse: create a per-inode flag for toggling iomap Darrick J. Wong
@ 2026-02-23 23:11   ` Darrick J. Wong
  2026-02-23 23:11   ` [PATCH 11/33] fuse: isolate the other regular file IO paths from iomap Darrick J. Wong
                     ` (22 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:11 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   44 ++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    8 +++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index af21654d797f45..fac981e2a30df0 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -300,6 +300,25 @@ DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
 	{ FUSE_IOMAP_TYPE_UNWRITTEN,		"unwritten" }, \
 	{ FUSE_IOMAP_TYPE_INLINE,		"inline" }
 
+TRACE_DEFINE_ENUM(FUSE_I_ADVISE_RDPLUS);
+TRACE_DEFINE_ENUM(FUSE_I_INIT_RDPLUS);
+TRACE_DEFINE_ENUM(FUSE_I_SIZE_UNSTABLE);
+TRACE_DEFINE_ENUM(FUSE_I_BAD);
+TRACE_DEFINE_ENUM(FUSE_I_BTIME);
+TRACE_DEFINE_ENUM(FUSE_I_CACHE_IO_MODE);
+TRACE_DEFINE_ENUM(FUSE_I_EXCLUSIVE);
+TRACE_DEFINE_ENUM(FUSE_I_IOMAP);
+
+#define FUSE_IFLAG_STRINGS \
+	{ 1 << FUSE_I_ADVISE_RDPLUS,		"advise_rdplus" }, \
+	{ 1 << FUSE_I_INIT_RDPLUS,		"init_rdplus" }, \
+	{ 1 << FUSE_I_SIZE_UNSTABLE,		"size_unstable" }, \
+	{ 1 << FUSE_I_BAD,			"bad" }, \
+	{ 1 << FUSE_I_BTIME,			"btime" }, \
+	{ 1 << FUSE_I_CACHE_IO_MODE,		"cacheio" }, \
+	{ 1 << FUSE_I_EXCLUSIVE,		"excl" }, \
+	{ 1 << FUSE_I_IOMAP,			"iomap" }
+
 DECLARE_EVENT_CLASS(fuse_iomap_check_class,
 	TP_PROTO(const char *func, int line, const char *condition),
 
@@ -488,6 +507,31 @@ TRACE_EVENT(fuse_iomap_dev_add,
 		  __entry->fd,
 		  __entry->flags)
 );
+
+DECLARE_EVENT_CLASS(fuse_inode_state_class,
+	TP_PROTO(const struct inode *inode),
+	TP_ARGS(inode),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		__field(unsigned long,		state)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->state		=	fi->state;
+	),
+
+	TP_printk(FUSE_INODE_FMT " state (%s)",
+		  FUSE_INODE_PRINTK_ARGS,
+		  __print_flags(__entry->state, "|", FUSE_IFLAG_STRINGS))
+);
+#define DEFINE_FUSE_INODE_STATE_EVENT(name)	\
+DEFINE_EVENT(fuse_inode_state_class, name,	\
+	TP_PROTO(const struct inode *inode),	\
+	TP_ARGS(inode))
+DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_init_inode);
+DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_evict_inode);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 39c9239c64435a..dccfc9a2c9847c 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -651,15 +651,21 @@ void fuse_iomap_init_inode(struct inode *inode, struct fuse_attr *attr)
 		return;
 	}
 
-	if (!S_ISREG(inode->i_mode))
+	if (!S_ISREG(inode->i_mode)) {
+		trace_fuse_iomap_init_inode(inode);
 		return;
+	}
 
 	fuse_inode_set_iomap(inode);
+
+	trace_fuse_iomap_init_inode(inode);
 }
 
 void fuse_iomap_evict_inode(struct inode *inode)
 {
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_evict_inode(inode);
+
 	fuse_inode_clear_iomap(inode);
 }


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 11/33] fuse: isolate the other regular file IO paths from iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (9 preceding siblings ...)
  2026-02-23 23:11   ` [PATCH 10/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:11   ` Darrick J. Wong
  2026-02-23 23:11   ` [PATCH 12/33] fuse: implement basic iomap reporting such as FIEMAP and SEEK_{DATA,HOLE} Darrick J. Wong
                     ` (21 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:11 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

iomap completely takes over all regular file IO, so we don't need to
access any of the other mechanisms at all.  Gate them off so that we can
eventually overlay them with a union to save space in struct fuse_inode.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/dir.c    |   14 +++++++++-----
 fs/fuse/file.c   |   18 +++++++++++++-----
 fs/fuse/inode.c  |    3 ++-
 fs/fuse/iomode.c |    3 ++-
 4 files changed, 26 insertions(+), 12 deletions(-)


diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 10db4dc046930f..138f8abbe42b4c 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -2196,6 +2196,7 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	FUSE_ARGS(args);
 	struct fuse_setattr_in inarg;
 	struct fuse_attr_out outarg;
+	const bool is_iomap = fuse_inode_has_iomap(inode);
 	bool is_truncate = false;
 	bool is_wb = fc->writeback_cache && S_ISREG(inode->i_mode);
 	loff_t oldsize;
@@ -2253,12 +2254,15 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 		if (err)
 			return err;
 
-		fuse_set_nowrite(inode);
-		fuse_release_nowrite(inode);
+		if (!is_iomap) {
+			fuse_set_nowrite(inode);
+			fuse_release_nowrite(inode);
+		}
 	}
 
 	if (is_truncate) {
-		fuse_set_nowrite(inode);
+		if (!is_iomap)
+			fuse_set_nowrite(inode);
 		set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
 		if (trust_local_cmtime && attr->ia_size != inode->i_size)
 			attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
@@ -2330,7 +2334,7 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	if (!is_wb || is_truncate)
 		i_size_write(inode, outarg.attr.size);
 
-	if (is_truncate) {
+	if (is_truncate && !is_iomap) {
 		/* NOTE: this may release/reacquire fi->lock */
 		__fuse_release_nowrite(inode);
 	}
@@ -2354,7 +2358,7 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	return 0;
 
 error:
-	if (is_truncate)
+	if (is_truncate && !is_iomap)
 		fuse_release_nowrite(inode);
 
 	clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 4a7b0c190aa8e4..c73536e29f1c96 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -251,6 +251,7 @@ static int fuse_open(struct inode *inode, struct file *file)
 	struct fuse_conn *fc = fm->fc;
 	struct fuse_file *ff;
 	int err;
+	const bool is_iomap = fuse_inode_has_iomap(inode);
 	bool is_truncate = (file->f_flags & O_TRUNC) && fc->atomic_o_trunc;
 	bool is_wb_truncate = is_truncate && fc->writeback_cache;
 	bool dax_truncate = is_truncate && FUSE_IS_DAX(inode);
@@ -272,7 +273,7 @@ static int fuse_open(struct inode *inode, struct file *file)
 			goto out_inode_unlock;
 	}
 
-	if (is_wb_truncate || dax_truncate)
+	if ((is_wb_truncate || dax_truncate) && !is_iomap)
 		fuse_set_nowrite(inode);
 
 	err = fuse_do_open(fm, get_node_id(inode), file, false);
@@ -285,7 +286,7 @@ static int fuse_open(struct inode *inode, struct file *file)
 			fuse_truncate_update_attr(inode, file);
 	}
 
-	if (is_wb_truncate || dax_truncate)
+	if ((is_wb_truncate || dax_truncate) && !is_iomap)
 		fuse_release_nowrite(inode);
 	if (!err) {
 		if (is_truncate)
@@ -533,12 +534,14 @@ static int fuse_fsync(struct file *file, loff_t start, loff_t end,
 {
 	struct inode *inode = file->f_mapping->host;
 	struct fuse_conn *fc = get_fuse_conn(inode);
+	const bool need_sync_writes = !fuse_inode_has_iomap(inode);
 	int err;
 
 	if (fuse_is_bad(inode))
 		return -EIO;
 
-	inode_lock(inode);
+	if (need_sync_writes)
+		inode_lock(inode);
 
 	/*
 	 * Start writeback against all dirty pages of the inode, then
@@ -549,7 +552,8 @@ static int fuse_fsync(struct file *file, loff_t start, loff_t end,
 	if (err)
 		goto out;
 
-	fuse_sync_writes(inode);
+	if (need_sync_writes)
+		fuse_sync_writes(inode);
 
 	/*
 	 * Due to implementation of fuse writeback
@@ -573,7 +577,8 @@ static int fuse_fsync(struct file *file, loff_t start, loff_t end,
 		err = 0;
 	}
 out:
-	inode_unlock(inode);
+	if (need_sync_writes)
+		inode_unlock(inode);
 
 	return err;
 }
@@ -2010,6 +2015,9 @@ static struct fuse_file *__fuse_write_file_get(struct fuse_inode *fi)
 {
 	struct fuse_file *ff;
 
+	if (fuse_inode_has_iomap(&fi->inode))
+		return NULL;
+
 	spin_lock(&fi->lock);
 	ff = list_first_entry_or_null(&fi->write_files, struct fuse_file,
 				      write_entry);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 27699a6c11f66b..fae33371c33da6 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -192,7 +192,8 @@ static void fuse_evict_inode(struct inode *inode)
 		if (inode->i_nlink > 0)
 			atomic64_inc(&fc->evict_ctr);
 	}
-	if (S_ISREG(inode->i_mode) && !fuse_is_bad(inode)) {
+	if (S_ISREG(inode->i_mode) && !fuse_is_bad(inode) &&
+	    !fuse_inode_has_iomap(inode)) {
 		WARN_ON(fi->iocachectr != 0);
 		WARN_ON(!list_empty(&fi->write_files));
 		WARN_ON(!list_empty(&fi->queued_writes));
diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c
index 3728933188f307..9be9ae3520003e 100644
--- a/fs/fuse/iomode.c
+++ b/fs/fuse/iomode.c
@@ -6,6 +6,7 @@
  */
 
 #include "fuse_i.h"
+#include "fuse_iomap.h"
 
 #include <linux/kernel.h>
 #include <linux/sched.h>
@@ -203,7 +204,7 @@ int fuse_file_io_open(struct file *file, struct inode *inode)
 	 * io modes are not relevant with DAX and with server that does not
 	 * implement open.
 	 */
-	if (FUSE_IS_DAX(inode) || !ff->args)
+	if (fuse_inode_has_iomap(inode) || FUSE_IS_DAX(inode) || !ff->args)
 		return 0;
 
 	/*


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 12/33] fuse: implement basic iomap reporting such as FIEMAP and SEEK_{DATA,HOLE}
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (10 preceding siblings ...)
  2026-02-23 23:11   ` [PATCH 11/33] fuse: isolate the other regular file IO paths from iomap Darrick J. Wong
@ 2026-02-23 23:11   ` Darrick J. Wong
  2026-02-23 23:12   ` [PATCH 13/33] fuse_trace: " Darrick J. Wong
                     ` (20 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:11 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Implement the basic file mapping reporting functions like FIEMAP, BMAP,
and SEEK_DATA/HOLE.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.h |    8 ++++++
 fs/fuse/dir.c        |    1 +
 fs/fuse/file.c       |   13 ++++++++++
 fs/fuse/fuse_iomap.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 89 insertions(+), 1 deletion(-)


diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 34f2c75416eb62..8ba30a496545f5 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -33,6 +33,11 @@ static inline bool fuse_inode_has_iomap(const struct inode *inode)
 
 	return test_bit(FUSE_I_IOMAP, &fi->state);
 }
+
+int fuse_iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		      u64 start, u64 length);
+loff_t fuse_iomap_lseek(struct file *file, loff_t offset, int whence);
+sector_t fuse_iomap_bmap(struct address_space *mapping, sector_t block);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -41,6 +46,9 @@ static inline bool fuse_inode_has_iomap(const struct inode *inode)
 # define fuse_iomap_init_inode(...)		((void)0)
 # define fuse_iomap_evict_inode(...)		((void)0)
 # define fuse_inode_has_iomap(...)		(false)
+# define fuse_iomap_fiemap			NULL
+# define fuse_iomap_lseek(...)			(-ENOSYS)
+# define fuse_iomap_bmap(...)			(-ENOSYS)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 138f8abbe42b4c..e16facbde126ef 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -2501,6 +2501,7 @@ static const struct inode_operations fuse_common_inode_operations = {
 	.set_acl	= fuse_set_acl,
 	.fileattr_get	= fuse_fileattr_get,
 	.fileattr_set	= fuse_fileattr_set,
+	.fiemap		= fuse_iomap_fiemap,
 };
 
 static const struct inode_operations fuse_symlink_inode_operations = {
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index c73536e29f1c96..e81571aaef15fe 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2588,6 +2588,12 @@ static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
 	struct fuse_bmap_out outarg;
 	int err;
 
+	if (fuse_inode_has_iomap(inode)) {
+		sector_t alt_sec = fuse_iomap_bmap(mapping, block);
+		if (alt_sec > 0)
+			return alt_sec;
+	}
+
 	if (!inode->i_sb->s_bdev || fm->fc->no_bmap)
 		return 0;
 
@@ -2623,6 +2629,13 @@ static loff_t fuse_lseek(struct file *file, loff_t offset, int whence)
 	struct fuse_lseek_out outarg;
 	int err;
 
+	if (fuse_inode_has_iomap(inode)) {
+		loff_t alt_pos = fuse_iomap_lseek(file, offset, whence);
+
+		if (alt_pos != -ENOSYS)
+			return alt_pos;
+	}
+
 	if (fm->fc->no_lseek)
 		goto fallback;
 
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index dccfc9a2c9847c..32ddf2fa6bdf78 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -4,6 +4,7 @@
  * Author: Darrick J. Wong <djwong@kernel.org>
  */
 #include <linux/iomap.h>
+#include <linux/fiemap.h>
 #include "fuse_i.h"
 #include "fuse_trace.h"
 #include "fuse_iomap.h"
@@ -539,7 +540,7 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
 	return 0;
 }
 
-const struct iomap_ops fuse_iomap_ops = {
+static const struct iomap_ops fuse_iomap_ops = {
 	.iomap_begin		= fuse_iomap_begin,
 	.iomap_end		= fuse_iomap_end,
 };
@@ -669,3 +670,68 @@ void fuse_iomap_evict_inode(struct inode *inode)
 
 	fuse_inode_clear_iomap(inode);
 }
+
+int fuse_iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		      u64 start, u64 count)
+{
+	struct fuse_conn *fc = get_fuse_conn(inode);
+	int error;
+
+	/*
+	 * We are called directly from the vfs so we need to check per-inode
+	 * support here explicitly.
+	 */
+	if (!fuse_inode_has_iomap(inode))
+		return -EOPNOTSUPP;
+
+	if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
+		return -EOPNOTSUPP;
+
+	if (fuse_is_bad(inode))
+		return -EIO;
+
+	if (!fuse_allow_current_process(fc))
+		return -EACCES;
+
+	inode_lock_shared(inode);
+	error = iomap_fiemap(inode, fieinfo, start, count, &fuse_iomap_ops);
+	inode_unlock_shared(inode);
+
+	return error;
+}
+
+sector_t fuse_iomap_bmap(struct address_space *mapping, sector_t block)
+{
+	ASSERT(fuse_inode_has_iomap(mapping->host));
+
+	return iomap_bmap(mapping, block, &fuse_iomap_ops);
+}
+
+loff_t fuse_iomap_lseek(struct file *file, loff_t offset, int whence)
+{
+	struct inode *inode = file->f_mapping->host;
+	struct fuse_conn *fc = get_fuse_conn(inode);
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	if (fuse_is_bad(inode))
+		return -EIO;
+
+	if (!fuse_allow_current_process(fc))
+		return -EACCES;
+
+	switch (whence) {
+	case SEEK_HOLE:
+		offset = iomap_seek_hole(inode, offset, &fuse_iomap_ops);
+		break;
+	case SEEK_DATA:
+		offset = iomap_seek_data(inode, offset, &fuse_iomap_ops);
+		break;
+	default:
+		return generic_file_llseek(file, offset, whence);
+	}
+
+	if (offset < 0)
+		return offset;
+	return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 13/33] fuse_trace: implement basic iomap reporting such as FIEMAP and SEEK_{DATA,HOLE}
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (11 preceding siblings ...)
  2026-02-23 23:11   ` [PATCH 12/33] fuse: implement basic iomap reporting such as FIEMAP and SEEK_{DATA,HOLE} Darrick J. Wong
@ 2026-02-23 23:12   ` Darrick J. Wong
  2026-02-23 23:12   ` [PATCH 14/33] fuse: implement direct IO with iomap Darrick J. Wong
                     ` (19 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:12 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    4 ++++
 2 files changed, 50 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index fac981e2a30df0..730ab8bce44450 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -532,6 +532,52 @@ DEFINE_EVENT(fuse_inode_state_class, name,	\
 	TP_ARGS(inode))
 DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_init_inode);
 DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_evict_inode);
+
+TRACE_EVENT(fuse_iomap_fiemap,
+	TP_PROTO(const struct inode *inode, u64 start, u64 count,
+		unsigned int flags),
+
+	TP_ARGS(inode, start, count, flags),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(unsigned int,		flags)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	start;
+		__entry->length		=	count;
+		__entry->flags		=	flags;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT("fiemap") " flags 0x%x",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __entry->flags)
+);
+
+TRACE_EVENT(fuse_iomap_lseek,
+	TP_PROTO(const struct inode *inode, loff_t offset, int whence),
+
+	TP_ARGS(inode, offset, whence),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		__field(loff_t,			offset)
+		__field(int,			whence)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	offset;
+		__entry->whence		=	whence;
+	),
+
+	TP_printk(FUSE_INODE_FMT " offset 0x%llx whence %d",
+		  FUSE_INODE_PRINTK_ARGS,
+		  __entry->offset,
+		  __entry->whence)
+);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 32ddf2fa6bdf78..be922888ae9e8a 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -693,6 +693,8 @@ int fuse_iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	if (!fuse_allow_current_process(fc))
 		return -EACCES;
 
+	trace_fuse_iomap_fiemap(inode, start, count, fieinfo->fi_flags);
+
 	inode_lock_shared(inode);
 	error = iomap_fiemap(inode, fieinfo, start, count, &fuse_iomap_ops);
 	inode_unlock_shared(inode);
@@ -720,6 +722,8 @@ loff_t fuse_iomap_lseek(struct file *file, loff_t offset, int whence)
 	if (!fuse_allow_current_process(fc))
 		return -EACCES;
 
+	trace_fuse_iomap_lseek(inode, offset, whence);
+
 	switch (whence) {
 	case SEEK_HOLE:
 		offset = iomap_seek_hole(inode, offset, &fuse_iomap_ops);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 14/33] fuse: implement direct IO with iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (12 preceding siblings ...)
  2026-02-23 23:12   ` [PATCH 13/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:12   ` Darrick J. Wong
  2026-02-23 23:12   ` [PATCH 15/33] fuse_trace: " Darrick J. Wong
                     ` (18 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:12 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Start implementing the fuse-iomap file I/O paths by adding direct I/O
support and all the signalling flags that come with it.  Buffered I/O
is much more complicated, so we leave that to a subsequent patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h          |   20 +++
 fs/fuse/fuse_iomap.h      |   18 ++
 include/uapi/linux/fuse.h |   27 ++++
 fs/fuse/dir.c             |   13 ++
 fs/fuse/file.c            |   29 ++++
 fs/fuse/fuse_iomap.c      |  334 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |    3 
 fs/fuse/iomode.c          |    2 
 8 files changed, 440 insertions(+), 6 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 011b252a437855..d1724bf8e87b93 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -188,6 +188,11 @@ struct fuse_inode {
 
 			/* waitq for direct-io completion */
 			wait_queue_head_t direct_io_waitq;
+
+#ifdef CONFIG_FUSE_IOMAP
+			/* file size as reported by fuse server */
+			loff_t i_disk_size;
+#endif
 		};
 
 		/* readdir cache (directory only) */
@@ -656,6 +661,16 @@ struct fuse_sync_bucket {
 	struct rcu_head rcu;
 };
 
+#ifdef CONFIG_FUSE_IOMAP
+struct fuse_iomap_conn {
+	/* fuse server doesn't implement iomap_end */
+	unsigned int no_end:1;
+
+	/* fuse server doesn't implement iomap_ioend */
+	unsigned int no_ioend:1;
+};
+#endif
+
 /**
  * A Fuse connection.
  *
@@ -1007,6 +1022,11 @@ struct fuse_conn {
 	struct idr backing_files_map;
 #endif
 
+#ifdef CONFIG_FUSE_IOMAP
+	/** iomap information */
+	struct fuse_iomap_conn iomap_conn;
+#endif
+
 #ifdef CONFIG_FUSE_IO_URING
 	/**  uring connection information*/
 	struct fuse_ring *ring;
diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 8ba30a496545f5..476e1b869d1906 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -38,6 +38,17 @@ int fuse_iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 		      u64 start, u64 length);
 loff_t fuse_iomap_lseek(struct file *file, loff_t offset, int whence);
 sector_t fuse_iomap_bmap(struct address_space *mapping, sector_t block);
+
+void fuse_iomap_open(struct inode *inode, struct file *file);
+int fuse_iomap_finish_open(const struct fuse_file *ff,
+			   const struct inode *inode);
+void fuse_iomap_open_truncate(struct inode *inode);
+
+void fuse_iomap_set_disk_size(struct fuse_inode *fi, loff_t newsize);
+int fuse_iomap_setsize_finish(struct inode *inode, loff_t newsize);
+
+ssize_t fuse_iomap_read_iter(struct kiocb *iocb, struct iov_iter *to);
+ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -49,6 +60,13 @@ sector_t fuse_iomap_bmap(struct address_space *mapping, sector_t block);
 # define fuse_iomap_fiemap			NULL
 # define fuse_iomap_lseek(...)			(-ENOSYS)
 # define fuse_iomap_bmap(...)			(-ENOSYS)
+# define fuse_iomap_open(...)			((void)0)
+# define fuse_iomap_finish_open(...)		(-ENOSYS)
+# define fuse_iomap_open_truncate(...)		((void)0)
+# define fuse_iomap_set_disk_size(...)		((void)0)
+# define fuse_iomap_setsize_finish(...)		(-ENOSYS)
+# define fuse_iomap_read_iter(...)		(-ENOSYS)
+# define fuse_iomap_write_iter(...)		(-ENOSYS)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 88f76f4be749a7..543965b2f8fb37 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -677,6 +677,7 @@ enum fuse_opcode {
 	FUSE_STATX		= 52,
 	FUSE_COPY_FILE_RANGE_64	= 53,
 
+	FUSE_IOMAP_IOEND	= 4093,
 	FUSE_IOMAP_BEGIN	= 4094,
 	FUSE_IOMAP_END		= 4095,
 
@@ -1411,4 +1412,30 @@ struct fuse_iomap_end_in {
 	struct fuse_iomap_io	map;
 };
 
+/* out of place write extent */
+#define FUSE_IOMAP_IOEND_SHARED		(1U << 0)
+/* unwritten extent */
+#define FUSE_IOMAP_IOEND_UNWRITTEN	(1U << 1)
+/* don't merge into previous ioend */
+#define FUSE_IOMAP_IOEND_BOUNDARY	(1U << 2)
+/* is direct I/O */
+#define FUSE_IOMAP_IOEND_DIRECT		(1U << 3)
+/* is append ioend */
+#define FUSE_IOMAP_IOEND_APPEND		(1U << 4)
+
+struct fuse_iomap_ioend_in {
+	uint32_t flags;		/* FUSE_IOMAP_IOEND_* */
+	int32_t error;		/* negative errno or 0 */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+	uint64_t pos;		/* file position, in bytes */
+	uint64_t new_addr;	/* disk offset of new mapping, in bytes */
+	uint64_t written;	/* bytes processed */
+	uint32_t dev;		/* device cookie */
+	uint32_t pad;		/* zero */
+};
+
+struct fuse_iomap_ioend_out {
+	uint64_t newsize;	/* new ondisk size */
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index e16facbde126ef..dcf5ccbc57c7be 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -907,6 +907,10 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
 		goto out_acl_release;
 
 	fuse_dir_changed(dir);
+
+	if (fuse_inode_has_iomap(inode))
+		fuse_iomap_open(inode, file);
+
 	err = generic_file_open(inode, file);
 	if (!err) {
 		file->private_data = ff;
@@ -1948,6 +1952,9 @@ static int fuse_dir_open(struct inode *inode, struct file *file)
 	if (fuse_is_bad(inode))
 		return -EIO;
 
+	if (fuse_inode_has_iomap(inode))
+		fuse_iomap_open(inode, file);
+
 	err = generic_file_open(inode, file);
 	if (err)
 		return err;
@@ -2308,6 +2315,12 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 		goto error;
 	}
 
+	if (is_iomap && is_truncate) {
+		err = fuse_iomap_setsize_finish(inode, outarg.attr.size);
+		if (err)
+			goto error;
+	}
+
 	spin_lock(&fi->lock);
 	/* the kernel maintains i_mtime locally */
 	if (trust_local_cmtime) {
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index e81571aaef15fe..ae320026f0648f 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -216,7 +216,10 @@ int fuse_finish_open(struct inode *inode, struct file *file)
 	struct fuse_conn *fc = get_fuse_conn(inode);
 	int err;
 
-	err = fuse_file_io_open(file, inode);
+	if (fuse_inode_has_iomap(inode))
+		err = fuse_iomap_finish_open(ff, inode);
+	else
+		err = fuse_file_io_open(file, inode);
 	if (err)
 		return err;
 
@@ -259,6 +262,9 @@ static int fuse_open(struct inode *inode, struct file *file)
 	if (fuse_is_bad(inode))
 		return -EIO;
 
+	if (is_iomap)
+		fuse_iomap_open(inode, file);
+
 	err = generic_file_open(inode, file);
 	if (err)
 		return err;
@@ -289,9 +295,11 @@ static int fuse_open(struct inode *inode, struct file *file)
 	if ((is_wb_truncate || dax_truncate) && !is_iomap)
 		fuse_release_nowrite(inode);
 	if (!err) {
-		if (is_truncate)
+		if (is_truncate) {
 			truncate_pagecache(inode, 0);
-		else if (!(ff->open_flags & FOPEN_KEEP_CACHE))
+			if (is_iomap)
+				fuse_iomap_open_truncate(inode);
+		} else if (!(ff->open_flags & FOPEN_KEEP_CACHE))
 			invalidate_inode_pages2(inode->i_mapping);
 	}
 	if (dax_truncate)
@@ -1822,6 +1830,9 @@ static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
 	if (fuse_is_bad(inode))
 		return -EIO;
 
+	if (fuse_inode_has_iomap(inode))
+		return fuse_iomap_read_iter(iocb, to);
+
 	if (FUSE_IS_DAX(inode))
 		return fuse_dax_read_iter(iocb, to);
 
@@ -1843,6 +1854,9 @@ static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	if (fuse_is_bad(inode))
 		return -EIO;
 
+	if (fuse_inode_has_iomap(inode))
+		return fuse_iomap_write_iter(iocb, from);
+
 	if (FUSE_IS_DAX(inode))
 		return fuse_dax_write_iter(iocb, from);
 
@@ -2955,7 +2969,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
 		.length = length,
 		.mode = mode
 	};
+	loff_t newsize = 0;
 	int err;
+	const bool is_iomap = fuse_inode_has_iomap(inode);
 	bool block_faults = FUSE_IS_DAX(inode) &&
 		(!(mode & FALLOC_FL_KEEP_SIZE) ||
 		 (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)));
@@ -2988,6 +3004,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
 		err = inode_newsize_ok(inode, offset + length);
 		if (err)
 			goto out;
+		newsize = offset + length;
 	}
 
 	err = file_modified(file);
@@ -3012,6 +3029,12 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
 
 	/* we could have extended the file */
 	if (!(mode & FALLOC_FL_KEEP_SIZE)) {
+		if (is_iomap && newsize > 0) {
+			err = fuse_iomap_setsize_finish(inode, newsize);
+			if (err)
+				goto out;
+		}
+
 		if (fuse_write_update_attr(inode, offset + length, length))
 			file_update_time(file);
 	}
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index be922888ae9e8a..4816e26a1ac76b 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -476,10 +476,15 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 }
 
 /* Decide if we send FUSE_IOMAP_END to the fuse server */
-static bool fuse_should_send_iomap_end(const struct iomap *iomap,
+static bool fuse_should_send_iomap_end(const struct fuse_mount *fm,
+				       const struct iomap *iomap,
 				       unsigned int opflags, loff_t count,
 				       ssize_t written)
 {
+	/* Not implemented on fuse server */
+	if (fm->fc->iomap_conn.no_end)
+		return false;
+
 	/* fuse server demanded an iomap_end call. */
 	if (iomap->flags & FUSE_IOMAP_F_WANT_IOMAP_END)
 		return true;
@@ -504,7 +509,7 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
 	struct fuse_mount *fm = get_fuse_mount(inode);
 	int err;
 
-	if (fuse_should_send_iomap_end(iomap, opflags, count, written)) {
+	if (fuse_should_send_iomap_end(fm, iomap, opflags, count, written)) {
 		struct fuse_iomap_end_in inarg = {
 			.opflags = fuse_iomap_op_to_server(opflags),
 			.attr_ino = fi->orig_ino,
@@ -529,6 +534,7 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
 			 * libfuse returns ENOSYS for servers that don't
 			 * implement iomap_end
 			 */
+			fm->fc->iomap_conn.no_end = 1;
 			err = 0;
 		}
 		if (err) {
@@ -545,6 +551,122 @@ static const struct iomap_ops fuse_iomap_ops = {
 	.iomap_end		= fuse_iomap_end,
 };
 
+static inline bool
+fuse_should_send_iomap_ioend(const struct fuse_mount *fm,
+			     const struct fuse_iomap_ioend_in *inarg)
+{
+	/* Not implemented on fuse server */
+	if (fm->fc->iomap_conn.no_ioend)
+		return false;
+
+	/* Always send an ioend for errors. */
+	if (inarg->error)
+		return true;
+
+	/* Send an ioend if we performed an IO involving metadata changes. */
+	return inarg->written > 0 &&
+	       (inarg->flags & (FUSE_IOMAP_IOEND_SHARED |
+				FUSE_IOMAP_IOEND_UNWRITTEN |
+				FUSE_IOMAP_IOEND_APPEND));
+}
+
+int
+fuse_iomap_setsize_finish(
+	struct inode		*inode,
+	loff_t			newsize)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	fi->i_disk_size = newsize;
+	return 0;
+}
+
+/*
+ * Fast and loose check if this write could update the on-disk inode size.
+ */
+static inline bool fuse_ioend_is_append(const struct fuse_inode *fi,
+					loff_t pos, size_t written)
+{
+	return pos + written > fi->i_disk_size;
+}
+
+static int fuse_iomap_ioend(struct inode *inode, loff_t pos, size_t written,
+			    int error, unsigned ioendflags,
+			    struct block_device *bdev, sector_t new_addr)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_mount *fm = get_fuse_mount(inode);
+	struct fuse_iomap_ioend_in inarg = {
+		.flags = ioendflags,
+		.error = error,
+		.attr_ino = fi->orig_ino,
+		.pos = pos,
+		.written = written,
+		.dev = fuse_iomap_find_backing_id(fm->fc, bdev),
+		.new_addr = new_addr,
+	};
+	struct fuse_iomap_ioend_out outarg = {
+		.newsize = max_t(loff_t, fi->i_disk_size, pos + written),
+	};
+
+	if (fuse_ioend_is_append(fi, pos, written))
+		inarg.flags |= FUSE_IOMAP_IOEND_APPEND;
+
+	if (fuse_should_send_iomap_ioend(fm, &inarg)) {
+		FUSE_ARGS(args);
+		int iomap_error;
+
+		args.opcode = FUSE_IOMAP_IOEND;
+		args.nodeid = get_node_id(inode);
+		args.in_numargs = 1;
+		args.in_args[0].size = sizeof(inarg);
+		args.in_args[0].value = &inarg;
+		args.out_numargs = 1;
+		args.out_args[0].size = sizeof(outarg);
+		args.out_args[0].value = &outarg;
+		iomap_error = fuse_simple_request(fm, &args);
+		switch (iomap_error) {
+		case -ENOSYS:
+			/*
+			 * fuse servers can return ENOSYS if ioend processing
+			 * is never needed for this filesystem.  Don't pass
+			 * that up to iomap.
+			 */
+			fm->fc->iomap_conn.no_ioend = 1;
+			break;
+		case 0:
+			break;
+		default:
+			/*
+			 * If the write IO failed, return the failure code to
+			 * the caller no matter what happens with the ioend.
+			 * If the write IO succeeded but the ioend did not,
+			 * pass the new error up to the caller.
+			 */
+			if (!error)
+				error = iomap_error;
+			break;
+		}
+	}
+
+	/*
+	 * Pass whatever error iomap gave us (or any new errors since then)
+	 * back to iomap.
+	 */
+	if (error)
+		return error;
+
+	/*
+	 * If there weren't any ioend errors, update the incore isize, which
+	 * confusingly takes the new i_size as "pos".
+	 */
+	fi->i_disk_size = outarg.newsize;
+	fuse_write_update_attr(inode, pos + written, written);
+	return 0;
+}
+
 static int fuse_iomap_may_admin(struct fuse_conn *fc, unsigned int flags)
 {
 	if (!fc->iomap)
@@ -739,3 +861,211 @@ loff_t fuse_iomap_lseek(struct file *file, loff_t offset, int whence)
 		return offset;
 	return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
 }
+
+void fuse_iomap_open(struct inode *inode, struct file *file)
+{
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT;
+}
+
+int fuse_iomap_finish_open(const struct fuse_file *ff,
+			   const struct inode *inode)
+{
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	/* no weird modes, iomap only handles seekable regular files */
+	if (ff->open_flags & (FOPEN_PASSTHROUGH |
+			      FOPEN_STREAM |
+			      FOPEN_NONSEEKABLE))
+		return -EINVAL;
+
+	return 0;
+}
+
+enum fuse_ilock_type {
+	SHARED,
+	EXCL,
+};
+
+static int fuse_iomap_ilock_iocb(const struct kiocb *iocb,
+				 enum fuse_ilock_type type)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+
+	if (iocb->ki_flags & IOCB_NOWAIT) {
+		switch (type) {
+		case SHARED:
+			return inode_trylock_shared(inode) ? 0 : -EAGAIN;
+		case EXCL:
+			return inode_trylock(inode) ? 0 : -EAGAIN;
+		default:
+			ASSERT(0);
+			return -EIO;
+		}
+
+		/* shut up gcc */
+		return 0;
+	}
+
+	switch (type) {
+	case SHARED:
+		inode_lock_shared(inode);
+		break;
+	case EXCL:
+		inode_lock(inode);
+		break;
+	default:
+		ASSERT(0);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static ssize_t fuse_iomap_direct_read(struct kiocb *iocb, struct iov_iter *to)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+	ssize_t ret;
+
+	if (!iov_iter_count(to))
+		return 0; /* skip atime */
+
+	ret = fuse_iomap_ilock_iocb(iocb, SHARED);
+	if (ret)
+		return ret;
+	ret = iomap_dio_rw(iocb, to, &fuse_iomap_ops, NULL, 0, NULL, 0);
+	if (ret > 0)
+		file_accessed(iocb->ki_filp);
+	inode_unlock_shared(inode);
+
+	return ret;
+}
+
+static int fuse_iomap_dio_write_end_io(struct kiocb *iocb, ssize_t written,
+				       int error, unsigned dioflags)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+	unsigned int ioendflags = FUSE_IOMAP_IOEND_DIRECT;
+
+	if (fuse_is_bad(inode))
+		return -EIO;
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	if (dioflags & IOMAP_DIO_COW)
+		ioendflags |= FUSE_IOMAP_IOEND_SHARED;
+	if (dioflags & IOMAP_DIO_UNWRITTEN)
+		ioendflags |= FUSE_IOMAP_IOEND_UNWRITTEN;
+
+	return fuse_iomap_ioend(inode, iocb->ki_pos, written, error,
+				ioendflags, NULL, FUSE_IOMAP_NULL_ADDR);
+}
+
+static const struct iomap_dio_ops fuse_iomap_dio_write_ops = {
+	.end_io		= fuse_iomap_dio_write_end_io,
+};
+
+static ssize_t
+fuse_iomap_write_checks(
+	struct kiocb		*iocb,
+	struct iov_iter		*from)
+{
+	ssize_t			error;
+
+	error = generic_write_checks(iocb, from);
+	if (error <= 0)
+		return error;
+
+	return kiocb_modified(iocb);
+}
+
+static ssize_t fuse_iomap_direct_write(struct kiocb *iocb,
+				       struct iov_iter *from)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+	loff_t blockmask = i_blocksize(inode) - 1;
+	size_t count = iov_iter_count(from);
+	unsigned int flags = IOMAP_DIO_COMP_WORK;
+	ssize_t ret;
+
+	if (!count)
+		return 0;
+
+	/*
+	 * Unaligned direct writes require zeroing of unwritten head and tail
+	 * blocks.  Extending writes require zeroing of post-EOF tail blocks.
+	 * The zeroing writes must complete before we return the direct write
+	 * to userspace.  Don't even bother trying the fast path.
+	 */
+	if ((iocb->ki_pos | count) & blockmask)
+		flags |= IOMAP_DIO_FORCE_WAIT;
+
+	ret = fuse_iomap_ilock_iocb(iocb, EXCL);
+	if (ret)
+		goto out_dsync;
+
+	ret = fuse_iomap_write_checks(iocb, from);
+	if (ret)
+		goto out_unlock;
+
+	/*
+	 * If we are doing exclusive unaligned I/O, this must be the only I/O
+	 * in-flight.  Otherwise we risk data corruption due to unwritten
+	 * extent conversions from the AIO end_io handler.  Wait for all other
+	 * I/O to drain first.
+	 */
+	if (flags & IOMAP_DIO_FORCE_WAIT)
+		inode_dio_wait(inode);
+
+	ret = iomap_dio_rw(iocb, from, &fuse_iomap_ops,
+			   &fuse_iomap_dio_write_ops, flags, NULL, 0);
+out_unlock:
+	inode_unlock(inode);
+out_dsync:
+	return ret;
+}
+
+void fuse_iomap_set_disk_size(struct fuse_inode *fi, loff_t newsize)
+{
+	if (fuse_inode_has_iomap(&fi->inode))
+		fi->i_disk_size = newsize;
+}
+
+void fuse_iomap_open_truncate(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	fi->i_disk_size = 0;
+}
+
+static inline bool fuse_iomap_force_directio(const struct kiocb *iocb)
+{
+	struct fuse_file *ff = iocb->ki_filp->private_data;
+
+	return ff->open_flags & FOPEN_DIRECT_IO;
+}
+
+ssize_t fuse_iomap_read_iter(struct kiocb *iocb, struct iov_iter *to)
+{
+	const bool force_directio = fuse_iomap_force_directio(iocb);
+
+	ASSERT(fuse_inode_has_iomap(file_inode(iocb->ki_filp)));
+
+	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio)
+		return fuse_iomap_direct_read(iocb, to);
+	return -EIO;
+}
+
+ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from)
+{
+	const bool force_directio = fuse_iomap_force_directio(iocb);
+
+	ASSERT(fuse_inode_has_iomap(file_inode(iocb->ki_filp)));
+
+	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio)
+		return fuse_iomap_direct_write(iocb, from);
+	return -EIO;
+}
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index fae33371c33da6..039a780749da30 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -303,6 +303,8 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
 	else
 		fi->cached_i_blkbits = inode->i_sb->s_blocksize_bits;
 
+	fuse_iomap_set_disk_size(fi, attr->size);
+
 	/*
 	 * Don't set the sticky bit in i_mode, unless we want the VFS
 	 * to check permissions.  This prevents failures due to the
@@ -352,6 +354,7 @@ static void fuse_change_attributes_i(struct inode *inode, struct fuse_attr *attr
 	 * inode.
 	 */
 	cache_mask = fuse_get_cache_mask(inode);
+	fuse_iomap_set_disk_size(fi, attr->size);
 	if (cache_mask & STATX_SIZE)
 		attr->size = i_size_read(inode);
 
diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c
index 9be9ae3520003e..ed666b39cf8af4 100644
--- a/fs/fuse/iomode.c
+++ b/fs/fuse/iomode.c
@@ -204,7 +204,7 @@ int fuse_file_io_open(struct file *file, struct inode *inode)
 	 * io modes are not relevant with DAX and with server that does not
 	 * implement open.
 	 */
-	if (fuse_inode_has_iomap(inode) || FUSE_IS_DAX(inode) || !ff->args)
+	if (FUSE_IS_DAX(inode) || !ff->args)
 		return 0;
 
 	/*


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 15/33] fuse_trace: implement direct IO with iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (13 preceding siblings ...)
  2026-02-23 23:12   ` [PATCH 14/33] fuse: implement direct IO with iomap Darrick J. Wong
@ 2026-02-23 23:12   ` Darrick J. Wong
  2026-02-23 23:12   ` [PATCH 16/33] fuse: implement buffered " Darrick J. Wong
                     ` (17 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:12 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.h |    5 +
 fs/fuse/fuse_trace.h |  212 +++++++++++++++++++++++++++++++++++++++++++++++++-
 fs/fuse/fuse_iomap.c |   18 ++++
 fs/fuse/trace.c      |    2 
 4 files changed, 233 insertions(+), 4 deletions(-)


diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 476e1b869d1906..07433c33535b2d 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -45,6 +45,10 @@ int fuse_iomap_finish_open(const struct fuse_file *ff,
 void fuse_iomap_open_truncate(struct inode *inode);
 
 void fuse_iomap_set_disk_size(struct fuse_inode *fi, loff_t newsize);
+static inline loff_t fuse_iomap_get_disk_size(const struct fuse_inode *fi)
+{
+	return fuse_inode_has_iomap(&fi->inode) ? fi->i_disk_size : 0;
+}
 int fuse_iomap_setsize_finish(struct inode *inode, loff_t newsize);
 
 ssize_t fuse_iomap_read_iter(struct kiocb *iocb, struct iov_iter *to);
@@ -64,6 +68,7 @@ ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from);
 # define fuse_iomap_finish_open(...)		(-ENOSYS)
 # define fuse_iomap_open_truncate(...)		((void)0)
 # define fuse_iomap_set_disk_size(...)		((void)0)
+# define fuse_iomap_get_disk_size(...)		((loff_t)0)
 # define fuse_iomap_setsize_finish(...)		(-ENOSYS)
 # define fuse_iomap_read_iter(...)		(-ENOSYS)
 # define fuse_iomap_write_iter(...)		(-ENOSYS)
diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 730ab8bce44450..a8337f5ddcf011 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -60,6 +60,7 @@
 	EM( FUSE_STATX,			"FUSE_STATX")		\
 	EM( FUSE_IOMAP_BEGIN,		"FUSE_IOMAP_BEGIN")	\
 	EM( FUSE_IOMAP_END,		"FUSE_IOMAP_END")	\
+	EM( FUSE_IOMAP_IOEND,		"FUSE_IOMAP_IOEND")	\
 	EMe(CUSE_INIT,			"CUSE_INIT")
 
 /*
@@ -84,7 +85,8 @@ OPCODES
 		__field(dev_t,			connection) \
 		__field(uint64_t,		ino) \
 		__field(uint64_t,		nodeid) \
-		__field(loff_t,			isize)
+		__field(loff_t,			isize) \
+		__field(loff_t,			idisksize)
 
 #define FUSE_INODE_ASSIGN(inode, fi, fm) \
 		const struct fuse_inode *fi = get_fuse_inode(inode); \
@@ -93,16 +95,18 @@ OPCODES
 		__entry->connection	=	(fm)->fc->dev; \
 		__entry->ino		=	(fi)->orig_ino; \
 		__entry->nodeid		=	(fi)->nodeid; \
-		__entry->isize		=	i_size_read(inode)
+		__entry->isize		=	i_size_read(inode); \
+		__entry->idisksize	=	fuse_iomap_get_disk_size(fi)
 
 #define FUSE_INODE_FMT \
-		"connection %u ino %llu nodeid %llu isize 0x%llx"
+		"connection %u ino %llu nodeid %llu isize 0x%llx idisksize 0x%llx"
 
 #define FUSE_INODE_PRINTK_ARGS \
 		__entry->connection, \
 		__entry->ino, \
 		__entry->nodeid, \
-		__entry->isize
+		__entry->isize, \
+		__entry->idisksize
 
 #define FUSE_FILE_RANGE_FIELDS(prefix) \
 		__field(loff_t,			prefix##offset) \
@@ -300,6 +304,17 @@ DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
 	{ FUSE_IOMAP_TYPE_UNWRITTEN,		"unwritten" }, \
 	{ FUSE_IOMAP_TYPE_INLINE,		"inline" }
 
+#define FUSE_IOMAP_IOEND_STRINGS \
+	{ FUSE_IOMAP_IOEND_SHARED,		"shared" }, \
+	{ FUSE_IOMAP_IOEND_UNWRITTEN,		"unwritten" }, \
+	{ FUSE_IOMAP_IOEND_BOUNDARY,		"boundary" }, \
+	{ FUSE_IOMAP_IOEND_DIRECT,		"direct" }, \
+	{ FUSE_IOMAP_IOEND_APPEND,		"append" }
+
+#define IOMAP_DIOEND_STRINGS \
+	{ IOMAP_DIO_UNWRITTEN,			"unwritten" }, \
+	{ IOMAP_DIO_COW,			"cow" }
+
 TRACE_DEFINE_ENUM(FUSE_I_ADVISE_RDPLUS);
 TRACE_DEFINE_ENUM(FUSE_I_INIT_RDPLUS);
 TRACE_DEFINE_ENUM(FUSE_I_SIZE_UNSTABLE);
@@ -484,6 +499,75 @@ TRACE_EVENT(fuse_iomap_end_error,
 		  __entry->error)
 );
 
+TRACE_EVENT(fuse_iomap_ioend,
+	TP_PROTO(const struct inode *inode,
+		 const struct fuse_iomap_ioend_in *inarg),
+
+	TP_ARGS(inode, inarg),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(unsigned,		ioendflags)
+		__field(int,			error)
+		__field(uint32_t,		dev)
+		__field(uint64_t,		new_addr)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	inarg->pos;
+		__entry->length		=	inarg->written;
+		__entry->ioendflags	=	inarg->flags;
+		__entry->error		=	inarg->error;
+		__entry->dev		=	inarg->dev;
+		__entry->new_addr	=	inarg->new_addr;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() " ioendflags (%s) error %d dev %u new_addr 0x%llx",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __print_flags(__entry->ioendflags, "|", FUSE_IOMAP_IOEND_STRINGS),
+		  __entry->error,
+		  __entry->dev,
+		  __entry->new_addr)
+);
+
+TRACE_EVENT(fuse_iomap_ioend_error,
+	TP_PROTO(const struct inode *inode,
+		 const struct fuse_iomap_ioend_in *inarg,
+		 const struct fuse_iomap_ioend_out *outarg,
+		 int error),
+
+	TP_ARGS(inode, inarg, outarg, error),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(unsigned,		ioendflags)
+		__field(int,			error)
+		__field(uint32_t,		dev)
+		__field(uint64_t,		new_addr)
+		__field(uint64_t,		new_size)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	inarg->pos;
+		__entry->length		=	inarg->written;
+		__entry->ioendflags	=	inarg->flags;
+		__entry->error		=	error;
+		__entry->dev		=	inarg->dev;
+		__entry->new_addr	=	inarg->new_addr;
+		__entry->new_size	=	outarg->newsize;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() " ioendflags (%s) error %d dev %u new_addr 0x%llx new_size 0x%llx",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __print_flags(__entry->ioendflags, "|", FUSE_IOMAP_IOEND_STRINGS),
+		  __entry->error,
+		  __entry->dev,
+		  __entry->new_addr,
+		  __entry->new_size)
+);
+
 TRACE_EVENT(fuse_iomap_dev_add,
 	TP_PROTO(const struct fuse_conn *fc,
 		 const struct fuse_backing_map *map),
@@ -578,6 +662,126 @@ TRACE_EVENT(fuse_iomap_lseek,
 		  __entry->offset,
 		  __entry->whence)
 );
+
+DECLARE_EVENT_CLASS(fuse_iomap_file_io_class,
+	TP_PROTO(const struct kiocb *iocb, const struct iov_iter *iter),
+	TP_ARGS(iocb, iter),
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+	),
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(file_inode(iocb->ki_filp), fi, fm);
+		__entry->offset		=	iocb->ki_pos;
+		__entry->length		=	iov_iter_count(iter);
+	),
+	TP_printk(FUSE_IO_RANGE_FMT(),
+		  FUSE_IO_RANGE_PRINTK_ARGS())
+)
+#define DEFINE_FUSE_IOMAP_FILE_IO_EVENT(name)		\
+DEFINE_EVENT(fuse_iomap_file_io_class, name,		\
+	TP_PROTO(const struct kiocb *iocb, const struct iov_iter *iter), \
+	TP_ARGS(iocb, iter))
+DEFINE_FUSE_IOMAP_FILE_IO_EVENT(fuse_iomap_direct_read);
+DEFINE_FUSE_IOMAP_FILE_IO_EVENT(fuse_iomap_direct_write);
+
+DECLARE_EVENT_CLASS(fuse_iomap_file_ioend_class,
+	TP_PROTO(const struct kiocb *iocb, const struct iov_iter *iter,
+		 ssize_t ret),
+	TP_ARGS(iocb, iter, ret),
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(ssize_t,		ret)
+	),
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(file_inode(iocb->ki_filp), fi, fm);
+		__entry->offset		=	iocb->ki_pos;
+		__entry->length		=	iov_iter_count(iter);
+		__entry->ret		=	ret;
+	),
+	TP_printk(FUSE_IO_RANGE_FMT() " ret 0x%zx",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __entry->ret)
+)
+#define DEFINE_FUSE_IOMAP_FILE_IOEND_EVENT(name)	\
+DEFINE_EVENT(fuse_iomap_file_ioend_class, name,		\
+	TP_PROTO(const struct kiocb *iocb, const struct iov_iter *iter, \
+		 ssize_t ret), \
+	TP_ARGS(iocb, iter, ret))
+DEFINE_FUSE_IOMAP_FILE_IOEND_EVENT(fuse_iomap_direct_read_end);
+DEFINE_FUSE_IOMAP_FILE_IOEND_EVENT(fuse_iomap_direct_write_end);
+
+TRACE_EVENT(fuse_iomap_dio_write_end_io,
+	TP_PROTO(const struct inode *inode, loff_t pos, ssize_t written,
+		 int error, unsigned flags),
+
+	TP_ARGS(inode, pos, written, error, flags),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(unsigned,		dioendflags)
+		__field(int,			error)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	pos;
+		__entry->length		=	written;
+		__entry->dioendflags	=	flags;
+		__entry->error		=	error;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() " dioendflags (%s) error %d",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __print_flags(__entry->dioendflags, "|", IOMAP_DIOEND_STRINGS),
+		  __entry->error)
+);
+
+DECLARE_EVENT_CLASS(fuse_iomap_inode_class,
+	TP_PROTO(const struct inode *inode),
+
+	TP_ARGS(inode),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+	),
+
+	TP_printk(FUSE_INODE_FMT,
+		  FUSE_INODE_PRINTK_ARGS)
+);
+#define DEFINE_FUSE_IOMAP_INODE_EVENT(name)	\
+DEFINE_EVENT(fuse_iomap_inode_class, name,	\
+	TP_PROTO(const struct inode *inode), \
+	TP_ARGS(inode))
+DEFINE_FUSE_IOMAP_INODE_EVENT(fuse_iomap_open_truncate);
+
+DECLARE_EVENT_CLASS(fuse_iomap_file_range_class,
+        TP_PROTO(const struct inode *inode, loff_t offset, loff_t length),
+
+        TP_ARGS(inode, offset, length),
+
+        TP_STRUCT__entry(
+                FUSE_IO_RANGE_FIELDS()
+        ),
+
+        TP_fast_assign(
+                FUSE_INODE_ASSIGN(inode, fi, fm);
+                __entry->offset         =       offset;
+                __entry->length         =       length;
+        ),
+
+        TP_printk(FUSE_IO_RANGE_FMT(),
+                  FUSE_IO_RANGE_PRINTK_ARGS())
+)
+#define DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(name)                \
+DEFINE_EVENT(fuse_iomap_file_range_class, name,         \
+        TP_PROTO(const struct inode *inode, loff_t offset, loff_t length), \
+        TP_ARGS(inode, offset, length))
+DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_setsize_finish);
+
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 4816e26a1ac76b..f0b5ea49b6e2ac 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -579,6 +579,8 @@ fuse_iomap_setsize_finish(
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_setsize_finish(inode, newsize, 0);
+
 	fi->i_disk_size = newsize;
 	return 0;
 }
@@ -614,6 +616,8 @@ static int fuse_iomap_ioend(struct inode *inode, loff_t pos, size_t written,
 	if (fuse_ioend_is_append(fi, pos, written))
 		inarg.flags |= FUSE_IOMAP_IOEND_APPEND;
 
+	trace_fuse_iomap_ioend(inode, &inarg);
+
 	if (fuse_should_send_iomap_ioend(fm, &inarg)) {
 		FUSE_ARGS(args);
 		int iomap_error;
@@ -639,6 +643,9 @@ static int fuse_iomap_ioend(struct inode *inode, loff_t pos, size_t written,
 		case 0:
 			break;
 		default:
+			trace_fuse_iomap_ioend_error(inode, &inarg, &outarg,
+						     iomap_error);
+
 			/*
 			 * If the write IO failed, return the failure code to
 			 * the caller no matter what happens with the ioend.
@@ -928,6 +935,8 @@ static ssize_t fuse_iomap_direct_read(struct kiocb *iocb, struct iov_iter *to)
 	struct inode *inode = file_inode(iocb->ki_filp);
 	ssize_t ret;
 
+	trace_fuse_iomap_direct_read(iocb, to);
+
 	if (!iov_iter_count(to))
 		return 0; /* skip atime */
 
@@ -939,6 +948,7 @@ static ssize_t fuse_iomap_direct_read(struct kiocb *iocb, struct iov_iter *to)
 		file_accessed(iocb->ki_filp);
 	inode_unlock_shared(inode);
 
+	trace_fuse_iomap_direct_read_end(iocb, to, ret);
 	return ret;
 }
 
@@ -953,6 +963,9 @@ static int fuse_iomap_dio_write_end_io(struct kiocb *iocb, ssize_t written,
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_dio_write_end_io(inode, iocb->ki_pos, written, error,
+					  dioflags);
+
 	if (dioflags & IOMAP_DIO_COW)
 		ioendflags |= FUSE_IOMAP_IOEND_SHARED;
 	if (dioflags & IOMAP_DIO_UNWRITTEN)
@@ -989,6 +1002,8 @@ static ssize_t fuse_iomap_direct_write(struct kiocb *iocb,
 	unsigned int flags = IOMAP_DIO_COMP_WORK;
 	ssize_t ret;
 
+	trace_fuse_iomap_direct_write(iocb, from);
+
 	if (!count)
 		return 0;
 
@@ -1023,6 +1038,7 @@ static ssize_t fuse_iomap_direct_write(struct kiocb *iocb,
 out_unlock:
 	inode_unlock(inode);
 out_dsync:
+	trace_fuse_iomap_direct_write_end(iocb, from, ret);
 	return ret;
 }
 
@@ -1038,6 +1054,8 @@ void fuse_iomap_open_truncate(struct inode *inode)
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_open_truncate(inode);
+
 	fi->i_disk_size = 0;
 }
 
diff --git a/fs/fuse/trace.c b/fs/fuse/trace.c
index c830c1c38a833c..71d444ac1e5021 100644
--- a/fs/fuse/trace.c
+++ b/fs/fuse/trace.c
@@ -6,9 +6,11 @@
 #include "dev_uring_i.h"
 #include "fuse_i.h"
 #include "fuse_dev_i.h"
+#include "fuse_iomap.h"
 #include "fuse_iomap_i.h"
 
 #include <linux/pagemap.h>
+#include <linux/iomap.h>
 
 #define CREATE_TRACE_POINTS
 #include "fuse_trace.h"


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 16/33] fuse: implement buffered IO with iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (14 preceding siblings ...)
  2026-02-23 23:12   ` [PATCH 15/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:12   ` Darrick J. Wong
  2026-02-27 18:04     ` Darrick J. Wong
  2026-02-23 23:13   ` [PATCH 17/33] fuse_trace: " Darrick J. Wong
                     ` (16 subsequent siblings)
  32 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:12 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Implement pagecache IO with iomap, complete with hooks into truncate and
fallocate so that the fuse server needn't implement disk block zeroing
of post-EOF and unaligned punch/zero regions.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h          |    7 
 fs/fuse/fuse_iomap.h      |   11 +
 include/uapi/linux/fuse.h |    5 
 fs/fuse/dir.c             |   23 +
 fs/fuse/file.c            |   61 +++-
 fs/fuse/fuse_iomap.c      |  696 ++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 772 insertions(+), 31 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index d1724bf8e87b93..b9f41c08cc8fb0 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -192,6 +192,11 @@ struct fuse_inode {
 #ifdef CONFIG_FUSE_IOMAP
 			/* file size as reported by fuse server */
 			loff_t i_disk_size;
+
+			/* pending io completions */
+			spinlock_t ioend_lock;
+			struct work_struct ioend_work;
+			struct list_head ioend_list;
 #endif
 		};
 
@@ -1741,4 +1746,6 @@ extern void fuse_sysctl_unregister(void);
 #define fuse_sysctl_unregister()	do { } while (0)
 #endif /* CONFIG_SYSCTL */
 
+sector_t fuse_bmap(struct address_space *mapping, sector_t block);
+
 #endif /* _FS_FUSE_I_H */
diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 07433c33535b2d..4b12af01ff00f5 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -53,6 +53,13 @@ int fuse_iomap_setsize_finish(struct inode *inode, loff_t newsize);
 
 ssize_t fuse_iomap_read_iter(struct kiocb *iocb, struct iov_iter *to);
 ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from);
+
+int fuse_iomap_mmap(struct file *file, struct vm_area_struct *vma);
+int fuse_iomap_setsize_start(struct inode *inode, loff_t newsize);
+int fuse_iomap_fallocate(struct file *file, int mode, loff_t offset,
+			 loff_t length, loff_t new_size);
+int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
+				 loff_t endpos);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -72,6 +79,10 @@ ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from);
 # define fuse_iomap_setsize_finish(...)		(-ENOSYS)
 # define fuse_iomap_read_iter(...)		(-ENOSYS)
 # define fuse_iomap_write_iter(...)		(-ENOSYS)
+# define fuse_iomap_mmap(...)			(-ENOSYS)
+# define fuse_iomap_setsize_start(...)		(-ENOSYS)
+# define fuse_iomap_fallocate(...)		(-ENOSYS)
+# define fuse_iomap_flush_unmap_range(...)	(-ENOSYS)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 543965b2f8fb37..71b216262c84cb 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1373,6 +1373,9 @@ struct fuse_uring_cmd_req {
 #define FUSE_IOMAP_OP_ATOMIC		(1U << 9)
 #define FUSE_IOMAP_OP_DONTCACHE		(1U << 10)
 
+/* pagecache writeback operation */
+#define FUSE_IOMAP_OP_WRITEBACK		(1U << 31)
+
 #define FUSE_IOMAP_NULL_ADDR		(-1ULL)	/* addr is not valid */
 
 struct fuse_iomap_io {
@@ -1422,6 +1425,8 @@ struct fuse_iomap_end_in {
 #define FUSE_IOMAP_IOEND_DIRECT		(1U << 3)
 /* is append ioend */
 #define FUSE_IOMAP_IOEND_APPEND		(1U << 4)
+/* is pagecache writeback */
+#define FUSE_IOMAP_IOEND_WRITEBACK	(1U << 5)
 
 struct fuse_iomap_ioend_in {
 	uint32_t flags;		/* FUSE_IOMAP_IOEND_* */
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index dcf5ccbc57c7be..fc0751deebfd20 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -2225,7 +2225,10 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 		is_truncate = true;
 	}
 
-	if (FUSE_IS_DAX(inode) && is_truncate) {
+	if (is_iomap && is_truncate) {
+		filemap_invalidate_lock(mapping);
+		fault_blocked = true;
+	} else if (FUSE_IS_DAX(inode) && is_truncate) {
 		filemap_invalidate_lock(mapping);
 		fault_blocked = true;
 		err = fuse_dax_break_layouts(inode, 0, -1);
@@ -2240,6 +2243,18 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 		WARN_ON(!(attr->ia_valid & ATTR_SIZE));
 		WARN_ON(attr->ia_size != 0);
 		if (fc->atomic_o_trunc) {
+			if (is_iomap) {
+				/*
+				 * fuse_open already set the size to zero and
+				 * truncated the pagecache, and we've since
+				 * cycled the inode locks.  Another thread
+				 * could have performed an appending write, so
+				 * we don't want to touch the file further.
+				 */
+				filemap_invalidate_unlock(mapping);
+				return 0;
+			}
+
 			/*
 			 * No need to send request to userspace, since actual
 			 * truncation has already been done by OPEN.  But still
@@ -2273,6 +2288,12 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 		set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
 		if (trust_local_cmtime && attr->ia_size != inode->i_size)
 			attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
+
+		if (is_iomap) {
+			err = fuse_iomap_setsize_start(inode, attr->ia_size);
+			if (err)
+				goto error;
+		}
 	}
 
 	memset(&inarg, 0, sizeof(inarg));
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index ae320026f0648f..0828ecb20a828c 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -402,7 +402,7 @@ static int fuse_release(struct inode *inode, struct file *file)
 	 * Dirty pages might remain despite write_inode_now() call from
 	 * fuse_flush() due to writes racing with the close.
 	 */
-	if (fc->writeback_cache)
+	if (fc->writeback_cache || fuse_inode_has_iomap(inode))
 		write_inode_now(inode, 1);
 
 	fuse_release_common(file, false);
@@ -2395,6 +2395,9 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
 	struct inode *inode = file_inode(file);
 	int rc;
 
+	if (fuse_inode_has_iomap(inode))
+		return fuse_iomap_mmap(file, vma);
+
 	/* DAX mmap is superior to direct_io mmap */
 	if (FUSE_IS_DAX(inode))
 		return fuse_dax_mmap(file, vma);
@@ -2593,7 +2596,7 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl)
 	return err;
 }
 
-static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
+sector_t fuse_bmap(struct address_space *mapping, sector_t block)
 {
 	struct inode *inode = mapping->host;
 	struct fuse_mount *fm = get_fuse_mount(inode);
@@ -2947,8 +2950,12 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
 
 static int fuse_writeback_range(struct inode *inode, loff_t start, loff_t end)
 {
-	int err = filemap_write_and_wait_range(inode->i_mapping, start, LLONG_MAX);
+	int err;
 
+	if (fuse_inode_has_iomap(inode))
+		return fuse_iomap_flush_unmap_range(inode, start, end);
+
+	err = filemap_write_and_wait_range(inode->i_mapping, start, LLONG_MAX);
 	if (!err)
 		fuse_sync_writes(inode);
 
@@ -2984,7 +2991,10 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
 		return -EOPNOTSUPP;
 
 	inode_lock(inode);
-	if (block_faults) {
+	if (is_iomap) {
+		filemap_invalidate_lock(inode->i_mapping);
+		block_faults = true;
+	} else if (block_faults) {
 		filemap_invalidate_lock(inode->i_mapping);
 		err = fuse_dax_break_layouts(inode, 0, -1);
 		if (err)
@@ -2999,6 +3009,17 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
 			goto out;
 	}
 
+	/*
+	 * If we are using iomap for file IO, fallocate must wait for all AIO
+	 * to complete before we continue as AIO can change the file size on
+	 * completion without holding any locks we currently hold. We must do
+	 * this first because AIO can update the in-memory inode size, and the
+	 * operations that follow require the in-memory size to be fully
+	 * up-to-date.
+	 */
+	if (is_iomap)
+		inode_dio_wait(inode);
+
 	if (!(mode & FALLOC_FL_KEEP_SIZE) &&
 	    offset + length > i_size_read(inode)) {
 		err = inode_newsize_ok(inode, offset + length);
@@ -3027,21 +3048,23 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
 	if (err)
 		goto out;
 
-	/* we could have extended the file */
-	if (!(mode & FALLOC_FL_KEEP_SIZE)) {
-		if (is_iomap && newsize > 0) {
-			err = fuse_iomap_setsize_finish(inode, newsize);
-			if (err)
-				goto out;
+	if (is_iomap) {
+		err = fuse_iomap_fallocate(file, mode, offset, length,
+					   newsize);
+		if (err)
+			goto out;
+	} else {
+		/* we could have extended the file */
+		if (!(mode & FALLOC_FL_KEEP_SIZE)) {
+			if (fuse_write_update_attr(inode, newsize, length))
+				file_update_time(file);
 		}
 
-		if (fuse_write_update_attr(inode, offset + length, length))
-			file_update_time(file);
+		if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE))
+			truncate_pagecache_range(inode, offset,
+						 offset + length - 1);
 	}
 
-	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE))
-		truncate_pagecache_range(inode, offset, offset + length - 1);
-
 	fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
 
 out:
@@ -3085,6 +3108,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
 	ssize_t err;
 	/* mark unstable when write-back is not used, and file_out gets
 	 * extended */
+	const bool is_iomap = fuse_inode_has_iomap(inode_out);
 	bool is_unstable = (!fc->writeback_cache) &&
 			   ((pos_out + len) > inode_out->i_size);
 
@@ -3128,6 +3152,10 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
 	if (err)
 		goto out;
 
+	/* See inode_dio_wait comment in fuse_file_fallocate */
+	if (is_iomap)
+		inode_dio_wait(inode_out);
+
 	if (is_unstable)
 		set_bit(FUSE_I_SIZE_UNSTABLE, &fi_out->state);
 
@@ -3168,7 +3196,8 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
 		goto out;
 	}
 
-	truncate_inode_pages_range(inode_out->i_mapping,
+	if (!is_iomap)
+		truncate_inode_pages_range(inode_out->i_mapping,
 				   ALIGN_DOWN(pos_out, PAGE_SIZE),
 				   ALIGN(pos_out + bytes_copied, PAGE_SIZE) - 1);
 
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index f0b5ea49b6e2ac..2097a83af833d5 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -5,6 +5,8 @@
  */
 #include <linux/iomap.h>
 #include <linux/fiemap.h>
+#include <linux/pagemap.h>
+#include <linux/falloc.h>
 #include "fuse_i.h"
 #include "fuse_trace.h"
 #include "fuse_iomap.h"
@@ -204,7 +206,7 @@ static inline uint16_t fuse_iomap_flags_from_server(uint16_t fuse_f_flags)
 		ret |= FUSE_IOMAP_OP_##word
 static inline uint32_t fuse_iomap_op_to_server(unsigned iomap_op_flags)
 {
-	uint32_t ret = 0;
+	uint32_t ret = iomap_op_flags & FUSE_IOMAP_OP_WRITEBACK;
 
 	XMAP(WRITE);
 	XMAP(ZERO);
@@ -370,7 +372,8 @@ fuse_iomap_begin_validate(const struct inode *inode,
 
 static inline bool fuse_is_iomap_file_write(unsigned int opflags)
 {
-	return opflags & (IOMAP_WRITE | IOMAP_ZERO | IOMAP_UNSHARE);
+	return opflags & (IOMAP_WRITE | IOMAP_ZERO | IOMAP_UNSHARE |
+			  FUSE_IOMAP_OP_WRITEBACK);
 }
 
 static inline struct fuse_backing *
@@ -747,12 +750,7 @@ void fuse_iomap_unmount(struct fuse_mount *fm)
 	fuse_send_destroy(fm);
 }
 
-static inline void fuse_inode_set_iomap(struct inode *inode)
-{
-	struct fuse_inode *fi = get_fuse_inode(inode);
-
-	set_bit(FUSE_I_IOMAP, &fi->state);
-}
+static inline void fuse_inode_set_iomap(struct inode *inode);
 
 static inline void fuse_inode_clear_iomap(struct inode *inode)
 {
@@ -979,17 +977,107 @@ static const struct iomap_dio_ops fuse_iomap_dio_write_ops = {
 	.end_io		= fuse_iomap_dio_write_end_io,
 };
 
+static const struct iomap_write_ops fuse_iomap_write_ops = {
+};
+
+static int
+fuse_iomap_zero_range(
+	struct inode		*inode,
+	loff_t			pos,
+	loff_t			len,
+	bool			*did_zero)
+{
+	return iomap_zero_range(inode, pos, len, did_zero, &fuse_iomap_ops,
+				&fuse_iomap_write_ops, NULL);
+}
+
+/* Take care of zeroing post-EOF blocks when they might exist. */
+static ssize_t
+fuse_iomap_write_zero_eof(
+	struct kiocb		*iocb,
+	struct iov_iter		*from,
+	bool			*drained_dio)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct address_space *mapping = iocb->ki_filp->f_mapping;
+	loff_t			isize;
+	int			error;
+
+	/*
+	 * We need to serialise against EOF updates that occur in IO
+	 * completions here. We want to make sure that nobody is changing the
+	 * size while we do this check until we have placed an IO barrier (i.e.
+	 * hold i_rwsem exclusively) that prevents new IO from being
+	 * dispatched.  The spinlock effectively forms a memory barrier once we
+	 * have i_rwsem exclusively so we are guaranteed to see the latest EOF
+	 * value and hence be able to correctly determine if we need to run
+	 * zeroing.
+	 */
+	spin_lock(&fi->lock);
+	isize = i_size_read(inode);
+	if (iocb->ki_pos <= isize) {
+		spin_unlock(&fi->lock);
+		return 0;
+	}
+	spin_unlock(&fi->lock);
+
+	if (iocb->ki_flags & IOCB_NOWAIT)
+		return -EAGAIN;
+
+	if (!(*drained_dio)) {
+		/*
+		 * We now have an IO submission barrier in place, but AIO can
+		 * do EOF updates during IO completion and hence we now need to
+		 * wait for all of them to drain.  Non-AIO DIO will have
+		 * drained before we are given the exclusive i_rwsem, and so
+		 * for most cases this wait is a no-op.
+		 */
+		inode_dio_wait(inode);
+		*drained_dio = true;
+		return 1;
+	}
+
+	filemap_invalidate_lock(mapping);
+	error = fuse_iomap_zero_range(inode, isize, iocb->ki_pos - isize, NULL);
+	filemap_invalidate_unlock(mapping);
+
+	return error;
+}
+
 static ssize_t
 fuse_iomap_write_checks(
 	struct kiocb		*iocb,
 	struct iov_iter		*from)
 {
+	struct inode		*inode = iocb->ki_filp->f_mapping->host;
 	ssize_t			error;
+	bool			drained_dio = false;
 
+restart:
 	error = generic_write_checks(iocb, from);
 	if (error <= 0)
 		return error;
 
+	/*
+	 * If the offset is beyond the size of the file, we need to zero all
+	 * blocks that fall between the existing EOF and the start of this
+	 * write.
+	 *
+	 * We can do an unlocked check for i_size here safely as I/O completion
+	 * can only extend EOF.  Truncate is locked out at this point, so the
+	 * EOF cannot move backwards, only forwards. Hence we only need to take
+	 * the slow path when we are at or beyond the current EOF.
+	 */
+	if (fuse_inode_has_iomap(inode) &&
+	    iocb->ki_pos > i_size_read(inode)) {
+		error = fuse_iomap_write_zero_eof(iocb, from, &drained_dio);
+		if (error == 1)
+			goto restart;
+		if (error)
+			return error;
+	}
+
 	return kiocb_modified(iocb);
 }
 
@@ -1059,6 +1147,366 @@ void fuse_iomap_open_truncate(struct inode *inode)
 	fi->i_disk_size = 0;
 }
 
+struct fuse_writepage_ctx {
+	struct iomap_writepage_ctx ctx;
+};
+
+static void fuse_iomap_end_ioend(struct iomap_ioend *ioend)
+{
+	struct inode *inode = ioend->io_inode;
+	unsigned int ioendflags = FUSE_IOMAP_IOEND_WRITEBACK;
+	unsigned int nofs_flag;
+	int error = blk_status_to_errno(ioend->io_bio.bi_status);
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	/* We still have to clean up the ioend even if the inode is dead */
+	if (!error && fuse_is_bad(inode))
+		error = -EIO;
+
+	if (ioend->io_flags & IOMAP_IOEND_SHARED)
+		ioendflags |= FUSE_IOMAP_IOEND_SHARED;
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
+		ioendflags |= FUSE_IOMAP_IOEND_UNWRITTEN;
+
+	/*
+	 * We can allocate memory here while doing writeback on behalf of
+	 * memory reclaim.  To avoid memory allocation deadlocks set the
+	 * task-wide nofs context for the following operations.
+	 */
+	nofs_flag = memalloc_nofs_save();
+	fuse_iomap_ioend(inode, ioend->io_offset, ioend->io_size, error,
+			 ioendflags, ioend->io_bio.bi_bdev, ioend->io_sector);
+	iomap_finish_ioends(ioend, error);
+	memalloc_nofs_restore(nofs_flag);
+}
+
+/*
+ * Finish all pending IO completions that require transactional modifications.
+ *
+ * We try to merge physical and logically contiguous ioends before completion to
+ * minimise the number of transactions we need to perform during IO completion.
+ * Both unwritten extent conversion and COW remapping need to iterate and modify
+ * one physical extent at a time, so we gain nothing by merging physically
+ * discontiguous extents here.
+ *
+ * The ioend chain length that we can be processing here is largely unbound in
+ * length and we may have to perform significant amounts of work on each ioend
+ * to complete it. Hence we have to be careful about holding the CPU for too
+ * long in this loop.
+ */
+static void fuse_iomap_end_io(struct work_struct *work)
+{
+	struct fuse_inode *fi =
+		container_of(work, struct fuse_inode, ioend_work);
+	struct iomap_ioend *ioend;
+	struct list_head tmp;
+	unsigned long flags;
+
+	spin_lock_irqsave(&fi->ioend_lock, flags);
+	list_replace_init(&fi->ioend_list, &tmp);
+	spin_unlock_irqrestore(&fi->ioend_lock, flags);
+
+	iomap_sort_ioends(&tmp);
+	while ((ioend = list_first_entry_or_null(&tmp, struct iomap_ioend,
+			io_list))) {
+		list_del_init(&ioend->io_list);
+		iomap_ioend_try_merge(ioend, &tmp);
+		fuse_iomap_end_ioend(ioend);
+		cond_resched();
+	}
+}
+
+static void fuse_iomap_end_bio(struct bio *bio)
+{
+	struct iomap_ioend *ioend = iomap_ioend_from_bio(bio);
+	struct inode *inode = ioend->io_inode;
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	unsigned long flags;
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	spin_lock_irqsave(&fi->ioend_lock, flags);
+	if (list_empty(&fi->ioend_list))
+		WARN_ON_ONCE(!queue_work(system_unbound_wq, &fi->ioend_work));
+	list_add_tail(&ioend->io_list, &fi->ioend_list);
+	spin_unlock_irqrestore(&fi->ioend_lock, flags);
+}
+
+/*
+ * Fast revalidation of the cached writeback mapping. Return true if the current
+ * mapping is valid, false otherwise.
+ */
+static bool fuse_iomap_revalidate_writeback(struct iomap_writepage_ctx *wpc,
+					    loff_t offset)
+{
+	if (offset < wpc->iomap.offset ||
+	    offset >= wpc->iomap.offset + wpc->iomap.length)
+		return false;
+
+	/* XXX actually use revalidation cookie */
+	return true;
+}
+
+/*
+ * If the folio has delalloc blocks on it, the caller is asking us to punch them
+ * out. If we don't, we can leave a stale delalloc mapping covered by a clean
+ * page that needs to be dirtied again before the delalloc mapping can be
+ * converted. This stale delalloc mapping can trip up a later direct I/O read
+ * operation on the same region.
+ *
+ * We prevent this by truncating away the delalloc regions on the folio. Because
+ * they are delalloc, we can do this without needing a transaction. Indeed - if
+ * we get ENOSPC errors, we have to be able to do this truncation without a
+ * transaction as there is no space left for block reservation (typically why
+ * we see a ENOSPC in writeback).
+ */
+static void fuse_iomap_discard_folio(struct folio *folio, loff_t pos, int error)
+{
+	struct inode *inode = folio->mapping->host;
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	loff_t end = folio_pos(folio) + folio_size(folio);
+
+	if (fuse_is_bad(inode))
+		return;
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	printk_ratelimited(KERN_ERR
+		"page discard on page %px, inode 0x%llx, pos %llu.",
+			folio, fi->orig_ino, pos);
+
+	/* Userspace may need to remove delayed allocations */
+	fuse_iomap_ioend(inode, pos, end - pos, error, 0, NULL,
+			 FUSE_IOMAP_NULL_ADDR);
+}
+
+static ssize_t fuse_iomap_writeback_range(struct iomap_writepage_ctx *wpc,
+					  struct folio *folio, u64 offset,
+					  unsigned int len, u64 end_pos)
+{
+	struct inode *inode = wpc->inode;
+	struct iomap write_iomap, dontcare;
+	ssize_t ret;
+
+	if (fuse_is_bad(inode)) {
+		ret = -EIO;
+		goto discard_folio;
+	}
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	if (!fuse_iomap_revalidate_writeback(wpc, offset)) {
+		ret = fuse_iomap_begin(inode, offset, len,
+				       FUSE_IOMAP_OP_WRITEBACK,
+				       &write_iomap, &dontcare);
+		if (ret)
+			goto discard_folio;
+
+		/*
+		 * Landed in a hole or beyond EOF?  Send that to iomap, it'll
+		 * skip writing back the file range.
+		 */
+		if (write_iomap.offset > offset) {
+			write_iomap.length = write_iomap.offset - offset;
+			write_iomap.offset = offset;
+			write_iomap.type = IOMAP_HOLE;
+		}
+
+		memcpy(&wpc->iomap, &write_iomap, sizeof(struct iomap));
+	}
+
+	ret = iomap_add_to_ioend(wpc, folio, offset, end_pos, len);
+	if (ret < 0)
+		goto discard_folio;
+
+	return ret;
+discard_folio:
+	fuse_iomap_discard_folio(folio, offset, ret);
+	return ret;
+}
+
+static int fuse_iomap_writeback_submit(struct iomap_writepage_ctx *wpc,
+				       int error)
+{
+	struct iomap_ioend *ioend = wpc->wb_ctx;
+
+	ASSERT(fuse_inode_has_iomap(ioend->io_inode));
+
+	/* always call our ioend function, even if we cancel the bio */
+	ioend->io_bio.bi_end_io = fuse_iomap_end_bio;
+	return iomap_ioend_writeback_submit(wpc, error);
+}
+
+static const struct iomap_writeback_ops fuse_iomap_writeback_ops = {
+	.writeback_range	= fuse_iomap_writeback_range,
+	.writeback_submit	= fuse_iomap_writeback_submit,
+};
+
+static int fuse_iomap_writepages(struct address_space *mapping,
+				 struct writeback_control *wbc)
+{
+	struct fuse_writepage_ctx wpc = {
+		.ctx = {
+			.inode = mapping->host,
+			.wbc = wbc,
+			.ops = &fuse_iomap_writeback_ops,
+		},
+	};
+
+	ASSERT(fuse_inode_has_iomap(mapping->host));
+
+	return iomap_writepages(&wpc.ctx);
+}
+
+static int fuse_iomap_read_folio(struct file *file, struct folio *folio)
+{
+	ASSERT(fuse_inode_has_iomap(file_inode(file)));
+
+	iomap_bio_read_folio(folio, &fuse_iomap_ops);
+	return 0;
+}
+
+static void fuse_iomap_readahead(struct readahead_control *rac)
+{
+	ASSERT(fuse_inode_has_iomap(file_inode(rac->file)));
+
+	iomap_bio_readahead(rac, &fuse_iomap_ops);
+}
+
+static const struct address_space_operations fuse_iomap_aops = {
+	.read_folio		= fuse_iomap_read_folio,
+	.readahead		= fuse_iomap_readahead,
+	.writepages		= fuse_iomap_writepages,
+	.dirty_folio		= iomap_dirty_folio,
+	.release_folio		= iomap_release_folio,
+	.invalidate_folio	= iomap_invalidate_folio,
+	.migrate_folio		= filemap_migrate_folio,
+	.is_partially_uptodate  = iomap_is_partially_uptodate,
+	.error_remove_folio	= generic_error_remove_folio,
+
+	/* These aren't pagecache operations per se */
+	.bmap			= fuse_bmap,
+};
+
+static inline void fuse_inode_set_iomap(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+
+	inode->i_data.a_ops = &fuse_iomap_aops;
+
+	INIT_WORK(&fi->ioend_work, fuse_iomap_end_io);
+	INIT_LIST_HEAD(&fi->ioend_list);
+	spin_lock_init(&fi->ioend_lock);
+	set_bit(FUSE_I_IOMAP, &fi->state);
+}
+
+/*
+ * Locking for serialisation of IO during page faults. This results in a lock
+ * ordering of:
+ *
+ * mmap_lock (MM)
+ *   sb_start_pagefault(vfs, freeze)
+ *     invalidate_lock (vfs - truncate serialisation)
+ *       page_lock (MM)
+ *         i_lock (FUSE - extent map serialisation)
+ */
+static vm_fault_t fuse_iomap_page_mkwrite(struct vm_fault *vmf)
+{
+	struct inode *inode = file_inode(vmf->vma->vm_file);
+	struct address_space *mapping = vmf->vma->vm_file->f_mapping;
+	vm_fault_t ret;
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	sb_start_pagefault(inode->i_sb);
+	file_update_time(vmf->vma->vm_file);
+
+	filemap_invalidate_lock_shared(mapping);
+	ret = iomap_page_mkwrite(vmf, &fuse_iomap_ops, NULL);
+	filemap_invalidate_unlock_shared(mapping);
+
+	sb_end_pagefault(inode->i_sb);
+	return ret;
+}
+
+static const struct vm_operations_struct fuse_iomap_vm_ops = {
+	.fault		= filemap_fault,
+	.map_pages	= filemap_map_pages,
+	.page_mkwrite	= fuse_iomap_page_mkwrite,
+};
+
+int fuse_iomap_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	ASSERT(fuse_inode_has_iomap(file_inode(file)));
+
+	file_accessed(file);
+	vma->vm_ops = &fuse_iomap_vm_ops;
+	return 0;
+}
+
+static ssize_t fuse_iomap_buffered_read(struct kiocb *iocb, struct iov_iter *to)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+	ssize_t ret;
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	if (!iov_iter_count(to))
+		return 0; /* skip atime */
+
+	ret = fuse_iomap_ilock_iocb(iocb, SHARED);
+	if (ret)
+		return ret;
+	ret = generic_file_read_iter(iocb, to);
+	if (ret > 0)
+		file_accessed(iocb->ki_filp);
+	inode_unlock_shared(inode);
+
+	return ret;
+}
+
+static ssize_t fuse_iomap_buffered_write(struct kiocb *iocb,
+					 struct iov_iter *from)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	loff_t pos = iocb->ki_pos;
+	ssize_t ret;
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	if (!iov_iter_count(from))
+		return 0;
+
+	ret = fuse_iomap_ilock_iocb(iocb, EXCL);
+	if (ret)
+		return ret;
+
+	ret = fuse_iomap_write_checks(iocb, from);
+	if (ret)
+		goto out_unlock;
+
+	if (inode->i_size < pos + iov_iter_count(from))
+		set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
+
+	ret = iomap_file_buffered_write(iocb, from, &fuse_iomap_ops,
+					&fuse_iomap_write_ops, NULL);
+
+	if (ret > 0)
+		fuse_write_update_attr(inode, pos + ret, ret);
+	clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
+
+out_unlock:
+	inode_unlock(inode);
+
+	if (ret > 0) {
+		/* Handle various SYNC-type writes */
+		ret = generic_write_sync(iocb, ret);
+	}
+	return ret;
+}
+
 static inline bool fuse_iomap_force_directio(const struct kiocb *iocb)
 {
 	struct fuse_file *ff = iocb->ki_filp->private_data;
@@ -1072,9 +1520,30 @@ ssize_t fuse_iomap_read_iter(struct kiocb *iocb, struct iov_iter *to)
 
 	ASSERT(fuse_inode_has_iomap(file_inode(iocb->ki_filp)));
 
-	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio)
-		return fuse_iomap_direct_read(iocb, to);
-	return -EIO;
+	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio) {
+		ssize_t ret = fuse_iomap_direct_read(iocb, to);
+
+		switch (ret) {
+		case -ENOTBLK:
+		case -ENOSYS:
+			/*
+			 * We fall back to a buffered read if:
+			 *
+			 *  - ENOTBLK means iomap told us to do it
+			 *  - ENOSYS means the fuse server wants it
+			 *
+			 * Don't fall back if we were forced to do it.
+			 */
+			if (force_directio)
+				return -EIO;
+			break;
+		default:
+			/* errors, no progress, or partial progress */
+			return ret;
+		}
+	}
+
+	return fuse_iomap_buffered_read(iocb, to);
 }
 
 ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from)
@@ -1083,7 +1552,206 @@ ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from)
 
 	ASSERT(fuse_inode_has_iomap(file_inode(iocb->ki_filp)));
 
-	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio)
-		return fuse_iomap_direct_write(iocb, from);
-	return -EIO;
+	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio) {
+		ssize_t ret = fuse_iomap_direct_write(iocb, from);
+
+		switch (ret) {
+		case -ENOTBLK:
+		case -ENOSYS:
+			/*
+			 * We fall back to a buffered write if:
+			 *
+			 *  - ENOTBLK means iomap told us to do it
+			 *  - ENOSYS means the fuse server wants it
+			 *
+			 * Either way, try the write again as a synchronous
+			 * buffered write unless we were forced to do directio.
+			 */
+			if (force_directio)
+				return -EIO;
+			iocb->ki_flags |= IOCB_SYNC;
+			break;
+		default:
+			/* errors, no progress, or partial progress */
+			return ret;
+		}
+	}
+
+	return fuse_iomap_buffered_write(iocb, from);
+}
+
+static int
+fuse_iomap_truncate_page(
+	struct inode *inode,
+	loff_t			pos,
+	bool			*did_zero)
+{
+	return iomap_truncate_page(inode, pos, did_zero, &fuse_iomap_ops,
+				   &fuse_iomap_write_ops, NULL);
+}
+/*
+ * Truncate pagecache for a file before sending the truncate request to
+ * userspace.  Must have write permission and not be a directory.
+ *
+ * Caution: The caller of this function is responsible for calling
+ * setattr_prepare() or otherwise verifying the change is fine.
+ */
+int
+fuse_iomap_setsize_start(
+	struct inode		*inode,
+	loff_t			newsize)
+{
+	loff_t			oldsize = i_size_read(inode);
+	int			error;
+	bool			did_zeroing = false;
+
+	rwsem_assert_held_write(&inode->i_rwsem);
+	rwsem_assert_held_write(&inode->i_mapping->invalidate_lock);
+	ASSERT(S_ISREG(inode->i_mode));
+
+	/*
+	 * Wait for all direct I/O to complete.
+	 */
+	inode_dio_wait(inode);
+
+	/*
+	 * File data changes must be complete and flushed to disk before we
+	 * call userspace to modify the inode.
+	 *
+	 * Start with zeroing any data beyond EOF that we may expose on file
+	 * extension, or zeroing out the rest of the block on a downward
+	 * truncate.
+	 */
+	if (newsize > oldsize)
+		error = fuse_iomap_zero_range(inode, oldsize, newsize - oldsize,
+					      &did_zeroing);
+	else
+		error = fuse_iomap_truncate_page(inode, newsize, &did_zeroing);
+	if (error)
+		return error;
+
+	/*
+	 * We've already locked out new page faults, so now we can safely
+	 * remove pages from the page cache knowing they won't get refaulted
+	 * until we drop the mapping invalidation lock after the extent
+	 * manipulations are complete. The truncate_setsize() call also cleans
+	 * folios spanning EOF on extending truncates and hence ensures
+	 * sub-page block size filesystems are correctly handled, too.
+	 *
+	 * And we update in-core i_size and truncate page cache beyond newsize
+	 * before writing back the whole file, so we're guaranteed not to write
+	 * stale data past the new EOF on truncate down.
+	 */
+	truncate_setsize(inode, newsize);
+
+	/*
+	 * Flush the entire pagecache to ensure the fuse server logs the inode
+	 * size change and all dirty data that might be associated with it.
+	 * We don't know the ondisk inode size, so we only have this clumsy
+	 * hammer.
+	 */
+	return filemap_write_and_wait(inode->i_mapping);
+}
+
+/*
+ * Prepare for a file data block remapping operation by flushing and unmapping
+ * all pagecache for the entire range.
+ */
+int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
+				 loff_t endpos)
+{
+	loff_t			start, end;
+	unsigned int		rounding;
+	int			error;
+
+	/*
+	 * Make sure we extend the flush out to extent alignment boundaries so
+	 * any extent range overlapping the start/end of the modification we
+	 * are about to do is clean and idle.
+	 */
+	rounding = max_t(unsigned int, i_blocksize(inode), PAGE_SIZE);
+	start = round_down(pos, rounding);
+	end = round_up(endpos + 1, rounding) - 1;
+
+	error = filemap_write_and_wait_range(inode->i_mapping, start, end);
+	if (error)
+		return error;
+	truncate_pagecache_range(inode, start, end);
+	return 0;
+}
+
+static int fuse_iomap_punch_range(struct inode *inode, loff_t offset,
+				  loff_t length)
+{
+	loff_t isize = i_size_read(inode);
+	int error;
+
+	/*
+	 * Now that we've unmap all full blocks we'll have to zero out any
+	 * partial block at the beginning and/or end.  iomap_zero_range is
+	 * smart enough to skip holes and unwritten extents, including those we
+	 * just created, but we must take care not to zero beyond EOF, which
+	 * would enlarge i_size.
+	 */
+	if (offset >= isize)
+		return 0;
+	if (offset + length > isize)
+		length = isize - offset;
+	error = fuse_iomap_zero_range(inode, offset, length, NULL);
+	if (error)
+		return error;
+
+	/*
+	 * If we zeroed right up to EOF and EOF straddles a page boundary we
+	 * must make sure that the post-EOF area is also zeroed because the
+	 * page could be mmap'd and iomap_zero_range doesn't do that for us.
+	 * Writeback of the eof page will do this, albeit clumsily.
+	 */
+	if (offset + length >= isize && offset_in_page(offset + length) > 0) {
+		error = filemap_write_and_wait_range(inode->i_mapping,
+					round_down(offset + length, PAGE_SIZE),
+					LLONG_MAX);
+	}
+
+	return error;
+}
+
+int
+fuse_iomap_fallocate(
+	struct file		*file,
+	int			mode,
+	loff_t			offset,
+	loff_t			length,
+	loff_t			new_size)
+{
+	struct inode *inode = file_inode(file);
+	int error;
+
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	/*
+	 * If we unmapped blocks from the file range, then we zero the
+	 * pagecache for those regions and push them to disk rather than make
+	 * the fuse server manually zero the disk blocks.
+	 */
+	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)) {
+		error = fuse_iomap_punch_range(inode, offset, length);
+		if (error)
+			return error;
+	}
+
+	/*
+	 * If this is an extending write, we need to zero the bytes beyond the
+	 * new EOF and bounce the new size out to userspace.
+	 */
+	if (new_size) {
+		error = fuse_iomap_setsize_start(inode, new_size);
+		if (error)
+			return error;
+
+		fuse_write_update_attr(inode, new_size, length);
+	}
+
+	file_update_time(file);
+	return 0;
 }


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 17/33] fuse_trace: implement buffered IO with iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (15 preceding siblings ...)
  2026-02-23 23:12   ` [PATCH 16/33] fuse: implement buffered " Darrick J. Wong
@ 2026-02-23 23:13   ` Darrick J. Wong
  2026-02-23 23:13   ` [PATCH 18/33] fuse: use an unrestricted backing device with iomap pagecache io Darrick J. Wong
                     ` (15 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:13 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |  227 ++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/dev.c        |   10 ++
 fs/fuse/fuse_iomap.c |   40 ++++++++-
 3 files changed, 273 insertions(+), 4 deletions(-)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index a8337f5ddcf011..c832fb9012d983 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -227,6 +227,9 @@ DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
 #endif /* CONFIG_FUSE_BACKING */
 
 #if IS_ENABLED(CONFIG_FUSE_IOMAP)
+struct iomap_writepage_ctx;
+struct iomap_ioend;
+
 /* tracepoint boilerplate so we don't have to keep doing this */
 #define FUSE_IOMAP_OPFLAGS_FIELD \
 		__field(unsigned,		opflags)
@@ -294,7 +297,8 @@ DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
 	{ FUSE_IOMAP_OP_UNSHARE,		"unshare" }, \
 	{ FUSE_IOMAP_OP_DAX,			"fsdax" }, \
 	{ FUSE_IOMAP_OP_ATOMIC,			"atomic" }, \
-	{ FUSE_IOMAP_OP_DONTCACHE,		"dontcache" }
+	{ FUSE_IOMAP_OP_DONTCACHE,		"dontcache" }, \
+	{ FUSE_IOMAP_OP_WRITEBACK,		"writeback" }
 
 #define FUSE_IOMAP_TYPE_STRINGS \
 	{ FUSE_IOMAP_TYPE_PURE_OVERWRITE,	"overwrite" }, \
@@ -309,7 +313,8 @@ DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
 	{ FUSE_IOMAP_IOEND_UNWRITTEN,		"unwritten" }, \
 	{ FUSE_IOMAP_IOEND_BOUNDARY,		"boundary" }, \
 	{ FUSE_IOMAP_IOEND_DIRECT,		"direct" }, \
-	{ FUSE_IOMAP_IOEND_APPEND,		"append" }
+	{ FUSE_IOMAP_IOEND_APPEND,		"append" }, \
+	{ FUSE_IOMAP_IOEND_WRITEBACK,		"writeback" }
 
 #define IOMAP_DIOEND_STRINGS \
 	{ IOMAP_DIO_UNWRITTEN,			"unwritten" }, \
@@ -334,6 +339,12 @@ TRACE_DEFINE_ENUM(FUSE_I_IOMAP);
 	{ 1 << FUSE_I_EXCLUSIVE,		"excl" }, \
 	{ 1 << FUSE_I_IOMAP,			"iomap" }
 
+#define IOMAP_IOEND_STRINGS \
+	{ IOMAP_IOEND_SHARED,			"shared" }, \
+	{ IOMAP_IOEND_UNWRITTEN,		"unwritten" }, \
+	{ IOMAP_IOEND_BOUNDARY,			"boundary" }, \
+	{ IOMAP_IOEND_DIRECT,			"direct" }
+
 DECLARE_EVENT_CLASS(fuse_iomap_check_class,
 	TP_PROTO(const char *func, int line, const char *condition),
 
@@ -683,6 +694,9 @@ DEFINE_EVENT(fuse_iomap_file_io_class, name,		\
 	TP_ARGS(iocb, iter))
 DEFINE_FUSE_IOMAP_FILE_IO_EVENT(fuse_iomap_direct_read);
 DEFINE_FUSE_IOMAP_FILE_IO_EVENT(fuse_iomap_direct_write);
+DEFINE_FUSE_IOMAP_FILE_IO_EVENT(fuse_iomap_buffered_read);
+DEFINE_FUSE_IOMAP_FILE_IO_EVENT(fuse_iomap_buffered_write);
+DEFINE_FUSE_IOMAP_FILE_IO_EVENT(fuse_iomap_write_zero_eof);
 
 DECLARE_EVENT_CLASS(fuse_iomap_file_ioend_class,
 	TP_PROTO(const struct kiocb *iocb, const struct iov_iter *iter,
@@ -709,6 +723,8 @@ DEFINE_EVENT(fuse_iomap_file_ioend_class, name,		\
 	TP_ARGS(iocb, iter, ret))
 DEFINE_FUSE_IOMAP_FILE_IOEND_EVENT(fuse_iomap_direct_read_end);
 DEFINE_FUSE_IOMAP_FILE_IOEND_EVENT(fuse_iomap_direct_write_end);
+DEFINE_FUSE_IOMAP_FILE_IOEND_EVENT(fuse_iomap_buffered_read_end);
+DEFINE_FUSE_IOMAP_FILE_IOEND_EVENT(fuse_iomap_buffered_write_end);
 
 TRACE_EVENT(fuse_iomap_dio_write_end_io,
 	TP_PROTO(const struct inode *inode, loff_t pos, ssize_t written,
@@ -781,7 +797,214 @@ DEFINE_EVENT(fuse_iomap_file_range_class, name,         \
         TP_PROTO(const struct inode *inode, loff_t offset, loff_t length), \
         TP_ARGS(inode, offset, length))
 DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_setsize_finish);
+DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_truncate_up);
+DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_truncate_down);
+DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_punch_range);
+DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_flush_unmap_range);
 
+TRACE_EVENT(fuse_iomap_end_ioend,
+	TP_PROTO(const struct iomap_ioend *ioend),
+
+	TP_ARGS(ioend),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(unsigned int,		ioendflags)
+		__field(int,			error)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(ioend->io_inode, fi, fm);
+		__entry->offset		=	ioend->io_offset;
+		__entry->length		=	ioend->io_size;
+		__entry->ioendflags	=	ioend->io_flags;
+		__entry->error		=	blk_status_to_errno(ioend->io_bio.bi_status);
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() " ioendflags (%s) error %d",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __print_flags(__entry->ioendflags, "|", IOMAP_IOEND_STRINGS),
+		  __entry->error)
+);
+
+TRACE_EVENT(fuse_iomap_writeback_range,
+	TP_PROTO(const struct inode *inode, u64 offset, unsigned int count,
+		 u64 end_pos),
+
+	TP_ARGS(inode, offset, count, end_pos),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(uint64_t,		end_pos)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	offset;
+		__entry->length		=	count;
+		__entry->end_pos	=	end_pos;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() " end_pos 0x%llx",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __entry->end_pos)
+);
+
+TRACE_EVENT(fuse_iomap_writeback_submit,
+	TP_PROTO(const struct iomap_writepage_ctx *wpc, int error),
+
+	TP_ARGS(wpc, error),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(unsigned int,		nr_folios)
+		__field(uint64_t,		addr)
+		__field(int,			error)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(wpc->inode, fi, fm);
+		__entry->nr_folios	=	wpc->nr_folios;
+		__entry->offset		=	wpc->iomap.offset;
+		__entry->length		=	wpc->iomap.length;
+		__entry->addr		=	wpc->iomap.addr << 9;
+		__entry->error		=	error;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() " addr 0x%llx nr_folios %u error %d",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __entry->addr,
+		  __entry->nr_folios,
+		  __entry->error)
+);
+
+TRACE_EVENT(fuse_iomap_discard_folio,
+	TP_PROTO(const struct inode *inode, loff_t offset, size_t count),
+
+	TP_ARGS(inode, offset, count),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	offset;
+		__entry->length		=	count;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT(),
+		  FUSE_IO_RANGE_PRINTK_ARGS())
+);
+
+TRACE_EVENT(fuse_iomap_writepages,
+	TP_PROTO(const struct inode *inode, const struct writeback_control *wbc),
+
+	TP_ARGS(inode, wbc),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(long,			nr_to_write)
+		__field(bool,			sync_all)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	wbc->range_start;
+		__entry->length		=	wbc->range_end - wbc->range_start + 1;
+		__entry->nr_to_write	=	wbc->nr_to_write;
+		__entry->sync_all	=	wbc->sync_mode == WB_SYNC_ALL;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() " nr_folios %ld sync_all? %d",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __entry->nr_to_write,
+		  __entry->sync_all)
+);
+
+TRACE_EVENT(fuse_iomap_read_folio,
+	TP_PROTO(const struct folio *folio),
+
+	TP_ARGS(folio),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(folio->mapping->host, fi, fm);
+		__entry->offset		=	folio_pos(folio);
+		__entry->length		=	folio_size(folio);
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT(),
+		  FUSE_IO_RANGE_PRINTK_ARGS())
+);
+
+TRACE_EVENT(fuse_iomap_readahead,
+	TP_PROTO(const struct readahead_control *rac),
+
+	TP_ARGS(rac),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+	),
+
+	TP_fast_assign(
+		struct readahead_control *mutrac = (struct readahead_control *)rac;
+		FUSE_INODE_ASSIGN(file_inode(rac->file), fi, fm);
+		__entry->offset		=	readahead_pos(mutrac);
+		__entry->length		=	readahead_length(mutrac);
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT(),
+		  FUSE_IO_RANGE_PRINTK_ARGS())
+);
+
+TRACE_EVENT(fuse_iomap_page_mkwrite,
+	TP_PROTO(const struct vm_fault *vmf),
+
+	TP_ARGS(vmf),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+	),
+
+	TP_fast_assign(
+		struct folio *folio = page_folio(vmf->page);
+		FUSE_INODE_ASSIGN(file_inode(vmf->vma->vm_file), fi, fm);
+		__entry->offset		=	folio_pos(folio);
+		__entry->length		=	folio_size(folio);
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT(),
+		  FUSE_IO_RANGE_PRINTK_ARGS())
+);
+
+TRACE_EVENT(fuse_iomap_fallocate,
+	TP_PROTO(const struct inode *inode, int mode, loff_t offset,
+		 loff_t length, loff_t newsize),
+	TP_ARGS(inode, mode, offset, length, newsize),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(loff_t,			newsize)
+		__field(int,			mode)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	offset;
+		__entry->length		=	length;
+		__entry->mode		=	mode;
+		__entry->newsize	=	newsize;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() " mode 0x%x newsize 0x%llx",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __entry->mode,
+		  __entry->newsize)
+);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index a3d762fd4d9a86..c5593f35dcb675 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -9,6 +9,7 @@
 #include "dev_uring_i.h"
 #include "fuse_i.h"
 #include "fuse_dev_i.h"
+#include "fuse_iomap.h"
 
 #include <linux/init.h>
 #include <linux/module.h>
@@ -1790,6 +1791,12 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 	if (!inode)
 		goto out_up_killsb;
 
+	/* no backchannels for messing with the pagecache */
+	if (fuse_inode_has_iomap(inode)) {
+		err = -EOPNOTSUPP;
+		goto out_iput;
+	}
+
 	mapping = inode->i_mapping;
 	index = outarg.offset >> PAGE_SHIFT;
 	offset = outarg.offset & ~PAGE_MASK;
@@ -1874,6 +1881,9 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 	struct fuse_args_pages *ap;
 	struct fuse_args *args;
 
+	if (fuse_inode_has_iomap(inode))
+		return -EOPNOTSUPP;
+
 	offset = outarg->offset & ~PAGE_MASK;
 	file_size = i_size_read(inode);
 
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 2097a83af833d5..b7c459acd0c93b 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -1038,6 +1038,8 @@ fuse_iomap_write_zero_eof(
 		return 1;
 	}
 
+	trace_fuse_iomap_write_zero_eof(iocb, from);
+
 	filemap_invalidate_lock(mapping);
 	error = fuse_iomap_zero_range(inode, isize, iocb->ki_pos - isize, NULL);
 	filemap_invalidate_unlock(mapping);
@@ -1164,6 +1166,8 @@ static void fuse_iomap_end_ioend(struct iomap_ioend *ioend)
 	if (!error && fuse_is_bad(inode))
 		error = -EIO;
 
+	trace_fuse_iomap_end_ioend(ioend);
+
 	if (ioend->io_flags & IOMAP_IOEND_SHARED)
 		ioendflags |= FUSE_IOMAP_IOEND_SHARED;
 	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
@@ -1272,6 +1276,8 @@ static void fuse_iomap_discard_folio(struct folio *folio, loff_t pos, int error)
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_discard_folio(inode, pos, folio_size(folio));
+
 	printk_ratelimited(KERN_ERR
 		"page discard on page %px, inode 0x%llx, pos %llu.",
 			folio, fi->orig_ino, pos);
@@ -1296,6 +1302,8 @@ static ssize_t fuse_iomap_writeback_range(struct iomap_writepage_ctx *wpc,
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_writeback_range(inode, offset, len, end_pos);
+
 	if (!fuse_iomap_revalidate_writeback(wpc, offset)) {
 		ret = fuse_iomap_begin(inode, offset, len,
 				       FUSE_IOMAP_OP_WRITEBACK,
@@ -1333,6 +1341,8 @@ static int fuse_iomap_writeback_submit(struct iomap_writepage_ctx *wpc,
 
 	ASSERT(fuse_inode_has_iomap(ioend->io_inode));
 
+	trace_fuse_iomap_writeback_submit(wpc, error);
+
 	/* always call our ioend function, even if we cancel the bio */
 	ioend->io_bio.bi_end_io = fuse_iomap_end_bio;
 	return iomap_ioend_writeback_submit(wpc, error);
@@ -1356,6 +1366,8 @@ static int fuse_iomap_writepages(struct address_space *mapping,
 
 	ASSERT(fuse_inode_has_iomap(mapping->host));
 
+	trace_fuse_iomap_writepages(mapping->host, wbc);
+
 	return iomap_writepages(&wpc.ctx);
 }
 
@@ -1363,6 +1375,8 @@ static int fuse_iomap_read_folio(struct file *file, struct folio *folio)
 {
 	ASSERT(fuse_inode_has_iomap(file_inode(file)));
 
+	trace_fuse_iomap_read_folio(folio);
+
 	iomap_bio_read_folio(folio, &fuse_iomap_ops);
 	return 0;
 }
@@ -1371,6 +1385,8 @@ static void fuse_iomap_readahead(struct readahead_control *rac)
 {
 	ASSERT(fuse_inode_has_iomap(file_inode(rac->file)));
 
+	trace_fuse_iomap_readahead(rac);
+
 	iomap_bio_readahead(rac, &fuse_iomap_ops);
 }
 
@@ -1419,6 +1435,8 @@ static vm_fault_t fuse_iomap_page_mkwrite(struct vm_fault *vmf)
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_page_mkwrite(vmf);
+
 	sb_start_pagefault(inode->i_sb);
 	file_update_time(vmf->vma->vm_file);
 
@@ -1452,6 +1470,8 @@ static ssize_t fuse_iomap_buffered_read(struct kiocb *iocb, struct iov_iter *to)
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_buffered_read(iocb, to);
+
 	if (!iov_iter_count(to))
 		return 0; /* skip atime */
 
@@ -1463,6 +1483,7 @@ static ssize_t fuse_iomap_buffered_read(struct kiocb *iocb, struct iov_iter *to)
 		file_accessed(iocb->ki_filp);
 	inode_unlock_shared(inode);
 
+	trace_fuse_iomap_buffered_read_end(iocb, to, ret);
 	return ret;
 }
 
@@ -1476,6 +1497,8 @@ static ssize_t fuse_iomap_buffered_write(struct kiocb *iocb,
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_buffered_write(iocb, from);
+
 	if (!iov_iter_count(from))
 		return 0;
 
@@ -1504,6 +1527,7 @@ static ssize_t fuse_iomap_buffered_write(struct kiocb *iocb,
 		/* Handle various SYNC-type writes */
 		ret = generic_write_sync(iocb, ret);
 	}
+	trace_fuse_iomap_buffered_write_end(iocb, from, ret);
 	return ret;
 }
 
@@ -1622,11 +1646,17 @@ fuse_iomap_setsize_start(
 	 * extension, or zeroing out the rest of the block on a downward
 	 * truncate.
 	 */
-	if (newsize > oldsize)
+	if (newsize > oldsize) {
+		trace_fuse_iomap_truncate_up(inode, oldsize, newsize - oldsize);
+
 		error = fuse_iomap_zero_range(inode, oldsize, newsize - oldsize,
 					      &did_zeroing);
-	else
+	} else {
+		trace_fuse_iomap_truncate_down(inode, newsize,
+					       oldsize - newsize);
+
 		error = fuse_iomap_truncate_page(inode, newsize, &did_zeroing);
+	}
 	if (error)
 		return error;
 
@@ -1673,6 +1703,8 @@ int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
 	start = round_down(pos, rounding);
 	end = round_up(endpos + 1, rounding) - 1;
 
+	trace_fuse_iomap_flush_unmap_range(inode, start, end + 1 - start);
+
 	error = filemap_write_and_wait_range(inode->i_mapping, start, end);
 	if (error)
 		return error;
@@ -1686,6 +1718,8 @@ static int fuse_iomap_punch_range(struct inode *inode, loff_t offset,
 	loff_t isize = i_size_read(inode);
 	int error;
 
+	trace_fuse_iomap_punch_range(inode, offset, length);
+
 	/*
 	 * Now that we've unmap all full blocks we'll have to zero out any
 	 * partial block at the beginning and/or end.  iomap_zero_range is
@@ -1729,6 +1763,8 @@ fuse_iomap_fallocate(
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_fallocate(inode, mode, offset, length, new_size);
+
 	/*
 	 * If we unmapped blocks from the file range, then we zero the
 	 * pagecache for those regions and push them to disk rather than make


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 18/33] fuse: use an unrestricted backing device with iomap pagecache io
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (16 preceding siblings ...)
  2026-02-23 23:13   ` [PATCH 17/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:13   ` Darrick J. Wong
  2026-02-23 23:13   ` [PATCH 19/33] fuse: implement large folios for iomap pagecache files Darrick J. Wong
                     ` (14 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:13 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

With iomap support turned on for the pagecache, the kernel issues
writeback to directly to block devices and we no longer have to push all
those pages through the fuse device to userspace.  Therefore, we don't
need the tight dirty limits (~1M) that are used for regular fuse.  This
dramatically increases the performance of fuse's pagecache IO.

A reviewer of this patch asked why we reset s_bdi to the noop bdi and
call super_setup_bdi_name a second time, instead of simply clearing
STRICTLIMIT and resetting the bdi max ratio.

That's sufficient to undo the effects of fuse_bdi_init, yes.  However
the BDI gets created with the name "$major:$minor{-fuseblk}" and there
are "management" scripts that try to tweak fuse BDIs for better
performance.

I don't want some dumb script to mismanage a fuse-iomap filesystem
because it can't tell the difference, so I create a new bdi with the
name "$major:$minor.iomap" to make it obvious.  But super_setup_bdi_name
gets cranky if s_bdi isn't set to noop and we don't want to fail a mount
here due to ENOMEM so ... I implemented this weird switcheroo code.

Also, userspace scripts such as udev rules can modify the bdi as soon as
it appears in sysfs, so we can't run the fuse_bdi_init code in reverse
and expect that will undo everything.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)


diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index b7c459acd0c93b..5690e5d079807b 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -721,6 +721,27 @@ const struct fuse_backing_ops fuse_iomap_backing_ops = {
 void fuse_iomap_mount(struct fuse_mount *fm)
 {
 	struct fuse_conn *fc = fm->fc;
+	struct super_block *sb = fm->sb;
+	struct backing_dev_info *old_bdi = sb->s_bdi;
+	char *suffix = sb->s_bdev ? "-fuseblk" : "-fuse";
+	int res;
+
+	/*
+	 * sb->s_bdi points to the initial private bdi.  However, we want to
+	 * redirect it to a new private bdi with default dirty and readahead
+	 * settings because iomap writeback won't be pushing a ton of dirty
+	 * data through the fuse device.  If this fails we fall back to the
+	 * initial fuse bdi.
+	 */
+	sb->s_bdi = &noop_backing_dev_info;
+	res = super_setup_bdi_name(sb, "%u:%u%s.iomap", MAJOR(fc->dev),
+				   MINOR(fc->dev), suffix);
+	if (res) {
+		sb->s_bdi = old_bdi;
+	} else {
+		bdi_unregister(old_bdi);
+		bdi_put(old_bdi);
+	}
 
 	/*
 	 * Enable syncfs for iomap fuse servers so that we can send a final


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 19/33] fuse: implement large folios for iomap pagecache files
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (17 preceding siblings ...)
  2026-02-23 23:13   ` [PATCH 18/33] fuse: use an unrestricted backing device with iomap pagecache io Darrick J. Wong
@ 2026-02-23 23:13   ` Darrick J. Wong
  2026-02-23 23:13   ` [PATCH 20/33] fuse: advertise support for iomap Darrick J. Wong
                     ` (13 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:13 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, joannelkoong, bpf, bernd, neal, linux-fsdevel,
	linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Use large folios when we're using iomap.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/fuse_iomap.c |    6 ++++++
 1 file changed, 6 insertions(+)


diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 5690e5d079807b..70b6fb922fc9ec 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -1429,12 +1429,18 @@ static const struct address_space_operations fuse_iomap_aops = {
 static inline void fuse_inode_set_iomap(struct inode *inode)
 {
 	struct fuse_inode *fi = get_fuse_inode(inode);
+	unsigned int min_order = 0;
 
 	inode->i_data.a_ops = &fuse_iomap_aops;
 
 	INIT_WORK(&fi->ioend_work, fuse_iomap_end_io);
 	INIT_LIST_HEAD(&fi->ioend_list);
 	spin_lock_init(&fi->ioend_lock);
+
+	if (inode->i_blkbits > PAGE_SHIFT)
+		min_order = inode->i_blkbits - PAGE_SHIFT;
+
+	mapping_set_folio_min_order(inode->i_mapping, min_order);
 	set_bit(FUSE_I_IOMAP, &fi->state);
 }
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 20/33] fuse: advertise support for iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (18 preceding siblings ...)
  2026-02-23 23:13   ` [PATCH 19/33] fuse: implement large folios for iomap pagecache files Darrick J. Wong
@ 2026-02-23 23:13   ` Darrick J. Wong
  2026-02-23 23:14   ` [PATCH 21/33] fuse: query filesystem geometry when using iomap Darrick J. Wong
                     ` (12 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:13 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Advertise our new IO paths programmatically by creating an ioctl that
can return the capabilities of the kernel.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.h      |    4 ++++
 include/uapi/linux/fuse.h |    9 +++++++++
 fs/fuse/dev.c             |    3 +++
 fs/fuse/fuse_iomap.c      |   13 +++++++++++++
 4 files changed, 29 insertions(+)


diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 4b12af01ff00f5..9a1051638a6ff4 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -60,6 +60,9 @@ int fuse_iomap_fallocate(struct file *file, int mode, loff_t offset,
 			 loff_t length, loff_t new_size);
 int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
 				 loff_t endpos);
+
+int fuse_dev_ioctl_iomap_support(struct file *file,
+				 struct fuse_iomap_support __user *argp);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -83,6 +86,7 @@ int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
 # define fuse_iomap_setsize_start(...)		(-ENOSYS)
 # define fuse_iomap_fallocate(...)		(-ENOSYS)
 # define fuse_iomap_flush_unmap_range(...)	(-ENOSYS)
+# define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 71b216262c84cb..de9b56e6e8d250 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1156,6 +1156,13 @@ struct fuse_backing_map {
 	uint64_t	padding;
 };
 
+/* basic file I/O functionality through iomap */
+#define FUSE_IOMAP_SUPPORT_FILEIO	(1ULL << 0)
+struct fuse_iomap_support {
+	uint64_t	flags;
+	uint64_t	padding;
+};
+
 /* Device ioctls: */
 #define FUSE_DEV_IOC_MAGIC		229
 #define FUSE_DEV_IOC_CLONE		_IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
@@ -1163,6 +1170,8 @@ struct fuse_backing_map {
 					     struct fuse_backing_map)
 #define FUSE_DEV_IOC_BACKING_CLOSE	_IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t)
 #define FUSE_DEV_IOC_SYNC_INIT		_IO(FUSE_DEV_IOC_MAGIC, 3)
+#define FUSE_DEV_IOC_IOMAP_SUPPORT	_IOR(FUSE_DEV_IOC_MAGIC, 99, \
+					     struct fuse_iomap_support)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index c5593f35dcb675..39d3c36774de55 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2713,6 +2713,9 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
 	case FUSE_DEV_IOC_SYNC_INIT:
 		return fuse_dev_ioctl_sync_init(file);
 
+	case FUSE_DEV_IOC_IOMAP_SUPPORT:
+		return fuse_dev_ioctl_iomap_support(file, argp);
+
 	default:
 		return -ENOTTY;
 	}
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 70b6fb922fc9ec..3395b1cd907afa 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -1818,3 +1818,16 @@ fuse_iomap_fallocate(
 	file_update_time(file);
 	return 0;
 }
+
+int fuse_dev_ioctl_iomap_support(struct file *file,
+				 struct fuse_iomap_support __user *argp)
+{
+	struct fuse_iomap_support ios = { };
+
+	if (fuse_iomap_enabled())
+		ios.flags = FUSE_IOMAP_SUPPORT_FILEIO;
+
+	if (copy_to_user(argp, &ios, sizeof(ios)))
+		return -EFAULT;
+	return 0;
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 21/33] fuse: query filesystem geometry when using iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (19 preceding siblings ...)
  2026-02-23 23:13   ` [PATCH 20/33] fuse: advertise support for iomap Darrick J. Wong
@ 2026-02-23 23:14   ` Darrick J. Wong
  2026-02-23 23:14   ` [PATCH 22/33] fuse_trace: " Darrick J. Wong
                     ` (11 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:14 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add a new upcall to the fuse server so that the kernel can request
filesystem geometry bits when iomap mode is in use.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h          |    4 +
 fs/fuse/fuse_iomap.h      |    6 +-
 include/uapi/linux/fuse.h |   39 ++++++++++++
 fs/fuse/fuse_iomap.c      |  147 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |   42 ++++++++++---
 5 files changed, 227 insertions(+), 11 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index b9f41c08cc8fb0..153aa441a78320 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1037,6 +1037,9 @@ struct fuse_conn {
 	struct fuse_ring *ring;
 #endif
 
+	/** How many subsystems still need initialization? */
+	atomic_t need_init;
+
 	/** Only used if the connection opts into request timeouts */
 	struct {
 		/* Worker for checking if any requests have timed out */
@@ -1450,6 +1453,7 @@ struct fuse_dev *fuse_dev_alloc(void);
 void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
 void fuse_dev_free(struct fuse_dev *fud);
 int fuse_send_init(struct fuse_mount *fm);
+void fuse_finish_init(struct fuse_conn *fc, bool ok);
 
 /**
  * Fill in superblock and initialize fuse connection
diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 9a1051638a6ff4..f80c1eae098af3 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -21,7 +21,8 @@ static inline bool fuse_has_iomap(const struct inode *inode)
 
 extern const struct fuse_backing_ops fuse_iomap_backing_ops;
 
-void fuse_iomap_mount(struct fuse_mount *fm);
+int fuse_iomap_mount(struct fuse_mount *fm);
+void fuse_iomap_mount_async(struct fuse_mount *fm);
 void fuse_iomap_unmount(struct fuse_mount *fm);
 
 void fuse_iomap_init_inode(struct inode *inode, struct fuse_attr *attr);
@@ -66,7 +67,8 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
-# define fuse_iomap_mount(...)			((void)0)
+# define fuse_iomap_mount(...)			(0)
+# define fuse_iomap_mount_async(...)		((void)0)
 # define fuse_iomap_unmount(...)		((void)0)
 # define fuse_iomap_init_inode(...)		((void)0)
 # define fuse_iomap_evict_inode(...)		((void)0)
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index de9b56e6e8d250..33668d66e9c4b4 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -246,6 +246,7 @@
  *  - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations
  *  - add FUSE_ATTR_EXCLUSIVE to enable exclusive mode for specific inodes
  *  - add FUSE_ATTR_IOMAP to enable iomap for specific inodes
+ *  - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry
  */
 
 #ifndef _LINUX_FUSE_H
@@ -677,6 +678,7 @@ enum fuse_opcode {
 	FUSE_STATX		= 52,
 	FUSE_COPY_FILE_RANGE_64	= 53,
 
+	FUSE_IOMAP_CONFIG	= 4092,
 	FUSE_IOMAP_IOEND	= 4093,
 	FUSE_IOMAP_BEGIN	= 4094,
 	FUSE_IOMAP_END		= 4095,
@@ -1452,4 +1454,41 @@ struct fuse_iomap_ioend_out {
 	uint64_t newsize;	/* new ondisk size */
 };
 
+struct fuse_iomap_config_in {
+	uint64_t flags;		/* supported FUSE_IOMAP_CONFIG_* flags */
+	int64_t maxbytes;	/* maximum supported file size */
+	uint64_t padding[6];	/* zero */
+};
+
+/* Which fields are set in fuse_iomap_config_out? */
+#define FUSE_IOMAP_CONFIG_SID		(1 << 0ULL)
+#define FUSE_IOMAP_CONFIG_UUID		(1 << 1ULL)
+#define FUSE_IOMAP_CONFIG_BLOCKSIZE	(1 << 2ULL)
+#define FUSE_IOMAP_CONFIG_MAX_LINKS	(1 << 3ULL)
+#define FUSE_IOMAP_CONFIG_TIME		(1 << 4ULL)
+#define FUSE_IOMAP_CONFIG_MAXBYTES	(1 << 5ULL)
+
+struct fuse_iomap_config_out {
+	uint64_t flags;		/* FUSE_IOMAP_CONFIG_* */
+
+	char s_id[32];		/* Informational name */
+	char s_uuid[16];	/* UUID */
+
+	uint8_t s_uuid_len;	/* length of s_uuid */
+
+	uint8_t s_pad[3];	/* must be zeroes */
+
+	uint32_t s_blocksize;	/* fs block size */
+	uint32_t s_max_links;	/* max hard links */
+
+	/* Granularity of c/m/atime in ns (cannot be worse than a second) */
+	uint32_t s_time_gran;
+
+	/* Time limits for c/m/atime in seconds */
+	int64_t s_time_min;
+	int64_t s_time_max;
+
+	int64_t s_maxbytes;	/* max file size */
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 3395b1cd907afa..d9be7d47fb7acd 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -718,14 +718,103 @@ const struct fuse_backing_ops fuse_iomap_backing_ops = {
 	.post_open = fuse_iomap_post_open,
 };
 
-void fuse_iomap_mount(struct fuse_mount *fm)
+struct fuse_iomap_config_args {
+	struct fuse_args args;
+	struct fuse_iomap_config_in inarg;
+	struct fuse_iomap_config_out outarg;
+};
+
+#define FUSE_IOMAP_CONFIG_ALL (FUSE_IOMAP_CONFIG_SID | \
+			       FUSE_IOMAP_CONFIG_UUID | \
+			       FUSE_IOMAP_CONFIG_BLOCKSIZE | \
+			       FUSE_IOMAP_CONFIG_MAX_LINKS | \
+			       FUSE_IOMAP_CONFIG_TIME | \
+			       FUSE_IOMAP_CONFIG_MAXBYTES)
+
+static int fuse_iomap_process_config(struct fuse_mount *fm, int error,
+				     const struct fuse_iomap_config_out *outarg)
 {
+	struct super_block *sb = fm->sb;
+
+	switch (error) {
+	case 0:
+		break;
+	case -ENOSYS:
+		return 0;
+	default:
+		return error;
+	}
+
+	if (outarg->flags & ~FUSE_IOMAP_CONFIG_ALL)
+		return -EINVAL;
+
+	if (outarg->s_uuid_len > sizeof(outarg->s_uuid))
+		return -EINVAL;
+
+	if (memchr_inv(outarg->s_pad, 0, sizeof(outarg->s_pad)))
+		return -EINVAL;
+
+	if (outarg->flags & FUSE_IOMAP_CONFIG_BLOCKSIZE) {
+		if (sb->s_bdev) {
+#ifdef CONFIG_BLOCK
+			if (!sb_set_blocksize(sb, outarg->s_blocksize))
+				return -EINVAL;
+#else
+			/*
+			 * XXX: how do we have a bdev filesystem without
+			 * CONFIG_BLOCK???
+			 */
+			return -EINVAL;
+#endif
+		} else {
+			sb->s_blocksize = outarg->s_blocksize;
+			sb->s_blocksize_bits = blksize_bits(outarg->s_blocksize);
+		}
+	}
+
+	if (outarg->flags & FUSE_IOMAP_CONFIG_SID)
+		memcpy(sb->s_id, outarg->s_id, sizeof(sb->s_id));
+
+	if (outarg->flags & FUSE_IOMAP_CONFIG_UUID) {
+		memcpy(&sb->s_uuid, outarg->s_uuid, outarg->s_uuid_len);
+		sb->s_uuid_len = outarg->s_uuid_len;
+	}
+
+	if (outarg->flags & FUSE_IOMAP_CONFIG_MAX_LINKS)
+		sb->s_max_links = outarg->s_max_links;
+
+	if (outarg->flags & FUSE_IOMAP_CONFIG_TIME) {
+		sb->s_time_gran = outarg->s_time_gran;
+		sb->s_time_min = outarg->s_time_min;
+		sb->s_time_max = outarg->s_time_max;
+	}
+
+	if (outarg->flags & FUSE_IOMAP_CONFIG_MAXBYTES)
+		sb->s_maxbytes = outarg->s_maxbytes;
+
+	return 0;
+}
+
+static void fuse_iomap_config_reply(struct fuse_mount *fm,
+				    struct fuse_args *args, int error)
+{
+	struct fuse_iomap_config_args *ia =
+		container_of(args, struct fuse_iomap_config_args, args);
 	struct fuse_conn *fc = fm->fc;
 	struct super_block *sb = fm->sb;
 	struct backing_dev_info *old_bdi = sb->s_bdi;
 	char *suffix = sb->s_bdev ? "-fuseblk" : "-fuse";
+	bool ok = true;
 	int res;
 
+	res = fuse_iomap_process_config(fm, error, &ia->outarg);
+	if (res) {
+		printk(KERN_ERR "%s: could not configure iomap, err=%d",
+		       sb->s_id, res);
+		ok = false;
+		goto done;
+	}
+
 	/*
 	 * sb->s_bdi points to the initial private bdi.  However, we want to
 	 * redirect it to a new private bdi with default dirty and readahead
@@ -749,6 +838,62 @@ void fuse_iomap_mount(struct fuse_mount *fm)
 	 * freeze/thaw properly.
 	 */
 	fc->sync_fs = true;
+
+done:
+	kfree(ia);
+	fuse_finish_init(fc, ok);
+}
+
+static struct fuse_iomap_config_args *
+fuse_iomap_new_mount(struct fuse_mount *fm)
+{
+	struct fuse_iomap_config_args *ia;
+
+	ia = kzalloc(sizeof(*ia), GFP_KERNEL | __GFP_NOFAIL);
+	ia->inarg.maxbytes = MAX_LFS_FILESIZE;
+	ia->inarg.flags = FUSE_IOMAP_CONFIG_ALL;
+
+	ia->args.opcode = FUSE_IOMAP_CONFIG;
+	ia->args.nodeid = 0;
+	ia->args.in_numargs = 1;
+	ia->args.in_args[0].size = sizeof(ia->inarg);
+	ia->args.in_args[0].value = &ia->inarg;
+	ia->args.out_argvar = true;
+	ia->args.out_numargs = 1;
+	ia->args.out_args[0].size = sizeof(ia->outarg);
+	ia->args.out_args[0].value = &ia->outarg;
+	ia->args.force = true;
+	ia->args.nocreds = true;
+
+	return ia;
+}
+
+int fuse_iomap_mount(struct fuse_mount *fm)
+{
+	struct fuse_iomap_config_args *ia = fuse_iomap_new_mount(fm);
+	int err;
+
+	ASSERT(fm->fc->sync_init);
+
+	err = fuse_simple_request(fm, &ia->args);
+	/* Ignore size of iomap_config reply */
+	if (err > 0)
+		err = 0;
+	fuse_iomap_config_reply(fm, &ia->args, err);
+	return err;
+}
+
+void fuse_iomap_mount_async(struct fuse_mount *fm)
+{
+	struct fuse_iomap_config_args *ia = fuse_iomap_new_mount(fm);
+	int err;
+
+	ASSERT(!fm->fc->sync_init);
+
+	ia->args.end = fuse_iomap_config_reply;
+	err = fuse_simple_background(fm, &ia->args, GFP_KERNEL);
+	if (err)
+		fuse_iomap_config_reply(fm, &ia->args, -ENOTCONN);
 }
 
 void fuse_iomap_unmount(struct fuse_mount *fm)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 039a780749da30..4d805c7f484517 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1354,6 +1354,8 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 	struct fuse_init_out *arg = &ia->out;
 	bool ok = true;
 
+	atomic_inc(&fc->need_init);
+
 	if (error || arg->major != FUSE_KERNEL_VERSION)
 		ok = false;
 	else {
@@ -1500,9 +1502,6 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 
 		init_server_timeout(fc, timeout);
 
-		if (fc->iomap)
-			fuse_iomap_mount(fm);
-
 		fm->sb->s_bdi->ra_pages =
 				min(fm->sb->s_bdi->ra_pages, ra_pages);
 		fc->minor = arg->minor;
@@ -1512,13 +1511,27 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 	}
 	kfree(ia);
 
-	if (!ok) {
+	if (!ok)
 		fc->conn_init = 0;
+
+	if (ok && fc->iomap) {
+		atomic_inc(&fc->need_init);
+		if (!fc->sync_init)
+			fuse_iomap_mount_async(fm);
+	}
+
+	fuse_finish_init(fc, ok);
+}
+
+void fuse_finish_init(struct fuse_conn *fc, bool ok)
+{
+	if (!ok)
 		fc->conn_error = 1;
-	}
 
-	fuse_set_initialized(fc);
-	wake_up_all(&fc->blocked_waitq);
+	if (atomic_dec_and_test(&fc->need_init)) {
+		fuse_set_initialized(fc);
+		wake_up_all(&fc->blocked_waitq);
+	}
 }
 
 static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)
@@ -1995,7 +2008,20 @@ static int fuse_fill_super(struct super_block *sb, struct fs_context *fsc)
 
 	fm = get_fuse_mount_super(sb);
 
-	return fuse_send_init(fm);
+	err = fuse_send_init(fm);
+	if (err)
+		return err;
+
+	if (fm->fc->conn_init && fm->fc->sync_init && fm->fc->iomap) {
+		err = fuse_iomap_mount(fm);
+		if (err)
+			return err;
+	}
+
+	if (fm->fc->conn_error)
+		return -EIO;
+
+	return 0;
 }
 
 /*


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 22/33] fuse_trace: query filesystem geometry when using iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (20 preceding siblings ...)
  2026-02-23 23:14   ` [PATCH 21/33] fuse: query filesystem geometry when using iomap Darrick J. Wong
@ 2026-02-23 23:14   ` Darrick J. Wong
  2026-02-23 23:14   ` [PATCH 23/33] fuse: implement fadvise for iomap files Darrick J. Wong
                     ` (10 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:14 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    2 ++
 2 files changed, 50 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index c832fb9012d983..96c4db84c7106a 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -58,6 +58,7 @@
 	EM( FUSE_SYNCFS,		"FUSE_SYNCFS")		\
 	EM( FUSE_TMPFILE,		"FUSE_TMPFILE")		\
 	EM( FUSE_STATX,			"FUSE_STATX")		\
+	EM( FUSE_IOMAP_CONFIG,		"FUSE_IOMAP_CONFIG")	\
 	EM( FUSE_IOMAP_BEGIN,		"FUSE_IOMAP_BEGIN")	\
 	EM( FUSE_IOMAP_END,		"FUSE_IOMAP_END")	\
 	EM( FUSE_IOMAP_IOEND,		"FUSE_IOMAP_IOEND")	\
@@ -345,6 +346,14 @@ TRACE_DEFINE_ENUM(FUSE_I_IOMAP);
 	{ IOMAP_IOEND_BOUNDARY,			"boundary" }, \
 	{ IOMAP_IOEND_DIRECT,			"direct" }
 
+#define FUSE_IOMAP_CONFIG_STRINGS \
+	{ FUSE_IOMAP_CONFIG_SID,		"sid" }, \
+	{ FUSE_IOMAP_CONFIG_UUID,		"uuid" }, \
+	{ FUSE_IOMAP_CONFIG_BLOCKSIZE,		"blocksize" }, \
+	{ FUSE_IOMAP_CONFIG_MAX_LINKS,		"max_links" }, \
+	{ FUSE_IOMAP_CONFIG_TIME,		"time" }, \
+	{ FUSE_IOMAP_CONFIG_MAXBYTES,		"maxbytes" }
+
 DECLARE_EVENT_CLASS(fuse_iomap_check_class,
 	TP_PROTO(const char *func, int line, const char *condition),
 
@@ -1005,6 +1014,45 @@ TRACE_EVENT(fuse_iomap_fallocate,
 		  __entry->mode,
 		  __entry->newsize)
 );
+
+TRACE_EVENT(fuse_iomap_config,
+	TP_PROTO(const struct fuse_mount *fm,
+		 const struct fuse_iomap_config_out *outarg),
+	TP_ARGS(fm, outarg),
+
+	TP_STRUCT__entry(
+		__field(dev_t,			connection)
+
+		__field(uint64_t,		flags)
+		__field(uint32_t,		blocksize)
+		__field(uint32_t,		max_links)
+		__field(uint32_t,		time_gran)
+
+		__field(int64_t,		time_min)
+		__field(int64_t,		time_max)
+		__field(int64_t,		maxbytes)
+		__field(uint8_t,		uuid_len)
+	),
+
+	TP_fast_assign(
+		__entry->connection	=	fm->fc->dev;
+		__entry->flags		=	outarg->flags;
+		__entry->blocksize	=	outarg->s_blocksize;
+		__entry->max_links	=	outarg->s_max_links;
+		__entry->time_gran	=	outarg->s_time_gran;
+		__entry->time_min	=	outarg->s_time_min;
+		__entry->time_max	=	outarg->s_time_max;
+		__entry->maxbytes	=	outarg->s_maxbytes;
+		__entry->uuid_len	=	outarg->s_uuid_len;
+	),
+
+	TP_printk("connection %u flags (%s) blocksize 0x%x max_links %u time_gran %u time_min %lld time_max %lld maxbytes 0x%llx uuid_len %u",
+		  __entry->connection,
+		  __print_flags(__entry->flags, "|", FUSE_IOMAP_CONFIG_STRINGS),
+		  __entry->blocksize, __entry->max_links, __entry->time_gran,
+		  __entry->time_min, __entry->time_max, __entry->maxbytes,
+		  __entry->uuid_len)
+);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index d9be7d47fb7acd..b7614674fae9e5 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -745,6 +745,8 @@ static int fuse_iomap_process_config(struct fuse_mount *fm, int error,
 		return error;
 	}
 
+	trace_fuse_iomap_config(fm, outarg);
+
 	if (outarg->flags & ~FUSE_IOMAP_CONFIG_ALL)
 		return -EINVAL;
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 23/33] fuse: implement fadvise for iomap files
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (21 preceding siblings ...)
  2026-02-23 23:14   ` [PATCH 22/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:14   ` Darrick J. Wong
  2026-02-23 23:14   ` [PATCH 24/33] fuse: invalidate ranges of block devices being used for iomap Darrick J. Wong
                     ` (9 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:14 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

If userspace asks us to perform readahead on a file, take i_rwsem so
that it can't race with hole punching or writes.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.h |    3 +++
 fs/fuse/file.c       |    1 +
 fs/fuse/fuse_iomap.c |   20 ++++++++++++++++++++
 3 files changed, 24 insertions(+)


diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index f80c1eae098af3..3e5df67db2a1fe 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -64,6 +64,8 @@ int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
 
 int fuse_dev_ioctl_iomap_support(struct file *file,
 				 struct fuse_iomap_support __user *argp);
+
+int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -89,6 +91,7 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
 # define fuse_iomap_fallocate(...)		(-ENOSYS)
 # define fuse_iomap_flush_unmap_range(...)	(-ENOSYS)
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
+# define fuse_iomap_fadvise			NULL
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 0828ecb20a828c..1243d0eea22a37 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -3252,6 +3252,7 @@ static const struct file_operations fuse_file_operations = {
 	.fallocate	= fuse_file_fallocate,
 	.copy_file_range = fuse_copy_file_range,
 	.setlease	= generic_setlease,
+	.fadvise	= fuse_iomap_fadvise,
 };
 
 static const struct address_space_operations fuse_file_aops  = {
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index b7614674fae9e5..df92740f1e781b 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -7,6 +7,7 @@
 #include <linux/fiemap.h>
 #include <linux/pagemap.h>
 #include <linux/falloc.h>
+#include <linux/fadvise.h>
 #include "fuse_i.h"
 #include "fuse_trace.h"
 #include "fuse_iomap.h"
@@ -1978,3 +1979,22 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
 		return -EFAULT;
 	return 0;
 }
+
+int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice)
+{
+	struct inode *inode = file_inode(file);
+	bool needlock = advice == POSIX_FADV_WILLNEED &&
+			fuse_inode_has_iomap(inode);
+	int ret;
+
+	/*
+	 * Operations creating pages in page cache need protection from hole
+	 * punching and similar ops
+	 */
+	if (needlock)
+		inode_lock_shared(inode);
+	ret = generic_fadvise(file, start, end, advice);
+	if (needlock)
+		inode_unlock_shared(inode);
+	return ret;
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 24/33] fuse: invalidate ranges of block devices being used for iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (22 preceding siblings ...)
  2026-02-23 23:14   ` [PATCH 23/33] fuse: implement fadvise for iomap files Darrick J. Wong
@ 2026-02-23 23:14   ` Darrick J. Wong
  2026-02-23 23:15   ` [PATCH 25/33] fuse_trace: " Darrick J. Wong
                     ` (8 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:14 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Make it easier to invalidate the page cache for a block device that is
being used in conjunction with iomap.  This allows a fuse server to kill
all cached data for a block that is being freed, so that block reuse
doesn't result in file corruption.  Right now, the only way to do this
is with fadvise, which ignores and doesn't wait for pages undergoing
writeback.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.h      |    3 +++
 include/uapi/linux/fuse.h |   16 ++++++++++++++++
 fs/fuse/dev.c             |   27 +++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c      |   41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+)


diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 3e5df67db2a1fe..d4a4d9f0313edf 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -64,6 +64,8 @@ int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
 
 int fuse_dev_ioctl_iomap_support(struct file *file,
 				 struct fuse_iomap_support __user *argp);
+int fuse_iomap_dev_inval(struct fuse_conn *fc,
+			 const struct fuse_iomap_dev_inval_out *arg);
 
 int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
 #else
@@ -91,6 +93,7 @@ int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
 # define fuse_iomap_fallocate(...)		(-ENOSYS)
 # define fuse_iomap_flush_unmap_range(...)	(-ENOSYS)
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
+# define fuse_iomap_dev_inval(...)		(-ENOSYS)
 # define fuse_iomap_fadvise			NULL
 #endif /* CONFIG_FUSE_IOMAP */
 
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 33668d66e9c4b4..1ef7152306a24f 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -247,6 +247,7 @@
  *  - add FUSE_ATTR_EXCLUSIVE to enable exclusive mode for specific inodes
  *  - add FUSE_ATTR_IOMAP to enable iomap for specific inodes
  *  - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry
+ *  - add FUSE_NOTIFY_IOMAP_DEV_INVAL to invalidate iomap bdev ranges
  */
 
 #ifndef _LINUX_FUSE_H
@@ -701,6 +702,8 @@ enum fuse_notify_code {
 	FUSE_NOTIFY_RESEND = 7,
 	FUSE_NOTIFY_INC_EPOCH = 8,
 	FUSE_NOTIFY_PRUNE = 9,
+	FUSE_NOTIFY_IOMAP_DEV_INVAL = 99,
+	FUSE_NOTIFY_CODE_MAX,
 };
 
 /* The read buffer is required to be at least 8k, but may be much larger */
@@ -1491,4 +1494,17 @@ struct fuse_iomap_config_out {
 	int64_t s_maxbytes;	/* max file size */
 };
 
+struct fuse_range {
+	uint64_t offset;
+	uint64_t length;
+};
+
+struct fuse_iomap_dev_inval_out {
+	uint32_t dev;		/* device cookie */
+	uint32_t reserved;	/* zero */
+
+	/* range of bdev pagecache to invalidate, in bytes */
+	struct fuse_range range;
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 39d3c36774de55..9a814a0d222fe6 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1849,6 +1849,30 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 	return err;
 }
 
+static int fuse_notify_iomap_dev_inval(struct fuse_conn *fc, unsigned int size,
+				       struct fuse_copy_state *cs)
+{
+	struct fuse_iomap_dev_inval_out outarg;
+	int err = -EINVAL;
+
+	if (size != sizeof(outarg))
+		goto err;
+
+	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
+	if (err)
+		goto err;
+	if (outarg.reserved) {
+		err = -EINVAL;
+		goto err;
+	}
+	fuse_copy_finish(cs);
+
+	return fuse_iomap_dev_inval(fc, &outarg);
+err:
+	fuse_copy_finish(cs);
+	return err;
+}
+
 struct fuse_retrieve_args {
 	struct fuse_args_pages ap;
 	struct fuse_notify_retrieve_in inarg;
@@ -2133,6 +2157,9 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 	case FUSE_NOTIFY_PRUNE:
 		return fuse_notify_prune(fc, size, cs);
 
+	case FUSE_NOTIFY_IOMAP_DEV_INVAL:
+		return fuse_notify_iomap_dev_inval(fc, size, cs);
+
 	default:
 		return -EINVAL;
 	}
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index df92740f1e781b..21c286c285a59d 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -1998,3 +1998,44 @@ int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice)
 		inode_unlock_shared(inode);
 	return ret;
 }
+
+int fuse_iomap_dev_inval(struct fuse_conn *fc,
+			 const struct fuse_iomap_dev_inval_out *arg)
+{
+	struct fuse_backing *fb;
+	struct block_device *bdev;
+	loff_t end;
+	int ret = 0;
+
+	if (!fc->iomap || arg->dev == FUSE_IOMAP_DEV_NULL)
+		return -EINVAL;
+
+	down_read(&fc->killsb);
+	fb = fuse_backing_lookup(fc, &fuse_iomap_backing_ops, arg->dev);
+	if (!fb) {
+		ret = -ENODEV;
+		goto out_killsb;
+	}
+	bdev = fb->bdev;
+
+	inode_lock(bdev->bd_mapping->host);
+	filemap_invalidate_lock(bdev->bd_mapping);
+
+	if (check_add_overflow(arg->range.offset, arg->range.length, &end) ||
+	    arg->range.offset >= bdev_nr_bytes(bdev)) {
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	end = min(end, bdev_nr_bytes(bdev));
+	truncate_inode_pages_range(bdev->bd_mapping, arg->range.offset,
+				   end - 1);
+
+out_unlock:
+	filemap_invalidate_unlock(bdev->bd_mapping);
+	inode_unlock(bdev->bd_mapping->host);
+	fuse_backing_put(fb);
+out_killsb:
+	up_read(&fc->killsb);
+	return ret;
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 25/33] fuse_trace: invalidate ranges of block devices being used for iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (23 preceding siblings ...)
  2026-02-23 23:14   ` [PATCH 24/33] fuse: invalidate ranges of block devices being used for iomap Darrick J. Wong
@ 2026-02-23 23:15   ` Darrick J. Wong
  2026-02-23 23:15   ` [PATCH 26/33] fuse: implement inline data file IO via iomap Darrick J. Wong
                     ` (7 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:15 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   26 ++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    2 ++
 2 files changed, 28 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 96c4db84c7106a..0e4be645802055 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -1053,6 +1053,32 @@ TRACE_EVENT(fuse_iomap_config,
 		  __entry->time_min, __entry->time_max, __entry->maxbytes,
 		  __entry->uuid_len)
 );
+
+TRACE_EVENT(fuse_iomap_dev_inval,
+	TP_PROTO(const struct fuse_conn *fc,
+		 const struct fuse_iomap_dev_inval_out *arg),
+	TP_ARGS(fc, arg),
+
+	TP_STRUCT__entry(
+		__field(dev_t,			connection)
+		__field(int,			dev)
+		__field(unsigned long long,	offset)
+		__field(unsigned long long,	length)
+	),
+
+	TP_fast_assign(
+		__entry->connection	=	fc->dev;
+		__entry->dev		=	arg->dev;
+		__entry->offset		=	arg->range.offset;
+		__entry->length		=	arg->range.length;
+	),
+
+	TP_printk("connection %u dev %d offset 0x%llx length 0x%llx",
+		  __entry->connection,
+		  __entry->dev,
+		  __entry->offset,
+		  __entry->length)
+);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 21c286c285a59d..e8a0c1ceb409c4 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -2007,6 +2007,8 @@ int fuse_iomap_dev_inval(struct fuse_conn *fc,
 	loff_t end;
 	int ret = 0;
 
+	trace_fuse_iomap_dev_inval(fc, arg);
+
 	if (!fc->iomap || arg->dev == FUSE_IOMAP_DEV_NULL)
 		return -EINVAL;
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 26/33] fuse: implement inline data file IO via iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (24 preceding siblings ...)
  2026-02-23 23:15   ` [PATCH 25/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:15   ` Darrick J. Wong
  2026-02-27 18:02     ` Darrick J. Wong
  2026-02-23 23:15   ` [PATCH 27/33] fuse_trace: " Darrick J. Wong
                     ` (6 subsequent siblings)
  32 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:15 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Implement inline data file IO by issuing FUSE_READ/FUSE_WRITE commands
in response to an inline data mapping.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.c |  205 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 197 insertions(+), 8 deletions(-)


diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index e8a0c1ceb409c4..1c3d99f11634d2 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -398,6 +398,152 @@ fuse_iomap_find_dev(struct fuse_conn *fc, const struct fuse_iomap_io *map)
 	return ret;
 }
 
+static inline int fuse_iomap_inline_alloc(struct iomap *iomap)
+{
+	ASSERT(iomap->inline_data == NULL);
+	ASSERT(iomap->length > 0);
+
+	iomap->inline_data = kvzalloc(iomap->length, GFP_KERNEL);
+	return iomap->inline_data ? 0 : -ENOMEM;
+}
+
+static inline void fuse_iomap_inline_free(struct iomap *iomap)
+{
+	kvfree(iomap->inline_data);
+	iomap->inline_data = NULL;
+}
+
+/*
+ * Use the FUSE_READ command to read inline file data from the fuse server.
+ * Note that there's no file handle attached, so the fuse server must be able
+ * to reconnect to the inode via the nodeid.
+ */
+static int fuse_iomap_inline_read(struct inode *inode, loff_t pos,
+				  loff_t count, struct iomap *iomap)
+{
+	struct fuse_read_in in = {
+		.offset = pos,
+		.size = count,
+	};
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_mount *fm = get_fuse_mount(inode);
+	FUSE_ARGS(args);
+	ssize_t ret;
+
+	if (BAD_DATA(!iomap_inline_data_valid(iomap))) {
+		fuse_iomap_inline_free(iomap);
+		return -EFSCORRUPTED;
+	}
+
+	args.opcode = FUSE_READ;
+	args.nodeid = fi->nodeid;
+	args.in_numargs = 1;
+	args.in_args[0].size = sizeof(in);
+	args.in_args[0].value = &in;
+	args.out_argvar = true;
+	args.out_numargs = 1;
+	args.out_args[0].size = count;
+	args.out_args[0].value = iomap_inline_data(iomap, pos);
+
+	ret = fuse_simple_request(fm, &args);
+	if (ret < 0) {
+		fuse_iomap_inline_free(iomap);
+		return ret;
+	}
+	/* no readahead means something bad happened */
+	if (ret == 0) {
+		fuse_iomap_inline_free(iomap);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+/*
+ * Use the FUSE_WRITE command to write inline file data from the fuse server.
+ * Note that there's no file handle attached, so the fuse server must be able
+ * to reconnect to the inode via the nodeid.
+ */
+static int fuse_iomap_inline_write(struct inode *inode, loff_t pos,
+				   loff_t count, struct iomap *iomap)
+{
+	struct fuse_write_in in = {
+		.offset = pos,
+		.size = count,
+	};
+	struct fuse_write_out out = { };
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_mount *fm = get_fuse_mount(inode);
+	FUSE_ARGS(args);
+	ssize_t ret;
+
+	if (BAD_DATA(!iomap_inline_data_valid(iomap)))
+		return -EFSCORRUPTED;
+
+	args.opcode = FUSE_WRITE;
+	args.nodeid = fi->nodeid;
+	args.in_numargs = 2;
+	args.in_args[0].size = sizeof(in);
+	args.in_args[0].value = &in;
+	args.in_args[1].size = count;
+	args.in_args[1].value = iomap_inline_data(iomap, pos);
+	args.out_numargs = 1;
+	args.out_args[0].size = sizeof(out);
+	args.out_args[0].value = &out;
+
+	ret = fuse_simple_request(fm, &args);
+	if (ret < 0) {
+		fuse_iomap_inline_free(iomap);
+		return ret;
+	}
+	/* short write means something bad happened */
+	if (out.size < count) {
+		fuse_iomap_inline_free(iomap);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+/* Set up inline data buffers for iomap_begin */
+static int fuse_iomap_set_inline(struct inode *inode, unsigned opflags,
+				 loff_t pos, loff_t count,
+				 struct iomap *iomap, struct iomap *srcmap)
+{
+	int err;
+
+	if (opflags & IOMAP_REPORT)
+		return 0;
+
+	if (fuse_is_iomap_file_write(opflags)) {
+		if (iomap->type == IOMAP_INLINE) {
+			err = fuse_iomap_inline_alloc(iomap);
+			if (err)
+				return err;
+		}
+
+		if (srcmap->type == IOMAP_INLINE) {
+			err = fuse_iomap_inline_alloc(srcmap);
+			if (!err)
+				err = fuse_iomap_inline_read(inode, pos, count,
+							     srcmap);
+			if (err) {
+				fuse_iomap_inline_free(iomap);
+				return err;
+			}
+		}
+	} else if (iomap->type == IOMAP_INLINE) {
+		/* inline data read */
+		err = fuse_iomap_inline_alloc(iomap);
+		if (!err)
+			err = fuse_iomap_inline_read(inode, pos, count, iomap);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 			    unsigned opflags, struct iomap *iomap,
 			    struct iomap *srcmap)
@@ -467,12 +613,20 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 		fuse_iomap_from_server(iomap, read_dev, &outarg.read);
 	}
 
+	if (iomap->type == IOMAP_INLINE || srcmap->type == IOMAP_INLINE) {
+		err = fuse_iomap_set_inline(inode, opflags, pos, count, iomap,
+					    srcmap);
+		if (err)
+			goto out_write_dev;
+	}
+
 	/*
 	 * XXX: if we ever want to support closing devices, we need a way to
 	 * track the fuse_backing refcount all the way through bio endios.
 	 * For now we put the refcount here because you can't remove an iomap
 	 * device until unmount time.
 	 */
+out_write_dev:
 	fuse_backing_put(write_dev);
 out_read_dev:
 	fuse_backing_put(read_dev);
@@ -511,8 +665,28 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
 {
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	struct fuse_mount *fm = get_fuse_mount(inode);
+	struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
+	struct iomap *srcmap = &iter->srcmap;
 	int err;
 
+	if (srcmap->inline_data)
+		fuse_iomap_inline_free(srcmap);
+
+	if (iomap->inline_data) {
+		if (fuse_is_iomap_file_write(opflags) && written > 0) {
+			err = fuse_iomap_inline_write(inode, pos, written,
+						      iomap);
+			fuse_iomap_inline_free(iomap);
+			if (err)
+				return err;
+		} else {
+			fuse_iomap_inline_free(iomap);
+		}
+
+		/* fuse server should already be aware of what happened */
+		return 0;
+	}
+
 	if (fuse_should_send_iomap_end(fm, iomap, opflags, count, written)) {
 		struct fuse_iomap_end_in inarg = {
 			.opflags = fuse_iomap_op_to_server(opflags),
@@ -1461,7 +1635,6 @@ static ssize_t fuse_iomap_writeback_range(struct iomap_writepage_ctx *wpc,
 					  unsigned int len, u64 end_pos)
 {
 	struct inode *inode = wpc->inode;
-	struct iomap write_iomap, dontcare;
 	ssize_t ret;
 
 	if (fuse_is_bad(inode)) {
@@ -1474,23 +1647,39 @@ static ssize_t fuse_iomap_writeback_range(struct iomap_writepage_ctx *wpc,
 	trace_fuse_iomap_writeback_range(inode, offset, len, end_pos);
 
 	if (!fuse_iomap_revalidate_writeback(wpc, offset)) {
+		struct iomap_iter fake_iter = { };
+		struct iomap *write_iomap = &fake_iter.iomap;
+
 		ret = fuse_iomap_begin(inode, offset, len,
-				       FUSE_IOMAP_OP_WRITEBACK,
-				       &write_iomap, &dontcare);
+				       FUSE_IOMAP_OP_WRITEBACK, write_iomap,
+				       &fake_iter.srcmap);
 		if (ret)
 			goto discard_folio;
 
+		if (BAD_DATA(write_iomap->type == IOMAP_INLINE)) {
+			/*
+			 * iomap assumes that inline data writes are completed
+			 * by the time ->iomap_end completes, so it should
+			 * never mark a pagecache folio dirty.
+			 */
+			fuse_iomap_end(inode, offset, len, 0,
+				       FUSE_IOMAP_OP_WRITEBACK,
+				       write_iomap);
+			ret = -EIO;
+			goto discard_folio;
+		}
+
 		/*
 		 * Landed in a hole or beyond EOF?  Send that to iomap, it'll
 		 * skip writing back the file range.
 		 */
-		if (write_iomap.offset > offset) {
-			write_iomap.length = write_iomap.offset - offset;
-			write_iomap.offset = offset;
-			write_iomap.type = IOMAP_HOLE;
+		if (write_iomap->offset > offset) {
+			write_iomap->length = write_iomap->offset - offset;
+			write_iomap->offset = offset;
+			write_iomap->type = IOMAP_HOLE;
 		}
 
-		memcpy(&wpc->iomap, &write_iomap, sizeof(struct iomap));
+		memcpy(&wpc->iomap, write_iomap, sizeof(struct iomap));
 	}
 
 	ret = iomap_add_to_ioend(wpc, folio, offset, end_pos, len);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 27/33] fuse_trace: implement inline data file IO via iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (25 preceding siblings ...)
  2026-02-23 23:15   ` [PATCH 26/33] fuse: implement inline data file IO via iomap Darrick J. Wong
@ 2026-02-23 23:15   ` Darrick J. Wong
  2026-02-23 23:15   ` [PATCH 28/33] fuse: allow more statx fields Darrick J. Wong
                     ` (5 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:15 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   45 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    7 +++++++
 2 files changed, 52 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 0e4be645802055..d3352e75fa6bdf 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -230,6 +230,7 @@ DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
 #if IS_ENABLED(CONFIG_FUSE_IOMAP)
 struct iomap_writepage_ctx;
 struct iomap_ioend;
+struct iomap;
 
 /* tracepoint boilerplate so we don't have to keep doing this */
 #define FUSE_IOMAP_OPFLAGS_FIELD \
@@ -1079,6 +1080,50 @@ TRACE_EVENT(fuse_iomap_dev_inval,
 		  __entry->offset,
 		  __entry->length)
 );
+
+DECLARE_EVENT_CLASS(fuse_iomap_inline_class,
+	TP_PROTO(const struct inode *inode, loff_t pos, uint64_t count,
+		 const struct iomap *map),
+	TP_ARGS(inode, pos, count, map),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		FUSE_IOMAP_MAP_FIELDS(map)
+		__field(bool,			has_buf)
+		__field(uint64_t,		validity_cookie)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	pos;
+		__entry->length		=	count;
+
+		__entry->mapdev		=	FUSE_IOMAP_DEV_NULL;
+		__entry->mapaddr	=	map->addr;
+		__entry->mapoffset	=	map->offset;
+		__entry->maplength	=	map->length;
+		__entry->maptype	=	map->type;
+		__entry->mapflags	=	map->flags;
+
+		__entry->has_buf	=	map->inline_data != NULL;
+		__entry->validity_cookie=	map->validity_cookie;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() FUSE_IOMAP_MAP_FMT() " has_buf? %d cookie 0x%llx",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(map),
+		  __entry->has_buf,
+		  __entry->validity_cookie)
+);
+#define DEFINE_FUSE_IOMAP_INLINE_EVENT(name)	\
+DEFINE_EVENT(fuse_iomap_inline_class, name,	\
+	TP_PROTO(const struct inode *inode, loff_t pos, uint64_t count, \
+		 const struct iomap *map), \
+	TP_ARGS(inode, pos, count, map))
+DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_inline_read);
+DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_inline_write);
+DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_set_inline_iomap);
+DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_set_inline_srcmap);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 1c3d99f11634d2..6230819d0962a2 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -435,6 +435,8 @@ static int fuse_iomap_inline_read(struct inode *inode, loff_t pos,
 		return -EFSCORRUPTED;
 	}
 
+	trace_fuse_iomap_inline_read(inode, pos, count, iomap);
+
 	args.opcode = FUSE_READ;
 	args.nodeid = fi->nodeid;
 	args.in_numargs = 1;
@@ -480,6 +482,8 @@ static int fuse_iomap_inline_write(struct inode *inode, loff_t pos,
 	if (BAD_DATA(!iomap_inline_data_valid(iomap)))
 		return -EFSCORRUPTED;
 
+	trace_fuse_iomap_inline_write(inode, pos, count, iomap);
+
 	args.opcode = FUSE_WRITE;
 	args.nodeid = fi->nodeid;
 	args.in_numargs = 2;
@@ -541,6 +545,9 @@ static int fuse_iomap_set_inline(struct inode *inode, unsigned opflags,
 			return err;
 	}
 
+	trace_fuse_iomap_set_inline_iomap(inode, pos, count, iomap);
+	trace_fuse_iomap_set_inline_srcmap(inode, pos, count, srcmap);
+
 	return 0;
 }
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 28/33] fuse: allow more statx fields
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (26 preceding siblings ...)
  2026-02-23 23:15   ` [PATCH 27/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:15   ` Darrick J. Wong
  2026-02-23 23:16   ` [PATCH 29/33] fuse: support atomic writes with iomap Darrick J. Wong
                     ` (4 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:15 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Allow the fuse server to supply us with the more recently added fields
of struct statx.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/uapi/linux/fuse.h |   15 ++++++++-
 fs/fuse/dir.c             |   76 ++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 79 insertions(+), 12 deletions(-)


diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 1ef7152306a24f..aa96b4cbdfa255 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -341,7 +341,20 @@ struct fuse_statx {
 	uint32_t	rdev_minor;
 	uint32_t	dev_major;
 	uint32_t	dev_minor;
-	uint64_t	__spare2[14];
+
+	uint64_t	mnt_id;
+	uint32_t	dio_mem_align;
+	uint32_t	dio_offset_align;
+	uint64_t	subvol;
+
+	uint32_t	atomic_write_unit_min;
+	uint32_t	atomic_write_unit_max;
+	uint32_t	atomic_write_segments_max;
+	uint32_t	dio_read_offset_align;
+	uint32_t	atomic_write_unit_max_opt;
+	uint32_t	__spare2[1];
+
+	uint64_t	__spare3[8];
 };
 
 struct fuse_kstatfs {
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index fc0751deebfd20..0492619e397f56 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1466,6 +1466,50 @@ static void fuse_statx_to_attr(struct fuse_statx *sx, struct fuse_attr *attr)
 	attr->blksize = sx->blksize;
 }
 
+#define FUSE_SUPPORTED_STATX_MASK	(STATX_BASIC_STATS | \
+					 STATX_BTIME | \
+					 STATX_DIOALIGN | \
+					 STATX_SUBVOL | \
+					 STATX_WRITE_ATOMIC)
+
+#define FUSE_UNCACHED_STATX_MASK	(STATX_DIOALIGN | \
+					 STATX_SUBVOL | \
+					 STATX_WRITE_ATOMIC)
+
+static void kstat_from_fuse_statx(const struct inode *inode,
+				  struct kstat *stat,
+				  const struct fuse_statx *sx)
+{
+	stat->result_mask = sx->mask & FUSE_SUPPORTED_STATX_MASK;
+
+	stat->attributes |= fuse_statx_attributes(inode, sx);
+	stat->attributes_mask |= fuse_statx_attributes_mask(inode, sx);
+
+	if (sx->mask & STATX_BTIME) {
+		stat->btime.tv_sec = sx->btime.tv_sec;
+		stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec,
+					    NSEC_PER_SEC - 1);
+	}
+
+	if (sx->mask & STATX_DIOALIGN) {
+		stat->dio_mem_align = sx->dio_mem_align;
+		stat->dio_offset_align = sx->dio_offset_align;
+	}
+
+	if (sx->mask & STATX_SUBVOL)
+		stat->subvol = sx->subvol;
+
+	if (sx->mask & STATX_WRITE_ATOMIC) {
+		stat->atomic_write_unit_min = sx->atomic_write_unit_min;
+		stat->atomic_write_unit_max = sx->atomic_write_unit_max;
+		stat->atomic_write_unit_max_opt = sx->atomic_write_unit_max_opt;
+		stat->atomic_write_segments_max = sx->atomic_write_segments_max;
+	}
+
+	if (sx->mask & STATX_DIO_READ_ALIGN)
+		stat->dio_read_offset_align = sx->dio_read_offset_align;
+}
+
 static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
 			 struct file *file, struct kstat *stat)
 {
@@ -1489,7 +1533,7 @@ static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
 	}
 	/* For now leave sync hints as the default, request all stats. */
 	inarg.sx_flags = 0;
-	inarg.sx_mask = STATX_BASIC_STATS | STATX_BTIME;
+	inarg.sx_mask = FUSE_SUPPORTED_STATX_MASK;
 	args.opcode = FUSE_STATX;
 	args.nodeid = get_node_id(inode);
 	args.in_numargs = 1;
@@ -1517,11 +1561,7 @@ static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
 	}
 
 	if (stat) {
-		stat->result_mask = sx->mask & (STATX_BASIC_STATS | STATX_BTIME);
-		stat->btime.tv_sec = sx->btime.tv_sec;
-		stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec, NSEC_PER_SEC - 1);
-		stat->attributes |= fuse_statx_attributes(inode, sx);
-		stat->attributes_mask |= fuse_statx_attributes_mask(inode, sx);
+		kstat_from_fuse_statx(inode, stat, sx);
 		fuse_fillattr(idmap, inode, &attr, stat);
 		stat->result_mask |= STATX_TYPE;
 	}
@@ -1586,16 +1626,30 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,
 	u32 inval_mask = READ_ONCE(fi->inval_mask);
 	u32 cache_mask = fuse_get_cache_mask(inode);
 
-
-	/* FUSE only supports basic stats and possibly btime */
-	request_mask &= STATX_BASIC_STATS | STATX_BTIME;
+	/* Only ask for supported stats */
+	request_mask &= FUSE_SUPPORTED_STATX_MASK;
 retry:
 	if (fc->no_statx)
 		request_mask &= STATX_BASIC_STATS;
 
 	if (!request_mask)
 		sync = false;
-	else if (flags & AT_STATX_FORCE_SYNC)
+	else if (request_mask & FUSE_UNCACHED_STATX_MASK) {
+		switch (flags & AT_STATX_SYNC_TYPE) {
+		case AT_STATX_DONT_SYNC:
+			request_mask &= ~FUSE_UNCACHED_STATX_MASK;
+			sync = false;
+			break;
+		case AT_STATX_FORCE_SYNC:
+		case AT_STATX_SYNC_AS_STAT:
+			sync = true;
+			break;
+		default:
+			WARN_ON(1);
+			sync = false;
+			break;
+		}
+	} else if (flags & AT_STATX_FORCE_SYNC)
 		sync = true;
 	else if (flags & AT_STATX_DONT_SYNC)
 		sync = false;
@@ -1606,7 +1660,7 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,
 
 	if (sync) {
 		forget_all_cached_acls(inode);
-		/* Try statx if BTIME is requested */
+		/* Try statx if a field not covered by regular stat is wanted */
 		if (!fc->no_statx && (request_mask & ~STATX_BASIC_STATS)) {
 			err = fuse_do_statx(idmap, inode, file, stat);
 			if (err == -ENOSYS) {


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 29/33] fuse: support atomic writes with iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (27 preceding siblings ...)
  2026-02-23 23:15   ` [PATCH 28/33] fuse: allow more statx fields Darrick J. Wong
@ 2026-02-23 23:16   ` Darrick J. Wong
  2026-02-24 12:58     ` Pankaj Raghav (Samsung)
  2026-02-23 23:16   ` [PATCH 30/33] fuse_trace: " Darrick J. Wong
                     ` (3 subsequent siblings)
  32 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:16 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Enable untorn writes of up to a single fsblock, if iomap is enabled.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h          |    2 ++
 fs/fuse/fuse_iomap.h      |    7 +++++++
 include/uapi/linux/fuse.h |    5 +++++
 fs/fuse/fuse_iomap.c      |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 58 insertions(+), 1 deletion(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 153aa441a78320..f96c69c755bd9b 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -276,6 +276,8 @@ enum {
 	FUSE_I_EXCLUSIVE,
 	/* Use iomap for this inode */
 	FUSE_I_IOMAP,
+	/* Enable untorn writes */
+	FUSE_I_ATOMIC,
 };
 
 struct fuse_conn;
diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index d4a4d9f0313edf..1d9d39383ca9b2 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -35,6 +35,13 @@ static inline bool fuse_inode_has_iomap(const struct inode *inode)
 	return test_bit(FUSE_I_IOMAP, &fi->state);
 }
 
+static inline bool fuse_inode_has_atomic(const struct inode *inode)
+{
+	const struct fuse_inode *fi = get_fuse_inode(inode);
+
+	return test_bit(FUSE_I_ATOMIC, &fi->state);
+}
+
 int fuse_iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 		      u64 start, u64 length);
 loff_t fuse_iomap_lseek(struct file *file, loff_t offset, int whence);
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index aa96b4cbdfa255..c454cea83083d3 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -248,6 +248,7 @@
  *  - add FUSE_ATTR_IOMAP to enable iomap for specific inodes
  *  - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry
  *  - add FUSE_NOTIFY_IOMAP_DEV_INVAL to invalidate iomap bdev ranges
+ *  - add FUSE_ATTR_ATOMIC for single-fsblock atomic write support
  */
 
 #ifndef _LINUX_FUSE_H
@@ -604,11 +605,13 @@ struct fuse_file_lock {
  * FUSE_ATTR_EXCLUSIVE: This file can only be modified by this mount, so the
  * kernel can use cached attributes more aggressively (e.g. ACL inheritance)
  * FUSE_ATTR_IOMAP: Use iomap for this inode
+ * FUSE_ATTR_ATOMIC: Enable untorn writes
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 #define FUSE_ATTR_DAX		(1 << 1)
 #define FUSE_ATTR_EXCLUSIVE	(1 << 2)
 #define FUSE_ATTR_IOMAP		(1 << 3)
+#define FUSE_ATTR_ATOMIC	(1 << 4)
 
 /**
  * Open flags
@@ -1176,6 +1179,8 @@ struct fuse_backing_map {
 
 /* basic file I/O functionality through iomap */
 #define FUSE_IOMAP_SUPPORT_FILEIO	(1ULL << 0)
+/* untorn writes through iomap */
+#define FUSE_IOMAP_SUPPORT_ATOMIC	(1ULL << 1)
 struct fuse_iomap_support {
 	uint64_t	flags;
 	uint64_t	padding;
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 6230819d0962a2..84bc8bbd2eeb85 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -1109,6 +1109,20 @@ static inline void fuse_inode_clear_iomap(struct inode *inode)
 	clear_bit(FUSE_I_IOMAP, &fi->state);
 }
 
+static inline void fuse_inode_set_atomic(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+
+	set_bit(FUSE_I_ATOMIC, &fi->state);
+}
+
+static inline void fuse_inode_clear_atomic(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+
+	clear_bit(FUSE_I_ATOMIC, &fi->state);
+}
+
 void fuse_iomap_init_inode(struct inode *inode, struct fuse_attr *attr)
 {
 	ASSERT(get_fuse_conn(inode)->iomap);
@@ -1135,6 +1149,8 @@ void fuse_iomap_init_inode(struct inode *inode, struct fuse_attr *attr)
 	}
 
 	fuse_inode_set_iomap(inode);
+	if (attr->flags & FUSE_ATTR_ATOMIC)
+		fuse_inode_set_atomic(inode);
 
 	trace_fuse_iomap_init_inode(inode);
 }
@@ -1145,6 +1161,7 @@ void fuse_iomap_evict_inode(struct inode *inode)
 
 	trace_fuse_iomap_evict_inode(inode);
 
+	fuse_inode_clear_atomic(inode);
 	fuse_inode_clear_iomap(inode);
 }
 
@@ -1222,6 +1239,8 @@ void fuse_iomap_open(struct inode *inode, struct file *file)
 	ASSERT(fuse_inode_has_iomap(inode));
 
 	file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT;
+	if (fuse_inode_has_atomic(inode))
+		file->f_mode |= FMODE_CAN_ATOMIC_WRITE;
 }
 
 int fuse_iomap_finish_open(const struct fuse_file *ff,
@@ -1433,6 +1452,17 @@ fuse_iomap_write_checks(
 	return kiocb_modified(iocb);
 }
 
+static inline ssize_t fuse_iomap_atomic_write_valid(struct kiocb *iocb,
+						    struct iov_iter *from)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+
+	if (iov_iter_count(from) != i_blocksize(inode))
+		return -EINVAL;
+
+	return generic_atomic_write_valid(iocb, from);
+}
+
 static ssize_t fuse_iomap_direct_write(struct kiocb *iocb,
 				       struct iov_iter *from)
 {
@@ -1447,6 +1477,12 @@ static ssize_t fuse_iomap_direct_write(struct kiocb *iocb,
 	if (!count)
 		return 0;
 
+	if (iocb->ki_flags & IOCB_ATOMIC) {
+		ret = fuse_iomap_atomic_write_valid(iocb, from);
+		if (ret)
+			return ret;
+	}
+
 	/*
 	 * Unaligned direct writes require zeroing of unwritten head and tail
 	 * blocks.  Extending writes require zeroing of post-EOF tail blocks.
@@ -1873,6 +1909,12 @@ static ssize_t fuse_iomap_buffered_write(struct kiocb *iocb,
 	if (!iov_iter_count(from))
 		return 0;
 
+	if (iocb->ki_flags & IOCB_ATOMIC) {
+		ret = fuse_iomap_atomic_write_valid(iocb, from);
+		if (ret)
+			return ret;
+	}
+
 	ret = fuse_iomap_ilock_iocb(iocb, EXCL);
 	if (ret)
 		return ret;
@@ -2169,7 +2211,8 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
 	struct fuse_iomap_support ios = { };
 
 	if (fuse_iomap_enabled())
-		ios.flags = FUSE_IOMAP_SUPPORT_FILEIO;
+		ios.flags = FUSE_IOMAP_SUPPORT_FILEIO |
+			    FUSE_IOMAP_SUPPORT_ATOMIC;
 
 	if (copy_to_user(argp, &ios, sizeof(ios)))
 		return -EFAULT;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 30/33] fuse_trace: support atomic writes with iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (28 preceding siblings ...)
  2026-02-23 23:16   ` [PATCH 29/33] fuse: support atomic writes with iomap Darrick J. Wong
@ 2026-02-23 23:16   ` Darrick J. Wong
  2026-02-23 23:16   ` [PATCH 31/33] fuse: disable direct fs reclaim for any fuse server that uses iomap Darrick J. Wong
                     ` (2 subsequent siblings)
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:16 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index d3352e75fa6bdf..de7d483d4b0f34 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -330,6 +330,7 @@ TRACE_DEFINE_ENUM(FUSE_I_BTIME);
 TRACE_DEFINE_ENUM(FUSE_I_CACHE_IO_MODE);
 TRACE_DEFINE_ENUM(FUSE_I_EXCLUSIVE);
 TRACE_DEFINE_ENUM(FUSE_I_IOMAP);
+TRACE_DEFINE_ENUM(FUSE_I_ATOMIC);
 
 #define FUSE_IFLAG_STRINGS \
 	{ 1 << FUSE_I_ADVISE_RDPLUS,		"advise_rdplus" }, \
@@ -339,7 +340,8 @@ TRACE_DEFINE_ENUM(FUSE_I_IOMAP);
 	{ 1 << FUSE_I_BTIME,			"btime" }, \
 	{ 1 << FUSE_I_CACHE_IO_MODE,		"cacheio" }, \
 	{ 1 << FUSE_I_EXCLUSIVE,		"excl" }, \
-	{ 1 << FUSE_I_IOMAP,			"iomap" }
+	{ 1 << FUSE_I_IOMAP,			"iomap" }, \
+	{ 1 << FUSE_I_ATOMIC,			"atomic" }
 
 #define IOMAP_IOEND_STRINGS \
 	{ IOMAP_IOEND_SHARED,			"shared" }, \


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 31/33] fuse: disable direct fs reclaim for any fuse server that uses iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (29 preceding siblings ...)
  2026-02-23 23:16   ` [PATCH 30/33] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:16   ` Darrick J. Wong
  2026-02-23 23:17   ` [PATCH 32/33] fuse: enable swapfile activation on iomap Darrick J. Wong
  2026-02-23 23:17   ` [PATCH 33/33] fuse: implement freeze and shutdowns for iomap filesystems Darrick J. Wong
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:16 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Any fuse server that uses iomap can create a substantial amount of dirty
pages in the pagecache because we don't write dirty stuff until reclaim
or fsync.  Therefore, memory reclaim on any fuse iomap server musn't
ever recurse back into the same filesystem.  We must also never throttle
the fuse server writes to a bdi because that will just slow down
metadata operations.

Add a new ioctl that the fuse server can call on the fuse device to set
PF_MEMALLOC_NOFS and PF_LOCAL_THROTTLE.  Either the fuse connection must
have already enabled iomap, or the caller must have CAP_SYS_RESOURCE.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.h      |    2 ++
 include/uapi/linux/fuse.h |    1 +
 fs/fuse/dev.c             |    2 ++
 fs/fuse/fuse_iomap.c      |   37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 42 insertions(+)


diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 1d9d39383ca9b2..bf6640c36465e1 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -75,6 +75,7 @@ int fuse_iomap_dev_inval(struct fuse_conn *fc,
 			 const struct fuse_iomap_dev_inval_out *arg);
 
 int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
+int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -102,6 +103,7 @@ int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
 # define fuse_iomap_dev_inval(...)		(-ENOSYS)
 # define fuse_iomap_fadvise			NULL
+# define fuse_dev_ioctl_iomap_set_nofs(...)	(-EOPNOTSUPP)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index c454cea83083d3..9e59fba64f48d9 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1195,6 +1195,7 @@ struct fuse_iomap_support {
 #define FUSE_DEV_IOC_SYNC_INIT		_IO(FUSE_DEV_IOC_MAGIC, 3)
 #define FUSE_DEV_IOC_IOMAP_SUPPORT	_IOR(FUSE_DEV_IOC_MAGIC, 99, \
 					     struct fuse_iomap_support)
+#define FUSE_DEV_IOC_SET_NOFS		_IOW(FUSE_DEV_IOC_MAGIC, 100, uint32_t)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 9a814a0d222fe6..896706c911cf24 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2742,6 +2742,8 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
 
 	case FUSE_DEV_IOC_IOMAP_SUPPORT:
 		return fuse_dev_ioctl_iomap_support(file, argp);
+	case FUSE_DEV_IOC_SET_NOFS:
+		return fuse_dev_ioctl_iomap_set_nofs(file, argp);
 
 	default:
 		return -ENOTTY;
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 84bc8bbd2eeb85..561b0105e6dadc 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -12,6 +12,7 @@
 #include "fuse_trace.h"
 #include "fuse_iomap.h"
 #include "fuse_iomap_i.h"
+#include "fuse_dev_i.h"
 
 static bool __read_mostly enable_iomap =
 #if IS_ENABLED(CONFIG_FUSE_IOMAP_BY_DEFAULT)
@@ -2280,3 +2281,39 @@ int fuse_iomap_dev_inval(struct fuse_conn *fc,
 	up_read(&fc->killsb);
 	return ret;
 }
+
+static inline bool can_set_nofs(struct fuse_dev *fud)
+{
+	if (fud && fud->fc && fud->fc->iomap)
+	       return true;
+
+	return capable(CAP_SYS_RESOURCE);
+}
+
+int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp)
+{
+	struct fuse_dev *fud = fuse_get_dev(file);
+	uint32_t flags;
+
+	if (!can_set_nofs(fud))
+		return -EPERM;
+
+	if (copy_from_user(&flags, argp, sizeof(flags)))
+		return -EFAULT;
+
+	/*
+	 * The fuse server could be asked to perform a substantial amount of
+	 * writeback, so prohibit reclaim from recursing into fuse or the
+	 * kernel from throttling any bdis that the fuse server might write to.
+	 */
+	switch (flags) {
+	case 1:
+		current->flags |= PF_MEMALLOC_NOFS | PF_LOCAL_THROTTLE;
+		return 0;
+	case 0:
+		current->flags &= ~(PF_MEMALLOC_NOFS | PF_LOCAL_THROTTLE);
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 32/33] fuse: enable swapfile activation on iomap
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (30 preceding siblings ...)
  2026-02-23 23:16   ` [PATCH 31/33] fuse: disable direct fs reclaim for any fuse server that uses iomap Darrick J. Wong
@ 2026-02-23 23:17   ` Darrick J. Wong
  2026-02-23 23:17   ` [PATCH 33/33] fuse: implement freeze and shutdowns for iomap filesystems Darrick J. Wong
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:17 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

It turns out that fuse supports swapfile activation, so let's enable
that.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h      |    1 +
 include/uapi/linux/fuse.h |    5 ++++
 fs/fuse/fuse_iomap.c      |   54 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 59 insertions(+), 1 deletion(-)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index de7d483d4b0f34..63cc1496ee5ca1 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -300,6 +300,7 @@ struct iomap;
 	{ FUSE_IOMAP_OP_DAX,			"fsdax" }, \
 	{ FUSE_IOMAP_OP_ATOMIC,			"atomic" }, \
 	{ FUSE_IOMAP_OP_DONTCACHE,		"dontcache" }, \
+	{ FUSE_IOMAP_OP_SWAPFILE,		"swapfile" }, \
 	{ FUSE_IOMAP_OP_WRITEBACK,		"writeback" }
 
 #define FUSE_IOMAP_TYPE_STRINGS \
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 9e59fba64f48d9..5f3724f36f764a 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1406,6 +1406,9 @@ struct fuse_uring_cmd_req {
 #define FUSE_IOMAP_OP_ATOMIC		(1U << 9)
 #define FUSE_IOMAP_OP_DONTCACHE		(1U << 10)
 
+/* swapfile config operation */
+#define FUSE_IOMAP_OP_SWAPFILE		(1U << 30)
+
 /* pagecache writeback operation */
 #define FUSE_IOMAP_OP_WRITEBACK		(1U << 31)
 
@@ -1460,6 +1463,8 @@ struct fuse_iomap_end_in {
 #define FUSE_IOMAP_IOEND_APPEND		(1U << 4)
 /* is pagecache writeback */
 #define FUSE_IOMAP_IOEND_WRITEBACK	(1U << 5)
+/* swapfile deactivation */
+#define FUSE_IOMAP_IOEND_SWAPOFF	(1U << 6)
 
 struct fuse_iomap_ioend_in {
 	uint32_t flags;		/* FUSE_IOMAP_IOEND_* */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 561b0105e6dadc..9a3703b2d65bbd 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -8,6 +8,7 @@
 #include <linux/pagemap.h>
 #include <linux/falloc.h>
 #include <linux/fadvise.h>
+#include <linux/swap.h>
 #include "fuse_i.h"
 #include "fuse_trace.h"
 #include "fuse_iomap.h"
@@ -202,13 +203,16 @@ static inline uint16_t fuse_iomap_flags_from_server(uint16_t fuse_f_flags)
 #undef XMAP2
 #undef XMAP
 
+#define FUSE_IOMAP_PRIVATE_OPS	(FUSE_IOMAP_OP_WRITEBACK | \
+				 FUSE_IOMAP_OP_SWAPFILE)
+
 /* Convert IOMAP_* operation flags to FUSE_IOMAP_OP_* */
 #define XMAP(word) \
 	if (iomap_op_flags & IOMAP_##word) \
 		ret |= FUSE_IOMAP_OP_##word
 static inline uint32_t fuse_iomap_op_to_server(unsigned iomap_op_flags)
 {
-	uint32_t ret = iomap_op_flags & FUSE_IOMAP_OP_WRITEBACK;
+	uint32_t ret = iomap_op_flags & FUSE_IOMAP_PRIVATE_OPS;
 
 	XMAP(WRITE);
 	XMAP(ZERO);
@@ -749,6 +753,13 @@ fuse_should_send_iomap_ioend(const struct fuse_mount *fm,
 	if (inarg->error)
 		return true;
 
+	/*
+	 * Always send an ioend for swapoff to let the fuse server know the
+	 * long term layout "lease" is over.
+	 */
+	if (inarg->flags & FUSE_IOMAP_IOEND_SWAPOFF)
+		return true;
+
 	/* Send an ioend if we performed an IO involving metadata changes. */
 	return inarg->written > 0 &&
 	       (inarg->flags & (FUSE_IOMAP_IOEND_SHARED |
@@ -1792,6 +1803,43 @@ static void fuse_iomap_readahead(struct readahead_control *rac)
 	iomap_bio_readahead(rac, &fuse_iomap_ops);
 }
 
+#ifdef CONFIG_SWAP
+static int fuse_iomap_swapfile_begin(struct inode *inode, loff_t pos,
+				     loff_t count, unsigned opflags,
+				     struct iomap *iomap, struct iomap *srcmap)
+{
+	return fuse_iomap_begin(inode, pos, count,
+				FUSE_IOMAP_OP_SWAPFILE | opflags, iomap,
+				srcmap);
+}
+
+static const struct iomap_ops fuse_iomap_swapfile_ops = {
+	.iomap_begin		= fuse_iomap_swapfile_begin,
+};
+
+static int fuse_iomap_swap_activate(struct swap_info_struct *sis,
+				    struct file *swap_file, sector_t *span)
+{
+	int ret;
+
+	/* obtain the block device from the header iomapping */
+	sis->bdev = NULL;
+	ret = iomap_swapfile_activate(sis, swap_file, span,
+				      &fuse_iomap_swapfile_ops);
+	if (ret < 0)
+		fuse_iomap_ioend(file_inode(swap_file), 0, 0, ret,
+				 FUSE_IOMAP_IOEND_SWAPOFF, NULL,
+				 FUSE_IOMAP_NULL_ADDR);
+	return ret;
+}
+
+static void fuse_iomap_swap_deactivate(struct file *file)
+{
+	fuse_iomap_ioend(file_inode(file), 0, 0, 0, FUSE_IOMAP_IOEND_SWAPOFF,
+			 NULL, FUSE_IOMAP_NULL_ADDR);
+}
+#endif
+
 static const struct address_space_operations fuse_iomap_aops = {
 	.read_folio		= fuse_iomap_read_folio,
 	.readahead		= fuse_iomap_readahead,
@@ -1802,6 +1850,10 @@ static const struct address_space_operations fuse_iomap_aops = {
 	.migrate_folio		= filemap_migrate_folio,
 	.is_partially_uptodate  = iomap_is_partially_uptodate,
 	.error_remove_folio	= generic_error_remove_folio,
+#ifdef CONFIG_SWAP
+	.swap_activate		= fuse_iomap_swap_activate,
+	.swap_deactivate	= fuse_iomap_swap_deactivate,
+#endif
 
 	/* These aren't pagecache operations per se */
 	.bmap			= fuse_bmap,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 33/33] fuse: implement freeze and shutdowns for iomap filesystems
  2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (31 preceding siblings ...)
  2026-02-23 23:17   ` [PATCH 32/33] fuse: enable swapfile activation on iomap Darrick J. Wong
@ 2026-02-23 23:17   ` Darrick J. Wong
  32 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:17 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Implement filesystem freezing and block device shutdown notifications
for iomap-based servers

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/uapi/linux/fuse.h |   12 +++++++
 fs/fuse/inode.c           |   73 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)


diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 5f3724f36f764a..b6fa828776b82f 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -695,6 +695,10 @@ enum fuse_opcode {
 	FUSE_STATX		= 52,
 	FUSE_COPY_FILE_RANGE_64	= 53,
 
+	FUSE_FREEZE_FS		= 4089,
+	FUSE_UNFREEZE_FS	= 4090,
+	FUSE_SHUTDOWN_FS	= 4091,
+
 	FUSE_IOMAP_CONFIG	= 4092,
 	FUSE_IOMAP_IOEND	= 4093,
 	FUSE_IOMAP_BEGIN	= 4094,
@@ -1257,6 +1261,14 @@ struct fuse_syncfs_in {
 	uint64_t	padding;
 };
 
+struct fuse_freezefs_in {
+	uint64_t	unlinked;
+};
+
+struct fuse_shutdownfs_in {
+	uint64_t	flags;
+};
+
 /*
  * For each security context, send fuse_secctx with size of security context
  * fuse_secctx will be followed by security context name and this in turn
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 4d805c7f484517..f3afa63bfe7f61 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1235,6 +1235,74 @@ static struct dentry *fuse_get_parent(struct dentry *child)
 	return parent;
 }
 
+#ifdef CONFIG_FUSE_IOMAP
+/*
+ * Second stage of a freeze. The data is already frozen so we only
+ * need to take care of the fuse server.
+ */
+static int fuse_freeze_fs(struct super_block *sb)
+{
+	struct fuse_mount *fm = get_fuse_mount_super(sb);
+	struct fuse_conn *fc = get_fuse_conn_super(sb);
+	struct fuse_freezefs_in inarg = {
+		.unlinked = atomic_long_read(&sb->s_remove_count),
+	};
+	FUSE_ARGS(args);
+	int err;
+
+	if (!fc->iomap)
+		return -EOPNOTSUPP;
+
+	args.opcode = FUSE_FREEZE_FS;
+	args.nodeid = get_node_id(sb->s_root->d_inode);
+	args.in_numargs = 1;
+	args.in_args[0].size = sizeof(inarg);
+	args.in_args[0].value = &inarg;
+	err = fuse_simple_request(fm, &args);
+	if (err == -ENOSYS)
+		err = -EOPNOTSUPP;
+	return err;
+}
+
+static int fuse_unfreeze_fs(struct super_block *sb)
+{
+	struct fuse_mount *fm = get_fuse_mount_super(sb);
+	struct fuse_conn *fc = get_fuse_conn_super(sb);
+	FUSE_ARGS(args);
+	int err;
+
+	if (!fc->iomap)
+		return 0;
+
+	args.opcode = FUSE_UNFREEZE_FS;
+	args.nodeid = get_node_id(sb->s_root->d_inode);
+	err = fuse_simple_request(fm, &args);
+	if (err == -ENOSYS)
+		err = 0;
+	return err;
+}
+
+static void fuse_shutdown_fs(struct super_block *sb)
+{
+	struct fuse_mount *fm = get_fuse_mount_super(sb);
+	struct fuse_conn *fc = get_fuse_conn_super(sb);
+	struct fuse_shutdownfs_in inarg = {
+		.flags = 0,
+	};
+	FUSE_ARGS(args);
+
+	if (!fc->iomap)
+		return;
+
+	args.opcode = FUSE_SHUTDOWN_FS;
+	args.nodeid = get_node_id(sb->s_root->d_inode);
+	args.in_numargs = 1;
+	args.in_args[0].size = sizeof(inarg);
+	args.in_args[0].value = &inarg;
+	fuse_simple_request(fm, &args);
+}
+#endif /* CONFIG_FUSE_IOMAP */
+
 /* only for fid encoding; no support for file handle */
 static const struct export_operations fuse_export_fid_operations = {
 	.encode_fh	= fuse_encode_fh,
@@ -1257,6 +1325,11 @@ static const struct super_operations fuse_super_operations = {
 	.statfs		= fuse_statfs,
 	.sync_fs	= fuse_sync_fs,
 	.show_options	= fuse_show_options,
+#ifdef CONFIG_FUSE_IOMAP
+	.freeze_fs	= fuse_freeze_fs,
+	.unfreeze_fs	= fuse_unfreeze_fs,
+	.shutdown	= fuse_shutdown_fs,
+#endif
 };
 
 static void sanitize_global_limit(unsigned int *limit)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/3] fuse: make the root nodeid dynamic
  2026-02-23 23:01 ` [PATCHSET v7 5/9] fuse: allow servers to specify root node id Darrick J. Wong
@ 2026-02-23 23:17   ` Darrick J. Wong
  2026-02-23 23:17   ` [PATCH 2/3] fuse_trace: " Darrick J. Wong
  2026-02-23 23:18   ` [PATCH 3/3] fuse: allow setting of root nodeid Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:17 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Change this from a hardcoded constant to a dynamic field so that fuse
servers don't need to translate.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h  |    7 +++++--
 fs/fuse/dir.c     |   10 ++++++----
 fs/fuse/inode.c   |   11 +++++++----
 fs/fuse/readdir.c |   10 +++++-----
 4 files changed, 23 insertions(+), 15 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index f96c69c755bd9b..fc0e352e2e8f9b 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -702,6 +702,9 @@ struct fuse_conn {
 
 	struct rcu_head rcu;
 
+	/* node id of the root directory */
+	u64 root_nodeid;
+
 	/** The user id for this mount */
 	kuid_t user_id;
 
@@ -1117,9 +1120,9 @@ static inline u64 get_node_id(struct inode *inode)
 	return get_fuse_inode(inode)->nodeid;
 }
 
-static inline int invalid_nodeid(u64 nodeid)
+static inline int invalid_nodeid(const struct fuse_conn *fc, u64 nodeid)
 {
-	return !nodeid || nodeid == FUSE_ROOT_ID;
+	return !nodeid || nodeid == fc->root_nodeid;
 }
 
 static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 0492619e397f56..ff678f26e9cd79 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -580,7 +580,7 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name
 	err = -EIO;
 	if (fuse_invalid_attr(&outarg->attr))
 		goto out_put_forget;
-	if (outarg->nodeid == FUSE_ROOT_ID && outarg->generation != 0) {
+	if (outarg->nodeid == fm->fc->root_nodeid && outarg->generation != 0) {
 		pr_warn_once("root generation should be zero\n");
 		outarg->generation = 0;
 	}
@@ -630,7 +630,7 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
 		goto out_err;
 
 	err = -EIO;
-	if (inode && get_node_id(inode) == FUSE_ROOT_ID)
+	if (inode && get_node_id(inode) == fc->root_nodeid)
 		goto out_iput;
 
 	newent = d_splice_alias(inode, entry);
@@ -881,7 +881,8 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
 		goto out_free_ff;
 
 	err = -EIO;
-	if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid) ||
+	if (!S_ISREG(outentry.attr.mode) ||
+	    invalid_nodeid(fm->fc, outentry.nodeid) ||
 	    fuse_invalid_attr(&outentry.attr))
 		goto out_free_ff;
 
@@ -1028,7 +1029,8 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun
 		goto out_put_forget_req;
 
 	err = -EIO;
-	if (invalid_nodeid(outarg.nodeid) || fuse_invalid_attr(&outarg.attr))
+	if (invalid_nodeid(fm->fc, outarg.nodeid) ||
+	    fuse_invalid_attr(&outarg.attr))
 		goto out_put_forget_req;
 
 	if ((outarg.attr.mode ^ mode) & S_IFMT)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index f3afa63bfe7f61..2a679bce3b178c 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1030,6 +1030,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
 	fc->max_pages_limit = fuse_max_pages_limit;
 	fc->name_max = FUSE_NAME_LOW_MAX;
 	fc->timeout.req_timeout = 0;
+	fc->root_nodeid = FUSE_ROOT_ID;
 
 	if (IS_ENABLED(CONFIG_FUSE_BACKING))
 		fuse_backing_files_init(fc);
@@ -1087,12 +1088,14 @@ EXPORT_SYMBOL_GPL(fuse_conn_get);
 static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned int mode)
 {
 	struct fuse_attr attr;
+	struct fuse_conn *fc = get_fuse_conn_super(sb);
+
 	memset(&attr, 0, sizeof(attr));
 
 	attr.mode = mode;
-	attr.ino = FUSE_ROOT_ID;
+	attr.ino = fc->root_nodeid;
 	attr.nlink = 1;
-	return fuse_iget(sb, FUSE_ROOT_ID, 0, &attr, 0, 0, 0);
+	return fuse_iget(sb, fc->root_nodeid, 0, &attr, 0, 0, 0);
 }
 
 struct fuse_inode_handle {
@@ -1136,7 +1139,7 @@ static struct dentry *fuse_get_dentry(struct super_block *sb,
 		goto out_iput;
 
 	entry = d_obtain_alias(inode);
-	if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID)
+	if (!IS_ERR(entry) && get_node_id(inode) != fc->root_nodeid)
 		fuse_invalidate_entry_cache(entry);
 
 	return entry;
@@ -1229,7 +1232,7 @@ static struct dentry *fuse_get_parent(struct dentry *child)
 	}
 
 	parent = d_obtain_alias(inode);
-	if (!IS_ERR(parent) && get_node_id(inode) != FUSE_ROOT_ID)
+	if (!IS_ERR(parent) && get_node_id(inode) != fc->root_nodeid)
 		fuse_invalidate_entry_cache(parent);
 
 	return parent;
diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c
index c2aae2eef0868b..45dd932eb03a5e 100644
--- a/fs/fuse/readdir.c
+++ b/fs/fuse/readdir.c
@@ -185,12 +185,12 @@ static int fuse_direntplus_link(struct file *file,
 			return 0;
 	}
 
-	if (invalid_nodeid(o->nodeid))
-		return -EIO;
-	if (fuse_invalid_attr(&o->attr))
-		return -EIO;
-
 	fc = get_fuse_conn(dir);
+	if (invalid_nodeid(fc, o->nodeid))
+		return -EIO;
+	if (fuse_invalid_attr(&o->attr))
+		return -EIO;
+
 	epoch = atomic_read(&fc->epoch);
 
 	name.hash = full_name_hash(parent, name.name, name.len);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/3] fuse_trace: make the root nodeid dynamic
  2026-02-23 23:01 ` [PATCHSET v7 5/9] fuse: allow servers to specify root node id Darrick J. Wong
  2026-02-23 23:17   ` [PATCH 1/3] fuse: make the root nodeid dynamic Darrick J. Wong
@ 2026-02-23 23:17   ` Darrick J. Wong
  2026-02-23 23:18   ` [PATCH 3/3] fuse: allow setting of root nodeid Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:17 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Enhance the iomap config tracepoint to report the node id of the root
directory.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 63cc1496ee5ca1..0016242ff34f62 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -1026,6 +1026,7 @@ TRACE_EVENT(fuse_iomap_config,
 
 	TP_STRUCT__entry(
 		__field(dev_t,			connection)
+		__field(uint64_t,		root_nodeid)
 
 		__field(uint64_t,		flags)
 		__field(uint32_t,		blocksize)
@@ -1040,6 +1041,7 @@ TRACE_EVENT(fuse_iomap_config,
 
 	TP_fast_assign(
 		__entry->connection	=	fm->fc->dev;
+		__entry->root_nodeid	=	fm->fc->root_nodeid;
 		__entry->flags		=	outarg->flags;
 		__entry->blocksize	=	outarg->s_blocksize;
 		__entry->max_links	=	outarg->s_max_links;
@@ -1050,8 +1052,8 @@ TRACE_EVENT(fuse_iomap_config,
 		__entry->uuid_len	=	outarg->s_uuid_len;
 	),
 
-	TP_printk("connection %u flags (%s) blocksize 0x%x max_links %u time_gran %u time_min %lld time_max %lld maxbytes 0x%llx uuid_len %u",
-		  __entry->connection,
+	TP_printk("connection %u root_ino 0x%llx flags (%s) blocksize 0x%x max_links %u time_gran %u time_min %lld time_max %lld maxbytes 0x%llx uuid_len %u",
+		  __entry->connection, __entry->root_nodeid,
 		  __print_flags(__entry->flags, "|", FUSE_IOMAP_CONFIG_STRINGS),
 		  __entry->blocksize, __entry->max_links, __entry->time_gran,
 		  __entry->time_min, __entry->time_max, __entry->maxbytes,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/3] fuse: allow setting of root nodeid
  2026-02-23 23:01 ` [PATCHSET v7 5/9] fuse: allow servers to specify root node id Darrick J. Wong
  2026-02-23 23:17   ` [PATCH 1/3] fuse: make the root nodeid dynamic Darrick J. Wong
  2026-02-23 23:17   ` [PATCH 2/3] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:18   ` Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:18 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Provide a new mount option so that fuse servers can actually set the
root nodeid.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h |    2 ++
 fs/fuse/inode.c  |   11 +++++++++++
 2 files changed, 13 insertions(+)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index fc0e352e2e8f9b..884f29533d0206 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -636,6 +636,7 @@ struct fuse_fs_context {
 	int fd;
 	struct file *file;
 	unsigned int rootmode;
+	u64 root_nodeid;
 	kuid_t user_id;
 	kgid_t group_id;
 	bool is_bdev:1;
@@ -649,6 +650,7 @@ struct fuse_fs_context {
 	bool no_control:1;
 	bool no_force_umount:1;
 	bool legacy_opts_show:1;
+	bool root_nodeid_present:1;
 	enum fuse_dax_mode dax_mode;
 	unsigned int max_read;
 	unsigned int blksize;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 2a679bce3b178c..9185b3b922559a 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -813,6 +813,7 @@ enum {
 	OPT_ALLOW_OTHER,
 	OPT_MAX_READ,
 	OPT_BLKSIZE,
+	OPT_ROOT_NODEID,
 	OPT_ERR
 };
 
@@ -827,6 +828,7 @@ static const struct fs_parameter_spec fuse_fs_parameters[] = {
 	fsparam_u32	("max_read",		OPT_MAX_READ),
 	fsparam_u32	("blksize",		OPT_BLKSIZE),
 	fsparam_string	("subtype",		OPT_SUBTYPE),
+	fsparam_u64	("root_nodeid",		OPT_ROOT_NODEID),
 	{}
 };
 
@@ -922,6 +924,11 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)
 		ctx->blksize = result.uint_32;
 		break;
 
+	case OPT_ROOT_NODEID:
+		ctx->root_nodeid = result.uint_64;
+		ctx->root_nodeid_present = true;
+		break;
+
 	default:
 		return -EINVAL;
 	}
@@ -957,6 +964,8 @@ static int fuse_show_options(struct seq_file *m, struct dentry *root)
 			seq_printf(m, ",max_read=%u", fc->max_read);
 		if (sb->s_bdev && sb->s_blocksize != FUSE_DEFAULT_BLKSIZE)
 			seq_printf(m, ",blksize=%lu", sb->s_blocksize);
+		if (fc->root_nodeid && fc->root_nodeid != FUSE_ROOT_ID)
+			seq_printf(m, ",root_nodeid=%llu", fc->root_nodeid);
 	}
 #ifdef CONFIG_FUSE_DAX
 	if (fc->dax_mode == FUSE_DAX_ALWAYS)
@@ -2005,6 +2014,8 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
 	sb->s_flags |= SB_POSIXACL;
 
 	fc->default_permissions = ctx->default_permissions;
+	if (ctx->root_nodeid_present)
+		fc->root_nodeid = ctx->root_nodeid;
 	fc->allow_other = ctx->allow_other;
 	fc->user_id = ctx->user_id;
 	fc->group_id = ctx->group_id;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/9] fuse: enable caching of timestamps
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
@ 2026-02-23 23:18   ` Darrick J. Wong
  2026-02-23 23:18   ` [PATCH 2/9] fuse: force a ctime update after a fileattr_set call when in iomap mode Darrick J. Wong
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:18 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Cache the timestamps in the kernel so that the kernel sends FUSE_SETATTR
calls to the fuse server after writes, because the iomap infrastructure
won't do that for us.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/dir.c        |    5 ++++-
 fs/fuse/file.c       |   18 ++++++++++++------
 fs/fuse/fuse_iomap.c |    6 ++++++
 fs/fuse/inode.c      |   13 +++++++------
 4 files changed, 29 insertions(+), 13 deletions(-)


diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index ff678f26e9cd79..5ae6c5639f6d2c 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -2261,7 +2261,8 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	struct fuse_attr_out outarg;
 	const bool is_iomap = fuse_inode_has_iomap(inode);
 	bool is_truncate = false;
-	bool is_wb = fc->writeback_cache && S_ISREG(inode->i_mode);
+	bool is_wb = (is_iomap || fc->writeback_cache) &&
+		     S_ISREG(inode->i_mode);
 	loff_t oldsize;
 	int err;
 	bool trust_local_cmtime = is_wb;
@@ -2401,6 +2402,8 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	spin_lock(&fi->lock);
 	/* the kernel maintains i_mtime locally */
 	if (trust_local_cmtime) {
+		if ((attr->ia_valid & ATTR_ATIME) && is_iomap)
+			inode_set_atime_to_ts(inode, attr->ia_atime);
 		if (attr->ia_valid & ATTR_MTIME)
 			inode_set_mtime_to_ts(inode, attr->ia_mtime);
 		if (attr->ia_valid & ATTR_CTIME)
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 1243d0eea22a37..0b21fcdefffeb7 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -256,7 +256,7 @@ static int fuse_open(struct inode *inode, struct file *file)
 	int err;
 	const bool is_iomap = fuse_inode_has_iomap(inode);
 	bool is_truncate = (file->f_flags & O_TRUNC) && fc->atomic_o_trunc;
-	bool is_wb_truncate = is_truncate && fc->writeback_cache;
+	bool is_wb_truncate = is_truncate && (is_iomap || fc->writeback_cache);
 	bool dax_truncate = is_truncate && FUSE_IS_DAX(inode);
 
 	if (fuse_is_bad(inode))
@@ -471,12 +471,14 @@ static int fuse_flush(struct file *file, fl_owner_t id)
 	struct fuse_file *ff = file->private_data;
 	struct fuse_flush_in inarg;
 	FUSE_ARGS(args);
+	const bool is_iomap = fuse_inode_has_iomap(inode);
 	int err;
 
 	if (fuse_is_bad(inode))
 		return -EIO;
 
-	if (ff->open_flags & FOPEN_NOFLUSH && !fm->fc->writeback_cache)
+	if ((ff->open_flags & FOPEN_NOFLUSH) &&
+	    !fm->fc->writeback_cache && !is_iomap)
 		return 0;
 
 	err = write_inode_now(inode, 1);
@@ -512,7 +514,7 @@ static int fuse_flush(struct file *file, fl_owner_t id)
 	 * In memory i_blocks is not maintained by fuse, if writeback cache is
 	 * enabled, i_blocks from cached attr may not be accurate.
 	 */
-	if (!err && fm->fc->writeback_cache)
+	if (!err && (is_iomap || fm->fc->writeback_cache))
 		fuse_invalidate_attr_mask(inode, STATX_BLOCKS);
 	return err;
 }
@@ -814,8 +816,10 @@ static void fuse_short_read(struct inode *inode, u64 attr_ver, size_t num_read,
 	 * If writeback_cache is enabled, a short read means there's a hole in
 	 * the file.  Some data after the hole is in page cache, but has not
 	 * reached the client fs yet.  So the hole is not present there.
+	 * If iomap is enabled, a short read means we hit EOF so there's
+	 * nothing to adjust.
 	 */
-	if (!fc->writeback_cache) {
+	if (!fc->writeback_cache && !fuse_inode_has_iomap(inode)) {
 		loff_t pos = folio_pos(ap->folios[0]) + num_read;
 		fuse_read_update_size(inode, pos, attr_ver);
 	}
@@ -864,6 +868,8 @@ static int fuse_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 			    unsigned int flags, struct iomap *iomap,
 			    struct iomap *srcmap)
 {
+	WARN_ON(fuse_inode_has_iomap(inode));
+
 	iomap->type = IOMAP_MAPPED;
 	iomap->length = length;
 	iomap->offset = offset;
@@ -2016,7 +2022,7 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args,
 	 * Do this only if writeback_cache is not enabled.  If writeback_cache
 	 * is enabled, we trust local ctime/mtime.
 	 */
-	if (!fc->writeback_cache)
+	if (!fc->writeback_cache && !fuse_inode_has_iomap(inode))
 		fuse_invalidate_attr_mask(inode, FUSE_STATX_MODIFY);
 	spin_lock(&fi->lock);
 	fi->writectr--;
@@ -3109,7 +3115,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
 	/* mark unstable when write-back is not used, and file_out gets
 	 * extended */
 	const bool is_iomap = fuse_inode_has_iomap(inode_out);
-	bool is_unstable = (!fc->writeback_cache) &&
+	bool is_unstable = (!fc->writeback_cache && !is_iomap) &&
 			   ((pos_out + len) > inode_out->i_size);
 
 	if (fc->no_copy_file_range)
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 9a3703b2d65bbd..65c8e06fdd653a 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -1864,6 +1864,12 @@ static inline void fuse_inode_set_iomap(struct inode *inode)
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	unsigned int min_order = 0;
 
+	/*
+	 * Manage timestamps ourselves, don't make the fuse server do it.  This
+	 * is critical for mtime updates to work correctly with page_mkwrite.
+	 */
+	inode->i_flags &= ~S_NOCMTIME;
+	inode->i_flags &= ~S_NOATIME;
 	inode->i_data.a_ops = &fuse_iomap_aops;
 
 	INIT_WORK(&fi->ioend_work, fuse_iomap_end_io);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 9185b3b922559a..94355977904068 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -331,10 +331,11 @@ u32 fuse_get_cache_mask(struct inode *inode)
 {
 	struct fuse_conn *fc = get_fuse_conn(inode);
 
-	if (!fc->writeback_cache || !S_ISREG(inode->i_mode))
-		return 0;
+	if (S_ISREG(inode->i_mode) &&
+	    (fuse_inode_has_iomap(inode) || fc->writeback_cache))
+		return STATX_MTIME | STATX_CTIME | STATX_SIZE;
 
-	return STATX_MTIME | STATX_CTIME | STATX_SIZE;
+	return 0;
 }
 
 static void fuse_change_attributes_i(struct inode *inode, struct fuse_attr *attr,
@@ -349,9 +350,9 @@ static void fuse_change_attributes_i(struct inode *inode, struct fuse_attr *attr
 
 	spin_lock(&fi->lock);
 	/*
-	 * In case of writeback_cache enabled, writes update mtime, ctime and
-	 * may update i_size.  In these cases trust the cached value in the
-	 * inode.
+	 * In case of writeback_cache or iomap enabled, writes update mtime,
+	 * ctime and may update i_size.  In these cases trust the cached value
+	 * in the inode.
 	 */
 	cache_mask = fuse_get_cache_mask(inode);
 	fuse_iomap_set_disk_size(fi, attr->size);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/9] fuse: force a ctime update after a fileattr_set call when in iomap mode
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
  2026-02-23 23:18   ` [PATCH 1/9] fuse: enable caching of timestamps Darrick J. Wong
@ 2026-02-23 23:18   ` Darrick J. Wong
  2026-02-23 23:18   ` [PATCH 3/9] fuse: allow local filesystems to set some VFS iflags Darrick J. Wong
                     ` (6 subsequent siblings)
  8 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:18 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

In iomap mode, the kernel is in charge of driving ctime updates to
the fuse server and ignores updates coming from the fuse server.
Therefore, when someone calls fileattr_set to change file attributes, we
must force a ctime update.

Found by generic/277.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/ioctl.c |   11 +++++++++++
 1 file changed, 11 insertions(+)


diff --git a/fs/fuse/ioctl.c b/fs/fuse/ioctl.c
index fdc175e93f7474..07529db21fb781 100644
--- a/fs/fuse/ioctl.c
+++ b/fs/fuse/ioctl.c
@@ -546,8 +546,13 @@ int fuse_fileattr_set(struct mnt_idmap *idmap,
 	struct fuse_file *ff;
 	unsigned int flags = fa->flags;
 	struct fsxattr xfa;
+	struct file_kattr old_ma = { };
+	bool is_wb = (fuse_get_cache_mask(inode) & STATX_CTIME);
 	int err;
 
+	if (is_wb)
+		vfs_fileattr_get(dentry, &old_ma);
+
 	ff = fuse_priv_ioctl_prepare(inode);
 	if (IS_ERR(ff))
 		return PTR_ERR(ff);
@@ -571,6 +576,12 @@ int fuse_fileattr_set(struct mnt_idmap *idmap,
 
 cleanup:
 	fuse_priv_ioctl_cleanup(inode, ff);
+	/*
+	 * If we cache ctime updates and the fileattr changed, then force a
+	 * ctime update.
+	 */
+	if (is_wb && memcmp(&old_ma, fa, sizeof(old_ma)))
+		fuse_update_ctime(inode);
 
 	return err;
 }


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/9] fuse: allow local filesystems to set some VFS iflags
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
  2026-02-23 23:18   ` [PATCH 1/9] fuse: enable caching of timestamps Darrick J. Wong
  2026-02-23 23:18   ` [PATCH 2/9] fuse: force a ctime update after a fileattr_set call when in iomap mode Darrick J. Wong
@ 2026-02-23 23:18   ` Darrick J. Wong
  2026-02-23 23:19   ` [PATCH 4/9] fuse_trace: " Darrick J. Wong
                     ` (5 subsequent siblings)
  8 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:18 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

There are three inode flags (immutable, append, sync) that are enforced
by the VFS.  Whenever we go around setting iflags, let's update the VFS
state so that they actually work.  Make it so that the fuse server can
set these three inode flags at load time and have the kernel advertise
and enforce them.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h          |    1 +
 include/uapi/linux/fuse.h |    8 +++++++
 fs/fuse/dir.c             |    1 +
 fs/fuse/inode.c           |    1 +
 fs/fuse/ioctl.c           |   50 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 61 insertions(+)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 884f29533d0206..b4da866187ba2c 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1654,6 +1654,7 @@ long fuse_file_compat_ioctl(struct file *file, unsigned int cmd,
 int fuse_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
 int fuse_fileattr_set(struct mnt_idmap *idmap,
 		      struct dentry *dentry, struct file_kattr *fa);
+void fuse_fileattr_init(struct inode *inode, const struct fuse_attr *attr);
 
 /* iomode.c */
 int fuse_file_cached_io_open(struct inode *inode, struct fuse_file *ff);
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index b6fa828776b82f..bf8514a5ee27af 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -249,6 +249,8 @@
  *  - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry
  *  - add FUSE_NOTIFY_IOMAP_DEV_INVAL to invalidate iomap bdev ranges
  *  - add FUSE_ATTR_ATOMIC for single-fsblock atomic write support
+ *  - add FUSE_ATTR_{SYNC,IMMUTABLE,APPEND} for VFS enforcement of file
+ *    attributes
  */
 
 #ifndef _LINUX_FUSE_H
@@ -606,12 +608,18 @@ struct fuse_file_lock {
  * kernel can use cached attributes more aggressively (e.g. ACL inheritance)
  * FUSE_ATTR_IOMAP: Use iomap for this inode
  * FUSE_ATTR_ATOMIC: Enable untorn writes
+ * FUSE_ATTR_SYNC: File writes are synchronous
+ * FUSE_ATTR_IMMUTABLE: File is immutable
+ * FUSE_ATTR_APPEND: File is append-only
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 #define FUSE_ATTR_DAX		(1 << 1)
 #define FUSE_ATTR_EXCLUSIVE	(1 << 2)
 #define FUSE_ATTR_IOMAP		(1 << 3)
 #define FUSE_ATTR_ATOMIC	(1 << 4)
+#define FUSE_ATTR_SYNC		(1 << 5)
+#define FUSE_ATTR_IMMUTABLE	(1 << 6)
+#define FUSE_ATTR_APPEND	(1 << 7)
 
 /**
  * Open flags
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 5ae6c5639f6d2c..10543873f1a611 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1446,6 +1446,7 @@ static void fuse_fillattr(struct mnt_idmap *idmap, struct inode *inode,
 		blkbits = inode->i_sb->s_blocksize_bits;
 
 	stat->blksize = 1 << blkbits;
+	generic_fill_statx_attr(inode, stat);
 }
 
 static void fuse_statx_to_attr(struct fuse_statx *sx, struct fuse_attr *attr)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 94355977904068..7fcadbfe87a593 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -542,6 +542,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
 			inode->i_flags |= S_NOCMTIME;
 		inode->i_generation = generation;
 		fuse_init_inode(inode, attr, fc);
+		fuse_fileattr_init(inode, attr);
 		unlock_new_inode(inode);
 	} else if (fuse_stale_inode(inode, generation, attr)) {
 		/* nodeid was reused, any I/O on the old inode should fail */
diff --git a/fs/fuse/ioctl.c b/fs/fuse/ioctl.c
index 07529db21fb781..bd2caf191ce2e0 100644
--- a/fs/fuse/ioctl.c
+++ b/fs/fuse/ioctl.c
@@ -502,6 +502,53 @@ static void fuse_priv_ioctl_cleanup(struct inode *inode, struct fuse_file *ff)
 	fuse_file_release(inode, ff, O_RDONLY, NULL, S_ISDIR(inode->i_mode));
 }
 
+static inline void update_iflag(struct inode *inode, unsigned int iflag,
+				bool set)
+{
+	if (set)
+		inode->i_flags |= iflag;
+	else
+		inode->i_flags &= ~iflag;
+}
+
+static void fuse_fileattr_update_inode(struct inode *inode,
+				       const struct file_kattr *fa)
+{
+	unsigned int old_iflags = inode->i_flags;
+
+	if (!fuse_inode_is_exclusive(inode))
+		return;
+
+	if (fa->flags_valid) {
+		update_iflag(inode, S_SYNC, fa->flags & FS_SYNC_FL);
+		update_iflag(inode, S_IMMUTABLE, fa->flags & FS_IMMUTABLE_FL);
+		update_iflag(inode, S_APPEND, fa->flags & FS_APPEND_FL);
+	} else if (fa->fsx_valid) {
+		update_iflag(inode, S_SYNC, fa->fsx_xflags & FS_XFLAG_SYNC);
+		update_iflag(inode, S_IMMUTABLE,
+					fa->fsx_xflags & FS_XFLAG_IMMUTABLE);
+		update_iflag(inode, S_APPEND, fa->fsx_xflags & FS_XFLAG_APPEND);
+	}
+
+	if (old_iflags != inode->i_flags)
+		fuse_invalidate_attr(inode);
+}
+
+void fuse_fileattr_init(struct inode *inode, const struct fuse_attr *attr)
+{
+	if (!fuse_inode_is_exclusive(inode))
+		return;
+
+	if (attr->flags & FUSE_ATTR_SYNC)
+		inode->i_flags |= S_SYNC;
+
+	if (attr->flags & FUSE_ATTR_IMMUTABLE)
+		inode->i_flags |= S_IMMUTABLE;
+
+	if (attr->flags & FUSE_ATTR_APPEND)
+		inode->i_flags |= S_APPEND;
+}
+
 int fuse_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
 {
 	struct inode *inode = d_inode(dentry);
@@ -572,7 +619,10 @@ int fuse_fileattr_set(struct mnt_idmap *idmap,
 
 		err = fuse_priv_ioctl(inode, ff, FS_IOC_FSSETXATTR,
 				      &xfa, sizeof(xfa));
+		if (err)
+			goto cleanup;
 	}
+	fuse_fileattr_update_inode(inode, fa);
 
 cleanup:
 	fuse_priv_ioctl_cleanup(inode, ff);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 4/9] fuse_trace: allow local filesystems to set some VFS iflags
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:18   ` [PATCH 3/9] fuse: allow local filesystems to set some VFS iflags Darrick J. Wong
@ 2026-02-23 23:19   ` Darrick J. Wong
  2026-02-23 23:19   ` [PATCH 5/9] fuse: cache atime when in iomap mode Darrick J. Wong
                     ` (4 subsequent siblings)
  8 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:19 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   29 +++++++++++++++++++++++++++++
 fs/fuse/ioctl.c      |    7 +++++++
 2 files changed, 36 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 0016242ff34f62..7136ecf25e1f2b 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -179,6 +179,35 @@ TRACE_EVENT(fuse_request_end,
 		  __entry->unique, __entry->len, __entry->error)
 );
 
+DECLARE_EVENT_CLASS(fuse_fileattr_class,
+	TP_PROTO(const struct inode *inode, unsigned int old_iflags),
+
+	TP_ARGS(inode, old_iflags),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		__field(unsigned int,		old_iflags)
+		__field(unsigned int,		new_iflags)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->old_iflags	=	old_iflags;
+		__entry->new_iflags	=	inode->i_flags;
+	),
+
+	TP_printk(FUSE_INODE_FMT " old_iflags 0x%x iflags 0x%x",
+		  FUSE_INODE_PRINTK_ARGS,
+		  __entry->old_iflags,
+		  __entry->new_iflags)
+);
+#define DEFINE_FUSE_FILEATTR_EVENT(name)	\
+DEFINE_EVENT(fuse_fileattr_class, name,		\
+	TP_PROTO(const struct inode *inode, unsigned int old_iflags), \
+	TP_ARGS(inode, old_iflags))
+DEFINE_FUSE_FILEATTR_EVENT(fuse_fileattr_update_inode);
+DEFINE_FUSE_FILEATTR_EVENT(fuse_fileattr_init);
+
 #ifdef CONFIG_FUSE_BACKING
 #define FUSE_BACKING_FLAG_STRINGS \
 	{ FUSE_BACKING_TYPE_PASSTHROUGH,	"pass" }, \
diff --git a/fs/fuse/ioctl.c b/fs/fuse/ioctl.c
index bd2caf191ce2e0..5180066678e8c1 100644
--- a/fs/fuse/ioctl.c
+++ b/fs/fuse/ioctl.c
@@ -4,6 +4,7 @@
  */
 
 #include "fuse_i.h"
+#include "fuse_trace.h"
 
 #include <linux/uio.h>
 #include <linux/compat.h>
@@ -530,12 +531,16 @@ static void fuse_fileattr_update_inode(struct inode *inode,
 		update_iflag(inode, S_APPEND, fa->fsx_xflags & FS_XFLAG_APPEND);
 	}
 
+	trace_fuse_fileattr_update_inode(inode, old_iflags);
+
 	if (old_iflags != inode->i_flags)
 		fuse_invalidate_attr(inode);
 }
 
 void fuse_fileattr_init(struct inode *inode, const struct fuse_attr *attr)
 {
+	unsigned int old_iflags = inode->i_flags;
+
 	if (!fuse_inode_is_exclusive(inode))
 		return;
 
@@ -547,6 +552,8 @@ void fuse_fileattr_init(struct inode *inode, const struct fuse_attr *attr)
 
 	if (attr->flags & FUSE_ATTR_APPEND)
 		inode->i_flags |= S_APPEND;
+
+	trace_fuse_fileattr_init(inode, old_iflags);
 }
 
 int fuse_fileattr_get(struct dentry *dentry, struct file_kattr *fa)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 5/9] fuse: cache atime when in iomap mode
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:19   ` [PATCH 4/9] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:19   ` Darrick J. Wong
  2026-02-23 23:19   ` [PATCH 6/9] fuse: let the kernel handle KILL_SUID/KILL_SGID for iomap filesystems Darrick J. Wong
                     ` (3 subsequent siblings)
  8 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:19 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

When we're running in iomap mode, allow the kernel to cache the access
timestamp to further reduce the number of roundtrips to the fuse server.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/dir.c        |    5 +++++
 fs/fuse/fuse_iomap.c |    6 ++++++
 fs/fuse/inode.c      |   11 ++++++++---
 3 files changed, 19 insertions(+), 3 deletions(-)


diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 10543873f1a611..6c05321e32f136 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -2232,6 +2232,11 @@ int fuse_flush_times(struct inode *inode, struct fuse_file *ff)
 		inarg.ctime = inode_get_ctime_sec(inode);
 		inarg.ctimensec = inode_get_ctime_nsec(inode);
 	}
+	if (fuse_inode_has_iomap(inode)) {
+		inarg.valid |= FATTR_ATIME;
+		inarg.atime = inode_get_atime_sec(inode);
+		inarg.atimensec = inode_get_atime_nsec(inode);
+	}
 	if (ff) {
 		inarg.valid |= FATTR_FH;
 		inarg.fh = ff->fh;
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 65c8e06fdd653a..9599efcf1c2593 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -1164,6 +1164,12 @@ void fuse_iomap_init_inode(struct inode *inode, struct fuse_attr *attr)
 	if (attr->flags & FUSE_ATTR_ATOMIC)
 		fuse_inode_set_atomic(inode);
 
+	/*
+	 * iomap caches atime too, so we must load it from the fuse server
+	 * at instantiation time.
+	 */
+	inode_set_atime(inode, attr->atime, attr->atimensec);
+
 	trace_fuse_iomap_init_inode(inode);
 }
 
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 7fcadbfe87a593..1fedfb57a22514 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -266,7 +266,8 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
 	attr->mtimensec = min_t(u32, attr->mtimensec, NSEC_PER_SEC - 1);
 	attr->ctimensec = min_t(u32, attr->ctimensec, NSEC_PER_SEC - 1);
 
-	inode_set_atime(inode, attr->atime, attr->atimensec);
+	if (!(cache_mask & STATX_ATIME))
+		inode_set_atime(inode, attr->atime, attr->atimensec);
 	/* mtime from server may be stale due to local buffered write */
 	if (!(cache_mask & STATX_MTIME)) {
 		inode_set_mtime(inode, attr->mtime, attr->mtimensec);
@@ -331,8 +332,12 @@ u32 fuse_get_cache_mask(struct inode *inode)
 {
 	struct fuse_conn *fc = get_fuse_conn(inode);
 
-	if (S_ISREG(inode->i_mode) &&
-	    (fuse_inode_has_iomap(inode) || fc->writeback_cache))
+	if (!S_ISREG(inode->i_mode))
+		return 0;
+
+	if (fuse_inode_has_iomap(inode))
+		return STATX_MTIME | STATX_CTIME | STATX_ATIME | STATX_SIZE;
+	if (fc->writeback_cache)
 		return STATX_MTIME | STATX_CTIME | STATX_SIZE;
 
 	return 0;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 6/9] fuse: let the kernel handle KILL_SUID/KILL_SGID for iomap filesystems
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (4 preceding siblings ...)
  2026-02-23 23:19   ` [PATCH 5/9] fuse: cache atime when in iomap mode Darrick J. Wong
@ 2026-02-23 23:19   ` Darrick J. Wong
  2026-02-23 23:19   ` [PATCH 7/9] fuse_trace: " Darrick J. Wong
                     ` (2 subsequent siblings)
  8 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:19 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Let the kernel handle killing the suid/sgid bits because the
write/falloc/truncate/chown code already does this, and we don't have to
worry about external modifications that are only visible to the fuse
server (i.e. we're not a cluster fs).

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/dir.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)


diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 6c05321e32f136..069afade99d44f 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -2473,6 +2473,7 @@ static int fuse_setattr(struct mnt_idmap *idmap, struct dentry *entry,
 	struct inode *inode = d_inode(entry);
 	struct fuse_conn *fc = get_fuse_conn(inode);
 	struct file *file = (attr->ia_valid & ATTR_FILE) ? attr->ia_file : NULL;
+	const bool is_iomap = fuse_inode_has_iomap(inode);
 	int ret;
 
 	if (fuse_is_bad(inode))
@@ -2481,15 +2482,19 @@ static int fuse_setattr(struct mnt_idmap *idmap, struct dentry *entry,
 	if (!fuse_allow_current_process(get_fuse_conn(inode)))
 		return -EACCES;
 
-	if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) {
+	if (!is_iomap &&
+	    (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))) {
 		attr->ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID |
 				    ATTR_MODE);
 
 		/*
 		 * The only sane way to reliably kill suid/sgid is to do it in
-		 * the userspace filesystem
+		 * the userspace filesystem if this isn't an iomap file.  For
+		 * iomap filesystems we let the kernel kill the setuid/setgid
+		 * bits.
 		 *
-		 * This should be done on write(), truncate() and chown().
+		 * This should be done on write(), truncate(), chown(), and
+		 * fallocate().
 		 */
 		if (!fc->handle_killpriv && !fc->handle_killpriv_v2) {
 			/*


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 7/9] fuse_trace: let the kernel handle KILL_SUID/KILL_SGID for iomap filesystems
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (5 preceding siblings ...)
  2026-02-23 23:19   ` [PATCH 6/9] fuse: let the kernel handle KILL_SUID/KILL_SGID for iomap filesystems Darrick J. Wong
@ 2026-02-23 23:19   ` Darrick J. Wong
  2026-02-23 23:20   ` [PATCH 8/9] fuse: update ctime when updating acls on an iomap inode Darrick J. Wong
  2026-02-23 23:20   ` [PATCH 9/9] fuse: always cache ACLs when using iomap Darrick J. Wong
  8 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:19 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/dir.c        |    5 ++++
 2 files changed, 63 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 7136ecf25e1f2b..a6374d64a62357 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -208,6 +208,64 @@ DEFINE_EVENT(fuse_fileattr_class, name,		\
 DEFINE_FUSE_FILEATTR_EVENT(fuse_fileattr_update_inode);
 DEFINE_FUSE_FILEATTR_EVENT(fuse_fileattr_init);
 
+TRACE_EVENT(fuse_setattr_fill,
+	TP_PROTO(const struct inode *inode,
+		 const struct fuse_setattr_in *inarg),
+	TP_ARGS(inode, inarg),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		__field(umode_t,		mode)
+		__field(uint32_t,		valid)
+		__field(umode_t,		new_mode)
+		__field(uint64_t,		new_size)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->mode		=	inode->i_mode;
+		__entry->valid		=	inarg->valid;
+		__entry->new_mode	=	inarg->mode;
+		__entry->new_size	=	inarg->size;
+	),
+
+	TP_printk(FUSE_INODE_FMT " mode 0%o valid 0x%x new_mode 0%o new_size 0x%llx",
+		  FUSE_INODE_PRINTK_ARGS,
+		  __entry->mode,
+		  __entry->valid,
+		  __entry->new_mode,
+		  __entry->new_size)
+);
+
+TRACE_EVENT(fuse_setattr,
+	TP_PROTO(const struct inode *inode,
+		 const struct iattr *inarg),
+	TP_ARGS(inode, inarg),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		__field(umode_t,		mode)
+		__field(uint32_t,		valid)
+		__field(umode_t,		new_mode)
+		__field(uint64_t,		new_size)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->mode		=	inode->i_mode;
+		__entry->valid		=	inarg->ia_valid;
+		__entry->new_mode	=	inarg->ia_mode;
+		__entry->new_size	=	inarg->ia_size;
+	),
+
+	TP_printk(FUSE_INODE_FMT " mode 0%o valid 0x%x new_mode 0%o new_size 0x%llx",
+		  FUSE_INODE_PRINTK_ARGS,
+		  __entry->mode,
+		  __entry->valid,
+		  __entry->new_mode,
+		  __entry->new_size)
+);
+
 #ifdef CONFIG_FUSE_BACKING
 #define FUSE_BACKING_FLAG_STRINGS \
 	{ FUSE_BACKING_TYPE_PASSTHROUGH,	"pass" }, \
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 069afade99d44f..4729137fddab30 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -8,6 +8,7 @@
 
 #include "fuse_i.h"
 #include "fuse_iomap.h"
+#include "fuse_trace.h"
 
 #include <linux/pagemap.h>
 #include <linux/file.h>
@@ -2201,6 +2202,8 @@ static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args,
 			      struct fuse_setattr_in *inarg_p,
 			      struct fuse_attr_out *outarg_p)
 {
+	trace_fuse_setattr_fill(inode, inarg_p);
+
 	args->opcode = FUSE_SETATTR;
 	args->nodeid = get_node_id(inode);
 	args->in_numargs = 1;
@@ -2482,6 +2485,8 @@ static int fuse_setattr(struct mnt_idmap *idmap, struct dentry *entry,
 	if (!fuse_allow_current_process(get_fuse_conn(inode)))
 		return -EACCES;
 
+	trace_fuse_setattr(inode, attr);
+
 	if (!is_iomap &&
 	    (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))) {
 		attr->ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID |


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 8/9] fuse: update ctime when updating acls on an iomap inode
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (6 preceding siblings ...)
  2026-02-23 23:19   ` [PATCH 7/9] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:20   ` Darrick J. Wong
  2026-02-23 23:20   ` [PATCH 9/9] fuse: always cache ACLs when using iomap Darrick J. Wong
  8 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:20 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

In iomap mode, the fuse kernel driver is in charge of updating file
attributes, so we need to update ctime after an ACL change.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/acl.c |   18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)


diff --git a/fs/fuse/acl.c b/fs/fuse/acl.c
index 483ddf195d40a6..b1e6520ae237cc 100644
--- a/fs/fuse/acl.c
+++ b/fs/fuse/acl.c
@@ -7,6 +7,7 @@
  */
 
 #include "fuse_i.h"
+#include "fuse_iomap.h"
 
 #include <linux/posix_acl.h>
 #include <linux/posix_acl_xattr.h>
@@ -112,6 +113,7 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 	struct fuse_conn *fc = get_fuse_conn(inode);
 	const char *name;
 	umode_t mode = inode->i_mode;
+	const bool is_iomap = fuse_inode_has_iomap(inode);
 	int ret;
 
 	if (fuse_is_bad(inode))
@@ -179,10 +181,24 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 			ret = 0;
 	}
 
-	/* If we scheduled a mode update above, push that to userspace now. */
 	if (!ret) {
 		struct iattr attr = { };
 
+		/*
+		 * When we're running in iomap mode, we need to update mode and
+		 * ctime ourselves instead of letting the fuse server figure
+		 * that out.
+		 */
+		if (is_iomap) {
+			attr.ia_valid |= ATTR_CTIME;
+			inode_set_ctime_current(inode);
+			attr.ia_ctime = inode_get_ctime(inode);
+		}
+
+		/*
+		 * If we scheduled a mode update above, push that to userspace
+		 * now.
+		 */
 		if (mode != inode->i_mode) {
 			attr.ia_valid |= ATTR_MODE;
 			attr.ia_mode = mode;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 9/9] fuse: always cache ACLs when using iomap
  2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (7 preceding siblings ...)
  2026-02-23 23:20   ` [PATCH 8/9] fuse: update ctime when updating acls on an iomap inode Darrick J. Wong
@ 2026-02-23 23:20   ` Darrick J. Wong
  8 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:20 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Keep ACLs cached in memory when we're using iomap, so that we don't have
to make a round trip to the fuse server.  This might want to become a
FUSE_ATTR_ flag.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/acl.c     |   12 +++++++++---
 fs/fuse/dir.c     |   11 ++++++++---
 fs/fuse/readdir.c |    5 ++++-
 3 files changed, 21 insertions(+), 7 deletions(-)


diff --git a/fs/fuse/acl.c b/fs/fuse/acl.c
index b1e6520ae237cc..146d80552072bd 100644
--- a/fs/fuse/acl.c
+++ b/fs/fuse/acl.c
@@ -211,10 +211,16 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 	if (fc->posix_acl) {
 		/*
 		 * Fuse daemons without FUSE_POSIX_ACL never cached POSIX ACLs
-		 * and didn't invalidate attributes. Retain that behavior.
+		 * and didn't invalidate attributes. Retain that behavior
+		 * except for iomap, where we assume that only the source of
+		 * ACL changes is userspace.
 		 */
-		forget_all_cached_acls(inode);
-		fuse_invalidate_attr(inode);
+		if (!ret && is_iomap) {
+			set_cached_acl(inode, type, acl);
+		} else {
+			forget_all_cached_acls(inode);
+			fuse_invalidate_attr(inode);
+		}
 	}
 
 	return ret;
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 4729137fddab30..7be5185d9506d9 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -448,7 +448,8 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name,
 		    fuse_stale_inode(inode, outarg.generation, &outarg.attr))
 			goto invalid;
 
-		forget_all_cached_acls(inode);
+		if (!fuse_inode_has_iomap(inode))
+			forget_all_cached_acls(inode);
 		fuse_change_attributes(inode, &outarg.attr, NULL,
 				       ATTR_TIMEOUT(&outarg),
 				       attr_version);
@@ -1663,7 +1664,8 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,
 		sync = time_before64(fi->i_time, get_jiffies_64());
 
 	if (sync) {
-		forget_all_cached_acls(inode);
+		if (!fuse_inode_has_iomap(inode))
+			forget_all_cached_acls(inode);
 		/* Try statx if a field not covered by regular stat is wanted */
 		if (!fc->no_statx && (request_mask & ~STATX_BASIC_STATS)) {
 			err = fuse_do_statx(idmap, inode, file, stat);
@@ -1847,6 +1849,9 @@ static int fuse_access(struct inode *inode, int mask)
 
 static int fuse_perm_getattr(struct inode *inode, int mask)
 {
+	if (fuse_inode_has_iomap(inode))
+		return 0;
+
 	if (mask & MAY_NOT_BLOCK)
 		return -ECHILD;
 
@@ -2530,7 +2535,7 @@ static int fuse_setattr(struct mnt_idmap *idmap, struct dentry *entry,
 		 * If filesystem supports acls it may have updated acl xattrs in
 		 * the filesystem, so forget cached acls for the inode.
 		 */
-		if (fc->posix_acl)
+		if (fc->posix_acl && !is_iomap)
 			forget_all_cached_acls(inode);
 
 		/* Directory mode changed, may need to revalidate access */
diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c
index 45dd932eb03a5e..7ecc55049eefc6 100644
--- a/fs/fuse/readdir.c
+++ b/fs/fuse/readdir.c
@@ -8,6 +8,8 @@
 
 
 #include "fuse_i.h"
+#include "fuse_iomap.h"
+
 #include <linux/iversion.h>
 #include <linux/posix_acl.h>
 #include <linux/pagemap.h>
@@ -224,7 +226,8 @@ static int fuse_direntplus_link(struct file *file,
 		fi->nlookup++;
 		spin_unlock(&fi->lock);
 
-		forget_all_cached_acls(inode);
+		if (!fuse_inode_has_iomap(inode))
+			forget_all_cached_acls(inode);
 		fuse_change_attributes(inode, &o->attr, NULL,
 				       ATTR_TIMEOUT(o),
 				       attr_version);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 01/12] fuse: cache iomaps
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
@ 2026-02-23 23:20   ` Darrick J. Wong
  2026-02-27 18:07     ` Darrick J. Wong
  2026-02-23 23:20   ` [PATCH 02/12] fuse_trace: " Darrick J. Wong
                     ` (10 subsequent siblings)
  11 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:20 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Cache iomaps to a file so that we don't have to upcall the server.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h           |    3 
 fs/fuse/fuse_iomap_cache.h |   99 +++
 include/uapi/linux/fuse.h  |    5 
 fs/fuse/Makefile           |    2 
 fs/fuse/fuse_iomap.c       |    5 
 fs/fuse/fuse_iomap_cache.c | 1701 ++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/trace.c            |    1 
 7 files changed, 1815 insertions(+), 1 deletion(-)
 create mode 100644 fs/fuse/fuse_iomap_cache.h
 create mode 100644 fs/fuse/fuse_iomap_cache.c


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index b4da866187ba2c..1ba95d1f430c3e 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -197,6 +197,9 @@ struct fuse_inode {
 			spinlock_t ioend_lock;
 			struct work_struct ioend_work;
 			struct list_head ioend_list;
+
+			/* cached iomap mappings */
+			struct fuse_iomap_cache *cache;
 #endif
 		};
 
diff --git a/fs/fuse/fuse_iomap_cache.h b/fs/fuse/fuse_iomap_cache.h
new file mode 100644
index 00000000000000..922ca182357aa7
--- /dev/null
+++ b/fs/fuse/fuse_iomap_cache.h
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * The fuse_iext code comes from xfs_iext_tree.[ch] and is:
+ * Copyright (c) 2017 Christoph Hellwig.
+ *
+ * Everything else is:
+ * Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#ifndef _FS_FUSE_IOMAP_CACHE_H
+#define _FS_FUSE_IOMAP_CACHE_H
+
+#if IS_ENABLED(CONFIG_FUSE_IOMAP)
+/*
+ * File incore extent information, present for read and write mappings.
+ */
+struct fuse_iext_root {
+	/* bytes in ir_data, or -1 if it has never been used */
+	int64_t			ir_bytes;
+	void			*ir_data;	/* extent tree root */
+	unsigned int		ir_height;	/* height of the extent tree */
+};
+
+struct fuse_iomap_cache {
+	struct fuse_iext_root	ic_read;
+	struct fuse_iext_root	ic_write;
+	uint64_t		ic_seq;		/* validity counter */
+	struct rw_semaphore	ic_lock;	/* mapping lock */
+	struct inode		*ic_inode;
+};
+
+void fuse_iomap_cache_lock(struct inode *inode);
+void fuse_iomap_cache_unlock(struct inode *inode);
+void fuse_iomap_cache_lock_shared(struct inode *inode);
+void fuse_iomap_cache_unlock_shared(struct inode *inode);
+
+struct fuse_iext_leaf;
+
+struct fuse_iext_cursor {
+	struct fuse_iext_leaf	*leaf;
+	int			pos;
+};
+
+#define FUSE_IEXT_LEFT_CONTIG	(1u << 0)
+#define FUSE_IEXT_RIGHT_CONTIG	(1u << 1)
+#define FUSE_IEXT_LEFT_FILLING	(1u << 2)
+#define FUSE_IEXT_RIGHT_FILLING	(1u << 3)
+#define FUSE_IEXT_LEFT_VALID	(1u << 4)
+#define FUSE_IEXT_RIGHT_VALID	(1u << 5)
+#define FUSE_IEXT_WRITE_MAPPING	(1u << 6)
+
+bool fuse_iext_get_extent(const struct fuse_iext_root *ir,
+			  const struct fuse_iext_cursor *cur,
+			  struct fuse_iomap_io *gotp);
+
+static inline uint64_t fuse_iext_read_seq(struct fuse_iomap_cache *ic)
+{
+	return (uint64_t)READ_ONCE(ic->ic_seq);
+}
+
+static inline void fuse_iomap_cache_init(struct fuse_inode *fi)
+{
+	fi->cache = NULL;
+}
+
+static inline bool fuse_inode_caches_iomaps(const struct inode *inode)
+{
+	const struct fuse_inode *fi = get_fuse_inode(inode);
+
+	return fi->cache != NULL;
+}
+
+int fuse_iomap_cache_alloc(struct inode *inode);
+void fuse_iomap_cache_free(struct inode *inode);
+
+int fuse_iomap_cache_remove(struct inode *inode, enum fuse_iomap_iodir iodir,
+			    loff_t off, uint64_t len);
+
+int fuse_iomap_cache_upsert(struct inode *inode, enum fuse_iomap_iodir iodir,
+			    const struct fuse_iomap_io *map);
+
+enum fuse_iomap_lookup_result {
+	LOOKUP_HIT,
+	LOOKUP_MISS,
+	LOOKUP_NOFORK,
+};
+
+struct fuse_iomap_lookup {
+	struct fuse_iomap_io	map;		 /* cached mapping */
+	uint64_t		validity_cookie; /* used with .iomap_valid() */
+};
+
+enum fuse_iomap_lookup_result
+fuse_iomap_cache_lookup(struct inode *inode, enum fuse_iomap_iodir iodir,
+			loff_t off, uint64_t len,
+			struct fuse_iomap_lookup *mval);
+#endif /* CONFIG_FUSE_IOMAP */
+
+#endif /* _FS_FUSE_IOMAP_CACHE_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index bf8514a5ee27af..a273838bc20f2f 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1394,6 +1394,8 @@ struct fuse_uring_cmd_req {
 
 /* fuse-specific mapping type indicating that writes use the read mapping */
 #define FUSE_IOMAP_TYPE_PURE_OVERWRITE	(255)
+/* fuse-specific mapping type saying the server has populated the cache */
+#define FUSE_IOMAP_TYPE_RETRY_CACHE	(254)
 
 #define FUSE_IOMAP_DEV_NULL		(0U)	/* null device cookie */
 
@@ -1551,4 +1553,7 @@ struct fuse_iomap_dev_inval_out {
 	struct fuse_range range;
 };
 
+/* invalidate all cached iomap mappings up to EOF */
+#define FUSE_IOMAP_INVAL_TO_EOF		(~0ULL)
+
 #endif /* _LINUX_FUSE_H */
diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile
index 2536bc6a71b898..c672503da7bcbd 100644
--- a/fs/fuse/Makefile
+++ b/fs/fuse/Makefile
@@ -18,6 +18,6 @@ fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o
 fuse-$(CONFIG_FUSE_BACKING) += backing.o
 fuse-$(CONFIG_SYSCTL) += sysctl.o
 fuse-$(CONFIG_FUSE_IO_URING) += dev_uring.o
-fuse-$(CONFIG_FUSE_IOMAP) += fuse_iomap.o
+fuse-$(CONFIG_FUSE_IOMAP) += fuse_iomap.o fuse_iomap_cache.o
 
 virtiofs-y := virtio_fs.o
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 9599efcf1c2593..849ce1626c35fd 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -14,6 +14,7 @@
 #include "fuse_iomap.h"
 #include "fuse_iomap_i.h"
 #include "fuse_dev_i.h"
+#include "fuse_iomap_cache.h"
 
 static bool __read_mostly enable_iomap =
 #if IS_ENABLED(CONFIG_FUSE_IOMAP_BY_DEFAULT)
@@ -1179,6 +1180,8 @@ void fuse_iomap_evict_inode(struct inode *inode)
 
 	trace_fuse_iomap_evict_inode(inode);
 
+	if (fuse_inode_caches_iomaps(inode))
+		fuse_iomap_cache_free(inode);
 	fuse_inode_clear_atomic(inode);
 	fuse_inode_clear_iomap(inode);
 }
@@ -1886,6 +1889,8 @@ static inline void fuse_inode_set_iomap(struct inode *inode)
 		min_order = inode->i_blkbits - PAGE_SHIFT;
 
 	mapping_set_folio_min_order(inode->i_mapping, min_order);
+
+	fuse_iomap_cache_init(fi);
 	set_bit(FUSE_I_IOMAP, &fi->state);
 }
 
diff --git a/fs/fuse/fuse_iomap_cache.c b/fs/fuse/fuse_iomap_cache.c
new file mode 100644
index 00000000000000..e32de8a5e3c325
--- /dev/null
+++ b/fs/fuse/fuse_iomap_cache.c
@@ -0,0 +1,1701 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * fuse_iext* code adapted from xfs_iext_tree.c:
+ * Copyright (c) 2017 Christoph Hellwig.
+ *
+ * fuse_iomap_cache*lock* code adapted from xfs_inode.c:
+ * Copyright (c) 2000-2006 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#include "fuse_i.h"
+#include "fuse_trace.h"
+#include "fuse_iomap_i.h"
+#include "fuse_iomap.h"
+#include "fuse_iomap_cache.h"
+#include <linux/iomap.h>
+
+void fuse_iomap_cache_lock_shared(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache *ic = fi->cache;
+
+	down_read(&ic->ic_lock);
+}
+
+void fuse_iomap_cache_unlock_shared(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache *ic = fi->cache;
+
+	up_read(&ic->ic_lock);
+}
+
+void fuse_iomap_cache_lock(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache *ic = fi->cache;
+
+	down_write(&ic->ic_lock);
+}
+
+void fuse_iomap_cache_unlock(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache *ic = fi->cache;
+
+	up_write(&ic->ic_lock);
+}
+
+static inline void assert_cache_locked_shared(struct fuse_iomap_cache *ic)
+{
+	rwsem_assert_held(&ic->ic_lock);
+}
+
+static inline void assert_cache_locked(struct fuse_iomap_cache *ic)
+{
+	rwsem_assert_held_write_nolockdep(&ic->ic_lock);
+}
+
+/*
+ * In-core extent btree block layout:
+ *
+ * There are two types of blocks in the btree: leaf and inner (non-leaf) blocks.
+ *
+ * The leaf blocks are made up by %KEYS_PER_NODE extent records, which each
+ * contain the startoffset, blockcount, startblock and unwritten extent flag.
+ * See above for the exact format, followed by pointers to the previous and next
+ * leaf blocks (if there are any).
+ *
+ * The inner (non-leaf) blocks first contain KEYS_PER_NODE lookup keys, followed
+ * by an equal number of pointers to the btree blocks at the next lower level.
+ *
+ *		+-------+-------+-------+-------+-------+----------+----------+
+ * Leaf:	| rec 1 | rec 2 | rec 3 | rec 4 | rec N | prev-ptr | next-ptr |
+ *		+-------+-------+-------+-------+-------+----------+----------+
+ *
+ *		+-------+-------+-------+-------+-------+-------+------+-------+
+ * Inner:	| key 1 | key 2 | key 3 | key N | ptr 1 | ptr 2 | ptr3 | ptr N |
+ *		+-------+-------+-------+-------+-------+-------+------+-------+
+ */
+typedef uint64_t fuse_iext_key_t;
+#define FUSE_IEXT_KEY_INVALID	(1ULL << 63)
+
+enum {
+	NODE_SIZE	= 256,
+	KEYS_PER_NODE	= NODE_SIZE / (sizeof(fuse_iext_key_t) + sizeof(void *)),
+	RECS_PER_LEAF	= (NODE_SIZE - (2 * sizeof(struct fuse_iext_leaf *))) /
+				sizeof(struct fuse_iomap_io),
+};
+
+/* maximum length of a mapping that we're willing to cache */
+#define FUSE_IOMAP_MAX_LEN	((loff_t)(1ULL << 63))
+
+struct fuse_iext_node {
+	fuse_iext_key_t		keys[KEYS_PER_NODE];
+	void			*ptrs[KEYS_PER_NODE];
+};
+
+struct fuse_iext_leaf {
+	struct fuse_iomap_io	recs[RECS_PER_LEAF];
+	struct fuse_iext_leaf	*prev;
+	struct fuse_iext_leaf	*next;
+};
+
+static uint32_t
+fuse_iomap_fork_to_state(const struct fuse_iomap_cache *ic,
+			 const struct fuse_iext_root *ir)
+{
+	ASSERT(ir == &ic->ic_write || ir == &ic->ic_read);
+
+	if (ir == &ic->ic_write)
+		return FUSE_IEXT_WRITE_MAPPING;
+	return 0;
+}
+
+/* Convert bmap state flags to an inode fork. */
+static struct fuse_iext_root *
+fuse_iext_state_to_fork(
+	struct fuse_iomap_cache	*ic,
+	uint32_t		state)
+{
+	if (state & FUSE_IEXT_WRITE_MAPPING)
+		return &ic->ic_write;
+	return &ic->ic_read;
+}
+
+/* The internal iext tree record is a struct fuse_iomap_io */
+
+static inline bool fuse_iext_rec_is_empty(const struct fuse_iomap_io *rec)
+{
+	return rec->length == 0;
+}
+
+static inline void fuse_iext_rec_clear(struct fuse_iomap_io *rec)
+{
+	memset(rec, 0, sizeof(*rec));
+}
+
+static inline void
+fuse_iext_set(
+	struct fuse_iomap_io		*rec,
+	const struct fuse_iomap_io	*irec)
+{
+	ASSERT(irec->length > 0);
+
+	*rec = *irec;
+}
+
+static inline void
+fuse_iext_get(
+	struct fuse_iomap_io		*irec,
+	const struct fuse_iomap_io	*rec)
+{
+	*irec = *rec;
+}
+
+static inline uint64_t fuse_iext_count(const struct fuse_iext_root *ir)
+{
+	return ir->ir_bytes / sizeof(struct fuse_iomap_io);
+}
+
+static inline int fuse_iext_max_recs(const struct fuse_iext_root *ir)
+{
+	if (ir->ir_height == 1)
+		return fuse_iext_count(ir);
+	return RECS_PER_LEAF;
+}
+
+static inline struct fuse_iomap_io *cur_rec(const struct fuse_iext_cursor *cur)
+{
+	return &cur->leaf->recs[cur->pos];
+}
+
+static bool fuse_iext_valid(const struct fuse_iext_root *ir,
+				   const struct fuse_iext_cursor *cur)
+{
+	if (!cur->leaf)
+		return false;
+	if (cur->pos < 0 || cur->pos >= fuse_iext_max_recs(ir))
+		return false;
+	if (fuse_iext_rec_is_empty(cur_rec(cur)))
+		return false;
+	return true;
+}
+
+static void *
+fuse_iext_find_first_leaf(
+	struct fuse_iext_root	*ir)
+{
+	struct fuse_iext_node	*node = ir->ir_data;
+	int			height;
+
+	if (!ir->ir_height)
+		return NULL;
+
+	for (height = ir->ir_height; height > 1; height--) {
+		node = node->ptrs[0];
+		ASSERT(node);
+	}
+
+	return node;
+}
+
+static void *
+fuse_iext_find_last_leaf(
+	struct fuse_iext_root	*ir)
+{
+	struct fuse_iext_node	*node = ir->ir_data;
+	int			height, i;
+
+	if (!ir->ir_height)
+		return NULL;
+
+	for (height = ir->ir_height; height > 1; height--) {
+		for (i = 1; i < KEYS_PER_NODE; i++)
+			if (!node->ptrs[i])
+				break;
+		node = node->ptrs[i - 1];
+		ASSERT(node);
+	}
+
+	return node;
+}
+
+static void
+fuse_iext_first(
+	struct fuse_iext_root	*ir,
+	struct fuse_iext_cursor	*cur)
+{
+	cur->pos = 0;
+	cur->leaf = fuse_iext_find_first_leaf(ir);
+}
+
+static void
+fuse_iext_last(
+	struct fuse_iext_root	*ir,
+	struct fuse_iext_cursor	*cur)
+{
+	int			i;
+
+	cur->leaf = fuse_iext_find_last_leaf(ir);
+	if (!cur->leaf) {
+		cur->pos = 0;
+		return;
+	}
+
+	for (i = 1; i < fuse_iext_max_recs(ir); i++) {
+		if (fuse_iext_rec_is_empty(&cur->leaf->recs[i]))
+			break;
+	}
+	cur->pos = i - 1;
+}
+
+static void
+fuse_iext_next(
+	struct fuse_iext_root	*ir,
+	struct fuse_iext_cursor	*cur)
+{
+	if (!cur->leaf) {
+		ASSERT(cur->pos <= 0 || cur->pos >= RECS_PER_LEAF);
+		fuse_iext_first(ir, cur);
+		return;
+	}
+
+	ASSERT(cur->pos >= 0);
+	ASSERT(cur->pos < fuse_iext_max_recs(ir));
+
+	cur->pos++;
+	if (ir->ir_height > 1 && !fuse_iext_valid(ir, cur) &&
+	    cur->leaf->next) {
+		cur->leaf = cur->leaf->next;
+		cur->pos = 0;
+	}
+}
+
+static void
+fuse_iext_prev(
+	struct fuse_iext_root	*ir,
+	struct fuse_iext_cursor	*cur)
+{
+	if (!cur->leaf) {
+		ASSERT(cur->pos <= 0 || cur->pos >= RECS_PER_LEAF);
+		fuse_iext_last(ir, cur);
+		return;
+	}
+
+	ASSERT(cur->pos >= 0);
+	ASSERT(cur->pos <= RECS_PER_LEAF);
+
+recurse:
+	do {
+		cur->pos--;
+		if (fuse_iext_valid(ir, cur))
+			return;
+	} while (cur->pos > 0);
+
+	if (ir->ir_height > 1 && cur->leaf->prev) {
+		cur->leaf = cur->leaf->prev;
+		cur->pos = RECS_PER_LEAF;
+		goto recurse;
+	}
+}
+
+/*
+ * Return true if the cursor points at an extent and return the extent structure
+ * in gotp.  Else return false.
+ */
+bool
+fuse_iext_get_extent(
+	const struct fuse_iext_root	*ir,
+	const struct fuse_iext_cursor	*cur,
+	struct fuse_iomap_io		*gotp)
+{
+	if (!fuse_iext_valid(ir, cur))
+		return false;
+	fuse_iext_get(gotp, cur_rec(cur));
+	return true;
+}
+
+static inline bool fuse_iext_next_extent(struct fuse_iext_root *ir,
+		struct fuse_iext_cursor *cur, struct fuse_iomap_io *gotp)
+{
+	fuse_iext_next(ir, cur);
+	return fuse_iext_get_extent(ir, cur, gotp);
+}
+
+static inline bool fuse_iext_prev_extent(struct fuse_iext_root *ir,
+		struct fuse_iext_cursor *cur, struct fuse_iomap_io *gotp)
+{
+	fuse_iext_prev(ir, cur);
+	return fuse_iext_get_extent(ir, cur, gotp);
+}
+
+/*
+ * Return the extent after cur in gotp without updating the cursor.
+ */
+static inline bool fuse_iext_peek_next_extent(struct fuse_iext_root *ir,
+		struct fuse_iext_cursor *cur, struct fuse_iomap_io *gotp)
+{
+	struct fuse_iext_cursor ncur = *cur;
+
+	fuse_iext_next(ir, &ncur);
+	return fuse_iext_get_extent(ir, &ncur, gotp);
+}
+
+/*
+ * Return the extent before cur in gotp without updating the cursor.
+ */
+static inline bool fuse_iext_peek_prev_extent(struct fuse_iext_root *ir,
+		struct fuse_iext_cursor *cur, struct fuse_iomap_io *gotp)
+{
+	struct fuse_iext_cursor ncur = *cur;
+
+	fuse_iext_prev(ir, &ncur);
+	return fuse_iext_get_extent(ir, &ncur, gotp);
+}
+
+static inline int
+fuse_iext_key_cmp(
+	struct fuse_iext_node	*node,
+	int			n,
+	loff_t			offset)
+{
+	if (node->keys[n] > offset)
+		return 1;
+	if (node->keys[n] < offset)
+		return -1;
+	return 0;
+}
+
+static inline int
+fuse_iext_rec_cmp(
+	struct fuse_iomap_io	*rec,
+	loff_t			offset)
+{
+	if (rec->offset > offset)
+		return 1;
+	if (rec->offset + rec->length <= offset)
+		return -1;
+	return 0;
+}
+
+static void *
+fuse_iext_find_level(
+	struct fuse_iext_root	*ir,
+	loff_t			offset,
+	int			level)
+{
+	struct fuse_iext_node	*node = ir->ir_data;
+	int			height, i;
+
+	if (!ir->ir_height)
+		return NULL;
+
+	for (height = ir->ir_height; height > level; height--) {
+		for (i = 1; i < KEYS_PER_NODE; i++)
+			if (fuse_iext_key_cmp(node, i, offset) > 0)
+				break;
+
+		node = node->ptrs[i - 1];
+		if (!node)
+			break;
+	}
+
+	return node;
+}
+
+static int
+fuse_iext_node_pos(
+	struct fuse_iext_node	*node,
+	loff_t			offset)
+{
+	int			i;
+
+	for (i = 1; i < KEYS_PER_NODE; i++) {
+		if (fuse_iext_key_cmp(node, i, offset) > 0)
+			break;
+	}
+
+	return i - 1;
+}
+
+static int
+fuse_iext_node_insert_pos(
+	struct fuse_iext_node	*node,
+	loff_t			offset)
+{
+	int			i;
+
+	for (i = 0; i < KEYS_PER_NODE; i++) {
+		if (fuse_iext_key_cmp(node, i, offset) > 0)
+			return i;
+	}
+
+	return KEYS_PER_NODE;
+}
+
+static int
+fuse_iext_node_nr_entries(
+	struct fuse_iext_node	*node,
+	int			start)
+{
+	int			i;
+
+	for (i = start; i < KEYS_PER_NODE; i++) {
+		if (node->keys[i] == FUSE_IEXT_KEY_INVALID)
+			break;
+	}
+
+	return i;
+}
+
+static int
+fuse_iext_leaf_nr_entries(
+	struct fuse_iext_root	*ir,
+	struct fuse_iext_leaf	*leaf,
+	int			start)
+{
+	int			i;
+
+	for (i = start; i < fuse_iext_max_recs(ir); i++) {
+		if (fuse_iext_rec_is_empty(&leaf->recs[i]))
+			break;
+	}
+
+	return i;
+}
+
+static inline fuse_iext_key_t
+fuse_iext_leaf_key(
+	struct fuse_iext_leaf	*leaf,
+	int			n)
+{
+	return leaf->recs[n].offset;
+}
+
+static inline void *
+fuse_iext_alloc_node(
+	int	size)
+{
+	return kzalloc(size, GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
+}
+
+static void
+fuse_iext_grow(
+	struct fuse_iext_root	*ir)
+{
+	struct fuse_iext_node	*node = fuse_iext_alloc_node(NODE_SIZE);
+	int			i;
+
+	if (ir->ir_height == 1) {
+		struct fuse_iext_leaf *prev = ir->ir_data;
+
+		node->keys[0] = fuse_iext_leaf_key(prev, 0);
+		node->ptrs[0] = prev;
+	} else  {
+		struct fuse_iext_node *prev = ir->ir_data;
+
+		ASSERT(ir->ir_height > 1);
+
+		node->keys[0] = prev->keys[0];
+		node->ptrs[0] = prev;
+	}
+
+	for (i = 1; i < KEYS_PER_NODE; i++)
+		node->keys[i] = FUSE_IEXT_KEY_INVALID;
+
+	ir->ir_data = node;
+	ir->ir_height++;
+}
+
+static void
+fuse_iext_update_node(
+	struct fuse_iext_root	*ir,
+	loff_t			old_offset,
+	loff_t			new_offset,
+	int			level,
+	void			*ptr)
+{
+	struct fuse_iext_node	*node = ir->ir_data;
+	int			height, i;
+
+	for (height = ir->ir_height; height > level; height--) {
+		for (i = 0; i < KEYS_PER_NODE; i++) {
+			if (i > 0 && fuse_iext_key_cmp(node, i, old_offset) > 0)
+				break;
+			if (node->keys[i] == old_offset)
+				node->keys[i] = new_offset;
+		}
+		node = node->ptrs[i - 1];
+		ASSERT(node);
+	}
+
+	ASSERT(node == ptr);
+}
+
+static struct fuse_iext_node *
+fuse_iext_split_node(
+	struct fuse_iext_node	**nodep,
+	int			*pos,
+	int			*nr_entries)
+{
+	struct fuse_iext_node	*node = *nodep;
+	struct fuse_iext_node	*new = fuse_iext_alloc_node(NODE_SIZE);
+	const int		nr_move = KEYS_PER_NODE / 2;
+	int			nr_keep = nr_move + (KEYS_PER_NODE & 1);
+	int			i = 0;
+
+	/* for sequential append operations just spill over into the new node */
+	if (*pos == KEYS_PER_NODE) {
+		*nodep = new;
+		*pos = 0;
+		*nr_entries = 0;
+		goto done;
+	}
+
+
+	for (i = 0; i < nr_move; i++) {
+		new->keys[i] = node->keys[nr_keep + i];
+		new->ptrs[i] = node->ptrs[nr_keep + i];
+
+		node->keys[nr_keep + i] = FUSE_IEXT_KEY_INVALID;
+		node->ptrs[nr_keep + i] = NULL;
+	}
+
+	if (*pos >= nr_keep) {
+		*nodep = new;
+		*pos -= nr_keep;
+		*nr_entries = nr_move;
+	} else {
+		*nr_entries = nr_keep;
+	}
+done:
+	for (; i < KEYS_PER_NODE; i++)
+		new->keys[i] = FUSE_IEXT_KEY_INVALID;
+	return new;
+}
+
+static void
+fuse_iext_insert_node(
+	struct fuse_iext_root	*ir,
+	fuse_iext_key_t		offset,
+	void			*ptr,
+	int			level)
+{
+	struct fuse_iext_node	*node, *new;
+	int			i, pos, nr_entries;
+
+again:
+	if (ir->ir_height < level)
+		fuse_iext_grow(ir);
+
+	new = NULL;
+	node = fuse_iext_find_level(ir, offset, level);
+	pos = fuse_iext_node_insert_pos(node, offset);
+	nr_entries = fuse_iext_node_nr_entries(node, pos);
+
+	ASSERT(pos >= nr_entries || fuse_iext_key_cmp(node, pos, offset) != 0);
+	ASSERT(nr_entries <= KEYS_PER_NODE);
+
+	if (nr_entries == KEYS_PER_NODE)
+		new = fuse_iext_split_node(&node, &pos, &nr_entries);
+
+	/*
+	 * Update the pointers in higher levels if the first entry changes
+	 * in an existing node.
+	 */
+	if (node != new && pos == 0 && nr_entries > 0)
+		fuse_iext_update_node(ir, node->keys[0], offset, level, node);
+
+	for (i = nr_entries; i > pos; i--) {
+		node->keys[i] = node->keys[i - 1];
+		node->ptrs[i] = node->ptrs[i - 1];
+	}
+	node->keys[pos] = offset;
+	node->ptrs[pos] = ptr;
+
+	if (new) {
+		offset = new->keys[0];
+		ptr = new;
+		level++;
+		goto again;
+	}
+}
+
+static struct fuse_iext_leaf *
+fuse_iext_split_leaf(
+	struct fuse_iext_cursor	*cur,
+	int			*nr_entries)
+{
+	struct fuse_iext_leaf	*leaf = cur->leaf;
+	struct fuse_iext_leaf	*new = fuse_iext_alloc_node(NODE_SIZE);
+	const int		nr_move = RECS_PER_LEAF / 2;
+	int			nr_keep = nr_move + (RECS_PER_LEAF & 1);
+	int			i;
+
+	/* for sequential append operations just spill over into the new node */
+	if (cur->pos == RECS_PER_LEAF) {
+		cur->leaf = new;
+		cur->pos = 0;
+		*nr_entries = 0;
+		goto done;
+	}
+
+	for (i = 0; i < nr_move; i++) {
+		new->recs[i] = leaf->recs[nr_keep + i];
+		fuse_iext_rec_clear(&leaf->recs[nr_keep + i]);
+	}
+
+	if (cur->pos >= nr_keep) {
+		cur->leaf = new;
+		cur->pos -= nr_keep;
+		*nr_entries = nr_move;
+	} else {
+		*nr_entries = nr_keep;
+	}
+done:
+	if (leaf->next)
+		leaf->next->prev = new;
+	new->next = leaf->next;
+	new->prev = leaf;
+	leaf->next = new;
+	return new;
+}
+
+static void
+fuse_iext_alloc_root(
+	struct fuse_iext_root	*ir,
+	struct fuse_iext_cursor	*cur)
+{
+	ASSERT(ir->ir_bytes == 0);
+
+	ir->ir_data = fuse_iext_alloc_node(sizeof(struct fuse_iomap_io));
+	ir->ir_height = 1;
+
+	/* now that we have a node step into it */
+	cur->leaf = ir->ir_data;
+	cur->pos = 0;
+}
+
+static void
+fuse_iext_realloc_root(
+	struct fuse_iext_root	*ir,
+	struct fuse_iext_cursor	*cur)
+{
+	int64_t new_size = ir->ir_bytes + sizeof(struct fuse_iomap_io);
+	void *new;
+
+	/* account for the prev/next pointers */
+	if (new_size / sizeof(struct fuse_iomap_io) == RECS_PER_LEAF)
+		new_size = NODE_SIZE;
+
+	new = krealloc(ir->ir_data, new_size,
+			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
+	memset(new + ir->ir_bytes, 0, new_size - ir->ir_bytes);
+	ir->ir_data = new;
+	cur->leaf = new;
+}
+
+/*
+ * Increment the sequence counter on extent tree changes. We use WRITE_ONCE
+ * here to ensure the update to the sequence counter is seen before the
+ * modifications to the extent tree itself take effect.
+ */
+static inline void fuse_iext_inc_seq(struct fuse_iomap_cache *ic)
+{
+	WRITE_ONCE(ic->ic_seq, READ_ONCE(ic->ic_seq) + 1);
+}
+
+static void
+fuse_iext_insert_raw(
+	struct fuse_iomap_cache		*ic,
+	struct fuse_iext_root		*ir,
+	struct fuse_iext_cursor		*cur,
+	const struct fuse_iomap_io	*irec)
+{
+	loff_t				offset = irec->offset;
+	struct fuse_iext_leaf		*new = NULL;
+	int				nr_entries, i;
+
+	fuse_iext_inc_seq(ic);
+
+	if (ir->ir_height == 0)
+		fuse_iext_alloc_root(ir, cur);
+	else if (ir->ir_height == 1)
+		fuse_iext_realloc_root(ir, cur);
+
+	nr_entries = fuse_iext_leaf_nr_entries(ir, cur->leaf, cur->pos);
+	ASSERT(nr_entries <= RECS_PER_LEAF);
+	ASSERT(cur->pos >= nr_entries ||
+	       fuse_iext_rec_cmp(cur_rec(cur), irec->offset) != 0);
+
+	if (nr_entries == RECS_PER_LEAF)
+		new = fuse_iext_split_leaf(cur, &nr_entries);
+
+	/*
+	 * Update the pointers in higher levels if the first entry changes
+	 * in an existing node.
+	 */
+	if (cur->leaf != new && cur->pos == 0 && nr_entries > 0) {
+		fuse_iext_update_node(ir, fuse_iext_leaf_key(cur->leaf, 0),
+				offset, 1, cur->leaf);
+	}
+
+	for (i = nr_entries; i > cur->pos; i--)
+		cur->leaf->recs[i] = cur->leaf->recs[i - 1];
+	fuse_iext_set(cur_rec(cur), irec);
+	ir->ir_bytes += sizeof(struct fuse_iomap_io);
+
+	if (new)
+		fuse_iext_insert_node(ir, fuse_iext_leaf_key(new, 0), new, 2);
+}
+
+static void
+fuse_iext_insert(
+	struct fuse_iomap_cache		*ic,
+	struct fuse_iext_cursor		*cur,
+	const struct fuse_iomap_io	*irec,
+	uint32_t			state)
+{
+	struct fuse_iext_root		*ir = fuse_iext_state_to_fork(ic, state);
+
+	fuse_iext_insert_raw(ic, ir, cur, irec);
+}
+
+static struct fuse_iext_node *
+fuse_iext_rebalance_node(
+	struct fuse_iext_node	*parent,
+	int			*pos,
+	struct fuse_iext_node	*node,
+	int			nr_entries)
+{
+	/*
+	 * If the neighbouring nodes are completely full, or have different
+	 * parents, we might never be able to merge our node, and will only
+	 * delete it once the number of entries hits zero.
+	 */
+	if (nr_entries == 0)
+		return node;
+
+	if (*pos > 0) {
+		struct fuse_iext_node *prev = parent->ptrs[*pos - 1];
+		int nr_prev = fuse_iext_node_nr_entries(prev, 0), i;
+
+		if (nr_prev + nr_entries <= KEYS_PER_NODE) {
+			for (i = 0; i < nr_entries; i++) {
+				prev->keys[nr_prev + i] = node->keys[i];
+				prev->ptrs[nr_prev + i] = node->ptrs[i];
+			}
+			return node;
+		}
+	}
+
+	if (*pos + 1 < fuse_iext_node_nr_entries(parent, *pos)) {
+		struct fuse_iext_node *next = parent->ptrs[*pos + 1];
+		int nr_next = fuse_iext_node_nr_entries(next, 0), i;
+
+		if (nr_entries + nr_next <= KEYS_PER_NODE) {
+			/*
+			 * Merge the next node into this node so that we don't
+			 * have to do an additional update of the keys in the
+			 * higher levels.
+			 */
+			for (i = 0; i < nr_next; i++) {
+				node->keys[nr_entries + i] = next->keys[i];
+				node->ptrs[nr_entries + i] = next->ptrs[i];
+			}
+
+			++*pos;
+			return next;
+		}
+	}
+
+	return NULL;
+}
+
+static void
+fuse_iext_remove_node(
+	struct fuse_iext_root	*ir,
+	loff_t			offset,
+	void			*victim)
+{
+	struct fuse_iext_node	*node, *parent;
+	int			level = 2, pos, nr_entries, i;
+
+	ASSERT(level <= ir->ir_height);
+	node = fuse_iext_find_level(ir, offset, level);
+	pos = fuse_iext_node_pos(node, offset);
+again:
+	ASSERT(node->ptrs[pos]);
+	ASSERT(node->ptrs[pos] == victim);
+	kfree(victim);
+
+	nr_entries = fuse_iext_node_nr_entries(node, pos) - 1;
+	offset = node->keys[0];
+	for (i = pos; i < nr_entries; i++) {
+		node->keys[i] = node->keys[i + 1];
+		node->ptrs[i] = node->ptrs[i + 1];
+	}
+	node->keys[nr_entries] = FUSE_IEXT_KEY_INVALID;
+	node->ptrs[nr_entries] = NULL;
+
+	if (pos == 0 && nr_entries > 0) {
+		fuse_iext_update_node(ir, offset, node->keys[0], level, node);
+		offset = node->keys[0];
+	}
+
+	if (nr_entries >= KEYS_PER_NODE / 2)
+		return;
+
+	if (level < ir->ir_height) {
+		/*
+		 * If we aren't at the root yet try to find a neighbour node to
+		 * merge with (or delete the node if it is empty), and then
+		 * recurse up to the next level.
+		 */
+		level++;
+		parent = fuse_iext_find_level(ir, offset, level);
+		pos = fuse_iext_node_pos(parent, offset);
+
+		ASSERT(pos != KEYS_PER_NODE);
+		ASSERT(parent->ptrs[pos] == node);
+
+		node = fuse_iext_rebalance_node(parent, &pos, node, nr_entries);
+		if (node) {
+			victim = node;
+			node = parent;
+			goto again;
+		}
+	} else if (nr_entries == 1) {
+		/*
+		 * If we are at the root and only one entry is left we can just
+		 * free this node and update the root pointer.
+		 */
+		ASSERT(node == ir->ir_data);
+		ir->ir_data = node->ptrs[0];
+		ir->ir_height--;
+		kfree(node);
+	}
+}
+
+static void
+fuse_iext_rebalance_leaf(
+	struct fuse_iext_root	*ir,
+	struct fuse_iext_cursor	*cur,
+	struct fuse_iext_leaf	*leaf,
+	loff_t			offset,
+	int			nr_entries)
+{
+	/*
+	 * If the neighbouring nodes are completely full we might never be able
+	 * to merge our node, and will only delete it once the number of
+	 * entries hits zero.
+	 */
+	if (nr_entries == 0)
+		goto remove_node;
+
+	if (leaf->prev) {
+		int nr_prev = fuse_iext_leaf_nr_entries(ir, leaf->prev, 0), i;
+
+		if (nr_prev + nr_entries <= RECS_PER_LEAF) {
+			for (i = 0; i < nr_entries; i++)
+				leaf->prev->recs[nr_prev + i] = leaf->recs[i];
+
+			if (cur->leaf == leaf) {
+				cur->leaf = leaf->prev;
+				cur->pos += nr_prev;
+			}
+			goto remove_node;
+		}
+	}
+
+	if (leaf->next) {
+		int nr_next = fuse_iext_leaf_nr_entries(ir, leaf->next, 0), i;
+
+		if (nr_entries + nr_next <= RECS_PER_LEAF) {
+			/*
+			 * Merge the next node into this node so that we don't
+			 * have to do an additional update of the keys in the
+			 * higher levels.
+			 */
+			for (i = 0; i < nr_next; i++) {
+				leaf->recs[nr_entries + i] =
+					leaf->next->recs[i];
+			}
+
+			if (cur->leaf == leaf->next) {
+				cur->leaf = leaf;
+				cur->pos += nr_entries;
+			}
+
+			offset = fuse_iext_leaf_key(leaf->next, 0);
+			leaf = leaf->next;
+			goto remove_node;
+		}
+	}
+
+	return;
+remove_node:
+	if (leaf->prev)
+		leaf->prev->next = leaf->next;
+	if (leaf->next)
+		leaf->next->prev = leaf->prev;
+	fuse_iext_remove_node(ir, offset, leaf);
+}
+
+static void
+fuse_iext_free_last_leaf(
+	struct fuse_iext_root	*ir)
+{
+	ir->ir_height--;
+	kfree(ir->ir_data);
+	ir->ir_data = NULL;
+}
+
+static void
+fuse_iext_remove(
+	struct fuse_iomap_cache	*ic,
+	struct fuse_iext_cursor	*cur,
+	uint32_t		state)
+{
+	struct fuse_iext_root	*ir = fuse_iext_state_to_fork(ic, state);
+	struct fuse_iext_leaf	*leaf = cur->leaf;
+	loff_t			offset = fuse_iext_leaf_key(leaf, 0);
+	int			i, nr_entries;
+
+	ASSERT(ir->ir_height > 0);
+	ASSERT(ir->ir_data != NULL);
+	ASSERT(fuse_iext_valid(ir, cur));
+
+	fuse_iext_inc_seq(ic);
+
+	nr_entries = fuse_iext_leaf_nr_entries(ir, leaf, cur->pos) - 1;
+	for (i = cur->pos; i < nr_entries; i++)
+		leaf->recs[i] = leaf->recs[i + 1];
+	fuse_iext_rec_clear(&leaf->recs[nr_entries]);
+	ir->ir_bytes -= sizeof(struct fuse_iomap_io);
+
+	if (cur->pos == 0 && nr_entries > 0) {
+		fuse_iext_update_node(ir, offset, fuse_iext_leaf_key(leaf, 0), 1,
+				leaf);
+		offset = fuse_iext_leaf_key(leaf, 0);
+	} else if (cur->pos == nr_entries) {
+		if (ir->ir_height > 1 && leaf->next)
+			cur->leaf = leaf->next;
+		else
+			cur->leaf = NULL;
+		cur->pos = 0;
+	}
+
+	if (nr_entries >= RECS_PER_LEAF / 2)
+		return;
+
+	if (ir->ir_height > 1)
+		fuse_iext_rebalance_leaf(ir, cur, leaf, offset, nr_entries);
+	else if (nr_entries == 0)
+		fuse_iext_free_last_leaf(ir);
+}
+
+/*
+ * Lookup the extent covering offset.
+ *
+ * If there is an extent covering offset return the extent index, and store the
+ * expanded extent structure in *gotp, and the extent cursor in *cur.
+ * If there is no extent covering offset, but there is an extent after it (e.g.
+ * it lies in a hole) return that extent in *gotp and its cursor in *cur
+ * instead.
+ * If offset is beyond the last extent return false, and return an invalid
+ * cursor value.
+ */
+static bool
+fuse_iext_lookup_extent(
+	struct fuse_iomap_cache	*ic,
+	struct fuse_iext_root	*ir,
+	loff_t			offset,
+	struct fuse_iext_cursor	*cur,
+	struct fuse_iomap_io	*gotp)
+{
+	cur->leaf = fuse_iext_find_level(ir, offset, 1);
+	if (!cur->leaf) {
+		cur->pos = 0;
+		return false;
+	}
+
+	for (cur->pos = 0; cur->pos < fuse_iext_max_recs(ir); cur->pos++) {
+		struct fuse_iomap_io *rec = cur_rec(cur);
+
+		if (fuse_iext_rec_is_empty(rec))
+			break;
+		if (fuse_iext_rec_cmp(rec, offset) >= 0)
+			goto found;
+	}
+
+	/* Try looking in the next node for an entry > offset */
+	if (ir->ir_height == 1 || !cur->leaf->next)
+		return false;
+	cur->leaf = cur->leaf->next;
+	cur->pos = 0;
+	if (!fuse_iext_valid(ir, cur))
+		return false;
+found:
+	fuse_iext_get(gotp, cur_rec(cur));
+	return true;
+}
+
+/*
+ * Returns the last extent before end, and if this extent doesn't cover
+ * end, update end to the end of the extent.
+ */
+static bool
+fuse_iext_lookup_extent_before(
+	struct fuse_iomap_cache	*ic,
+	struct fuse_iext_root	*ir,
+	loff_t			*end,
+	struct fuse_iext_cursor	*cur,
+	struct fuse_iomap_io	*gotp)
+{
+	/* could be optimized to not even look up the next on a match.. */
+	if (fuse_iext_lookup_extent(ic, ir, *end - 1, cur, gotp) &&
+	    gotp->offset <= *end - 1)
+		return true;
+	if (!fuse_iext_prev_extent(ir, cur, gotp))
+		return false;
+	*end = gotp->offset + gotp->length;
+	return true;
+}
+
+static void
+fuse_iext_update_extent(
+	struct fuse_iomap_cache	*ic,
+	uint32_t		state,
+	struct fuse_iext_cursor	*cur,
+	struct fuse_iomap_io	*new)
+{
+	struct fuse_iext_root	*ir = fuse_iext_state_to_fork(ic, state);
+
+	fuse_iext_inc_seq(ic);
+
+	if (cur->pos == 0) {
+		struct fuse_iomap_io	old;
+
+		fuse_iext_get(&old, cur_rec(cur));
+		if (new->offset != old.offset) {
+			fuse_iext_update_node(ir, old.offset,
+					new->offset, 1, cur->leaf);
+		}
+	}
+
+	fuse_iext_set(cur_rec(cur), new);
+}
+
+/*
+ * This is a recursive function, because of that we need to be extremely
+ * careful with stack usage.
+ */
+static void
+fuse_iext_destroy_node(
+	struct fuse_iext_node	*node,
+	int			level)
+{
+	int			i;
+
+	if (level > 1) {
+		for (i = 0; i < KEYS_PER_NODE; i++) {
+			if (node->keys[i] == FUSE_IEXT_KEY_INVALID)
+				break;
+			fuse_iext_destroy_node(node->ptrs[i], level - 1);
+		}
+	}
+
+	kfree(node);
+}
+
+static void
+fuse_iext_destroy(
+	struct fuse_iext_root	*ir)
+{
+	fuse_iext_destroy_node(ir->ir_data, ir->ir_height);
+
+	ir->ir_bytes = 0;
+	ir->ir_height = 0;
+	ir->ir_data = NULL;
+}
+
+static inline struct fuse_iext_root *
+fuse_iext_root_ptr(
+	struct fuse_iomap_cache	*ic,
+	enum fuse_iomap_iodir	iodir)
+{
+	switch (iodir) {
+	case READ_MAPPING:
+		return &ic->ic_read;
+	case WRITE_MAPPING:
+		return &ic->ic_write;
+	default:
+		ASSERT(0);
+		return NULL;
+	}
+}
+
+static inline bool fuse_iomap_addrs_adjacent(const struct fuse_iomap_io *left,
+					     const struct fuse_iomap_io *right)
+{
+	switch (left->type) {
+	case FUSE_IOMAP_TYPE_MAPPED:
+	case FUSE_IOMAP_TYPE_UNWRITTEN:
+		return left->addr + left->length == right->addr;
+	default:
+		return left->addr  == FUSE_IOMAP_NULL_ADDR &&
+		       right->addr == FUSE_IOMAP_NULL_ADDR;
+	}
+}
+
+static inline bool fuse_iomap_can_merge(const struct fuse_iomap_io *left,
+					const struct fuse_iomap_io *right)
+{
+	return (left->dev == right->dev &&
+		left->offset + left->length == right->offset &&
+		left->type  == right->type &&
+		fuse_iomap_addrs_adjacent(left, right) &&
+		left->flags == right->flags &&
+		left->length + right->length <= FUSE_IOMAP_MAX_LEN);
+}
+
+static inline bool fuse_iomap_can_merge3(const struct fuse_iomap_io *left,
+					 const struct fuse_iomap_io *new,
+					 const struct fuse_iomap_io *right)
+{
+	return left->length + new->length + right->length <= FUSE_IOMAP_MAX_LEN;
+}
+
+#if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG)
+static void fuse_iext_check_mappings(struct fuse_iomap_cache *ic,
+				     struct fuse_iext_root *ir)
+{
+	struct fuse_iext_cursor	icur;
+	struct fuse_iomap_io	prev, got;
+	struct inode		*inode = ic->ic_inode;
+	struct fuse_inode	*fi = get_fuse_inode(inode);
+	unsigned long long	nr = 0;
+
+	if (ir->ir_bytes < 0 || !static_branch_unlikely(&fuse_iomap_debug))
+		return;
+
+	fuse_iext_first(ir, &icur);
+	if (!fuse_iext_get_extent(ir, &icur, &prev))
+		return;
+	nr++;
+
+	fuse_iext_next(ir, &icur);
+	while (fuse_iext_get_extent(ir, &icur, &got)) {
+		if (got.length == 0 ||
+		    got.offset < prev.offset + prev.length ||
+		    fuse_iomap_can_merge(&prev, &got)) {
+			printk(KERN_ERR "FUSE IOMAP CORRUPTION ino=%llu nr=%llu",
+			       fi->orig_ino, nr);
+			printk(KERN_ERR "prev: offset=%llu length=%llu type=%u flags=0x%x dev=%u addr=%llu\n",
+			       prev.offset, prev.length, prev.type, prev.flags,
+			       prev.dev, prev.addr);
+			printk(KERN_ERR "curr: offset=%llu length=%llu type=%u flags=0x%x dev=%u addr=%llu\n",
+			       got.offset, got.length, got.type, got.flags,
+			       got.dev, got.addr);
+		}
+
+		prev = got;
+		nr++;
+		fuse_iext_next(ir, &icur);
+	}
+}
+#else
+# define fuse_iext_check_mappings(...)	((void)0)
+#endif
+
+static void
+fuse_iext_del_mapping(
+	struct fuse_iomap_cache	*ic,
+	struct fuse_iext_root	*ir,
+	struct fuse_iext_cursor	*icur,
+	struct fuse_iomap_io	*got,	/* current extent entry */
+	struct fuse_iomap_io	*del)	/* data to remove from extents */
+{
+	struct fuse_iomap_io	new;	/* new record to be inserted */
+	/* first addr (fsblock aligned) past del */
+	fuse_iext_key_t		del_endaddr;
+	/* first offset (fsblock aligned) past del */
+	fuse_iext_key_t		del_endoff = del->offset + del->length;
+	/* first offset (fsblock aligned) past got */
+	fuse_iext_key_t		got_endoff = got->offset + got->length;
+	uint32_t		state = fuse_iomap_fork_to_state(ic, ir);
+
+	ASSERT(del->length > 0);
+	ASSERT(got->offset <= del->offset);
+	ASSERT(got_endoff >= del_endoff);
+
+	switch (del->type) {
+	case FUSE_IOMAP_TYPE_MAPPED:
+	case FUSE_IOMAP_TYPE_UNWRITTEN:
+		del_endaddr = del->addr + del->length;
+		break;
+	default:
+		del_endaddr = FUSE_IOMAP_NULL_ADDR;
+		break;
+	}
+
+	if (got->offset == del->offset)
+		state |= FUSE_IEXT_LEFT_FILLING;
+	if (got_endoff == del_endoff)
+		state |= FUSE_IEXT_RIGHT_FILLING;
+
+	switch (state & (FUSE_IEXT_LEFT_FILLING | FUSE_IEXT_RIGHT_FILLING)) {
+	case FUSE_IEXT_LEFT_FILLING | FUSE_IEXT_RIGHT_FILLING:
+		/*
+		 * Matches the whole extent.  Delete the entry.
+		 */
+		fuse_iext_remove(ic, icur, state);
+		fuse_iext_prev(ir, icur);
+		break;
+	case FUSE_IEXT_LEFT_FILLING:
+		/*
+		 * Deleting the first part of the extent.
+		 */
+		got->offset = del_endoff;
+		got->addr = del_endaddr;
+		got->length -= del->length;
+		fuse_iext_update_extent(ic, state, icur, got);
+		break;
+	case FUSE_IEXT_RIGHT_FILLING:
+		/*
+		 * Deleting the last part of the extent.
+		 */
+		got->length -= del->length;
+		fuse_iext_update_extent(ic, state, icur, got);
+		break;
+	case 0:
+		/*
+		 * Deleting the middle of the extent.
+		 */
+		got->length = del->offset - got->offset;
+		fuse_iext_update_extent(ic, state, icur, got);
+
+		new.offset = del_endoff;
+		new.length = got_endoff - del_endoff;
+		new.type = got->type;
+		new.flags = got->flags;
+		new.addr = del_endaddr;
+		new.dev = got->dev;
+
+		fuse_iext_next(ir, icur);
+		fuse_iext_insert(ic, icur, &new, state);
+		break;
+	}
+}
+
+int
+fuse_iomap_cache_remove(
+	struct inode		*inode,
+	enum fuse_iomap_iodir	iodir,
+	loff_t			start,		/* first file offset deleted */
+	uint64_t		len)		/* length to unmap */
+{
+	struct fuse_iext_cursor	icur;
+	struct fuse_iomap_io	got;		/* current extent record */
+	struct fuse_iomap_io	del;		/* extent being deleted */
+	loff_t			end;
+	struct fuse_inode	*fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache	*ic = fi->cache;
+	struct fuse_iext_root	*ir = fuse_iext_root_ptr(ic, iodir);
+	bool			wasreal;
+	bool			done = false;
+	int			ret = 0;
+
+	assert_cache_locked(ic);
+
+	/* Fork is not active or has zero mappings */
+	if (ir->ir_bytes < 0 || fuse_iext_count(ir) == 0)
+		return 0;
+
+	/* Fast shortcut if the caller wants to erase everything */
+	if (start == 0 && len >= inode->i_sb->s_maxbytes) {
+		fuse_iext_destroy(ir);
+		return 0;
+	}
+
+	if (!len)
+		goto out;
+
+	/*
+	 * If the caller wants us to remove everything to EOF, we set the end
+	 * of the removal range to the maximum file offset.  We don't support
+	 * unsigned file offsets.
+	 */
+	if (len == FUSE_IOMAP_INVAL_TO_EOF) {
+		const unsigned int blocksize = i_blocksize(&fi->inode);
+
+		len = round_up(inode->i_sb->s_maxbytes, blocksize) - start;
+	}
+
+	/*
+	 * Now that we've settled len, look up the extent before the end of the
+	 * range.
+	 */
+	end = start + len;
+	if (!fuse_iext_lookup_extent_before(ic, ir, &end, &icur, &got))
+		goto out;
+	end--;
+
+	while (end != -1 && end >= start) {
+		/*
+		 * Is the found extent after a hole in which end lives?
+		 * Just back up to the previous extent, if so.
+		 */
+		if (got.offset > end &&
+		    !fuse_iext_prev_extent(ir, &icur, &got)) {
+			done = true;
+			break;
+		}
+		/*
+		 * Is the last block of this extent before the range
+		 * we're supposed to delete?  If so, we're done.
+		 */
+		end = min_t(loff_t, end, got.offset + got.length - 1);
+		if (end < start)
+			break;
+		/*
+		 * Then deal with the (possibly delayed) allocated space
+		 * we found.
+		 */
+		del = got;
+		switch (del.type) {
+		case FUSE_IOMAP_TYPE_DELALLOC:
+		case FUSE_IOMAP_TYPE_HOLE:
+		case FUSE_IOMAP_TYPE_INLINE:
+		case FUSE_IOMAP_TYPE_PURE_OVERWRITE:
+			wasreal = false;
+			break;
+		case FUSE_IOMAP_TYPE_MAPPED:
+		case FUSE_IOMAP_TYPE_UNWRITTEN:
+			wasreal = true;
+			break;
+		default:
+			ASSERT(0);
+			ret = -EFSCORRUPTED;
+			goto out;
+		}
+
+		if (got.offset < start) {
+			del.offset = start;
+			del.length -= start - got.offset;
+			if (wasreal)
+				del.addr += start - got.offset;
+		}
+		if (del.offset + del.length > end + 1)
+			del.length = end + 1 - del.offset;
+
+		fuse_iext_del_mapping(ic, ir, &icur, &got, &del);
+		end = del.offset - 1;
+
+		/*
+		 * If not done go on to the next (previous) record.
+		 */
+		if (end != -1 && end >= start) {
+			if (!fuse_iext_get_extent(ir, &icur, &got) ||
+			    (got.offset > end &&
+			     !fuse_iext_prev_extent(ir, &icur, &got))) {
+				done = true;
+				break;
+			}
+		}
+	}
+
+	/* Should have removed everything */
+	if (len == 0 || done || end == (loff_t)-1 || end < start)
+		ret = 0;
+	else
+		ret = -EFSCORRUPTED;
+
+out:
+	fuse_iext_check_mappings(ic, ir);
+	return ret;
+}
+
+static void
+fuse_iext_add_mapping(
+	struct fuse_iomap_cache		*ic,
+	struct fuse_iext_root		*ir,
+	struct fuse_iext_cursor		*icur,
+	const struct fuse_iomap_io	*new)	/* new extent entry */
+{
+	struct fuse_iomap_io		left;	/* left neighbor extent entry */
+	struct fuse_iomap_io		right;	/* right neighbor extent entry */
+	uint32_t			state = fuse_iomap_fork_to_state(ic, ir);
+
+	/*
+	 * Check and set flags if this segment has a left neighbor.
+	 */
+	if (fuse_iext_peek_prev_extent(ir, icur, &left))
+		state |= FUSE_IEXT_LEFT_VALID;
+
+	/*
+	 * Check and set flags if this segment has a current value.
+	 * Not true if we're inserting into the "hole" at eof.
+	 */
+	if (fuse_iext_get_extent(ir, icur, &right))
+		state |= FUSE_IEXT_RIGHT_VALID;
+
+	/*
+	 * We're inserting a real allocation between "left" and "right".
+	 * Set the contiguity flags.  Don't let extents get too large.
+	 */
+	if ((state & FUSE_IEXT_LEFT_VALID) && fuse_iomap_can_merge(&left, new))
+		state |= FUSE_IEXT_LEFT_CONTIG;
+
+	if ((state & FUSE_IEXT_RIGHT_VALID) &&
+	    fuse_iomap_can_merge(new, &right) &&
+	    (!(state & FUSE_IEXT_LEFT_CONTIG) ||
+	     fuse_iomap_can_merge3(&left, new, &right)))
+		state |= FUSE_IEXT_RIGHT_CONTIG;
+
+	/*
+	 * Select which case we're in here, and implement it.
+	 */
+	switch (state & (FUSE_IEXT_LEFT_CONTIG | FUSE_IEXT_RIGHT_CONTIG)) {
+	case FUSE_IEXT_LEFT_CONTIG | FUSE_IEXT_RIGHT_CONTIG:
+		/*
+		 * New allocation is contiguous with real allocations on the
+		 * left and on the right.
+		 * Merge all three into a single extent record.
+		 */
+		left.length += new->length + right.length;
+
+		fuse_iext_remove(ic, icur, state);
+		fuse_iext_prev(ir, icur);
+		fuse_iext_update_extent(ic, state, icur, &left);
+		break;
+
+	case FUSE_IEXT_LEFT_CONTIG:
+		/*
+		 * New allocation is contiguous with a real allocation
+		 * on the left.
+		 * Merge the new allocation with the left neighbor.
+		 */
+		left.length += new->length;
+
+		fuse_iext_prev(ir, icur);
+		fuse_iext_update_extent(ic, state, icur, &left);
+		break;
+
+	case FUSE_IEXT_RIGHT_CONTIG:
+		/*
+		 * New allocation is contiguous with a real allocation
+		 * on the right.
+		 * Merge the new allocation with the right neighbor.
+		 */
+		right.offset = new->offset;
+		right.addr = new->addr;
+		right.length += new->length;
+		fuse_iext_update_extent(ic, state, icur, &right);
+		break;
+
+	case 0:
+		/*
+		 * New allocation is not contiguous with another
+		 * real allocation.
+		 * Insert a new entry.
+		 */
+		fuse_iext_insert(ic, icur, new, state);
+		break;
+	}
+}
+
+static int
+fuse_iomap_cache_add(
+	struct inode			*inode,
+	enum fuse_iomap_iodir		iodir,
+	const struct fuse_iomap_io	*new)
+{
+	struct fuse_iext_cursor		icur;
+	struct fuse_iomap_io		got;
+	struct fuse_inode		*fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache		*ic = fi->cache;
+	struct fuse_iext_root		*ir = fuse_iext_root_ptr(ic, iodir);
+
+	assert_cache_locked(ic);
+	ASSERT(new->length > 0);
+	ASSERT(new->offset < inode->i_sb->s_maxbytes);
+
+	/* Mark this fork as being in use */
+	if (ir->ir_bytes < 0)
+		ir->ir_bytes = 0;
+
+	if (fuse_iext_lookup_extent(ic, ir, new->offset, &icur, &got)) {
+		/* make sure we only add into a hole. */
+		ASSERT(got.offset > new->offset);
+		ASSERT(got.offset - new->offset >= new->length);
+
+		if (got.offset <= new->offset ||
+		    got.offset - new->offset < new->length)
+			return -EFSCORRUPTED;
+	}
+
+	fuse_iext_add_mapping(ic, ir, &icur, new);
+	fuse_iext_check_mappings(ic, ir);
+	return 0;
+}
+
+int fuse_iomap_cache_alloc(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache *old = NULL;
+	struct fuse_iomap_cache *ic;
+
+	ic = kzalloc_obj(struct fuse_iomap_cache);
+	if (!ic)
+		return -ENOMEM;
+
+	/* Only the write mapping cache can return NOFORK */
+	ic->ic_write.ir_bytes = -1;
+	ic->ic_inode = inode;
+	init_rwsem(&ic->ic_lock);
+
+	if (!try_cmpxchg(&fi->cache, &old, ic)) {
+		/* Someone created mapping cache before us? Free ours... */
+		kfree(ic);
+	}
+
+	return 0;
+}
+
+static void fuse_iomap_cache_purge(struct fuse_iomap_cache *ic)
+{
+	fuse_iext_destroy(&ic->ic_read);
+	fuse_iext_destroy(&ic->ic_write);
+}
+
+void fuse_iomap_cache_free(struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache *ic = fi->cache;
+
+	/*
+	 * This is only called from eviction, so we cannot be racing to set or
+	 * clear the pointer.
+	 */
+	fi->cache = NULL;
+
+	fuse_iomap_cache_purge(ic);
+	kfree(ic);
+}
+
+int
+fuse_iomap_cache_upsert(
+	struct inode			*inode,
+	enum fuse_iomap_iodir		iodir,
+	const struct fuse_iomap_io	*map)
+{
+	struct fuse_inode		*fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache		*ic = fi->cache;
+	int				err;
+
+	ASSERT(fuse_inode_caches_iomaps(inode));
+
+	/*
+	 * We interpret no write fork to mean that all writes are pure
+	 * overwrites.  Avoid wasting memory if we're trying to upsert a
+	 * pure overwrite.
+	 */
+	if (iodir == WRITE_MAPPING &&
+	    map->type == FUSE_IOMAP_TYPE_PURE_OVERWRITE &&
+	    ic->ic_write.ir_bytes < 0)
+		return 0;
+
+	err = fuse_iomap_cache_remove(inode, iodir, map->offset, map->length);
+	if (err)
+		return err;
+
+	return fuse_iomap_cache_add(inode, iodir, map);
+}
+
+/*
+ * Trim the returned map to the required bounds
+ */
+static void
+fuse_iomap_trim(
+	struct fuse_inode		*fi,
+	struct fuse_iomap_lookup	*mval,
+	const struct fuse_iomap_io	*got,
+	loff_t				off,
+	loff_t				len)
+{
+	struct fuse_iomap_cache		*ic = fi->cache;
+	const unsigned int blocksize = i_blocksize(&fi->inode);
+	const loff_t aligned_off = round_down(off, blocksize);
+	const loff_t aligned_end = round_up(off + len, blocksize);
+	const loff_t aligned_len = aligned_end - aligned_off;
+
+	ASSERT(aligned_off >= got->offset);
+
+	switch (got->type) {
+	case FUSE_IOMAP_TYPE_MAPPED:
+	case FUSE_IOMAP_TYPE_UNWRITTEN:
+		mval->map.addr = got->addr + (aligned_off - got->offset);
+		break;
+	default:
+		mval->map.addr = FUSE_IOMAP_NULL_ADDR;
+		break;
+	}
+	mval->map.offset = aligned_off;
+	mval->map.length = min_t(loff_t, aligned_len,
+				 got->length - (aligned_off - got->offset));
+	mval->map.type = got->type;
+	mval->map.flags = got->flags;
+	mval->map.dev = got->dev;
+	mval->validity_cookie = fuse_iext_read_seq(ic);
+}
+
+enum fuse_iomap_lookup_result
+fuse_iomap_cache_lookup(
+	struct inode			*inode,
+	enum fuse_iomap_iodir		iodir,
+	loff_t				off,
+	uint64_t			len,
+	struct fuse_iomap_lookup	*mval)
+{
+	struct fuse_iomap_io		got;
+	struct fuse_iext_cursor		icur;
+	struct fuse_inode		*fi = get_fuse_inode(inode);
+	struct fuse_iomap_cache		*ic = fi->cache;
+	struct fuse_iext_root		*ir = fuse_iext_root_ptr(ic, iodir);
+
+	assert_cache_locked_shared(ic);
+
+	if (ir->ir_bytes < 0) {
+		/*
+		 * No write fork at all means this filesystem doesn't do out of
+		 * place writes.
+		 */
+		return LOOKUP_NOFORK;
+	}
+
+	if (!fuse_iext_lookup_extent(ic, ir, off, &icur, &got)) {
+		/*
+		 * Does not contain a mapping at or beyond off, which is a
+		 * cache miss.
+		 */
+		return LOOKUP_MISS;
+	}
+
+	if (got.offset > off) {
+		/*
+		 * Found a mapping, but it doesn't cover the start of the
+		 * range, which is effectively a miss.
+		 */
+		return LOOKUP_MISS;
+	}
+
+	/* Found a mapping in the cache, return it */
+	fuse_iomap_trim(fi, mval, &got, off, len);
+	return LOOKUP_HIT;
+}
diff --git a/fs/fuse/trace.c b/fs/fuse/trace.c
index 71d444ac1e5021..69310d6f773ffa 100644
--- a/fs/fuse/trace.c
+++ b/fs/fuse/trace.c
@@ -8,6 +8,7 @@
 #include "fuse_dev_i.h"
 #include "fuse_iomap.h"
 #include "fuse_iomap_i.h"
+#include "fuse_iomap_cache.h"
 
 #include <linux/pagemap.h>
 #include <linux/iomap.h>


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 02/12] fuse_trace: cache iomaps
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
  2026-02-23 23:20   ` [PATCH 01/12] fuse: cache iomaps Darrick J. Wong
@ 2026-02-23 23:20   ` Darrick J. Wong
  2026-02-23 23:21   ` [PATCH 03/12] fuse: use the iomap cache for iomap_begin Darrick J. Wong
                     ` (9 subsequent siblings)
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:20 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h       |  293 ++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap_cache.c |   36 +++++
 2 files changed, 329 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index a6374d64a62357..697289c82d0dad 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -318,6 +318,8 @@ DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
 struct iomap_writepage_ctx;
 struct iomap_ioend;
 struct iomap;
+struct fuse_iext_cursor;
+struct fuse_iomap_lookup;
 
 /* tracepoint boilerplate so we don't have to keep doing this */
 #define FUSE_IOMAP_OPFLAGS_FIELD \
@@ -348,6 +350,16 @@ struct iomap;
 		__entry->prefix##addr, \
 		__print_flags(__entry->prefix##flags, "|", FUSE_IOMAP_F_STRINGS)
 
+#define FUSE_IOMAP_IODIR_FIELD \
+		__field(unsigned int,	iodir)
+
+#define FUSE_IOMAP_IODIR_FMT \
+		 " iodir %s"
+
+#define FUSE_IOMAP_IODIR_PRINTK_ARGS \
+		  __print_symbolic(__entry->iodir, FUSE_IOMAP_FORK_STRINGS)
+
+
 /* combinations of boilerplate to reduce typing further */
 #define FUSE_IOMAP_OP_FIELDS(prefix) \
 		FUSE_INODE_FIELDS \
@@ -445,6 +457,22 @@ TRACE_DEFINE_ENUM(FUSE_I_ATOMIC);
 	{ FUSE_IOMAP_CONFIG_TIME,		"time" }, \
 	{ FUSE_IOMAP_CONFIG_MAXBYTES,		"maxbytes" }
 
+TRACE_DEFINE_ENUM(READ_MAPPING);
+TRACE_DEFINE_ENUM(WRITE_MAPPING);
+
+#define FUSE_IOMAP_FORK_STRINGS \
+	{ READ_MAPPING,				"read" }, \
+	{ WRITE_MAPPING,			"write" }
+
+#define FUSE_IEXT_STATE_STRINGS \
+	{ FUSE_IEXT_LEFT_CONTIG,		"l_cont" }, \
+	{ FUSE_IEXT_RIGHT_CONTIG,		"r_cont" }, \
+	{ FUSE_IEXT_LEFT_FILLING,		"l_fill" }, \
+	{ FUSE_IEXT_RIGHT_FILLING,		"r_fill" }, \
+	{ FUSE_IEXT_LEFT_VALID,			"l_valid" }, \
+	{ FUSE_IEXT_RIGHT_VALID,		"r_valid" }, \
+	{ FUSE_IEXT_WRITE_MAPPING,		"write" }
+
 DECLARE_EVENT_CLASS(fuse_iomap_check_class,
 	TP_PROTO(const char *func, int line, const char *condition),
 
@@ -727,6 +755,8 @@ DEFINE_EVENT(fuse_inode_state_class, name,	\
 	TP_ARGS(inode))
 DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_init_inode);
 DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_evict_inode);
+DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_cache_alloc);
+DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_cache_free);
 
 TRACE_EVENT(fuse_iomap_fiemap,
 	TP_PROTO(const struct inode *inode, u64 start, u64 count,
@@ -1216,6 +1246,269 @@ DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_inline_read);
 DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_inline_write);
 DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_set_inline_iomap);
 DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_set_inline_srcmap);
+
+DECLARE_EVENT_CLASS(fuse_iext_class,
+	TP_PROTO(const struct inode *inode, const struct fuse_iext_cursor *cur,
+		 int state, unsigned long caller_ip),
+
+	TP_ARGS(inode, cur, state, caller_ip),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		FUSE_IOMAP_MAP_FIELDS(map)
+		__field(void *,			leaf)
+		__field(int,			pos)
+		__field(int,			iext_state)
+		__field(unsigned long,		caller_ip)
+	),
+	TP_fast_assign(
+		const struct fuse_iext_root *ir;
+		struct fuse_iomap_io r = { };
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+
+		if (state & FUSE_IEXT_WRITE_MAPPING)
+			ir = &fi->cache->ic_write;
+		else
+			ir = &fi->cache->ic_read;
+		if (ir)
+			fuse_iext_get_extent(ir, cur, &r);
+
+		__entry->mapoffset	=	r.offset;
+		__entry->mapaddr	=	r.addr;
+		__entry->maplength	=	r.length;
+		__entry->mapdev		=	r.dev;
+		__entry->maptype	=	r.type;
+		__entry->mapflags	=	r.flags;
+
+		__entry->leaf		=	cur->leaf;
+		__entry->pos		=	cur->pos;
+
+		__entry->iext_state	=	state;
+		__entry->caller_ip	=	caller_ip;
+	),
+	TP_printk(FUSE_INODE_FMT " state (%s) cur %p/%d " FUSE_IOMAP_MAP_FMT() " caller %pS",
+		  FUSE_INODE_PRINTK_ARGS,
+		  __print_flags(__entry->iext_state, "|", FUSE_IEXT_STATE_STRINGS),
+		  __entry->leaf,
+		  __entry->pos,
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(map),
+		  (void *)__entry->caller_ip)
+)
+
+#define DEFINE_IEXT_EVENT(name) \
+DEFINE_EVENT(fuse_iext_class, name, \
+	TP_PROTO(const struct inode *inode, const struct fuse_iext_cursor *cur, \
+		 int state, unsigned long caller_ip), \
+	TP_ARGS(inode, cur, state, caller_ip))
+DEFINE_IEXT_EVENT(fuse_iext_insert);
+DEFINE_IEXT_EVENT(fuse_iext_remove);
+DEFINE_IEXT_EVENT(fuse_iext_pre_update);
+DEFINE_IEXT_EVENT(fuse_iext_post_update);
+
+TRACE_EVENT(fuse_iext_update_class,
+	TP_PROTO(const struct inode *inode, uint32_t iext_state,
+		 const struct fuse_iomap_io *map),
+	TP_ARGS(inode, iext_state, map),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		FUSE_IOMAP_MAP_FIELDS(map)
+		__field(uint32_t,		iext_state)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->mapoffset	=	map->offset;
+		__entry->maplength	=	map->length;
+		__entry->maptype	=	map->type;
+		__entry->mapflags	=	map->flags;
+		__entry->mapdev		=	map->dev;
+		__entry->mapaddr	=	map->addr;
+
+		__entry->iext_state	=	iext_state;
+	),
+
+	TP_printk(FUSE_INODE_FMT " state (%s)" FUSE_IOMAP_MAP_FMT(),
+		  FUSE_INODE_PRINTK_ARGS,
+		  __print_flags(__entry->iext_state, "|", FUSE_IEXT_STATE_STRINGS),
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(map))
+);
+#define DEFINE_IEXT_UPDATE_EVENT(name) \
+DEFINE_EVENT(fuse_iext_update_class, name, \
+	TP_PROTO(const struct inode *inode, uint32_t iext_state, \
+		 const struct fuse_iomap_io *map), \
+	TP_ARGS(inode, iext_state, map))
+DEFINE_IEXT_UPDATE_EVENT(fuse_iext_del_mapping);
+DEFINE_IEXT_UPDATE_EVENT(fuse_iext_add_mapping);
+
+TRACE_EVENT(fuse_iext_alt_update_class,
+	TP_PROTO(const struct inode *inode, const struct fuse_iomap_io *map),
+	TP_ARGS(inode, map),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		FUSE_IOMAP_MAP_FIELDS(map)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+
+		__entry->mapoffset	=	map->offset;
+		__entry->maplength	=	map->length;
+		__entry->maptype	=	map->type;
+		__entry->mapflags	=	map->flags;
+		__entry->mapdev		=	map->dev;
+		__entry->mapaddr	=	map->addr;
+	),
+
+	TP_printk(FUSE_INODE_FMT FUSE_IOMAP_MAP_FMT(),
+		  FUSE_INODE_PRINTK_ARGS,
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(map))
+);
+#define DEFINE_IEXT_ALT_UPDATE_EVENT(name) \
+DEFINE_EVENT(fuse_iext_alt_update_class, name, \
+	TP_PROTO(const struct inode *inode, const struct fuse_iomap_io *map), \
+	TP_ARGS(inode, map))
+DEFINE_IEXT_ALT_UPDATE_EVENT(fuse_iext_del_mapping_got);
+DEFINE_IEXT_ALT_UPDATE_EVENT(fuse_iext_add_mapping_left);
+DEFINE_IEXT_ALT_UPDATE_EVENT(fuse_iext_add_mapping_right);
+
+TRACE_EVENT(fuse_iomap_cache_remove,
+	TP_PROTO(const struct inode *inode, unsigned int iodir,
+		 loff_t offset, uint64_t length, unsigned long caller_ip),
+	TP_ARGS(inode, iodir, offset, length, caller_ip),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		FUSE_IOMAP_IODIR_FIELD
+		__field(unsigned long,		caller_ip)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->iodir		=	iodir;
+		__entry->offset		=	offset;
+		__entry->length		=	length;
+		__entry->caller_ip	=	caller_ip;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() FUSE_IOMAP_IODIR_FMT " caller %pS",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  FUSE_IOMAP_IODIR_PRINTK_ARGS,
+		  (void *)__entry->caller_ip)
+);
+
+TRACE_EVENT(fuse_iomap_cached_mapping_class,
+	TP_PROTO(const struct inode *inode, unsigned int iodir,
+		 const struct fuse_iomap_io *map, unsigned long caller_ip),
+	TP_ARGS(inode, iodir, map, caller_ip),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		FUSE_IOMAP_IODIR_FIELD
+		FUSE_IOMAP_MAP_FIELDS(map)
+		__field(unsigned long,		caller_ip)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->iodir		=	iodir;
+
+		__entry->mapoffset	=	map->offset;
+		__entry->maplength	=	map->length;
+		__entry->maptype	=	map->type;
+		__entry->mapflags	=	map->flags;
+		__entry->mapdev		=	map->dev;
+		__entry->mapaddr	=	map->addr;
+
+		__entry->caller_ip	=	caller_ip;
+	),
+
+	TP_printk(FUSE_INODE_FMT FUSE_IOMAP_IODIR_FMT FUSE_IOMAP_MAP_FMT() " caller %pS",
+		  FUSE_INODE_PRINTK_ARGS,
+		  FUSE_IOMAP_IODIR_PRINTK_ARGS,
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(map),
+		  (void *)__entry->caller_ip)
+);
+#define DEFINE_FUSE_IOMAP_CACHED_MAPPING_EVENT(name) \
+DEFINE_EVENT(fuse_iomap_cached_mapping_class, name, \
+	TP_PROTO(const struct inode *inode, unsigned int iodir, \
+		 const struct fuse_iomap_io *map, unsigned long caller_ip), \
+	TP_ARGS(inode, iodir, map, caller_ip))
+DEFINE_FUSE_IOMAP_CACHED_MAPPING_EVENT(fuse_iomap_cache_add);
+DEFINE_FUSE_IOMAP_CACHED_MAPPING_EVENT(fuse_iext_check_mapping);
+
+TRACE_EVENT(fuse_iomap_cache_lookup,
+	TP_PROTO(const struct inode *inode, unsigned int iodir,
+		 loff_t pos, uint64_t count, unsigned long caller_ip),
+	TP_ARGS(inode, iodir, pos, count, caller_ip),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		FUSE_IOMAP_IODIR_FIELD
+		__field(unsigned long,		caller_ip)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->iodir		=	iodir;
+		__entry->offset		=	pos;
+		__entry->length		=	count;
+		__entry->caller_ip	=	caller_ip;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() FUSE_IOMAP_IODIR_FMT " caller %pS",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  FUSE_IOMAP_IODIR_PRINTK_ARGS,
+		  (void *)__entry->caller_ip)
+);
+
+TRACE_EVENT(fuse_iomap_cache_lookup_result,
+	TP_PROTO(const struct inode *inode, unsigned int iodir,
+		 loff_t pos, uint64_t count, const struct fuse_iomap_io *got,
+		 const struct fuse_iomap_lookup *map),
+	TP_ARGS(inode, iodir, pos, count, got, map),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+
+		FUSE_IOMAP_MAP_FIELDS(got)
+		FUSE_IOMAP_MAP_FIELDS(map)
+
+		FUSE_IOMAP_IODIR_FIELD
+		__field(uint64_t,		validity_cookie)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->iodir		=	iodir;
+		__entry->offset		=	pos;
+		__entry->length		=	count;
+
+		__entry->gotoffset	=	got->offset;
+		__entry->gotlength	=	got->length;
+		__entry->gottype	=	got->type;
+		__entry->gotflags	=	got->flags;
+		__entry->gotdev		=	got->dev;
+		__entry->gotaddr	=	got->addr;
+
+		__entry->mapoffset	=	map->map.offset;
+		__entry->maplength	=	map->map.length;
+		__entry->maptype	=	map->map.type;
+		__entry->mapflags	=	map->map.flags;
+		__entry->mapdev		=	map->map.dev;
+		__entry->mapaddr	=	map->map.addr;
+
+		__entry->validity_cookie=	map->validity_cookie;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() FUSE_IOMAP_IODIR_FMT FUSE_IOMAP_MAP_FMT("map") FUSE_IOMAP_MAP_FMT("got") " cookie 0x%llx",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  FUSE_IOMAP_IODIR_PRINTK_ARGS,
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(map),
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(got),
+		  __entry->validity_cookie)
+);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap_cache.c b/fs/fuse/fuse_iomap_cache.c
index e32de8a5e3c325..a047d7bf95257a 100644
--- a/fs/fuse/fuse_iomap_cache.c
+++ b/fs/fuse/fuse_iomap_cache.c
@@ -763,6 +763,7 @@ fuse_iext_insert(
 	struct fuse_iext_root		*ir = fuse_iext_state_to_fork(ic, state);
 
 	fuse_iext_insert_raw(ic, ir, cur, irec);
+	trace_fuse_iext_insert(ic->ic_inode, cur, state, _RET_IP_);
 }
 
 static struct fuse_iext_node *
@@ -970,6 +971,8 @@ fuse_iext_remove(
 	ASSERT(ir->ir_data != NULL);
 	ASSERT(fuse_iext_valid(ir, cur));
 
+	trace_fuse_iext_remove(ic->ic_inode, cur, state, _RET_IP_);
+
 	fuse_iext_inc_seq(ic);
 
 	nr_entries = fuse_iext_leaf_nr_entries(ir, leaf, cur->pos) - 1;
@@ -1088,7 +1091,9 @@ fuse_iext_update_extent(
 		}
 	}
 
+	trace_fuse_iext_pre_update(ic->ic_inode, cur, state, _RET_IP_);
 	fuse_iext_set(cur_rec(cur), new);
+	trace_fuse_iext_post_update(ic->ic_inode, cur, state, _RET_IP_);
 }
 
 /*
@@ -1180,17 +1185,26 @@ static void fuse_iext_check_mappings(struct fuse_iomap_cache *ic,
 	struct inode		*inode = ic->ic_inode;
 	struct fuse_inode	*fi = get_fuse_inode(inode);
 	unsigned long long	nr = 0;
+	enum fuse_iomap_iodir	iodir;
 
 	if (ir->ir_bytes < 0 || !static_branch_unlikely(&fuse_iomap_debug))
 		return;
 
+	if (ir == &ic->ic_write)
+		iodir = WRITE_MAPPING;
+	else
+		iodir = READ_MAPPING;
+
 	fuse_iext_first(ir, &icur);
 	if (!fuse_iext_get_extent(ir, &icur, &prev))
 		return;
+	trace_fuse_iext_check_mapping(ic->ic_inode, iodir, &prev, _RET_IP_);
 	nr++;
 
 	fuse_iext_next(ir, &icur);
 	while (fuse_iext_get_extent(ir, &icur, &got)) {
+		trace_fuse_iext_check_mapping(ic->ic_inode, iodir, &got,
+					      _RET_IP_);
 		if (got.length == 0 ||
 		    got.offset < prev.offset + prev.length ||
 		    fuse_iomap_can_merge(&prev, &got)) {
@@ -1249,6 +1263,9 @@ fuse_iext_del_mapping(
 	if (got_endoff == del_endoff)
 		state |= FUSE_IEXT_RIGHT_FILLING;
 
+	trace_fuse_iext_del_mapping(ic->ic_inode, state, del);
+	trace_fuse_iext_del_mapping_got(ic->ic_inode, got);
+
 	switch (state & (FUSE_IEXT_LEFT_FILLING | FUSE_IEXT_RIGHT_FILLING)) {
 	case FUSE_IEXT_LEFT_FILLING | FUSE_IEXT_RIGHT_FILLING:
 		/*
@@ -1313,6 +1330,8 @@ fuse_iomap_cache_remove(
 
 	assert_cache_locked(ic);
 
+	trace_fuse_iomap_cache_remove(&fi->inode, iodir, start, len, _RET_IP_);
+
 	/* Fork is not active or has zero mappings */
 	if (ir->ir_bytes < 0 || fuse_iext_count(ir) == 0)
 		return 0;
@@ -1458,6 +1477,12 @@ fuse_iext_add_mapping(
 	     fuse_iomap_can_merge3(&left, new, &right)))
 		state |= FUSE_IEXT_RIGHT_CONTIG;
 
+	trace_fuse_iext_add_mapping(ic->ic_inode, state, new);
+	if (state & FUSE_IEXT_LEFT_VALID)
+		trace_fuse_iext_add_mapping_left(ic->ic_inode, &left);
+	if (state & FUSE_IEXT_RIGHT_VALID)
+		trace_fuse_iext_add_mapping_right(ic->ic_inode, &right);
+
 	/*
 	 * Select which case we're in here, and implement it.
 	 */
@@ -1526,6 +1551,8 @@ fuse_iomap_cache_add(
 	ASSERT(new->length > 0);
 	ASSERT(new->offset < inode->i_sb->s_maxbytes);
 
+	trace_fuse_iomap_cache_add(&fi->inode, iodir, new, _RET_IP_);
+
 	/* Mark this fork as being in use */
 	if (ir->ir_bytes < 0)
 		ir->ir_bytes = 0;
@@ -1563,8 +1590,10 @@ int fuse_iomap_cache_alloc(struct inode *inode)
 	if (!try_cmpxchg(&fi->cache, &old, ic)) {
 		/* Someone created mapping cache before us? Free ours... */
 		kfree(ic);
+		return 0;
 	}
 
+	trace_fuse_iomap_cache_alloc(inode);
 	return 0;
 }
 
@@ -1579,6 +1608,8 @@ void fuse_iomap_cache_free(struct inode *inode)
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	struct fuse_iomap_cache *ic = fi->cache;
 
+	trace_fuse_iomap_cache_free(inode);
+
 	/*
 	 * This is only called from eviction, so we cannot be racing to set or
 	 * clear the pointer.
@@ -1671,6 +1702,8 @@ fuse_iomap_cache_lookup(
 
 	assert_cache_locked_shared(ic);
 
+	trace_fuse_iomap_cache_lookup(ic->ic_inode, iodir, off, len, _RET_IP_);
+
 	if (ir->ir_bytes < 0) {
 		/*
 		 * No write fork at all means this filesystem doesn't do out of
@@ -1697,5 +1730,8 @@ fuse_iomap_cache_lookup(
 
 	/* Found a mapping in the cache, return it */
 	fuse_iomap_trim(fi, mval, &got, off, len);
+
+	trace_fuse_iomap_cache_lookup_result(inode, iodir, off, len, &got,
+					     mval);
 	return LOOKUP_HIT;
 }


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 03/12] fuse: use the iomap cache for iomap_begin
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
  2026-02-23 23:20   ` [PATCH 01/12] fuse: cache iomaps Darrick J. Wong
  2026-02-23 23:20   ` [PATCH 02/12] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:21   ` Darrick J. Wong
  2026-02-23 23:21   ` [PATCH 04/12] fuse_trace: " Darrick J. Wong
                     ` (8 subsequent siblings)
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:21 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Look inside the iomap cache to try to satisfy iomap_begin.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap_cache.h |    5 +
 fs/fuse/fuse_iomap.c       |  221 +++++++++++++++++++++++++++++++++++++++++++-
 fs/fuse/fuse_iomap_cache.c |    7 +
 3 files changed, 228 insertions(+), 5 deletions(-)


diff --git a/fs/fuse/fuse_iomap_cache.h b/fs/fuse/fuse_iomap_cache.h
index 922ca182357aa7..dcd52c183f22ab 100644
--- a/fs/fuse/fuse_iomap_cache.h
+++ b/fs/fuse/fuse_iomap_cache.h
@@ -53,6 +53,11 @@ bool fuse_iext_get_extent(const struct fuse_iext_root *ir,
 			  const struct fuse_iext_cursor *cur,
 			  struct fuse_iomap_io *gotp);
 
+/* iomaps that come direct from the fuse server are presumed to be valid */
+#define FUSE_IOMAP_ALWAYS_VALID	((uint64_t)0)
+/* set initial iomap cookie value to avoid ALWAYS_VALID */
+#define FUSE_IOMAP_INIT_COOKIE	((uint64_t)1)
+
 static inline uint64_t fuse_iext_read_seq(struct fuse_iomap_cache *ic)
 {
 	return (uint64_t)READ_ONCE(ic->ic_seq);
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 849ce1626c35fd..b87ccc63ac81ed 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -131,6 +131,7 @@ static inline bool fuse_iomap_check_type(uint16_t fuse_type)
 	case FUSE_IOMAP_TYPE_UNWRITTEN:
 	case FUSE_IOMAP_TYPE_INLINE:
 	case FUSE_IOMAP_TYPE_PURE_OVERWRITE:
+	case FUSE_IOMAP_TYPE_RETRY_CACHE:
 		return true;
 	}
 
@@ -239,9 +240,21 @@ static inline bool fuse_iomap_check_mapping(const struct inode *inode,
 	const unsigned int blocksize = i_blocksize(inode);
 	uint64_t end;
 
-	/* Type and flags must be known */
+	/*
+	 * Type and flags must be known.  Mapping type "retry cache" doesn't
+	 * use any of the other fields.
+	 */
 	if (BAD_DATA(!fuse_iomap_check_type(map->type)))
 		return false;
+	if (map->type == FUSE_IOMAP_TYPE_RETRY_CACHE) {
+		/*
+		 * We only accept cache retries if we have a cache to query.
+		 * There must not be a device addr.
+		 */
+		if (BAD_DATA(!fuse_inode_caches_iomaps(inode)))
+			return false;
+		return true;
+	}
 	if (BAD_DATA(!fuse_iomap_check_flags(map->flags)))
 		return false;
 
@@ -286,6 +299,7 @@ static inline bool fuse_iomap_check_mapping(const struct inode *inode,
 		if (BAD_DATA(iodir != WRITE_MAPPING))
 			return false;
 		break;
+	case FUSE_IOMAP_TYPE_RETRY_CACHE:
 	default:
 		/* should have been caught already */
 		ASSERT(0);
@@ -557,6 +571,157 @@ static int fuse_iomap_set_inline(struct inode *inode, unsigned opflags,
 	return 0;
 }
 
+/* Convert a mapping from the cache into something the kernel can use */
+static int fuse_iomap_from_cache(struct inode *inode, struct iomap *iomap,
+				 const struct fuse_iomap_lookup *lmap)
+{
+	struct fuse_mount *fm = get_fuse_mount(inode);
+	struct fuse_backing *fb;
+
+	fb = fuse_iomap_find_dev(fm->fc, &lmap->map);
+	if (IS_ERR(fb))
+		return PTR_ERR(fb);
+
+	fuse_iomap_from_server(iomap, fb, &lmap->map);
+	iomap->validity_cookie = lmap->validity_cookie;
+
+	fuse_backing_put(fb);
+	return 0;
+}
+
+#if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG)
+static inline int
+fuse_iomap_cached_validate(const struct inode *inode,
+			   enum fuse_iomap_iodir dir,
+			   const struct fuse_iomap_lookup *lmap)
+{
+	if (!static_branch_unlikely(&fuse_iomap_debug))
+		return 0;
+
+	/* Make sure the mappings aren't garbage */
+	if (!fuse_iomap_check_mapping(inode, &lmap->map, dir))
+		return -EFSCORRUPTED;
+
+	/* The cache should not be storing "retry cache" mappings */
+	if (BAD_DATA(lmap->map.type == FUSE_IOMAP_TYPE_RETRY_CACHE))
+		return -EFSCORRUPTED;
+
+	return 0;
+}
+#else
+# define fuse_iomap_cached_validate(...)	(0)
+#endif
+
+/*
+ * Look up iomappings from the cache.  Returns 1 if iomap and srcmap were
+ * satisfied from cache; 0 if not; or a negative errno.
+ */
+static int fuse_iomap_try_cache(struct inode *inode, loff_t pos, loff_t count,
+				unsigned opflags, struct iomap *iomap,
+				struct iomap *srcmap)
+{
+	struct fuse_iomap_lookup lmap;
+	struct iomap *dest = iomap;
+	enum fuse_iomap_lookup_result res;
+	int ret;
+
+	if (!fuse_inode_caches_iomaps(inode))
+		return 0;
+
+	fuse_iomap_cache_lock_shared(inode);
+
+	if (fuse_is_iomap_file_write(opflags)) {
+		res = fuse_iomap_cache_lookup(inode, WRITE_MAPPING, pos, count,
+					      &lmap);
+		switch (res) {
+		case LOOKUP_HIT:
+			ret = fuse_iomap_cached_validate(inode, WRITE_MAPPING,
+					&lmap);
+			if (ret)
+				goto out_unlock;
+
+			if (lmap.map.type != FUSE_IOMAP_TYPE_PURE_OVERWRITE) {
+				ret = fuse_iomap_from_cache(inode, dest, &lmap);
+				if (ret)
+					goto out_unlock;
+
+				dest = srcmap;
+			}
+			fallthrough;
+		case LOOKUP_NOFORK:
+			/* move on to the read fork */
+			break;
+		case LOOKUP_MISS:
+			ret = 0;
+			goto out_unlock;
+		}
+	}
+
+	res = fuse_iomap_cache_lookup(inode, READ_MAPPING, pos, count, &lmap);
+	switch (res) {
+	case LOOKUP_HIT:
+		break;
+	case LOOKUP_NOFORK:
+		ASSERT(res != LOOKUP_NOFORK);
+		ret = -EFSCORRUPTED;
+		goto out_unlock;
+	case LOOKUP_MISS:
+		ret = 0;
+		goto out_unlock;
+	}
+
+	ret = fuse_iomap_cached_validate(inode, READ_MAPPING, &lmap);
+	if (ret)
+		goto out_unlock;
+
+	ret = fuse_iomap_from_cache(inode, dest, &lmap);
+	if (ret)
+		goto out_unlock;
+
+	if (fuse_is_iomap_file_write(opflags)) {
+		switch (iomap->type) {
+		case IOMAP_HOLE:
+			if (opflags & (IOMAP_ZERO | IOMAP_UNSHARE))
+				ret = 1;
+			else
+				ret = 0;
+			break;
+		case IOMAP_DELALLOC:
+			if (opflags & IOMAP_DIRECT)
+				ret = 0;
+			else
+				ret = 1;
+			break;
+		default:
+			ret = 1;
+			break;
+		}
+	} else {
+		ret = 1;
+	}
+
+out_unlock:
+	fuse_iomap_cache_unlock_shared(inode);
+	if (ret < 1)
+		return ret;
+
+	if (iomap->type == IOMAP_INLINE || srcmap->type == IOMAP_INLINE) {
+		ret = fuse_iomap_set_inline(inode, opflags, pos, count, iomap,
+					    srcmap);
+		if (ret)
+			return ret;
+	}
+	return 1;
+}
+
+/*
+ * For atomic writes we must always query the server because that might require
+ * assistance from the fuse server.  For swapfiles we always query the server
+ * because we have no idea if the server actually wants to support that.
+ */
+#define FUSE_IOMAP_OP_NOCACHE	(FUSE_IOMAP_OP_ATOMIC | \
+				 FUSE_IOMAP_OP_SWAPFILE)
+
 static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 			    unsigned opflags, struct iomap *iomap,
 			    struct iomap *srcmap)
@@ -577,6 +742,20 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 
 	trace_fuse_iomap_begin(inode, pos, count, opflags);
 
+	/*
+	 * Try to read mappings from the cache; if we find something then use
+	 * it; otherwise we upcall the fuse server.
+	 */
+	if (!(opflags & FUSE_IOMAP_OP_NOCACHE)) {
+		err = fuse_iomap_try_cache(inode, pos, count, opflags, iomap,
+					   srcmap);
+		if (err < 0)
+			return err;
+		if (err == 1)
+			return 0;
+	}
+
+retry:
 	args.opcode = FUSE_IOMAP_BEGIN;
 	args.nodeid = get_node_id(inode);
 	args.in_numargs = 1;
@@ -598,6 +777,24 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 	if (err)
 		return err;
 
+	/*
+	 * If the fuse server tells us it populated the cache, we'll try the
+	 * cache lookup again.  Note that we dropped the cache lock, so it's
+	 * entirely possible that another thread could have invalidated the
+	 * cache -- if the cache misses, we'll call the server again.
+	 */
+	if (outarg.read.type == FUSE_IOMAP_TYPE_RETRY_CACHE) {
+		err = fuse_iomap_try_cache(inode, pos, count, opflags, iomap,
+					   srcmap);
+		if (err < 0)
+			return err;
+		if (err == 1)
+			return 0;
+		if (signal_pending(current))
+			return -EINTR;
+		goto retry;
+	}
+
 	read_dev = fuse_iomap_find_dev(fm->fc, &outarg.read);
 	if (IS_ERR(read_dev))
 		return PTR_ERR(read_dev);
@@ -625,6 +822,8 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 		 */
 		fuse_iomap_from_server(iomap, read_dev, &outarg.read);
 	}
+	iomap->validity_cookie = FUSE_IOMAP_ALWAYS_VALID;
+	srcmap->validity_cookie = FUSE_IOMAP_ALWAYS_VALID;
 
 	if (iomap->type == IOMAP_INLINE || srcmap->type == IOMAP_INLINE) {
 		err = fuse_iomap_set_inline(inode, opflags, pos, count, iomap,
@@ -1367,7 +1566,21 @@ static const struct iomap_dio_ops fuse_iomap_dio_write_ops = {
 	.end_io		= fuse_iomap_dio_write_end_io,
 };
 
+static bool fuse_iomap_revalidate(struct inode *inode,
+				  const struct iomap *iomap)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	uint64_t validity_cookie;
+
+	if (iomap->validity_cookie == FUSE_IOMAP_ALWAYS_VALID)
+		return true;
+
+	validity_cookie = fuse_iext_read_seq(fi->cache);
+	return iomap->validity_cookie == validity_cookie;
+}
+
 static const struct iomap_write_ops fuse_iomap_write_ops = {
+	.iomap_valid		= fuse_iomap_revalidate,
 };
 
 static int
@@ -1649,14 +1862,14 @@ static void fuse_iomap_end_bio(struct bio *bio)
  * mapping is valid, false otherwise.
  */
 static bool fuse_iomap_revalidate_writeback(struct iomap_writepage_ctx *wpc,
+					    struct inode *inode,
 					    loff_t offset)
 {
 	if (offset < wpc->iomap.offset ||
 	    offset >= wpc->iomap.offset + wpc->iomap.length)
 		return false;
 
-	/* XXX actually use revalidation cookie */
-	return true;
+	return fuse_iomap_revalidate(inode, &wpc->iomap);
 }
 
 /*
@@ -1710,7 +1923,7 @@ static ssize_t fuse_iomap_writeback_range(struct iomap_writepage_ctx *wpc,
 
 	trace_fuse_iomap_writeback_range(inode, offset, len, end_pos);
 
-	if (!fuse_iomap_revalidate_writeback(wpc, offset)) {
+	if (!fuse_iomap_revalidate_writeback(wpc, inode, offset)) {
 		struct iomap_iter fake_iter = { };
 		struct iomap *write_iomap = &fake_iter.iomap;
 
diff --git a/fs/fuse/fuse_iomap_cache.c b/fs/fuse/fuse_iomap_cache.c
index a047d7bf95257a..7fb5dd1198819f 100644
--- a/fs/fuse/fuse_iomap_cache.c
+++ b/fs/fuse/fuse_iomap_cache.c
@@ -706,7 +706,11 @@ fuse_iext_realloc_root(
  */
 static inline void fuse_iext_inc_seq(struct fuse_iomap_cache *ic)
 {
-	WRITE_ONCE(ic->ic_seq, READ_ONCE(ic->ic_seq) + 1);
+	uint64_t new_val = READ_ONCE(ic->ic_seq) + 1;
+
+	if (new_val == FUSE_IOMAP_ALWAYS_VALID)
+		new_val++;
+	WRITE_ONCE(ic->ic_seq, new_val);
 }
 
 static void
@@ -1584,6 +1588,7 @@ int fuse_iomap_cache_alloc(struct inode *inode)
 
 	/* Only the write mapping cache can return NOFORK */
 	ic->ic_write.ir_bytes = -1;
+	ic->ic_seq = FUSE_IOMAP_INIT_COOKIE;
 	ic->ic_inode = inode;
 	init_rwsem(&ic->ic_lock);
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 04/12] fuse_trace: use the iomap cache for iomap_begin
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:21   ` [PATCH 03/12] fuse: use the iomap cache for iomap_begin Darrick J. Wong
@ 2026-02-23 23:21   ` Darrick J. Wong
  2026-02-23 23:21   ` [PATCH 05/12] fuse: invalidate iomap cache after file updates Darrick J. Wong
                     ` (7 subsequent siblings)
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:21 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   34 ++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    7 ++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 697289c82d0dad..bf47008e50920a 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -404,6 +404,7 @@ struct fuse_iomap_lookup;
 
 #define FUSE_IOMAP_TYPE_STRINGS \
 	{ FUSE_IOMAP_TYPE_PURE_OVERWRITE,	"overwrite" }, \
+	{ FUSE_IOMAP_TYPE_RETRY_CACHE,		"retry" }, \
 	{ FUSE_IOMAP_TYPE_HOLE,			"hole" }, \
 	{ FUSE_IOMAP_TYPE_DELALLOC,		"delalloc" }, \
 	{ FUSE_IOMAP_TYPE_MAPPED,		"mapped" }, \
@@ -1509,6 +1510,39 @@ TRACE_EVENT(fuse_iomap_cache_lookup_result,
 		  FUSE_IOMAP_MAP_PRINTK_ARGS(got),
 		  __entry->validity_cookie)
 );
+
+TRACE_EVENT(fuse_iomap_invalid,
+	TP_PROTO(const struct inode *inode, const struct iomap *map,
+		 uint64_t validity_cookie),
+	TP_ARGS(inode, map, validity_cookie),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		FUSE_IOMAP_MAP_FIELDS(map)
+		__field(uint64_t,		old_validity_cookie)
+		__field(uint64_t,		validity_cookie)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+
+		__entry->mapoffset	=	map->offset;
+		__entry->maplength	=	map->length;
+		__entry->maptype	=	map->type;
+		__entry->mapflags	=	map->flags;
+		__entry->mapaddr	=	map->addr;
+		__entry->mapdev		=	FUSE_IOMAP_DEV_NULL;
+
+		__entry->old_validity_cookie=	map->validity_cookie;
+		__entry->validity_cookie=	validity_cookie;
+	),
+
+	TP_printk(FUSE_INODE_FMT FUSE_IOMAP_MAP_FMT() " old_cookie 0x%llx new_cookie 0x%llx",
+		  FUSE_INODE_PRINTK_ARGS,
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(map),
+		  __entry->old_validity_cookie,
+		  __entry->validity_cookie)
+);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index b87ccc63ac81ed..59a2481f89626d 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -1576,7 +1576,12 @@ static bool fuse_iomap_revalidate(struct inode *inode,
 		return true;
 
 	validity_cookie = fuse_iext_read_seq(fi->cache);
-	return iomap->validity_cookie == validity_cookie;
+	if (unlikely(iomap->validity_cookie != validity_cookie)) {
+		trace_fuse_iomap_invalid(inode, iomap, validity_cookie);
+		return false;
+	}
+
+	return true;
 }
 
 static const struct iomap_write_ops fuse_iomap_write_ops = {


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 05/12] fuse: invalidate iomap cache after file updates
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:21   ` [PATCH 04/12] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:21   ` Darrick J. Wong
  2026-02-23 23:21   ` [PATCH 06/12] fuse_trace: " Darrick J. Wong
                     ` (6 subsequent siblings)
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:21 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

The kernel doesn't know what the fuse server might have done in response
to truncate, fallocate, or ioend events.  Therefore, it must invalidate
the mapping cache after those operations to ensure cache coherency.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.h       |    3 +++
 fs/fuse/fuse_iomap_cache.h |    9 +++++++++
 fs/fuse/file.c             |   18 ++++++++++--------
 fs/fuse/fuse_iomap.c       |   26 ++++++++++++++++++++++++--
 fs/fuse/fuse_iomap_cache.c |   27 +++++++++++++++++++++++++++
 5 files changed, 73 insertions(+), 10 deletions(-)


diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index bf6640c36465e1..efc8adbc4f31dc 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -68,6 +68,8 @@ int fuse_iomap_fallocate(struct file *file, int mode, loff_t offset,
 			 loff_t length, loff_t new_size);
 int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
 				 loff_t endpos);
+void fuse_iomap_copied_file_range(struct inode *inode, loff_t offset,
+				  u64 written);
 
 int fuse_dev_ioctl_iomap_support(struct file *file,
 				 struct fuse_iomap_support __user *argp);
@@ -100,6 +102,7 @@ int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 # define fuse_iomap_setsize_start(...)		(-ENOSYS)
 # define fuse_iomap_fallocate(...)		(-ENOSYS)
 # define fuse_iomap_flush_unmap_range(...)	(-ENOSYS)
+# define fuse_iomap_copied_file_range(...)	((void)0)
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
 # define fuse_iomap_dev_inval(...)		(-ENOSYS)
 # define fuse_iomap_fadvise			NULL
diff --git a/fs/fuse/fuse_iomap_cache.h b/fs/fuse/fuse_iomap_cache.h
index dcd52c183f22ab..eba90d9519b8c3 100644
--- a/fs/fuse/fuse_iomap_cache.h
+++ b/fs/fuse/fuse_iomap_cache.h
@@ -99,6 +99,15 @@ enum fuse_iomap_lookup_result
 fuse_iomap_cache_lookup(struct inode *inode, enum fuse_iomap_iodir iodir,
 			loff_t off, uint64_t len,
 			struct fuse_iomap_lookup *mval);
+
+int fuse_iomap_cache_invalidate_range(struct inode *inode, loff_t offset,
+				      uint64_t length);
+static inline int fuse_iomap_cache_invalidate(struct inode *inode,
+					      loff_t offset)
+{
+	return fuse_iomap_cache_invalidate_range(inode, offset,
+						 FUSE_IOMAP_INVAL_TO_EOF);
+}
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_CACHE_H */
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 0b21fcdefffeb7..771885adf8a5e1 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -101,7 +101,7 @@ static void fuse_release_end(struct fuse_mount *fm, struct fuse_args *args,
 	kfree(ra);
 }
 
-static void fuse_file_put(struct fuse_file *ff, bool sync)
+static void fuse_file_put(struct fuse_file *ff, struct inode *inode, bool sync)
 {
 	if (refcount_dec_and_test(&ff->count)) {
 		struct fuse_release_args *ra = &ff->args->release_args;
@@ -385,7 +385,7 @@ void fuse_file_release(struct inode *inode, struct fuse_file *ff,
 	 * own ref to the file, the IO completion has to drop the ref, which is
 	 * how the fuse server can end up closing its clients' files.
 	 */
-	fuse_file_put(ff, false);
+	fuse_file_put(ff, inode, false);
 }
 
 void fuse_release_common(struct file *file, bool isdir)
@@ -416,7 +416,7 @@ void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff,
 {
 	WARN_ON(refcount_read(&ff->count) > 1);
 	fuse_prepare_release(fi, ff, flags, FUSE_RELEASE, true);
-	fuse_file_put(ff, true);
+	fuse_file_put(ff, fi ? &fi->inode : NULL, true);
 }
 EXPORT_SYMBOL_GPL(fuse_sync_release);
 
@@ -1043,7 +1043,7 @@ static void fuse_readpages_end(struct fuse_mount *fm, struct fuse_args *args,
 		folio_put(ap->folios[i]);
 	}
 	if (ia->ff)
-		fuse_file_put(ia->ff, false);
+		fuse_file_put(ia->ff, inode, false);
 
 	fuse_io_free(ia);
 }
@@ -1907,7 +1907,7 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa)
 	if (wpa->bucket)
 		fuse_sync_bucket_dec(wpa->bucket);
 
-	fuse_file_put(wpa->ia.ff, false);
+	fuse_file_put(wpa->ia.ff, wpa->inode, false);
 
 	kfree(ap->folios);
 	kfree(wpa);
@@ -2064,7 +2064,7 @@ int fuse_write_inode(struct inode *inode, struct writeback_control *wbc)
 	ff = __fuse_write_file_get(fi);
 	err = fuse_flush_times(inode, ff);
 	if (ff)
-		fuse_file_put(ff, false);
+		fuse_file_put(ff, inode, false);
 
 	return err;
 }
@@ -2290,7 +2290,7 @@ static int fuse_iomap_writeback_submit(struct iomap_writepage_ctx *wpc,
 	}
 
 	if (data->ff)
-		fuse_file_put(data->ff, false);
+		fuse_file_put(data->ff, wpc->inode, false);
 
 	return error;
 }
@@ -3202,7 +3202,9 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
 		goto out;
 	}
 
-	if (!is_iomap)
+	if (is_iomap)
+		fuse_iomap_copied_file_range(inode_out, pos_out, bytes_copied);
+	else
 		truncate_inode_pages_range(inode_out->i_mapping,
 				   ALIGN_DOWN(pos_out, PAGE_SIZE),
 				   ALIGN(pos_out + bytes_copied, PAGE_SIZE) - 1);
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 59a2481f89626d..98e6db197a01d3 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -891,6 +891,7 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
 			fuse_iomap_inline_free(iomap);
 			if (err)
 				return err;
+			fuse_iomap_cache_invalidate_range(inode, pos, written);
 		} else {
 			fuse_iomap_inline_free(iomap);
 		}
@@ -979,7 +980,7 @@ fuse_iomap_setsize_finish(
 	trace_fuse_iomap_setsize_finish(inode, newsize, 0);
 
 	fi->i_disk_size = newsize;
-	return 0;
+	return fuse_iomap_cache_invalidate(inode, newsize);
 }
 
 /*
@@ -1064,10 +1065,12 @@ static int fuse_iomap_ioend(struct inode *inode, loff_t pos, size_t written,
 
 	/*
 	 * If there weren't any ioend errors, update the incore isize, which
-	 * confusingly takes the new i_size as "pos".
+	 * confusingly takes the new i_size as "pos".  Invalidate cached
+	 * mappings for the file range that we just completed.
 	 */
 	fi->i_disk_size = outarg.newsize;
 	fuse_write_update_attr(inode, pos + written, written);
+	fuse_iomap_cache_invalidate_range(inode, pos, written);
 	return 0;
 }
 
@@ -1772,6 +1775,7 @@ void fuse_iomap_open_truncate(struct inode *inode)
 	trace_fuse_iomap_open_truncate(inode);
 
 	fi->i_disk_size = 0;
+	fuse_iomap_cache_invalidate(inode, 0);
 }
 
 struct fuse_writepage_ctx {
@@ -2466,6 +2470,14 @@ fuse_iomap_fallocate(
 
 	trace_fuse_iomap_fallocate(inode, mode, offset, length, new_size);
 
+	if (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE))
+		error = fuse_iomap_cache_invalidate(inode, offset);
+	else
+		error = fuse_iomap_cache_invalidate_range(inode, offset,
+							  length);
+	if (error)
+		return error;
+
 	/*
 	 * If we unmapped blocks from the file range, then we zero the
 	 * pagecache for those regions and push them to disk rather than make
@@ -2483,6 +2495,8 @@ fuse_iomap_fallocate(
 	 */
 	if (new_size) {
 		error = fuse_iomap_setsize_start(inode, new_size);
+		if (!error)
+			error = fuse_iomap_setsize_finish(inode, new_size);
 		if (error)
 			return error;
 
@@ -2604,3 +2618,11 @@ int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp)
 		return -EINVAL;
 	}
 }
+
+void fuse_iomap_copied_file_range(struct inode *inode, loff_t offset,
+				  u64 written)
+{
+	ASSERT(fuse_inode_has_iomap(inode));
+
+	fuse_iomap_cache_invalidate_range(inode, offset, written);
+}
diff --git a/fs/fuse/fuse_iomap_cache.c b/fs/fuse/fuse_iomap_cache.c
index 7fb5dd1198819f..4f30a27360b029 100644
--- a/fs/fuse/fuse_iomap_cache.c
+++ b/fs/fuse/fuse_iomap_cache.c
@@ -1444,6 +1444,33 @@ fuse_iomap_cache_remove(
 	return ret;
 }
 
+int fuse_iomap_cache_invalidate_range(struct inode *inode, loff_t offset,
+				      uint64_t length)
+{
+	loff_t aligned_offset;
+	const unsigned int blocksize = i_blocksize(inode);
+	int ret, ret2;
+
+	if (!fuse_inode_caches_iomaps(inode))
+		return 0;
+
+	aligned_offset = round_down(offset, blocksize);
+	if (length != FUSE_IOMAP_INVAL_TO_EOF) {
+		length += offset - aligned_offset;
+		length = round_up(length, blocksize);
+	}
+
+	fuse_iomap_cache_lock(inode);
+	ret = fuse_iomap_cache_remove(inode, READ_MAPPING,
+				      aligned_offset, length);
+	ret2 = fuse_iomap_cache_remove(inode, WRITE_MAPPING,
+				       aligned_offset, length);
+	fuse_iomap_cache_unlock(inode);
+	if (ret)
+		return ret;
+	return ret2;
+}
+
 static void
 fuse_iext_add_mapping(
 	struct fuse_iomap_cache		*ic,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 06/12] fuse_trace: invalidate iomap cache after file updates
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (4 preceding siblings ...)
  2026-02-23 23:21   ` [PATCH 05/12] fuse: invalidate iomap cache after file updates Darrick J. Wong
@ 2026-02-23 23:21   ` Darrick J. Wong
  2026-02-23 23:22   ` [PATCH 07/12] fuse: enable iomap cache management Darrick J. Wong
                     ` (5 subsequent siblings)
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:21 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h       |   20 ++++++++++++++++++++
 fs/fuse/fuse_iomap.c       |    2 ++
 fs/fuse/fuse_iomap_cache.c |    2 ++
 3 files changed, 24 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index bf47008e50920a..ddcbefd33a4024 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -932,6 +932,7 @@ DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_truncate_up);
 DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_truncate_down);
 DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_punch_range);
 DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_flush_unmap_range);
+DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_cache_invalidate_range);
 
 TRACE_EVENT(fuse_iomap_end_ioend,
 	TP_PROTO(const struct iomap_ioend *ioend),
@@ -1248,6 +1249,25 @@ DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_inline_write);
 DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_set_inline_iomap);
 DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_set_inline_srcmap);
 
+TRACE_EVENT(fuse_iomap_copied_file_range,
+	TP_PROTO(const struct inode *inode, loff_t offset,
+		 size_t written),
+	TP_ARGS(inode, offset, written),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	offset;
+		__entry->length		=	written;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT(),
+		  FUSE_IO_RANGE_PRINTK_ARGS())
+);
+
 DECLARE_EVENT_CLASS(fuse_iext_class,
 	TP_PROTO(const struct inode *inode, const struct fuse_iext_cursor *cur,
 		 int state, unsigned long caller_ip),
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 98e6db197a01d3..4bc2322a4ba796 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -2624,5 +2624,7 @@ void fuse_iomap_copied_file_range(struct inode *inode, loff_t offset,
 {
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_copied_file_range(inode, offset, written);
+
 	fuse_iomap_cache_invalidate_range(inode, offset, written);
 }
diff --git a/fs/fuse/fuse_iomap_cache.c b/fs/fuse/fuse_iomap_cache.c
index 4f30a27360b029..277311c7c0c4ea 100644
--- a/fs/fuse/fuse_iomap_cache.c
+++ b/fs/fuse/fuse_iomap_cache.c
@@ -1454,6 +1454,8 @@ int fuse_iomap_cache_invalidate_range(struct inode *inode, loff_t offset,
 	if (!fuse_inode_caches_iomaps(inode))
 		return 0;
 
+	trace_fuse_iomap_cache_invalidate_range(inode, offset, length);
+
 	aligned_offset = round_down(offset, blocksize);
 	if (length != FUSE_IOMAP_INVAL_TO_EOF) {
 		length += offset - aligned_offset;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 07/12] fuse: enable iomap cache management
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (5 preceding siblings ...)
  2026-02-23 23:21   ` [PATCH 06/12] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:22   ` Darrick J. Wong
  2026-02-23 23:22   ` [PATCH 08/12] fuse_trace: " Darrick J. Wong
                     ` (4 subsequent siblings)
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:22 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Provide a means for the fuse server to upload iomappings to the kernel
and invalidate them.  This is how we enable iomap caching for better
performance.  This is also required for correct synchronization between
pagecache writes and writeback.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.h      |    7 +
 include/uapi/linux/fuse.h |   29 +++++
 fs/fuse/dev.c             |   46 ++++++++
 fs/fuse/fuse_iomap.c      |  264 ++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 343 insertions(+), 3 deletions(-)


diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index efc8adbc4f31dc..b13d305ee0508b 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -78,6 +78,11 @@ int fuse_iomap_dev_inval(struct fuse_conn *fc,
 
 int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
 int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
+
+int fuse_iomap_upsert_mappings(struct fuse_conn *fc,
+		      const struct fuse_iomap_upsert_mappings_out *outarg);
+int fuse_iomap_inval_mappings(struct fuse_conn *fc,
+		     const struct fuse_iomap_inval_mappings_out *outarg);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -107,6 +112,8 @@ int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 # define fuse_iomap_dev_inval(...)		(-ENOSYS)
 # define fuse_iomap_fadvise			NULL
 # define fuse_dev_ioctl_iomap_set_nofs(...)	(-EOPNOTSUPP)
+# define fuse_iomap_upsert_mappings(...)	(-ENOSYS)
+# define fuse_iomap_inval_mappings(...)		(-ENOSYS)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index a273838bc20f2f..8c5e67731b21b8 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -251,6 +251,8 @@
  *  - add FUSE_ATTR_ATOMIC for single-fsblock atomic write support
  *  - add FUSE_ATTR_{SYNC,IMMUTABLE,APPEND} for VFS enforcement of file
  *    attributes
+ *  - add FUSE_NOTIFY_IOMAP_{UPSERT,INVAL}_MAPPINGS so fuse servers can cache
+ *    file range mappings in the kernel for iomap
  */
 
 #ifndef _LINUX_FUSE_H
@@ -731,6 +733,8 @@ enum fuse_notify_code {
 	FUSE_NOTIFY_INC_EPOCH = 8,
 	FUSE_NOTIFY_PRUNE = 9,
 	FUSE_NOTIFY_IOMAP_DEV_INVAL = 99,
+	FUSE_NOTIFY_IOMAP_UPSERT_MAPPINGS = 100,
+	FUSE_NOTIFY_IOMAP_INVAL_MAPPINGS = 101,
 	FUSE_NOTIFY_CODE_MAX,
 };
 
@@ -1396,6 +1400,8 @@ struct fuse_uring_cmd_req {
 #define FUSE_IOMAP_TYPE_PURE_OVERWRITE	(255)
 /* fuse-specific mapping type saying the server has populated the cache */
 #define FUSE_IOMAP_TYPE_RETRY_CACHE	(254)
+/* do not upsert this mapping */
+#define FUSE_IOMAP_TYPE_NOCACHE		(253)
 
 #define FUSE_IOMAP_DEV_NULL		(0U)	/* null device cookie */
 
@@ -1556,4 +1562,27 @@ struct fuse_iomap_dev_inval_out {
 /* invalidate all cached iomap mappings up to EOF */
 #define FUSE_IOMAP_INVAL_TO_EOF		(~0ULL)
 
+struct fuse_iomap_inval_mappings_out {
+	uint64_t nodeid;	/* Inode ID */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+
+	/*
+	 * Range of read and mappings to invalidate.  Zero length means ignore
+	 * the range; and FUSE_IOMAP_INVAL_TO_EOF can be used for length.
+	 */
+	struct fuse_range read;
+	struct fuse_range write;
+};
+
+struct fuse_iomap_upsert_mappings_out {
+	uint64_t nodeid;	/* Inode ID */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+
+	/* read file data from here */
+	struct fuse_iomap_io	read;
+
+	/* write file data to here, if applicable */
+	struct fuse_iomap_io	write;
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 896706c911cf24..b2433dec8cc5e5 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1873,6 +1873,48 @@ static int fuse_notify_iomap_dev_inval(struct fuse_conn *fc, unsigned int size,
 	return err;
 }
 
+static int fuse_notify_iomap_upsert_mappings(struct fuse_conn *fc,
+					     unsigned int size,
+					     struct fuse_copy_state *cs)
+{
+	struct fuse_iomap_upsert_mappings_out outarg;
+	int err = -EINVAL;
+
+	if (size != sizeof(outarg))
+		goto err;
+
+	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
+	if (err)
+		goto err;
+	fuse_copy_finish(cs);
+
+	return fuse_iomap_upsert_mappings(fc, &outarg);
+err:
+	fuse_copy_finish(cs);
+	return err;
+}
+
+static int fuse_notify_iomap_inval_mappings(struct fuse_conn *fc,
+					    unsigned int size,
+					    struct fuse_copy_state *cs)
+{
+	struct fuse_iomap_inval_mappings_out outarg;
+	int err = -EINVAL;
+
+	if (size != sizeof(outarg))
+		goto err;
+
+	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
+	if (err)
+		goto err;
+	fuse_copy_finish(cs);
+
+	return fuse_iomap_inval_mappings(fc, &outarg);
+err:
+	fuse_copy_finish(cs);
+	return err;
+}
+
 struct fuse_retrieve_args {
 	struct fuse_args_pages ap;
 	struct fuse_notify_retrieve_in inarg;
@@ -2159,6 +2201,10 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 
 	case FUSE_NOTIFY_IOMAP_DEV_INVAL:
 		return fuse_notify_iomap_dev_inval(fc, size, cs);
+	case FUSE_NOTIFY_IOMAP_UPSERT_MAPPINGS:
+		return fuse_notify_iomap_upsert_mappings(fc, size, cs);
+	case FUSE_NOTIFY_IOMAP_INVAL_MAPPINGS:
+		return fuse_notify_iomap_inval_mappings(fc, size, cs);
 
 	default:
 		return -EINVAL;
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 4bc2322a4ba796..478c11b90ad4aa 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -132,6 +132,7 @@ static inline bool fuse_iomap_check_type(uint16_t fuse_type)
 	case FUSE_IOMAP_TYPE_INLINE:
 	case FUSE_IOMAP_TYPE_PURE_OVERWRITE:
 	case FUSE_IOMAP_TYPE_RETRY_CACHE:
+	case FUSE_IOMAP_TYPE_NOCACHE:
 		return true;
 	}
 
@@ -241,8 +242,8 @@ static inline bool fuse_iomap_check_mapping(const struct inode *inode,
 	uint64_t end;
 
 	/*
-	 * Type and flags must be known.  Mapping type "retry cache" doesn't
-	 * use any of the other fields.
+	 * Type and flags must be known.  Mapping types "retry cache" and "do
+	 * not insert in cache" don't use any of the other fields.
 	 */
 	if (BAD_DATA(!fuse_iomap_check_type(map->type)))
 		return false;
@@ -255,6 +256,8 @@ static inline bool fuse_iomap_check_mapping(const struct inode *inode,
 			return false;
 		return true;
 	}
+	if (map->type == FUSE_IOMAP_TYPE_NOCACHE)
+		return true;
 	if (BAD_DATA(!fuse_iomap_check_flags(map->flags)))
 		return false;
 
@@ -299,6 +302,7 @@ static inline bool fuse_iomap_check_mapping(const struct inode *inode,
 		if (BAD_DATA(iodir != WRITE_MAPPING))
 			return false;
 		break;
+	case FUSE_IOMAP_TYPE_NOCACHE:
 	case FUSE_IOMAP_TYPE_RETRY_CACHE:
 	default:
 		/* should have been caught already */
@@ -373,6 +377,15 @@ fuse_iomap_begin_validate(const struct inode *inode,
 	if (!fuse_iomap_check_mapping(inode, &outarg->write, WRITE_MAPPING))
 		return -EFSCORRUPTED;
 
+	/*
+	 * ->iomap_begin requires real mappings or "retry from cache"; "do not
+	 * add to cache" does not apply here.
+	 */
+	if (BAD_DATA(outarg->read.type == FUSE_IOMAP_TYPE_NOCACHE))
+		return -EFSCORRUPTED;
+	if (BAD_DATA(outarg->write.type == FUSE_IOMAP_TYPE_NOCACHE))
+		return -EFSCORRUPTED;
+
 	/*
 	 * Must have returned a mapping for at least the first byte in the
 	 * range.  The main mapping check already validated that the length
@@ -602,9 +615,11 @@ fuse_iomap_cached_validate(const struct inode *inode,
 	if (!fuse_iomap_check_mapping(inode, &lmap->map, dir))
 		return -EFSCORRUPTED;
 
-	/* The cache should not be storing "retry cache" mappings */
+	/* The cache should not be storing cache management mappings */
 	if (BAD_DATA(lmap->map.type == FUSE_IOMAP_TYPE_RETRY_CACHE))
 		return -EFSCORRUPTED;
+	if (BAD_DATA(lmap->map.type == FUSE_IOMAP_TYPE_NOCACHE))
+		return -EFSCORRUPTED;
 
 	return 0;
 }
@@ -2628,3 +2643,246 @@ void fuse_iomap_copied_file_range(struct inode *inode, loff_t offset,
 
 	fuse_iomap_cache_invalidate_range(inode, offset, written);
 }
+
+static inline int
+fuse_iomap_upsert_validate_dev(
+	const struct fuse_backing	*fb,
+	const struct fuse_iomap_io	*map)
+{
+	uint64_t			map_end;
+	sector_t			device_bytes;
+
+	if (!fb) {
+		if (BAD_DATA(map->addr != FUSE_IOMAP_NULL_ADDR))
+			return -EFSCORRUPTED;
+
+		return 0;
+	}
+
+	if (BAD_DATA(map->addr == FUSE_IOMAP_NULL_ADDR))
+		return -EFSCORRUPTED;
+
+	if (BAD_DATA(check_add_overflow(map->addr, map->length, &map_end)))
+		return -EFSCORRUPTED;
+
+	/*
+	 * bdev_nr_sectors() == 0 usually means the device has gone away from
+	 * underneath us.  We won't cache this mapping, but we'll return
+	 * -EINVAL to signal a softer error to the fuse server than "your fs
+	 * metadata are corrupt".  If the fuse server persists anyway, then
+	 * the worst that happens is that the IO will fail.
+	 */
+	device_bytes = bdev_nr_sectors(fb->bdev) << SECTOR_SHIFT;
+	if (!device_bytes)
+		return -EINVAL;
+
+	if (BAD_DATA(map_end > device_bytes))
+		return -EFSCORRUPTED;
+
+	return 0;
+}
+
+/* Validate one of the incoming upsert mappings */
+static inline int
+fuse_iomap_upsert_validate_mapping(struct inode *inode,
+				   enum fuse_iomap_iodir iodir,
+				   const struct fuse_iomap_io *map)
+{
+	struct fuse_conn *fc = get_fuse_conn(inode);
+	struct fuse_backing *fb;
+	int ret;
+
+	if (!fuse_iomap_check_mapping(inode, map, iodir))
+		return -EFSCORRUPTED;
+
+	/*
+	 * A "retry cache" instruction makes no sense when we're adding to
+	 * the mapping cache.
+	 */
+	if (BAD_DATA(map->type == FUSE_IOMAP_TYPE_RETRY_CACHE))
+		return -EFSCORRUPTED;
+
+	/* nocache is allowed, because we ignore it later */
+	if (map->type == FUSE_IOMAP_TYPE_NOCACHE)
+		return 0;
+
+	/* Make sure we can find the device */
+	fb = fuse_iomap_find_dev(fc, map);
+	if (BAD_DATA(IS_ERR(fb)))
+		return -EFSCORRUPTED;
+
+	ret = fuse_iomap_upsert_validate_dev(fb, map);
+	fuse_backing_put(fb);
+	return ret;
+}
+
+/* Check the incoming upsert mappings to make sure they're not nonsense */
+static inline int
+fuse_iomap_upsert_validate_mappings(struct inode *inode,
+		const struct fuse_iomap_upsert_mappings_out *outarg)
+{
+	int ret = fuse_iomap_upsert_validate_mapping(inode, READ_MAPPING,
+						     &outarg->read);
+	if (ret)
+		return ret;
+
+	return fuse_iomap_upsert_validate_mapping(inode, WRITE_MAPPING,
+						  &outarg->write);
+}
+
+static int fuse_iomap_upsert_inode(struct inode *inode,
+		const struct fuse_iomap_upsert_mappings_out *outarg)
+{
+	int ret = fuse_iomap_upsert_validate_mappings(inode, outarg);
+	if (ret)
+		return ret;
+
+	if (!fuse_inode_caches_iomaps(inode)) {
+		ret = fuse_iomap_cache_alloc(inode);
+		if (ret)
+			return ret;
+	}
+
+	fuse_iomap_cache_lock(inode);
+
+	if (outarg->read.type != FUSE_IOMAP_TYPE_NOCACHE) {
+		ret = fuse_iomap_cache_upsert(inode, READ_MAPPING,
+					      &outarg->read);
+		if (ret)
+			goto out_unlock;
+	}
+
+	if (outarg->write.type != FUSE_IOMAP_TYPE_NOCACHE) {
+		ret = fuse_iomap_cache_upsert(inode, WRITE_MAPPING,
+					      &outarg->write);
+		if (ret)
+			goto out_unlock;
+	}
+
+out_unlock:
+	fuse_iomap_cache_unlock(inode);
+	return ret;
+}
+
+int fuse_iomap_upsert_mappings(struct fuse_conn *fc,
+		const struct fuse_iomap_upsert_mappings_out *outarg)
+{
+	struct inode *inode;
+	struct fuse_inode *fi;
+	int ret;
+
+	if (!fc->iomap)
+		return -EINVAL;
+
+	down_read(&fc->killsb);
+	inode = fuse_ilookup(fc, outarg->nodeid, NULL);
+	if (!inode) {
+		ret = -ESTALE;
+		goto out_sb;
+	}
+
+	fi = get_fuse_inode(inode);
+	if (BAD_DATA(fi->orig_ino != outarg->attr_ino)) {
+		ret = -EINVAL;
+		goto out_inode;
+	}
+
+	if (fuse_is_bad(inode)) {
+		ret = -EIO;
+		goto out_inode;
+	}
+
+	ret = fuse_iomap_upsert_inode(inode, outarg);
+out_inode:
+	iput(inode);
+out_sb:
+	up_read(&fc->killsb);
+	return ret;
+}
+
+static inline bool
+fuse_iomap_inval_validate_range(const struct inode *inode,
+				const struct fuse_range *range)
+{
+	const unsigned int blocksize = i_blocksize(inode);
+
+	if (range->length == 0)
+		return true;
+
+	/* Range can't start beyond maxbytes */
+	if (BAD_DATA(range->offset >= inode->i_sb->s_maxbytes))
+		return false;
+
+	/* File range must be aligned to blocksize */
+	if (BAD_DATA(!IS_ALIGNED(range->offset, blocksize)))
+		return false;
+	if (range->length != FUSE_IOMAP_INVAL_TO_EOF &&
+	    BAD_DATA(!IS_ALIGNED(range->length, blocksize)))
+		return false;
+
+	return true;
+}
+
+static int fuse_iomap_inval_inode(struct inode *inode,
+		const struct fuse_iomap_inval_mappings_out *outarg)
+{
+	int ret = 0, ret2 = 0;
+
+	if (!fuse_iomap_inval_validate_range(inode, &outarg->write))
+		return -EFSCORRUPTED;
+
+	if (!fuse_iomap_inval_validate_range(inode, &outarg->read))
+		return -EFSCORRUPTED;
+
+	if (!fuse_inode_caches_iomaps(inode))
+		return 0;
+
+	fuse_iomap_cache_lock(inode);
+	if (outarg->read.length)
+		ret2 = fuse_iomap_cache_remove(inode, READ_MAPPING,
+					       outarg->read.offset,
+					       outarg->read.length);
+	if (outarg->write.length)
+		ret = fuse_iomap_cache_remove(inode, WRITE_MAPPING,
+					      outarg->write.offset,
+					      outarg->write.length);
+	fuse_iomap_cache_unlock(inode);
+
+	return ret ? ret : ret2;
+}
+
+int fuse_iomap_inval_mappings(struct fuse_conn *fc,
+		const struct fuse_iomap_inval_mappings_out *outarg)
+{
+	struct inode *inode;
+	struct fuse_inode *fi;
+	int ret;
+
+	if (!fc->iomap)
+		return -EINVAL;
+
+	down_read(&fc->killsb);
+	inode = fuse_ilookup(fc, outarg->nodeid, NULL);
+	if (!inode) {
+		ret = -ESTALE;
+		goto out_sb;
+	}
+
+	fi = get_fuse_inode(inode);
+	if (BAD_DATA(fi->orig_ino != outarg->attr_ino)) {
+		ret = -EINVAL;
+		goto out_inode;
+	}
+
+	if (fuse_is_bad(inode)) {
+		ret = -EIO;
+		goto out_inode;
+	}
+
+	ret = fuse_iomap_inval_inode(inode, outarg);
+out_inode:
+	iput(inode);
+out_sb:
+	up_read(&fc->killsb);
+	return ret;
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 08/12] fuse_trace: enable iomap cache management
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (6 preceding siblings ...)
  2026-02-23 23:22   ` [PATCH 07/12] fuse: enable iomap cache management Darrick J. Wong
@ 2026-02-23 23:22   ` Darrick J. Wong
  2026-02-23 23:22   ` [PATCH 09/12] fuse: overlay iomap inode info in struct fuse_inode Darrick J. Wong
                     ` (3 subsequent siblings)
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:22 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    4 +++
 2 files changed, 71 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index ddcbefd33a4024..09da9bce61b98c 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -405,6 +405,7 @@ struct fuse_iomap_lookup;
 #define FUSE_IOMAP_TYPE_STRINGS \
 	{ FUSE_IOMAP_TYPE_PURE_OVERWRITE,	"overwrite" }, \
 	{ FUSE_IOMAP_TYPE_RETRY_CACHE,		"retry" }, \
+	{ FUSE_IOMAP_TYPE_NOCACHE,		"nocache" }, \
 	{ FUSE_IOMAP_TYPE_HOLE,			"hole" }, \
 	{ FUSE_IOMAP_TYPE_DELALLOC,		"delalloc" }, \
 	{ FUSE_IOMAP_TYPE_MAPPED,		"mapped" }, \
@@ -1563,6 +1564,72 @@ TRACE_EVENT(fuse_iomap_invalid,
 		  __entry->old_validity_cookie,
 		  __entry->validity_cookie)
 );
+
+TRACE_EVENT(fuse_iomap_upsert_mappings,
+	TP_PROTO(const struct inode *inode,
+		 const struct fuse_iomap_upsert_mappings_out *outarg),
+	TP_ARGS(inode, outarg),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		__field(uint64_t,		attr_ino)
+
+		FUSE_IOMAP_MAP_FIELDS(read)
+		FUSE_IOMAP_MAP_FIELDS(write)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->attr_ino	=	outarg->attr_ino;
+		__entry->readoffset	=	outarg->read.offset;
+		__entry->readlength	=	outarg->read.length;
+		__entry->readaddr	=	outarg->read.addr;
+		__entry->readtype	=	outarg->read.type;
+		__entry->readflags	=	outarg->read.flags;
+		__entry->readdev	=	outarg->read.dev;
+		__entry->writeoffset	=	outarg->write.offset;
+		__entry->writelength	=	outarg->write.length;
+		__entry->writeaddr	=	outarg->write.addr;
+		__entry->writetype	=	outarg->write.type;
+		__entry->writeflags	=	outarg->write.flags;
+		__entry->writedev	=	outarg->write.dev;
+	),
+
+	TP_printk(FUSE_INODE_FMT " attr_ino 0x%llx" FUSE_IOMAP_MAP_FMT("read") FUSE_IOMAP_MAP_FMT("write"),
+		  FUSE_INODE_PRINTK_ARGS,
+		  __entry->attr_ino,
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(read),
+		  FUSE_IOMAP_MAP_PRINTK_ARGS(write))
+);
+
+TRACE_EVENT(fuse_iomap_inval_mappings,
+	TP_PROTO(const struct inode *inode,
+		 const struct fuse_iomap_inval_mappings_out *outarg),
+	TP_ARGS(inode, outarg),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+		__field(uint64_t,		attr_ino)
+
+		FUSE_FILE_RANGE_FIELDS(read)
+		FUSE_FILE_RANGE_FIELDS(write)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->attr_ino	=	outarg->attr_ino;
+		__entry->readoffset	=	outarg->read.offset;
+		__entry->readlength	=	outarg->read.length;
+		__entry->writeoffset	=	outarg->write.offset;
+		__entry->writelength	=	outarg->write.length;
+	),
+
+	TP_printk(FUSE_INODE_FMT " attr_ino 0x%llx" FUSE_FILE_RANGE_FMT("read") FUSE_FILE_RANGE_FMT("write"),
+		  FUSE_INODE_PRINTK_ARGS,
+		  __entry->attr_ino,
+		  FUSE_FILE_RANGE_PRINTK_ARGS(read),
+		  FUSE_FILE_RANGE_PRINTK_ARGS(write))
+);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 478c11b90ad4aa..2e428b6e6b0ce6 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -2781,6 +2781,8 @@ int fuse_iomap_upsert_mappings(struct fuse_conn *fc,
 		goto out_sb;
 	}
 
+	trace_fuse_iomap_upsert_mappings(inode, outarg);
+
 	fi = get_fuse_inode(inode);
 	if (BAD_DATA(fi->orig_ino != outarg->attr_ino)) {
 		ret = -EINVAL;
@@ -2868,6 +2870,8 @@ int fuse_iomap_inval_mappings(struct fuse_conn *fc,
 		goto out_sb;
 	}
 
+	trace_fuse_iomap_inval_mappings(inode, outarg);
+
 	fi = get_fuse_inode(inode);
 	if (BAD_DATA(fi->orig_ino != outarg->attr_ino)) {
 		ret = -EINVAL;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 09/12] fuse: overlay iomap inode info in struct fuse_inode
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (7 preceding siblings ...)
  2026-02-23 23:22   ` [PATCH 08/12] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:22   ` Darrick J. Wong
  2026-02-23 23:23   ` [PATCH 10/12] fuse: constrain iomap mapping cache size Darrick J. Wong
                     ` (2 subsequent siblings)
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:22 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

It's not possible for a regular file to use iomap mode and writeback
caching at the same time, so we can save some memory in struct
fuse_inode by overlaying them in the union.  This is a separate patch
because C unions are rather unsafe and I prefer any errors to be
bisectable to this patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 1ba95d1f430c3e..f6725d699b3e26 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -188,8 +188,11 @@ struct fuse_inode {
 
 			/* waitq for direct-io completion */
 			wait_queue_head_t direct_io_waitq;
+		};
 
 #ifdef CONFIG_FUSE_IOMAP
+		/* regular file iomap mode */
+		struct {
 			/* file size as reported by fuse server */
 			loff_t i_disk_size;
 
@@ -200,8 +203,8 @@ struct fuse_inode {
 
 			/* cached iomap mappings */
 			struct fuse_iomap_cache *cache;
-#endif
 		};
+#endif
 
 		/* readdir cache (directory only) */
 		struct {


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 10/12] fuse: constrain iomap mapping cache size
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (8 preceding siblings ...)
  2026-02-23 23:22   ` [PATCH 09/12] fuse: overlay iomap inode info in struct fuse_inode Darrick J. Wong
@ 2026-02-23 23:23   ` Darrick J. Wong
  2026-02-23 23:23   ` [PATCH 11/12] fuse_trace: " Darrick J. Wong
  2026-02-23 23:23   ` [PATCH 12/12] fuse: enable iomap Darrick J. Wong
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:23 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Provide a means to constrain the size of each iomap mapping cache.
Most files (at least on XFS) don't have more than 1000 extents, so we'll
set the absolute maximum to 10000 and let the fuse server set a lower
limit if it so desires.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h           |    3 +++
 fs/fuse/fuse_iomap_cache.h |    8 ++++++++
 include/uapi/linux/fuse.h  |    7 ++++++-
 fs/fuse/fuse_iomap.c       |    9 ++++++++-
 fs/fuse/fuse_iomap_cache.c |   24 ++++++++++++++++++++++++
 5 files changed, 49 insertions(+), 2 deletions(-)


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index f6725d699b3e26..5c10be0d02538e 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -683,6 +683,9 @@ struct fuse_iomap_conn {
 
 	/* fuse server doesn't implement iomap_ioend */
 	unsigned int no_ioend:1;
+
+	/* maximum mapping cache size */
+	unsigned int cache_maxbytes;
 };
 #endif
 
diff --git a/fs/fuse/fuse_iomap_cache.h b/fs/fuse/fuse_iomap_cache.h
index eba90d9519b8c3..cb312b0720d6b7 100644
--- a/fs/fuse/fuse_iomap_cache.h
+++ b/fs/fuse/fuse_iomap_cache.h
@@ -108,6 +108,14 @@ static inline int fuse_iomap_cache_invalidate(struct inode *inode,
 	return fuse_iomap_cache_invalidate_range(inode, offset,
 						 FUSE_IOMAP_INVAL_TO_EOF);
 }
+
+/* absolute maximum memory consumption per iomap mapping cache */
+#define FUSE_IOMAP_CACHE_MAX_MAXBYTES		(SZ_2M)
+
+/* default maximum memory consumption per iomap mapping cache */
+#define FUSE_IOMAP_CACHE_DEFAULT_MAXBYTES	(SZ_256K)
+
+void fuse_iomap_cache_set_maxbytes(struct fuse_conn *fc, unsigned int maxbytes);
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_CACHE_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 8c5e67731b21b8..035e1a59ce50d3 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1512,7 +1512,9 @@ struct fuse_iomap_ioend_out {
 struct fuse_iomap_config_in {
 	uint64_t flags;		/* supported FUSE_IOMAP_CONFIG_* flags */
 	int64_t maxbytes;	/* maximum supported file size */
-	uint64_t padding[6];	/* zero */
+	uint32_t cache_maxbytes; /* mapping cache maxbytes */
+	uint32_t zero;		/* zero */
+	uint64_t padding[5];	/* zero */
 };
 
 /* Which fields are set in fuse_iomap_config_out? */
@@ -1522,6 +1524,7 @@ struct fuse_iomap_config_in {
 #define FUSE_IOMAP_CONFIG_MAX_LINKS	(1 << 3ULL)
 #define FUSE_IOMAP_CONFIG_TIME		(1 << 4ULL)
 #define FUSE_IOMAP_CONFIG_MAXBYTES	(1 << 5ULL)
+#define FUSE_IOMAP_CONFIG_CACHE_MAXBYTES (1 << 6ULL)
 
 struct fuse_iomap_config_out {
 	uint64_t flags;		/* FUSE_IOMAP_CONFIG_* */
@@ -1544,6 +1547,8 @@ struct fuse_iomap_config_out {
 	int64_t s_time_max;
 
 	int64_t s_maxbytes;	/* max file size */
+
+	uint32_t cache_maxbytes; /* mapping cache maximum size */
 };
 
 struct fuse_range {
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 2e428b6e6b0ce6..8fad9278293bff 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -1141,7 +1141,8 @@ struct fuse_iomap_config_args {
 			       FUSE_IOMAP_CONFIG_BLOCKSIZE | \
 			       FUSE_IOMAP_CONFIG_MAX_LINKS | \
 			       FUSE_IOMAP_CONFIG_TIME | \
-			       FUSE_IOMAP_CONFIG_MAXBYTES)
+			       FUSE_IOMAP_CONFIG_MAXBYTES | \
+			       FUSE_IOMAP_CONFIG_CACHE_MAXBYTES)
 
 static int fuse_iomap_process_config(struct fuse_mount *fm, int error,
 				     const struct fuse_iomap_config_out *outarg)
@@ -1206,6 +1207,9 @@ static int fuse_iomap_process_config(struct fuse_mount *fm, int error,
 	if (outarg->flags & FUSE_IOMAP_CONFIG_MAXBYTES)
 		sb->s_maxbytes = outarg->s_maxbytes;
 
+	if (outarg->flags & FUSE_IOMAP_CONFIG_CACHE_MAXBYTES)
+		fuse_iomap_cache_set_maxbytes(fm->fc, outarg->cache_maxbytes);
+
 	return 0;
 }
 
@@ -1267,6 +1271,9 @@ fuse_iomap_new_mount(struct fuse_mount *fm)
 	ia->inarg.maxbytes = MAX_LFS_FILESIZE;
 	ia->inarg.flags = FUSE_IOMAP_CONFIG_ALL;
 
+	fm->fc->iomap_conn.cache_maxbytes = FUSE_IOMAP_CACHE_DEFAULT_MAXBYTES;
+	ia->inarg.cache_maxbytes = fm->fc->iomap_conn.cache_maxbytes;
+
 	ia->args.opcode = FUSE_IOMAP_CONFIG;
 	ia->args.nodeid = 0;
 	ia->args.in_numargs = 1;
diff --git a/fs/fuse/fuse_iomap_cache.c b/fs/fuse/fuse_iomap_cache.c
index 277311c7c0c4ea..b9e6083a18ce63 100644
--- a/fs/fuse/fuse_iomap_cache.c
+++ b/fs/fuse/fuse_iomap_cache.c
@@ -1654,6 +1654,28 @@ void fuse_iomap_cache_free(struct inode *inode)
 	kfree(ic);
 }
 
+void fuse_iomap_cache_set_maxbytes(struct fuse_conn *fc, unsigned int maxbytes)
+{
+	if (!maxbytes)
+		return;
+
+	fc->iomap_conn.cache_maxbytes = clamp(maxbytes, NODE_SIZE,
+					      FUSE_IOMAP_CACHE_MAX_MAXBYTES);
+}
+
+static void
+fuse_iomap_cache_cleanup(
+	struct inode		*inode,
+	enum fuse_iomap_iodir	iodir)
+{
+	struct fuse_inode	*fi = get_fuse_inode(inode);
+	struct fuse_mount	*fm = get_fuse_mount(inode);
+	struct fuse_iext_root	*ir = fuse_iext_root_ptr(fi->cache, iodir);
+
+	if (ir && ir->ir_bytes > fm->fc->iomap_conn.cache_maxbytes)
+		fuse_iext_destroy(ir);
+}
+
 int
 fuse_iomap_cache_upsert(
 	struct inode			*inode,
@@ -1680,6 +1702,8 @@ fuse_iomap_cache_upsert(
 	if (err)
 		return err;
 
+	fuse_iomap_cache_cleanup(inode, iodir);
+
 	return fuse_iomap_cache_add(inode, iodir, map);
 }
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 11/12] fuse_trace: constrain iomap mapping cache size
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (9 preceding siblings ...)
  2026-02-23 23:23   ` [PATCH 10/12] fuse: constrain iomap mapping cache size Darrick J. Wong
@ 2026-02-23 23:23   ` Darrick J. Wong
  2026-02-23 23:23   ` [PATCH 12/12] fuse: enable iomap Darrick J. Wong
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:23 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h       |   31 +++++++++++++++++++++++++++++--
 fs/fuse/fuse_iomap_cache.c |    4 +++-
 2 files changed, 32 insertions(+), 3 deletions(-)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 09da9bce61b98c..aa2d5ca88c9d40 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -320,6 +320,7 @@ struct iomap_ioend;
 struct iomap;
 struct fuse_iext_cursor;
 struct fuse_iomap_lookup;
+struct fuse_iext_root;
 
 /* tracepoint boilerplate so we don't have to keep doing this */
 #define FUSE_IOMAP_OPFLAGS_FIELD \
@@ -1157,6 +1158,8 @@ TRACE_EVENT(fuse_iomap_config,
 		__field(int64_t,		time_max)
 		__field(int64_t,		maxbytes)
 		__field(uint8_t,		uuid_len)
+
+		__field(uint32_t,		cache_maxbytes)
 	),
 
 	TP_fast_assign(
@@ -1170,14 +1173,15 @@ TRACE_EVENT(fuse_iomap_config,
 		__entry->time_max	=	outarg->s_time_max;
 		__entry->maxbytes	=	outarg->s_maxbytes;
 		__entry->uuid_len	=	outarg->s_uuid_len;
+		__entry->cache_maxbytes	=	outarg->cache_maxbytes;
 	),
 
-	TP_printk("connection %u root_ino 0x%llx flags (%s) blocksize 0x%x max_links %u time_gran %u time_min %lld time_max %lld maxbytes 0x%llx uuid_len %u",
+	TP_printk("connection %u root_ino 0x%llx flags (%s) blocksize 0x%x max_links %u time_gran %u time_min %lld time_max %lld maxbytes 0x%llx uuid_len %u cache_maxbytes %u",
 		  __entry->connection, __entry->root_nodeid,
 		  __print_flags(__entry->flags, "|", FUSE_IOMAP_CONFIG_STRINGS),
 		  __entry->blocksize, __entry->max_links, __entry->time_gran,
 		  __entry->time_min, __entry->time_max, __entry->maxbytes,
-		  __entry->uuid_len)
+		  __entry->uuid_len, __entry->cache_maxbytes)
 );
 
 TRACE_EVENT(fuse_iomap_dev_inval,
@@ -1395,6 +1399,29 @@ DEFINE_IEXT_ALT_UPDATE_EVENT(fuse_iext_del_mapping_got);
 DEFINE_IEXT_ALT_UPDATE_EVENT(fuse_iext_add_mapping_left);
 DEFINE_IEXT_ALT_UPDATE_EVENT(fuse_iext_add_mapping_right);
 
+TRACE_EVENT(fuse_iomap_cache_cleanup,
+	TP_PROTO(const struct inode *inode, unsigned int iodir,
+		 struct fuse_iext_root *ir),
+	TP_ARGS(inode, iodir, ir),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		FUSE_IOMAP_IODIR_FIELD
+		__field(unsigned long long,	bytes)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->iodir		=	iodir;
+		__entry->bytes		=	ir->ir_bytes;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() FUSE_IOMAP_IODIR_FMT " bytes 0x%llx",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  FUSE_IOMAP_IODIR_PRINTK_ARGS,
+		  __entry->bytes)
+);
+
 TRACE_EVENT(fuse_iomap_cache_remove,
 	TP_PROTO(const struct inode *inode, unsigned int iodir,
 		 loff_t offset, uint64_t length, unsigned long caller_ip),
diff --git a/fs/fuse/fuse_iomap_cache.c b/fs/fuse/fuse_iomap_cache.c
index b9e6083a18ce63..7f79ea4197e676 100644
--- a/fs/fuse/fuse_iomap_cache.c
+++ b/fs/fuse/fuse_iomap_cache.c
@@ -1672,8 +1672,10 @@ fuse_iomap_cache_cleanup(
 	struct fuse_mount	*fm = get_fuse_mount(inode);
 	struct fuse_iext_root	*ir = fuse_iext_root_ptr(fi->cache, iodir);
 
-	if (ir && ir->ir_bytes > fm->fc->iomap_conn.cache_maxbytes)
+	if (ir && ir->ir_bytes > fm->fc->iomap_conn.cache_maxbytes) {
+		trace_fuse_iomap_cache_cleanup(inode, iodir, ir);
 		fuse_iext_destroy(ir);
+	}
 }
 
 int


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 12/12] fuse: enable iomap
  2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (10 preceding siblings ...)
  2026-02-23 23:23   ` [PATCH 11/12] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:23   ` Darrick J. Wong
  11 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:23 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Remove the guard that we used to avoid bisection problems.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.c |    3 ---
 1 file changed, 3 deletions(-)


diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 8fad9278293bff..74bd18bb4009c6 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -70,9 +70,6 @@ MODULE_PARM_DESC(debug_iomap, "Enable debugging of fuse iomap");
 
 bool fuse_iomap_enabled(void)
 {
-	/* Don't let anyone touch iomap until the end of the patchset. */
-	return false;
-
 	/*
 	 * There are fears that a fuse+iomap server could somehow DoS the
 	 * system by doing things like going out to lunch during a writeback


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/2] fuse: allow privileged mount helpers to pre-approve iomap usage
  2026-02-23 23:02 ` [PATCHSET v7 8/9] fuse: run fuse servers as a contained service Darrick J. Wong
@ 2026-02-23 23:23   ` Darrick J. Wong
  2026-02-23 23:24   ` [PATCH 2/2] fuse: set iomap backing device block size Darrick J. Wong
  1 sibling, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:23 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

For the upcoming safemount functionality in libfuse, we will create a
privileged "mount.safe" helper that starts the fuse server in a
completely unprivileged systemd container.  The mount helper will pass
the mount options and fds for /dev/fuse and any other files requested by
the fuse server into the container via a Unix socket.

Currently, the ability to turn on iomap for fuse depends on a module
parameter and the process that calls mount() having the CAP_SYS_RAWIO
capability.  However, the unprivilged fuse server might want to query
the /dev/fuse fd for iomap capabilities before mount or FUSE_INIT so
that it can get ready.

Similar to FUSE_DEV_SYNC_INIT, add a new bit for iomap that can be
squirreled away in file->private_data and an ioctl to set that bit.
That way the privileged mount helper can pass its iomap privilege to the
contained fuse server without the fuse server needing to have
CAP_SYS_RAWIO.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_dev_i.h      |   32 +++++++++++++++++++++++++++++---
 fs/fuse/fuse_i.h          |    7 +++++++
 fs/fuse/fuse_iomap.h      |    2 ++
 include/uapi/linux/fuse.h |    1 +
 fs/fuse/dev.c             |   11 +++++------
 fs/fuse/fuse_iomap.c      |   45 +++++++++++++++++++++++++++++++++++++++++++--
 fs/fuse/inode.c           |   18 ++++++++++++------
 7 files changed, 99 insertions(+), 17 deletions(-)


diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h
index 134bf44aff0d39..900c0ce2ffa96e 100644
--- a/fs/fuse/fuse_dev_i.h
+++ b/fs/fuse/fuse_dev_i.h
@@ -39,8 +39,10 @@ struct fuse_copy_state {
 	} ring;
 };
 
-#define FUSE_DEV_SYNC_INIT ((struct fuse_dev *) 1)
-#define FUSE_DEV_PTR_MASK (~1UL)
+#define FUSE_DEV_SYNC_INIT	(1UL << 0)
+#define FUSE_DEV_INHERIT_IOMAP	(1UL << 1)
+#define FUSE_DEV_FLAGS_MASK	(FUSE_DEV_SYNC_INIT | FUSE_DEV_INHERIT_IOMAP)
+#define FUSE_DEV_PTR_MASK	(~FUSE_DEV_FLAGS_MASK)
 
 static inline struct fuse_dev *__fuse_get_dev(struct file *file)
 {
@@ -50,7 +52,31 @@ static inline struct fuse_dev *__fuse_get_dev(struct file *file)
 	 */
 	struct fuse_dev *fud = READ_ONCE(file->private_data);
 
-	return (typeof(fud)) ((unsigned long) fud & FUSE_DEV_PTR_MASK);
+	return (typeof(fud)) ((uintptr_t)fud & FUSE_DEV_PTR_MASK);
+}
+
+static inline struct fuse_dev *__fuse_get_dev_and_flags(struct file *file,
+							uintptr_t *flagsp)
+{
+	/*
+	 * Lockless access is OK, because file->private data is set
+	 * once during mount and is valid until the file is released.
+	 */
+	struct fuse_dev *fud = READ_ONCE(file->private_data);
+
+	*flagsp = ((uintptr_t)fud) & FUSE_DEV_FLAGS_MASK;
+	return (typeof(fud)) ((uintptr_t) fud & FUSE_DEV_PTR_MASK);
+}
+
+static inline int __fuse_set_dev_flags(struct file *file, uintptr_t flag)
+{
+	uintptr_t old_flags = 0;
+
+	if (__fuse_get_dev_and_flags(file, &old_flags))
+		return -EINVAL;
+
+	WRITE_ONCE(file->private_data, (struct fuse_dev *)(old_flags | flag));
+	return 0;
 }
 
 struct fuse_dev *fuse_get_dev(struct file *file);
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 5c10be0d02538e..5f2e7755e3e4e4 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -982,6 +982,13 @@ struct fuse_conn {
 	/* Enable fs/iomap for file operations */
 	unsigned int iomap:1;
 
+	/*
+	 * Are filesystems using this connection allowed to use iomap?  This is
+	 * determined by the privilege level of the process that initiated the
+	 * mount() call.
+	 */
+	unsigned int may_iomap:1;
+
 	/* Use io_uring for communication */
 	unsigned int io_uring;
 
diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index b13d305ee0508b..6afc916e31a4fa 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -71,6 +71,7 @@ int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
 void fuse_iomap_copied_file_range(struct inode *inode, loff_t offset,
 				  u64 written);
 
+int fuse_dev_ioctl_add_iomap(struct file *file);
 int fuse_dev_ioctl_iomap_support(struct file *file,
 				 struct fuse_iomap_support __user *argp);
 int fuse_iomap_dev_inval(struct fuse_conn *fc,
@@ -108,6 +109,7 @@ int fuse_iomap_inval_mappings(struct fuse_conn *fc,
 # define fuse_iomap_fallocate(...)		(-ENOSYS)
 # define fuse_iomap_flush_unmap_range(...)	(-ENOSYS)
 # define fuse_iomap_copied_file_range(...)	((void)0)
+# define fuse_dev_ioctl_add_iomap(...)		(-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
 # define fuse_iomap_dev_inval(...)		(-ENOSYS)
 # define fuse_iomap_fadvise			NULL
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 035e1a59ce50d3..1132493c66d266 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1212,6 +1212,7 @@ struct fuse_iomap_support {
 #define FUSE_DEV_IOC_IOMAP_SUPPORT	_IOR(FUSE_DEV_IOC_MAGIC, 99, \
 					     struct fuse_iomap_support)
 #define FUSE_DEV_IOC_SET_NOFS		_IOW(FUSE_DEV_IOC_MAGIC, 100, uint32_t)
+#define FUSE_DEV_IOC_ADD_IOMAP		_IO(FUSE_DEV_IOC_MAGIC, 101)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index b2433dec8cc5e5..f4ca408653cf61 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1559,7 +1559,7 @@ struct fuse_dev *fuse_get_dev(struct file *file)
 		return fud;
 
 	err = wait_event_interruptible(fuse_dev_waitq,
-				       READ_ONCE(file->private_data) != FUSE_DEV_SYNC_INIT);
+				       __fuse_get_dev(file) != NULL);
 	if (err)
 		return ERR_PTR(err);
 
@@ -2757,13 +2757,10 @@ 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;
+	int err;
 
 	mutex_lock(&fuse_mutex);
-	if (!__fuse_get_dev(file)) {
-		WRITE_ONCE(file->private_data, FUSE_DEV_SYNC_INIT);
-		err = 0;
-	}
+	err = __fuse_set_dev_flags(file, FUSE_DEV_SYNC_INIT);
 	mutex_unlock(&fuse_mutex);
 	return err;
 }
@@ -2790,6 +2787,8 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
 		return fuse_dev_ioctl_iomap_support(file, argp);
 	case FUSE_DEV_IOC_SET_NOFS:
 		return fuse_dev_ioctl_iomap_set_nofs(file, argp);
+	case FUSE_DEV_IOC_ADD_IOMAP:
+		return fuse_dev_ioctl_add_iomap(file);
 
 	default:
 		return -ENOTTY;
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 74bd18bb4009c6..ca37eb93d71a43 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -10,6 +10,7 @@
 #include <linux/fadvise.h>
 #include <linux/swap.h>
 #include "fuse_i.h"
+#include "fuse_dev_i.h"
 #include "fuse_trace.h"
 #include "fuse_iomap.h"
 #include "fuse_iomap_i.h"
@@ -80,6 +81,12 @@ bool fuse_iomap_enabled(void)
 	return enable_iomap && has_capability_noaudit(current, CAP_SYS_RAWIO);
 }
 
+static inline bool fuse_iomap_may_enable(void)
+{
+	/* Same as above, but this time we log the denial in audit log */
+	return enable_iomap && capable(CAP_SYS_RAWIO);
+}
+
 /* Convert IOMAP_* mapping types to FUSE_IOMAP_TYPE_* */
 #define XMAP(word) \
 	case IOMAP_##word: \
@@ -2526,12 +2533,46 @@ fuse_iomap_fallocate(
 	return 0;
 }
 
+int fuse_dev_ioctl_add_iomap(struct file *file)
+{
+	uintptr_t flags = 0;
+	struct fuse_dev *fud;
+	int ret = 0;
+
+	mutex_lock(&fuse_mutex);
+	fud = __fuse_get_dev_and_flags(file, &flags);
+	if (fud) {
+		if (!fud->fc->may_iomap && !fuse_iomap_may_enable()) {
+			ret = -EPERM;
+			goto out_unlock;
+		}
+
+		fud->fc->may_iomap = 1;
+		goto out_unlock;
+	}
+
+	if (!(flags & FUSE_DEV_INHERIT_IOMAP) && !fuse_iomap_may_enable()) {
+		ret = -EPERM;
+		goto out_unlock;
+	}
+
+	ret = __fuse_set_dev_flags(file, FUSE_DEV_INHERIT_IOMAP);
+
+out_unlock:
+	mutex_unlock(&fuse_mutex);
+	return ret;
+}
+
 int fuse_dev_ioctl_iomap_support(struct file *file,
 				 struct fuse_iomap_support __user *argp)
 {
 	struct fuse_iomap_support ios = { };
+	uintptr_t flags = 0;
+	struct fuse_dev *fud = __fuse_get_dev_and_flags(file, &flags);
 
-	if (fuse_iomap_enabled())
+	if ((!fud && (flags & FUSE_DEV_INHERIT_IOMAP)) ||
+	    (fud && fud->fc->may_iomap) ||
+	    fuse_iomap_enabled())
 		ios.flags = FUSE_IOMAP_SUPPORT_FILEIO |
 			    FUSE_IOMAP_SUPPORT_ATOMIC;
 
@@ -2604,7 +2645,7 @@ int fuse_iomap_dev_inval(struct fuse_conn *fc,
 
 static inline bool can_set_nofs(struct fuse_dev *fud)
 {
-	if (fud && fud->fc && fud->fc->iomap)
+	if (fud && fud->fc && (fud->fc->iomap || fud->fc->may_iomap))
 	       return true;
 
 	return capable(CAP_SYS_RESOURCE);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 1fedfb57a22514..0f2b12aa1ac4bb 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1047,6 +1047,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
 	fc->name_max = FUSE_NAME_LOW_MAX;
 	fc->timeout.req_timeout = 0;
 	fc->root_nodeid = FUSE_ROOT_ID;
+	fc->may_iomap = fuse_iomap_enabled();
 
 	if (IS_ENABLED(CONFIG_FUSE_BACKING))
 		fuse_backing_files_init(fc);
@@ -1581,7 +1582,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 			if (flags & FUSE_REQUEST_TIMEOUT)
 				timeout = arg->request_timeout;
 
-			if ((flags & FUSE_IOMAP) && fuse_iomap_enabled()) {
+			if ((flags & FUSE_IOMAP) && fc->may_iomap) {
 				fc->iomap = 1;
 				pr_warn(
  "EXPERIMENTAL iomap feature enabled.  Use at your own risk!");
@@ -1668,7 +1669,7 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)
 	 */
 	if (fuse_uring_enabled())
 		flags |= FUSE_OVER_IO_URING;
-	if (fuse_iomap_enabled())
+	if (fm->fc->may_iomap)
 		flags |= FUSE_IOMAP;
 
 	ia->in.flags = flags;
@@ -2041,11 +2042,16 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
 
 	mutex_lock(&fuse_mutex);
 	err = -EINVAL;
-	if (ctx->fudptr && *ctx->fudptr) {
-		if (*ctx->fudptr == FUSE_DEV_SYNC_INIT)
-			fc->sync_init = 1;
-		else
+	if (ctx->fudptr) {
+		uintptr_t raw = (uintptr_t)(*ctx->fudptr);
+		uintptr_t flags = raw & FUSE_DEV_FLAGS_MASK;
+
+		if (raw & FUSE_DEV_PTR_MASK)
 			goto err_unlock;
+		if (flags & FUSE_DEV_SYNC_INIT)
+			fc->sync_init = 1;
+		if (flags & FUSE_DEV_INHERIT_IOMAP)
+			fc->may_iomap = 1;
 	}
 
 	err = fuse_ctl_add_conn(fc);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/2] fuse: set iomap backing device block size
  2026-02-23 23:02 ` [PATCHSET v7 8/9] fuse: run fuse servers as a contained service Darrick J. Wong
  2026-02-23 23:23   ` [PATCH 1/2] fuse: allow privileged mount helpers to pre-approve iomap usage Darrick J. Wong
@ 2026-02-23 23:24   ` Darrick J. Wong
  1 sibling, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:24 UTC (permalink / raw)
  To: miklos, djwong; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add a new ioctl so that an unprivileged fuse server can set the block
size of a bdev that's opened for iomap usage.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap.h      |    3 +++
 include/uapi/linux/fuse.h |    7 +++++++
 fs/fuse/dev.c             |    2 ++
 fs/fuse/fuse_iomap.c      |   27 +++++++++++++++++++++++++++
 4 files changed, 39 insertions(+)


diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
index 6afc916e31a4fa..f61e99941e94cb 100644
--- a/fs/fuse/fuse_iomap.h
+++ b/fs/fuse/fuse_iomap.h
@@ -74,6 +74,8 @@ void fuse_iomap_copied_file_range(struct inode *inode, loff_t offset,
 int fuse_dev_ioctl_add_iomap(struct file *file);
 int fuse_dev_ioctl_iomap_support(struct file *file,
 				 struct fuse_iomap_support __user *argp);
+int fuse_dev_ioctl_iomap_set_blocksize(struct file *file,
+				struct fuse_iomap_backing_info __user *argp);
 int fuse_iomap_dev_inval(struct fuse_conn *fc,
 			 const struct fuse_iomap_dev_inval_out *arg);
 
@@ -111,6 +113,7 @@ int fuse_iomap_inval_mappings(struct fuse_conn *fc,
 # define fuse_iomap_copied_file_range(...)	((void)0)
 # define fuse_dev_ioctl_add_iomap(...)		(-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
+# define fuse_dev_ioctl_iomap_set_blocksize(...) (-EOPNOTSUPP)
 # define fuse_iomap_dev_inval(...)		(-ENOSYS)
 # define fuse_iomap_fadvise			NULL
 # define fuse_dev_ioctl_iomap_set_nofs(...)	(-EOPNOTSUPP)
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 1132493c66d266..94e99a01af5da7 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1202,6 +1202,11 @@ struct fuse_iomap_support {
 	uint64_t	padding;
 };
 
+struct fuse_iomap_backing_info {
+	uint32_t	backing_id;
+	uint32_t	blocksize;
+};
+
 /* Device ioctls: */
 #define FUSE_DEV_IOC_MAGIC		229
 #define FUSE_DEV_IOC_CLONE		_IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
@@ -1213,6 +1218,8 @@ struct fuse_iomap_support {
 					     struct fuse_iomap_support)
 #define FUSE_DEV_IOC_SET_NOFS		_IOW(FUSE_DEV_IOC_MAGIC, 100, uint32_t)
 #define FUSE_DEV_IOC_ADD_IOMAP		_IO(FUSE_DEV_IOC_MAGIC, 101)
+#define FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE _IOW(FUSE_DEV_IOC_MAGIC, 102, \
+					      struct fuse_iomap_backing_info)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index f4ca408653cf61..60327b5609fe74 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2789,6 +2789,8 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
 		return fuse_dev_ioctl_iomap_set_nofs(file, argp);
 	case FUSE_DEV_IOC_ADD_IOMAP:
 		return fuse_dev_ioctl_add_iomap(file);
+	case FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE:
+		return fuse_dev_ioctl_iomap_set_blocksize(file, argp);
 
 	default:
 		return -ENOTTY;
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index ca37eb93d71a43..7bc938cd859fae 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -2935,3 +2935,30 @@ int fuse_iomap_inval_mappings(struct fuse_conn *fc,
 	up_read(&fc->killsb);
 	return ret;
 }
+
+int fuse_dev_ioctl_iomap_set_blocksize(struct file *file,
+				struct fuse_iomap_backing_info __user *argp)
+{
+	struct fuse_iomap_backing_info fbi;
+	struct fuse_dev *fud = fuse_get_dev(file);
+	struct fuse_backing *fb;
+	int ret;
+
+	if (IS_ERR(fud))
+		return PTR_ERR(fud);
+
+	if (!fud->fc->iomap)
+		return -EOPNOTSUPP;
+
+	if (copy_from_user(&fbi, argp, sizeof(fbi)))
+		return -EFAULT;
+
+	fb = fuse_backing_lookup(fud->fc, &fuse_iomap_backing_ops,
+				 fbi.backing_id);
+	if (!fb)
+		return -ENOENT;
+
+	ret = set_blocksize(fb->file, fbi.blocksize);
+	fuse_backing_put(fb);
+	return ret;
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/5] fuse: enable fuse servers to upload BPF programs to handle iomap requests
  2026-02-23 23:02 ` [PATCHSET RFC 9/9] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
@ 2026-02-23 23:24   ` Darrick J. Wong
  2026-02-23 23:24   ` [PATCH 2/5] fuse_trace: " Darrick J. Wong
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:24 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, bpf, john, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

There are certain fuse servers that might benefit from the ability to
upload a BPF program into the kernel to respond to ->iomap_begin
requests instead of upcalling the fuse server itself.

For example, consider a fuse server that abstracts a large amount of
storage for use as intermediate storage by programs.  If the storage is
striped across hardware devices (e.g. RAID0 or interleaved memory
controllers) then the iomapping pattern will be completely regular
but the mappings themselves might be very small.

Performance for large IOs will suck if it is necessary to upcall the
fuse server every time we cross a mapping boundary.  The fuse server can
try to mitigate that hit by upserting mappings ahead of time, but
there's a better solution for this usecase: BPF programs.

In this case, the fuse server can compile a BPF program that will
compute the mapping data for a given request and upload the program.
This avoids the overhead of cache lookups and server upcalls.  Note that
the BPF verifier still imposes instruction count and complexity limits
on the uploaded programs.

Note that I embraced and extended some code from Joanne, but at this
point I've modified it so heavily that it's not really the original
anymore.  But she still gets credit for coming up with the idea and
engaging me in flinging prototypes around.

Link: https://lore.kernel.org/linux-ext4/CAJnrk1ag3ffQC=U1ZXVLTipDyo1VBQBM3MYNB6=6d4ywLOEieA@mail.gmail.com/
Co-authored-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_i.h         |    5 +
 fs/fuse/fuse_iomap_bpf.h |   88 +++++++++++++
 fs/fuse/Makefile         |    4 +
 fs/fuse/fuse_iomap.c     |   13 +-
 fs/fuse/fuse_iomap_bpf.c |  309 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c          |    7 +
 6 files changed, 423 insertions(+), 3 deletions(-)
 create mode 100644 fs/fuse/fuse_iomap_bpf.h
 create mode 100644 fs/fuse/fuse_iomap_bpf.c


diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 5f2e7755e3e4e4..677e1fa4c8586c 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -686,6 +686,11 @@ struct fuse_iomap_conn {
 
 	/* maximum mapping cache size */
 	unsigned int cache_maxbytes;
+
+#ifdef CONFIG_BPF_SYSCALL
+	/* bpf iomap overrides for this fs */
+	struct fuse_iomap_bpf_ops __rcu *bpf_ops;
+#endif
 };
 #endif
 
diff --git a/fs/fuse/fuse_iomap_bpf.h b/fs/fuse/fuse_iomap_bpf.h
new file mode 100644
index 00000000000000..f6bfd2133bf2bb
--- /dev/null
+++ b/fs/fuse/fuse_iomap_bpf.h
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ * Copied from: Joanne Koong <joannelkoong@gmail.com>
+ */
+#ifndef _FS_FUSE_IOMAP_BPF_H
+#define _FS_FUSE_IOMAP_BPF_H
+
+#if IS_ENABLED(CONFIG_FUSE_IOMAP) && IS_ENABLED(CONFIG_BPF_SYSCALL)
+enum fuse_iomap_bpf_ret {
+	/* fall back to fuse server upcall */
+	FIB_FALLBACK = 0,
+	/* bpf function handled event completely */
+	FIB_HANDLED = 1,
+};
+
+struct fuse_iomap_bpf_ops {
+	/**
+	 * @iomap_begin: override iomap_begin.  See FUSE_IOMAP_BEGIN for
+	 * details.
+	 */
+	enum fuse_iomap_bpf_ret (*iomap_begin)(struct fuse_inode *fi,
+			uint64_t pos, uint64_t count, uint32_t opflags,
+			struct fuse_iomap_begin_out *outarg);
+
+	/**
+	 * @iomap_end: override iomap_end.  See FUSE_IOMAP_END for
+	 * details.
+	 */
+	enum fuse_iomap_bpf_ret (*iomap_end)(struct fuse_inode *fi,
+			uint64_t pos, uint64_t count, int64_t written,
+			uint32_t opflags);
+
+	/**
+	 * @iomap_ioend: override iomap_ioend.  See FUSE_IOMAP_IOEND for
+	 * details.
+	 */
+	enum fuse_iomap_bpf_ret (*iomap_ioend)(struct fuse_inode *fi,
+			uint64_t pos, int64_t written, uint32_t ioendflags,
+			int error, uint32_t dev, uint64_t new_addr,
+			struct fuse_iomap_ioend_out *outarg);
+
+	/**
+	 * @fuse_fd: file descriptor of the open fuse device
+	 */
+	int fuse_fd;
+
+	/**
+	 * @zeropad: Explicitly pad to zero.
+	 */
+	unsigned int zeropad;
+
+	/**
+	 * @name: string describing the fuse iomap bpf operations
+	 */
+	char name[16];
+
+	/* private: don't show fuse connection to the world */
+	struct fuse_conn *fc;
+
+	/*
+	 * private: number of iomap operations in progress, biased by one for
+	 * the fuse connection
+	 */
+	atomic_t users;
+};
+
+int fuse_iomap_init_bpf(void);
+void fuse_iomap_unmount_bpf(struct fuse_conn *fc);
+
+int fuse_iomap_begin_bpf(struct inode *inode,
+			 const struct fuse_iomap_begin_in *inarg,
+			 struct fuse_iomap_begin_out *outarg);
+int fuse_iomap_end_bpf(struct inode *inode,
+		       const struct fuse_iomap_end_in *inarg);
+int fuse_iomap_ioend_bpf(struct inode *inode,
+			 const struct fuse_iomap_ioend_in *inarg,
+			 struct fuse_iomap_ioend_out *outarg);
+#else
+# define fuse_iomap_init_bpf()		(0)
+# define fuse_iomap_unmount_bpf(...)	((void)0)
+# define fuse_iomap_begin_bpf(...)	(-ENOSYS)
+# define fuse_iomap_end_bpf(...)	(-ENOSYS)
+# define fuse_iomap_ioend_bpf(...)	(-ENOSYS)
+#endif /* CONFIG_FUSE_IOMAP && CONFIG_BPF_SYSCALL */
+
+#endif /* _FS_FUSE_IOMAP_BPF_H */
diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile
index c672503da7bcbd..43ba967db197b1 100644
--- a/fs/fuse/Makefile
+++ b/fs/fuse/Makefile
@@ -20,4 +20,8 @@ fuse-$(CONFIG_SYSCTL) += sysctl.o
 fuse-$(CONFIG_FUSE_IO_URING) += dev_uring.o
 fuse-$(CONFIG_FUSE_IOMAP) += fuse_iomap.o fuse_iomap_cache.o
 
+ifeq ($(CONFIG_BPF_SYSCALL),y)
+fuse-$(CONFIG_FUSE_IOMAP) += fuse_iomap_bpf.o
+endif
+
 virtiofs-y := virtio_fs.o
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 7bc938cd859fae..2e0c35e879ffcc 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -16,6 +16,7 @@
 #include "fuse_iomap_i.h"
 #include "fuse_dev_i.h"
 #include "fuse_iomap_cache.h"
+#include "fuse_iomap_bpf.h"
 
 static bool __read_mostly enable_iomap =
 #if IS_ENABLED(CONFIG_FUSE_IOMAP_BY_DEFAULT)
@@ -783,7 +784,9 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 	args.out_numargs = 1;
 	args.out_args[0].size = sizeof(outarg);
 	args.out_args[0].value = &outarg;
-	err = fuse_simple_request(fm, &args);
+	err = fuse_iomap_begin_bpf(inode, &inarg, &outarg);
+	if (err == -ENOSYS)
+		err = fuse_simple_request(fm, &args);
 	if (err) {
 		trace_fuse_iomap_begin_error(inode, pos, count, opflags, err);
 		return err;
@@ -938,7 +941,9 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
 		args.in_numargs = 1;
 		args.in_args[0].size = sizeof(inarg);
 		args.in_args[0].value = &inarg;
-		err = fuse_simple_request(fm, &args);
+		err = fuse_iomap_end_bpf(inode, &inarg);
+		if (err == -ENOSYS)
+			err = fuse_simple_request(fm, &args);
 		if (err == -ENOSYS) {
 			/*
 			 * libfuse returns ENOSYS for servers that don't
@@ -1047,7 +1052,9 @@ static int fuse_iomap_ioend(struct inode *inode, loff_t pos, size_t written,
 		args.out_numargs = 1;
 		args.out_args[0].size = sizeof(outarg);
 		args.out_args[0].value = &outarg;
-		iomap_error = fuse_simple_request(fm, &args);
+		iomap_error = fuse_iomap_ioend_bpf(inode, &inarg, &outarg);
+		if (iomap_error == -ENOSYS)
+			iomap_error = fuse_simple_request(fm, &args);
 		switch (iomap_error) {
 		case -ENOSYS:
 			/*
diff --git a/fs/fuse/fuse_iomap_bpf.c b/fs/fuse/fuse_iomap_bpf.c
new file mode 100644
index 00000000000000..b104f3961721b2
--- /dev/null
+++ b/fs/fuse/fuse_iomap_bpf.c
@@ -0,0 +1,309 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ * Copied from: Joanne Koong <joannelkoong@gmail.com>
+ */
+#include <linux/bpf.h>
+
+#include "fuse_i.h"
+#include "fuse_dev_i.h"
+#include "fuse_iomap_bpf.h"
+#include "fuse_iomap_i.h"
+#include "fuse_trace.h"
+
+/* spinlock for atomically updating fuse_conn <-> bpf_ops pointers */
+static DEFINE_SPINLOCK(fuse_iomap_bpf_ops_lock);
+
+/*
+ * The only structures that we provide to the BPF program are outparams, so
+ * they can write anything they want to it.
+ */
+static bool fuse_iomap_bpf_ops_is_valid_access(int off, int size,
+					       enum bpf_access_type type,
+					       const struct bpf_prog *prog,
+					       struct bpf_insn_access_aux *info)
+{
+	return bpf_tracing_btf_ctx_access(off, size, type, prog, info);
+}
+
+static int fuse_iomap_bpf_ops_check_member(const struct btf_type *t,
+					   const struct btf_member *member,
+					   const struct bpf_prog *prog)
+{
+	return 0;
+}
+
+static int fuse_iomap_bpf_ops_btf_struct_access(struct bpf_verifier_log *log,
+						const struct bpf_reg_state *reg,
+						int off, int size)
+{
+	return 0;
+}
+
+static const struct bpf_verifier_ops fuse_iomap_bpf_verifier_ops = {
+	.get_func_proto		= bpf_base_func_proto,
+	.is_valid_access	= fuse_iomap_bpf_ops_is_valid_access,
+	.btf_struct_access	= fuse_iomap_bpf_ops_btf_struct_access,
+};
+
+static int fuse_iomap_bpf_ops_init(struct btf *btf)
+{
+	return 0;
+}
+
+/* Copy data from userspace bpf ops to the kernel */
+static int fuse_iomap_bpf_ops_init_member(const struct btf_type *t,
+					  const struct btf_member *member,
+					  void *kdata, const void *udata)
+{
+	const struct fuse_iomap_bpf_ops *u_ops = udata;
+	struct fuse_iomap_bpf_ops *ops = kdata;
+	u32 moff;
+
+	/*
+	 * This function must copy all non-function-pointers by itself and
+	 * return 1 to indicate that the data has been handled by the
+	 * struct_ops type, or the verifier will reject the map if the value of
+	 * those fields is not zero.
+	 */
+	moff = __btf_member_bit_offset(t, member) / 8;
+	switch (moff) {
+	case offsetof(struct fuse_iomap_bpf_ops, fuse_fd):
+		ops->fuse_fd = u_ops->fuse_fd;
+		return 1;
+	case offsetof(struct fuse_iomap_bpf_ops, users):
+		ASSERT(atomic_read(&ops->users) == 0);
+		atomic_set(&ops->users, 1);
+		return 1;
+	case offsetof(struct fuse_iomap_bpf_ops, name):
+		if (bpf_obj_name_cpy(ops->name, u_ops->name,
+				     sizeof(ops->name)) <= 0)
+			return -EINVAL;
+		return 1;  /* Handled */
+	}
+
+	/* Not handled, use default */
+	return 0;
+}
+
+/* Register an iomap bpf program with a fuse connection */
+static int fuse_iomap_bpf_reg(void *kdata, struct bpf_link *link)
+{
+	struct fuse_iomap_bpf_ops *ops = kdata;
+	struct file *fusedev_file;
+	struct fuse_dev *fud;
+	struct fuse_conn *fc;
+
+	CLASS(fd, fusedev_fd)(ops->fuse_fd);
+	if (fd_empty(fusedev_fd))
+		return -EBADF;
+
+	fusedev_file = fd_file(fusedev_fd);
+	if (fusedev_file->f_op != &fuse_dev_operations)
+		return -EBADF;
+
+	fud = fuse_get_dev(fusedev_file);
+	fc = fud->fc;
+
+	if (!fc->iomap)
+		return -EOPNOTSUPP;
+
+	spin_lock(&fuse_iomap_bpf_ops_lock);
+	if (fc->iomap_conn.bpf_ops) {
+		spin_unlock(&fuse_iomap_bpf_ops_lock);
+		return -EBUSY;
+	}
+
+	/*
+	 * The initial ops user count bias is transferred to fc so that we only
+	 * initiate wakeup events when someone tries to unregister the BPF.
+	 */
+	rcu_assign_pointer(fc->iomap_conn.bpf_ops, ops);
+	ops->fc = fc;
+	spin_unlock(&fuse_iomap_bpf_ops_lock);
+
+	return 0;
+}
+
+static inline struct fuse_iomap_bpf_ops *
+fuse_iomap_get_bpf_ops(struct inode *inode)
+{
+	struct fuse_conn *fc = get_fuse_conn(inode);
+	struct fuse_iomap_bpf_ops *ops;
+
+	rcu_read_lock();
+	ops = rcu_dereference(fc->iomap_conn.bpf_ops);
+	if (ops && !atomic_inc_not_zero(&ops->users))
+		ops = NULL;
+	rcu_read_unlock();
+
+	return ops;
+}
+
+static inline void
+fuse_iomap_put_bpf_ops(struct fuse_iomap_bpf_ops *ops)
+{
+	if (ops)
+		atomic_dec_and_wake_up(&ops->users);
+}
+
+DEFINE_CLASS(iomap_bpf_ops, struct fuse_iomap_bpf_ops *,
+	     fuse_iomap_put_bpf_ops(_T), fuse_iomap_get_bpf_ops(inode),
+	     struct inode *inode);
+
+static void __fuse_iomap_detach_bpf(struct fuse_conn *fc,
+				    struct fuse_iomap_bpf_ops *ops)
+{
+	ops->fc = NULL;
+	rcu_assign_pointer(fc->iomap_conn.bpf_ops, NULL);
+	fuse_iomap_put_bpf_ops(ops);
+}
+
+/* Detach any iomap bpf programs from the fuse connection */
+void fuse_iomap_unmount_bpf(struct fuse_conn *fc)
+{
+	spin_lock(&fuse_iomap_bpf_ops_lock);
+	if (fc->iomap_conn.bpf_ops) {
+		/*
+		 * This should only be called from unmount, so there won't be
+		 * anybody trying to call the BPF iomap functions.
+		 */
+		ASSERT(atomic_read(&fc->iomap_conn.bpf_ops->users) == 1);
+
+		__fuse_iomap_detach_bpf(fc, fc->iomap_conn.bpf_ops);
+	}
+	spin_unlock(&fuse_iomap_bpf_ops_lock);
+}
+
+/* Detach the fuse connection from this iomap bpf program */
+static void fuse_iomap_bpf_unreg(void *kdata, struct bpf_link *link)
+{
+	struct fuse_iomap_bpf_ops *ops = kdata;
+
+	spin_lock(&fuse_iomap_bpf_ops_lock);
+	if (ops->fc && ops->fc->iomap_conn.bpf_ops == ops)
+		__fuse_iomap_detach_bpf(ops->fc, ops);
+	spin_unlock(&fuse_iomap_bpf_ops_lock);
+
+	/* wait until nobody's trying to call into the bpf iomap program */
+	wait_var_event(&ops->users, atomic_read(&ops->users) == 0);
+}
+
+/* Dummy function stubs for control flow integrity hashes */
+static enum fuse_iomap_bpf_ret
+__iomap_begin(struct fuse_inode *fi, uint64_t pos, uint64_t count,
+	      uint32_t opflags, struct fuse_iomap_begin_out *outarg)
+{
+	return FIB_FALLBACK;
+}
+
+static enum fuse_iomap_bpf_ret
+__iomap_end(struct fuse_inode *fi, uint64_t pos, uint64_t count,
+	    int64_t written, uint32_t opflags)
+{
+	return FIB_FALLBACK;
+}
+
+static enum fuse_iomap_bpf_ret
+__iomap_ioend(struct fuse_inode *fi, uint64_t pos, int64_t written,
+	      uint32_t ioendflags, int error, uint32_t dev, uint64_t new_addr,
+	      struct fuse_iomap_ioend_out *outarg)
+{
+	return FIB_FALLBACK;
+}
+
+static struct fuse_iomap_bpf_ops __fuse_iomap_bpf_ops = {
+	.iomap_begin	= __iomap_begin,
+	.iomap_end	= __iomap_end,
+	.iomap_ioend	= __iomap_ioend,
+};
+
+static struct bpf_struct_ops fuse_iomap_bpf_struct_ops = {
+	.verifier_ops	= &fuse_iomap_bpf_verifier_ops,
+	.init		= fuse_iomap_bpf_ops_init,
+	.check_member	= fuse_iomap_bpf_ops_check_member,
+	.init_member	= fuse_iomap_bpf_ops_init_member,
+	.reg		= fuse_iomap_bpf_reg,
+	.unreg		= fuse_iomap_bpf_unreg,
+	.name		= "fuse_iomap_bpf_ops",
+	.cfi_stubs	= &__fuse_iomap_bpf_ops,
+	.owner		= THIS_MODULE,
+};
+
+/* Register the iomap bpf ops so that fuse servers can attach to it */
+int __init fuse_iomap_init_bpf(void)
+{
+	return register_bpf_struct_ops(&fuse_iomap_bpf_struct_ops,
+				       fuse_iomap_bpf_ops);
+}
+
+/* Register key structures with BTF so that BPF programs can use structs */
+BTF_ID_LIST_GLOBAL_SINGLE(btf_fuse_iomap_bpf_ops_id,
+			  struct, fuse_iomap_bpf_ops)
+BTF_ID_LIST_GLOBAL_SINGLE(btf_fuse_iomap_begin_out_id,
+			  struct, fuse_iomap_begin_out)
+BTF_ID_LIST_GLOBAL_SINGLE(btf_fuse_iomap_ioend_out_id,
+			  struct, fuse_iomap_ioend_out)
+
+static inline int bpf_to_errno(enum fuse_iomap_bpf_ret ret)
+{
+	switch (ret) {
+	case FIB_HANDLED:
+		return 0;
+	case FIB_FALLBACK:
+	default:
+		return -ENOSYS;
+	}
+}
+
+/* Try to call the bpf version of ->iomap_begin */
+int fuse_iomap_begin_bpf(struct inode *inode,
+			 const struct fuse_iomap_begin_in *inarg,
+			 struct fuse_iomap_begin_out *outarg)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	CLASS(iomap_bpf_ops, bpf_ops)(inode);
+	enum fuse_iomap_bpf_ret ret;
+
+	if (!bpf_ops || !bpf_ops->iomap_begin)
+		return -ENOSYS;
+
+	ret = bpf_ops->iomap_begin(fi, inarg->pos, inarg->count,
+				   inarg->opflags, outarg);
+	return bpf_to_errno(ret);
+}
+
+/* Try to call the bpf version of ->iomap_end */
+int fuse_iomap_end_bpf(struct inode *inode,
+		       const struct fuse_iomap_end_in *inarg)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	CLASS(iomap_bpf_ops, bpf_ops)(inode);
+	enum fuse_iomap_bpf_ret ret;
+
+	if (!bpf_ops || !bpf_ops->iomap_end)
+		return -ENOSYS;
+
+	ret = bpf_ops->iomap_end(fi, inarg->pos, inarg->count,
+				 inarg->written, inarg->opflags);
+	return bpf_to_errno(ret);
+}
+
+/* Try to call the bpf version of ->iomap_ioend */
+int fuse_iomap_ioend_bpf(struct inode *inode,
+			 const struct fuse_iomap_ioend_in *inarg,
+			 struct fuse_iomap_ioend_out *outarg)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	CLASS(iomap_bpf_ops, bpf_ops)(inode);
+	enum fuse_iomap_bpf_ret ret;
+
+	if (!bpf_ops || !bpf_ops->iomap_ioend)
+		return -ENOSYS;
+
+	ret = bpf_ops->iomap_ioend(fi, inarg->pos, inarg->written,
+				   inarg->flags, inarg->error, inarg->dev,
+				   inarg->new_addr, outarg);
+	return bpf_to_errno(ret);
+}
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 0f2b12aa1ac4bb..1ab9c0dc3fc964 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -10,6 +10,7 @@
 #include "fuse_dev_i.h"
 #include "dev_uring_i.h"
 #include "fuse_iomap.h"
+#include "fuse_iomap_bpf.h"
 
 #include <linux/dax.h>
 #include <linux/pagemap.h>
@@ -1718,6 +1719,8 @@ EXPORT_SYMBOL_GPL(fuse_send_init);
 void fuse_free_conn(struct fuse_conn *fc)
 {
 	WARN_ON(!list_empty(&fc->devices));
+
+	fuse_iomap_unmount_bpf(fc);
 	kfree(fc);
 }
 EXPORT_SYMBOL_GPL(fuse_free_conn);
@@ -2373,6 +2376,10 @@ static int __init fuse_fs_init(void)
 	if (!fuse_inode_cachep)
 		goto out;
 
+	err = fuse_iomap_init_bpf();
+	if (err)
+		goto out2;
+
 	err = register_fuseblk();
 	if (err)
 		goto out2;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/5] fuse_trace: enable fuse servers to upload BPF programs to handle iomap requests
  2026-02-23 23:02 ` [PATCHSET RFC 9/9] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
  2026-02-23 23:24   ` [PATCH 1/5] fuse: enable fuse servers to upload BPF programs to handle iomap requests Darrick J. Wong
@ 2026-02-23 23:24   ` Darrick J. Wong
  2026-02-23 23:24   ` [PATCH 3/5] fuse: prevent iomap bpf programs from writing to most of the system Darrick J. Wong
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:24 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, bpf, john, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add tracepoints to the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_trace.h     |   53 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap_bpf.c |   10 +++++++++
 fs/fuse/trace.c          |    1 +
 3 files changed, 64 insertions(+)


diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index aa2d5ca88c9d40..956881dada5252 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -1657,6 +1657,59 @@ TRACE_EVENT(fuse_iomap_inval_mappings,
 		  FUSE_FILE_RANGE_PRINTK_ARGS(read),
 		  FUSE_FILE_RANGE_PRINTK_ARGS(write))
 );
+
+#ifdef CONFIG_BPF_SYSCALL
+DECLARE_EVENT_CLASS(fuse_iomap_bpf_ops_class,
+	TP_PROTO(const struct fuse_conn *fc, struct fuse_iomap_bpf_ops *ops),
+
+	TP_ARGS(fc, ops),
+
+	TP_STRUCT__entry(
+		__field(dev_t,			connection)
+		__string(name,			ops->name)
+	),
+
+	TP_fast_assign(
+		__entry->connection	=	fc->dev;
+		__assign_str(name);
+	),
+
+	TP_printk("connection %u iomap_ops %s",
+		  __entry->connection,
+		  __get_str(name))
+);
+#define DEFINE_FUSE_IOMAP_BPF_OPS_EVENT(name) \
+DEFINE_EVENT(fuse_iomap_bpf_ops_class, name, \
+	TP_PROTO(const struct fuse_conn *fc, struct fuse_iomap_bpf_ops *ops), \
+	TP_ARGS(fc, ops))
+DEFINE_FUSE_IOMAP_BPF_OPS_EVENT(fuse_iomap_attach_bpf);
+DEFINE_FUSE_IOMAP_BPF_OPS_EVENT(fuse_iomap_detach_bpf);
+
+DECLARE_EVENT_CLASS(fuse_iomap_bpf_class,
+	TP_PROTO(const struct inode *inode),
+
+	TP_ARGS(inode),
+
+	TP_STRUCT__entry(
+		FUSE_INODE_FIELDS
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+	),
+
+	TP_printk(FUSE_INODE_FMT,
+		  FUSE_INODE_PRINTK_ARGS)
+);
+#define DEFINE_FUSE_IOMAP_BPF_EVENT(name) \
+DEFINE_EVENT(fuse_iomap_bpf_class, name, \
+	TP_PROTO(const struct inode *inode), \
+	TP_ARGS(inode))
+DEFINE_FUSE_IOMAP_BPF_EVENT(fuse_iomap_begin_bpf);
+DEFINE_FUSE_IOMAP_BPF_EVENT(fuse_iomap_end_bpf);
+DEFINE_FUSE_IOMAP_BPF_EVENT(fuse_iomap_ioend_bpf);
+
+#endif /* CONFIG_BPF_SYSCALL */
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/fuse_iomap_bpf.c b/fs/fuse/fuse_iomap_bpf.c
index b104f3961721b2..d4b826e4440ca7 100644
--- a/fs/fuse/fuse_iomap_bpf.c
+++ b/fs/fuse/fuse_iomap_bpf.c
@@ -115,6 +115,8 @@ static int fuse_iomap_bpf_reg(void *kdata, struct bpf_link *link)
 		return -EBUSY;
 	}
 
+	trace_fuse_iomap_attach_bpf(fc, ops);
+
 	/*
 	 * The initial ops user count bias is transferred to fc so that we only
 	 * initiate wakeup events when someone tries to unregister the BPF.
@@ -155,6 +157,8 @@ DEFINE_CLASS(iomap_bpf_ops, struct fuse_iomap_bpf_ops *,
 static void __fuse_iomap_detach_bpf(struct fuse_conn *fc,
 				    struct fuse_iomap_bpf_ops *ops)
 {
+	trace_fuse_iomap_detach_bpf(fc, ops);
+
 	ops->fc = NULL;
 	rcu_assign_pointer(fc->iomap_conn.bpf_ops, NULL);
 	fuse_iomap_put_bpf_ops(ops);
@@ -269,6 +273,8 @@ int fuse_iomap_begin_bpf(struct inode *inode,
 	if (!bpf_ops || !bpf_ops->iomap_begin)
 		return -ENOSYS;
 
+	trace_fuse_iomap_begin_bpf(inode);
+
 	ret = bpf_ops->iomap_begin(fi, inarg->pos, inarg->count,
 				   inarg->opflags, outarg);
 	return bpf_to_errno(ret);
@@ -285,6 +291,8 @@ int fuse_iomap_end_bpf(struct inode *inode,
 	if (!bpf_ops || !bpf_ops->iomap_end)
 		return -ENOSYS;
 
+	trace_fuse_iomap_end_bpf(inode);
+
 	ret = bpf_ops->iomap_end(fi, inarg->pos, inarg->count,
 				 inarg->written, inarg->opflags);
 	return bpf_to_errno(ret);
@@ -302,6 +310,8 @@ int fuse_iomap_ioend_bpf(struct inode *inode,
 	if (!bpf_ops || !bpf_ops->iomap_ioend)
 		return -ENOSYS;
 
+	trace_fuse_iomap_ioend_bpf(inode);
+
 	ret = bpf_ops->iomap_ioend(fi, inarg->pos, inarg->written,
 				   inarg->flags, inarg->error, inarg->dev,
 				   inarg->new_addr, outarg);
diff --git a/fs/fuse/trace.c b/fs/fuse/trace.c
index 69310d6f773ffa..7d65ccdc2be609 100644
--- a/fs/fuse/trace.c
+++ b/fs/fuse/trace.c
@@ -9,6 +9,7 @@
 #include "fuse_iomap.h"
 #include "fuse_iomap_i.h"
 #include "fuse_iomap_cache.h"
+#include "fuse_iomap_bpf.h"
 
 #include <linux/pagemap.h>
 #include <linux/iomap.h>


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/5] fuse: prevent iomap bpf programs from writing to most of the system
  2026-02-23 23:02 ` [PATCHSET RFC 9/9] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
  2026-02-23 23:24   ` [PATCH 1/5] fuse: enable fuse servers to upload BPF programs to handle iomap requests Darrick J. Wong
  2026-02-23 23:24   ` [PATCH 2/5] fuse_trace: " Darrick J. Wong
@ 2026-02-23 23:24   ` Darrick J. Wong
  2026-02-23 23:25   ` [PATCH 4/5] fuse: add kfuncs for iomap bpf programs to manage the cache Darrick J. Wong
  2026-02-23 23:25   ` [PATCH 5/5] fuse: make fuse_inode opaque to iomap bpf programs Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:24 UTC (permalink / raw)
  To: miklos, djwong
  Cc: bpf, joannelkoong, bpf, john, bernd, neal, linux-fsdevel,
	linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

The stub implementation fuse_iomap_bpf_ops_btf_struct_access has the
unfortunate behavior of allowing the bpf program to write to any struct
pointer passed into the function!  We don't want to allow random updates
to struct fuse_inode, but we will eventually want to pass the pointer
as a dumb cookie to the kfunc added a few patches from now.

Therefore, look up the btf types of the two structs for which the bpf
program *can* write, and disallow all writes to any other structs.
This requires a new export from the bpf subsystem.

Cc: bpf@vger.kernel.org
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap_bpf.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++
 kernel/bpf/btf.c         |    1 +
 2 files changed, 50 insertions(+)


diff --git a/fs/fuse/fuse_iomap_bpf.c b/fs/fuse/fuse_iomap_bpf.c
index d4b826e4440ca7..13b5d4b96b66b5 100644
--- a/fs/fuse/fuse_iomap_bpf.c
+++ b/fs/fuse/fuse_iomap_bpf.c
@@ -5,6 +5,7 @@
  * Copied from: Joanne Koong <joannelkoong@gmail.com>
  */
 #include <linux/bpf.h>
+#include <linux/bpf_verifier.h>
 
 #include "fuse_i.h"
 #include "fuse_dev_i.h"
@@ -12,6 +13,8 @@
 #include "fuse_iomap_i.h"
 #include "fuse_trace.h"
 
+static const struct btf_type *iomap_begin_out_type, *iomap_ioend_out_type;
+
 /* spinlock for atomically updating fuse_conn <-> bpf_ops pointers */
 static DEFINE_SPINLOCK(fuse_iomap_bpf_ops_lock);
 
@@ -38,6 +41,14 @@ static int fuse_iomap_bpf_ops_btf_struct_access(struct bpf_verifier_log *log,
 						const struct bpf_reg_state *reg,
 						int off, int size)
 {
+	const struct btf_type *t = btf_type_by_id(reg->btf, reg->btf_id);
+
+	if (t != iomap_begin_out_type && t != iomap_ioend_out_type) {
+		bpf_log(log,
+			"Cannot write to memory from a fuse-iomap program\n");
+		return -EACCES;
+	}
+
 	return 0;
 }
 
@@ -47,8 +58,46 @@ static const struct bpf_verifier_ops fuse_iomap_bpf_verifier_ops = {
 	.btf_struct_access	= fuse_iomap_bpf_ops_btf_struct_access,
 };
 
+static const struct btf_type *
+fuse_iomap_find_struct_type(struct btf *btf, const char *name)
+{
+	struct btf *some_btf;
+	const struct btf_type *ret;
+	s32 type_id;
+
+	type_id = bpf_find_btf_id(name, BTF_KIND_STRUCT, &some_btf);
+	if (type_id < 0)
+		return ERR_PTR(-ENOENT);
+
+	/*
+	 * It's only safe to alias a btf_type without a ref to the btf object
+	 * if the type is from the current module because the btf object won't
+	 * go away until the module unloads.
+	 */
+	if (some_btf == btf)
+		ret = btf_type_by_id(some_btf, type_id);
+	else
+		ret = ERR_PTR(-ENOENT);
+	btf_put(some_btf);
+
+	return ret;
+}
+
 static int fuse_iomap_bpf_ops_init(struct btf *btf)
 {
+	const struct btf_type *t1, *t2;
+
+	t1 = fuse_iomap_find_struct_type(btf, "fuse_iomap_begin_out");
+	if (IS_ERR(t1))
+		return PTR_ERR(t1);
+
+	t2 = fuse_iomap_find_struct_type(btf, "fuse_iomap_ioend_out");
+	if (IS_ERR(t2))
+		return PTR_ERR(t2);
+
+	iomap_begin_out_type = t1;
+	iomap_ioend_out_type = t2;
+
 	return 0;
 }
 
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 4872d2a6c42d3a..9a5b6480243f14 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -1890,6 +1890,7 @@ void btf_put(struct btf *btf)
 		call_rcu(&btf->rcu, btf_free_rcu);
 	}
 }
+EXPORT_SYMBOL_GPL(btf_put);
 
 struct btf *btf_base_btf(const struct btf *btf)
 {


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 4/5] fuse: add kfuncs for iomap bpf programs to manage the cache
  2026-02-23 23:02 ` [PATCHSET RFC 9/9] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:24   ` [PATCH 3/5] fuse: prevent iomap bpf programs from writing to most of the system Darrick J. Wong
@ 2026-02-23 23:25   ` Darrick J. Wong
  2026-02-23 23:25   ` [PATCH 5/5] fuse: make fuse_inode opaque to iomap bpf programs Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:25 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, bpf, john, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Add a couple of kfuncs so that a BPF program that generates iomappings
can add them to the inode's mapping cache, thereby avoiding the need to
go into BPF program on the next access.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap_i.h   |    6 ++++
 fs/fuse/fuse_iomap.c     |    4 +-
 fs/fuse/fuse_iomap_bpf.c |   76 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 2 deletions(-)


diff --git a/fs/fuse/fuse_iomap_i.h b/fs/fuse/fuse_iomap_i.h
index c37a7c5cfc862f..70c5a831dc9134 100644
--- a/fs/fuse/fuse_iomap_i.h
+++ b/fs/fuse/fuse_iomap_i.h
@@ -40,6 +40,12 @@ while (static_branch_unlikely(&fuse_iomap_debug)) {			\
 	unlikely(__cond);						\
 })
 #endif /* CONFIG_FUSE_IOMAP_DEBUG */
+
+int fuse_iomap_inval_inode(struct inode *inode,
+		const struct fuse_iomap_inval_mappings_out *outarg);
+int fuse_iomap_upsert_inode(struct inode *inode,
+		const struct fuse_iomap_upsert_mappings_out *outarg);
+
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_I_H */
diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
index 2e0c35e879ffcc..d2642eef59b779 100644
--- a/fs/fuse/fuse_iomap.c
+++ b/fs/fuse/fuse_iomap.c
@@ -2782,7 +2782,7 @@ fuse_iomap_upsert_validate_mappings(struct inode *inode,
 						  &outarg->write);
 }
 
-static int fuse_iomap_upsert_inode(struct inode *inode,
+int fuse_iomap_upsert_inode(struct inode *inode,
 		const struct fuse_iomap_upsert_mappings_out *outarg)
 {
 	int ret = fuse_iomap_upsert_validate_mappings(inode, outarg);
@@ -2877,7 +2877,7 @@ fuse_iomap_inval_validate_range(const struct inode *inode,
 	return true;
 }
 
-static int fuse_iomap_inval_inode(struct inode *inode,
+int fuse_iomap_inval_inode(struct inode *inode,
 		const struct fuse_iomap_inval_mappings_out *outarg)
 {
 	int ret = 0, ret2 = 0;
diff --git a/fs/fuse/fuse_iomap_bpf.c b/fs/fuse/fuse_iomap_bpf.c
index 13b5d4b96b66b5..71bfcddae7f5b7 100644
--- a/fs/fuse/fuse_iomap_bpf.c
+++ b/fs/fuse/fuse_iomap_bpf.c
@@ -6,9 +6,12 @@
  */
 #include <linux/bpf.h>
 #include <linux/bpf_verifier.h>
+#include <linux/btf.h>
+#include <linux/btf_ids.h>
 
 #include "fuse_i.h"
 #include "fuse_dev_i.h"
+#include "fuse_iomap.h"
 #include "fuse_iomap_bpf.h"
 #include "fuse_iomap_i.h"
 #include "fuse_trace.h"
@@ -284,9 +287,82 @@ static struct bpf_struct_ops fuse_iomap_bpf_struct_ops = {
 	.owner		= THIS_MODULE,
 };
 
+__bpf_kfunc_start_defs();
+
+__bpf_kfunc int
+fuse_bpf_iomap_inval_mappings(struct fuse_inode *fi,
+			      const struct fuse_range *read__nullable,
+			      const struct fuse_range *write__nullable)
+{
+	struct fuse_iomap_inval_mappings_out outarg = {
+		.nodeid = fi->nodeid,
+		.attr_ino = fi->orig_ino,
+	};
+	struct inode *inode = &fi->inode;
+	struct fuse_conn *fc = get_fuse_conn(inode);
+
+	if (!fc->iomap)
+		return -EOPNOTSUPP;
+
+	if (read__nullable)
+		memcpy(&outarg.read, read__nullable, sizeof(outarg.read));
+	if (write__nullable)
+		memcpy(&outarg.write, write__nullable, sizeof(outarg.write));
+
+	trace_fuse_iomap_inval_mappings(inode, &outarg);
+
+	return fuse_iomap_inval_inode(inode, &outarg);
+}
+
+__bpf_kfunc int
+fuse_bpf_iomap_upsert_mappings(struct fuse_inode *fi,
+			       const struct fuse_iomap_io *read__nullable,
+			       const struct fuse_iomap_io *write__nullable)
+{
+	struct fuse_iomap_upsert_mappings_out outarg = {
+		.nodeid = fi->nodeid,
+		.attr_ino = fi->orig_ino,
+		.read.type = FUSE_IOMAP_TYPE_NOCACHE,
+		.write.type = FUSE_IOMAP_TYPE_NOCACHE,
+	};
+	struct inode *inode = &fi->inode;
+	struct fuse_conn *fc = get_fuse_conn(inode);
+
+	if (!fc->iomap)
+		return -EOPNOTSUPP;
+
+	if (read__nullable)
+		memcpy(&outarg.read, read__nullable, sizeof(outarg.read));
+	if (write__nullable)
+		memcpy(&outarg.write, write__nullable, sizeof(outarg.write));
+
+	trace_fuse_iomap_upsert_mappings(inode, &outarg);
+
+	return fuse_iomap_upsert_inode(inode, &outarg);
+}
+
+__bpf_kfunc_end_defs();
+
+BTF_KFUNCS_START(fuse_iomap_kfunc_ids)
+BTF_ID_FLAGS(func, fuse_bpf_iomap_inval_mappings,
+	     KF_SLEEPABLE | KF_TRUSTED_ARGS)
+BTF_ID_FLAGS(func, fuse_bpf_iomap_upsert_mappings,
+	     KF_SLEEPABLE | KF_TRUSTED_ARGS)
+BTF_KFUNCS_END(fuse_iomap_kfunc_ids)
+
+static const struct btf_kfunc_id_set fuse_iomap_kfunc_set = {
+	.owner = THIS_MODULE,
+	.set   = &fuse_iomap_kfunc_ids,
+};
+
 /* Register the iomap bpf ops so that fuse servers can attach to it */
 int __init fuse_iomap_init_bpf(void)
 {
+	int ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
+			&fuse_iomap_kfunc_set);
+	if (ret)
+		return ret;
+
 	return register_bpf_struct_ops(&fuse_iomap_bpf_struct_ops,
 				       fuse_iomap_bpf_ops);
 }


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 5/5] fuse: make fuse_inode opaque to iomap bpf programs
  2026-02-23 23:02 ` [PATCHSET RFC 9/9] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:25   ` [PATCH 4/5] fuse: add kfuncs for iomap bpf programs to manage the cache Darrick J. Wong
@ 2026-02-23 23:25   ` Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:25 UTC (permalink / raw)
  To: miklos, djwong
  Cc: joannelkoong, bpf, john, bernd, neal, linux-fsdevel, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

Introduce an opaque type (and some casting helpers) for struct
fuse_inode.  This tricks BTF/BPF into thinking that the "inode" object
we pass to BPF programs is an empty structure, which means that the BPF
program cannot even look at the contents.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/fuse/fuse_iomap_bpf.h |   41 ++++++++++++++++++++++++++++++++++++++---
 fs/fuse/fuse_iomap_bpf.c |   42 +++++++++++++++++++++++++++++++-----------
 2 files changed, 69 insertions(+), 14 deletions(-)


diff --git a/fs/fuse/fuse_iomap_bpf.h b/fs/fuse/fuse_iomap_bpf.h
index f6bfd2133bf2bb..148e8f1fa1d1fb 100644
--- a/fs/fuse/fuse_iomap_bpf.h
+++ b/fs/fuse/fuse_iomap_bpf.h
@@ -15,12 +15,47 @@ enum fuse_iomap_bpf_ret {
 	FIB_HANDLED = 1,
 };
 
+/* opaque structure so that bpf programs cannot see inside a fuse inode */
+struct fuse_bpf_inode { };
+
+static inline const struct fuse_inode *
+__fuse_inode_from_bpf_c(const struct fuse_bpf_inode *fbi)
+{
+	return (const struct fuse_inode *)fbi;
+}
+
+static inline struct fuse_inode *
+__fuse_inode_from_bpf(struct fuse_bpf_inode *fbi)
+{
+	return (struct fuse_inode *)fbi;
+}
+
+#define fuse_inode_from_bpf(x) _Generic((x), \
+	struct fuse_bpf_inode * :	__fuse_inode_from_bpf, \
+	const struct fuse_bpf_inode * :	__fuse_inode_from_bpf_c)(x)
+
+static inline const struct fuse_bpf_inode *
+__fuse_inode_to_bpf_c(const struct fuse_inode *fi)
+{
+	return (const struct fuse_bpf_inode *)fi;
+}
+
+static inline struct fuse_bpf_inode *
+__fuse_inode_to_bpf(struct fuse_inode *fi)
+{
+	return (struct fuse_bpf_inode *)fi;
+}
+
+#define fuse_inode_to_bpf(x) _Generic((x), \
+	struct fuse_inode * :		__fuse_inode_to_bpf, \
+	const struct fuse_inode * :	__fuse_inode_to_bpf_c)(x)
+
 struct fuse_iomap_bpf_ops {
 	/**
 	 * @iomap_begin: override iomap_begin.  See FUSE_IOMAP_BEGIN for
 	 * details.
 	 */
-	enum fuse_iomap_bpf_ret (*iomap_begin)(struct fuse_inode *fi,
+	enum fuse_iomap_bpf_ret (*iomap_begin)(struct fuse_bpf_inode *fbi,
 			uint64_t pos, uint64_t count, uint32_t opflags,
 			struct fuse_iomap_begin_out *outarg);
 
@@ -28,7 +63,7 @@ struct fuse_iomap_bpf_ops {
 	 * @iomap_end: override iomap_end.  See FUSE_IOMAP_END for
 	 * details.
 	 */
-	enum fuse_iomap_bpf_ret (*iomap_end)(struct fuse_inode *fi,
+	enum fuse_iomap_bpf_ret (*iomap_end)(struct fuse_bpf_inode *fbi,
 			uint64_t pos, uint64_t count, int64_t written,
 			uint32_t opflags);
 
@@ -36,7 +71,7 @@ struct fuse_iomap_bpf_ops {
 	 * @iomap_ioend: override iomap_ioend.  See FUSE_IOMAP_IOEND for
 	 * details.
 	 */
-	enum fuse_iomap_bpf_ret (*iomap_ioend)(struct fuse_inode *fi,
+	enum fuse_iomap_bpf_ret (*iomap_ioend)(struct fuse_bpf_inode *fbi,
 			uint64_t pos, int64_t written, uint32_t ioendflags,
 			int error, uint32_t dev, uint64_t new_addr,
 			struct fuse_iomap_ioend_out *outarg);
diff --git a/fs/fuse/fuse_iomap_bpf.c b/fs/fuse/fuse_iomap_bpf.c
index 71bfcddae7f5b7..6f183b6f7e975c 100644
--- a/fs/fuse/fuse_iomap_bpf.c
+++ b/fs/fuse/fuse_iomap_bpf.c
@@ -248,21 +248,21 @@ static void fuse_iomap_bpf_unreg(void *kdata, struct bpf_link *link)
 
 /* Dummy function stubs for control flow integrity hashes */
 static enum fuse_iomap_bpf_ret
-__iomap_begin(struct fuse_inode *fi, uint64_t pos, uint64_t count,
+__iomap_begin(struct fuse_bpf_inode *fbi, uint64_t pos, uint64_t count,
 	      uint32_t opflags, struct fuse_iomap_begin_out *outarg)
 {
 	return FIB_FALLBACK;
 }
 
 static enum fuse_iomap_bpf_ret
-__iomap_end(struct fuse_inode *fi, uint64_t pos, uint64_t count,
+__iomap_end(struct fuse_bpf_inode *fbi, uint64_t pos, uint64_t count,
 	    int64_t written, uint32_t opflags)
 {
 	return FIB_FALLBACK;
 }
 
 static enum fuse_iomap_bpf_ret
-__iomap_ioend(struct fuse_inode *fi, uint64_t pos, int64_t written,
+__iomap_ioend(struct fuse_bpf_inode *fbi, uint64_t pos, int64_t written,
 	      uint32_t ioendflags, int error, uint32_t dev, uint64_t new_addr,
 	      struct fuse_iomap_ioend_out *outarg)
 {
@@ -290,10 +290,11 @@ static struct bpf_struct_ops fuse_iomap_bpf_struct_ops = {
 __bpf_kfunc_start_defs();
 
 __bpf_kfunc int
-fuse_bpf_iomap_inval_mappings(struct fuse_inode *fi,
+fuse_bpf_iomap_inval_mappings(struct fuse_bpf_inode *fbi,
 			      const struct fuse_range *read__nullable,
 			      const struct fuse_range *write__nullable)
 {
+	struct fuse_inode *fi = fuse_inode_from_bpf(fbi);
 	struct fuse_iomap_inval_mappings_out outarg = {
 		.nodeid = fi->nodeid,
 		.attr_ino = fi->orig_ino,
@@ -315,10 +316,11 @@ fuse_bpf_iomap_inval_mappings(struct fuse_inode *fi,
 }
 
 __bpf_kfunc int
-fuse_bpf_iomap_upsert_mappings(struct fuse_inode *fi,
+fuse_bpf_iomap_upsert_mappings(struct fuse_bpf_inode *fbi,
 			       const struct fuse_iomap_io *read__nullable,
 			       const struct fuse_iomap_io *write__nullable)
 {
+	struct fuse_inode *fi = fuse_inode_from_bpf(fbi);
 	struct fuse_iomap_upsert_mappings_out outarg = {
 		.nodeid = fi->nodeid,
 		.attr_ino = fi->orig_ino,
@@ -341,6 +343,22 @@ fuse_bpf_iomap_upsert_mappings(struct fuse_inode *fi,
 	return fuse_iomap_upsert_inode(inode, &outarg);
 }
 
+__bpf_kfunc uint64_t
+fuse_bpf_inode_nodeid(const struct fuse_bpf_inode *fbi)
+{
+	const struct fuse_inode *fi = fuse_inode_from_bpf(fbi);
+
+	return fi->nodeid;
+}
+
+__bpf_kfunc uint64_t
+fuse_bpf_inode_orig_ino(const struct fuse_bpf_inode *fbi)
+{
+	const struct fuse_inode *fi = fuse_inode_from_bpf(fbi);
+
+	return fi->orig_ino;
+}
+
 __bpf_kfunc_end_defs();
 
 BTF_KFUNCS_START(fuse_iomap_kfunc_ids)
@@ -348,6 +366,8 @@ BTF_ID_FLAGS(func, fuse_bpf_iomap_inval_mappings,
 	     KF_SLEEPABLE | KF_TRUSTED_ARGS)
 BTF_ID_FLAGS(func, fuse_bpf_iomap_upsert_mappings,
 	     KF_SLEEPABLE | KF_TRUSTED_ARGS)
+BTF_ID_FLAGS(func, fuse_bpf_inode_nodeid, KF_TRUSTED_ARGS)
+BTF_ID_FLAGS(func, fuse_bpf_inode_orig_ino, KF_TRUSTED_ARGS)
 BTF_KFUNCS_END(fuse_iomap_kfunc_ids)
 
 static const struct btf_kfunc_id_set fuse_iomap_kfunc_set = {
@@ -400,8 +420,8 @@ int fuse_iomap_begin_bpf(struct inode *inode,
 
 	trace_fuse_iomap_begin_bpf(inode);
 
-	ret = bpf_ops->iomap_begin(fi, inarg->pos, inarg->count,
-				   inarg->opflags, outarg);
+	ret = bpf_ops->iomap_begin(fuse_inode_to_bpf(fi), inarg->pos,
+				   inarg->count, inarg->opflags, outarg);
 	return bpf_to_errno(ret);
 }
 
@@ -418,7 +438,7 @@ int fuse_iomap_end_bpf(struct inode *inode,
 
 	trace_fuse_iomap_end_bpf(inode);
 
-	ret = bpf_ops->iomap_end(fi, inarg->pos, inarg->count,
+	ret = bpf_ops->iomap_end(fuse_inode_to_bpf(fi), inarg->pos, inarg->count,
 				 inarg->written, inarg->opflags);
 	return bpf_to_errno(ret);
 }
@@ -437,8 +457,8 @@ int fuse_iomap_ioend_bpf(struct inode *inode,
 
 	trace_fuse_iomap_ioend_bpf(inode);
 
-	ret = bpf_ops->iomap_ioend(fi, inarg->pos, inarg->written,
-				   inarg->flags, inarg->error, inarg->dev,
-				   inarg->new_addr, outarg);
+	ret = bpf_ops->iomap_ioend(fuse_inode_to_bpf(fi), inarg->pos,
+				   inarg->written, inarg->flags, inarg->error,
+				   inarg->dev, inarg->new_addr, outarg);
 	return bpf_to_errno(ret);
 }


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 01/25] libfuse: bump kernel and library ABI versions
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
@ 2026-02-23 23:25   ` Darrick J. Wong
  2026-02-23 23:25   ` [PATCH 02/25] libfuse: wait in do_destroy until all open files are closed Darrick J. Wong
                     ` (23 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:25 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Bump the kernel ABI version to 7.99 and the libfuse ABI version to 3.99
to start our development.  This patch exists to avoid confusion during
the prototyping stage.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_kernel.h  |    5 ++++-
 ChangeLog.rst          |    5 +++++
 lib/fuse_versionscript |    3 +++
 lib/meson.build        |    4 ++--
 meson.build            |    2 +-
 5 files changed, 15 insertions(+), 4 deletions(-)


diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index f0dee3d6cf51b0..842cc08a083a6f 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -240,6 +240,9 @@
  *  - add FUSE_COPY_FILE_RANGE_64
  *  - add struct fuse_copy_file_range_out
  *  - add FUSE_NOTIFY_PRUNE
+ *
+ *  7.99
+ *  - XXX magic minor revision to make experimental code really obvious
  */
 
 #ifndef _LINUX_FUSE_H
@@ -275,7 +278,7 @@
 #define FUSE_KERNEL_VERSION 7
 
 /** Minor version number of this interface */
-#define FUSE_KERNEL_MINOR_VERSION 45
+#define FUSE_KERNEL_MINOR_VERSION 99
 
 /** The node ID of the root inode */
 #define FUSE_ROOT_ID 1
diff --git a/ChangeLog.rst b/ChangeLog.rst
index 15c998cf1623b8..3cb95081d42d06 100644
--- a/ChangeLog.rst
+++ b/ChangeLog.rst
@@ -1,3 +1,8 @@
+libfuse 3.99-rc0 (2025-12-19)
+===============================
+
+* Add prototypes of iomap and syncfs (djwong)
+
 libfuse 3.18.0 (2025-12-18)
 ===========================
 
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index cce09610316f4b..826d9fee00a8ee 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -229,6 +229,9 @@ FUSE_3.19 {
 		fuse_lowlevel_notify_prune;
 } FUSE_3.18;
 
+FUSE_3.99 {
+} FUSE_3.19;
+
 # Local Variables:
 # indent-tabs-mode: t
 # End:
diff --git a/lib/meson.build b/lib/meson.build
index fcd95741c9d374..a3d3d49f9ba42b 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -44,12 +44,12 @@ fusermount_path = join_paths(get_option('prefix'), get_option('bindir'))
 libfuse = library('fuse3',
                   libfuse_sources,
                   version: base_version,
-                  soversion: '4',
+                  soversion: '99',
                   include_directories: include_dirs,
                   dependencies: deps,
                   install: true,
                   link_depends: 'fuse_versionscript',
-                  c_args: [ '-DFUSE_USE_VERSION=317',
+                  c_args: [ '-DFUSE_USE_VERSION=399',
                             '-DFUSERMOUNT_DIR="@0@"'.format(fusermount_path) ],
                   link_args: ['-Wl,--version-script,' + meson.current_source_dir()
                               + '/fuse_versionscript' ])
diff --git a/meson.build b/meson.build
index 80c5f1dc0bd356..8359a489c351b9 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,5 @@
 project('libfuse3', ['c'],
-        version: '3.19.0-rc0',
+        version: '3.99.0-rc0',  # Version with RC suffix
         meson_version: '>= 0.60.0',
         default_options: [
             'buildtype=debugoptimized',


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 02/25] libfuse: wait in do_destroy until all open files are closed
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
  2026-02-23 23:25   ` [PATCH 01/25] libfuse: bump kernel and library ABI versions Darrick J. Wong
@ 2026-02-23 23:25   ` Darrick J. Wong
  2026-02-23 23:26   ` [PATCH 03/25] libfuse: add kernel gates for FUSE_IOMAP Darrick J. Wong
                     ` (22 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:25 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

This patch complements the Linux kernel patch "fuse: flush pending fuse
events before aborting the connection".

This test opens a large number of files, unlinks them (which really just
renames them to fuse hidden files), closes the program, unmounts the
filesystem, and runs fsck to check that there aren't any inconsistencies
in the filesystem.

Unfortunately, the 488.full file shows that there are a lot of hidden
files left over in the filesystem, with incorrect link counts.  Tracing
fuse_request_* shows that there are a large number of FUSE_RELEASE
commands that are queued up on behalf of the unlinked files at the time
that fuse_conn_destroy calls fuse_abort_conn.  Had the connection not
aborted, the fuse server would have responded to the RELEASE commands by
removing the hidden files; instead they stick around.

For upper-level fuse servers that don't use fuseblk mode this isn't a
problem because libfuse responds to the connection going down by pruning
its inode cache and calling the fuse server's ->release for any open
files before calling the server's ->destroy function.

For fuseblk servers this is a problem, however, because the kernel sends
FUSE_DESTROY to the fuse server, and the fuse server has to write all of
its pending changes to the block device before replying to the DESTROY
request because the kernel releases its O_EXCL hold on the block device.
This means that the kernel must flush all pending FUSE_RELEASE requests
before issuing FUSE_DESTROY.

For fuse-iomap servers this will also be a problem because iomap servers
are expected to release all exclusively-held resources before unmount
returns from the kernel.

Create a function to push all the background requests to the queue
before sending FUSE_DESTROY.  That way, all the pending file release
events are processed by the fuse server before it tears itself down, and
we don't end up with a corrupt filesystem.

Note that multithreaded fuse servers will need to track the number of
open files and defer a FUSE_DESTROY request until that number reaches
zero.  An earlier version of this patch made the kernel wait for the
RELEASE acknowledgements before sending DESTROY, but the kernel people
weren't comfortable with adding blocking waits to unmount.

This patch implements the deferral for the multithreaded libfuse
backend.  However, we must implement this deferral by starting a new
background thread because libfuse in io_uring mode starts up a bunch of
threads, each of which submit batches of SQEs to request fuse commands,
and then waits for the kernel to mark some CQEs to note which slots now
have fuse commands to process.  Each uring thread processes the fuse
comands in the CQE serially, which means that _do_destroy can't just
wait for the open file counter to hit zero; it has to start a new
background thread to do that, so that it can continue to process pending
fuse commands.

[Aside: is this bad for fuse command processing latency?  Suppose we get
two CQE completions, then the second command won't even be looked at
until the first one is done.]

Non-uring fuse by contrast reads one fuse command and processes it
immediately, so one command taking a long time won't stall any other
commands.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/fuse_i.h        |    4 ++
 lib/fuse_lowlevel.c |  107 ++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 104 insertions(+), 7 deletions(-)


diff --git a/lib/fuse_i.h b/lib/fuse_i.h
index 65d2f68f7f3091..c7d0d38408105f 100644
--- a/lib/fuse_i.h
+++ b/lib/fuse_i.h
@@ -122,6 +122,10 @@ struct fuse_session {
 	 */
 	uint32_t conn_want;
 	uint64_t conn_want_ext;
+
+	/* destroy has to wait for all the open files to go away */
+	pthread_cond_t zero_open_files;
+	uint64_t open_files;
 };
 
 struct fuse_chan {
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index ac6b2fd25d24c7..c3d57f5c5b104c 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -54,6 +54,22 @@
 #define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
 #define OFFSET_MAX 0x7fffffffffffffffLL
 
+static inline void inc_open_files(struct fuse_session *se)
+{
+	pthread_mutex_lock(&se->lock);
+	se->open_files++;
+	pthread_mutex_unlock(&se->lock);
+}
+
+static inline void dec_open_files(struct fuse_session *se)
+{
+	pthread_mutex_lock(&se->lock);
+	se->open_files--;
+	if (!se->open_files)
+		pthread_cond_broadcast(&se->zero_open_files);
+	pthread_mutex_unlock(&se->lock);
+}
+
 struct fuse_pollhandle {
 	uint64_t kh;
 	struct fuse_session *se;
@@ -550,12 +566,17 @@ int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
 		FUSE_COMPAT_ENTRY_OUT_SIZE : sizeof(struct fuse_entry_out);
 	struct fuse_entry_out *earg = (struct fuse_entry_out *) buf;
 	struct fuse_open_out *oarg = (struct fuse_open_out *) (buf + entrysize);
+	struct fuse_session *se = req->se;
+	int error;
 
 	memset(buf, 0, sizeof(buf));
 	fill_entry(earg, e);
 	fill_open(oarg, f);
-	return send_reply_ok(req, buf,
+	error = send_reply_ok(req, buf,
 			     entrysize + sizeof(struct fuse_open_out));
+	if (!error)
+		inc_open_files(se);
+	return error;
 }
 
 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
@@ -606,10 +627,15 @@ int fuse_passthrough_close(fuse_req_t req, int backing_id)
 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *f)
 {
 	struct fuse_open_out arg;
+	struct fuse_session *se = req->se;
+	int error;
 
 	memset(&arg, 0, sizeof(arg));
 	fill_open(&arg, f);
-	return send_reply_ok(req, &arg, sizeof(arg));
+	error = send_reply_ok(req, &arg, sizeof(arg));
+	if (!error)
+		inc_open_files(se);
+	return error;
 }
 
 static int do_fuse_reply_write(fuse_req_t req, size_t count)
@@ -1877,6 +1903,7 @@ static void _do_release(fuse_req_t req, const fuse_ino_t nodeid,
 {
 	(void)in_payload;
 	const struct fuse_release_in *arg = op_in;
+	struct fuse_session *se = req->se;
 	struct fuse_file_info fi;
 
 	memset(&fi, 0, sizeof(fi));
@@ -1895,6 +1922,7 @@ static void _do_release(fuse_req_t req, const fuse_ino_t nodeid,
 		req->se->op.release(req, nodeid, &fi);
 	else
 		fuse_reply_err(req, 0);
+	dec_open_files(se);
 }
 
 static void do_release(fuse_req_t req, const fuse_ino_t nodeid,
@@ -1999,6 +2027,7 @@ static void _do_releasedir(fuse_req_t req, const fuse_ino_t nodeid,
 {
 	(void)in_payload;
 	struct fuse_release_in *arg = (struct fuse_release_in *)op_in;
+	struct fuse_session *se = req->se;
 	struct fuse_file_info fi;
 
 	memset(&fi, 0, sizeof(fi));
@@ -2009,6 +2038,7 @@ static void _do_releasedir(fuse_req_t req, const fuse_ino_t nodeid,
 		req->se->op.releasedir(req, nodeid, &fi);
 	else
 		fuse_reply_err(req, 0);
+	dec_open_files(se);
 }
 
 static void do_releasedir(fuse_req_t req, const fuse_ino_t nodeid,
@@ -3027,15 +3057,21 @@ do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
 	_do_init(req, nodeid, inarg, NULL);
 }
 
-static void _do_destroy(fuse_req_t req, const fuse_ino_t nodeid,
-			const void *op_in, const void *in_payload)
+static void *__fuse_destroy_sync(void *arg)
 {
+	struct fuse_req *req = arg;
 	struct fuse_session *se = req->se;
 	char *mountpoint;
 
-	(void) nodeid;
-	(void)op_in;
-	(void)in_payload;
+	/*
+	 * Wait for all the FUSE_RELEASE requests to work their way through the
+	 * other worker threads, if any.
+	 */
+	pthread_mutex_lock(&se->lock);
+	se->open_files--;
+	while (se->open_files > 0)
+		pthread_cond_wait(&se->zero_open_files, &se->lock);
+	pthread_mutex_unlock(&se->lock);
 
 	mountpoint = atomic_exchange(&se->mountpoint, NULL);
 	free(mountpoint);
@@ -3046,6 +3082,54 @@ static void _do_destroy(fuse_req_t req, const fuse_ino_t nodeid,
 		se->op.destroy(se->userdata);
 
 	send_reply_ok(req, NULL, 0);
+	return NULL;
+}
+
+/*
+ * Destroy the fuse session asynchronously.
+ *
+ * If we have any open files, then we want to kick the actual destroy call to a
+ * new detached background thread that can wait for the open file count to
+ * reach zero without blocking processing of the rest of the commands that are
+ * pending in the fuse thread's cqe.  For non-uring multithreaded mode, we also
+ * use the detached thread to avoid blocking a fuse worker from processing
+ * other commands.
+ *
+ * If the kernel sends us an explicit FUSE_DESTROY command then it won't tear
+ * down the fuse fd until it receives the reply, so fuse_session_destroy
+ * doesn't need to wait for this thread.
+ */
+static int __fuse_destroy_try_async(fuse_req_t req)
+{
+	pthread_t destroy_thread;
+	pthread_attr_t destroy_attr;
+	int ret;
+
+	ret = pthread_attr_init(&destroy_attr);
+	if (ret)
+		return ret;
+
+	ret = pthread_attr_setdetachstate(&destroy_attr,
+			PTHREAD_CREATE_DETACHED);
+	if (ret)
+		return ret;
+
+	return pthread_create(&destroy_thread, &destroy_attr,
+			__fuse_destroy_sync, req);
+}
+
+static void _do_destroy(fuse_req_t req, const fuse_ino_t nodeid,
+			const void *op_in, const void *in_payload)
+{
+	struct fuse_session *se = req->se;
+
+	(void) nodeid;
+	(void)op_in;
+	(void)in_payload;
+
+	if (se->open_files > 0 && __fuse_destroy_try_async(req) == 0)
+		return;
+	__fuse_destroy_sync(req);
 }
 
 static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
@@ -3891,6 +3975,7 @@ void fuse_session_destroy(struct fuse_session *se)
 		fuse_ll_pipe_free(llp);
 	pthread_key_delete(se->pipe_key);
 	sem_destroy(&se->mt_finish);
+	pthread_cond_destroy(&se->zero_open_files);
 	pthread_mutex_destroy(&se->mt_lock);
 	pthread_mutex_destroy(&se->lock);
 	free(se->cuse_data);
@@ -4275,9 +4360,16 @@ fuse_session_new_versioned(struct fuse_args *args,
 	list_init_nreq(&se->notify_list);
 	se->notify_ctr = 1;
 	pthread_mutex_init(&se->lock, NULL);
+	pthread_cond_init(&se->zero_open_files, NULL);
 	sem_init(&se->mt_finish, 0, 0);
 	pthread_mutex_init(&se->mt_lock, NULL);
 
+	/*
+	 * Bias the open file counter by 1 so that we only wake the condition
+	 * variable once FUSE_DESTROY has been seen.
+	 */
+	se->open_files = 1;
+
 	err = pthread_key_create(&se->pipe_key, fuse_ll_pipe_destructor);
 	if (err) {
 		fuse_log(FUSE_LOG_ERR, "fuse: failed to create thread specific key: %s\n",
@@ -4302,6 +4394,7 @@ fuse_session_new_versioned(struct fuse_args *args,
 
 out5:
 	sem_destroy(&se->mt_finish);
+	pthread_cond_destroy(&se->zero_open_files);
 	pthread_mutex_destroy(&se->mt_lock);
 	pthread_mutex_destroy(&se->lock);
 out4:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 03/25] libfuse: add kernel gates for FUSE_IOMAP
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
  2026-02-23 23:25   ` [PATCH 01/25] libfuse: bump kernel and library ABI versions Darrick J. Wong
  2026-02-23 23:25   ` [PATCH 02/25] libfuse: wait in do_destroy until all open files are closed Darrick J. Wong
@ 2026-02-23 23:26   ` Darrick J. Wong
  2026-02-23 23:26   ` [PATCH 04/25] libfuse: add fuse commands for iomap_begin and end Darrick J. Wong
                     ` (21 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:26 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Add some flags to query and request kernel support for filesystem iomap
for regular files.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h |    5 +++++
 include/fuse_kernel.h |    3 +++
 lib/fuse_lowlevel.c   |   12 +++++++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index 041188ec7fa732..9d53354de78868 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -512,6 +512,11 @@ struct fuse_loop_config_v1 {
  */
 #define FUSE_CAP_OVER_IO_URING (1UL << 31)
 
+/**
+ * Client supports using iomap for regular file operations
+ */
+#define FUSE_CAP_IOMAP (1ULL << 32)
+
 /**
  * Ioctl flags
  *
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 842cc08a083a6f..354a6da01c2ecc 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -243,6 +243,7 @@
  *
  *  7.99
  *  - XXX magic minor revision to make experimental code really obvious
+ *  - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations
  */
 
 #ifndef _LINUX_FUSE_H
@@ -451,6 +452,7 @@ struct fuse_file_lock {
  * FUSE_OVER_IO_URING: Indicate that client supports io-uring
  * FUSE_REQUEST_TIMEOUT: kernel supports timing out requests.
  *			 init_out.request_timeout contains the timeout (in secs)
+ * FUSE_IOMAP: Client supports iomap for regular file operations
  */
 #define FUSE_ASYNC_READ		(1 << 0)
 #define FUSE_POSIX_LOCKS	(1 << 1)
@@ -498,6 +500,7 @@ struct fuse_file_lock {
 #define FUSE_ALLOW_IDMAP	(1ULL << 40)
 #define FUSE_OVER_IO_URING	(1ULL << 41)
 #define FUSE_REQUEST_TIMEOUT	(1ULL << 42)
+#define FUSE_IOMAP		(1ULL << 43)
 
 /**
  * CUSE INIT request/reply flags
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index c3d57f5c5b104c..237c02c6dce7d5 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -2817,7 +2817,10 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in,
 			se->conn.capable_ext |= FUSE_CAP_NO_EXPORT_SUPPORT;
 		if (inargflags & FUSE_OVER_IO_URING)
 			se->conn.capable_ext |= FUSE_CAP_OVER_IO_URING;
-
+		if (inargflags & FUSE_IOMAP)
+			se->conn.capable_ext |= FUSE_CAP_IOMAP;
+		/* Don't let anyone touch iomap until the end of the patchset. */
+		se->conn.capable_ext &= ~FUSE_CAP_IOMAP;
 	} else {
 		se->conn.max_readahead = 0;
 	}
@@ -2863,6 +2866,9 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in,
 		       FUSE_CAP_READDIRPLUS_AUTO);
 	LL_SET_DEFAULT(1, FUSE_CAP_OVER_IO_URING);
 
+	/* servers need to opt-in to iomap explicitly */
+	LL_SET_DEFAULT(0, FUSE_CAP_IOMAP);
+
 	/* This could safely become default, but libfuse needs an API extension
 	 * to support it
 	 * LL_SET_DEFAULT(1, FUSE_CAP_SETXATTR_EXT);
@@ -2980,6 +2986,8 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in,
 		outargflags |= FUSE_REQUEST_TIMEOUT;
 		outarg.request_timeout = se->conn.request_timeout;
 	}
+	if (se->conn.want_ext & FUSE_CAP_IOMAP)
+		outargflags |= FUSE_IOMAP;
 
 	outarg.max_readahead = se->conn.max_readahead;
 	outarg.max_write = se->conn.max_write;
@@ -3014,6 +3022,8 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in,
 		if (se->conn.want_ext & FUSE_CAP_PASSTHROUGH)
 			fuse_log(FUSE_LOG_DEBUG, "   max_stack_depth=%u\n",
 				outarg.max_stack_depth);
+		if (se->conn.want_ext & FUSE_CAP_IOMAP)
+			fuse_log(FUSE_LOG_DEBUG, "   iomap=1\n");
 	}
 	if (arg->minor < 5)
 		outargsize = FUSE_COMPAT_INIT_OUT_SIZE;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 04/25] libfuse: add fuse commands for iomap_begin and end
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:26   ` [PATCH 03/25] libfuse: add kernel gates for FUSE_IOMAP Darrick J. Wong
@ 2026-02-23 23:26   ` Darrick J. Wong
  2026-02-23 23:26   ` [PATCH 05/25] libfuse: add upper level iomap commands Darrick J. Wong
                     ` (20 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:26 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Teach the low level API how to handle iomap begin and end commands that
we get from the kernel.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h   |   71 +++++++++++++++++++++++++++++++++
 include/fuse_kernel.h   |   40 ++++++++++++++++++
 include/fuse_lowlevel.h |   59 +++++++++++++++++++++++++++
 lib/fuse_lowlevel.c     |  102 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/fuse_versionscript  |    3 +
 5 files changed, 275 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index 9d53354de78868..58726ce43b1014 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1135,7 +1135,78 @@ bool fuse_get_feature_flag(struct fuse_conn_info *conn, uint64_t flag);
  */
 int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn);
 
+/**
+ * iomap operations.
+ * These APIs are introduced in version 399 (FUSE_MAKE_VERSION(3, 99)).
+ */
 
+/* mapping types; see corresponding IOMAP_TYPE_ */
+#define FUSE_IOMAP_TYPE_HOLE		(0)
+#define FUSE_IOMAP_TYPE_DELALLOC	(1)
+#define FUSE_IOMAP_TYPE_MAPPED		(2)
+#define FUSE_IOMAP_TYPE_UNWRITTEN	(3)
+#define FUSE_IOMAP_TYPE_INLINE		(4)
+
+/* fuse-specific mapping type indicating that writes use the read mapping */
+#define FUSE_IOMAP_TYPE_PURE_OVERWRITE	(255)
+
+#define FUSE_IOMAP_DEV_NULL		(0U)	/* null device cookie */
+
+/* mapping flags passed back from iomap_begin; see corresponding IOMAP_F_ */
+#define FUSE_IOMAP_F_NEW		(1U << 0)
+#define FUSE_IOMAP_F_DIRTY		(1U << 1)
+#define FUSE_IOMAP_F_SHARED		(1U << 2)
+#define FUSE_IOMAP_F_MERGED		(1U << 3)
+#define FUSE_IOMAP_F_BOUNDARY		(1U << 4)
+#define FUSE_IOMAP_F_ANON_WRITE		(1U << 5)
+#define FUSE_IOMAP_F_ATOMIC_BIO		(1U << 6)
+
+/* fuse-specific mapping flag asking for ->iomap_end call */
+#define FUSE_IOMAP_F_WANT_IOMAP_END	(1U << 7)
+
+/* mapping flags passed to iomap_end */
+#define FUSE_IOMAP_F_SIZE_CHANGED	(1U << 8)
+#define FUSE_IOMAP_F_STALE		(1U << 9)
+
+/* operation flags from iomap; see corresponding IOMAP_* */
+#define FUSE_IOMAP_OP_WRITE		(1U << 0)
+#define FUSE_IOMAP_OP_ZERO		(1U << 1)
+#define FUSE_IOMAP_OP_REPORT		(1U << 2)
+#define FUSE_IOMAP_OP_FAULT		(1U << 3)
+#define FUSE_IOMAP_OP_DIRECT		(1U << 4)
+#define FUSE_IOMAP_OP_NOWAIT		(1U << 5)
+#define FUSE_IOMAP_OP_OVERWRITE_ONLY	(1U << 6)
+#define FUSE_IOMAP_OP_UNSHARE		(1U << 7)
+#define FUSE_IOMAP_OP_DAX		(1U << 8)
+#define FUSE_IOMAP_OP_ATOMIC		(1U << 9)
+#define FUSE_IOMAP_OP_DONTCACHE		(1U << 10)
+
+/* pagecache writeback operation */
+#define FUSE_IOMAP_OP_WRITEBACK		(1U << 31)
+
+#define FUSE_IOMAP_NULL_ADDR		(-1ULL)	/* addr is not valid */
+
+struct fuse_file_iomap {
+	uint64_t offset;	/* file offset of mapping, bytes */
+	uint64_t length;	/* length of mapping, bytes */
+	uint64_t addr;		/* disk offset of mapping, bytes */
+	uint16_t type;		/* FUSE_IOMAP_TYPE_* */
+	uint16_t flags;		/* FUSE_IOMAP_F_* */
+	uint32_t dev;		/* device cookie */
+};
+
+static inline bool fuse_iomap_is_write(unsigned int opflags)
+{
+	return opflags & (FUSE_IOMAP_OP_WRITE | FUSE_IOMAP_OP_ZERO |
+			  FUSE_IOMAP_OP_UNSHARE | FUSE_IOMAP_OP_WRITEBACK);
+}
+
+static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
+					const struct fuse_file_iomap *map)
+{
+	return map->type == FUSE_IOMAP_TYPE_HOLE &&
+		!(opflags & FUSE_IOMAP_OP_ZERO);
+}
 
 /* ----------------------------------------------------------- *
  * Compatibility stuff					       *
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 354a6da01c2ecc..b3750bb6275620 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -670,6 +670,9 @@ enum fuse_opcode {
 	FUSE_STATX		= 52,
 	FUSE_COPY_FILE_RANGE_64	= 53,
 
+	FUSE_IOMAP_BEGIN	= 4094,
+	FUSE_IOMAP_END		= 4095,
+
 	/* CUSE specific operations */
 	CUSE_INIT		= 4096,
 
@@ -1313,4 +1316,41 @@ struct fuse_uring_cmd_req {
 	uint8_t padding[6];
 };
 
+struct fuse_iomap_io {
+	uint64_t offset;	/* file offset of mapping, bytes */
+	uint64_t length;	/* length of mapping, bytes */
+	uint64_t addr;		/* disk offset of mapping, bytes */
+	uint16_t type;		/* FUSE_IOMAP_TYPE_* */
+	uint16_t flags;		/* FUSE_IOMAP_F_* */
+	uint32_t dev;		/* device cookie */
+};
+
+struct fuse_iomap_begin_in {
+	uint32_t opflags;	/* FUSE_IOMAP_OP_* */
+	uint32_t reserved;	/* zero */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+	uint64_t pos;		/* file position, in bytes */
+	uint64_t count;		/* operation length, in bytes */
+};
+
+struct fuse_iomap_begin_out {
+	/* read file data from here */
+	struct fuse_iomap_io	read;
+
+	/* write file data to here, if applicable */
+	struct fuse_iomap_io	write;
+};
+
+struct fuse_iomap_end_in {
+	uint32_t opflags;	/* FUSE_IOMAP_OP_* */
+	uint32_t reserved;	/* zero */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+	uint64_t pos;		/* file position, in bytes */
+	uint64_t count;		/* operation length, in bytes */
+	int64_t written;	/* bytes processed */
+
+	/* mapping that the kernel acted upon */
+	struct fuse_iomap_io	map;
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index ee0bd8d71d95e4..f01fb06d6737ba 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -1357,6 +1357,43 @@ struct fuse_lowlevel_ops {
 	 * @param ino the inode number
 	 */
 	void (*syncfs)(fuse_req_t req, fuse_ino_t ino);
+
+	/**
+	 * Fetch file I/O mappings to begin an operation
+	 *
+	 * Valid replies:
+	 *   fuse_reply_iomap_begin
+	 *   fuse_reply_err
+	 *
+	 * @param req request handle
+	 * @param nodeid the inode number
+	 * @param attr_ino inode number as told by fuse_attr::ino
+	 * @param pos position in file, in bytes
+	 * @param count length of operation, in bytes
+	 * @param opflags mask of FUSE_IOMAP_OP_ flags specifying operation
+	 */
+	void (*iomap_begin) (fuse_req_t req, fuse_ino_t nodeid,
+			     uint64_t attr_ino, off_t pos, uint64_t count,
+			     uint32_t opflags);
+
+	/**
+	 * Complete an iomap operation
+	 *
+	 * Valid replies:
+	 *   fuse_reply_err
+	 *
+	 * @param req request handle
+	 * @param nodeid the inode number
+	 * @param attr_ino inode number as told by fuse_attr::ino
+	 * @param pos position in file, in bytes
+	 * @param count length of operation, in bytes
+	 * @param written number of bytes processed, or a negative errno
+	 * @param opflags mask of FUSE_IOMAP_OP_ flags specifying operation
+	 * @param iomap file I/O mapping that was acted upon
+	 */
+	void (*iomap_end) (fuse_req_t req, fuse_ino_t nodeid, uint64_t attr_ino,
+			   off_t pos, uint64_t count, uint32_t opflags,
+			   ssize_t written, const struct fuse_file_iomap *iomap);
 };
 
 /**
@@ -1751,6 +1788,28 @@ int fuse_reply_lseek(fuse_req_t req, off_t off);
  */
 int fuse_reply_statx(fuse_req_t req, int flags, struct statx *statx, double attr_timeout);
 
+/**
+ * Set an iomap write mapping to be a pure overwrite of the read mapping.
+ * @param write mapping for file data writes
+ * @param read mapping for file data reads
+ */
+void fuse_iomap_pure_overwrite(struct fuse_file_iomap *write,
+			       const struct fuse_file_iomap *read);
+
+/**
+ * Reply with iomappings for an iomap_begin operation
+ *
+ * Possible requests:
+ *   iomap_begin
+ *
+ * @param req request handle
+ * @param read mapping for file data reads
+ * @param write mapping for file data writes
+ * @return zero for success, -errno for failure to send reply
+ */
+int fuse_reply_iomap_begin(fuse_req_t req, const struct fuse_file_iomap *read,
+			   const struct fuse_file_iomap *write);
+
 /* ----------------------------------------------------------- *
  * Notification						       *
  * ----------------------------------------------------------- */
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 237c02c6dce7d5..ccfae61390290b 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -2620,6 +2620,104 @@ static void do_syncfs(fuse_req_t req, const fuse_ino_t nodeid,
 	_do_syncfs(req, nodeid, inarg, NULL);
 }
 
+void fuse_iomap_pure_overwrite(struct fuse_file_iomap *write,
+			       const struct fuse_file_iomap *read)
+{
+	write->addr = FUSE_IOMAP_NULL_ADDR;
+	write->offset = read->offset;
+	write->length = read->length;
+	write->type = FUSE_IOMAP_TYPE_PURE_OVERWRITE;
+	write->flags = 0;
+	write->dev = FUSE_IOMAP_DEV_NULL;
+}
+
+static inline void fuse_iomap_to_kernel(struct fuse_iomap_io *fmap,
+					const struct fuse_file_iomap *fimap)
+{
+	fmap->addr = fimap->addr;
+	fmap->offset = fimap->offset;
+	fmap->length = fimap->length;
+	fmap->type = fimap->type;
+	fmap->flags = fimap->flags;
+	fmap->dev = fimap->dev;
+}
+
+static inline void fuse_iomap_from_kernel(struct fuse_file_iomap *fimap,
+					  const struct fuse_iomap_io *fmap)
+{
+	fimap->addr = fmap->addr;
+	fimap->offset = fmap->offset;
+	fimap->length = fmap->length;
+	fimap->type = fmap->type;
+	fimap->flags = fmap->flags;
+	fimap->dev = fmap->dev;
+}
+
+int fuse_reply_iomap_begin(fuse_req_t req, const struct fuse_file_iomap *read,
+			   const struct fuse_file_iomap *write)
+{
+	struct fuse_iomap_begin_out arg = {
+		.write = {
+			.addr = FUSE_IOMAP_NULL_ADDR,
+			.offset = read->offset,
+			.length = read->length,
+			.type = FUSE_IOMAP_TYPE_PURE_OVERWRITE,
+			.flags = 0,
+			.dev = FUSE_IOMAP_DEV_NULL,
+		},
+	};
+
+	fuse_iomap_to_kernel(&arg.read, read);
+	if (write)
+		fuse_iomap_to_kernel(&arg.write, write);
+
+	return send_reply_ok(req, &arg, sizeof(arg));
+}
+
+static void _do_iomap_begin(fuse_req_t req, const fuse_ino_t nodeid,
+			    const void *op_in, const void *in_payload)
+{
+	const struct fuse_iomap_begin_in *arg = op_in;
+	(void)in_payload;
+	(void)nodeid;
+
+	if (req->se->op.iomap_begin)
+		req->se->op.iomap_begin(req, nodeid, arg->attr_ino, arg->pos,
+					arg->count, arg->opflags);
+	else
+		fuse_reply_err(req, ENOSYS);
+}
+
+static void do_iomap_begin(fuse_req_t req, const fuse_ino_t nodeid,
+			   const void *inarg)
+{
+	_do_iomap_begin(req, nodeid, inarg, NULL);
+}
+
+static void _do_iomap_end(fuse_req_t req, const fuse_ino_t nodeid,
+			    const void *op_in, const void *in_payload)
+{
+	const struct fuse_iomap_end_in *arg = op_in;
+	(void)in_payload;
+	(void)nodeid;
+
+	if (req->se->op.iomap_end) {
+		struct fuse_file_iomap fimap;
+
+		fuse_iomap_from_kernel(&fimap, &arg->map);
+		req->se->op.iomap_end(req, nodeid, arg->attr_ino, arg->pos,
+				      arg->count, arg->opflags, arg->written,
+				      &fimap);
+	} else
+		fuse_reply_err(req, ENOSYS);
+}
+
+static void do_iomap_end(fuse_req_t req, const fuse_ino_t nodeid,
+			   const void *inarg)
+{
+	_do_iomap_end(req, nodeid, inarg, NULL);
+}
+
 static bool want_flags_valid(uint64_t capable, uint64_t want)
 {
 	uint64_t unknown_flags = want & (~capable);
@@ -3606,6 +3704,8 @@ static struct {
 	[FUSE_LSEEK]	   = { do_lseek,       "LSEEK"	     },
 	[FUSE_SYNCFS]	   = { do_syncfs,      "SYNCFS"      },
 	[FUSE_STATX]	   = { do_statx,       "STATX"	     },
+	[FUSE_IOMAP_BEGIN] = { do_iomap_begin,	"IOMAP_BEGIN" },
+	[FUSE_IOMAP_END]   = { do_iomap_end,	"IOMAP_END" },
 	[CUSE_INIT]	   = { cuse_lowlevel_init, "CUSE_INIT"   },
 };
 
@@ -3663,6 +3763,8 @@ static struct {
 	[FUSE_LSEEK]		= { _do_lseek,		"LSEEK" },
 	[FUSE_SYNCFS]		= { _do_syncfs,		"SYNCFS" },
 	[FUSE_STATX]		= { _do_statx,		"STATX" },
+	[FUSE_IOMAP_BEGIN]	= { _do_iomap_begin,	"IOMAP_BEGIN" },
+	[FUSE_IOMAP_END]	= { _do_iomap_end,	"IOMAP_END" },
 	[CUSE_INIT]		= { _cuse_lowlevel_init, "CUSE_INIT" },
 };
 
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 826d9fee00a8ee..e346ce29a7f7a3 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -230,6 +230,9 @@ FUSE_3.19 {
 } FUSE_3.18;
 
 FUSE_3.99 {
+	global:
+		fuse_iomap_pure_overwrite;
+		fuse_reply_iomap_begin;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 05/25] libfuse: add upper level iomap commands
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:26   ` [PATCH 04/25] libfuse: add fuse commands for iomap_begin and end Darrick J. Wong
@ 2026-02-23 23:26   ` Darrick J. Wong
  2026-02-23 23:26   ` [PATCH 06/25] libfuse: add a lowlevel notification to add a new device to iomap Darrick J. Wong
                     ` (19 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:26 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Teach the upper level fuse library about the iomap begin and end
operations, and connect it to the lower level.  This is needed for
fuse2fs to start using iomap.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h |   17 +++++++++
 lib/fuse.c     |  102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 119 insertions(+)


diff --git a/include/fuse.h b/include/fuse.h
index 595cac07f2be36..1c8caf0c2ee034 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -885,6 +885,23 @@ struct fuse_operations {
 	 * calling fsync(2) on every file on the filesystem.
 	 */
 	int (*syncfs)(const char *path);
+
+	/**
+	 * Send a mapping to the kernel so that a file IO operation can run.
+	 */
+	int (*iomap_begin) (const char *path, uint64_t nodeid,
+			    uint64_t attr_ino, off_t pos_in,
+			    uint64_t length_in, uint32_t opflags_in,
+			    struct fuse_file_iomap *read_out,
+			    struct fuse_file_iomap *write_out);
+
+	/**
+	 * Respond to the outcome of a previous file mapping operation.
+	 */
+	int (*iomap_end) (const char *path, uint64_t nodeid, uint64_t attr_ino,
+			  off_t pos_in, uint64_t length_in,
+			  uint32_t opflags_in, ssize_t written_in,
+			  const struct fuse_file_iomap *iomap);
 };
 
 /** Extra context that may be needed by some filesystems
diff --git a/lib/fuse.c b/lib/fuse.c
index 65c3ce217a7784..ac325b1a3d9e82 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2804,6 +2804,49 @@ int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode,
 	return fs->op.chmod(path, mode, fi);
 }
 
+static int fuse_fs_iomap_begin(struct fuse_fs *fs, const char *path,
+			       fuse_ino_t nodeid, uint64_t attr_ino, off_t pos,
+			       uint64_t count, uint32_t opflags,
+			       struct fuse_file_iomap *read,
+			       struct fuse_file_iomap *write)
+{
+	fuse_get_context()->private_data = fs->user_data;
+	if (!fs->op.iomap_begin)
+		return -ENOSYS;
+
+	if (fs->debug) {
+		fuse_log(FUSE_LOG_DEBUG,
+			 "iomap_begin[%s] nodeid %llu attr_ino %llu pos %llu count %llu opflags 0x%x\n",
+			 path, (unsigned long long)nodeid,
+			 (unsigned long long)attr_ino, (unsigned long long)pos,
+			 (unsigned long long)count, opflags);
+	}
+
+	return fs->op.iomap_begin(path, nodeid, attr_ino, pos, count, opflags,
+				  read, write);
+}
+
+static int fuse_fs_iomap_end(struct fuse_fs *fs, const char *path,
+			     fuse_ino_t nodeid, uint64_t attr_ino, off_t pos,
+			     uint64_t count, uint32_t opflags, ssize_t written,
+			     const struct fuse_file_iomap *iomap)
+{
+	fuse_get_context()->private_data = fs->user_data;
+	if (!fs->op.iomap_end)
+		return -ENOSYS;
+
+	if (fs->debug) {
+		fuse_log(FUSE_LOG_DEBUG,
+			 "iomap_end[%s] nodeid %llu attr_ino %llu pos %llu count %llu opflags 0x%x written %zd\n",
+			 path, (unsigned long long)nodeid,
+			 (unsigned long long)attr_ino, (unsigned long long)pos,
+			 (unsigned long long)count, opflags, written);
+	}
+
+	return fs->op.iomap_end(path, nodeid, attr_ino, pos, count, opflags,
+				written, iomap);
+}
+
 static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
 			     int valid, struct fuse_file_info *fi)
 {
@@ -4497,6 +4540,63 @@ static void fuse_lib_syncfs(fuse_req_t req, fuse_ino_t ino)
 	reply_err(req, err);
 }
 
+static void fuse_lib_iomap_begin(fuse_req_t req, fuse_ino_t nodeid,
+				 uint64_t attr_ino, off_t pos, uint64_t count,
+				 uint32_t opflags)
+{
+	struct fuse *f = req_fuse_prepare(req);
+	struct fuse_file_iomap read = { };
+	struct fuse_file_iomap write = { };
+	struct fuse_intr_data d;
+	char *path;
+	int err;
+
+	err = get_path_nullok(f, nodeid, &path);
+	if (err) {
+		reply_err(req, err);
+		return;
+	}
+
+	fuse_prepare_interrupt(f, req, &d);
+	err = fuse_fs_iomap_begin(f->fs, path, nodeid, attr_ino, pos, count,
+				  opflags, &read, &write);
+	fuse_finish_interrupt(f, req, &d);
+	free_path(f, nodeid, path);
+	if (err) {
+		reply_err(req, err);
+		return;
+	}
+
+	if (write.length == 0)
+		fuse_iomap_pure_overwrite(&write, &read);
+
+	fuse_reply_iomap_begin(req, &read, &write);
+}
+
+static void fuse_lib_iomap_end(fuse_req_t req, fuse_ino_t nodeid,
+			       uint64_t attr_ino, off_t pos, uint64_t count,
+			       uint32_t opflags, ssize_t written,
+			       const struct fuse_file_iomap *iomap)
+{
+	struct fuse *f = req_fuse_prepare(req);
+	struct fuse_intr_data d;
+	char *path;
+	int err;
+
+	err = get_path_nullok(f, nodeid, &path);
+	if (err) {
+		reply_err(req, err);
+		return;
+	}
+
+	fuse_prepare_interrupt(f, req, &d);
+	err = fuse_fs_iomap_end(f->fs, path, nodeid, attr_ino, pos, count,
+				opflags, written, iomap);
+	fuse_finish_interrupt(f, req, &d);
+	free_path(f, nodeid, path);
+	reply_err(req, err);
+}
+
 static int clean_delay(struct fuse *f)
 {
 	/*
@@ -4599,6 +4699,8 @@ static struct fuse_lowlevel_ops fuse_path_ops = {
 	.statx = fuse_lib_statx,
 #endif
 	.syncfs = fuse_lib_syncfs,
+	.iomap_begin = fuse_lib_iomap_begin,
+	.iomap_end = fuse_lib_iomap_end,
 };
 
 int fuse_notify_poll(struct fuse_pollhandle *ph)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 06/25] libfuse: add a lowlevel notification to add a new device to iomap
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (4 preceding siblings ...)
  2026-02-23 23:26   ` [PATCH 05/25] libfuse: add upper level iomap commands Darrick J. Wong
@ 2026-02-23 23:26   ` Darrick J. Wong
  2026-02-23 23:27   ` [PATCH 07/25] libfuse: add upper-level iomap add device function Darrick J. Wong
                     ` (18 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:26 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Plumb in the pieces needed to attach block devices to a fuse+iomap mount
for use with iomap operations.  This enables us to have filesystems
where the metadata could live somewhere else, but the actual file IO
goes to locally attached storage.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_kernel.h   |    7 +++++++
 include/fuse_lowlevel.h |   30 +++++++++++++++++++++++++++++
 lib/fuse_lowlevel.c     |   49 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/fuse_versionscript  |    2 ++
 4 files changed, 88 insertions(+)


diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index b3750bb6275620..e69f9675c4b57d 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -1135,6 +1135,13 @@ struct fuse_notify_prune_out {
 	uint64_t	spare;
 };
 
+#define FUSE_BACKING_TYPE_MASK		(0xFF)
+#define FUSE_BACKING_TYPE_PASSTHROUGH	(0)
+#define FUSE_BACKING_TYPE_IOMAP		(1)
+#define FUSE_BACKING_MAX_TYPE		(FUSE_BACKING_TYPE_IOMAP)
+
+#define FUSE_BACKING_FLAGS_ALL		(FUSE_BACKING_TYPE_MASK)
+
 struct fuse_backing_map {
 	int32_t		fd;
 	uint32_t	flags;
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index f01fb06d6737ba..7f9a56b0a7eda1 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -2034,6 +2034,36 @@ int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
 int fuse_lowlevel_notify_prune(struct fuse_session *se,
 			       fuse_ino_t *nodeids, uint32_t count);
 
+/*
+ * Attach an open file descriptor to a fuse+iomap mount.  Currently must be
+ * a block device.
+ *
+ * Added in FUSE protocol version 7.99. If the kernel does not support
+ * this (or a newer) version, the function will return -ENOSYS and do
+ * nothing.
+ *
+ * @param se the session object
+ * @param fd file descriptor of an open block device
+ * @param flags flags for the operation; none defined so far
+ * @return positive nonzero device id on success, or negative errno on failure
+ */
+int fuse_lowlevel_iomap_device_add(struct fuse_session *se, int fd,
+				   unsigned int flags);
+
+/**
+ * Detach an open file from a fuse+iomap mount.  Must be a device id returned
+ * by fuse_lowlevel_iomap_device_add.
+ *
+ * Added in FUSE protocol version 7.99. If the kernel does not support
+ * this (or a newer) version, the function will return -ENOSYS and do
+ * nothing.
+ *
+ * @param se the session object
+ * @param device_id device index as returned by fuse_lowlevel_iomap_device_add
+ * @return 0 on success, or negative errno on failure
+ */
+int fuse_lowlevel_iomap_device_remove(struct fuse_session *se, int device_id);
+
 /* ----------------------------------------------------------- *
  * Utility functions					       *
  * ----------------------------------------------------------- */
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index ccfae61390290b..cf97ed8b471c49 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -624,6 +624,55 @@ int fuse_passthrough_close(fuse_req_t req, int backing_id)
 	return ret;
 }
 
+int fuse_lowlevel_iomap_device_add(struct fuse_session *se, int fd,
+				   unsigned int flags)
+{
+	struct fuse_backing_map map = {
+		.fd = fd,
+		.flags = FUSE_BACKING_TYPE_IOMAP |
+			(flags & ~FUSE_BACKING_TYPE_MASK),
+	};
+	int ret;
+
+	if (!(se->conn.want_ext & FUSE_CAP_IOMAP))
+		return -ENOSYS;
+
+	ret = ioctl(se->fd, FUSE_DEV_IOC_BACKING_OPEN, &map);
+	if (ret == 0) {
+		/* not supposed to happen */
+		ret = -1;
+		errno = ERANGE;
+	}
+	if (ret < 0) {
+		int err = errno;
+
+		fuse_log(FUSE_LOG_ERR, "fuse: iomap_device_add: %s\n",
+			 strerror(err));
+		return -err;
+	}
+
+	return ret;
+}
+
+int fuse_lowlevel_iomap_device_remove(struct fuse_session *se, int device_id)
+{
+	int ret;
+
+	if (!(se->conn.want_ext & FUSE_CAP_IOMAP))
+		return -ENOSYS;
+
+	ret = ioctl(se->fd, FUSE_DEV_IOC_BACKING_CLOSE, &device_id);
+	if (ret < 0) {
+		int err = errno;
+
+		fuse_log(FUSE_LOG_ERR, "fuse: iomap_device_remove: %s\n",
+			 strerror(errno));
+		return -err;
+	}
+
+	return ret;
+}
+
 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *f)
 {
 	struct fuse_open_out arg;
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index e346ce29a7f7a3..bd9255f95d9948 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -233,6 +233,8 @@ FUSE_3.99 {
 	global:
 		fuse_iomap_pure_overwrite;
 		fuse_reply_iomap_begin;
+		fuse_lowlevel_iomap_device_add;
+		fuse_lowlevel_iomap_device_remove;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 07/25] libfuse: add upper-level iomap add device function
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (5 preceding siblings ...)
  2026-02-23 23:26   ` [PATCH 06/25] libfuse: add a lowlevel notification to add a new device to iomap Darrick J. Wong
@ 2026-02-23 23:27   ` Darrick J. Wong
  2026-02-23 23:27   ` [PATCH 08/25] libfuse: add iomap ioend low level handler Darrick J. Wong
                     ` (17 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:27 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Make it so that the upper level fuse library can add iomap devices too.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h         |   19 +++++++++++++++++++
 lib/fuse.c             |   16 ++++++++++++++++
 lib/fuse_versionscript |    2 ++
 3 files changed, 37 insertions(+)


diff --git a/include/fuse.h b/include/fuse.h
index 1c8caf0c2ee034..23b6d3f7c93303 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -1403,6 +1403,25 @@ void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn,
 		struct fuse_config *cfg);
 void fuse_fs_destroy(struct fuse_fs *fs);
 
+/**
+ * Attach an open file descriptor to a fuse+iomap mount.  Currently must be
+ * a block device.
+ *
+ * @param fd file descriptor of an open block device
+ * @param flags flags for the operation; none defined so far
+ * @return positive nonzero device id on success, or negative errno on failure
+ */
+int fuse_fs_iomap_device_add(int fd, unsigned int flags);
+
+/**
+ * Detach an open file from a fuse+iomap mount.  Must be a device id returned
+ * by fuse_lowlevel_iomap_device_add.
+ *
+ * @param device_id device index as returned by fuse_lowlevel_iomap_device_add
+ * @return 0 on success, or negative errno on failure
+ */
+int fuse_fs_iomap_device_remove(int device_id);
+
 int fuse_notify_poll(struct fuse_pollhandle *ph);
 
 /**
diff --git a/lib/fuse.c b/lib/fuse.c
index ac325b1a3d9e82..9662d007746809 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2847,6 +2847,22 @@ static int fuse_fs_iomap_end(struct fuse_fs *fs, const char *path,
 				written, iomap);
 }
 
+int fuse_fs_iomap_device_add(int fd, unsigned int flags)
+{
+	struct fuse_context *ctxt = fuse_get_context();
+	struct fuse_session *se = fuse_get_session(ctxt->fuse);
+
+	return fuse_lowlevel_iomap_device_add(se, fd, flags);
+}
+
+int fuse_fs_iomap_device_remove(int device_id)
+{
+	struct fuse_context *ctxt = fuse_get_context();
+	struct fuse_session *se = fuse_get_session(ctxt->fuse);
+
+	return fuse_lowlevel_iomap_device_remove(se, device_id);
+}
+
 static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
 			     int valid, struct fuse_file_info *fi)
 {
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index bd9255f95d9948..5c4a7dc53b33f3 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -235,6 +235,8 @@ FUSE_3.99 {
 		fuse_reply_iomap_begin;
 		fuse_lowlevel_iomap_device_add;
 		fuse_lowlevel_iomap_device_remove;
+		fuse_fs_iomap_device_add;
+		fuse_fs_iomap_device_remove;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 08/25] libfuse: add iomap ioend low level handler
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (6 preceding siblings ...)
  2026-02-23 23:27   ` [PATCH 07/25] libfuse: add upper-level iomap add device function Darrick J. Wong
@ 2026-02-23 23:27   ` Darrick J. Wong
  2026-02-23 23:27   ` [PATCH 09/25] libfuse: add upper level iomap ioend commands Darrick J. Wong
                     ` (16 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:27 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Teach the low level library about the iomap ioend handler, which gets
called by the kernel when we finish a file write that isn't a pure
overwrite operation.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h   |   13 +++++++++++++
 include/fuse_kernel.h   |   16 ++++++++++++++++
 include/fuse_lowlevel.h |   34 ++++++++++++++++++++++++++++++++++
 lib/fuse_lowlevel.c     |   32 ++++++++++++++++++++++++++++++++
 lib/fuse_versionscript  |    1 +
 5 files changed, 96 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index 58726ce43b1014..013e74a0e9eefe 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1208,6 +1208,19 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
 		!(opflags & FUSE_IOMAP_OP_ZERO);
 }
 
+/* out of place write extent */
+#define FUSE_IOMAP_IOEND_SHARED		(1U << 0)
+/* unwritten extent */
+#define FUSE_IOMAP_IOEND_UNWRITTEN	(1U << 1)
+/* don't merge into previous ioend */
+#define FUSE_IOMAP_IOEND_BOUNDARY	(1U << 2)
+/* is direct I/O */
+#define FUSE_IOMAP_IOEND_DIRECT		(1U << 3)
+/* is append ioend */
+#define FUSE_IOMAP_IOEND_APPEND		(1U << 4)
+/* is pagecache writeback */
+#define FUSE_IOMAP_IOEND_WRITEBACK	(1U << 5)
+
 /* ----------------------------------------------------------- *
  * Compatibility stuff					       *
  * ----------------------------------------------------------- */
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index e69f9675c4b57d..732085a1b900b0 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -670,6 +670,7 @@ enum fuse_opcode {
 	FUSE_STATX		= 52,
 	FUSE_COPY_FILE_RANGE_64	= 53,
 
+	FUSE_IOMAP_IOEND	= 4093,
 	FUSE_IOMAP_BEGIN	= 4094,
 	FUSE_IOMAP_END		= 4095,
 
@@ -1360,4 +1361,19 @@ struct fuse_iomap_end_in {
 	struct fuse_iomap_io	map;
 };
 
+struct fuse_iomap_ioend_in {
+	uint32_t flags;		/* FUSE_IOMAP_IOEND_* */
+	int32_t error;		/* negative errno or 0 */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+	uint64_t pos;		/* file position, in bytes */
+	uint64_t new_addr;	/* disk offset of new mapping, in bytes */
+	uint64_t written;	/* bytes processed */
+	uint32_t dev;		/* device cookie */
+	uint32_t pad;		/* zero */
+};
+
+struct fuse_iomap_ioend_out {
+	uint64_t newsize;	/* new ondisk size */
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index 7f9a56b0a7eda1..a8e845ba796937 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -1394,6 +1394,28 @@ struct fuse_lowlevel_ops {
 	void (*iomap_end) (fuse_req_t req, fuse_ino_t nodeid, uint64_t attr_ino,
 			   off_t pos, uint64_t count, uint32_t opflags,
 			   ssize_t written, const struct fuse_file_iomap *iomap);
+
+	/**
+	 * Complete an iomap IO operation
+	 *
+	 * Valid replies:
+	 *   fuse_reply_ioend
+	 *   fuse_reply_err
+	 *
+	 * @param req request handle
+	 * @param nodeid the inode number
+	 * @param attr_ino inode number as told by fuse_attr::ino
+	 * @param pos position in file, in bytes
+	 * @param written number of bytes processed, or a negative errno
+	 * @param flags mask of FUSE_IOMAP_IOEND_ flags specifying operation
+	 * @param error errno code of what went wrong
+	 * @param dev device cookie of new address
+	 * @param new_addr disk address of new mapping, in bytes
+	 */
+	void (*iomap_ioend) (fuse_req_t req, fuse_ino_t nodeid,
+			     uint64_t attr_ino, off_t pos, uint64_t written,
+			     uint32_t ioendflags, int error, uint32_t dev,
+			     uint64_t new_addr);
 };
 
 /**
@@ -1810,6 +1832,18 @@ void fuse_iomap_pure_overwrite(struct fuse_file_iomap *write,
 int fuse_reply_iomap_begin(fuse_req_t req, const struct fuse_file_iomap *read,
 			   const struct fuse_file_iomap *write);
 
+/**
+ * Reply to an ioend with the new ondisk size
+ *
+ * Possible requests:
+ *   iomap_ioend
+ *
+ * @param req request handle
+ * @param newsize new ondisk file size
+ * @return zero for success, -errno for failure to send reply
+ */
+int fuse_reply_iomap_ioend(fuse_req_t req, off_t newsize);
+
 /* ----------------------------------------------------------- *
  * Notification						       *
  * ----------------------------------------------------------- */
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index cf97ed8b471c49..45d5965caf7b7f 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -2767,6 +2767,36 @@ static void do_iomap_end(fuse_req_t req, const fuse_ino_t nodeid,
 	_do_iomap_end(req, nodeid, inarg, NULL);
 }
 
+int fuse_reply_iomap_ioend(fuse_req_t req, off_t newsize)
+{
+	struct fuse_iomap_ioend_out arg = {
+		.newsize = newsize,
+	};
+
+	return send_reply_ok(req, &arg, sizeof(arg));
+}
+
+static void _do_iomap_ioend(fuse_req_t req, const fuse_ino_t nodeid,
+			    const void *op_in, const void *in_payload)
+{
+	const struct fuse_iomap_ioend_in *arg = op_in;
+	(void)in_payload;
+	(void)nodeid;
+
+	if (req->se->op.iomap_ioend)
+		req->se->op.iomap_ioend(req, nodeid, arg->attr_ino, arg->pos,
+					arg->written, arg->flags, arg->error,
+					arg->dev, arg->new_addr);
+	else
+		fuse_reply_err(req, ENOSYS);
+}
+
+static void do_iomap_ioend(fuse_req_t req, const fuse_ino_t nodeid,
+			   const void *inarg)
+{
+	_do_iomap_ioend(req, nodeid, inarg, NULL);
+}
+
 static bool want_flags_valid(uint64_t capable, uint64_t want)
 {
 	uint64_t unknown_flags = want & (~capable);
@@ -3755,6 +3785,7 @@ static struct {
 	[FUSE_STATX]	   = { do_statx,       "STATX"	     },
 	[FUSE_IOMAP_BEGIN] = { do_iomap_begin,	"IOMAP_BEGIN" },
 	[FUSE_IOMAP_END]   = { do_iomap_end,	"IOMAP_END" },
+	[FUSE_IOMAP_IOEND] = { do_iomap_ioend,	"IOMAP_IOEND" },
 	[CUSE_INIT]	   = { cuse_lowlevel_init, "CUSE_INIT"   },
 };
 
@@ -3814,6 +3845,7 @@ static struct {
 	[FUSE_STATX]		= { _do_statx,		"STATX" },
 	[FUSE_IOMAP_BEGIN]	= { _do_iomap_begin,	"IOMAP_BEGIN" },
 	[FUSE_IOMAP_END]	= { _do_iomap_end,	"IOMAP_END" },
+	[FUSE_IOMAP_IOEND]	= { _do_iomap_ioend,	"IOMAP_IOEND" },
 	[CUSE_INIT]		= { _cuse_lowlevel_init, "CUSE_INIT" },
 };
 
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 5c4a7dc53b33f3..a018600d26ba4d 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -233,6 +233,7 @@ FUSE_3.99 {
 	global:
 		fuse_iomap_pure_overwrite;
 		fuse_reply_iomap_begin;
+		fuse_reply_iomap_ioend;
 		fuse_lowlevel_iomap_device_add;
 		fuse_lowlevel_iomap_device_remove;
 		fuse_fs_iomap_device_add;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 09/25] libfuse: add upper level iomap ioend commands
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (7 preceding siblings ...)
  2026-02-23 23:27   ` [PATCH 08/25] libfuse: add iomap ioend low level handler Darrick J. Wong
@ 2026-02-23 23:27   ` Darrick J. Wong
  2026-02-23 23:27   ` [PATCH 10/25] libfuse: add a reply function to send FUSE_ATTR_* to the kernel Darrick J. Wong
                     ` (15 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:27 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Teach the upper level fuse library about iomap ioend events, which
happen when a write that isn't a pure overwrite completes.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h |    9 +++++++++
 lib/fuse.c     |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)


diff --git a/include/fuse.h b/include/fuse.h
index 23b6d3f7c93303..dc4b79e98f6cd0 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -902,6 +902,15 @@ struct fuse_operations {
 			  off_t pos_in, uint64_t length_in,
 			  uint32_t opflags_in, ssize_t written_in,
 			  const struct fuse_file_iomap *iomap);
+
+	/**
+	 * Respond to the outcome of a file IO operation.
+	 */
+	int (*iomap_ioend) (const char *path, uint64_t nodeid,
+			    uint64_t attr_ino, off_t pos_in,
+			    uint64_t written_in, uint32_t ioendflags_in,
+			    int error_in, uint32_t dev_in,
+			    uint64_t new_addr_in, off_t *newsize);
 };
 
 /** Extra context that may be needed by some filesystems
diff --git a/lib/fuse.c b/lib/fuse.c
index 9662d007746809..8d6d1686fc733c 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2863,6 +2863,28 @@ int fuse_fs_iomap_device_remove(int device_id)
 	return fuse_lowlevel_iomap_device_remove(se, device_id);
 }
 
+static int fuse_fs_iomap_ioend(struct fuse_fs *fs, const char *path,
+			       uint64_t nodeid, uint64_t attr_ino, off_t pos,
+			       uint64_t written, uint32_t ioendflags, int error,
+			       uint32_t dev, uint64_t new_addr, off_t *newsize)
+{
+	fuse_get_context()->private_data = fs->user_data;
+	if (!fs->op.iomap_ioend)
+		return -ENOSYS;
+
+	if (fs->debug) {
+		fuse_log(FUSE_LOG_DEBUG,
+			 "iomap_ioend[%s] nodeid %llu attr_ino %llu pos %llu written %zu ioendflags 0x%x error %d dev %u new_addr 0x%llx\n",
+			 path, (unsigned long long)nodeid,
+			 (unsigned long long)attr_ino, (unsigned long long)pos,
+			 written, ioendflags, error, dev,
+			 (unsigned long long)new_addr);
+	}
+
+	return fs->op.iomap_ioend(path, nodeid, attr_ino, pos, written,
+				  ioendflags, error, dev, new_addr, newsize);
+}
+
 static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
 			     int valid, struct fuse_file_info *fi)
 {
@@ -4613,6 +4635,36 @@ static void fuse_lib_iomap_end(fuse_req_t req, fuse_ino_t nodeid,
 	reply_err(req, err);
 }
 
+static void fuse_lib_iomap_ioend(fuse_req_t req, fuse_ino_t nodeid,
+				 uint64_t attr_ino, off_t pos, size_t written,
+				 uint32_t ioendflags, int error, uint32_t dev,
+				 uint64_t new_addr)
+{
+	struct fuse *f = req_fuse_prepare(req);
+	struct fuse_intr_data d;
+	char *path;
+	off_t newsize = 0;
+	int err;
+
+	err = get_path_nullok(f, nodeid, &path);
+	if (err) {
+		reply_err(req, err);
+		return;
+	}
+
+	fuse_prepare_interrupt(f, req, &d);
+	err = fuse_fs_iomap_ioend(f->fs, path, nodeid, attr_ino, pos, written,
+				  ioendflags, error, dev, new_addr, &newsize);
+	fuse_finish_interrupt(f, req, &d);
+	free_path(f, nodeid, path);
+	if (err) {
+		reply_err(req, err);
+		return;
+	}
+
+	fuse_reply_iomap_ioend(req, newsize);
+}
+
 static int clean_delay(struct fuse *f)
 {
 	/*
@@ -4717,6 +4769,7 @@ static struct fuse_lowlevel_ops fuse_path_ops = {
 	.syncfs = fuse_lib_syncfs,
 	.iomap_begin = fuse_lib_iomap_begin,
 	.iomap_end = fuse_lib_iomap_end,
+	.iomap_ioend = fuse_lib_iomap_ioend,
 };
 
 int fuse_notify_poll(struct fuse_pollhandle *ph)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 10/25] libfuse: add a reply function to send FUSE_ATTR_* to the kernel
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (8 preceding siblings ...)
  2026-02-23 23:27   ` [PATCH 09/25] libfuse: add upper level iomap ioend commands Darrick J. Wong
@ 2026-02-23 23:27   ` Darrick J. Wong
  2026-02-23 23:28   ` [PATCH 11/25] libfuse: connect high level fuse library to fuse_reply_attr_iflags Darrick J. Wong
                     ` (14 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:27 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Create new fuse_reply_{attr,create,entry}_iflags functions so that we
can send FUSE_ATTR_* flags to the kernel when instantiating an inode.
Servers are expected to send FUSE_IFLAG_* values, which will be
translated into what the kernel can understand.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h   |    3 ++
 include/fuse_lowlevel.h |   83 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/fuse_lowlevel.c     |   64 ++++++++++++++++++++++++++++--------
 lib/fuse_versionscript  |    4 ++
 4 files changed, 139 insertions(+), 15 deletions(-)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index 013e74a0e9eefe..f34f4be6a61770 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1221,6 +1221,9 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
 /* is pagecache writeback */
 #define FUSE_IOMAP_IOEND_WRITEBACK	(1U << 5)
 
+/* enable fsdax */
+#define FUSE_IFLAG_DAX			(1U << 0)
+
 /* ----------------------------------------------------------- *
  * Compatibility stuff					       *
  * ----------------------------------------------------------- */
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index a8e845ba796937..c113c85067fb82 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -242,6 +242,7 @@ struct fuse_lowlevel_ops {
 	 *
 	 * Valid replies:
 	 *   fuse_reply_entry
+	 *   fuse_reply_entry_iflags
 	 *   fuse_reply_err
 	 *
 	 * @param req request handle
@@ -301,6 +302,7 @@ struct fuse_lowlevel_ops {
 	 *
 	 * Valid replies:
 	 *   fuse_reply_attr
+	 *   fuse_reply_attr_iflags
 	 *   fuse_reply_err
 	 *
 	 * @param req request handle
@@ -336,6 +338,7 @@ struct fuse_lowlevel_ops {
 	 *
 	 * Valid replies:
 	 *   fuse_reply_attr
+	 *   fuse_reply_attr_iflags
 	 *   fuse_reply_err
 	 *
 	 * @param req request handle
@@ -367,6 +370,7 @@ struct fuse_lowlevel_ops {
 	 *
 	 * Valid replies:
 	 *   fuse_reply_entry
+	 *   fuse_reply_entry_iflags
 	 *   fuse_reply_err
 	 *
 	 * @param req request handle
@@ -383,6 +387,7 @@ struct fuse_lowlevel_ops {
 	 *
 	 * Valid replies:
 	 *   fuse_reply_entry
+	 *   fuse_reply_entry_iflags
 	 *   fuse_reply_err
 	 *
 	 * @param req request handle
@@ -432,6 +437,7 @@ struct fuse_lowlevel_ops {
 	 *
 	 * Valid replies:
 	 *   fuse_reply_entry
+	 *   fuse_reply_entry_iflags
 	 *   fuse_reply_err
 	 *
 	 * @param req request handle
@@ -480,6 +486,7 @@ struct fuse_lowlevel_ops {
 	 *
 	 * Valid replies:
 	 *   fuse_reply_entry
+	 *   fuse_reply_entry_iflags
 	 *   fuse_reply_err
 	 *
 	 * @param req request handle
@@ -971,6 +978,7 @@ struct fuse_lowlevel_ops {
 	 *
 	 * Valid replies:
 	 *   fuse_reply_create
+	 *   fuse_reply_create_iflags
 	 *   fuse_reply_err
 	 *
 	 * @param req request handle
@@ -1316,6 +1324,7 @@ struct fuse_lowlevel_ops {
 	 *
 	 * Valid replies:
 	 *   fuse_reply_create
+	 *   fuse_reply_create_iflags
 	 *   fuse_reply_err
 	 *
 	 * @param req request handle
@@ -1468,6 +1477,23 @@ void fuse_reply_none(fuse_req_t req);
  */
 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
 
+/**
+ * Reply with a directory entry and FUSE_IFLAG_*
+ *
+ * Possible requests:
+ *   lookup, mknod, mkdir, symlink, link
+ *
+ * Side effects:
+ *   increments the lookup count on success
+ *
+ * @param req request handle
+ * @param e the entry parameters
+ * @param iflags	FUSE_IFLAG_*
+ * @return zero for success, -errno for failure to send reply
+ */
+int fuse_reply_entry_iflags(fuse_req_t req, const struct fuse_entry_param *e,
+			    unsigned int iflags);
+
 /**
  * Reply with a directory entry and open parameters
  *
@@ -1489,6 +1515,29 @@ int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
 		      const struct fuse_file_info *fi);
 
+/**
+ * Reply with a directory entry, open parameters and FUSE_IFLAG_*
+ *
+ * currently the following members of 'fi' are used:
+ *   fh, direct_io, keep_cache, cache_readdir, nonseekable, noflush,
+ *   parallel_direct_writes
+ *
+ * Possible requests:
+ *   create
+ *
+ * Side effects:
+ *   increments the lookup count on success
+ *
+ * @param req request handle
+ * @param e the entry parameters
+ * @param iflags	FUSE_IFLAG_*
+ * @param fi file information
+ * @return zero for success, -errno for failure to send reply
+ */
+int fuse_reply_create_iflags(fuse_req_t req, const struct fuse_entry_param *e,
+			     unsigned int iflags,
+			     const struct fuse_file_info *fi);
+
 /**
  * Reply with attributes
  *
@@ -1503,6 +1552,21 @@ int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
 		    double attr_timeout);
 
+/**
+ * Reply with attributes and FUSE_IFLAG_* flags
+ *
+ * Possible requests:
+ *   getattr, setattr
+ *
+ * @param req request handle
+ * @param attr the attributes
+ * @param attr_timeout	validity timeout (in seconds) for the attributes
+ * @param iflags	set of FUSE_IFLAG_* flags
+ * @return zero for success, -errno for failure to send reply
+ */
+int fuse_reply_attr_iflags(fuse_req_t req, const struct stat *attr,
+			   unsigned int iflags, double attr_timeout);
+
 /**
  * Reply with the contents of a symbolic link
  *
@@ -1730,6 +1794,25 @@ size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
 			      const char *name,
 			      const struct fuse_entry_param *e, off_t off);
 
+/**
+ * Add a directory entry and FUSE_IFLAG_* to the buffer with the attributes
+ *
+ * See documentation of `fuse_add_direntry_plus()` for more details.
+ *
+ * @param req request handle
+ * @param buf the point where the new entry will be added to the buffer
+ * @param bufsize remaining size of the buffer
+ * @param name the name of the entry
+ * @param iflags	FUSE_IFLAG_*
+ * @param e the directory entry
+ * @param off the offset of the next entry
+ * @return the space needed for the entry
+ */
+size_t fuse_add_direntry_plus_iflags(fuse_req_t req, char *buf, size_t bufsize,
+				     const char *name, unsigned int iflags,
+				     const struct fuse_entry_param *e,
+				     off_t off);
+
 /**
  * Reply to ask for data fetch and output buffer preparation.  ioctl
  * will be retried with the specified input data fetched and output
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 45d5965caf7b7f..c21e64787215cc 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -142,7 +142,8 @@ static void trace_request_reply(uint64_t unique, unsigned int len,
 }
 #endif
 
-static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr)
+static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr,
+			 unsigned int iflags)
 {
 	attr->ino	= stbuf->st_ino;
 	attr->mode	= stbuf->st_mode;
@@ -159,6 +160,10 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr)
 	attr->atimensec = ST_ATIM_NSEC(stbuf);
 	attr->mtimensec = ST_MTIM_NSEC(stbuf);
 	attr->ctimensec = ST_CTIM_NSEC(stbuf);
+
+	attr->flags	= 0;
+	if (iflags & FUSE_IFLAG_DAX)
+		attr->flags |= FUSE_ATTR_DAX;
 }
 
 static void convert_attr(const struct fuse_setattr_in *attr, struct stat *stbuf)
@@ -477,7 +482,8 @@ static unsigned int calc_timeout_nsec(double t)
 }
 
 static void fill_entry(struct fuse_entry_out *arg,
-		       const struct fuse_entry_param *e)
+		       const struct fuse_entry_param *e,
+		       unsigned int iflags)
 {
 	arg->nodeid = e->ino;
 	arg->generation = e->generation;
@@ -485,14 +491,15 @@ static void fill_entry(struct fuse_entry_out *arg,
 	arg->entry_valid_nsec = calc_timeout_nsec(e->entry_timeout);
 	arg->attr_valid = calc_timeout_sec(e->attr_timeout);
 	arg->attr_valid_nsec = calc_timeout_nsec(e->attr_timeout);
-	convert_stat(&e->attr, &arg->attr);
+	convert_stat(&e->attr, &arg->attr, iflags);
 }
 
 /* `buf` is allowed to be empty so that the proper size may be
    allocated by the caller */
-size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
-			      const char *name,
-			      const struct fuse_entry_param *e, off_t off)
+size_t fuse_add_direntry_plus_iflags(fuse_req_t req, char *buf, size_t bufsize,
+				     const char *name, unsigned int iflags,
+				     const struct fuse_entry_param *e,
+				     off_t off)
 {
 	(void)req;
 	size_t namelen;
@@ -507,7 +514,7 @@ size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
 
 	struct fuse_direntplus *dp = (struct fuse_direntplus *) buf;
 	memset(&dp->entry_out, 0, sizeof(dp->entry_out));
-	fill_entry(&dp->entry_out, e);
+	fill_entry(&dp->entry_out, e, iflags);
 
 	struct fuse_dirent *dirent = &dp->dirent;
 	dirent->ino = e->attr.st_ino;
@@ -520,6 +527,14 @@ size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
 	return entlen_padded;
 }
 
+size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
+			      const char *name,
+			      const struct fuse_entry_param *e, off_t off)
+{
+	return fuse_add_direntry_plus_iflags(req, buf, bufsize, name, 0, e,
+					     off);
+}
+
 static void fill_open(struct fuse_open_out *arg,
 		      const struct fuse_file_info *f)
 {
@@ -542,7 +557,8 @@ static void fill_open(struct fuse_open_out *arg,
 		arg->open_flags |= FOPEN_PARALLEL_DIRECT_WRITES;
 }
 
-int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
+int fuse_reply_entry_iflags(fuse_req_t req, const struct fuse_entry_param *e,
+			    unsigned int iflags)
 {
 	struct fuse_entry_out arg;
 	size_t size = req->se->conn.proto_minor < 9 ?
@@ -554,12 +570,18 @@ int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
 		return fuse_reply_err(req, ENOENT);
 
 	memset(&arg, 0, sizeof(arg));
-	fill_entry(&arg, e);
+	fill_entry(&arg, e, iflags);
 	return send_reply_ok(req, &arg, size);
 }
 
-int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
-		      const struct fuse_file_info *f)
+int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
+{
+	return fuse_reply_entry_iflags(req, e, 0);
+}
+
+int fuse_reply_create_iflags(fuse_req_t req, const struct fuse_entry_param *e,
+			     unsigned int iflags,
+			     const struct fuse_file_info *f)
 {
 	alignas(uint64_t) char buf[sizeof(struct fuse_entry_out) + sizeof(struct fuse_open_out)];
 	size_t entrysize = req->se->conn.proto_minor < 9 ?
@@ -570,7 +592,7 @@ int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
 	int error;
 
 	memset(buf, 0, sizeof(buf));
-	fill_entry(earg, e);
+	fill_entry(earg, e, iflags);
 	fill_open(oarg, f);
 	error = send_reply_ok(req, buf,
 			     entrysize + sizeof(struct fuse_open_out));
@@ -579,8 +601,14 @@ int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
 	return error;
 }
 
-int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
-		    double attr_timeout)
+int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
+		      const struct fuse_file_info *f)
+{
+	return fuse_reply_create_iflags(req, e, 0, f);
+}
+
+int fuse_reply_attr_iflags(fuse_req_t req, const struct stat *attr,
+			   unsigned int iflags, double attr_timeout)
 {
 	struct fuse_attr_out arg;
 	size_t size = req->se->conn.proto_minor < 9 ?
@@ -589,11 +617,17 @@ int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
 	memset(&arg, 0, sizeof(arg));
 	arg.attr_valid = calc_timeout_sec(attr_timeout);
 	arg.attr_valid_nsec = calc_timeout_nsec(attr_timeout);
-	convert_stat(attr, &arg.attr);
+	convert_stat(attr, &arg.attr, iflags);
 
 	return send_reply_ok(req, &arg, size);
 }
 
+int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
+		    double attr_timeout)
+{
+	return fuse_reply_attr_iflags(req, attr, 0, attr_timeout);
+}
+
 int fuse_reply_readlink(fuse_req_t req, const char *linkname)
 {
 	return send_reply_ok(req, linkname, strlen(linkname));
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index a018600d26ba4d..fa1943e18dcafa 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -238,6 +238,10 @@ FUSE_3.99 {
 		fuse_lowlevel_iomap_device_remove;
 		fuse_fs_iomap_device_add;
 		fuse_fs_iomap_device_remove;
+		fuse_reply_attr_iflags;
+		fuse_reply_create_iflags;
+		fuse_reply_entry_iflags;
+		fuse_add_direntry_plus_iflags;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 11/25] libfuse: connect high level fuse library to fuse_reply_attr_iflags
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (9 preceding siblings ...)
  2026-02-23 23:27   ` [PATCH 10/25] libfuse: add a reply function to send FUSE_ATTR_* to the kernel Darrick J. Wong
@ 2026-02-23 23:28   ` Darrick J. Wong
  2026-02-23 23:28   ` [PATCH 12/25] libfuse: support enabling exclusive mode for files Darrick J. Wong
                     ` (13 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:28 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Create a new ->getattr_iflags function so that iomap filesystems can set
the appropriate in-kernel inode flags on instantiation.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h |    7 ++
 lib/fuse.c     |  191 ++++++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 151 insertions(+), 47 deletions(-)


diff --git a/include/fuse.h b/include/fuse.h
index dc4b79e98f6cd0..0db5f7e961d8fa 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -911,6 +911,13 @@ struct fuse_operations {
 			    uint64_t written_in, uint32_t ioendflags_in,
 			    int error_in, uint32_t dev_in,
 			    uint64_t new_addr_in, off_t *newsize);
+
+	/**
+	 * Get file attributes and FUSE_IFLAG_* flags.  Otherwise the same as
+	 * getattr.
+	 */
+	int (*getattr_iflags) (const char *path, struct stat *buf,
+			       unsigned int *iflags, struct fuse_file_info *fi);
 };
 
 /** Extra context that may be needed by some filesystems
diff --git a/lib/fuse.c b/lib/fuse.c
index 8d6d1686fc733c..78812b66c05106 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -123,6 +123,7 @@ struct fuse {
 	struct list_head partial_slabs;
 	struct list_head full_slabs;
 	pthread_t prune_thread;
+	bool want_iflags;
 };
 
 struct lock {
@@ -144,6 +145,7 @@ struct node {
 	char *name;
 	uint64_t nlookup;
 	int open_count;
+	unsigned int iflags;
 	struct timespec stat_updated;
 	struct timespec mtime;
 	off_t size;
@@ -1628,6 +1630,24 @@ int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf,
 	return fs->op.getattr(path, buf, fi);
 }
 
+static int fuse_fs_getattr_iflags(struct fuse_fs *fs, const char *path,
+				  struct stat *buf, unsigned int *iflags,
+				  struct fuse_file_info *fi)
+{
+	fuse_get_context()->private_data = fs->user_data;
+	if (!fs->op.getattr_iflags)
+		return -ENOSYS;
+
+	if (fs->debug) {
+		char buf[10];
+
+		fuse_log(FUSE_LOG_DEBUG, "getattr_iflags[%s] %s\n",
+			file_info_string(fi, buf, sizeof(buf)),
+			path);
+	}
+	return fs->op.getattr_iflags(path, buf, iflags, fi);
+}
+
 int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath,
 		   const char *newpath, unsigned int flags)
 {
@@ -2484,7 +2504,7 @@ static void update_stat(struct node *node, const struct stat *stbuf)
 }
 
 static int do_lookup(struct fuse *f, fuse_ino_t nodeid, const char *name,
-		     struct fuse_entry_param *e)
+		     struct fuse_entry_param *e, unsigned int *iflags)
 {
 	struct node *node;
 
@@ -2502,25 +2522,64 @@ static int do_lookup(struct fuse *f, fuse_ino_t nodeid, const char *name,
 		pthread_mutex_unlock(&f->lock);
 	}
 	set_stat(f, e->ino, &e->attr);
+	*iflags = node->iflags;
 	return 0;
 }
 
+static int lookup_and_update(struct fuse *f, fuse_ino_t nodeid,
+			     const char *name, struct fuse_entry_param *e,
+			     unsigned int iflags)
+{
+	struct node *node;
+
+	node = find_node(f, nodeid, name);
+	if (node == NULL)
+		return -ENOMEM;
+
+	e->ino = node->nodeid;
+	e->generation = node->generation;
+	e->entry_timeout = f->conf.entry_timeout;
+	e->attr_timeout = f->conf.attr_timeout;
+	if (f->conf.auto_cache) {
+		pthread_mutex_lock(&f->lock);
+		update_stat(node, &e->attr);
+		pthread_mutex_unlock(&f->lock);
+	}
+	set_stat(f, e->ino, &e->attr);
+	node->iflags = iflags;
+	return 0;
+}
+
+static int getattr(struct fuse *f, const char *path, struct stat *buf,
+		   unsigned int *iflags, struct fuse_file_info *fi)
+{
+	if (f->want_iflags)
+		return fuse_fs_getattr_iflags(f->fs, path, buf, iflags, fi);
+	return fuse_fs_getattr(f->fs, path, buf, fi);
+}
+
 static int lookup_path(struct fuse *f, fuse_ino_t nodeid,
 		       const char *name, const char *path,
-		       struct fuse_entry_param *e, struct fuse_file_info *fi)
+		       struct fuse_entry_param *e, unsigned int *iflags,
+		       struct fuse_file_info *fi)
 {
 	int res;
 
 	memset(e, 0, sizeof(struct fuse_entry_param));
-	res = fuse_fs_getattr(f->fs, path, &e->attr, fi);
-	if (res == 0) {
-		res = do_lookup(f, nodeid, name, e);
-		if (res == 0 && f->conf.debug) {
-			fuse_log(FUSE_LOG_DEBUG, "   NODEID: %llu\n",
-				(unsigned long long) e->ino);
-		}
-	}
-	return res;
+	*iflags = 0;
+	res = getattr(f, path, &e->attr, iflags, fi);
+	if (res)
+		return res;
+
+	res = lookup_and_update(f, nodeid, name, e, *iflags);
+	if (res)
+		return res;
+
+	if (f->conf.debug)
+		fuse_log(FUSE_LOG_DEBUG, "   NODEID: %llu iflags 0x%x\n",
+			(unsigned long long) e->ino, *iflags);
+
+	return 0;
 }
 
 static struct fuse_context_i *fuse_get_context_internal(void)
@@ -2604,11 +2663,14 @@ static inline void reply_err(fuse_req_t req, int err)
 }
 
 static void reply_entry(fuse_req_t req, const struct fuse_entry_param *e,
-			int err)
+			unsigned int iflags, int err)
 {
 	if (!err) {
 		struct fuse *f = req_fuse(req);
-		if (fuse_reply_entry(req, e) == -ENOENT) {
+		int entry_res;
+
+		entry_res = fuse_reply_entry_iflags(req, e, iflags);
+		if (entry_res == -ENOENT) {
 			/* Skip forget for negative result */
 			if  (e->ino != 0)
 				forget_node(f, e->ino, 1);
@@ -2649,6 +2711,9 @@ static void fuse_lib_init(void *data, struct fuse_conn_info *conn)
 		/* Disable the receiving and processing of FUSE_INTERRUPT requests */
 		conn->no_interrupt = 1;
 	}
+
+	if (conn->want_ext & FUSE_CAP_IOMAP)
+		f->want_iflags = true;
 }
 
 void fuse_fs_destroy(struct fuse_fs *fs)
@@ -2672,6 +2737,7 @@ static void fuse_lib_lookup(fuse_req_t req, fuse_ino_t parent,
 	struct fuse *f = req_fuse_prepare(req);
 	struct fuse_entry_param e = { .ino = 0 }; /* invalid ino */
 	char *path;
+	unsigned int iflags = 0;
 	int err;
 	struct node *dot = NULL;
 
@@ -2686,7 +2752,7 @@ static void fuse_lib_lookup(fuse_req_t req, fuse_ino_t parent,
 				dot = get_node_nocheck(f, parent);
 				if (dot == NULL) {
 					pthread_mutex_unlock(&f->lock);
-					reply_entry(req, &e, -ESTALE);
+					reply_entry(req, &e, -ESTALE, 0);
 					return;
 				}
 				dot->refctr++;
@@ -2706,7 +2772,7 @@ static void fuse_lib_lookup(fuse_req_t req, fuse_ino_t parent,
 		if (f->conf.debug)
 			fuse_log(FUSE_LOG_DEBUG, "LOOKUP %s\n", path);
 		fuse_prepare_interrupt(f, req, &d);
-		err = lookup_path(f, parent, name, path, &e, NULL);
+		err = lookup_path(f, parent, name, path, &e, &iflags, NULL);
 		if (err == -ENOENT && f->conf.negative_timeout != 0.0) {
 			e.ino = 0;
 			e.entry_timeout = f->conf.negative_timeout;
@@ -2720,7 +2786,7 @@ static void fuse_lib_lookup(fuse_req_t req, fuse_ino_t parent,
 		unref_node(f, dot);
 		pthread_mutex_unlock(&f->lock);
 	}
-	reply_entry(req, &e, err);
+	reply_entry(req, &e, iflags, err);
 }
 
 static void do_forget(struct fuse *f, fuse_ino_t ino, uint64_t nlookup)
@@ -2756,6 +2822,7 @@ static void fuse_lib_getattr(fuse_req_t req, fuse_ino_t ino,
 	struct fuse *f = req_fuse_prepare(req);
 	struct stat buf;
 	char *path;
+	unsigned int iflags = 0;
 	int err;
 
 	memset(&buf, 0, sizeof(buf));
@@ -2767,7 +2834,7 @@ static void fuse_lib_getattr(fuse_req_t req, fuse_ino_t ino,
 	if (!err) {
 		struct fuse_intr_data d;
 		fuse_prepare_interrupt(f, req, &d);
-		err = fuse_fs_getattr(f->fs, path, &buf, fi);
+		err = getattr(f, path, &buf, &iflags, fi);
 		fuse_finish_interrupt(f, req, &d);
 		free_path(f, ino, path);
 	}
@@ -2780,9 +2847,11 @@ static void fuse_lib_getattr(fuse_req_t req, fuse_ino_t ino,
 			buf.st_nlink--;
 		if (f->conf.auto_cache)
 			update_stat(node, &buf);
+		node->iflags = iflags;
 		pthread_mutex_unlock(&f->lock);
 		set_stat(f, ino, &buf);
-		fuse_reply_attr(req, &buf, f->conf.attr_timeout);
+		fuse_reply_attr_iflags(req, &buf, iflags,
+				       f->conf.attr_timeout);
 	} else
 		reply_err(req, err);
 }
@@ -2891,6 +2960,7 @@ static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
 	struct fuse *f = req_fuse_prepare(req);
 	struct stat buf;
 	char *path;
+	unsigned int iflags = 0;
 	int err;
 
 	memset(&buf, 0, sizeof(buf));
@@ -2949,19 +3019,23 @@ static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
 			err = fuse_fs_utimens(f->fs, path, tv, fi);
 		}
 		if (!err) {
-			err = fuse_fs_getattr(f->fs, path, &buf, fi);
+			err = getattr(f, path, &buf, &iflags, fi);
 		}
 		fuse_finish_interrupt(f, req, &d);
 		free_path(f, ino, path);
 	}
 	if (!err) {
-		if (f->conf.auto_cache) {
-			pthread_mutex_lock(&f->lock);
-			update_stat(get_node(f, ino), &buf);
-			pthread_mutex_unlock(&f->lock);
-		}
+		struct node *node;
+
+		pthread_mutex_lock(&f->lock);
+		node = get_node(f, ino);
+		if (f->conf.auto_cache)
+			update_stat(node, &buf);
+		node->iflags = iflags;
+		pthread_mutex_unlock(&f->lock);
 		set_stat(f, ino, &buf);
-		fuse_reply_attr(req, &buf, f->conf.attr_timeout);
+		fuse_reply_attr_iflags(req, &buf, iflags,
+				       f->conf.attr_timeout);
 	} else
 		reply_err(req, err);
 }
@@ -3012,6 +3086,7 @@ static void fuse_lib_mknod(fuse_req_t req, fuse_ino_t parent, const char *name,
 	struct fuse *f = req_fuse_prepare(req);
 	struct fuse_entry_param e;
 	char *path;
+	unsigned int iflags = 0;
 	int err;
 
 	err = get_path_name(f, parent, name, &path);
@@ -3028,7 +3103,7 @@ static void fuse_lib_mknod(fuse_req_t req, fuse_ino_t parent, const char *name,
 			err = fuse_fs_create(f->fs, path, mode, &fi);
 			if (!err) {
 				err = lookup_path(f, parent, name, path, &e,
-						  &fi);
+						  &iflags, &fi);
 				fuse_fs_release(f->fs, path, &fi);
 			}
 		}
@@ -3036,12 +3111,12 @@ static void fuse_lib_mknod(fuse_req_t req, fuse_ino_t parent, const char *name,
 			err = fuse_fs_mknod(f->fs, path, mode, rdev);
 			if (!err)
 				err = lookup_path(f, parent, name, path, &e,
-						  NULL);
+						  &iflags, NULL);
 		}
 		fuse_finish_interrupt(f, req, &d);
 		free_path(f, parent, path);
 	}
-	reply_entry(req, &e, err);
+	reply_entry(req, &e, iflags, err);
 }
 
 static void fuse_lib_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name,
@@ -3050,6 +3125,7 @@ static void fuse_lib_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name,
 	struct fuse *f = req_fuse_prepare(req);
 	struct fuse_entry_param e;
 	char *path;
+	unsigned int iflags = 0;
 	int err;
 
 	err = get_path_name(f, parent, name, &path);
@@ -3059,11 +3135,12 @@ static void fuse_lib_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name,
 		fuse_prepare_interrupt(f, req, &d);
 		err = fuse_fs_mkdir(f->fs, path, mode);
 		if (!err)
-			err = lookup_path(f, parent, name, path, &e, NULL);
+			err = lookup_path(f, parent, name, path, &e, &iflags,
+					  NULL);
 		fuse_finish_interrupt(f, req, &d);
 		free_path(f, parent, path);
 	}
-	reply_entry(req, &e, err);
+	reply_entry(req, &e, iflags, err);
 }
 
 static void fuse_lib_unlink(fuse_req_t req, fuse_ino_t parent,
@@ -3133,6 +3210,7 @@ static void fuse_lib_symlink(fuse_req_t req, const char *linkname,
 	struct fuse *f = req_fuse_prepare(req);
 	struct fuse_entry_param e;
 	char *path;
+	unsigned int iflags = 0;
 	int err;
 
 	err = get_path_name(f, parent, name, &path);
@@ -3142,11 +3220,12 @@ static void fuse_lib_symlink(fuse_req_t req, const char *linkname,
 		fuse_prepare_interrupt(f, req, &d);
 		err = fuse_fs_symlink(f->fs, linkname, path);
 		if (!err)
-			err = lookup_path(f, parent, name, path, &e, NULL);
+			err = lookup_path(f, parent, name, path, &e, &iflags,
+					  NULL);
 		fuse_finish_interrupt(f, req, &d);
 		free_path(f, parent, path);
 	}
-	reply_entry(req, &e, err);
+	reply_entry(req, &e, iflags, err);
 }
 
 static void fuse_lib_rename(fuse_req_t req, fuse_ino_t olddir,
@@ -3194,6 +3273,7 @@ static void fuse_lib_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
 	struct fuse_entry_param e;
 	char *oldpath;
 	char *newpath;
+	unsigned int iflags = 0;
 	int err;
 
 	err = get_path2(f, ino, NULL, newparent, newname,
@@ -3205,11 +3285,11 @@ static void fuse_lib_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
 		err = fuse_fs_link(f->fs, oldpath, newpath);
 		if (!err)
 			err = lookup_path(f, newparent, newname, newpath,
-					  &e, NULL);
+					  &e, &iflags, NULL);
 		fuse_finish_interrupt(f, req, &d);
 		free_path2(f, ino, newparent, NULL, NULL, oldpath, newpath);
 	}
-	reply_entry(req, &e, err);
+	reply_entry(req, &e, iflags, err);
 }
 
 static void fuse_do_release(struct fuse *f, fuse_ino_t ino, const char *path,
@@ -3252,6 +3332,7 @@ static void fuse_lib_create(fuse_req_t req, fuse_ino_t parent,
 	struct fuse_intr_data d;
 	struct fuse_entry_param e;
 	char *path;
+	unsigned int iflags;
 	int err;
 
 	err = get_path_name(f, parent, name, &path);
@@ -3259,7 +3340,8 @@ static void fuse_lib_create(fuse_req_t req, fuse_ino_t parent,
 		fuse_prepare_interrupt(f, req, &d);
 		err = fuse_fs_create(f->fs, path, mode, fi);
 		if (!err) {
-			err = lookup_path(f, parent, name, path, &e, fi);
+			err = lookup_path(f, parent, name, path, &e,
+					  &iflags, fi);
 			if (err)
 				fuse_fs_release(f->fs, path, fi);
 			else if (!S_ISREG(e.attr.st_mode)) {
@@ -3279,10 +3361,14 @@ static void fuse_lib_create(fuse_req_t req, fuse_ino_t parent,
 		fuse_finish_interrupt(f, req, &d);
 	}
 	if (!err) {
+		int create_res;
+
 		pthread_mutex_lock(&f->lock);
 		get_node(f, e.ino)->open_count++;
 		pthread_mutex_unlock(&f->lock);
-		if (fuse_reply_create(req, &e, fi) == -ENOENT) {
+
+		create_res = fuse_reply_create_iflags(req, &e, iflags, fi);
+		if (create_res == -ENOENT) {
 			/* The open syscall was interrupted, so it
 			   must be cancelled */
 			fuse_do_release(f, e.ino, path, fi);
@@ -3316,13 +3402,16 @@ static void open_auto_cache(struct fuse *f, fuse_ino_t ino, const char *path,
 		if (diff_timespec(&now, &node->stat_updated) >
 		    f->conf.ac_attr_timeout) {
 			struct stat stbuf;
+			unsigned int iflags = 0;
 			int err;
+
 			pthread_mutex_unlock(&f->lock);
-			err = fuse_fs_getattr(f->fs, path, &stbuf, fi);
+			err = getattr(f, path, &stbuf, &iflags, fi);
 			pthread_mutex_lock(&f->lock);
-			if (!err)
+			if (!err) {
 				update_stat(node, &stbuf);
-			else
+				node->iflags = iflags;
+			} else
 				node->cache_valid = 0;
 		}
 	}
@@ -3651,6 +3740,7 @@ static int fill_dir_plus(void *dh_, const char *name, const struct stat *statp,
 		.ino = 0,
 	};
 	struct fuse *f = dh->fuse;
+	unsigned int iflags = 0;
 	int res;
 
 	if ((flags & ~FUSE_FILL_DIR_PLUS) != 0) {
@@ -3675,6 +3765,7 @@ static int fill_dir_plus(void *dh_, const char *name, const struct stat *statp,
 
 	if (off) {
 		size_t newlen;
+		size_t thislen;
 
 		if (dh->filled) {
 			dh->error = -EIO;
@@ -3690,7 +3781,8 @@ static int fill_dir_plus(void *dh_, const char *name, const struct stat *statp,
 
 		if (statp && (flags & FUSE_FILL_DIR_PLUS)) {
 			if (!is_dot_or_dotdot(name)) {
-				res = do_lookup(f, dh->nodeid, name, &e);
+				res = do_lookup(f, dh->nodeid, name, &e,
+						&iflags);
 				if (res) {
 					dh->error = res;
 					return 1;
@@ -3698,10 +3790,12 @@ static int fill_dir_plus(void *dh_, const char *name, const struct stat *statp,
 			}
 		}
 
-		newlen = dh->len +
-			fuse_add_direntry_plus(dh->req, dh->contents + dh->len,
-					       dh->needlen - dh->len, name,
-					       &e, off);
+		thislen = fuse_add_direntry_plus_iflags(dh->req,
+							dh->contents + dh->len,
+							dh->needlen - dh->len,
+							name, iflags, &e, off);
+		newlen = dh->len + thislen;
+
 		if (newlen > dh->needlen)
 			return 1;
 		dh->len = newlen;
@@ -3788,6 +3882,7 @@ static int readdir_fill_from_list(fuse_req_t req, struct fuse_dh *dh,
 		unsigned rem = dh->needlen - dh->len;
 		unsigned thislen;
 		unsigned newlen;
+		unsigned int iflags = 0;
 		pos++;
 
 		if (flags & FUSE_READDIR_PLUS) {
@@ -3799,15 +3894,17 @@ static int readdir_fill_from_list(fuse_req_t req, struct fuse_dh *dh,
 			if (de->flags & FUSE_FILL_DIR_PLUS &&
 			    !is_dot_or_dotdot(de->name)) {
 				res = do_lookup(dh->fuse, dh->nodeid,
-						de->name, &e);
+						de->name, &e, &iflags);
 				if (res) {
 					dh->error = res;
 					return 1;
 				}
 			}
 
-			thislen = fuse_add_direntry_plus(req, p, rem,
-							 de->name, &e, pos);
+			thislen = fuse_add_direntry_plus_iflags(req, p, rem,
+								de->name,
+								iflags, &e,
+								pos);
 		} else {
 			thislen = fuse_add_direntry(req, p, rem,
 						    de->name, &de->stat, pos);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 12/25] libfuse: support enabling exclusive mode for files
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (10 preceding siblings ...)
  2026-02-23 23:28   ` [PATCH 11/25] libfuse: connect high level fuse library to fuse_reply_attr_iflags Darrick J. Wong
@ 2026-02-23 23:28   ` Darrick J. Wong
  2026-02-23 23:28   ` [PATCH 13/25] libfuse: support direct I/O through iomap Darrick J. Wong
                     ` (12 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:28 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Make it so that lowlevel fuse servers can ask for exclusive mode.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h |    2 ++
 include/fuse_kernel.h |    4 ++++
 lib/fuse_lowlevel.c   |    2 ++
 3 files changed, 8 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index f34f4be6a61770..a21f1c8dd12e91 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1223,6 +1223,8 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
 
 /* enable fsdax */
 #define FUSE_IFLAG_DAX			(1U << 0)
+/* exclusive attr mode */
+#define FUSE_IFLAG_EXCLUSIVE		(1U << 1)
 
 /* ----------------------------------------------------------- *
  * Compatibility stuff					       *
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 732085a1b900b0..9b0894899ca453 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -244,6 +244,7 @@
  *  7.99
  *  - XXX magic minor revision to make experimental code really obvious
  *  - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations
+ *  - add FUSE_ATTR_EXCLUSIVE to enable exclusive mode for specific inodes
  */
 
 #ifndef _LINUX_FUSE_H
@@ -584,9 +585,12 @@ struct fuse_file_lock {
  *
  * FUSE_ATTR_SUBMOUNT: Object is a submount root
  * FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode
+ * FUSE_ATTR_EXCLUSIVE: This file can only be modified by this mount, so the
+ * kernel can use cached attributes more aggressively (e.g. ACL inheritance)
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 #define FUSE_ATTR_DAX		(1 << 1)
+#define FUSE_ATTR_EXCLUSIVE	(1 << 2)
 
 /**
  * Open flags
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index c21e64787215cc..f34c86406552f9 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -164,6 +164,8 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr,
 	attr->flags	= 0;
 	if (iflags & FUSE_IFLAG_DAX)
 		attr->flags |= FUSE_ATTR_DAX;
+	if (iflags & FUSE_IFLAG_EXCLUSIVE)
+		attr->flags |= FUSE_ATTR_EXCLUSIVE;
 }
 
 static void convert_attr(const struct fuse_setattr_in *attr, struct stat *stbuf)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 13/25] libfuse: support direct I/O through iomap
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (11 preceding siblings ...)
  2026-02-23 23:28   ` [PATCH 12/25] libfuse: support enabling exclusive mode for files Darrick J. Wong
@ 2026-02-23 23:28   ` Darrick J. Wong
  2026-02-23 23:29   ` [PATCH 14/25] libfuse: don't allow hardlinking of iomap files in the upper level fuse library Darrick J. Wong
                     ` (11 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:28 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Make it so that fuse servers can ask the kernel fuse driver to use iomap
to support direct IO.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h |    2 ++
 include/fuse_kernel.h |    3 +++
 lib/fuse_lowlevel.c   |    2 ++
 3 files changed, 7 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index a21f1c8dd12e91..bece561ef3ec9c 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1225,6 +1225,8 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
 #define FUSE_IFLAG_DAX			(1U << 0)
 /* exclusive attr mode */
 #define FUSE_IFLAG_EXCLUSIVE		(1U << 1)
+/* use iomap for this inode */
+#define FUSE_IFLAG_IOMAP		(1U << 2)
 
 /* ----------------------------------------------------------- *
  * Compatibility stuff					       *
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 9b0894899ca453..6b1fcc44004dbf 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -245,6 +245,7 @@
  *  - XXX magic minor revision to make experimental code really obvious
  *  - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations
  *  - add FUSE_ATTR_EXCLUSIVE to enable exclusive mode for specific inodes
+ *  - add FUSE_ATTR_IOMAP to enable iomap for specific inodes
  */
 
 #ifndef _LINUX_FUSE_H
@@ -587,10 +588,12 @@ struct fuse_file_lock {
  * FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode
  * FUSE_ATTR_EXCLUSIVE: This file can only be modified by this mount, so the
  * kernel can use cached attributes more aggressively (e.g. ACL inheritance)
+ * FUSE_ATTR_IOMAP: Use iomap for this inode
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 #define FUSE_ATTR_DAX		(1 << 1)
 #define FUSE_ATTR_EXCLUSIVE	(1 << 2)
+#define FUSE_ATTR_IOMAP		(1 << 3)
 
 /**
  * Open flags
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index f34c86406552f9..23169c1946ce0b 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -166,6 +166,8 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr,
 		attr->flags |= FUSE_ATTR_DAX;
 	if (iflags & FUSE_IFLAG_EXCLUSIVE)
 		attr->flags |= FUSE_ATTR_EXCLUSIVE;
+	if (iflags & FUSE_IFLAG_IOMAP)
+		attr->flags |= FUSE_ATTR_IOMAP;
 }
 
 static void convert_attr(const struct fuse_setattr_in *attr, struct stat *stbuf)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 14/25] libfuse: don't allow hardlinking of iomap files in the upper level fuse library
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (12 preceding siblings ...)
  2026-02-23 23:28   ` [PATCH 13/25] libfuse: support direct I/O through iomap Darrick J. Wong
@ 2026-02-23 23:29   ` Darrick J. Wong
  2026-02-23 23:29   ` [PATCH 15/25] libfuse: allow discovery of the kernel's iomap capabilities Darrick J. Wong
                     ` (10 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:29 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

The upper level fuse library creates a separate node object for every
(i)node referenced by a directory entry.  Unfortunately, it doesn't
account for the possibility of hardlinks, which means that we can create
multiple nodeids that refer to the same hardlinked inode.  Inode locking
in iomap mode in the kernel relies there only being one inode object for
a hardlinked file, so we cannot allow anyone to hardlink an iomap file.
The client had better not turn on iomap for an existing hardlinked file.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h         |   18 ++++++++++
 lib/fuse.c             |   90 +++++++++++++++++++++++++++++++++++++++++++-----
 lib/fuse_versionscript |    2 +
 3 files changed, 101 insertions(+), 9 deletions(-)


diff --git a/include/fuse.h b/include/fuse.h
index 0db5f7e961d8fa..817b3cf6c419c4 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -1438,6 +1438,24 @@ int fuse_fs_iomap_device_add(int fd, unsigned int flags);
  */
 int fuse_fs_iomap_device_remove(int device_id);
 
+/**
+ * Decide if we can enable iomap mode for a particular file for an upper-level
+ * fuse server.
+ *
+ * @param statbuf stat information for the file.
+ * @return true if it can be enabled, false if not.
+ */
+bool fuse_fs_can_enable_iomap(const struct stat *statbuf);
+
+/**
+ * Decide if we can enable iomap mode for a particular file for an upper-level
+ * fuse server.
+ *
+ * @param statxbuf statx information for the file.
+ * @return true if it can be enabled, false if not.
+ */
+bool fuse_fs_can_enable_iomapx(const struct statx *statxbuf);
+
 int fuse_notify_poll(struct fuse_pollhandle *ph);
 
 /**
diff --git a/lib/fuse.c b/lib/fuse.c
index 78812b66c05106..5d9acbc177a177 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -3266,10 +3266,66 @@ static void fuse_lib_rename(fuse_req_t req, fuse_ino_t olddir,
 	reply_err(req, err);
 }
 
+/*
+ * Decide if file IO for this inode can use iomap.
+ *
+ * The upper level libfuse creates internal node ids that have nothing to do
+ * with the ext2_ino_t that we give it.  These internal node ids are what
+ * actually gets igetted in the kernel, which means that there can be multiple
+ * fuse_inode objects in the kernel for a single hardlinked inode in the fuse
+ * server.
+ *
+ * What this means, horrifyingly, is that on a fuse filesystem that supports
+ * hard links, the in-kernel i_rwsem does not protect against concurrent writes
+ * between files that point to the same inode.  That in turn means that the
+ * file mode and size can get desynchronized between the multiple fuse_inode
+ * objects.  This also means that we cannot cache iomaps in the kernel AT ALL
+ * because the caches will get out of sync, leading to WARN_ONs from the iomap
+ * zeroing code and probably data corruption after that.
+ *
+ * Therefore, libfuse must never create hardlinks of iomap files, and the
+ * predicates below allow fuse servers to decide if they can turn on iomap for
+ * existing hardlinked files.
+ */
+bool fuse_fs_can_enable_iomap(const struct stat *statbuf)
+{
+	struct fuse_context *ctxt = fuse_get_context();
+	struct fuse_session *se = fuse_get_session(ctxt->fuse);
+
+	if (!(se->conn.want_ext & FUSE_CAP_IOMAP))
+		return false;
+
+	return statbuf->st_nlink < 2;
+}
+
+bool fuse_fs_can_enable_iomapx(const struct statx *statxbuf)
+{
+	struct fuse_context *ctxt = fuse_get_context();
+	struct fuse_session *se = fuse_get_session(ctxt->fuse);
+
+	if (!(se->conn.want_ext & FUSE_CAP_IOMAP))
+		return false;
+
+	return statxbuf->stx_nlink < 2;
+}
+
+static bool fuse_lib_can_link(fuse_req_t req, fuse_ino_t ino)
+{
+	struct fuse *f = req_fuse_prepare(req);
+	struct node *node;
+
+	if (!(req->se->conn.want_ext & FUSE_CAP_IOMAP))
+		return true;
+
+	node = get_node(f, ino);
+	return !(node->iflags & FUSE_IFLAG_IOMAP);
+}
+
 static void fuse_lib_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
 			  const char *newname)
 {
 	struct fuse *f = req_fuse_prepare(req);
+	struct fuse_intr_data d;
 	struct fuse_entry_param e;
 	char *oldpath;
 	char *newpath;
@@ -3278,17 +3334,33 @@ static void fuse_lib_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
 
 	err = get_path2(f, ino, NULL, newparent, newname,
 			&oldpath, &newpath, NULL, NULL);
-	if (!err) {
-		struct fuse_intr_data d;
+	if (err)
+		goto out_reply;
 
-		fuse_prepare_interrupt(f, req, &d);
-		err = fuse_fs_link(f->fs, oldpath, newpath);
-		if (!err)
-			err = lookup_path(f, newparent, newname, newpath,
-					  &e, &iflags, NULL);
-		fuse_finish_interrupt(f, req, &d);
-		free_path2(f, ino, newparent, NULL, NULL, oldpath, newpath);
+	/*
+	 * The upper level fuse library creates a separate node object for
+	 * every (i)node referenced by a directory entry.  Unfortunately, it
+	 * doesn't account for the possibility of hardlinks, which means that
+	 * we can create multiple nodeids that refer to the same hardlinked
+	 * inode.  Inode locking in iomap mode in the kernel relies there only
+	 * being one inode object for a hardlinked file, so we cannot allow
+	 * anyone to hardlink an iomap file.  The client had better not turn on
+	 * iomap for an existing hardlinked file.
+	 */
+	if (!fuse_lib_can_link(req, ino)) {
+		err = -EPERM;
+		goto out_path;
 	}
+
+	fuse_prepare_interrupt(f, req, &d);
+	err = fuse_fs_link(f->fs, oldpath, newpath);
+	if (!err)
+		err = lookup_path(f, newparent, newname, newpath,
+				  &e, &iflags, NULL);
+	fuse_finish_interrupt(f, req, &d);
+out_path:
+	free_path2(f, ino, newparent, NULL, NULL, oldpath, newpath);
+out_reply:
 	reply_entry(req, &e, iflags, err);
 }
 
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index fa1943e18dcafa..67c3bd614c44fc 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -242,6 +242,8 @@ FUSE_3.99 {
 		fuse_reply_create_iflags;
 		fuse_reply_entry_iflags;
 		fuse_add_direntry_plus_iflags;
+		fuse_fs_can_enable_iomap;
+		fuse_fs_can_enable_iomapx;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 15/25] libfuse: allow discovery of the kernel's iomap capabilities
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (13 preceding siblings ...)
  2026-02-23 23:29   ` [PATCH 14/25] libfuse: don't allow hardlinking of iomap files in the upper level fuse library Darrick J. Wong
@ 2026-02-23 23:29   ` Darrick J. Wong
  2026-02-23 23:29   ` [PATCH 16/25] libfuse: add lower level iomap_config implementation Darrick J. Wong
                     ` (9 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:29 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Create a library function so that we can discover the kernel's iomap
capabilities ahead of time.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h   |    7 +++++++
 include/fuse_kernel.h   |    7 +++++++
 include/fuse_lowlevel.h |    9 +++++++++
 lib/fuse_lowlevel.c     |   19 +++++++++++++++++++
 lib/fuse_versionscript  |    1 +
 5 files changed, 43 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index bece561ef3ec9c..cce263aa62f5d0 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -534,6 +534,13 @@ struct fuse_loop_config_v1 {
 
 #define FUSE_IOCTL_MAX_IOV	256
 
+/**
+ * iomap discovery flags
+ *
+ * FUSE_IOMAP_SUPPORT_FILEIO: basic file I/O functionality through iomap
+ */
+#define FUSE_IOMAP_SUPPORT_FILEIO	(1ULL << 0)
+
 /**
  * Connection information, passed to the ->init() method
  *
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 6b1fcc44004dbf..95c6c179a4398a 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -1156,12 +1156,19 @@ struct fuse_backing_map {
 	uint64_t	padding;
 };
 
+struct fuse_iomap_support {
+	uint64_t	flags;
+	uint64_t	padding;
+};
+
 /* Device ioctls: */
 #define FUSE_DEV_IOC_MAGIC		229
 #define FUSE_DEV_IOC_CLONE		_IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
 #define FUSE_DEV_IOC_BACKING_OPEN	_IOW(FUSE_DEV_IOC_MAGIC, 1, \
 					     struct fuse_backing_map)
 #define FUSE_DEV_IOC_BACKING_CLOSE	_IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t)
+#define FUSE_DEV_IOC_IOMAP_SUPPORT	_IOR(FUSE_DEV_IOC_MAGIC, 99, \
+					     struct fuse_iomap_support)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index c113c85067fb82..f31f250f13a965 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -2658,6 +2658,15 @@ bool fuse_req_is_uring(fuse_req_t req);
 int fuse_req_get_payload(fuse_req_t req, char **payload, size_t *payload_sz,
 			 void **mr);
 
+/**
+ * Discover the kernel's iomap capabilities.  Returns FUSE_CAP_IOMAP_* flags.
+ *
+ * @param fd open file descriptor to a fuse device, or -1 if you're running
+ *           in the same process that will call mount().
+ * @return FUSE_IOMAP_SUPPORT_* flags
+ */
+uint64_t fuse_lowlevel_discover_iomap(int fd);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 23169c1946ce0b..4f3585f9a6841d 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -5073,3 +5073,22 @@ void fuse_session_stop_teardown_watchdog(void *data)
 	pthread_join(tt->thread_id, NULL);
 	fuse_tt_destruct(tt);
 }
+
+uint64_t fuse_lowlevel_discover_iomap(int fd)
+{
+	struct fuse_iomap_support ios = { };
+
+	if (fd >= 0) {
+		ioctl(fd, FUSE_DEV_IOC_IOMAP_SUPPORT, &ios);
+		return ios.flags;
+	}
+
+	fd = open("/dev/fuse", O_RDONLY | O_CLOEXEC);
+	if (fd < 0)
+		return 0;
+
+	ioctl(fd, FUSE_DEV_IOC_IOMAP_SUPPORT, &ios);
+	close(fd);
+
+	return ios.flags;
+}
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 67c3bd614c44fc..f16698f3c4dbfa 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -244,6 +244,7 @@ FUSE_3.99 {
 		fuse_add_direntry_plus_iflags;
 		fuse_fs_can_enable_iomap;
 		fuse_fs_can_enable_iomapx;
+		fuse_lowlevel_discover_iomap;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 16/25] libfuse: add lower level iomap_config implementation
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (14 preceding siblings ...)
  2026-02-23 23:29   ` [PATCH 15/25] libfuse: allow discovery of the kernel's iomap capabilities Darrick J. Wong
@ 2026-02-23 23:29   ` Darrick J. Wong
  2026-02-23 23:29   ` [PATCH 17/25] libfuse: add upper " Darrick J. Wong
                     ` (8 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:29 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Add FUSE_IOMAP_CONFIG helpers to the low level fuse library.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h   |   31 ++++++++++++++++++
 include/fuse_kernel.h   |   31 ++++++++++++++++++
 include/fuse_lowlevel.h |   27 +++++++++++++++
 lib/fuse_lowlevel.c     |   82 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/fuse_versionscript  |    1 +
 5 files changed, 172 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index cce263aa62f5d0..2f6672fc14d90d 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1235,6 +1235,37 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
 /* use iomap for this inode */
 #define FUSE_IFLAG_IOMAP		(1U << 2)
 
+/* Which fields are set in fuse_iomap_config_out? */
+#define FUSE_IOMAP_CONFIG_SID		(1 << 0ULL)
+#define FUSE_IOMAP_CONFIG_UUID		(1 << 1ULL)
+#define FUSE_IOMAP_CONFIG_BLOCKSIZE	(1 << 2ULL)
+#define FUSE_IOMAP_CONFIG_MAX_LINKS	(1 << 3ULL)
+#define FUSE_IOMAP_CONFIG_TIME		(1 << 4ULL)
+#define FUSE_IOMAP_CONFIG_MAXBYTES	(1 << 5ULL)
+
+struct fuse_iomap_config{
+	uint64_t flags;		/* FUSE_IOMAP_CONFIG_* */
+
+	char s_id[32];		/* Informational name */
+	char s_uuid[16];	/* UUID */
+
+	uint8_t s_uuid_len;	/* length of s_uuid */
+
+	uint8_t s_pad[3];	/* must be zeroes */
+
+	uint32_t s_blocksize;	/* fs block size */
+	uint32_t s_max_links;	/* max hard links */
+
+	/* Granularity of c/m/atime in ns (cannot be worse than a second) */
+	uint32_t s_time_gran;
+
+	/* Time limits for c/m/atime in seconds */
+	int64_t s_time_min;
+	int64_t s_time_max;
+
+	int64_t s_maxbytes;	/* max file size */
+};
+
 /* ----------------------------------------------------------- *
  * Compatibility stuff					       *
  * ----------------------------------------------------------- */
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 95c6c179a4398a..897d996a0ce60d 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -246,6 +246,7 @@
  *  - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations
  *  - add FUSE_ATTR_EXCLUSIVE to enable exclusive mode for specific inodes
  *  - add FUSE_ATTR_IOMAP to enable iomap for specific inodes
+ *  - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry
  */
 
 #ifndef _LINUX_FUSE_H
@@ -677,6 +678,7 @@ enum fuse_opcode {
 	FUSE_STATX		= 52,
 	FUSE_COPY_FILE_RANGE_64	= 53,
 
+	FUSE_IOMAP_CONFIG	= 4092,
 	FUSE_IOMAP_IOEND	= 4093,
 	FUSE_IOMAP_BEGIN	= 4094,
 	FUSE_IOMAP_END		= 4095,
@@ -1390,4 +1392,33 @@ struct fuse_iomap_ioend_out {
 	uint64_t newsize;	/* new ondisk size */
 };
 
+struct fuse_iomap_config_in {
+	uint64_t flags;		/* supported FUSE_IOMAP_CONFIG_* flags */
+	int64_t maxbytes;	/* max supported file size */
+	uint64_t padding[6];	/* zero */
+};
+
+struct fuse_iomap_config_out {
+	uint64_t flags;		/* FUSE_IOMAP_CONFIG_* */
+
+	char s_id[32];		/* Informational name */
+	char s_uuid[16];	/* UUID */
+
+	uint8_t s_uuid_len;	/* length of s_uuid */
+
+	uint8_t s_pad[3];	/* must be zeroes */
+
+	uint32_t s_blocksize;	/* fs block size */
+	uint32_t s_max_links;	/* max hard links */
+
+	/* Granularity of c/m/atime in ns (cannot be worse than a second) */
+	uint32_t s_time_gran;
+
+	/* Time limits for c/m/atime in seconds */
+	int64_t s_time_min;
+	int64_t s_time_max;
+
+	int64_t s_maxbytes;	/* max file size */
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index f31f250f13a965..a00b6d5a7fa0b6 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -1425,6 +1425,20 @@ struct fuse_lowlevel_ops {
 			     uint64_t attr_ino, off_t pos, uint64_t written,
 			     uint32_t ioendflags, int error, uint32_t dev,
 			     uint64_t new_addr);
+
+	/**
+	 * Configure the filesystem geometry for iomap mode
+	 *
+	 * Valid replies:
+	 *   fuse_reply_iomap_config
+	 *   fuse_reply_err
+	 *
+	 * @param req request handle
+	 * @param flags FUSE_IOMAP_CONFIG_* flags that can be passed back
+	 * @param maxbytes maximum supported file size
+	 */
+	void (*iomap_config) (fuse_req_t req, uint64_t flags,
+			      uint64_t maxbytes);
 };
 
 /**
@@ -1927,6 +1941,19 @@ int fuse_reply_iomap_begin(fuse_req_t req, const struct fuse_file_iomap *read,
  */
 int fuse_reply_iomap_ioend(fuse_req_t req, off_t newsize);
 
+/**
+ * Reply with iomap configuration
+ *
+ * Possible requests:
+ *   iomap_config
+ *
+ * @param req request handle
+ * @param cfg iomap configuration
+ * @return zero for success, -errno for failure to send reply
+ */
+int fuse_reply_iomap_config(fuse_req_t req,
+			    const struct fuse_iomap_config *cfg);
+
 /* ----------------------------------------------------------- *
  * Notification						       *
  * ----------------------------------------------------------- */
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 4f3585f9a6841d..19f292c0cb8ee3 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -2835,6 +2835,86 @@ static void do_iomap_ioend(fuse_req_t req, const fuse_ino_t nodeid,
 	_do_iomap_ioend(req, nodeid, inarg, NULL);
 }
 
+#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
+#define offsetofend(TYPE, MEMBER) \
+	(offsetof(TYPE, MEMBER)	+ sizeof_field(TYPE, MEMBER))
+
+#define FUSE_IOMAP_CONFIG_V1 (FUSE_IOMAP_CONFIG_SID | \
+			      FUSE_IOMAP_CONFIG_UUID | \
+			      FUSE_IOMAP_CONFIG_BLOCKSIZE | \
+			      FUSE_IOMAP_CONFIG_MAX_LINKS | \
+			      FUSE_IOMAP_CONFIG_TIME | \
+			      FUSE_IOMAP_CONFIG_MAXBYTES)
+
+#define FUSE_IOMAP_CONFIG_ALL (FUSE_IOMAP_CONFIG_V1)
+
+static ssize_t iomap_config_reply_size(const struct fuse_iomap_config *cfg)
+{
+	if (cfg->flags & ~FUSE_IOMAP_CONFIG_ALL)
+		return -EINVAL;
+
+	return offsetofend(struct fuse_iomap_config_out, s_maxbytes);
+}
+
+int fuse_reply_iomap_config(fuse_req_t req, const struct fuse_iomap_config *cfg)
+{
+	struct fuse_iomap_config_out arg = {
+		.flags = cfg->flags,
+	};
+	const ssize_t reply_size = iomap_config_reply_size(cfg);
+
+	if (reply_size < 0)
+		fuse_reply_err(req, -reply_size);
+
+	if (cfg->flags & FUSE_IOMAP_CONFIG_BLOCKSIZE)
+		arg.s_blocksize = cfg->s_blocksize;
+
+	if (cfg->flags & FUSE_IOMAP_CONFIG_SID)
+		memcpy(arg.s_id, cfg->s_id, sizeof(arg.s_id));
+
+	if (cfg->flags & FUSE_IOMAP_CONFIG_UUID) {
+		arg.s_uuid_len = cfg->s_uuid_len;
+		if (arg.s_uuid_len > sizeof(arg.s_uuid))
+			arg.s_uuid_len = sizeof(arg.s_uuid);
+		memcpy(arg.s_uuid, cfg->s_uuid, arg.s_uuid_len);
+	}
+
+	if (cfg->flags & FUSE_IOMAP_CONFIG_MAX_LINKS)
+		arg.s_max_links = cfg->s_max_links;
+
+	if (cfg->flags & FUSE_IOMAP_CONFIG_TIME) {
+		arg.s_time_gran = cfg->s_time_gran;
+		arg.s_time_min = cfg->s_time_min;
+		arg.s_time_max = cfg->s_time_max;
+	}
+
+	if (cfg->flags & FUSE_IOMAP_CONFIG_MAXBYTES)
+		arg.s_maxbytes = cfg->s_maxbytes;
+
+	return send_reply_ok(req, &arg, reply_size);
+}
+
+static void _do_iomap_config(fuse_req_t req, const fuse_ino_t nodeid,
+		      const void *op_in, const void *in_payload)
+{
+	(void)nodeid;
+	(void)in_payload;
+	const struct fuse_iomap_config_in *arg = op_in;
+
+	if (req->se->op.iomap_config)
+		req->se->op.iomap_config(req,
+					 arg->flags & FUSE_IOMAP_CONFIG_ALL,
+					 arg->maxbytes);
+	else
+		fuse_reply_err(req, ENOSYS);
+}
+
+static void do_iomap_config(fuse_req_t req, const fuse_ino_t nodeid,
+			    const void *inarg)
+{
+	_do_iomap_config(req, nodeid, inarg, NULL);
+}
+
 static bool want_flags_valid(uint64_t capable, uint64_t want)
 {
 	uint64_t unknown_flags = want & (~capable);
@@ -3821,6 +3901,7 @@ static struct {
 	[FUSE_LSEEK]	   = { do_lseek,       "LSEEK"	     },
 	[FUSE_SYNCFS]	   = { do_syncfs,      "SYNCFS"      },
 	[FUSE_STATX]	   = { do_statx,       "STATX"	     },
+	[FUSE_IOMAP_CONFIG]= { do_iomap_config, "IOMAP_CONFIG" },
 	[FUSE_IOMAP_BEGIN] = { do_iomap_begin,	"IOMAP_BEGIN" },
 	[FUSE_IOMAP_END]   = { do_iomap_end,	"IOMAP_END" },
 	[FUSE_IOMAP_IOEND] = { do_iomap_ioend,	"IOMAP_IOEND" },
@@ -3881,6 +3962,7 @@ static struct {
 	[FUSE_LSEEK]		= { _do_lseek,		"LSEEK" },
 	[FUSE_SYNCFS]		= { _do_syncfs,		"SYNCFS" },
 	[FUSE_STATX]		= { _do_statx,		"STATX" },
+	[FUSE_IOMAP_CONFIG]	= { _do_iomap_config,	"IOMAP_CONFIG" },
 	[FUSE_IOMAP_BEGIN]	= { _do_iomap_begin,	"IOMAP_BEGIN" },
 	[FUSE_IOMAP_END]	= { _do_iomap_end,	"IOMAP_END" },
 	[FUSE_IOMAP_IOEND]	= { _do_iomap_ioend,	"IOMAP_IOEND" },
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index f16698f3c4dbfa..14c59928ca9f00 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -245,6 +245,7 @@ FUSE_3.99 {
 		fuse_fs_can_enable_iomap;
 		fuse_fs_can_enable_iomapx;
 		fuse_lowlevel_discover_iomap;
+		fuse_reply_iomap_config;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 17/25] libfuse: add upper level iomap_config implementation
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (15 preceding siblings ...)
  2026-02-23 23:29   ` [PATCH 16/25] libfuse: add lower level iomap_config implementation Darrick J. Wong
@ 2026-02-23 23:29   ` Darrick J. Wong
  2026-02-23 23:30   ` [PATCH 18/25] libfuse: add low level code to invalidate iomap block device ranges Darrick J. Wong
                     ` (7 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:29 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Add FUSE_IOMAP_CONFIG helpers to the upper level fuse library.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h |    7 +++++++
 lib/fuse.c     |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)


diff --git a/include/fuse.h b/include/fuse.h
index 817b3cf6c419c4..9f0ac44295e46f 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -918,6 +918,13 @@ struct fuse_operations {
 	 */
 	int (*getattr_iflags) (const char *path, struct stat *buf,
 			       unsigned int *iflags, struct fuse_file_info *fi);
+
+	/**
+	 * Configure the filesystem geometry that will be used by iomap
+	 * files.
+	 */
+	int (*iomap_config) (uint64_t supported_flags, off_t maxbytes,
+			     struct fuse_iomap_config *cfg);
 };
 
 /** Extra context that may be needed by some filesystems
diff --git a/lib/fuse.c b/lib/fuse.c
index 5d9acbc177a177..5301e34901bb3e 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2954,6 +2954,23 @@ static int fuse_fs_iomap_ioend(struct fuse_fs *fs, const char *path,
 				  ioendflags, error, dev, new_addr, newsize);
 }
 
+static int fuse_fs_iomap_config(struct fuse_fs *fs, uint64_t flags,
+				uint64_t maxbytes,
+				struct fuse_iomap_config *cfg)
+{
+	fuse_get_context()->private_data = fs->user_data;
+	if (!fs->op.iomap_config)
+		return -ENOSYS;
+
+	if (fs->debug) {
+		fuse_log(FUSE_LOG_DEBUG,
+			 "iomap_config flags 0x%llx maxbytes %lld\n",
+			 (unsigned long long)flags, (long long)maxbytes);
+	}
+
+	return fs->op.iomap_config(flags, maxbytes, cfg);
+}
+
 static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
 			     int valid, struct fuse_file_info *fi)
 {
@@ -4834,6 +4851,25 @@ static void fuse_lib_iomap_ioend(fuse_req_t req, fuse_ino_t nodeid,
 	fuse_reply_iomap_ioend(req, newsize);
 }
 
+static void fuse_lib_iomap_config(fuse_req_t req, uint64_t flags,
+				  uint64_t maxbytes)
+{
+	struct fuse_iomap_config cfg = { };
+	struct fuse *f = req_fuse_prepare(req);
+	struct fuse_intr_data d;
+	int err;
+
+	fuse_prepare_interrupt(f, req, &d);
+	err = fuse_fs_iomap_config(f->fs, flags, maxbytes, &cfg);
+	fuse_finish_interrupt(f, req, &d);
+	if (err) {
+		reply_err(req, err);
+		return;
+	}
+
+	fuse_reply_iomap_config(req, &cfg);
+}
+
 static int clean_delay(struct fuse *f)
 {
 	/*
@@ -4939,6 +4975,7 @@ static struct fuse_lowlevel_ops fuse_path_ops = {
 	.iomap_begin = fuse_lib_iomap_begin,
 	.iomap_end = fuse_lib_iomap_end,
 	.iomap_ioend = fuse_lib_iomap_ioend,
+	.iomap_config = fuse_lib_iomap_config,
 };
 
 int fuse_notify_poll(struct fuse_pollhandle *ph)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 18/25] libfuse: add low level code to invalidate iomap block device ranges
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (16 preceding siblings ...)
  2026-02-23 23:29   ` [PATCH 17/25] libfuse: add upper " Darrick J. Wong
@ 2026-02-23 23:30   ` Darrick J. Wong
  2026-02-23 23:30   ` [PATCH 19/25] libfuse: add upper-level API to invalidate parts of an iomap block device Darrick J. Wong
                     ` (6 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:30 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Make it easier to invalidate the page cache for a block device that is
being used in conjunction with iomap.  This allows a fuse server to kill
all cached data for a block that is being freed, so that block reuse
doesn't result in file corruption.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_kernel.h   |   15 +++++++++++++++
 include/fuse_lowlevel.h |   15 +++++++++++++++
 lib/fuse_lowlevel.c     |   22 ++++++++++++++++++++++
 lib/fuse_versionscript  |    1 +
 4 files changed, 53 insertions(+)


diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 897d996a0ce60d..1e7c9d8082cf23 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -247,6 +247,7 @@
  *  - add FUSE_ATTR_EXCLUSIVE to enable exclusive mode for specific inodes
  *  - add FUSE_ATTR_IOMAP to enable iomap for specific inodes
  *  - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry
+ *  - add FUSE_NOTIFY_IOMAP_DEV_INVAL to invalidate iomap bdev ranges
  */
 
 #ifndef _LINUX_FUSE_H
@@ -701,6 +702,7 @@ enum fuse_notify_code {
 	FUSE_NOTIFY_RESEND = 7,
 	FUSE_NOTIFY_INC_EPOCH = 8,
 	FUSE_NOTIFY_PRUNE = 9,
+	FUSE_NOTIFY_IOMAP_DEV_INVAL = 99,
 };
 
 /* The read buffer is required to be at least 8k, but may be much larger */
@@ -1421,4 +1423,17 @@ struct fuse_iomap_config_out {
 	int64_t s_maxbytes;	/* max file size */
 };
 
+struct fuse_range {
+	uint64_t offset;
+	uint64_t length;
+};
+
+struct fuse_iomap_dev_inval_out {
+	uint32_t dev;		/* device cookie */
+	uint32_t reserved;	/* zero */
+
+	/* range of bdev pagecache to invalidate, in bytes */
+	struct fuse_range range;
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index a00b6d5a7fa0b6..95429ac096a82c 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -2208,6 +2208,21 @@ int fuse_lowlevel_iomap_device_add(struct fuse_session *se, int fd,
  */
 int fuse_lowlevel_iomap_device_remove(struct fuse_session *se, int device_id);
 
+/*
+ * Invalidate the page cache of a block device opened for use with iomap.
+ *
+ * Added in FUSE protocol version 7.99. If the kernel does not support
+ * this (or a newer) version, the function will return -ENOSYS and do
+ * nothing.
+ *
+ * @param se the session object
+ * @param dev device cookie returned by fuse_lowlevel_iomap_add_device
+ * @param offset start of the range to invalidate, in bytes
+ * @return length length of the range to invalidate, in bytes
+ */
+int fuse_lowlevel_iomap_device_invalidate(struct fuse_session *se, int dev,
+					  off_t offset, off_t length);
+
 /* ----------------------------------------------------------- *
  * Utility functions					       *
  * ----------------------------------------------------------- */
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 19f292c0cb8ee3..89e26f207addbf 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -3684,6 +3684,28 @@ int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
 	return res;
 }
 
+int fuse_lowlevel_iomap_device_invalidate(struct fuse_session *se, int dev,
+					  off_t offset, off_t length)
+{
+	struct fuse_iomap_dev_inval_out arg = {
+		.dev = dev,
+		.range.offset = offset,
+		.range.length = length,
+	};
+	struct iovec iov[2];
+
+	if (!se)
+		return -EINVAL;
+
+	if (!(se->conn.want_ext & FUSE_CAP_IOMAP))
+		return -ENOSYS;
+
+	iov[1].iov_base = &arg;
+	iov[1].iov_len = sizeof(arg);
+
+	return send_notify_iov(se, FUSE_NOTIFY_IOMAP_DEV_INVAL, iov, 2);
+}
+
 struct fuse_retrieve_req {
 	struct fuse_notify_req nreq;
 	void *cookie;
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 14c59928ca9f00..56edd16862ca30 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -246,6 +246,7 @@ FUSE_3.99 {
 		fuse_fs_can_enable_iomapx;
 		fuse_lowlevel_discover_iomap;
 		fuse_reply_iomap_config;
+		fuse_lowlevel_iomap_device_invalidate;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 19/25] libfuse: add upper-level API to invalidate parts of an iomap block device
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (17 preceding siblings ...)
  2026-02-23 23:30   ` [PATCH 18/25] libfuse: add low level code to invalidate iomap block device ranges Darrick J. Wong
@ 2026-02-23 23:30   ` Darrick J. Wong
  2026-02-23 23:30   ` [PATCH 20/25] libfuse: add atomic write support Darrick J. Wong
                     ` (5 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:30 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Wire up the upper-level wrappers to
fuse_lowlevel_iomap_invalidate_device.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h         |   10 ++++++++++
 lib/fuse.c             |    9 +++++++++
 lib/fuse_versionscript |    1 +
 3 files changed, 20 insertions(+)


diff --git a/include/fuse.h b/include/fuse.h
index 9f0ac44295e46f..db4281e3f330c6 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -1445,6 +1445,16 @@ int fuse_fs_iomap_device_add(int fd, unsigned int flags);
  */
 int fuse_fs_iomap_device_remove(int device_id);
 
+/**
+ * Invalidate any pagecache for the given iomap (block) device.
+ *
+ * @param device_id device index as returned by fuse_lowlevel_iomap_device_add
+ * @param offset starting offset of the range to invalidate
+ * @param length length of the range to invalidate
+ * @return 0 on success, or negative errno on failure
+ */
+int fuse_fs_iomap_device_invalidate(int device_id, off_t offset, off_t length);
+
 /**
  * Decide if we can enable iomap mode for a particular file for an upper-level
  * fuse server.
diff --git a/lib/fuse.c b/lib/fuse.c
index 5301e34901bb3e..022888c475cb3d 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2932,6 +2932,15 @@ int fuse_fs_iomap_device_remove(int device_id)
 	return fuse_lowlevel_iomap_device_remove(se, device_id);
 }
 
+int fuse_fs_iomap_device_invalidate(int device_id, off_t offset, off_t length)
+{
+	struct fuse_context *ctxt = fuse_get_context();
+	struct fuse_session *se = fuse_get_session(ctxt->fuse);
+
+	return fuse_lowlevel_iomap_device_invalidate(se, device_id, offset,
+						     length);
+}
+
 static int fuse_fs_iomap_ioend(struct fuse_fs *fs, const char *path,
 			       uint64_t nodeid, uint64_t attr_ino, off_t pos,
 			       uint64_t written, uint32_t ioendflags, int error,
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 56edd16862ca30..56cc5fade272e5 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -247,6 +247,7 @@ FUSE_3.99 {
 		fuse_lowlevel_discover_iomap;
 		fuse_reply_iomap_config;
 		fuse_lowlevel_iomap_device_invalidate;
+		fuse_fs_iomap_device_invalidate;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 20/25] libfuse: add atomic write support
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (18 preceding siblings ...)
  2026-02-23 23:30   ` [PATCH 19/25] libfuse: add upper-level API to invalidate parts of an iomap block device Darrick J. Wong
@ 2026-02-23 23:30   ` Darrick J. Wong
  2026-02-23 23:30   ` [PATCH 21/25] libfuse: allow disabling of fs memory reclaim and write throttling Darrick J. Wong
                     ` (4 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:30 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Add the single flag that we need to turn on atomic write support in
fuse.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h |    4 ++++
 include/fuse_kernel.h |    3 +++
 lib/fuse_lowlevel.c   |    2 ++
 3 files changed, 9 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index 2f6672fc14d90d..a42d70f79d57e1 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -540,6 +540,8 @@ struct fuse_loop_config_v1 {
  * FUSE_IOMAP_SUPPORT_FILEIO: basic file I/O functionality through iomap
  */
 #define FUSE_IOMAP_SUPPORT_FILEIO	(1ULL << 0)
+/* untorn writes through iomap */
+#define FUSE_IOMAP_SUPPORT_ATOMIC	(1ULL << 1)
 
 /**
  * Connection information, passed to the ->init() method
@@ -1234,6 +1236,8 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
 #define FUSE_IFLAG_EXCLUSIVE		(1U << 1)
 /* use iomap for this inode */
 #define FUSE_IFLAG_IOMAP		(1U << 2)
+/* enable untorn writes */
+#define FUSE_IFLAG_ATOMIC		(1U << 3)
 
 /* Which fields are set in fuse_iomap_config_out? */
 #define FUSE_IOMAP_CONFIG_SID		(1 << 0ULL)
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 1e7c9d8082cf23..71a6a92b4b4a65 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -248,6 +248,7 @@
  *  - add FUSE_ATTR_IOMAP to enable iomap for specific inodes
  *  - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry
  *  - add FUSE_NOTIFY_IOMAP_DEV_INVAL to invalidate iomap bdev ranges
+ *  - add FUSE_ATTR_ATOMIC for single-fsblock atomic write support
  */
 
 #ifndef _LINUX_FUSE_H
@@ -591,11 +592,13 @@ struct fuse_file_lock {
  * FUSE_ATTR_EXCLUSIVE: This file can only be modified by this mount, so the
  * kernel can use cached attributes more aggressively (e.g. ACL inheritance)
  * FUSE_ATTR_IOMAP: Use iomap for this inode
+ * FUSE_ATTR_ATOMIC: Enable untorn writes
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 #define FUSE_ATTR_DAX		(1 << 1)
 #define FUSE_ATTR_EXCLUSIVE	(1 << 2)
 #define FUSE_ATTR_IOMAP		(1 << 3)
+#define FUSE_ATTR_ATOMIC	(1 << 4)
 
 /**
  * Open flags
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 89e26f207addbf..91aaf6a1183d30 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -168,6 +168,8 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr,
 		attr->flags |= FUSE_ATTR_EXCLUSIVE;
 	if (iflags & FUSE_IFLAG_IOMAP)
 		attr->flags |= FUSE_ATTR_IOMAP;
+	if (iflags & FUSE_IFLAG_ATOMIC)
+		attr->flags |= FUSE_ATTR_ATOMIC;
 }
 
 static void convert_attr(const struct fuse_setattr_in *attr, struct stat *stbuf)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 21/25] libfuse: allow disabling of fs memory reclaim and write throttling
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (19 preceding siblings ...)
  2026-02-23 23:30   ` [PATCH 20/25] libfuse: add atomic write support Darrick J. Wong
@ 2026-02-23 23:30   ` Darrick J. Wong
  2026-02-23 23:31   ` [PATCH 22/25] libfuse: create a helper to transform an open regular file into an open loopdev Darrick J. Wong
                     ` (3 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:30 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Create a library function so that fuse-iomap servers can ask the kernel
to disable direct memory reclaim for filesystems and BDI write
throttling.

Disabling fs reclaim prevents livelocks where the fuse server can
allocate memory, fault into the kernel, and then the allocation tries to
initiate writeback by calling back into the same fuse server.

Disabling BDI write throttling means that writeback won't be throttled
by metadata writes to the filesystem.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_kernel.h   |    1 +
 include/fuse_lowlevel.h |   13 +++++++++++++
 lib/fuse_lowlevel.c     |    5 +++++
 lib/fuse_versionscript  |    1 +
 4 files changed, 20 insertions(+)


diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 71a6a92b4b4a65..0779e3917a1e8f 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -1176,6 +1176,7 @@ struct fuse_iomap_support {
 #define FUSE_DEV_IOC_BACKING_CLOSE	_IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t)
 #define FUSE_DEV_IOC_IOMAP_SUPPORT	_IOR(FUSE_DEV_IOC_MAGIC, 99, \
 					     struct fuse_iomap_support)
+#define FUSE_DEV_IOC_SET_NOFS		_IOW(FUSE_DEV_IOC_MAGIC, 100, uint32_t)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index 95429ac096a82c..e2127c40940640 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -2709,6 +2709,19 @@ int fuse_req_get_payload(fuse_req_t req, char **payload, size_t *payload_sz,
  */
 uint64_t fuse_lowlevel_discover_iomap(int fd);
 
+/**
+ * Disable direct fs memory reclaim and BDI throttling for a fuse-iomap server.
+ * This prevents memory allocations for the fuse server from initiating
+ * pagecache writeback to the fuse server and only throttles writes to the
+ * fuse server's block devices.  The fuse connection must already be
+ * initialized with iomap enabled.
+ *
+ * @param se the session object
+ * @param val 1 to disable fs reclaim and throttling, 0 to enable them
+ * @return 0 on success, or -1 on failure with errno set
+ */
+int fuse_lowlevel_disable_fsreclaim(struct fuse_session *se, int val);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 91aaf6a1183d30..a6b65ccf9fe1df 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -5198,3 +5198,8 @@ uint64_t fuse_lowlevel_discover_iomap(int fd)
 
 	return ios.flags;
 }
+
+int fuse_lowlevel_disable_fsreclaim(struct fuse_session *se, int val)
+{
+	return ioctl(se->fd, FUSE_DEV_IOC_SET_NOFS, &val);
+}
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 56cc5fade272e5..556562f1bb4588 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -248,6 +248,7 @@ FUSE_3.99 {
 		fuse_reply_iomap_config;
 		fuse_lowlevel_iomap_device_invalidate;
 		fuse_fs_iomap_device_invalidate;
+		fuse_lowlevel_disable_fsreclaim;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 22/25] libfuse: create a helper to transform an open regular file into an open loopdev
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (20 preceding siblings ...)
  2026-02-23 23:30   ` [PATCH 21/25] libfuse: allow disabling of fs memory reclaim and write throttling Darrick J. Wong
@ 2026-02-23 23:31   ` Darrick J. Wong
  2026-02-23 23:31   ` [PATCH 23/25] libfuse: add swapfile support for iomap files Darrick J. Wong
                     ` (2 subsequent siblings)
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:31 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Create a helper function to configure a loop device for an open regular
file fd, and then return an open fd to the loop device.  This will
enable the use of fuse+iomap file servers with filesystem image files.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_loopdev.h |   27 +++
 include/meson.build    |    4 
 lib/fuse_loopdev.c     |  403 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/fuse_versionscript |    1 
 lib/meson.build        |    3 
 meson.build            |   11 +
 6 files changed, 448 insertions(+), 1 deletion(-)
 create mode 100644 include/fuse_loopdev.h
 create mode 100644 lib/fuse_loopdev.c


diff --git a/include/fuse_loopdev.h b/include/fuse_loopdev.h
new file mode 100644
index 00000000000000..b0a897c9ce4eda
--- /dev/null
+++ b/include/fuse_loopdev.h
@@ -0,0 +1,27 @@
+/*  FUSE: Filesystem in Userspace
+  Copyright (C) 2025-2026 Oracle.
+  Author: Darrick J. Wong <djwong@kernel.org>
+
+  This program can be distributed under the terms of the GNU LGPLv2.
+  See the file LGPL2.txt.
+*/
+#ifndef FUSE_LOOPDEV_H_
+#define FUSE_LOOPDEV_H_
+
+/**
+ * If possible, set up a loop device for the given file fd.  Return the opened
+ * loop device fd and the path to the loop device.  The loop device will be
+ * removed when the last close() occurs.
+ *
+ * @param file_fd an open file
+ * @param open_flags O_* flags that were used to open file_fd
+ * @param path path to the open file
+ * @param timeout spend this much time waiting to lock the file
+ * @param loop_fd set to an open fd to the new loop device or -1 if inappropriate
+ * @param loop_dev (optional) set to a pointer to the path to the loop device
+ * @return 0 for success, or -1 on error
+ */
+int fuse_loopdev_setup(int file_fd, int open_flags, const char *path,
+		       unsigned int timeout, int *loop_fd, char **loop_dev);
+
+#endif /* FUSE_LOOPDEV_H_ */
diff --git a/include/meson.build b/include/meson.build
index bf671977a5a6a9..0b1e3a9d4fcb43 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -1,4 +1,8 @@
 libfuse_headers = [ 'fuse.h', 'fuse_common.h', 'fuse_lowlevel.h',
 	            'fuse_opt.h', 'cuse_lowlevel.h', 'fuse_log.h' ]
 
+if private_cfg.get('FUSE_LOOPDEV_ENABLED')
+  libfuse_headers += [ 'fuse_loopdev.h' ]
+endif
+
 install_headers(libfuse_headers, subdir: 'fuse3')
diff --git a/lib/fuse_loopdev.c b/lib/fuse_loopdev.c
new file mode 100644
index 00000000000000..9a74d9c6ec1dc8
--- /dev/null
+++ b/lib/fuse_loopdev.c
@@ -0,0 +1,403 @@
+/*
+  FUSE: Filesystem in Userspace
+  Copyright (C) 2025-2026 Oracle.
+  Author: Darrick J. Wong <djwong@kernel.org>
+
+  Library functions for handling loopback devices on linux.
+
+  This program can be distributed under the terms of the GNU LGPLv2.
+  See the file LGPL2.txt
+*/
+
+#define _GNU_SOURCE
+#include "fuse_config.h"
+#include "fuse_loopdev.h"
+
+#ifdef FUSE_LOOPDEV_ENABLED
+#include <stdint.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <dirent.h>
+#include <signal.h>
+#include <time.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <linux/loop.h>
+
+#include "fuse_log.h"
+
+#define _PATH_LOOPCTL		"/dev/loop-control"
+#define _PATH_SYS_BLOCK		"/sys/block"
+
+#ifdef STATX_SUBVOL
+# define STATX_SUBVOL_FLAG	STATX_SUBVOL
+#else
+# define STATX_SUBVOL_FLAG	0
+#endif
+
+static int lock_file(int fd, const char *path)
+{
+	int ret;
+
+	ret = flock(fd, LOCK_EX);
+	if (ret) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", path, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+static double gettime_monotonic(void)
+{
+#ifdef CLOCK_MONOTONIC
+	struct timespec ts;
+#endif
+	struct timeval tv;
+	static double fake_ret = 0;
+	int ret;
+
+#ifdef CLOCK_MONOTONIC
+	ret = clock_gettime(CLOCK_MONOTONIC, &ts);
+	if (ret == 0)
+		return ts.tv_sec + (ts.tv_nsec / 1000000000.0);
+#endif
+	ret = gettimeofday(&tv, NULL);
+	if (ret == 0)
+		return tv.tv_sec + (tv.tv_usec / 1000000.0);
+
+	fake_ret += 1.0;
+	return fake_ret;
+}
+
+static int lock_file_timeout(int fd, const char *path, unsigned int timeout)
+{
+	double deadline, now;
+	int ret;
+
+	now = gettime_monotonic();
+	deadline = now + timeout;
+
+	/* Use a tight sleeping loop here to avoid signal handlers */
+	while (now <= deadline) {
+		ret = flock(fd, LOCK_EX | LOCK_NB);
+		if (ret == 0)
+			return 0;
+		if (errno != EWOULDBLOCK) {
+			fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", path,
+				 strerror(errno));
+			return -1;
+		}
+
+		/* sleep 0.1s before trying again */
+		usleep(100000);
+
+		now = gettime_monotonic();
+	}
+
+	fuse_log(FUSE_LOG_DEBUG, "%s: could not lock file\n", path);
+	errno = EWOULDBLOCK;
+	return -1;
+}
+
+static int unlock_file(int fd, const char *path)
+{
+	int ret;
+
+	ret = flock(fd, LOCK_UN);
+	if (ret) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", path, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int want_loopdev(int file_fd, const char *path)
+{
+	struct stat statbuf;
+	int ret;
+
+	ret = fstat(file_fd, &statbuf);
+	if (ret < 0) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: fstat failed: %s\n",
+			 path, strerror(errno));
+		return -1;
+	}
+
+	/*
+	 * Keep quiet about block devices, the client can probably still read
+	 * and write that.
+	 */
+	if (S_ISBLK(statbuf.st_mode))
+		return 0;
+
+	ret = S_ISREG(statbuf.st_mode) && statbuf.st_size >= 512;
+	if (!ret)
+		fuse_log(FUSE_LOG_DEBUG,
+			 "%s: file not compatible with loop device\n", path);
+	return ret;
+}
+
+static int same_backing_file(int dir_fd, const char *name,
+			     const struct statx *file_stat)
+{
+	struct statx backing_stat;
+	char backing_name[NAME_MAX + 18 + 1];
+	char path[PATH_MAX + 1];
+	ssize_t bytes;
+	int fd;
+	int ret;
+
+	snprintf(backing_name, sizeof(backing_name), "%s/loop/backing_file",
+			name);
+
+	fd = openat(dir_fd, backing_name, O_RDONLY);
+	if (fd < 0) {
+		/* unconfigured loop devices don't have backing_file attr */
+		if (errno == ENOENT)
+			return 0;
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", backing_name,
+			 strerror(errno));
+		return -1;
+	}
+
+	bytes = pread(fd, path, sizeof(path) - 1, 0);
+	if (bytes < 0) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", backing_name,
+			 strerror(errno));
+		ret = -1;
+		goto out_backing;
+	} else if (bytes == 0) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: no path in backing file?\n",
+			 backing_name);
+		ret = -1;
+		goto out_backing;
+	}
+
+	if (path[bytes - 1] == '\n')
+		path[bytes - 1] = 0;
+
+	ret = statx(AT_FDCWD, path, 0, STATX_BASIC_STATS | STATX_SUBVOL_FLAG,
+			&backing_stat);
+	if (ret) {
+		/*
+		 * backing file deleted, assume nobody's doing procfd
+		 * shenanigans
+		 */
+		if (errno == ENOENT) {
+			ret = 0;
+			goto out_backing;
+		}
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", path, strerror(errno));
+		goto out_backing;
+	}
+
+	/* different devices */
+	if (backing_stat.stx_dev_major != file_stat->stx_dev_major)
+		goto out_backing;
+	if (backing_stat.stx_dev_minor != file_stat->stx_dev_minor)
+		goto out_backing;
+
+	/* different inode number */
+	if (backing_stat.stx_ino != file_stat->stx_ino)
+		goto out_backing;
+
+#ifdef STATX_SUBVOL
+	/* different subvol (or subvol state) */
+	if ((backing_stat.stx_mask ^ file_stat->stx_mask) & STATX_SUBVOL)
+		goto out_backing;
+
+	if ((backing_stat.stx_mask & STATX_SUBVOL) &&
+	    backing_stat.stx_subvol != file_stat->stx_subvol)
+		goto out_backing;
+#endif
+
+	ret = 1;
+
+out_backing:
+	close(fd);
+	return ret;
+}
+
+static int has_existing_loopdev(int file_fd, const char *path)
+{
+	struct statx file_stat;
+	DIR *dir;
+	struct dirent *d;
+	int blockfd;
+	int ret;
+
+	ret = statx(file_fd, "", AT_EMPTY_PATH,
+		    STATX_BASIC_STATS | STATX_SUBVOL_FLAG, &file_stat);
+	if (ret) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", path, strerror(errno));
+		return -1;
+	}
+
+	dir = opendir(_PATH_SYS_BLOCK);
+	if (!dir) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", _PATH_SYS_BLOCK,
+			 strerror(errno));
+		return -1;
+	}
+
+	blockfd = dirfd(dir);
+
+	while ((d = readdir(dir)) != NULL) {
+		if (strcmp(d->d_name, ".") == 0
+		    || strcmp(d->d_name, "..") == 0
+		    || strncmp(d->d_name, "loop", 4) != 0)
+			continue;
+
+		ret = same_backing_file(blockfd, d->d_name, &file_stat);
+		if (ret != 0)
+			break;
+	}
+
+	closedir(dir);
+	return ret;
+}
+
+static int open_loopdev(int file_fd, int open_flags, char *loopdev,
+			size_t loopdev_sz)
+{
+	struct loop_config lc = {
+		.info.lo_flags = LO_FLAGS_DIRECT_IO | LO_FLAGS_AUTOCLEAR,
+	};
+	int ctl_fd = -1;
+	int loop_fd = -1;
+	int loopno;
+	int ret;
+
+	if ((open_flags & O_ACCMODE) == O_RDONLY)
+		lc.info.lo_flags |= LO_FLAGS_READ_ONLY;
+
+	ctl_fd = open(_PATH_LOOPCTL, O_RDONLY);
+	if (ctl_fd < 0) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", _PATH_LOOPCTL,
+			 strerror(errno));
+		return -1;
+	}
+
+	ret = ioctl(ctl_fd, LOOP_CTL_GET_FREE);
+	if (ret < 0) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", _PATH_LOOPCTL,
+			 strerror(errno));
+		goto out_ctl;
+	}
+	loopno = ret;
+	snprintf(loopdev, loopdev_sz, "/dev/loop%d", loopno);
+
+	loop_fd = open(loopdev, open_flags);
+	if (loop_fd < 0) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", loopdev, strerror(errno));
+		ret = -1;
+		goto out_ctl;
+	}
+
+	lc.fd = file_fd;
+
+	ret = ioctl(loop_fd, LOOP_CONFIGURE, &lc);
+	if (ret < 0) {
+		fuse_log(FUSE_LOG_DEBUG, "%s: %s\n", loopdev, strerror(errno));
+		goto out_loop;
+	}
+
+	close(ctl_fd);
+	return loop_fd;
+
+out_loop:
+	ioctl(ctl_fd, LOOP_CTL_REMOVE, loopno);
+	close(loop_fd);
+out_ctl:
+	close(ctl_fd);
+	return ret;
+}
+
+int fuse_loopdev_setup(int file_fd, int open_flags, const char *path,
+		       unsigned int timeout, int *loop_fd, char **loop_dev)
+{
+	char loopdev[PATH_MAX];
+	int loopfd = -1;
+	int ret;
+
+	*loop_fd = -1;
+	if (loop_dev)
+		*loop_dev = NULL;
+
+	if (timeout)
+		ret = lock_file_timeout(file_fd, path, timeout);
+	else
+		ret = lock_file(file_fd, path);
+	if (ret)
+		return ret;
+
+	ret = want_loopdev(file_fd, path);
+	if (ret <= 0)
+		goto out_unlock;
+
+	ret = has_existing_loopdev(file_fd, path);
+	if (ret < 0)
+		goto out_unlock;
+	if (ret == 1) {
+		fuse_log(FUSE_LOG_DEBUG,
+			 "%s: attached to another loop device\n", path);
+		ret = -1;
+		errno = EBUSY;
+		goto out_unlock;
+	}
+
+	loopfd = open_loopdev(file_fd, open_flags, loopdev, sizeof(loopdev));
+	if (loopfd < 0)
+		goto out_unlock;
+
+	ret = unlock_file(file_fd, path);
+	if (ret)
+		goto out_loop;
+
+	if (loop_dev) {
+		char *ldev = strdup(loopdev);
+		if (!ldev)
+			goto out_loop;
+
+		*loop_fd = loopfd;
+		*loop_dev = ldev;
+	} else {
+		*loop_fd = loopfd;
+	}
+
+	return 0;
+
+out_loop:
+	close(loopfd);
+out_unlock:
+	unlock_file(file_fd, path);
+	return ret;
+}
+#else
+#include <stdlib.h>
+
+#include "util.h"
+
+int fuse_loopdev_setup(int file_fd FUSE_VAR_UNUSED,
+		       int open_flags FUSE_VAR_UNUSED,
+		       const char *path FUSE_VAR_UNUSED,
+		       unsigned int timeout FUSE_VAR_UNUSED,
+		       int *loop_fd, char **loop_dev)
+{
+	*loop_fd = -1;
+	if (loop_dev)
+		*loop_dev = NULL;
+	return 0;
+}
+#endif /* FUSE_LOOPDEV_ENABLED */
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 556562f1bb4588..f459d06c2f3377 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -249,6 +249,7 @@ FUSE_3.99 {
 		fuse_lowlevel_iomap_device_invalidate;
 		fuse_fs_iomap_device_invalidate;
 		fuse_lowlevel_disable_fsreclaim;
+		fuse_loopdev_setup;
 } FUSE_3.19;
 
 # Local Variables:
diff --git a/lib/meson.build b/lib/meson.build
index a3d3d49f9ba42b..477b0fc2f86d38 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -2,7 +2,8 @@ libfuse_sources = ['fuse.c', 'fuse_i.h', 'fuse_loop.c', 'fuse_loop_mt.c',
                    'fuse_lowlevel.c', 'fuse_misc.h', 'fuse_opt.c',
                    'fuse_signals.c', 'buffer.c', 'cuse_lowlevel.c',
                    'helper.c', 'modules/subdir.c', 'mount_util.c',
-                   'fuse_log.c', 'compat.c', 'util.c', 'util.h' ]
+                   'fuse_log.c', 'compat.c', 'util.c', 'util.h',
+                   'fuse_loopdev.c' ]
 
 if host_machine.system().startswith('linux')
    libfuse_sources += [ 'mount.c' ]
diff --git a/meson.build b/meson.build
index 8359a489c351b9..73aee98c775a2a 100644
--- a/meson.build
+++ b/meson.build
@@ -153,7 +153,18 @@ private_cfg.set('HAVE_STRUCT_STAT_ST_ATIMESPEC',
     cc.has_member('struct stat', 'st_atimespec',
                   prefix: include_default + '#include <sys/stat.h>',
                   args: args_default))
+private_cfg.set('HAVE_STRUCT_LOOP_CONFIG_INFO',
+    cc.has_member('struct loop_config', 'info',
+                  prefix: include_default + '#include <linux/loop.h>',
+                  args: args_default))
+private_cfg.set('HAVE_STATX_BASIC_STATS',
+    cc.has_member('struct statx', 'stx_ino',
+                  prefix: include_default + '#include <sys/stat.h>',
+                  args: args_default))
 
+private_cfg.set('FUSE_LOOPDEV_ENABLED', \
+    private_cfg.get('HAVE_STRUCT_LOOP_CONFIG_INFO') and \
+    private_cfg.get('HAVE_STATX_BASIC_STATS'))
 private_cfg.set('USDT_ENABLED', get_option('enable-usdt'))
 
 # Check for liburing with SQE128 support


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 23/25] libfuse: add swapfile support for iomap files
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (21 preceding siblings ...)
  2026-02-23 23:31   ` [PATCH 22/25] libfuse: create a helper to transform an open regular file into an open loopdev Darrick J. Wong
@ 2026-02-23 23:31   ` Darrick J. Wong
  2026-02-23 23:31   ` [PATCH 24/25] libfuse: add lower-level filesystem freeze, thaw, and shutdown requests Darrick J. Wong
  2026-02-23 23:31   ` [PATCH 25/25] libfuse: add upper-level filesystem freeze, thaw, and shutdown events Darrick J. Wong
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:31 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Add flags for swapfile activation and deactivation.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h |    5 +++++
 1 file changed, 5 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index a42d70f79d57e1..a8aec81ec123a2 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1190,6 +1190,9 @@ int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn);
 #define FUSE_IOMAP_OP_ATOMIC		(1U << 9)
 #define FUSE_IOMAP_OP_DONTCACHE		(1U << 10)
 
+/* swapfile config operation */
+#define FUSE_IOMAP_OP_SWAPFILE		(1U << 30)
+
 /* pagecache writeback operation */
 #define FUSE_IOMAP_OP_WRITEBACK		(1U << 31)
 
@@ -1229,6 +1232,8 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
 #define FUSE_IOMAP_IOEND_APPEND		(1U << 4)
 /* is pagecache writeback */
 #define FUSE_IOMAP_IOEND_WRITEBACK	(1U << 5)
+/* swapfile deactivation */
+#define FUSE_IOMAP_IOEND_SWAPOFF	(1U << 6)
 
 /* enable fsdax */
 #define FUSE_IFLAG_DAX			(1U << 0)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 24/25] libfuse: add lower-level filesystem freeze, thaw, and shutdown requests
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (22 preceding siblings ...)
  2026-02-23 23:31   ` [PATCH 23/25] libfuse: add swapfile support for iomap files Darrick J. Wong
@ 2026-02-23 23:31   ` Darrick J. Wong
  2026-02-23 23:31   ` [PATCH 25/25] libfuse: add upper-level filesystem freeze, thaw, and shutdown events Darrick J. Wong
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:31 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Pass the kernel's filesystem freeze, thaw, and shutdown requests through
to low level fuse servers.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_kernel.h   |   12 +++++++++
 include/fuse_lowlevel.h |   35 +++++++++++++++++++++++++++
 lib/fuse_lowlevel.c     |   60 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 107 insertions(+)


diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 0779e3917a1e8f..ff21973e1c88f7 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -682,6 +682,10 @@ enum fuse_opcode {
 	FUSE_STATX		= 52,
 	FUSE_COPY_FILE_RANGE_64	= 53,
 
+	FUSE_FREEZE_FS		= 4089,
+	FUSE_UNFREEZE_FS	= 4090,
+	FUSE_SHUTDOWN_FS	= 4091,
+
 	FUSE_IOMAP_CONFIG	= 4092,
 	FUSE_IOMAP_IOEND	= 4093,
 	FUSE_IOMAP_BEGIN	= 4094,
@@ -1238,6 +1242,14 @@ struct fuse_syncfs_in {
 	uint64_t	padding;
 };
 
+struct fuse_freezefs_in {
+	uint64_t	unlinked;
+};
+
+struct fuse_shutdownfs_in {
+	uint64_t	flags;
+};
+
 /*
  * For each security context, send fuse_secctx with size of security context
  * fuse_secctx will be followed by security context name and this in turn
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index e2127c40940640..0d7577718490ba 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -1439,6 +1439,41 @@ struct fuse_lowlevel_ops {
 	 */
 	void (*iomap_config) (fuse_req_t req, uint64_t flags,
 			      uint64_t maxbytes);
+
+	/**
+	 * Freeze the filesystem
+	 *
+	 * Valid replies:
+	 *   fuse_reply_err
+	 *
+	 * @param req request handle
+	 * @param ino the root inode number
+	 * @param unlinked count of open unlinked inodes
+	 */
+	void (*freezefs) (fuse_req_t req, fuse_ino_t ino, uint64_t unlinked);
+
+	/**
+	 * Thaw the filesystem
+	 *
+	 * Valid replies:
+	 *   fuse_reply_err
+	 *
+	 * @param req request handle
+	 * @param ino the root inode number
+	 */
+	void (*unfreezefs) (fuse_req_t req, fuse_ino_t ino);
+
+	/**
+	 * Shut down the filesystem
+	 *
+	 * Valid replies:
+	 *   fuse_reply_err
+	 *
+	 * @param req request handle
+	 * @param ino the root inode number
+	 * @param flags zero, currently
+	 */
+	void (*shutdownfs) (fuse_req_t req, fuse_ino_t ino, uint64_t flags);
 };
 
 /**
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index a6b65ccf9fe1df..18503a1fa64d88 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -2917,6 +2917,60 @@ static void do_iomap_config(fuse_req_t req, const fuse_ino_t nodeid,
 	_do_iomap_config(req, nodeid, inarg, NULL);
 }
 
+static void _do_freezefs(fuse_req_t req, const fuse_ino_t nodeid,
+			 const void *op_in, const void *in_payload)
+{
+	const struct fuse_freezefs_in *inarg = op_in;
+	(void)in_payload;
+
+	if (req->se->op.freezefs)
+		req->se->op.freezefs(req, nodeid, inarg->unlinked);
+	else
+		fuse_reply_err(req, ENOSYS);
+}
+
+static void do_freezefs(fuse_req_t req, const fuse_ino_t nodeid,
+			const void *inarg)
+{
+	_do_freezefs(req, nodeid, inarg, NULL);
+}
+
+static void _do_unfreezefs(fuse_req_t req, const fuse_ino_t nodeid,
+			 const void *op_in, const void *in_payload)
+{
+	(void)op_in;
+	(void)in_payload;
+
+	if (req->se->op.unfreezefs)
+		req->se->op.unfreezefs(req, nodeid);
+	else
+		fuse_reply_err(req, ENOSYS);
+}
+
+static void do_unfreezefs(fuse_req_t req, const fuse_ino_t nodeid,
+			const void *inarg)
+{
+	_do_unfreezefs(req, nodeid, inarg, NULL);
+}
+
+static void _do_shutdownfs(fuse_req_t req, const fuse_ino_t nodeid,
+			 const void *op_in, const void *in_payload)
+{
+	const struct fuse_shutdownfs_in *inarg = op_in;
+	(void)in_payload;
+
+	if (req->se->op.shutdownfs)
+		req->se->op.shutdownfs(req, nodeid, inarg->flags);
+	else
+		fuse_reply_err(req, ENOSYS);
+}
+
+static void do_shutdownfs(fuse_req_t req, const fuse_ino_t nodeid,
+			const void *inarg)
+{
+	_do_shutdownfs(req, nodeid, inarg, NULL);
+}
+
 static bool want_flags_valid(uint64_t capable, uint64_t want)
 {
 	uint64_t unknown_flags = want & (~capable);
@@ -3925,6 +3979,9 @@ static struct {
 	[FUSE_LSEEK]	   = { do_lseek,       "LSEEK"	     },
 	[FUSE_SYNCFS]	   = { do_syncfs,      "SYNCFS"      },
 	[FUSE_STATX]	   = { do_statx,       "STATX"	     },
+	[FUSE_FREEZE_FS]   = { do_freezefs,	"FREEZE"     },
+	[FUSE_UNFREEZE_FS] = { do_unfreezefs,	"UNFREEZE"   },
+	[FUSE_SHUTDOWN_FS] = { do_shutdownfs,	"SHUTDOWN"   },
 	[FUSE_IOMAP_CONFIG]= { do_iomap_config, "IOMAP_CONFIG" },
 	[FUSE_IOMAP_BEGIN] = { do_iomap_begin,	"IOMAP_BEGIN" },
 	[FUSE_IOMAP_END]   = { do_iomap_end,	"IOMAP_END" },
@@ -3986,6 +4043,9 @@ static struct {
 	[FUSE_LSEEK]		= { _do_lseek,		"LSEEK" },
 	[FUSE_SYNCFS]		= { _do_syncfs,		"SYNCFS" },
 	[FUSE_STATX]		= { _do_statx,		"STATX" },
+	[FUSE_FREEZE_FS]	= { _do_freezefs,	"FREEZE" },
+	[FUSE_UNFREEZE_FS]	= { _do_unfreezefs,	"UNFREEZE" },
+	[FUSE_SHUTDOWN_FS]	= { _do_shutdownfs,	"SHUTDOWN" },
 	[FUSE_IOMAP_CONFIG]	= { _do_iomap_config,	"IOMAP_CONFIG" },
 	[FUSE_IOMAP_BEGIN]	= { _do_iomap_begin,	"IOMAP_BEGIN" },
 	[FUSE_IOMAP_END]	= { _do_iomap_end,	"IOMAP_END" },


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 25/25] libfuse: add upper-level filesystem freeze, thaw, and shutdown events
  2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
                     ` (23 preceding siblings ...)
  2026-02-23 23:31   ` [PATCH 24/25] libfuse: add lower-level filesystem freeze, thaw, and shutdown requests Darrick J. Wong
@ 2026-02-23 23:31   ` Darrick J. Wong
  24 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:31 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Pass filesystem freeze, thaw, and shutdown requests from the low level
library to the upper level library so that those fuse servers can handle
the events.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h |   15 +++++++++
 lib/fuse.c     |   95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)


diff --git a/include/fuse.h b/include/fuse.h
index db4281e3f330c6..2f73d42672acdd 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -925,6 +925,21 @@ struct fuse_operations {
 	 */
 	int (*iomap_config) (uint64_t supported_flags, off_t maxbytes,
 			     struct fuse_iomap_config *cfg);
+
+	/**
+	 * Freeze the filesystem
+	 */
+	int (*freezefs) (const char *path, uint64_t unlinked_files);
+
+	/**
+	 * Thaw the filesystem
+	 */
+	int (*unfreezefs) (const char *path);
+
+	/**
+	 * Shut down the filesystem
+	 */
+	int (*shutdownfs) (const char *path, uint64_t flags);
 };
 
 /** Extra context that may be needed by some filesystems
diff --git a/lib/fuse.c b/lib/fuse.c
index 022888c475cb3d..2969e0f332045f 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2980,6 +2980,38 @@ static int fuse_fs_iomap_config(struct fuse_fs *fs, uint64_t flags,
 	return fs->op.iomap_config(flags, maxbytes, cfg);
 }
 
+static int fuse_fs_freezefs(struct fuse_fs *fs, const char *path,
+			    uint64_t unlinked)
+{
+	fuse_get_context()->private_data = fs->user_data;
+	if (!fs->op.freezefs)
+		return -ENOSYS;
+	if (fs->debug)
+		fuse_log(FUSE_LOG_DEBUG, "freezefs[%s]\n", path);
+	return fs->op.freezefs(path, unlinked);
+}
+
+static int fuse_fs_unfreezefs(struct fuse_fs *fs, const char *path)
+{
+	fuse_get_context()->private_data = fs->user_data;
+	if (!fs->op.unfreezefs)
+		return -ENOSYS;
+	if (fs->debug)
+		fuse_log(FUSE_LOG_DEBUG, "unfreezefs[%s]\n", path);
+	return fs->op.unfreezefs(path);
+}
+
+static int fuse_fs_shutdownfs(struct fuse_fs *fs, const char *path,
+			      uint64_t flags)
+{
+	fuse_get_context()->private_data = fs->user_data;
+	if (!fs->op.shutdownfs)
+		return -ENOSYS;
+	if (fs->debug)
+		fuse_log(FUSE_LOG_DEBUG, "shutdownfs[%s]\n", path);
+	return fs->op.shutdownfs(path, flags);
+}
+
 static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
 			     int valid, struct fuse_file_info *fi)
 {
@@ -4879,6 +4911,66 @@ static void fuse_lib_iomap_config(fuse_req_t req, uint64_t flags,
 	fuse_reply_iomap_config(req, &cfg);
 }
 
+static void fuse_lib_freezefs(fuse_req_t req, fuse_ino_t ino, uint64_t unlinked)
+{
+	struct fuse *f = req_fuse_prepare(req);
+	struct fuse_intr_data d;
+	char *path;
+	int err;
+
+	err = get_path(f, ino, &path);
+	if (err) {
+		reply_err(req, err);
+		return;
+	}
+
+	fuse_prepare_interrupt(f, req, &d);
+	err = fuse_fs_freezefs(f->fs, path, unlinked);
+	fuse_finish_interrupt(f, req, &d);
+	free_path(f, ino, path);
+	reply_err(req, err);
+}
+
+static void fuse_lib_unfreezefs(fuse_req_t req, fuse_ino_t ino)
+{
+	struct fuse *f = req_fuse_prepare(req);
+	struct fuse_intr_data d;
+	char *path;
+	int err;
+
+	err = get_path(f, ino, &path);
+	if (err) {
+		reply_err(req, err);
+		return;
+	}
+
+	fuse_prepare_interrupt(f, req, &d);
+	err = fuse_fs_unfreezefs(f->fs, path);
+	fuse_finish_interrupt(f, req, &d);
+	free_path(f, ino, path);
+	reply_err(req, err);
+}
+
+static void fuse_lib_shutdownfs(fuse_req_t req, fuse_ino_t ino, uint64_t flags)
+{
+	struct fuse *f = req_fuse_prepare(req);
+	struct fuse_intr_data d;
+	char *path;
+	int err;
+
+	err = get_path(f, ino, &path);
+	if (err) {
+		reply_err(req, err);
+		return;
+	}
+
+	fuse_prepare_interrupt(f, req, &d);
+	err = fuse_fs_shutdownfs(f->fs, path, flags);
+	fuse_finish_interrupt(f, req, &d);
+	free_path(f, ino, path);
+	reply_err(req, err);
+}
+
 static int clean_delay(struct fuse *f)
 {
 	/*
@@ -4981,6 +5073,9 @@ static struct fuse_lowlevel_ops fuse_path_ops = {
 	.statx = fuse_lib_statx,
 #endif
 	.syncfs = fuse_lib_syncfs,
+	.freezefs = fuse_lib_freezefs,
+	.unfreezefs = fuse_lib_unfreezefs,
+	.shutdownfs = fuse_lib_shutdownfs,
 	.iomap_begin = fuse_lib_iomap_begin,
 	.iomap_end = fuse_lib_iomap_end,
 	.iomap_ioend = fuse_lib_iomap_ioend,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/1] libfuse: allow root_nodeid mount option
  2026-02-23 23:03 ` [PATCHSET v7 2/6] libfuse: allow servers to specify root node id Darrick J. Wong
@ 2026-02-23 23:32   ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:32 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Allow this mount option so that fuse servers can configure the root
nodeid if they want to.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/mount.c |    1 +
 1 file changed, 1 insertion(+)


diff --git a/lib/mount.c b/lib/mount.c
index 7a856c101a7fc4..c82fd4c293ce66 100644
--- a/lib/mount.c
+++ b/lib/mount.c
@@ -100,6 +100,7 @@ static const struct fuse_opt fuse_mount_opts[] = {
 	FUSE_OPT_KEY("defcontext=",		KEY_KERN_OPT),
 	FUSE_OPT_KEY("rootcontext=",		KEY_KERN_OPT),
 	FUSE_OPT_KEY("max_read=",		KEY_KERN_OPT),
+	FUSE_OPT_KEY("root_nodeid=",		KEY_KERN_OPT),
 	FUSE_OPT_KEY("user=",			KEY_MTAB_OPT),
 	FUSE_OPT_KEY("-n",			KEY_MTAB_OPT),
 	FUSE_OPT_KEY("-r",			KEY_RO),


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/2] libfuse: add strictatime/lazytime mount options
  2026-02-23 23:03 ` [PATCHSET v7 3/6] libfuse: implement syncfs Darrick J. Wong
@ 2026-02-23 23:32   ` Darrick J. Wong
  2026-02-23 23:32   ` [PATCH 2/2] libfuse: set sync, immutable, and append when loading files Darrick J. Wong
  1 sibling, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:32 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

fuse+iomap leaves the kernel completely in charge of handling
timestamps.  Add the lazytime and strictatime mount options so that
fuse+iomap filesystems can take advantage of those options.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/mount.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)


diff --git a/lib/mount.c b/lib/mount.c
index c82fd4c293ce66..1b20c4eab92d46 100644
--- a/lib/mount.c
+++ b/lib/mount.c
@@ -117,9 +117,16 @@ static const struct fuse_opt fuse_mount_opts[] = {
 	FUSE_OPT_KEY("dirsync",			KEY_KERN_FLAG),
 	FUSE_OPT_KEY("noatime",			KEY_KERN_FLAG),
 	FUSE_OPT_KEY("nodiratime",		KEY_KERN_FLAG),
-	FUSE_OPT_KEY("nostrictatime",		KEY_KERN_FLAG),
 	FUSE_OPT_KEY("symfollow",		KEY_KERN_FLAG),
 	FUSE_OPT_KEY("nosymfollow",		KEY_KERN_FLAG),
+#ifdef MS_LAZYTIME
+	FUSE_OPT_KEY("lazytime",		KEY_KERN_FLAG),
+	FUSE_OPT_KEY("nolazytime",		KEY_KERN_FLAG),
+#endif
+#ifdef MS_STRICTATIME
+	FUSE_OPT_KEY("strictatime",		KEY_KERN_FLAG),
+	FUSE_OPT_KEY("nostrictatime",		KEY_KERN_FLAG),
+#endif
 	FUSE_OPT_END
 };
 
@@ -189,11 +196,18 @@ static const struct mount_flags mount_flags[] = {
 	{"noatime", MS_NOATIME,	    1},
 	{"nodiratime",	    MS_NODIRATIME,	1},
 	{"norelatime",	    MS_RELATIME,	0},
-	{"nostrictatime",   MS_STRICTATIME,	0},
 	{"symfollow",	    MS_NOSYMFOLLOW,	0},
 	{"nosymfollow",	    MS_NOSYMFOLLOW,	1},
 #ifndef __NetBSD__
 	{"dirsync", MS_DIRSYNC,	    1},
+#endif
+#ifdef MS_LAZYTIME
+	{"lazytime",	    MS_LAZYTIME,	1},
+	{"nolazytime",	    MS_LAZYTIME,	0},
+#endif
+#ifdef MS_STRICTATIME
+	{"strictatime",	    MS_STRICTATIME,	1},
+	{"nostrictatime",   MS_STRICTATIME,	0},
 #endif
 	{NULL,	    0,		    0}
 };


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/2] libfuse: set sync, immutable, and append when loading files
  2026-02-23 23:03 ` [PATCHSET v7 3/6] libfuse: implement syncfs Darrick J. Wong
  2026-02-23 23:32   ` [PATCH 1/2] libfuse: add strictatime/lazytime mount options Darrick J. Wong
@ 2026-02-23 23:32   ` Darrick J. Wong
  1 sibling, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:32 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Add these three fuse_attr::flags bits so that servers can mark a file as
immutable or append-only and have the kernel advertise and enforce that.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h |    6 ++++++
 include/fuse_kernel.h |    8 ++++++++
 lib/fuse_lowlevel.c   |    6 ++++++
 3 files changed, 20 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index a8aec81ec123a2..d1bd783cd667c7 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1243,6 +1243,12 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
 #define FUSE_IFLAG_IOMAP		(1U << 2)
 /* enable untorn writes */
 #define FUSE_IFLAG_ATOMIC		(1U << 3)
+/* file writes are synchronous */
+#define FUSE_IFLAG_SYNC			(1U << 4)
+/* file is immutable */
+#define FUSE_IFLAG_IMMUTABLE		(1U << 5)
+/* file is append only */
+#define FUSE_IFLAG_APPEND		(1U << 6)
 
 /* Which fields are set in fuse_iomap_config_out? */
 #define FUSE_IOMAP_CONFIG_SID		(1 << 0ULL)
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index ff21973e1c88f7..bee825a6d17ad5 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -249,6 +249,8 @@
  *  - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry
  *  - add FUSE_NOTIFY_IOMAP_DEV_INVAL to invalidate iomap bdev ranges
  *  - add FUSE_ATTR_ATOMIC for single-fsblock atomic write support
+ *  - add FUSE_ATTR_{SYNC,IMMUTABLE,APPEND} for VFS enforcement of file
+ *    attributes
  */
 
 #ifndef _LINUX_FUSE_H
@@ -593,12 +595,18 @@ struct fuse_file_lock {
  * kernel can use cached attributes more aggressively (e.g. ACL inheritance)
  * FUSE_ATTR_IOMAP: Use iomap for this inode
  * FUSE_ATTR_ATOMIC: Enable untorn writes
+ * FUSE_ATTR_SYNC: File writes are always synchronous
+ * FUSE_ATTR_IMMUTABLE: File is immutable
+ * FUSE_ATTR_APPEND: File is append-only
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 #define FUSE_ATTR_DAX		(1 << 1)
 #define FUSE_ATTR_EXCLUSIVE	(1 << 2)
 #define FUSE_ATTR_IOMAP		(1 << 3)
 #define FUSE_ATTR_ATOMIC	(1 << 4)
+#define FUSE_ATTR_SYNC		(1 << 5)
+#define FUSE_ATTR_IMMUTABLE	(1 << 6)
+#define FUSE_ATTR_APPEND	(1 << 7)
 
 /**
  * Open flags
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 18503a1fa64d88..7b501e2f3ef047 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -170,6 +170,12 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr,
 		attr->flags |= FUSE_ATTR_IOMAP;
 	if (iflags & FUSE_IFLAG_ATOMIC)
 		attr->flags |= FUSE_ATTR_ATOMIC;
+	if (iflags & FUSE_IFLAG_SYNC)
+		attr->flags |= FUSE_ATTR_SYNC;
+	if (iflags & FUSE_IFLAG_IMMUTABLE)
+		attr->flags |= FUSE_ATTR_IMMUTABLE;
+	if (iflags & FUSE_IFLAG_APPEND)
+		attr->flags |= FUSE_ATTR_APPEND;
 }
 
 static void convert_attr(const struct fuse_setattr_in *attr, struct stat *stbuf)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/5] libfuse: enable iomap cache management for lowlevel fuse
  2026-02-23 23:03 ` [PATCHSET v7 4/6] libfuse: cache iomap mappings for even better file IO performance Darrick J. Wong
@ 2026-02-23 23:32   ` Darrick J. Wong
  2026-02-23 23:33   ` [PATCH 2/5] libfuse: add upper-level iomap cache management Darrick J. Wong
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:32 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Add the library methods so that fuse servers can manage an in-kernel
iomap cache.  This enables better performance on small IOs and is
required if the filesystem needs synchronization between pagecache
writes and writeback.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h   |   12 +++++++
 include/fuse_kernel.h   |   27 ++++++++++++++++
 include/fuse_lowlevel.h |   41 +++++++++++++++++++++++++
 lib/fuse_lowlevel.c     |   77 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/fuse_versionscript  |    2 +
 5 files changed, 159 insertions(+)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index d1bd783cd667c7..313f78c9cb6632 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1158,6 +1158,10 @@ int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn);
 
 /* fuse-specific mapping type indicating that writes use the read mapping */
 #define FUSE_IOMAP_TYPE_PURE_OVERWRITE	(255)
+/* fuse-specific mapping type saying the server has populated the cache */
+#define FUSE_IOMAP_TYPE_RETRY_CACHE	(254)
+/* do not upsert this mapping */
+#define FUSE_IOMAP_TYPE_NOCACHE		(253)
 
 #define FUSE_IOMAP_DEV_NULL		(0U)	/* null device cookie */
 
@@ -1281,6 +1285,14 @@ struct fuse_iomap_config{
 	int64_t s_maxbytes;	/* max file size */
 };
 
+/* invalidate to end of file */
+#define FUSE_IOMAP_INVAL_TO_EOF		(~0ULL)
+
+struct fuse_file_range {
+	uint64_t offset;	/* file offset to invalidate, bytes */
+	uint64_t length;	/* length to invalidate, bytes */
+};
+
 /* ----------------------------------------------------------- *
  * Compatibility stuff					       *
  * ----------------------------------------------------------- */
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index bee825a6d17ad5..f2a1e187aea3a1 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -251,6 +251,8 @@
  *  - add FUSE_ATTR_ATOMIC for single-fsblock atomic write support
  *  - add FUSE_ATTR_{SYNC,IMMUTABLE,APPEND} for VFS enforcement of file
  *    attributes
+ *  - add FUSE_NOTIFY_IOMAP_{UPSERT,INVAL}_MAPPINGS so fuse servers can cache
+ *    file range mappings in the kernel for iomap
  */
 
 #ifndef _LINUX_FUSE_H
@@ -718,6 +720,8 @@ enum fuse_notify_code {
 	FUSE_NOTIFY_INC_EPOCH = 8,
 	FUSE_NOTIFY_PRUNE = 9,
 	FUSE_NOTIFY_IOMAP_DEV_INVAL = 99,
+	FUSE_NOTIFY_IOMAP_UPSERT_MAPPINGS = 100,
+	FUSE_NOTIFY_IOMAP_INVAL_MAPPINGS = 101,
 };
 
 /* The read buffer is required to be at least 8k, but may be much larger */
@@ -1460,4 +1464,27 @@ struct fuse_iomap_dev_inval_out {
 	struct fuse_range range;
 };
 
+struct fuse_iomap_inval_mappings_out {
+	uint64_t nodeid;	/* Inode ID */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+
+	/*
+	 * Range of read and mappings to invalidate.  Zero length means ignore
+	 * the range; and FUSE_IOMAP_INVAL_TO_EOF can be used for length.
+	 */
+	struct fuse_range read;
+	struct fuse_range write;
+};
+
+struct fuse_iomap_upsert_mappings_out {
+	uint64_t nodeid;	/* Inode ID */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+
+	/* read file data from here */
+	struct fuse_iomap_io	read;
+
+	/* write file data to here, if applicable */
+	struct fuse_iomap_io	write;
+};
+
 #endif /* _LINUX_FUSE_H */
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index 0d7577718490ba..67fdde0a5f49d9 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -2258,6 +2258,47 @@ int fuse_lowlevel_iomap_device_remove(struct fuse_session *se, int device_id);
 int fuse_lowlevel_iomap_device_invalidate(struct fuse_session *se, int dev,
 					  off_t offset, off_t length);
 
+/*
+ * Upsert some file mapping information into the kernel.  This is necessary
+ * for filesystems that require coordination of mapping state changes between
+ * buffered writes and writeback, and desirable for better performance
+ * elsewhere.
+ *
+ * Added in FUSE protocol version 7.99. If the kernel does not support
+ * this (or a newer) version, the function will return -ENOSYS and do
+ * nothing.
+ *
+ * @param se the session object
+ * @param nodeid the inode number
+ * @param attr_ino inode number as told by fuse_attr::ino
+ * @param read mapping information for file reads
+ * @param write mapping information for file writes
+ * @return zero for success, -errno for failure
+ */
+int fuse_lowlevel_iomap_upsert_mappings(struct fuse_session *se,
+					fuse_ino_t nodeid, uint64_t attr_ino,
+					const struct fuse_file_iomap *read,
+					const struct fuse_file_iomap *write);
+
+/**
+ * Invalidate some file mapping information in the kernel.
+ *
+ * Added in FUSE protocol version 7.99. If the kernel does not support
+ * this (or a newer) version, the function will return -ENOSYS and do
+ * nothing.
+ *
+ * @param se the session object
+ * @param nodeid the inode number
+ * @param attr_ino inode number as told by fuse_attr::ino
+ * @param read read mapping range to invalidate
+ * @param write write mapping range to invalidate
+ * @return zero for success, -errno for failure
+ */
+int fuse_lowlevel_iomap_inval_mappings(struct fuse_session *se,
+				       fuse_ino_t nodeid, uint64_t attr_ino,
+				       const struct fuse_file_range *read,
+				       const struct fuse_file_range *write);
+
 /* ----------------------------------------------------------- *
  * Utility functions					       *
  * ----------------------------------------------------------- */
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 7b501e2f3ef047..ea6aba18619458 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -3768,6 +3768,83 @@ int fuse_lowlevel_iomap_device_invalidate(struct fuse_session *se, int dev,
 	return send_notify_iov(se, FUSE_NOTIFY_IOMAP_DEV_INVAL, iov, 2);
 }
 
+int fuse_lowlevel_iomap_upsert_mappings(struct fuse_session *se,
+					fuse_ino_t nodeid, uint64_t attr_ino,
+					const struct fuse_file_iomap *read,
+					const struct fuse_file_iomap *write)
+{
+	struct fuse_iomap_upsert_mappings_out outarg = {
+		.nodeid		= nodeid,
+		.attr_ino	= attr_ino,
+		.read		= {
+			.type	= FUSE_IOMAP_TYPE_NOCACHE,
+		},
+		.write		= {
+			.type	= FUSE_IOMAP_TYPE_NOCACHE,
+		}
+	};
+	struct iovec iov[2];
+
+	if (!se)
+		return -EINVAL;
+
+	if (se->conn.proto_minor < 99)
+		return -ENOSYS;
+
+	if (!read && !write)
+		return 0;
+
+	if (read)
+		fuse_iomap_to_kernel(&outarg.read, read);
+
+	if (write)
+		fuse_iomap_to_kernel(&outarg.write, write);
+
+	iov[1].iov_base = &outarg;
+	iov[1].iov_len = sizeof(outarg);
+
+	return send_notify_iov(se, FUSE_NOTIFY_IOMAP_UPSERT_MAPPINGS, iov, 2);
+}
+
+static inline void
+fuse_iomap_range_to_kernel(struct fuse_range *range,
+			   const struct fuse_file_range *firange)
+{
+	range->offset = firange->offset;
+	range->length = firange->length;
+}
+
+int fuse_lowlevel_iomap_inval_mappings(struct fuse_session *se,
+				       fuse_ino_t nodeid, uint64_t attr_ino,
+				       const struct fuse_file_range *read,
+				       const struct fuse_file_range *write)
+{
+	struct fuse_iomap_inval_mappings_out outarg = {
+		.nodeid		= nodeid,
+		.attr_ino	= attr_ino,
+	};
+	struct iovec iov[2];
+
+	if (!se)
+		return -EINVAL;
+
+	if (se->conn.proto_minor < 99)
+		return -ENOSYS;
+
+	if (!read && !write)
+		return 0;
+
+	if (read)
+		fuse_iomap_range_to_kernel(&outarg.read, read);
+	if (write)
+		fuse_iomap_range_to_kernel(&outarg.write, write);
+
+	iov[1].iov_base = &outarg;
+	iov[1].iov_len = sizeof(outarg);
+
+	return send_notify_iov(se, FUSE_NOTIFY_IOMAP_INVAL_MAPPINGS, iov, 2);
+}
+
 struct fuse_retrieve_req {
 	struct fuse_notify_req nreq;
 	void *cookie;
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index f459d06c2f3377..ed388f8ebdb558 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -250,6 +250,8 @@ FUSE_3.99 {
 		fuse_fs_iomap_device_invalidate;
 		fuse_lowlevel_disable_fsreclaim;
 		fuse_loopdev_setup;
+		fuse_lowlevel_iomap_upsert_mappings;
+		fuse_lowlevel_iomap_inval_mappings;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/5] libfuse: add upper-level iomap cache management
  2026-02-23 23:03 ` [PATCHSET v7 4/6] libfuse: cache iomap mappings for even better file IO performance Darrick J. Wong
  2026-02-23 23:32   ` [PATCH 1/5] libfuse: enable iomap cache management for lowlevel fuse Darrick J. Wong
@ 2026-02-23 23:33   ` Darrick J. Wong
  2026-02-23 23:33   ` [PATCH 3/5] libfuse: allow constraining of iomap mapping cache size Darrick J. Wong
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:33 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Make it so that upper-level fuse servers can use the iomap cache too.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h         |   31 +++++++++++++++++++++++++++++++
 lib/fuse.c             |   30 ++++++++++++++++++++++++++++++
 lib/fuse_versionscript |    2 ++
 3 files changed, 63 insertions(+)


diff --git a/include/fuse.h b/include/fuse.h
index 2f73d42672acdd..e54aa1368bbb6b 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -1488,6 +1488,37 @@ bool fuse_fs_can_enable_iomap(const struct stat *statbuf);
  */
 bool fuse_fs_can_enable_iomapx(const struct statx *statxbuf);
 
+/*
+ * Upsert some file mapping information into the kernel.  This is necessary
+ * for filesystems that require coordination of mapping state changes between
+ * buffered writes and writeback, and desirable for better performance
+ * elsewhere.
+ *
+ * @param nodeid the inode number
+ * @param attr_ino inode number as told by fuse_attr::ino
+ * @param read mapping information for file reads
+ * @param write mapping information for file writes
+ * @return zero for success, -errno for failure
+ */
+int fuse_fs_iomap_upsert(uint64_t nodeid, uint64_t attr_ino,
+			 const struct fuse_file_iomap *read,
+			 const struct fuse_file_iomap *write);
+
+/**
+ * Invalidate some file mapping information in the kernel.
+ *
+ * @param nodeid the inode number
+ * @param attr_ino inode number as told by fuse_attr::ino
+ * @param read_off start of the range of read mappings to invalidate
+ * @param read_len length of the range of read mappings to invalidate
+ * @param write_off start of the range of write mappings to invalidate
+ * @param write_len length of the range of write mappings to invalidate
+ * @return zero for success, -errno for failure
+ */
+int fuse_fs_iomap_inval(uint64_t nodeid, uint64_t attr_ino, loff_t read_off,
+			uint64_t read_len, loff_t write_off,
+			uint64_t write_len);
+
 int fuse_notify_poll(struct fuse_pollhandle *ph);
 
 /**
diff --git a/lib/fuse.c b/lib/fuse.c
index 2969e0f332045f..0fb1bc106514a1 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -3012,6 +3012,36 @@ static int fuse_fs_shutdownfs(struct fuse_fs *fs, const char *path,
 	return fs->op.shutdownfs(path, flags);
 }
 
+int fuse_fs_iomap_upsert(uint64_t nodeid, uint64_t attr_ino,
+			 const struct fuse_file_iomap *read,
+			 const struct fuse_file_iomap *write)
+{
+	struct fuse_context *ctxt = fuse_get_context();
+	struct fuse_session *se = fuse_get_session(ctxt->fuse);
+
+	return fuse_lowlevel_iomap_upsert_mappings(se, nodeid, attr_ino, read,
+						   write);
+}
+
+int fuse_fs_iomap_inval(uint64_t nodeid, uint64_t attr_ino,
+			loff_t read_off, uint64_t read_len,
+			loff_t write_off, uint64_t write_len)
+{
+	struct fuse_context *ctxt = fuse_get_context();
+	struct fuse_session *se = fuse_get_session(ctxt->fuse);
+	struct fuse_file_range read = {
+		.offset = read_off,
+		.length = read_len,
+	};
+	struct fuse_file_range write = {
+		.offset = write_off,
+		.length = write_len,
+	};
+
+	return fuse_lowlevel_iomap_inval_mappings(se, nodeid, attr_ino, &read,
+						  &write);
+}
+
 static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
 			     int valid, struct fuse_file_info *fi)
 {
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index ed388f8ebdb558..60d5e1be50deaa 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -252,6 +252,8 @@ FUSE_3.99 {
 		fuse_loopdev_setup;
 		fuse_lowlevel_iomap_upsert_mappings;
 		fuse_lowlevel_iomap_inval_mappings;
+		fuse_fs_iomap_upsert;
+		fuse_fs_iomap_inval;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/5] libfuse: allow constraining of iomap mapping cache size
  2026-02-23 23:03 ` [PATCHSET v7 4/6] libfuse: cache iomap mappings for even better file IO performance Darrick J. Wong
  2026-02-23 23:32   ` [PATCH 1/5] libfuse: enable iomap cache management for lowlevel fuse Darrick J. Wong
  2026-02-23 23:33   ` [PATCH 2/5] libfuse: add upper-level iomap cache management Darrick J. Wong
@ 2026-02-23 23:33   ` Darrick J. Wong
  2026-02-23 23:33   ` [PATCH 4/5] libfuse: add upper-level iomap mapping cache constraint code Darrick J. Wong
  2026-02-23 23:33   ` [PATCH 5/5] libfuse: enable iomap Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:33 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Allow the fuse server to constrain the maximum size of each iomap
mapping cache.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_common.h   |    3 +++
 include/fuse_kernel.h   |    6 +++++-
 include/fuse_lowlevel.h |    3 ++-
 lib/fuse.c              |    2 +-
 lib/fuse_lowlevel.c     |   11 ++++++++---
 5 files changed, 19 insertions(+), 6 deletions(-)


diff --git a/include/fuse_common.h b/include/fuse_common.h
index 313f78c9cb6632..18c2e0e11ce8ce 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1261,6 +1261,7 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
 #define FUSE_IOMAP_CONFIG_MAX_LINKS	(1 << 3ULL)
 #define FUSE_IOMAP_CONFIG_TIME		(1 << 4ULL)
 #define FUSE_IOMAP_CONFIG_MAXBYTES	(1 << 5ULL)
+#define FUSE_IOMAP_CONFIG_CACHE_MAXBYTES (1 << 6ULL)
 
 struct fuse_iomap_config{
 	uint64_t flags;		/* FUSE_IOMAP_CONFIG_* */
@@ -1283,6 +1284,8 @@ struct fuse_iomap_config{
 	int64_t s_time_max;
 
 	int64_t s_maxbytes;	/* max file size */
+
+	uint32_t cache_maxbytes; /* mapping cache maximum size */
 };
 
 /* invalidate to end of file */
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index f2a1e187aea3a1..8149657ac44cb9 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -1425,7 +1425,9 @@ struct fuse_iomap_ioend_out {
 struct fuse_iomap_config_in {
 	uint64_t flags;		/* supported FUSE_IOMAP_CONFIG_* flags */
 	int64_t maxbytes;	/* max supported file size */
-	uint64_t padding[6];	/* zero */
+	uint32_t cache_maxbytes; /* mapping cache maxbytes */
+	uint32_t zero;		/* zero */
+	uint64_t padding[5];	/* zero */
 };
 
 struct fuse_iomap_config_out {
@@ -1449,6 +1451,8 @@ struct fuse_iomap_config_out {
 	int64_t s_time_max;
 
 	int64_t s_maxbytes;	/* max file size */
+
+	uint32_t cache_maxbytes; /* mapping cache maximum size */
 };
 
 struct fuse_range {
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index 67fdde0a5f49d9..77fc623386ce20 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -1436,9 +1436,10 @@ struct fuse_lowlevel_ops {
 	 * @param req request handle
 	 * @param flags FUSE_IOMAP_CONFIG_* flags that can be passed back
 	 * @param maxbytes maximum supported file size
+	 * @param cache_maxbytes maximum allowed iomap cache size
 	 */
 	void (*iomap_config) (fuse_req_t req, uint64_t flags,
-			      uint64_t maxbytes);
+			      uint64_t maxbytes, uint32_t cache_maxbytes);
 
 	/**
 	 * Freeze the filesystem
diff --git a/lib/fuse.c b/lib/fuse.c
index 0fb1bc106514a1..04836044e7a25b 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -4923,7 +4923,7 @@ static void fuse_lib_iomap_ioend(fuse_req_t req, fuse_ino_t nodeid,
 }
 
 static void fuse_lib_iomap_config(fuse_req_t req, uint64_t flags,
-				  uint64_t maxbytes)
+				  uint64_t maxbytes, uint32_t cache_maxbytes)
 {
 	struct fuse_iomap_config cfg = { };
 	struct fuse *f = req_fuse_prepare(req);
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index ea6aba18619458..b2bf2e5345cc71 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -2852,7 +2852,8 @@ static void do_iomap_ioend(fuse_req_t req, const fuse_ino_t nodeid,
 			      FUSE_IOMAP_CONFIG_BLOCKSIZE | \
 			      FUSE_IOMAP_CONFIG_MAX_LINKS | \
 			      FUSE_IOMAP_CONFIG_TIME | \
-			      FUSE_IOMAP_CONFIG_MAXBYTES)
+			      FUSE_IOMAP_CONFIG_MAXBYTES | \
+			      FUSE_IOMAP_CONFIG_CACHE_MAXBYTES)
 
 #define FUSE_IOMAP_CONFIG_ALL (FUSE_IOMAP_CONFIG_V1)
 
@@ -2861,7 +2862,7 @@ static ssize_t iomap_config_reply_size(const struct fuse_iomap_config *cfg)
 	if (cfg->flags & ~FUSE_IOMAP_CONFIG_ALL)
 		return -EINVAL;
 
-	return offsetofend(struct fuse_iomap_config_out, s_maxbytes);
+	return offsetofend(struct fuse_iomap_config_out, cache_maxbytes);
 }
 
 int fuse_reply_iomap_config(fuse_req_t req, const struct fuse_iomap_config *cfg)
@@ -2899,6 +2900,9 @@ int fuse_reply_iomap_config(fuse_req_t req, const struct fuse_iomap_config *cfg)
 	if (cfg->flags & FUSE_IOMAP_CONFIG_MAXBYTES)
 		arg.s_maxbytes = cfg->s_maxbytes;
 
+	if (cfg->flags & FUSE_IOMAP_CONFIG_CACHE_MAXBYTES)
+		arg.cache_maxbytes = cfg->cache_maxbytes;
+
 	return send_reply_ok(req, &arg, reply_size);
 }
 
@@ -2912,7 +2916,8 @@ static void _do_iomap_config(fuse_req_t req, const fuse_ino_t nodeid,
 	if (req->se->op.iomap_config)
 		req->se->op.iomap_config(req,
 					 arg->flags & FUSE_IOMAP_CONFIG_ALL,
-					 arg->maxbytes);
+					 arg->maxbytes,
+					 arg->cache_maxbytes);
 	else
 		fuse_reply_err(req, ENOSYS);
 }


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 4/5] libfuse: add upper-level iomap mapping cache constraint code
  2026-02-23 23:03 ` [PATCHSET v7 4/6] libfuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:33   ` [PATCH 3/5] libfuse: allow constraining of iomap mapping cache size Darrick J. Wong
@ 2026-02-23 23:33   ` Darrick J. Wong
  2026-02-23 23:33   ` [PATCH 5/5] libfuse: enable iomap Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:33 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Allow high-level fuse servers to constrain the maximum size of each
iomap mapping cache.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse.h |    1 +
 lib/fuse.c     |   12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)


diff --git a/include/fuse.h b/include/fuse.h
index e54aa1368bbb6b..bdc910ad1c2381 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -924,6 +924,7 @@ struct fuse_operations {
 	 * files.
 	 */
 	int (*iomap_config) (uint64_t supported_flags, off_t maxbytes,
+			     uint32_t cache_maxbytes,
 			     struct fuse_iomap_config *cfg);
 
 	/**
diff --git a/lib/fuse.c b/lib/fuse.c
index 04836044e7a25b..15372b23a7aef4 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2964,7 +2964,7 @@ static int fuse_fs_iomap_ioend(struct fuse_fs *fs, const char *path,
 }
 
 static int fuse_fs_iomap_config(struct fuse_fs *fs, uint64_t flags,
-				uint64_t maxbytes,
+				uint64_t maxbytes, uint32_t cache_maxbytes,
 				struct fuse_iomap_config *cfg)
 {
 	fuse_get_context()->private_data = fs->user_data;
@@ -2973,11 +2973,12 @@ static int fuse_fs_iomap_config(struct fuse_fs *fs, uint64_t flags,
 
 	if (fs->debug) {
 		fuse_log(FUSE_LOG_DEBUG,
-			 "iomap_config flags 0x%llx maxbytes %lld\n",
-			 (unsigned long long)flags, (long long)maxbytes);
+			 "iomap_config flags 0x%llx maxbytes %lld cache_maxbytes %u\n",
+			 (unsigned long long)flags, (long long)maxbytes,
+			 cache_maxbytes);
 	}
 
-	return fs->op.iomap_config(flags, maxbytes, cfg);
+	return fs->op.iomap_config(flags, maxbytes, cache_maxbytes, cfg);
 }
 
 static int fuse_fs_freezefs(struct fuse_fs *fs, const char *path,
@@ -4931,7 +4932,8 @@ static void fuse_lib_iomap_config(fuse_req_t req, uint64_t flags,
 	int err;
 
 	fuse_prepare_interrupt(f, req, &d);
-	err = fuse_fs_iomap_config(f->fs, flags, maxbytes, &cfg);
+	err = fuse_fs_iomap_config(f->fs, flags, maxbytes, cache_maxbytes,
+				   &cfg);
 	fuse_finish_interrupt(f, req, &d);
 	if (err) {
 		reply_err(req, err);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 5/5] libfuse: enable iomap
  2026-02-23 23:03 ` [PATCHSET v7 4/6] libfuse: cache iomap mappings for even better file IO performance Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:33   ` [PATCH 4/5] libfuse: add upper-level iomap mapping cache constraint code Darrick J. Wong
@ 2026-02-23 23:33   ` Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:33 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Remove the guard that we used to avoid bisection problems.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/fuse_lowlevel.c |    2 --
 1 file changed, 2 deletions(-)


diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index b2bf2e5345cc71..714c26385c044f 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -3181,8 +3181,6 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in,
 			se->conn.capable_ext |= FUSE_CAP_OVER_IO_URING;
 		if (inargflags & FUSE_IOMAP)
 			se->conn.capable_ext |= FUSE_CAP_IOMAP;
-		/* Don't let anyone touch iomap until the end of the patchset. */
-		se->conn.capable_ext &= ~FUSE_CAP_IOMAP;
 	} else {
 		se->conn.max_readahead = 0;
 	}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/5] libfuse: add systemd/inetd socket service mounting helper
  2026-02-23 23:03 ` [PATCHSET v7 5/6] libfuse: run fuse servers as a contained service Darrick J. Wong
@ 2026-02-23 23:34   ` Darrick J. Wong
  2026-02-23 23:34   ` [PATCH 2/5] libfuse: integrate fuse services into mount.fuse3 Darrick J. Wong
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:34 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Create a mount.service helper that can start a fuse server that runs
as a socket-based systemd (or inetd) service.  To make things simpler
for fuse server authors, define a new library interface to wrap all the
functionality so that they don't have to know the details

This enables untrusted ext4 mounts via systemd service containers, which
avoids the problem of malicious filesystems compromising the integrity
of the running kernel through memory corruption.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_service.h      |  153 +++++++
 include/fuse_service_priv.h |  116 +++++
 lib/fuse_i.h                |    5 
 util/mount_service.h        |   32 +
 doc/fuservicemount3.8       |   24 +
 doc/meson.build             |    3 
 include/meson.build         |    4 
 lib/fuse_service.c          |  796 +++++++++++++++++++++++++++++++++++
 lib/fuse_service_stub.c     |   91 ++++
 lib/fuse_versionscript      |   12 +
 lib/helper.c                |   53 ++
 lib/meson.build             |   14 +
 lib/mount.c                 |   57 ++
 meson.build                 |   36 ++
 meson_options.txt           |    6 
 util/fuservicemount.c       |   18 +
 util/meson.build            |    9 
 util/mount_service.c        |  984 +++++++++++++++++++++++++++++++++++++++++++
 18 files changed, 2399 insertions(+), 14 deletions(-)
 create mode 100644 include/fuse_service.h
 create mode 100644 include/fuse_service_priv.h
 create mode 100644 util/mount_service.h
 create mode 100644 doc/fuservicemount3.8
 create mode 100644 lib/fuse_service.c
 create mode 100644 lib/fuse_service_stub.c
 create mode 100644 util/fuservicemount.c
 create mode 100644 util/mount_service.c


diff --git a/include/fuse_service.h b/include/fuse_service.h
new file mode 100644
index 00000000000000..d3a3a4a4237380
--- /dev/null
+++ b/include/fuse_service.h
@@ -0,0 +1,153 @@
+/*  FUSE: Filesystem in Userspace
+  Copyright (C) 2025-2026 Oracle.
+  Author: Darrick J. Wong <djwong@kernel.org>
+
+  This program can be distributed under the terms of the GNU LGPLv2.
+  See the file LGPL2.txt.
+*/
+#ifndef FUSE_SERVICE_H_
+#define FUSE_SERVICE_H_
+
+struct fuse_service;
+
+/**
+ * Accept a socket created by mount.service for information exchange.
+ *
+ * @param sfp pointer to pointer to a service context
+ * @return -1 on error, 0 on success
+ */
+int fuse_service_accept(struct fuse_service **sfp);
+
+/**
+ * Has the fuse server accepted a service context?
+ *
+ * @param sf service context
+ */
+static inline bool fuse_service_accepted(struct fuse_service *sf)
+{
+	return sf != NULL;
+}
+
+/**
+ * Release all resources associated with the service context.
+ *
+ * @param sfp service context
+ */
+void fuse_service_release(struct fuse_service *sf);
+
+/**
+ * Destroy a service context and release all resources
+ *
+ * @param sfp pointer to pointer to a service context
+ */
+void fuse_service_destroy(struct fuse_service **sfp);
+
+/**
+ * Append the command line arguments from the mount service helper to an
+ * existing fuse_args structure.  The fuse_args should have been initialized
+ * with the argc and argv passed to main().
+ *
+ * @param sfp service context
+ * @param args arguments to modify (input+output)
+ * @return -1 on success, 0 on success
+ */
+int fuse_service_append_args(struct fuse_service *sf, struct fuse_args *args);
+
+/**
+ * Generate the effective fuse server command line from the args structure.
+ * The args structure should be the outcome from fuse_service_append_args.
+ * The resulting string is suitable for setproctitle and must be freed by the
+ * callre.
+ *
+ * @param argc argument count passed to main()
+ * @param argv argument vector passed to main()
+ * @param args fuse args structure
+ * @return effective command line string, or NULL
+ */
+char *fuse_service_cmdline(int argc, char *argv[], struct fuse_args *args);
+
+/**
+ * Take the fuse device fd passed from the mount.service helper
+ *
+ * @return device fd on success, -1 on error
+ */
+int fuse_service_take_fusedev(struct fuse_service *sfp);
+
+/**
+ * Utility function to parse common options for simple file systems
+ * using the low-level API. A help text that describes the available
+ * options can be printed with `fuse_cmdline_help`. A single
+ * non-option argument is treated as the mountpoint. Multiple
+ * non-option arguments will result in an error.
+ *
+ * If neither -o subtype= or -o fsname= options are given, a new
+ * subtype option will be added and set to the basename of the program
+ * (the fsname will remain unset, and then defaults to "fuse").
+ *
+ * Known options will be removed from *args*, unknown options will
+ * remain. The mountpoint will not be checked here; that is the job of
+ * mount.service.
+ *
+ * @param args argument vector (input+output)
+ * @param opts output argument for parsed options
+ * @return 0 on success, -1 on failure
+ */
+int fuse_service_parse_cmdline_opts(struct fuse_args *args,
+				    struct fuse_cmdline_opts *opts);
+
+/**
+ * Ask the mount.service helper to open a file on behalf of the fuse server.
+ *
+ * @param sf service context
+ * @param path path to file
+ * @param open_flags O_ flags
+ * @param create_mode mode with which to create the file
+ * @param request_flags set of FUSE_SERVICE_REQUEST_* flags
+ * @return 0 on success, -1 on failure
+ */
+int fuse_service_request_file(struct fuse_service *sf, const char *path,
+			      int open_flags, mode_t create_mode,
+			      unsigned int request_flags);
+
+/**
+ * Receive a file perviously requested.
+ *
+ * @param sf service context
+ * @param path to file
+ * @fdp pointer to file descriptor, which will be set to -1 if the file could
+ *      not be opened
+ * @return -1 on socket communication failure, 0 otherwise
+ */
+int fuse_service_receive_file(struct fuse_service *sf,
+			      const char *path, int *fdp);
+
+/**
+ * Prevent the mount.service server from sending us any more open files.
+ *
+ * @param sf service context
+ */
+int fuse_service_finish_file_requests(struct fuse_service *sf);
+
+/**
+ * Ask the mount.service helper to mount the filesystem for us.  The fuse client
+ * will begin sending requests to the fuse server immediately after this.
+ *
+ * @param sf service context
+ * @param se fuse session
+ * @param mountpoint place to mount the filesystem
+ * @return 0 on success, -1 on error
+ */
+int fuse_service_mount(struct fuse_service *sf, struct fuse_session *se,
+		       const char *mountpoint);
+
+/**
+ * Bid farewell to the mount.service helper.  It is still necessary to call
+ * fuse_service_destroy after this.
+ *
+ * @param sf service context
+ * @param error any additional errors to send to the mount helper
+ * @return 0 on success, -1 on error
+ */
+int fuse_service_send_goodbye(struct fuse_service *sf, int error);
+
+#endif /* FUSE_SERVICE_H_ */
diff --git a/include/fuse_service_priv.h b/include/fuse_service_priv.h
new file mode 100644
index 00000000000000..4df323097c2470
--- /dev/null
+++ b/include/fuse_service_priv.h
@@ -0,0 +1,116 @@
+/*  FUSE: Filesystem in Userspace
+  Copyright (C) 2025-2026 Oracle.
+  Author: Darrick J. Wong <djwong@kernel.org>
+
+  This program can be distributed under the terms of the GNU LGPLv2.
+  See the file LGPL2.txt.
+*/
+#ifndef FUSE_SERVICE_PRIV_H_
+#define FUSE_SERVICE_PRIV_H_
+
+struct fuse_service_memfd_arg {
+	__be32 pos;
+	__be32 len;
+};
+
+struct fuse_service_memfd_argv {
+	__be32 magic;
+	__be32 argc;
+};
+
+#define FUSE_SERVICE_ARGS_MAGIC		0x41524753	/* ARGS */
+
+/* mount.service sends a hello to the server and it replies */
+#define FUSE_SERVICE_HELLO_CMD		0x53414654	/* SAFT */
+#define FUSE_SERVICE_HELLO_REPLY	0x4c415354	/* LAST */
+
+/* fuse servers send commands to mount.service */
+#define FUSE_SERVICE_OPEN_CMD		0x4f50454e	/* OPEN */
+#define FUSE_SERVICE_FSOPEN_CMD		0x54595045	/* TYPE */
+#define FUSE_SERVICE_SOURCE_CMD		0x4e414d45	/* NAME */
+#define FUSE_SERVICE_MNTOPTS_CMD	0x4f505453	/* OPTS */
+#define FUSE_SERVICE_MNTPT_CMD		0x4d4e5450	/* MNTP */
+#define FUSE_SERVICE_MOUNT_CMD		0x444f4954	/* DOIT */
+#define FUSE_SERVICE_BYE_CMD		0x42594545	/* BYEE */
+
+/* mount.service sends replies to the fuse server */
+#define FUSE_SERVICE_OPEN_REPLY		0x46494c45	/* FILE */
+#define FUSE_SERVICE_SIMPLE_REPLY	0x5245504c	/* REPL */
+
+struct fuse_service_packet {
+	__be32 magic;			/* FUSE_SERVICE_*_{CMD,REPLY} */
+};
+
+#define FUSE_SERVICE_PROTO	(1)
+#define FUSE_SERVICE_MIN_PROTO	(1)
+#define FUSE_SERVICE_MAX_PROTO	(1)
+
+struct fuse_service_hello {
+	struct fuse_service_packet p;
+	__be16 min_version;
+	__be16 max_version;
+};
+
+struct fuse_service_hello_reply {
+	struct fuse_service_packet p;
+	__be16 version;
+};
+
+struct fuse_service_simple_reply {
+	struct fuse_service_packet p;
+	__be32 error;
+};
+
+struct fuse_service_requested_file {
+	struct fuse_service_packet p;
+	__be32 error;			/* positive errno */
+	char path[];
+};
+
+static inline size_t sizeof_fuse_service_requested_file(size_t pathlen)
+{
+	return sizeof(struct fuse_service_requested_file) + pathlen + 1;
+}
+
+#define FUSE_SERVICE_OPEN_FLAGS		(0)
+
+struct fuse_service_open_command {
+	struct fuse_service_packet p;
+	__be32 open_flags;
+	__be32 create_mode;
+	__be32 request_flags;
+	char path[];
+};
+
+static inline size_t sizeof_fuse_service_open_command(size_t pathlen)
+{
+	return sizeof(struct fuse_service_open_command) + pathlen + 1;
+}
+
+struct fuse_service_string_command {
+	struct fuse_service_packet p;
+	char value[];
+};
+
+static inline size_t sizeof_fuse_service_string_command(size_t len)
+{
+	return sizeof(struct fuse_service_string_command) + len + 1;
+}
+
+struct fuse_service_bye_command {
+	struct fuse_service_packet p;
+	__be32 error;
+};
+
+struct fuse_service_mount_command {
+	struct fuse_service_packet p;
+	__be32 flags;
+};
+
+int fuse_parse_cmdline_service(struct fuse_args *args,
+				 struct fuse_cmdline_opts *opts);
+
+#define FUSE_SERVICE_ARGV	"argv"
+#define FUSE_SERVICE_FUSEDEV	"fusedev"
+
+#endif /* FUSE_SERVICE_PRIV_H_ */
diff --git a/lib/fuse_i.h b/lib/fuse_i.h
index c7d0d38408105f..4eade95f10f4e8 100644
--- a/lib/fuse_i.h
+++ b/lib/fuse_i.h
@@ -226,6 +226,11 @@ unsigned get_max_read(struct mount_opts *o);
 void fuse_kern_unmount(const char *mountpoint, int fd);
 int fuse_kern_mount(const char *mountpoint, struct mount_opts *mo);
 
+char *fuse_mountopts_fstype(const struct mount_opts *mo);
+char *fuse_mountopts_source(const struct mount_opts *mo, const char *devname);
+char *fuse_mountopts_kernel_opts(const struct mount_opts *mo);
+unsigned int fuse_mountopts_flags(const struct mount_opts *mo);
+
 int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
 			       int count);
 void fuse_free_req(fuse_req_t req);
diff --git a/util/mount_service.h b/util/mount_service.h
new file mode 100644
index 00000000000000..16e120da10765e
--- /dev/null
+++ b/util/mount_service.h
@@ -0,0 +1,32 @@
+/*
+  FUSE: Filesystem in Userspace
+  Copyright (C) 2025-2026 Oracle.
+  Author: Darrick J. Wong <djwong@kernel.org>
+
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file GPL2.txt.
+*/
+#ifndef MOUNT_SERVICE_H_
+#define MOUNT_SERVICE_H_
+
+/**
+ * Connect to a fuse service socket and try to mount the filesystem as
+ * specified with the CLI arguments.
+ *
+ * @argc argument count
+ * @argv vector of argument strings
+ * @return EXIT_SUCCESS for success, EXIT_FAILURE if mount fails
+ */
+int mount_service_main(int argc, char *argv[]);
+
+/**
+ * Return the fuse filesystem subtype from a full fuse filesystem type
+ * specification.  IOWs, fuse.Y -> Y; fuseblk.Z -> Z; or A -> A.  The returned
+ * pointer is within the caller's string.
+ *
+ * @param fstype full fuse filesystem type
+ * @return fuse subtype
+ */
+const char *mount_service_subtype(const char *fstype);
+
+#endif /* MOUNT_SERVICE_H_ */
diff --git a/doc/fuservicemount3.8 b/doc/fuservicemount3.8
new file mode 100644
index 00000000000000..e45d6a89c8b81a
--- /dev/null
+++ b/doc/fuservicemount3.8
@@ -0,0 +1,24 @@
+.TH fuservicemount3 "8"
+.SH NAME
+fuservicemount3 \- mount a FUSE filesystem that runs as a system socket service
+.SH SYNOPSIS
+.B fuservicemount3
+.B source
+.B mountpoint
+.BI -t " fstype"
+[
+.I options
+]
+.SH DESCRIPTION
+Mount a filesystem using a FUSE server that runs as a socket service.
+These servers can be contained using the platform's service management
+framework.
+.SH "AUTHORS"
+.LP
+The author of the fuse socket service code is Darrick J. Wong <djwong@kernel.org>.
+Debian GNU/Linux distribution.
+.SH SEE ALSO
+.BR fusermount3 (1)
+.BR fusermount (1)
+.BR mount (8)
+.BR fuse (4)
diff --git a/doc/meson.build b/doc/meson.build
index db3e0b26f71975..c105cf3471fdf4 100644
--- a/doc/meson.build
+++ b/doc/meson.build
@@ -2,3 +2,6 @@ if not platform.endswith('bsd') and platform != 'dragonfly'
   install_man('fusermount3.1', 'mount.fuse3.8')
 endif
 
+if private_cfg.get('HAVE_SERVICEMOUNT', false)
+  install_man('fuservicemount3.8')
+endif
diff --git a/include/meson.build b/include/meson.build
index 0b1e3a9d4fcb43..5ab4ecf052bf56 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -5,4 +5,8 @@ if private_cfg.get('FUSE_LOOPDEV_ENABLED')
   libfuse_headers += [ 'fuse_loopdev.h' ]
 endif
 
+if private_cfg.get('HAVE_SERVICEMOUNT', false)
+  libfuse_headers += [ 'fuse_service.h' ]
+endif
+
 install_headers(libfuse_headers, subdir: 'fuse3')
diff --git a/lib/fuse_service.c b/lib/fuse_service.c
new file mode 100644
index 00000000000000..40763143946c83
--- /dev/null
+++ b/lib/fuse_service.c
@@ -0,0 +1,796 @@
+/*
+  FUSE: Filesystem in Userspace
+  Copyright (C) 2025-2026 Oracle.
+  Author: Darrick J. Wong <djwong@kernel.org>
+
+  Library functions to support fuse servers that can be run as "safe" systemd
+  containers.
+
+  This program can be distributed under the terms of the GNU LGPLv2.
+  See the file LGPL2.txt
+*/
+
+#define _GNU_SOURCE
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <systemd/sd-daemon.h>
+#include <arpa/inet.h>
+
+#include "fuse_config.h"
+#include "fuse_i.h"
+#include "fuse_service_priv.h"
+#include "fuse_service.h"
+
+struct fuse_service {
+	/* socket fd */
+	int sockfd;
+
+	/* /dev/fuse device */
+	int fusedevfd;
+
+	/* memfd for cli arguments */
+	int argvfd;
+};
+
+static int __recv_fd(int sockfd, struct fuse_service_requested_file *buf,
+		     ssize_t bufsize, int *fdp)
+{
+	struct iovec iov = {
+		.iov_base = buf,
+		.iov_len = bufsize,
+	};
+	union {
+		struct cmsghdr cmsghdr;
+		char control[CMSG_SPACE(sizeof (int))];
+	} cmsgu;
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+		.msg_control = cmsgu.control,
+		.msg_controllen = sizeof(cmsgu.control),
+	};
+	struct cmsghdr *cmsg;
+	ssize_t size;
+
+	memset(&cmsgu, 0, sizeof(cmsgu));
+
+	size = recvmsg(sockfd, &msg, MSG_TRUNC);
+	if (size < 0) {
+		perror("fuse: service file reply");
+		return -1;
+	}
+	if (size > bufsize ||
+	    size < offsetof(struct fuse_service_requested_file, path)) {
+		fprintf(stderr,
+ "fuse: wrong service file reply size %zd, expected %zd\n",
+			size, bufsize);
+		return -1;
+	}
+
+	cmsg = CMSG_FIRSTHDR(&msg);
+	if (!cmsg) {
+		/* no control message means mount.service sent us an error */
+		return 0;
+	}
+	if (cmsg->cmsg_len != CMSG_LEN(sizeof(int))) {
+		fprintf(stderr,
+ "fuse: wrong service file reply control data size %zd, expected %zd\n",
+			cmsg->cmsg_len, CMSG_LEN(sizeof(int)));
+		return -1;
+	}
+	if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
+		fprintf(stderr,
+ "fuse: wrong service file reply control data level %d type %d, expected %d and %d\n",
+			cmsg->cmsg_level, cmsg->cmsg_type, SOL_SOCKET,
+			SCM_RIGHTS);
+		return -1;
+	}
+
+	memcpy(fdp, (int *)CMSG_DATA(cmsg), sizeof(int));
+	return 0;
+}
+
+static int recv_requested_file(int sockfd, const char *path, int *fdp)
+{
+	struct fuse_service_requested_file *req;
+	const size_t req_sz = sizeof_fuse_service_requested_file(strlen(path));
+	int ret;
+
+	*fdp = -1;
+	req = calloc(1, req_sz + 1);
+	if (!req) {
+		perror("fuse: alloc service file reply");
+		return -1;
+	}
+
+	ret = __recv_fd(sockfd, req, req_sz, fdp);
+	if (ret)
+		goto out_req;
+
+	if (req->p.magic != ntohl(FUSE_SERVICE_OPEN_REPLY)) {
+		fprintf(stderr,
+ "fuse: service file reply contains wrong magic!\n");
+		ret = -1;
+		goto out_close;
+	}
+	if (strcmp(req->path, path)) {
+		fprintf(stderr,
+ "fuse: `%s': not the requested service file, got `%s'\n",
+			path, req->path);
+		ret = -1;
+		goto out_close;
+	}
+
+	if (req->error) {
+		errno = ntohl(req->error);
+		ret = 0;
+		goto out_req;
+	}
+
+	free(req);
+	return 0;
+
+out_close:
+	close(*fdp);
+	*fdp = -1;
+out_req:
+	free(req);
+	return ret;
+}
+
+int fuse_service_receive_file(struct fuse_service *sf, const char *path,
+			      int *fdp)
+{
+	return recv_requested_file(sf->sockfd, path, fdp);
+}
+
+#define FUSE_SERVICE_REQUEST_FILE_FLAGS	(0)
+
+int fuse_service_request_file(struct fuse_service *sf, const char *path,
+			      int open_flags, mode_t create_mode,
+			      unsigned int request_flags)
+{
+	struct iovec iov = {
+		.iov_len = sizeof_fuse_service_open_command(strlen(path)),
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+	struct fuse_service_open_command *cmd;
+	ssize_t size;
+	unsigned int rqflags = 0;
+	int ret;
+
+	if (request_flags & ~FUSE_SERVICE_REQUEST_FILE_FLAGS) {
+		fprintf(stderr,
+ "fuse: invalid fuse service file request flags 0x%x\n", request_flags);
+		errno = EINVAL;
+		return -1;
+	}
+
+	cmd = calloc(1, iov.iov_len);
+	if (!cmd) {
+		perror("fuse: alloc service file request");
+		return -1;
+	}
+	cmd->p.magic = htonl(FUSE_SERVICE_OPEN_CMD);
+	cmd->open_flags = htonl(open_flags);
+	cmd->create_mode = htonl(create_mode);
+	cmd->request_flags = htonl(rqflags);
+	strcpy(cmd->path, path);
+	iov.iov_base = cmd;
+
+	size = sendmsg(sf->sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+	if (size < 0) {
+		perror("fuse: request service file");
+		ret = -1;
+		goto out_free;
+	}
+
+	ret = 0;
+out_free:
+	free(cmd);
+	return ret;
+}
+
+int fuse_service_send_goodbye(struct fuse_service *sf, int error)
+{
+	struct fuse_service_bye_command c = {
+		.p.magic = htonl(FUSE_SERVICE_BYE_CMD),
+		.error = htonl(error),
+	};
+	struct iovec iov = {
+		.iov_base = &c,
+		.iov_len = sizeof(c),
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+	ssize_t size;
+
+	/* already gone? */
+	if (sf->sockfd < 0)
+		return 0;
+
+	size = sendmsg(sf->sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+	if (size < 0) {
+		perror("fuse: send service goodbye");
+		return -1;
+	}
+
+	shutdown(sf->sockfd, SHUT_RDWR);
+	close(sf->sockfd);
+	sf->sockfd = -1;
+	return 0;
+}
+
+static int find_socket_fd(void)
+{
+	struct stat statbuf;
+	char *listen_fds;
+	int nr_fds;
+	int ret;
+
+	listen_fds = getenv("LISTEN_FDS");
+	if (!listen_fds)
+		return -2;
+
+	nr_fds = atoi(listen_fds);
+	if (nr_fds != 1) {
+		fprintf(stderr,
+ "fuse: can only handle 1 service socket, got %d.\n",
+			nr_fds);
+		return -1;
+	}
+
+	ret = fstat(SD_LISTEN_FDS_START, &statbuf);
+	if (ret) {
+		perror("fuse: service socket");
+		return -1;
+	}
+
+	if (!S_ISSOCK(statbuf.st_mode)) {
+		fprintf(stderr,
+ "fuse: expected service fd %d to be a socket\n",
+				SD_LISTEN_FDS_START);
+		return -1;
+	}
+
+	return SD_LISTEN_FDS_START;
+}
+
+static int negotiate_hello(int sockfd)
+{
+	struct fuse_service_hello hello = { };
+	struct fuse_service_hello_reply reply = {
+		.p.magic = htonl(FUSE_SERVICE_HELLO_REPLY),
+		.version = htons(FUSE_SERVICE_PROTO),
+	};
+	struct iovec iov = {
+		.iov_base = &hello,
+		.iov_len = sizeof(hello),
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+	ssize_t size;
+
+	size = recvmsg(sockfd, &msg, MSG_TRUNC);
+	if (size < 0) {
+		perror("fuse: receive service hello");
+		return -1;
+	}
+	if (size != sizeof(hello)) {
+		fprintf(stderr,
+ "fuse: wrong service hello size %zd, expected %zd\n",
+			size, sizeof(hello));
+		return -1;
+	}
+
+	if (hello.p.magic != ntohl(FUSE_SERVICE_HELLO_CMD)) {
+		fprintf(stderr,
+ "fuse: service server did not send hello command\n");
+		return -1;
+	}
+
+	if (ntohs(hello.min_version) < FUSE_SERVICE_MIN_PROTO) {
+		fprintf(stderr,
+ "fuse: unsupported min service protocol version %u\n",
+			ntohs(hello.min_version));
+		return -1;
+	}
+
+	if (ntohs(hello.max_version) > FUSE_SERVICE_MAX_PROTO) {
+		fprintf(stderr,
+ "fuse: unsupported max service protocol version %u\n",
+			ntohs(hello.min_version));
+		return -1;
+	}
+
+	iov.iov_base = &reply;
+	iov.iov_len = sizeof(reply);
+
+	size = sendmsg(sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+	if (size < 0) {
+		perror("fuse: service hello reply");
+		return -1;
+	}
+
+	return 0;
+}
+
+int fuse_service_accept(struct fuse_service **sfp)
+{
+	struct fuse_service *sf;
+	int ret = 0;
+
+	*sfp = NULL;
+
+	sf = calloc(1, sizeof(struct fuse_service));
+	if (!sf) {
+		perror("fuse: service alloc");
+		return -1;
+	}
+
+	/* Find the socket that connects us to mount.service */
+	sf->sockfd = find_socket_fd();
+	if (sf->sockfd == -2) {
+		/* magic code that means no service configured */
+		ret = 0;
+		goto out_sf;
+	}
+	if (sf->sockfd < 0) {
+		ret = -1;
+		goto out_sf;
+	}
+
+	ret = negotiate_hello(sf->sockfd);
+	if (ret)
+		goto out_sf;
+
+	/* Receive the two critical sockets */
+	ret = recv_requested_file(sf->sockfd, FUSE_SERVICE_ARGV, &sf->argvfd);
+	if (ret < 0)
+		goto out_sockfd;
+	if (sf->argvfd < 0) {
+		perror("fuse: service mount options file");
+		goto out_sockfd;
+	}
+
+	ret = recv_requested_file(sf->sockfd, FUSE_SERVICE_FUSEDEV,
+				  &sf->fusedevfd);
+	if (ret < 0)
+		goto out_argvfd;
+	if (sf->fusedevfd < 0) {
+		perror("fuse: service fuse device");
+		goto out_argvfd;
+	}
+
+	*sfp = sf;
+	return 0;
+
+out_argvfd:
+	close(sf->argvfd);
+out_sockfd:
+	shutdown(sf->sockfd, SHUT_RDWR);
+	close(sf->sockfd);
+out_sf:
+	free(sf);
+	return ret;
+}
+
+int fuse_service_append_args(struct fuse_service *sf,
+			     struct fuse_args *existing_args)
+{
+	struct fuse_service_memfd_argv memfd_args = { };
+	struct fuse_args new_args = {
+		.allocated = 1,
+	};
+	char *str = NULL;
+	off_t memfd_pos = 0;
+	ssize_t received;
+	unsigned int i;
+	int ret;
+
+	/* Figure out how many arguments we're getting from the mount helper. */
+	received = pread(sf->argvfd, &memfd_args, sizeof(memfd_args), 0);
+	if (received < 0) {
+		perror("fuse: service args file");
+		return -1;
+	}
+	if (received < sizeof(memfd_args)) {
+		fprintf(stderr,
+ "fuse: service args file length unreadable\n");
+		return -1;
+	}
+	if (ntohl(memfd_args.magic) != FUSE_SERVICE_ARGS_MAGIC) {
+		fprintf(stderr, "fuse: service args file corrupt\n");
+		return -1;
+	}
+	memfd_args.magic = ntohl(memfd_args.magic);
+	memfd_args.argc = ntohl(memfd_args.argc);
+	memfd_pos += sizeof(memfd_args);
+
+	/* Allocate a new array of argv string pointers */
+	new_args.argv = calloc(memfd_args.argc + existing_args->argc,
+			       sizeof(char *));
+	if (!new_args.argv) {
+		perror("fuse: service new args");
+		return -1;
+	}
+
+	/*
+	 * Copy the fuse server's CLI arguments.  We'll leave new_args.argv[0]
+	 * unset for now, because we'll set it in the next step with the fstype
+	 * that the mount helper sent us.
+	 */
+	new_args.argc++;
+	for (i = 1; i < existing_args->argc; i++) {
+		if (existing_args->allocated) {
+			new_args.argv[new_args.argc] = existing_args->argv[i];
+			existing_args->argv[i] = NULL;
+		} else {
+			new_args.argv[new_args.argc] =
+						strdup(existing_args->argv[i]);
+			if (!new_args.argv[new_args.argc]) {
+				perror("fuse: service duplicate existing args");
+				ret = -1;
+				goto out_new_args;
+			}
+		}
+
+		new_args.argc++;
+	}
+
+	/* Copy the rest of the arguments from the helper */
+	for (i = 0; i < memfd_args.argc; i++) {
+		struct fuse_service_memfd_arg memfd_arg = { };
+
+		/* Read argv iovec */
+		received = pread(sf->argvfd, &memfd_arg, sizeof(memfd_arg),
+				 memfd_pos);
+		if (received < 0) {
+			perror("fuse: service args file iovec read");
+			ret = -1;
+			goto out_new_args;
+		}
+		if (received < sizeof(struct fuse_service_memfd_arg)) {
+			fprintf(stderr,
+ "fuse: service args file argv[%u] iovec short read %zd",
+				i, received);
+			ret = -1;
+			goto out_new_args;
+		}
+		memfd_arg.pos = ntohl(memfd_arg.pos);
+		memfd_arg.len = ntohl(memfd_arg.len);
+		memfd_pos += sizeof(memfd_arg);
+
+		/* read arg string from file */
+		str = calloc(1, memfd_arg.len + 1);
+		if (!str) {
+			perror("fuse: service arg alloc");
+			ret = -1;
+			goto out_new_args;
+		}
+
+		received = pread(sf->argvfd, str, memfd_arg.len, memfd_arg.pos);
+		if (received < 0) {
+			perror("fuse: service args file read");
+			ret = -1;
+			goto out_str;
+		}
+		if (received < memfd_arg.len) {
+			fprintf(stderr,
+ "fuse: service args file argv[%u] short read %zd",
+				i, received);
+			ret = -1;
+			goto out_str;
+		}
+
+		/* move string into the args structure */
+		if (i == 0) {
+			/* the first argument is the fs type */
+			new_args.argv[0] = str;
+		} else {
+			new_args.argv[new_args.argc] = str;
+			new_args.argc++;
+		}
+		str = NULL;
+	}
+
+	/* drop existing args, move new args to existing args */
+	fuse_opt_free_args(existing_args);
+	memcpy(existing_args, &new_args, sizeof(*existing_args));
+
+	close(sf->argvfd);
+	sf->argvfd = -1;
+
+	return 0;
+
+out_str:
+	free(str);
+out_new_args:
+	fuse_opt_free_args(&new_args);
+	return ret;
+}
+
+int fuse_service_take_fusedev(struct fuse_service *sfp)
+{
+	int ret = sfp->fusedevfd;
+
+	sfp->fusedevfd = -1;
+	return ret;
+}
+
+int fuse_service_finish_file_requests(struct fuse_service *sf)
+{
+#ifdef SO_PASSRIGHTS
+	int zero = 0;
+
+	/* don't let a malicious mount helper send us more fds */
+	return setsockopt(sf->sockfd, SOL_SOCKET, SO_PASSRIGHTS, &zero,
+			  sizeof(zero));
+#else
+	/* shut up gcc */
+	sf = sf;
+	return 0;
+#endif
+}
+
+static int send_string(struct fuse_service *sf, uint32_t command,
+		       const char *value, int *error)
+{
+	struct fuse_service_simple_reply reply = { };
+	struct iovec iov = {
+		.iov_len = sizeof_fuse_service_string_command(strlen(value)),
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+	struct fuse_service_string_command *cmd;
+	ssize_t size;
+
+	cmd = malloc(iov.iov_len);
+	if (!cmd) {
+		perror("fuse: alloc service string send");
+		return -1;
+	}
+	cmd->p.magic = ntohl(command);
+	strcpy(cmd->value, value);
+	iov.iov_base = cmd;
+
+	size = sendmsg(sf->sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+	if (size < 0) {
+		perror("fuse: send service string");
+		return -1;
+	}
+	free(cmd);
+
+	iov.iov_base = &reply;
+	iov.iov_len = sizeof(reply);
+	size = recvmsg(sf->sockfd, &msg, MSG_TRUNC);
+	if (size < 0) {
+		perror("fuse: service string reply");
+		return -1;
+	}
+	if (size != sizeof(reply)) {
+		fprintf(stderr,
+ "fuse: wrong service string reply size %zd, expected %zd\n",
+			size, sizeof(reply));
+		return -1;
+	}
+
+	if (ntohl(reply.p.magic) != FUSE_SERVICE_SIMPLE_REPLY) {
+		fprintf(stderr,
+ "fuse: service string reply contains wrong magic!\n");
+		return -1;
+	}
+
+	*error = ntohl(reply.error);
+	return 0;
+}
+
+static int send_mount(struct fuse_service *sf, unsigned int flags, int *error)
+{
+	struct fuse_service_simple_reply reply = { };
+	struct fuse_service_mount_command c = {
+		.p.magic = htonl(FUSE_SERVICE_MOUNT_CMD),
+		.flags = htonl(flags),
+	};
+	struct iovec iov = {
+		.iov_base = &c,
+		.iov_len = sizeof(c),
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+	ssize_t size;
+
+	size = sendmsg(sf->sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+	if (size < 0) {
+		perror("fuse: send service mount command");
+		return -1;
+	}
+
+	iov.iov_base = &reply;
+	iov.iov_len = sizeof(reply);
+	size = recvmsg(sf->sockfd, &msg, MSG_TRUNC);
+	if (size < 0) {
+		perror("fuse: service mount reply");
+		return -1;
+	}
+	if (size != sizeof(reply)) {
+		fprintf(stderr,
+ "fuse: wrong service mount reply size %zd, expected %zd\n",
+			size, sizeof(reply));
+		return -1;
+	}
+
+	if (ntohl(reply.p.magic) != FUSE_SERVICE_SIMPLE_REPLY) {
+		fprintf(stderr,
+ "fuse: service mount reply contains wrong magic!\n");
+		return -1;
+	}
+
+	*error = ntohl(reply.error);
+	return 0;
+}
+
+int fuse_service_mount(struct fuse_service *sf, struct fuse_session *se,
+		       const char *mountpoint)
+{
+	char *fstype = fuse_mountopts_fstype(se->mo);
+	char *source = fuse_mountopts_source(se->mo, "???");
+	char *mntopts = fuse_mountopts_kernel_opts(se->mo);
+	int ret;
+	int error;
+
+	if (!fstype || !source) {
+		fprintf(stderr, "fuse: cannot allocate service strings\n");
+		ret = -1;
+		goto out_strings;
+	}
+
+	ret = send_string(sf, FUSE_SERVICE_FSOPEN_CMD, fstype, &error);
+	if (ret)
+		goto out_strings;
+	if (error) {
+		fprintf(stderr, "fuse: service fsopen: %s\n",
+			strerror(error));
+		ret = -1;
+		goto out_strings;
+	}
+
+	ret = send_string(sf, FUSE_SERVICE_SOURCE_CMD, source, &error);
+	if (ret)
+		goto out_strings;
+	if (error) {
+		fprintf(stderr, "fuse: service fs source: %s\n",
+			strerror(error));
+		ret = -1;
+		goto out_strings;
+	}
+
+	ret = send_string(sf, FUSE_SERVICE_MNTPT_CMD, mountpoint, &error);
+	if (ret)
+		goto out_strings;
+	if (error) {
+		fprintf(stderr, "fuse: service fs mountpoint: %s\n",
+			strerror(error));
+		ret = -1;
+		goto out_strings;
+	}
+
+	if (mntopts) {
+		ret = send_string(sf, FUSE_SERVICE_MNTOPTS_CMD, mntopts,
+				  &error);
+		if (ret)
+			goto out_strings;
+		if (error) {
+			fprintf(stderr,
+ "fuse: service fs mount options: %s\n",
+				strerror(error));
+			ret = -1;
+			goto out_strings;
+		}
+	}
+
+	ret = send_mount(sf, fuse_mountopts_flags(se->mo), &error);
+	if (ret)
+		goto out_strings;
+	if (error) {
+		fprintf(stderr, "fuse: service mount: %s\n", strerror(error));
+		ret = -1;
+		goto out_strings;
+	}
+
+out_strings:
+	free(mntopts);
+	free(source);
+	free(fstype);
+	return ret;
+}
+
+void fuse_service_release(struct fuse_service *sf)
+{
+	close(sf->fusedevfd);
+	sf->fusedevfd = -1;
+	close(sf->argvfd);
+	sf->argvfd = -1;
+	shutdown(sf->sockfd, SHUT_RDWR);
+	close(sf->sockfd);
+	sf->sockfd = -1;
+}
+
+void fuse_service_destroy(struct fuse_service **sfp)
+{
+	struct fuse_service *sf = *sfp;
+
+	if (sf) {
+		fuse_service_release(*sfp);
+		free(sf);
+	}
+
+	*sfp = NULL;
+}
+
+char *fuse_service_cmdline(int argc, char *argv[], struct fuse_args *args)
+{
+	char *p, *dst;
+	size_t len = 1;
+	ssize_t ret;
+	char *argv0;
+	unsigned int i;
+
+	/* Try to preserve argv[0] */
+	if (argc > 0)
+		argv0 = argv[0];
+	else if (args->argc > 0)
+		argv0 = args->argv[0];
+	else
+		return NULL;
+
+	/* Pick up the alleged fstype from args->argv[0] */
+	if (args->argc == 0)
+		return NULL;
+
+	len += strlen(argv0) + 1;
+	len += 3; /* " -t" */
+	for (i = 0; i < args->argc; i++) {
+		len += strlen(args->argv[i]) + 1;
+	}
+
+	p = malloc(len);
+	if (!p)
+		return NULL;
+	dst = p;
+
+	/* Format: argv0 -t alleged_fstype [all other options...] */
+	ret = sprintf(dst, "%s -t", argv0);
+	dst += ret;
+	for (i = 0; i < args->argc; i++) {
+		ret = sprintf(dst, " %s", args->argv[i]);
+		dst += ret;
+	}
+
+	return p;
+}
+
+int fuse_service_parse_cmdline_opts(struct fuse_args *args,
+				    struct fuse_cmdline_opts *opts)
+{
+	return fuse_parse_cmdline_service(args, opts);
+}
diff --git a/lib/fuse_service_stub.c b/lib/fuse_service_stub.c
new file mode 100644
index 00000000000000..79abeca9dfb70e
--- /dev/null
+++ b/lib/fuse_service_stub.c
@@ -0,0 +1,91 @@
+/*
+  FUSE: Filesystem in Userspace
+  Copyright (C) 2025-2026 Oracle.
+  Author: Darrick J. Wong <djwong@kernel.org>
+
+  Stub functions for platforms where we cannot have fuse servers run as "safe"
+  systemd containers.
+
+  This program can be distributed under the terms of the GNU LGPLv2.
+  See the file LGPL2.txt
+*/
+
+/* shut up gcc */
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+
+#define _GNU_SOURCE
+#include <errno.h>
+
+#include "fuse_config.h"
+#include "fuse_i.h"
+#include "fuse_service_priv.h"
+#include "fuse_service.h"
+
+int fuse_service_receive_file(struct fuse_service *sf, const char *path,
+			      int *fdp)
+{
+	errno = EOPNOTSUPP;
+	return -1;
+}
+
+int fuse_service_request_file(struct fuse_service *sf, const char *path,
+			      int open_flags, mode_t create_mode,
+			      unsigned int request_flags)
+{
+	errno = EOPNOTSUPP;
+	return -1;
+}
+
+int fuse_service_send_goodbye(struct fuse_service *sf, int error)
+{
+	errno = EOPNOTSUPP;
+	return -1;
+}
+
+int fuse_service_accept(struct fuse_service **sfp)
+{
+	*sfp = NULL;
+	errno = EOPNOTSUPP;
+	return -1;
+}
+
+int fuse_service_append_args(struct fuse_service *sf,
+			     struct fuse_args *existing_args)
+{
+	errno = EOPNOTSUPP;
+	return -1;
+}
+
+int fuse_service_take_fusedev(struct fuse_service *sfp)
+{
+	return -1;
+}
+
+int fuse_service_finish_file_requests(struct fuse_service *sf)
+{
+	errno = EOPNOTSUPP;
+	return -1;
+}
+
+int fuse_service_mount(struct fuse_service *sf, struct fuse_session *se,
+		       const char *mountpoint)
+{
+	errno = EOPNOTSUPP;
+	return -1;
+}
+
+void fuse_service_release(struct fuse_service *sf)
+{
+}
+
+void fuse_service_destroy(struct fuse_service **sfp)
+{
+	*sfp = NULL;
+}
+
+int fuse_service_parse_cmdline_opts(struct fuse_args *args,
+				    struct fuse_cmdline_opts *opts)
+{
+	errno = EOPNOTSUPP;
+	return -1;
+}
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 60d5e1be50deaa..935eaec820c7a7 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -254,6 +254,18 @@ FUSE_3.99 {
 		fuse_lowlevel_iomap_inval_mappings;
 		fuse_fs_iomap_upsert;
 		fuse_fs_iomap_inval;
+		fuse_service_accept;
+		fuse_service_append_args;
+		fuse_service_destroy;
+		fuse_service_finish_file_requests;
+		fuse_service_mount;
+		fuse_service_cmdline;
+		fuse_service_parse_cmdline_opts;
+		fuse_service_receive_file;
+		fuse_service_release;
+		fuse_service_request_file;
+		fuse_service_send_goodbye;
+		fuse_service_take_fusedev;
 } FUSE_3.19;
 
 # Local Variables:
diff --git a/lib/helper.c b/lib/helper.c
index 5c13b93a473181..3b57788621d902 100644
--- a/lib/helper.c
+++ b/lib/helper.c
@@ -26,6 +26,11 @@
 #include <errno.h>
 #include <sys/param.h>
 
+#ifdef HAVE_SERVICEMOUNT
+# include <linux/types.h>
+# include "fuse_service_priv.h"
+#endif
+
 #define FUSE_HELPER_OPT(t, p) \
 	{ t, offsetof(struct fuse_cmdline_opts, p), 1 }
 
@@ -174,6 +179,29 @@ static int fuse_helper_opt_proc(void *data, const char *arg, int key,
 	}
 }
 
+#ifdef HAVE_SERVICEMOUNT
+static int fuse_helper_opt_proc_service(void *data, const char *arg, int key,
+					struct fuse_args *outargs)
+{
+	(void) outargs;
+	struct fuse_cmdline_opts *opts = data;
+
+	switch (key) {
+	case FUSE_OPT_KEY_NONOPT:
+		if (!opts->mountpoint) {
+			return fuse_opt_add_opt(&opts->mountpoint, arg);
+		} else {
+			fuse_log(FUSE_LOG_ERR, "fuse: invalid argument `%s'\n", arg);
+			return -1;
+		}
+
+	default:
+		/* Pass through unknown options */
+		return 1;
+	}
+}
+#endif
+
 /* Under FreeBSD, there is no subtype option so this
    function actually sets the fsname */
 static int add_default_subtype(const char *progname, struct fuse_args *args)
@@ -228,6 +256,31 @@ int fuse_parse_cmdline_312(struct fuse_args *args,
 	return 0;
 }
 
+#ifdef HAVE_SERVICEMOUNT
+int fuse_parse_cmdline_service(struct fuse_args *args,
+			       struct fuse_cmdline_opts *opts)
+{
+	memset(opts, 0, sizeof(struct fuse_cmdline_opts));
+
+	opts->max_idle_threads = UINT_MAX; /* new default in fuse version 3.12 */
+	opts->max_threads = 10;
+
+	if (fuse_opt_parse(args, opts, fuse_helper_opts,
+			   fuse_helper_opt_proc_service) == -1)
+		return -1;
+
+	/* *Linux*: if neither -o subtype nor -o fsname are specified,
+	   set subtype to program's basename.
+	   *FreeBSD*: if fsname is not specified, set to program's
+	   basename. */
+	if (!opts->nodefault_subtype)
+		if (add_default_subtype(args->argv[0], args) == -1)
+			return -1;
+
+	return 0;
+}
+#endif
+
 /**
  * struct fuse_cmdline_opts got extended in libfuse-3.12
  */
diff --git a/lib/meson.build b/lib/meson.build
index 477b0fc2f86d38..4fe11e346c46d3 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -11,6 +11,12 @@ else
    libfuse_sources += [ 'mount_bsd.c' ]
 endif
 
+if private_cfg.get('HAVE_SERVICEMOUNT', false)
+  libfuse_sources += [ 'fuse_service.c' ]
+else
+  libfuse_sources += [ 'fuse_service_stub.c' ]
+endif
+
 deps = [ thread_dep ]
 if private_cfg.get('HAVE_ICONV')
    libfuse_sources += [ 'modules/iconv.c' ]
@@ -55,13 +61,19 @@ libfuse = library('fuse3',
                   link_args: ['-Wl,--version-script,' + meson.current_source_dir()
                               + '/fuse_versionscript' ])
 
+vars = []
+if private_cfg.get('HAVE_SERVICEMOUNT', false)
+  service_socket_dir = private_cfg.get_unquoted('FUSE_SERVICE_SOCKET_DIR', '')
+  vars += ['service_socket_dir=' + service_socket_dir]
+endif
 pkg = import('pkgconfig')
 pkg.generate(libraries: [ libfuse, '-lpthread' ],
              libraries_private: '-ldl',
              version: meson.project_version(),
              name: 'fuse3',
              description: 'Filesystem in Userspace',
-             subdirs: 'fuse3')
+             subdirs: 'fuse3',
+             variables: vars)
 
 libfuse_dep = declare_dependency(include_directories: include_dirs,
                                  link_with: libfuse, dependencies: deps)
diff --git a/lib/mount.c b/lib/mount.c
index 1b20c4eab92d46..4ad9baf963599e 100644
--- a/lib/mount.c
+++ b/lib/mount.c
@@ -561,24 +561,13 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
 	if (res == -1)
 		goto out_close;
 
-	source = malloc((mo->fsname ? strlen(mo->fsname) : 0) +
-			(mo->subtype ? strlen(mo->subtype) : 0) +
-			strlen(devname) + 32);
-
-	type = malloc((mo->subtype ? strlen(mo->subtype) : 0) + 32);
+	type = fuse_mountopts_fstype(mo);
+	source = fuse_mountopts_source(mo, devname);
 	if (!type || !source) {
 		fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate memory\n");
 		goto out_close;
 	}
 
-	strcpy(type, mo->blkdev ? "fuseblk" : "fuse");
-	if (mo->subtype) {
-		strcat(type, ".");
-		strcat(type, mo->subtype);
-	}
-	strcpy(source,
-	       mo->fsname ? mo->fsname : (mo->subtype ? mo->subtype : devname));
-
 	res = mount(source, mnt, type, mo->flags, mo->kernel_opts);
 	if (res == -1 && errno == ENODEV && mo->subtype) {
 		/* Probably missing subtype support */
@@ -689,6 +678,48 @@ void destroy_mount_opts(struct mount_opts *mo)
 	free(mo);
 }
 
+char *fuse_mountopts_fstype(const struct mount_opts *mo)
+{
+	char *type = malloc((mo->subtype ? strlen(mo->subtype) : 0) + 32);
+
+	if (!type)
+		return NULL;
+
+	strcpy(type, mo->blkdev ? "fuseblk" : "fuse");
+	if (mo->subtype) {
+		strcat(type, ".");
+		strcat(type, mo->subtype);
+	}
+
+	return type;
+}
+
+char *fuse_mountopts_source(const struct mount_opts *mo, const char *devname)
+{
+	char *source = malloc((mo->fsname ? strlen(mo->fsname) : 0) +
+			(mo->subtype ? strlen(mo->subtype) : 0) +
+			strlen(devname) + 32);
+
+	if (!source)
+		return NULL;
+
+	strcpy(source,
+	       mo->fsname ? mo->fsname : (mo->subtype ? mo->subtype : devname));
+
+	return source;
+}
+
+char *fuse_mountopts_kernel_opts(const struct mount_opts *mo)
+{
+	if (mo->kernel_opts)
+		return strdup(mo->kernel_opts);
+	return NULL;
+}
+
+unsigned int fuse_mountopts_flags(const struct mount_opts *mo)
+{
+	return mo->flags;
+}
 
 int fuse_kern_mount(const char *mountpoint, struct mount_opts *mo)
 {
diff --git a/meson.build b/meson.build
index 73aee98c775a2a..360912f1773662 100644
--- a/meson.build
+++ b/meson.build
@@ -69,6 +69,11 @@ args_default = [ '-D_GNU_SOURCE' ]
 #
 private_cfg = configuration_data()
 private_cfg.set_quoted('PACKAGE_VERSION', meson.project_version())
+service_socket_dir = get_option('service-socket-dir')
+if service_socket_dir == ''
+  service_socket_dir = '/run/filesystems'
+endif
+private_cfg.set_quoted('FUSE_SERVICE_SOCKET_DIR', service_socket_dir)
 
 # Test for presence of some functions
 test_funcs = [ 'fork', 'fstatat', 'openat', 'readlinkat', 'pipe2',
@@ -191,6 +196,37 @@ if get_option('enable-io-uring') and liburing.found() and libnuma.found()
    endif
 endif
 
+# Check for systemd support
+systemd_system_unit_dir = get_option('systemdsystemunitdir')
+if systemd_system_unit_dir == ''
+  systemd = dependency('systemd', required: false)
+  if systemd.found()
+     systemd_system_unit_dir = systemd.get_variable(pkgconfig: 'systemd_system_unit_dir')
+  endif
+endif
+
+if systemd_system_unit_dir == ''
+  warning('could not determine systemdsystemunitdir, systemd stuff will not be installed')
+else
+  private_cfg.set_quoted('SYSTEMD_SYSTEM_UNIT_DIR', systemd_system_unit_dir)
+  private_cfg.set('HAVE_SYSTEMD', true)
+endif
+
+# Check for libc SCM_RIGHTS support (aka Linux)
+code = '''
+#include <sys/socket.h>
+int main(void) {
+    int moo = SCM_RIGHTS;
+    return moo;
+}'''
+if cc.links(code, name: 'libc SCM_RIGHTS support')
+  private_cfg.set('HAVE_SCM_RIGHTS', true)
+endif
+
+if private_cfg.get('HAVE_SCM_RIGHTS', false) and private_cfg.get('HAVE_SYSTEMD', false)
+  private_cfg.set('HAVE_SERVICEMOUNT', true)
+endif
+
 #
 # Compiler configuration
 #
diff --git a/meson_options.txt b/meson_options.txt
index c1f8fe69467184..95655a0d64895c 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -27,3 +27,9 @@ option('enable-usdt', type : 'boolean', value : false,
 
 option('enable-io-uring', type: 'boolean', value: true,
        description: 'Enable fuse-over-io-uring support')
+
+option('service-socket-dir', type : 'string', value : '',
+       description: 'Where to install fuse server sockets (if empty, /run/filesystems)')
+
+option('systemdsystemunitdir', type : 'string', value : '',
+       description: 'Where to install systemd unit files (if empty, query pkg-config(1))')
diff --git a/util/fuservicemount.c b/util/fuservicemount.c
new file mode 100644
index 00000000000000..860c512a34e30f
--- /dev/null
+++ b/util/fuservicemount.c
@@ -0,0 +1,18 @@
+/*
+  FUSE: Filesystem in Userspace
+  Copyright (C) 2025-2026 Oracle.
+  Author: Darrick J. Wong <djwong@kernel.org>
+
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file GPL2.txt.
+*/
+/* This program does the mounting of FUSE filesystems that run in systemd */
+
+#define _GNU_SOURCE
+#include "fuse_config.h"
+#include "mount_service.h"
+
+int main(int argc, char *argv[])
+{
+	return mount_service_main(argc, argv);
+}
diff --git a/util/meson.build b/util/meson.build
index 0e4b1cce95377e..68d8bb11f92955 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -6,6 +6,15 @@ executable('fusermount3', ['fusermount.c', '../lib/mount_util.c', '../lib/util.c
            install_dir: get_option('bindir'),
            c_args: '-DFUSE_CONF="@0@"'.format(fuseconf_path))
 
+if private_cfg.get('HAVE_SERVICEMOUNT', false)
+  executable('fuservicemount3', ['mount_service.c', 'fuservicemount.c'],
+             include_directories: include_dirs,
+             link_with: [ libfuse ],
+             install: true,
+             install_dir: get_option('sbindir'),
+             c_args: '-DFUSE_USE_VERSION=317')
+endif
+
 executable('mount.fuse3', ['mount.fuse.c'],
            include_directories: include_dirs,
            link_with: [ libfuse ],
diff --git a/util/mount_service.c b/util/mount_service.c
new file mode 100644
index 00000000000000..5d92ffb264e4bd
--- /dev/null
+++ b/util/mount_service.c
@@ -0,0 +1,984 @@
+/*
+  FUSE: Filesystem in Userspace
+  Copyright (C) 2025-2026 Oracle.
+  Author: Darrick J. Wong <djwong@kernel.org>
+
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file GPL2.txt.
+*/
+/* This program does the mounting of FUSE filesystems that run in systemd */
+
+#define _GNU_SOURCE
+#include "fuse_config.h"
+#include <stdint.h>
+#include <sys/mman.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mount.h>
+#include <stdbool.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <arpa/inet.h>
+
+#include "mount_util.h"
+#include "util.h"
+#include "fuse_i.h"
+#include "fuse_service_priv.h"
+#include "mount_service.h"
+
+#define FUSE_KERN_DEVICE_ENV	"FUSE_KERN_DEVICE"
+#define FUSE_DEV		"/dev/fuse"
+
+struct mount_service {
+	/* alleged fuse subtype based on -t cli argument */
+	const char *subtype;
+
+	/* full fuse filesystem type we give to mount() */
+	char *fstype;
+
+	/* source argument to mount() */
+	char *source;
+
+	/* target argument (aka mountpoint) to mount() */
+	char *mountpoint;
+
+	/* mount options */
+	char *mntopts;
+
+	/* socket fd */
+	int sockfd;
+
+	/* /dev/fuse device */
+	int fusedevfd;
+
+	/* memfd for cli arguments */
+	int argvfd;
+
+	/* fd for fsopen */
+	int fsopenfd;
+};
+
+/* Filter out the subtype of the filesystem (e.g. fuse.Y -> Y) */
+const char *mount_service_subtype(const char *fstype)
+{
+	char *period = strrchr(fstype, '.');
+	if (period)
+		return period + 1;
+
+	return fstype;
+}
+
+static int mount_service_init(struct mount_service *mo, int argc,
+			      char *argv[])
+{
+	char *fstype = NULL;
+	int i;
+
+	mo->sockfd = -1;
+	mo->fsopenfd = -1;
+
+	for (i = 0; i < argc; i++) {
+		if (!strcmp(argv[i], "-t") && i + 1 < argc) {
+			fstype = argv[i + 1];
+			break;
+		}
+	}
+	if (!fstype)
+		return -1;
+
+	mo->subtype = mount_service_subtype(fstype);
+	return 0;
+}
+
+static int mount_service_connect(struct mount_service *mo)
+{
+	struct sockaddr_un name = {
+		.sun_family = AF_UNIX,
+	};
+	int sockfd;
+	ssize_t written;
+	int ret;
+
+	written = snprintf(name.sun_path, sizeof(name.sun_path),
+			FUSE_SERVICE_SOCKET_DIR "/%s", mo->subtype);
+	if (written > sizeof(name.sun_path)) {
+		fprintf(stderr,
+ "mount.service: filesystem type name (\"%s\") is too long.\n",
+			mo->subtype);
+		return -1;
+	}
+
+	sockfd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (sockfd < 0) {
+		fprintf(stderr,
+ "mount.service: opening %s service socket: %s\n", mo->subtype,
+			strerror(errno));
+		return -1;
+	}
+
+	ret = connect(sockfd, (const struct sockaddr *)&name, sizeof(name));
+	if (ret) {
+		if (errno == ENOENT)
+			fprintf(stderr,
+ "mount.service: no safe filesystem driver for %s available.\n",
+				mo->subtype);
+		else
+			perror(name.sun_path);
+		goto out;
+	}
+
+#ifdef SO_PASSRIGHTS
+	{
+		int zero = 0;
+
+		/* don't let a malicious fuse server send us more fds */
+		setsockopt(sockfd, SOL_SOCKET, SO_PASSRIGHTS, &zero,
+			   sizeof(zero));
+	}
+#endif
+
+	mo->sockfd = sockfd;
+	return 0;
+out:
+	close(sockfd);
+	return -1;
+}
+
+static int mount_service_send_hello(struct mount_service *mo)
+{
+	struct fuse_service_hello hello = {
+		.p.magic = htonl(FUSE_SERVICE_HELLO_CMD),
+		.min_version = htons(FUSE_SERVICE_MIN_PROTO),
+		.max_version = htons(FUSE_SERVICE_MAX_PROTO),
+	};
+	struct fuse_service_hello_reply reply = { };
+	struct iovec iov = {
+		.iov_base = &hello,
+		.iov_len = sizeof(hello),
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+	ssize_t size;
+
+	size = sendmsg(mo->sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+	if (size < 0) {
+		perror("mount.service: send hello");
+		return -1;
+	}
+
+	iov.iov_base = &reply;
+	iov.iov_len = sizeof(reply);
+
+	size = recvmsg(mo->sockfd, &msg, MSG_TRUNC);
+	if (size < 0) {
+		perror("mount.service: hello reply");
+		return -1;
+	}
+	if (size != sizeof(reply)) {
+		fprintf(stderr,
+ "mount.service: wrong hello reply size %zd, expected %zd\n",
+			size, sizeof(reply));
+		return -1;
+	}
+
+	if (reply.p.magic != ntohl(FUSE_SERVICE_HELLO_REPLY)) {
+		fprintf(stderr,
+ "mount.service: %s service server did not reply to hello\n",
+			mo->subtype);
+		return -1;
+	}
+
+	if (ntohs(reply.version) < FUSE_SERVICE_MIN_PROTO ||
+	    ntohs(reply.version) > FUSE_SERVICE_MAX_PROTO) {
+		fprintf(stderr,
+ "mount.service: unsupported protocol version %u\n",
+			ntohs(reply.version));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int mount_service_capture_arg(struct mount_service *mo,
+				     struct fuse_service_memfd_argv *args,
+				     const char *string, off_t *array_pos,
+				     off_t *string_pos)
+{
+	const size_t string_len = strlen(string) + 1;
+	struct fuse_service_memfd_arg arg = {
+		.pos = htonl(*string_pos),
+		.len = htonl(string_len),
+	};
+	ssize_t written;
+
+	written = pwrite(mo->argvfd, string, string_len, *string_pos);
+	if (written < 0) {
+		perror("mount.service: memfd argv write");
+		return -1;
+	}
+	if (written < string_len) {
+		fprintf(stderr, "mount.service: memfd argv[%u] write %zd\n",
+			args->argc, written);
+		return -1;
+	}
+
+	written = pwrite(mo->argvfd, &arg, sizeof(arg), *array_pos);
+	if (written < 0) {
+		perror("mount.service: memfd arg write");
+		return -1;
+	}
+	if (written < sizeof(arg)) {
+		fprintf(stderr, "mount.service: memfd arg[%u] write %zd\n",
+			args->argc, written);
+		return -1;
+	}
+
+	args->argc++;
+	*string_pos += string_len;
+	*array_pos += sizeof(arg);
+
+	return 0;
+}
+
+static int mount_service_capture_args(struct mount_service *mo, int argc,
+				      char *argv[])
+{
+	struct fuse_service_memfd_argv args = {
+		.magic = htonl(FUSE_SERVICE_ARGS_MAGIC),
+	};
+	off_t array_pos = sizeof(struct fuse_service_memfd_argv);
+	off_t string_pos = array_pos +
+			(argc * sizeof(struct fuse_service_memfd_arg));
+	ssize_t written;
+	int i;
+	int ret;
+
+	if (argc < 0) {
+		fprintf(stderr, "mount.service: argc cannot be negative\n");
+		return -1;
+	}
+
+	/*
+	 * Create the memfd in which we'll stash arguments, and set the write
+	 * pointer for the names.
+	 */
+	mo->argvfd = memfd_create("mount.service args", MFD_CLOEXEC);
+	if (mo->argvfd < 0) {
+		perror("mount.service: argvfd create");
+		return -1;
+	}
+
+	/*
+	 * Write the alleged subtype as if it were argv[0], then write the rest
+	 * of the argv arguments.
+	 */
+	ret = mount_service_capture_arg(mo, &args, mo->subtype, &array_pos,
+					&string_pos);
+	if (ret)
+		return ret;
+
+	for (i = 1; i < argc; i++) {
+		/* skip the -t(ype) argument */
+		if (!strcmp(argv[i], "-t")) {
+			i++;
+			continue;
+		}
+
+		ret = mount_service_capture_arg(mo, &args, argv[i],
+						&array_pos, &string_pos);
+		if (ret)
+			return ret;
+	}
+
+	/* Now write the header */
+	args.argc = htonl(args.argc);
+	written = pwrite(mo->argvfd, &args, sizeof(args), 0);
+	if (written < 0) {
+		perror("mount.service: memfd argv write");
+		return -1;
+	}
+	if (written < sizeof(args)) {
+		fprintf(stderr, "mount.service: memfd argv wrote %zd\n",
+			written);
+		return -1;
+	}
+
+	return 0;
+}
+
+static ssize_t __send_fd(int sockfd, struct fuse_service_requested_file *req,
+			 size_t req_sz, int fd)
+{
+	union {
+		struct cmsghdr cmsghdr;
+		char control[CMSG_SPACE(sizeof(int))];
+	} cmsgu;
+	struct iovec iov = {
+		.iov_base = req,
+		.iov_len = req_sz,
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+		.msg_control = cmsgu.control,
+		.msg_controllen = sizeof(cmsgu.control),
+	};
+	struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
+
+	memset(&cmsgu, 0, sizeof(cmsgu));
+	cmsg->cmsg_len = CMSG_LEN(sizeof (int));
+	cmsg->cmsg_level = SOL_SOCKET;
+	cmsg->cmsg_type = SCM_RIGHTS;
+
+	*((int *)CMSG_DATA(cmsg)) = fd;
+
+	return sendmsg(sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+}
+
+static int mount_service_send_file(struct mount_service *mo,
+				   const char *path, int fd)
+{
+	struct fuse_service_requested_file *req;
+	const size_t req_sz =
+			sizeof_fuse_service_requested_file(strlen(path));
+	ssize_t written;
+	int ret = 0;
+
+	req = malloc(req_sz);
+	if (!req) {
+		perror("mount.service: alloc send file reply");
+		return -1;
+	}
+	req->p.magic = htonl(FUSE_SERVICE_OPEN_REPLY);
+	req->error = 0;
+	strcpy(req->path, path);
+
+	written = __send_fd(mo->sockfd, req, req_sz, fd);
+	if (written < 0) {
+		perror("mount.service: send file reply");
+		ret = -1;
+	}
+
+	free(req);
+	return ret;
+}
+
+static ssize_t __send_packet(int sockfd, void *buf, ssize_t buflen)
+{
+	struct iovec iov = {
+		.iov_base = buf,
+		.iov_len = buflen,
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+
+	return sendmsg(sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+}
+
+static int mount_service_send_file_error(struct mount_service *mo, int error,
+					 const char *path)
+{
+	struct fuse_service_requested_file *req;
+	const size_t req_sz =
+			sizeof_fuse_service_requested_file(strlen(path));
+	ssize_t written;
+	int ret = 0;
+
+	req = malloc(req_sz);
+	if (!req) {
+		perror("mount.service: alloc send file error");
+		return -1;
+	}
+	req->p.magic = htonl(FUSE_SERVICE_OPEN_REPLY);
+	req->error = htonl(error);
+	strcpy(req->path, path);
+
+	written = __send_packet(mo->sockfd, req, req_sz);
+	if (written < 0) {
+		perror("mount.service: send file error");
+		ret = -1;
+	}
+
+	free(req);
+	return ret;
+}
+
+static int mount_service_send_required_files(struct mount_service *mo,
+					     const char *fusedev)
+{
+	int ret;
+
+	mo->fusedevfd = open(fusedev, O_RDWR | O_CLOEXEC);
+	if (mo->fusedevfd < 0) {
+		perror(fusedev);
+		return -1;
+	}
+
+	ret = mount_service_send_file(mo, FUSE_SERVICE_ARGV, mo->argvfd);
+	close(mo->argvfd);
+	mo->argvfd = -1;
+	if (ret)
+		return ret;
+
+	return mount_service_send_file(mo, FUSE_SERVICE_FUSEDEV,
+				       mo->fusedevfd);
+}
+
+static int
+mount_service_receive_command(struct mount_service *mo,
+			      struct fuse_service_packet **commandp)
+{
+	struct iovec iov = {
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+	struct fuse_service_packet *command;
+	ssize_t size;
+
+	size = recvmsg(mo->sockfd, &msg, MSG_PEEK | MSG_TRUNC);
+	if (size < 0) {
+		perror("mount.service: peek service command");
+		return -1;
+	}
+	if (size == 0) {
+		/* fuse server probably exited early */
+		return -1;
+	}
+	if (size < sizeof(struct fuse_service_packet)) {
+		fprintf(stderr,
+ "mount.service: wrong command packet size %zd, expected at least %zd\n",
+			size, sizeof(struct fuse_service_packet));
+		return -1;
+	}
+
+	command = calloc(1, size + 1);
+	if (!command) {
+		perror("mount.service: alloc service command");
+		return -1;
+	}
+	iov.iov_base = command;
+	iov.iov_len = size;
+
+	size = recvmsg(mo->sockfd, &msg, MSG_TRUNC);
+	if (size < 0) {
+		perror("mount.service: receive service command");
+		return -1;
+	}
+	if (size != iov.iov_len) {
+		fprintf(stderr,
+ "mount.service: wrong service command size %zd, expected %zd\n",
+			size, iov.iov_len);
+		return -1;
+	}
+
+	*commandp = command;
+	return 0;
+}
+
+static int mount_service_send_reply(struct mount_service *mo, int error)
+{
+	struct fuse_service_simple_reply reply = {
+		.p.magic = htonl(FUSE_SERVICE_SIMPLE_REPLY),
+		.error = htonl(error),
+	};
+	struct iovec iov = {
+		.iov_base = &reply,
+		.iov_len = sizeof(reply),
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+	ssize_t size;
+
+	size = sendmsg(mo->sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+	if (size < 0) {
+		perror("mount.service: send service reply");
+		return -1;
+	}
+
+	return 0;
+}
+
+static int mount_service_handle_open_cmd(struct mount_service *mo,
+					 struct fuse_service_packet *p)
+{
+	struct fuse_service_open_command *oc =
+			container_of(p, struct fuse_service_open_command, p);
+	uint32_t request_flags = ntohl(oc->request_flags);
+	int ret;
+	int fd;
+
+	if (request_flags & ~FUSE_SERVICE_OPEN_FLAGS)
+		return mount_service_send_file_error(mo, EINVAL, oc->path);
+
+	fd = open(oc->path, ntohl(oc->open_flags), ntohl(oc->create_mode));
+	if (fd < 0) {
+		int error = errno;
+
+		/*
+		 * Don't print a busy device error report because the
+		 * filesystem might decide to retry.
+		 */
+		if (errno != EBUSY)
+			perror(oc->path);
+		return mount_service_send_file_error(mo, error, oc->path);
+	}
+
+	ret = mount_service_send_file(mo, oc->path, fd);
+	close(fd);
+	return ret;
+}
+
+static int
+mount_service_handle_fsopen_cmd(struct mount_service *mo,
+				const struct fuse_service_packet *p)
+{
+	struct fuse_service_string_command *oc =
+			container_of(p, struct fuse_service_string_command, p);
+
+	mo->fsopenfd = -1;
+#if 0
+	mo->fsopenfd = fsopen(oc->value, FSOPEN_CLOEXEC);
+#endif
+	if (mo->fsopenfd >= 0)
+		return mount_service_send_reply(mo, 0);
+
+	if (mo->fstype) {
+		fprintf(stderr, "mount.service: fstype respecified!\n");
+		mount_service_send_reply(mo, EINVAL);
+		return -1;
+	}
+
+	mo->fstype = strdup(oc->value);
+	if (!mo->fstype) {
+		perror("mount.service: alloc fstype string");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	return mount_service_send_reply(mo, 0);
+}
+
+static int
+mount_service_handle_source_cmd(struct mount_service *mo,
+				const struct fuse_service_packet *p)
+{
+	struct fuse_service_string_command *oc =
+			container_of(p, struct fuse_service_string_command, p);
+	int ret;
+
+	if (mo->fsopenfd < 0) {
+		if (mo->source) {
+			fprintf(stderr, "mount.service: source respecified!\n");
+			mount_service_send_reply(mo, EINVAL);
+			return -1;
+		}
+
+		mo->source = strdup(oc->value);
+		if (!mo->source) {
+			perror("mount.service: alloc source string");
+			mount_service_send_reply(mo, errno);
+			return -1;
+		}
+
+		return mount_service_send_reply(mo, 0);
+	}
+
+	ret = fsconfig(mo->fsopenfd, FSCONFIG_SET_STRING, "source", oc->value,
+		       0);
+	if (ret) {
+		perror("mount.service: fsconfig source");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	return mount_service_send_reply(mo, 0);
+}
+
+static int
+mount_service_handle_mntopts_cmd(struct mount_service *mo,
+				 const struct fuse_service_packet *p)
+{
+	struct fuse_service_string_command *oc =
+			container_of(p, struct fuse_service_string_command, p);
+	char *tokstr = oc->value;
+	char *tok, *savetok;
+	int ret;
+
+	if (mo->fsopenfd < 0) {
+		if (mo->mntopts) {
+			fprintf(stderr,
+ "mount.service: mount options respecified!\n");
+			mount_service_send_reply(mo, EINVAL);
+			return -1;
+		}
+
+		mo->mntopts = strdup(oc->value);
+		if (!mo->mntopts) {
+			perror("mount.service: alloc mount options string");
+			mount_service_send_reply(mo, errno);
+			return -1;
+		}
+
+		return mount_service_send_reply(mo, 0);
+	}
+
+	while ((tok = strtok_r(tokstr, ",", &savetok)) != NULL) {
+		char *equals = strchr(tok, '=');
+
+		if (equals) {
+			char oldchar = *equals;
+
+			*equals = 0;
+			ret = fsconfig(mo->fsopenfd, FSCONFIG_SET_STRING, tok,
+				       equals + 1, 0);
+			*equals = oldchar;
+		} else {
+			ret = fsconfig(mo->fsopenfd, FSCONFIG_SET_FLAG, tok,
+				       NULL, 0);
+		}
+		if (ret) {
+			perror("mount.service: set mount option");
+			mount_service_send_reply(mo, errno);
+			return -1;
+		}
+
+		tokstr = NULL;
+	}
+
+	return mount_service_send_reply(mo, 0);
+}
+
+static int
+mount_service_handle_mountpoint_cmd(struct mount_service *mo,
+				    const struct fuse_service_packet *p)
+{
+	struct fuse_service_string_command *oc =
+			container_of(p, struct fuse_service_string_command, p);
+
+	if (mo->mountpoint) {
+		fprintf(stderr, "mount.service: mount point respecified!\n");
+		mount_service_send_reply(mo, EINVAL);
+		return -1;
+	}
+
+	mo->mountpoint = strdup(oc->value);
+	if (!mo->mountpoint) {
+		perror("mount.service: alloc mount point string");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	return mount_service_send_reply(mo, 0);
+}
+
+static inline int format_libfuse_mntopts(char *buf, size_t bufsz,
+					 const struct mount_service *mo,
+					 const struct stat *statbuf)
+{
+	if (mo->mntopts)
+		return snprintf(buf, bufsz,
+				"%s,fd=%i,rootmode=%o,user_id=%u,group_id=%u",
+				mo->mntopts, mo->fusedevfd,
+				statbuf->st_mode & S_IFMT,
+				getuid(), getgid());
+
+	return snprintf(buf, bufsz,
+			"fd=%i,rootmode=%o,user_id=%u,group_id=%u",
+			mo->fusedevfd, statbuf->st_mode & S_IFMT,
+			getuid(), getgid());
+}
+
+static int mount_service_regular_mount(struct mount_service *mo,
+				       struct fuse_service_mount_command *oc,
+				       struct stat *stbuf)
+{
+	char *realmopts;
+	int ret;
+
+	if (!mo->fstype) {
+		fprintf(stderr, "mount.service: missing mount type parameter\n");
+		mount_service_send_reply(mo, EINVAL);
+		return -1;
+	}
+
+	if (!mo->source) {
+		fprintf(stderr, "mount.service: missing mount source parameter\n");
+		mount_service_send_reply(mo, EINVAL);
+		return -1;
+	}
+
+	ret = format_libfuse_mntopts(NULL, 0, mo, stbuf);
+	if (ret < 0) {
+		perror("mount.service: mount option preformatting");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	realmopts = malloc(ret + 1);
+	if (!realmopts) {
+		perror("mount.service: alloc real mount options string");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	ret = format_libfuse_mntopts(realmopts, ret + 1, mo, stbuf);
+	if (ret < 0) {
+		free(realmopts);
+		perror("mount.service: mount options formatting");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	ret = mount(mo->source, mo->mountpoint, mo->fstype, ntohl(oc->flags),
+		    realmopts);
+	free(realmopts);
+	if (ret) {
+		perror("mount.service");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	return mount_service_send_reply(mo, 0);
+}
+
+static int mount_service_fsopen_mount(struct mount_service *mo,
+				      struct fuse_service_mount_command *oc,
+				      struct stat *stbuf)
+{
+	char tmp[64];
+	int mfd;
+	int ret;
+
+	snprintf(tmp, sizeof(tmp), "%i", mo->fusedevfd);
+	ret = fsconfig(mo->fsopenfd, FSCONFIG_SET_STRING, "fd", tmp, 0);
+	if (ret) {
+		perror("mount.service: set fd option");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	snprintf(tmp, sizeof(tmp), "%o", stbuf->st_mode & S_IFMT);
+	ret = fsconfig(mo->fsopenfd, FSCONFIG_SET_STRING, "rootmode", tmp, 0);
+	if (ret) {
+		perror("mount.service: set rootmode option");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	snprintf(tmp, sizeof(tmp), "%u", getuid());
+	ret = fsconfig(mo->fsopenfd, FSCONFIG_SET_STRING, "user_id", tmp, 0);
+	if (ret) {
+		perror("mount.service: set user_id option");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	snprintf(tmp, sizeof(tmp), "%u", getgid());
+	ret = fsconfig(mo->fsopenfd, FSCONFIG_SET_STRING, "group_id", tmp, 0);
+	if (ret) {
+		perror("mount.service: set group_id option");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	mfd = fsmount(mo->fsopenfd, FSMOUNT_CLOEXEC, ntohl(oc->flags));
+	if (mfd < 0) {
+		perror("mount.service");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	ret = move_mount(mfd, "", AT_FDCWD, mo->mountpoint,
+			 MOVE_MOUNT_F_EMPTY_PATH);
+	close(mfd);
+	if (ret) {
+		perror("mount.service: move_mount");
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	return mount_service_send_reply(mo, 0);
+}
+
+static int mount_service_handle_mount_cmd(struct mount_service *mo,
+					  struct fuse_service_packet *p)
+{
+	struct stat stbuf;
+	char mountpoint[PATH_MAX] = "";
+	struct fuse_service_mount_command *oc =
+			container_of(p, struct fuse_service_mount_command, p);
+	int ret;
+
+	if (!mo->mountpoint) {
+		fprintf(stderr, "mount.service: missing mount point parameter\n");
+		mount_service_send_reply(mo, EINVAL);
+		return -1;
+	}
+
+	if (realpath(mo->mountpoint, mountpoint) == NULL) {
+		int error = errno;
+
+		fprintf(stderr, "mount.service: bad mount point `%s': %s\n",
+			mo->mountpoint, strerror(error));
+		mount_service_send_reply(mo, error);
+		return -1;
+	}
+
+	ret = stat(mo->mountpoint, &stbuf);
+	if (ret == -1) {
+		perror(mo->mountpoint);
+		mount_service_send_reply(mo, errno);
+		return -1;
+	}
+
+	if (mo->fsopenfd >= 0)
+		return mount_service_fsopen_mount(mo, oc, &stbuf);
+	return mount_service_regular_mount(mo, oc, &stbuf);
+}
+
+static int mount_service_handle_bye_cmd(struct fuse_service_packet *p)
+{
+	int error;
+
+	struct fuse_service_bye_command *bc =
+			container_of(p, struct fuse_service_bye_command, p);
+
+	error = ntohl(bc->error);
+	if (error) {
+		fprintf(stderr, "mount.service: initialization failed: %s\n",
+			strerror(error));
+		return -1;
+	}
+
+	return 0;
+}
+
+static void mount_service_destroy(struct mount_service *mo)
+{
+	close(mo->fusedevfd);
+	close(mo->argvfd);
+	close(mo->fsopenfd);
+	shutdown(mo->sockfd, SHUT_RDWR);
+	close(mo->sockfd);
+
+	free(mo->source);
+	free(mo->mountpoint);
+	free(mo->mntopts);
+	free(mo->fstype);
+
+	memset(mo, 0, sizeof(*mo));
+	mo->fsopenfd = -1;
+	mo->sockfd = -1;
+	mo->argvfd = -1;
+	mo->fusedevfd = -1;
+}
+
+int mount_service_main(int argc, char *argv[])
+{
+	const char *fusedev = getenv(FUSE_KERN_DEVICE_ENV) ?: FUSE_DEV;
+	struct mount_service mo = { };
+	bool running = true;
+	int ret;
+
+	if (argc < 3 || !strcmp(argv[1], "--help")) {
+		printf("Usage: %s source mountpoint -t type [-o options]\n",
+				argv[0]);
+		return EXIT_FAILURE;
+	}
+
+	ret = mount_service_init(&mo, argc, argv);
+	if (ret) {
+		fprintf(stderr, "%s: cannot determine filesystem type.\n",
+			argv[0]);
+		return EXIT_FAILURE;
+	}
+
+	ret = mount_service_connect(&mo);
+	if (ret) {
+		ret = EXIT_FAILURE;
+		goto out;
+	}
+
+	ret = mount_service_send_hello(&mo);
+	if (ret) {
+		ret = EXIT_FAILURE;
+		goto out;
+	}
+
+	ret = mount_service_capture_args(&mo, argc, argv);
+	if (ret) {
+		ret = EXIT_FAILURE;
+		goto out;
+	}
+
+	ret = mount_service_send_required_files(&mo, fusedev);
+	if (ret) {
+		ret = EXIT_FAILURE;
+		goto out;
+	}
+
+	while (running) {
+		struct fuse_service_packet *p = NULL;
+
+		ret = mount_service_receive_command(&mo, &p);
+		if (ret) {
+			ret = EXIT_FAILURE;
+			goto out;
+		}
+
+		switch (ntohl(p->magic)) {
+		case FUSE_SERVICE_OPEN_CMD:
+			ret = mount_service_handle_open_cmd(&mo, p);
+			break;
+		case FUSE_SERVICE_FSOPEN_CMD:
+			ret = mount_service_handle_fsopen_cmd(&mo, p);
+			break;
+		case FUSE_SERVICE_SOURCE_CMD:
+			ret = mount_service_handle_source_cmd(&mo, p);
+			break;
+		case FUSE_SERVICE_MNTOPTS_CMD:
+			ret = mount_service_handle_mntopts_cmd(&mo, p);
+			break;
+		case FUSE_SERVICE_MNTPT_CMD:
+			ret = mount_service_handle_mountpoint_cmd(&mo, p);
+			break;
+		case FUSE_SERVICE_MOUNT_CMD:
+			ret = mount_service_handle_mount_cmd(&mo, p);
+			break;
+		case FUSE_SERVICE_BYE_CMD:
+			ret = mount_service_handle_bye_cmd(p);
+			running = false;
+			break;
+		default:
+			fprintf(stderr, "unrecognized packet 0x%x\n",
+				ntohl(p->magic));
+			ret = EXIT_FAILURE;
+			break;
+		}
+		free(p);
+
+		if (ret) {
+			ret = EXIT_FAILURE;
+			goto out;
+		}
+	}
+
+	ret = EXIT_SUCCESS;
+out:
+	mount_service_destroy(&mo);
+	return ret;
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/5] libfuse: integrate fuse services into mount.fuse3
  2026-02-23 23:03 ` [PATCHSET v7 5/6] libfuse: run fuse servers as a contained service Darrick J. Wong
  2026-02-23 23:34   ` [PATCH 1/5] libfuse: add systemd/inetd socket service mounting helper Darrick J. Wong
@ 2026-02-23 23:34   ` Darrick J. Wong
  2026-02-23 23:34   ` [PATCH 3/5] libfuse: delegate iomap privilege from mount.service to fuse services Darrick J. Wong
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:34 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Teach mount.fuse3 how to start fuse via service, if present.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 util/mount_service.h  |    9 ++++++++
 doc/fuservicemount3.8 |   10 ++++++++
 util/fuservicemount.c |   48 +++++++++++++++++++++++++++++++++++++++++
 util/meson.build      |    4 +++
 util/mount.fuse.c     |   58 +++++++++++++++++++++++++++++++------------------
 util/mount_service.c  |   18 +++++++++++++++
 6 files changed, 124 insertions(+), 23 deletions(-)


diff --git a/util/mount_service.h b/util/mount_service.h
index 16e120da10765e..b211c7ede4e034 100644
--- a/util/mount_service.h
+++ b/util/mount_service.h
@@ -29,4 +29,13 @@ int mount_service_main(int argc, char *argv[]);
  */
 const char *mount_service_subtype(const char *fstype);
 
+/**
+ * Discover if there is a fuse service socket for the given fuse subtype.
+ *
+ * @param subtype subtype of a fuse filesystem type (e.g. Y from
+ *                mount_service_subtype)
+ * @return true if available, false if not
+ */
+bool mount_service_present(const char *subtype);
+
 #endif /* MOUNT_SERVICE_H_ */
diff --git a/doc/fuservicemount3.8 b/doc/fuservicemount3.8
index e45d6a89c8b81a..aa2167cb4872c6 100644
--- a/doc/fuservicemount3.8
+++ b/doc/fuservicemount3.8
@@ -7,12 +7,20 @@ .SH SYNOPSIS
 .B mountpoint
 .BI -t " fstype"
 [
-.I options
+.BI -o " options"
 ]
+
+.B fuservicemount3
+.BI -t " fstype"
+.B --check
+
 .SH DESCRIPTION
 Mount a filesystem using a FUSE server that runs as a socket service.
 These servers can be contained using the platform's service management
 framework.
+
+The second form checks if there is a FUSE service available for the given
+filesystem type.
 .SH "AUTHORS"
 .LP
 The author of the fuse socket service code is Darrick J. Wong <djwong@kernel.org>.
diff --git a/util/fuservicemount.c b/util/fuservicemount.c
index 860c512a34e30f..13b80b3150e3bf 100644
--- a/util/fuservicemount.c
+++ b/util/fuservicemount.c
@@ -9,10 +9,58 @@
 /* This program does the mounting of FUSE filesystems that run in systemd */
 
 #define _GNU_SOURCE
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
 #include "fuse_config.h"
 #include "mount_service.h"
 
+static int check_service(const char *fstype)
+{
+	const char *subtype;
+
+	if (!fstype) {
+		fprintf(stderr,
+			"fuservicemount: expected fs type for --check\n");
+		return EXIT_FAILURE;
+	}
+
+	subtype = mount_service_subtype(fstype);
+	return mount_service_present(subtype) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
 int main(int argc, char *argv[])
 {
+	char *fstype = NULL;
+	bool check = false;
+	int i;
+
+	/*
+	 * If the user passes us exactly the args -t FSTYPE --check then
+	 * we'll just check if there's a service for the FSTYPE fuse server.
+	 */
+	for (i = 1; i < argc; i++) {
+		if (!strcmp(argv[i], "--check")) {
+			if (check) {
+				check = false;
+				break;
+			}
+			check = true;
+		} else if (!strcmp(argv[i], "-t") && i + 1 < argc) {
+			if (fstype) {
+				check = false;
+				break;
+			}
+			fstype = argv[i + 1];
+			i++;
+		} else {
+			check = false;
+			break;
+		}
+	}
+	if (check)
+		return check_service(fstype);
+
 	return mount_service_main(argc, argv);
 }
diff --git a/util/meson.build b/util/meson.build
index 68d8bb11f92955..3adf395bfb6386 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -6,7 +6,9 @@ executable('fusermount3', ['fusermount.c', '../lib/mount_util.c', '../lib/util.c
            install_dir: get_option('bindir'),
            c_args: '-DFUSE_CONF="@0@"'.format(fuseconf_path))
 
+mount_fuse3_sources = ['mount.fuse.c']
 if private_cfg.get('HAVE_SERVICEMOUNT', false)
+  mount_fuse3_sources += ['mount_service.c']
   executable('fuservicemount3', ['mount_service.c', 'fuservicemount.c'],
              include_directories: include_dirs,
              link_with: [ libfuse ],
@@ -15,7 +17,7 @@ if private_cfg.get('HAVE_SERVICEMOUNT', false)
              c_args: '-DFUSE_USE_VERSION=317')
 endif
 
-executable('mount.fuse3', ['mount.fuse.c'],
+executable('mount.fuse3', mount_fuse3_sources,
            include_directories: include_dirs,
            link_with: [ libfuse ],
            install: true,
diff --git a/util/mount.fuse.c b/util/mount.fuse.c
index f1a90fe8abae7c..b6a55eebb7f88b 100644
--- a/util/mount.fuse.c
+++ b/util/mount.fuse.c
@@ -49,6 +49,9 @@
 #endif
 
 #include "fuse.h"
+#ifdef HAVE_SERVICEMOUNT
+# include "mount_service.h"
+#endif
 
 static char *progname;
 
@@ -280,9 +283,7 @@ int main(int argc, char *argv[])
 	mountpoint = argv[2];
 
 	for (i = 3; i < argc; i++) {
-		if (strcmp(argv[i], "-v") == 0) {
-			continue;
-		} else if (strcmp(argv[i], "-t") == 0) {
+		if (strcmp(argv[i], "-t") == 0) {
 			i++;
 
 			if (i == argc) {
@@ -303,6 +304,39 @@ int main(int argc, char *argv[])
 					progname);
 				exit(1);
 			}
+		}
+	}
+
+	if (!type) {
+		if (source) {
+			dup_source = xstrdup(source);
+			type = dup_source;
+			source = strchr(type, '#');
+			if (source)
+				*source++ = '\0';
+			if (!type[0]) {
+				fprintf(stderr, "%s: empty filesystem type\n",
+					progname);
+				exit(1);
+			}
+		} else {
+			fprintf(stderr, "%s: empty source\n", progname);
+			exit(1);
+		}
+	}
+
+#ifdef HAVE_SERVICEMOUNT
+	/*
+	 * Now that we know the desired filesystem type, see if we can find
+	 * a socket service implementing that.
+	 */
+	if (mount_service_present(type))
+		return mount_service_main(argc, argv);
+#endif
+
+	for (i = 3; i < argc; i++) {
+		if (strcmp(argv[i], "-v") == 0) {
+			continue;
 		} else	if (strcmp(argv[i], "-o") == 0) {
 			char *opts;
 			char *opt;
@@ -366,24 +400,6 @@ int main(int argc, char *argv[])
 	if (suid)
 		options = add_option("suid", options);
 
-	if (!type) {
-		if (source) {
-			dup_source = xstrdup(source);
-			type = dup_source;
-			source = strchr(type, '#');
-			if (source)
-				*source++ = '\0';
-			if (!type[0]) {
-				fprintf(stderr, "%s: empty filesystem type\n",
-					progname);
-				exit(1);
-			}
-		} else {
-			fprintf(stderr, "%s: empty source\n", progname);
-			exit(1);
-		}
-	}
-
 	if (setuid_name && setuid_name[0]) {
 #ifdef linux
 		if (drop_privileges) {
diff --git a/util/mount_service.c b/util/mount_service.c
index 5d92ffb264e4bd..642d4a19c443c4 100644
--- a/util/mount_service.c
+++ b/util/mount_service.c
@@ -982,3 +982,21 @@ int mount_service_main(int argc, char *argv[])
 	mount_service_destroy(&mo);
 	return ret;
 }
+
+bool mount_service_present(const char *fstype)
+{
+	struct stat stbuf;
+	char path[PATH_MAX];
+	int ret;
+
+	snprintf(path, sizeof(path), FUSE_SERVICE_SOCKET_DIR "/%s", fstype);
+	ret = stat(path, &stbuf);
+	if (ret)
+		return false;
+
+	if (!S_ISSOCK(stbuf.st_mode))
+		return false;
+
+	ret = access(path, R_OK | W_OK);
+	return ret == 0;
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/5] libfuse: delegate iomap privilege from mount.service to fuse services
  2026-02-23 23:03 ` [PATCHSET v7 5/6] libfuse: run fuse servers as a contained service Darrick J. Wong
  2026-02-23 23:34   ` [PATCH 1/5] libfuse: add systemd/inetd socket service mounting helper Darrick J. Wong
  2026-02-23 23:34   ` [PATCH 2/5] libfuse: integrate fuse services into mount.fuse3 Darrick J. Wong
@ 2026-02-23 23:34   ` Darrick J. Wong
  2026-02-23 23:34   ` [PATCH 4/5] libfuse: enable setting iomap block device block size Darrick J. Wong
  2026-02-23 23:35   ` [PATCH 5/5] fuservicemount: create loop devices for regular files Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:34 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Enable the mount.service helper to attach whatever privileges it might
have to enable iomap to a /dev/fuse fd before passing that fd to the
fuse server.  Assuming that the fuse service itself does not have
sufficient privilege to enable iomap on its own, it can now inherit that
privilege via the fd.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_kernel.h       |    1 +
 include/fuse_lowlevel.h     |   10 +++++++
 include/fuse_service.h      |   11 +++++++
 include/fuse_service_priv.h |   10 +++++++
 lib/fuse_lowlevel.c         |    5 +++
 lib/fuse_service.c          |   49 +++++++++++++++++++++++++++++++++
 lib/fuse_versionscript      |    2 +
 util/mount_service.c        |   64 +++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 152 insertions(+)


diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 8149657ac44cb9..417f1d42b0618d 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -1193,6 +1193,7 @@ struct fuse_iomap_support {
 #define FUSE_DEV_IOC_IOMAP_SUPPORT	_IOR(FUSE_DEV_IOC_MAGIC, 99, \
 					     struct fuse_iomap_support)
 #define FUSE_DEV_IOC_SET_NOFS		_IOW(FUSE_DEV_IOC_MAGIC, 100, uint32_t)
+#define FUSE_DEV_IOC_ADD_IOMAP		_IO(FUSE_DEV_IOC_MAGIC, 101)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index 77fc623386ce20..eefc69360b8aa8 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -2799,6 +2799,16 @@ uint64_t fuse_lowlevel_discover_iomap(int fd);
  */
 int fuse_lowlevel_disable_fsreclaim(struct fuse_session *se, int val);
 
+/**
+ * Request that iomap capabilities be added to this fuse device.  This enables
+ * a privileged mount helper to convey the privileges that allow iomap usage to
+ * a completely unprivileged fuse server.
+ *
+ * @param fd open file descriptor to a fuse device
+ * @return 0 on success, -1 on failure with errno set
+ */
+int fuse_lowlevel_add_iomap(int fd);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/fuse_service.h b/include/fuse_service.h
index d3a3a4a4237380..a88173a0e4c227 100644
--- a/include/fuse_service.h
+++ b/include/fuse_service.h
@@ -128,6 +128,17 @@ int fuse_service_receive_file(struct fuse_service *sf,
  */
 int fuse_service_finish_file_requests(struct fuse_service *sf);
 
+/**
+ * Attach iomap to the fuse connection.
+ *
+ * @param sf service context
+ * @param mandatory true if the server requires iomap
+ * @param error result of trying to enable iomap
+ * @return 0 on success, -1 on error
+ */
+int fuse_service_configure_iomap(struct fuse_service *sf, bool mandatory,
+				 int *error);
+
 /**
  * Ask the mount.service helper to mount the filesystem for us.  The fuse client
  * will begin sending requests to the fuse server immediately after this.
diff --git a/include/fuse_service_priv.h b/include/fuse_service_priv.h
index 4df323097c2470..f755710863c766 100644
--- a/include/fuse_service_priv.h
+++ b/include/fuse_service_priv.h
@@ -32,6 +32,7 @@ struct fuse_service_memfd_argv {
 #define FUSE_SERVICE_MNTPT_CMD		0x4d4e5450	/* MNTP */
 #define FUSE_SERVICE_MOUNT_CMD		0x444f4954	/* DOIT */
 #define FUSE_SERVICE_BYE_CMD		0x42594545	/* BYEE */
+#define FUSE_SERVICE_IOMAP_CMD		0x494f4d41	/* IOMA */
 
 /* mount.service sends replies to the fuse server */
 #define FUSE_SERVICE_OPEN_REPLY		0x46494c45	/* FILE */
@@ -87,6 +88,15 @@ static inline size_t sizeof_fuse_service_open_command(size_t pathlen)
 	return sizeof(struct fuse_service_open_command) + pathlen + 1;
 }
 
+#define FUSE_IOMAP_MODE_OPTIONAL	0x503F /* P? */
+#define FUSE_IOMAP_MODE_MANDATORY	0x5021 /* P! */
+
+struct fuse_service_iomap_command {
+	struct fuse_service_packet p;
+	__be16 mode;
+	__be16 padding;
+};
+
 struct fuse_service_string_command {
 	struct fuse_service_packet p;
 	char value[];
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 714c26385c044f..4f27603400f2da 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -5349,3 +5349,8 @@ int fuse_lowlevel_disable_fsreclaim(struct fuse_session *se, int val)
 {
 	return ioctl(se->fd, FUSE_DEV_IOC_SET_NOFS, &val);
 }
+
+int fuse_lowlevel_add_iomap(int fd)
+{
+	return ioctl(fd, FUSE_DEV_IOC_ADD_IOMAP);
+}
diff --git a/lib/fuse_service.c b/lib/fuse_service.c
index 40763143946c83..a9fce8b022c005 100644
--- a/lib/fuse_service.c
+++ b/lib/fuse_service.c
@@ -649,6 +649,55 @@ static int send_mount(struct fuse_service *sf, unsigned int flags, int *error)
 	return 0;
 }
 
+int fuse_service_configure_iomap(struct fuse_service *sf, bool mandatory,
+				 int *error)
+{
+	struct fuse_service_iomap_command cmd = {
+		.p.magic = ntohl(FUSE_SERVICE_IOMAP_CMD),
+		.mode = mandatory ? ntohs(FUSE_IOMAP_MODE_MANDATORY) :
+				    ntohs(FUSE_IOMAP_MODE_OPTIONAL),
+	};
+	struct fuse_service_simple_reply reply = { };
+	struct iovec iov = {
+		.iov_base = &cmd,
+		.iov_len = sizeof(cmd),
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+	ssize_t size;
+
+	size = sendmsg(sf->sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
+	if (size < 0) {
+		perror("fuse: send iomap command");
+		return -1;
+	}
+
+	iov.iov_base = &reply;
+	iov.iov_len = sizeof(reply);
+	size = recvmsg(sf->sockfd, &msg, MSG_TRUNC);
+	if (size < 0) {
+		perror("fuse: iomap command reply");
+		return -1;
+	}
+	if (size != sizeof(reply)) {
+		fprintf(stderr,
+ "fuse: wrong iomap command reply size %zd, expected %zd\n",
+			size, sizeof(reply));
+		return -1;
+	}
+
+	if (ntohl(reply.p.magic) != FUSE_SERVICE_SIMPLE_REPLY) {
+		fprintf(stderr,
+ "fuse: iomap command reply contains wrong magic!\n");
+		return -1;
+	}
+
+	*error = ntohl(reply.error);
+	return 0;
+}
+
 int fuse_service_mount(struct fuse_service *sf, struct fuse_session *se,
 		       const char *mountpoint)
 {
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 935eaec820c7a7..334a0f7cf3a096 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -254,8 +254,10 @@ FUSE_3.99 {
 		fuse_lowlevel_iomap_inval_mappings;
 		fuse_fs_iomap_upsert;
 		fuse_fs_iomap_inval;
+		fuse_lowlevel_add_iomap;
 		fuse_service_accept;
 		fuse_service_append_args;
+		fuse_service_configure_iomap;
 		fuse_service_destroy;
 		fuse_service_finish_file_requests;
 		fuse_service_mount;
diff --git a/util/mount_service.c b/util/mount_service.c
index 642d4a19c443c4..241f47822deaa6 100644
--- a/util/mount_service.c
+++ b/util/mount_service.c
@@ -62,6 +62,9 @@ struct mount_service {
 
 	/* fd for fsopen */
 	int fsopenfd;
+
+	/* did someone configure iomap already? */
+	int iomap_configured:1;
 };
 
 /* Filter out the subtype of the filesystem (e.g. fuse.Y -> Y) */
@@ -413,6 +416,22 @@ static int mount_service_send_file_error(struct mount_service *mo, int error,
 	return ret;
 }
 
+static int mount_service_config_iomap(struct mount_service *mo,
+				      bool mandatory)
+{
+	int ret;
+
+	mo->iomap_configured = 1;
+
+	ret = fuse_lowlevel_add_iomap(mo->fusedevfd);
+	if (ret && mandatory) {
+		perror("mount.service: adding iomap capability");
+		return -errno;
+	}
+
+	return 0;
+}
+
 static int mount_service_send_required_files(struct mount_service *mo,
 					     const char *fusedev)
 {
@@ -743,6 +762,13 @@ static int mount_service_regular_mount(struct mount_service *mo,
 		return -1;
 	}
 
+	/*
+	 * If nobody tried to configure iomap, try to enable it but don't
+	 * fail if we can't.
+	 */
+	if (!mo->iomap_configured)
+		mount_service_config_iomap(mo, false);
+
 	ret = mount(mo->source, mo->mountpoint, mo->fstype, ntohl(oc->flags),
 		    realmopts);
 	free(realmopts);
@@ -814,6 +840,41 @@ static int mount_service_fsopen_mount(struct mount_service *mo,
 	return mount_service_send_reply(mo, 0);
 }
 
+static int mount_service_handle_iomap_cmd(struct mount_service *mo,
+					  struct fuse_service_packet *p)
+{
+	struct fuse_service_iomap_command *oc =
+			container_of(p, struct fuse_service_iomap_command, p);
+	bool mandatory = false;
+	int ret;
+
+	if (oc->padding) {
+		fprintf(stderr, "mount.service: invalid iomap command\n");
+		mount_service_send_reply(mo, EINVAL);
+		return -1;
+	}
+
+	switch (ntohs(oc->mode)) {
+	case FUSE_IOMAP_MODE_MANDATORY:
+		mandatory = true;
+		/* fallthrough */
+	case FUSE_IOMAP_MODE_OPTIONAL:
+		ret = mount_service_config_iomap(mo, mandatory);
+		break;
+	default:
+		fprintf(stderr, "mount.service: invalid iomap command mode\n");
+		ret = -1;
+	}
+
+	if (ret < 0) {
+		mount_service_send_reply(mo, -ret);
+		return -1;
+	}
+
+	mount_service_send_reply(mo, 0);
+	return 0;
+}
+
 static int mount_service_handle_mount_cmd(struct mount_service *mo,
 					  struct fuse_service_packet *p)
 {
@@ -956,6 +1017,9 @@ int mount_service_main(int argc, char *argv[])
 		case FUSE_SERVICE_MNTPT_CMD:
 			ret = mount_service_handle_mountpoint_cmd(&mo, p);
 			break;
+		case FUSE_SERVICE_IOMAP_CMD:
+			ret = mount_service_handle_iomap_cmd(&mo, p);
+			break;
 		case FUSE_SERVICE_MOUNT_CMD:
 			ret = mount_service_handle_mount_cmd(&mo, p);
 			break;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 4/5] libfuse: enable setting iomap block device block size
  2026-02-23 23:03 ` [PATCHSET v7 5/6] libfuse: run fuse servers as a contained service Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:34   ` [PATCH 3/5] libfuse: delegate iomap privilege from mount.service to fuse services Darrick J. Wong
@ 2026-02-23 23:34   ` Darrick J. Wong
  2026-02-23 23:35   ` [PATCH 5/5] fuservicemount: create loop devices for regular files Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:34 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Create a means for an unprivileged fuse server to set the block size of
a block device that it previously opened and associated with the fuse
connection.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_kernel.h   |    7 +++++++
 include/fuse_lowlevel.h |   12 ++++++++++++
 lib/fuse_lowlevel.c     |   11 +++++++++++
 lib/fuse_versionscript  |    1 +
 4 files changed, 31 insertions(+)


diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 417f1d42b0618d..d9b65fe2395bde 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -1184,6 +1184,11 @@ struct fuse_iomap_support {
 	uint64_t	padding;
 };
 
+struct fuse_iomap_backing_info {
+	uint32_t	backing_id;
+	uint32_t	blocksize;
+};
+
 /* Device ioctls: */
 #define FUSE_DEV_IOC_MAGIC		229
 #define FUSE_DEV_IOC_CLONE		_IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
@@ -1194,6 +1199,8 @@ struct fuse_iomap_support {
 					     struct fuse_iomap_support)
 #define FUSE_DEV_IOC_SET_NOFS		_IOW(FUSE_DEV_IOC_MAGIC, 100, uint32_t)
 #define FUSE_DEV_IOC_ADD_IOMAP		_IO(FUSE_DEV_IOC_MAGIC, 101)
+#define FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE _IOW(FUSE_DEV_IOC_MAGIC, 102, \
+					      struct fuse_iomap_backing_info)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index eefc69360b8aa8..f0dba1918f09b6 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -2809,6 +2809,18 @@ int fuse_lowlevel_disable_fsreclaim(struct fuse_session *se, int val);
  */
 int fuse_lowlevel_add_iomap(int fd);
 
+/**
+ * Set the block size of an open block device that has been opened for use with
+ * iomap.
+ *
+ * @param fd open file descriptor to a fuse device
+ * @param dev_index device index returned by fuse_lowlevel_iomap_device_add
+ * @param blocksize block size in bytes
+ * @return 0 on success, -1 on failure with errno set
+ */
+int fuse_lowlevel_iomap_set_blocksize(int fd, int dev_index,
+				      unsigned int blocksize);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 4f27603400f2da..1549b1d339e24b 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -5354,3 +5354,14 @@ int fuse_lowlevel_add_iomap(int fd)
 {
 	return ioctl(fd, FUSE_DEV_IOC_ADD_IOMAP);
 }
+
+int fuse_lowlevel_iomap_set_blocksize(int fd, int dev_index,
+				      unsigned int blocksize)
+{
+	struct fuse_iomap_backing_info fbi = {
+		.backing_id = dev_index,
+		.blocksize = blocksize,
+	};
+
+	return ioctl(fd, FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE, &fbi);
+}
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 334a0f7cf3a096..5f1a50701a9ba9 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -268,6 +268,7 @@ FUSE_3.99 {
 		fuse_service_request_file;
 		fuse_service_send_goodbye;
 		fuse_service_take_fusedev;
+		fuse_lowlevel_iomap_set_blocksize;
 } FUSE_3.19;
 
 # Local Variables:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 5/5] fuservicemount: create loop devices for regular files
  2026-02-23 23:03 ` [PATCHSET v7 5/6] libfuse: run fuse servers as a contained service Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:34   ` [PATCH 4/5] libfuse: enable setting iomap block device block size Darrick J. Wong
@ 2026-02-23 23:35   ` Darrick J. Wong
  4 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:35 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, linux-fsdevel, bpf, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

If a fuse server asks fuservicemount to open a regular file, try to
create an auto-clear loop device so that the fuse server can use iomap.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_service.h      |    6 ++++++
 include/fuse_service_priv.h |    3 ++-
 lib/fuse_service.c          |    5 ++++-
 util/mount_service.c        |   34 ++++++++++++++++++++++++++++++++++
 4 files changed, 46 insertions(+), 2 deletions(-)


diff --git a/include/fuse_service.h b/include/fuse_service.h
index a88173a0e4c227..035ea57873e536 100644
--- a/include/fuse_service.h
+++ b/include/fuse_service.h
@@ -95,6 +95,12 @@ int fuse_service_take_fusedev(struct fuse_service *sfp);
 int fuse_service_parse_cmdline_opts(struct fuse_args *args,
 				    struct fuse_cmdline_opts *opts);
 
+/**
+ * If the file opened is a regular file, try to create a loop device for it.
+ * If successful, the loop device is returned; if not, the regular file is.
+ */
+#define FUSE_SERVICE_REQUEST_FILE_TRYLOOP	(1U << 0)
+
 /**
  * Ask the mount.service helper to open a file on behalf of the fuse server.
  *
diff --git a/include/fuse_service_priv.h b/include/fuse_service_priv.h
index f755710863c766..e8b6da260b089e 100644
--- a/include/fuse_service_priv.h
+++ b/include/fuse_service_priv.h
@@ -73,7 +73,8 @@ static inline size_t sizeof_fuse_service_requested_file(size_t pathlen)
 	return sizeof(struct fuse_service_requested_file) + pathlen + 1;
 }
 
-#define FUSE_SERVICE_OPEN_FLAGS		(0)
+#define FUSE_SERVICE_OPEN_TRYLOOP	(1U << 0)
+#define FUSE_SERVICE_OPEN_FLAGS		(FUSE_SERVICE_OPEN_TRYLOOP)
 
 struct fuse_service_open_command {
 	struct fuse_service_packet p;
diff --git a/lib/fuse_service.c b/lib/fuse_service.c
index a9fce8b022c005..bcab6913809dfd 100644
--- a/lib/fuse_service.c
+++ b/lib/fuse_service.c
@@ -152,7 +152,7 @@ int fuse_service_receive_file(struct fuse_service *sf, const char *path,
 	return recv_requested_file(sf->sockfd, path, fdp);
 }
 
-#define FUSE_SERVICE_REQUEST_FILE_FLAGS	(0)
+#define FUSE_SERVICE_REQUEST_FILE_FLAGS	(FUSE_SERVICE_REQUEST_FILE_TRYLOOP)
 
 int fuse_service_request_file(struct fuse_service *sf, const char *path,
 			      int open_flags, mode_t create_mode,
@@ -177,6 +177,9 @@ int fuse_service_request_file(struct fuse_service *sf, const char *path,
 		return -1;
 	}
 
+	if (request_flags & FUSE_SERVICE_REQUEST_FILE_TRYLOOP)
+		rqflags |= FUSE_SERVICE_OPEN_TRYLOOP;
+
 	cmd = calloc(1, iov.iov_len);
 	if (!cmd) {
 		perror("fuse: alloc service file request");
diff --git a/util/mount_service.c b/util/mount_service.c
index 241f47822deaa6..f1e2fc4c52092d 100644
--- a/util/mount_service.c
+++ b/util/mount_service.c
@@ -25,15 +25,20 @@
 #include <limits.h>
 #include <sys/stat.h>
 #include <arpa/inet.h>
+#ifdef HAVE_STRUCT_LOOP_CONFIG_INFO
+# include <linux/loop.h>
+#endif
 
 #include "mount_util.h"
 #include "util.h"
 #include "fuse_i.h"
 #include "fuse_service_priv.h"
+#include "fuse_loopdev.h"
 #include "mount_service.h"
 
 #define FUSE_KERN_DEVICE_ENV	"FUSE_KERN_DEVICE"
 #define FUSE_DEV		"/dev/fuse"
+#define LOOPCTL			"/dev/loop-control"
 
 struct mount_service {
 	/* alleged fuse subtype based on -t cli argument */
@@ -556,6 +561,35 @@ static int mount_service_handle_open_cmd(struct mount_service *mo,
 		return mount_service_send_file_error(mo, error, oc->path);
 	}
 
+	if (request_flags & FUSE_SERVICE_OPEN_TRYLOOP) {
+		int loop_fd = -1;
+
+		ret = fuse_loopdev_setup(fd, ntohl(oc->open_flags), oc->path,
+					 5, &loop_fd, NULL);
+		if (ret) {
+			/*
+			 * If the setup function returned EBUSY, there is
+			 * already a loop device backed by this file, so we
+			 * must return an error.  For any other type of error
+			 * we'll send back the first file we opened.
+			 */
+			if (errno == EBUSY) {
+				ret = mount_service_send_file_error(mo, errno,
+						oc->path);
+				close(fd);
+				return ret;
+			}
+		} else if (loop_fd >= 0) {
+			/*
+			 * Send back the loop device instead of the file.
+			 */
+			ret = mount_service_send_file(mo, oc->path, loop_fd);
+			close(loop_fd);
+			close(fd);
+			return ret;
+		}
+	}
+
 	ret = mount_service_send_file(mo, oc->path, fd);
 	close(fd);
 	return ret;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/3] libfuse: allow fuse servers to upload bpf code for iomap functions
  2026-02-23 23:04 ` [PATCHSET RFC 6/6] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
@ 2026-02-23 23:35   ` Darrick J. Wong
  2026-02-23 23:35   ` [PATCH 2/3] libfuse: add kfuncs for iomap bpf programs to manage the cache Darrick J. Wong
  2026-02-23 23:36   ` [PATCH 3/3] libfuse: make fuse_inode opaque to iomap bpf programs Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:35 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, john, linux-fsdevel, bpf,
	joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Create the necessary header files to enable lowlevel fuse servers to
compile their own BPF blobs that override iomap functions, and a bunch
of meson code to detect if the system is even capable of compiling BPF.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_iomap_bpf.h |  241 ++++++++++++++++++++++++++++++++++++++++++++++
 include/meson.build      |    3 -
 2 files changed, 243 insertions(+), 1 deletion(-)
 create mode 100644 include/fuse_iomap_bpf.h


diff --git a/include/fuse_iomap_bpf.h b/include/fuse_iomap_bpf.h
new file mode 100644
index 00000000000000..3e69fb33cbdd7c
--- /dev/null
+++ b/include/fuse_iomap_bpf.h
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ * Copied from: Joanne Koong <joannelkoong@gmail.com>
+ */
+#ifndef FUSE_IOMAP_BPF_H_
+#define FUSE_IOMAP_BPF_H_
+
+/* Note: You probably want to #include bpf_helpers and bpf_tracing.h */
+
+/*
+ * XXX: Avoid including fuse_lowlevel.h and fuse_kernel.h because their use of
+ * uint64_t (instead of u64 like the kernel requires for uapi) is extremely
+ * problematic due to the kernel and glibc not agreeing on the exact type
+ * definitions.  BPF is considered a separate architecture from the host
+ * machine, which complicates things further.
+ */
+
+/* mapping types; see corresponding IOMAP_TYPE_ */
+#define FUSE_IOMAP_TYPE_HOLE		(0)
+#define FUSE_IOMAP_TYPE_DELALLOC	(1)
+#define FUSE_IOMAP_TYPE_MAPPED		(2)
+#define FUSE_IOMAP_TYPE_UNWRITTEN	(3)
+#define FUSE_IOMAP_TYPE_INLINE		(4)
+
+/* fuse-specific mapping type indicating that writes use the read mapping */
+#define FUSE_IOMAP_TYPE_PURE_OVERWRITE	(255)
+/* fuse-specific mapping type saying the server has populated the cache */
+#define FUSE_IOMAP_TYPE_RETRY_CACHE	(254)
+/* do not upsert this mapping */
+#define FUSE_IOMAP_TYPE_NOCACHE		(253)
+
+#define FUSE_IOMAP_DEV_NULL		(0U)	/* null device cookie */
+
+/* mapping flags passed back from iomap_begin; see corresponding IOMAP_F_ */
+#define FUSE_IOMAP_F_NEW		(1U << 0)
+#define FUSE_IOMAP_F_DIRTY		(1U << 1)
+#define FUSE_IOMAP_F_SHARED		(1U << 2)
+#define FUSE_IOMAP_F_MERGED		(1U << 3)
+#define FUSE_IOMAP_F_BOUNDARY		(1U << 4)
+#define FUSE_IOMAP_F_ANON_WRITE		(1U << 5)
+#define FUSE_IOMAP_F_ATOMIC_BIO		(1U << 6)
+
+/* fuse-specific mapping flag asking for ->iomap_end call */
+#define FUSE_IOMAP_F_WANT_IOMAP_END	(1U << 7)
+
+/* mapping flags passed to iomap_end */
+#define FUSE_IOMAP_F_SIZE_CHANGED	(1U << 8)
+#define FUSE_IOMAP_F_STALE		(1U << 9)
+
+/* operation flags from iomap; see corresponding IOMAP_* */
+#define FUSE_IOMAP_OP_WRITE		(1U << 0)
+#define FUSE_IOMAP_OP_ZERO		(1U << 1)
+#define FUSE_IOMAP_OP_REPORT		(1U << 2)
+#define FUSE_IOMAP_OP_FAULT		(1U << 3)
+#define FUSE_IOMAP_OP_DIRECT		(1U << 4)
+#define FUSE_IOMAP_OP_NOWAIT		(1U << 5)
+#define FUSE_IOMAP_OP_OVERWRITE_ONLY	(1U << 6)
+#define FUSE_IOMAP_OP_UNSHARE		(1U << 7)
+#define FUSE_IOMAP_OP_DAX		(1U << 8)
+#define FUSE_IOMAP_OP_ATOMIC		(1U << 9)
+#define FUSE_IOMAP_OP_DONTCACHE		(1U << 10)
+
+/* swapfile config operation */
+#define FUSE_IOMAP_OP_SWAPFILE		(1U << 30)
+
+/* pagecache writeback operation */
+#define FUSE_IOMAP_OP_WRITEBACK		(1U << 31)
+
+#define FUSE_IOMAP_NULL_ADDR		(-1ULL)	/* addr is not valid */
+
+struct fuse_iomap_io {
+	uint64_t offset;	/* file offset of mapping, bytes */
+	uint64_t length;	/* length of mapping, bytes */
+	uint64_t addr;		/* disk offset of mapping, bytes */
+	uint16_t type;		/* FUSE_IOMAP_TYPE_* */
+	uint16_t flags;		/* FUSE_IOMAP_F_* */
+	uint32_t dev;		/* device cookie */
+};
+
+struct fuse_iomap_begin_in {
+	uint32_t opflags;	/* FUSE_IOMAP_OP_* */
+	uint32_t reserved;	/* zero */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+	uint64_t pos;		/* file position, in bytes */
+	uint64_t count;		/* operation length, in bytes */
+};
+
+struct fuse_iomap_begin_out {
+	/* read file data from here */
+	struct fuse_iomap_io	read;
+
+	/* write file data to here, if applicable */
+	struct fuse_iomap_io	write;
+};
+
+struct fuse_iomap_end_in {
+	uint32_t opflags;	/* FUSE_IOMAP_OP_* */
+	uint32_t reserved;	/* zero */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+	uint64_t pos;		/* file position, in bytes */
+	uint64_t count;		/* operation length, in bytes */
+	int64_t written;	/* bytes processed */
+
+	/* mapping that the kernel acted upon */
+	struct fuse_iomap_io	map;
+};
+
+/* out of place write extent */
+#define FUSE_IOMAP_IOEND_SHARED		(1U << 0)
+/* unwritten extent */
+#define FUSE_IOMAP_IOEND_UNWRITTEN	(1U << 1)
+/* don't merge into previous ioend */
+#define FUSE_IOMAP_IOEND_BOUNDARY	(1U << 2)
+/* is direct I/O */
+#define FUSE_IOMAP_IOEND_DIRECT		(1U << 3)
+/* is append ioend */
+#define FUSE_IOMAP_IOEND_APPEND		(1U << 4)
+/* is pagecache writeback */
+#define FUSE_IOMAP_IOEND_WRITEBACK	(1U << 5)
+/* swapfile deactivation */
+#define FUSE_IOMAP_IOEND_SWAPOFF	(1U << 6)
+
+struct fuse_iomap_ioend_in {
+	uint32_t flags;		/* FUSE_IOMAP_IOEND_* */
+	int32_t error;		/* negative errno or 0 */
+	uint64_t attr_ino;	/* matches fuse_attr:ino */
+	uint64_t pos;		/* file position, in bytes */
+	uint64_t new_addr;	/* disk offset of new mapping, in bytes */
+	uint64_t written;	/* bytes processed */
+	uint32_t dev;		/* device cookie */
+	uint32_t pad;		/* zero */
+};
+
+struct fuse_iomap_ioend_out {
+	uint64_t newsize;	/* new ondisk size */
+};
+
+/* Signal that reads and writes go to the same storage. */
+static inline void
+fuse_iomap_begin_pure_overwrite(struct fuse_iomap_begin_out *outarg)
+{
+	outarg->write.addr = FUSE_IOMAP_NULL_ADDR;
+	outarg->write.offset = outarg->read.offset;
+	outarg->write.length = outarg->read.length;
+	outarg->write.type = FUSE_IOMAP_TYPE_PURE_OVERWRITE;
+	outarg->write.flags = 0;
+	outarg->write.dev = FUSE_IOMAP_DEV_NULL;
+}
+
+enum fuse_iomap_bpf_ret {
+	/* fall back to fuse server upcall */
+	FIB_FALLBACK = 0,
+	/* bpf function handled event completely */
+	FIB_HANDLED = 1,
+};
+
+struct fuse_iomap_bpf_ops {
+	/**
+	 * @iomap_begin: override iomap_begin.  See FUSE_IOMAP_BEGIN for
+	 * details.
+	 */
+	enum fuse_iomap_bpf_ret (*iomap_begin)(struct fuse_inode *fi,
+			uint64_t pos, uint64_t count, uint32_t opflags,
+			struct fuse_iomap_begin_out *outarg);
+
+	/**
+	 * @iomap_end: override iomap_end.  See FUSE_IOMAP_END for
+	 * details.
+	 */
+	enum fuse_iomap_bpf_ret (*iomap_end)(struct fuse_inode *fi,
+			uint64_t pos, uint64_t count, int64_t written,
+			uint32_t opflags);
+
+	/**
+	 * @iomap_ioend: override iomap_ioend.  See FUSE_IOMAP_IOEND for
+	 * details.
+	 */
+	enum fuse_iomap_bpf_ret (*iomap_ioend)(struct fuse_inode *fi,
+			uint64_t pos, int64_t written, uint32_t ioendflags,
+			int error, uint32_t dev, uint64_t new_addr,
+			struct fuse_iomap_ioend_out *outarg);
+
+	/**
+	 * @fuse_fd: file descriptor of the open fuse device
+	 */
+	int fuse_fd;
+
+	/**
+	 * @zeropad: Explicitly pad to zero.
+	 */
+	unsigned int zeropad;
+
+	/**
+	 * @name: string describing the fuse iomap bpf operations
+	 */
+	char name[16];
+};
+
+/* BPF code must be GPLv2 */
+#define DECLARE_GPL2_LICENSE_FOR_FUSE_IOMAP_BPF \
+	char LICENSE[] SEC("license") = "GPL v2";
+
+/* Macros to handle creating iomap_ops override functions */
+#define FUSE_IOMAP_BEGIN_BPF_FUNC(name) \
+SEC("struct_ops/iomap_begin") \
+enum fuse_iomap_bpf_ret BPF_PROG(name, struct fuse_inode *fi, \
+		uint64_t pos, uint64_t count, uint32_t opflags, \
+		struct fuse_iomap_begin_out *outarg)
+
+#define FUSE_IOMAP_END_BPF_FUNC(name) \
+SEC("struct_ops/iomap_end") \
+enum fuse_iomap_bpf_ret BPF_PROG(name, struct fuse_inode *fi, \
+		uint64_t pos, uint64_t count, int64_t written, \
+		uint32_t opflags)
+
+#define FUSE_IOMAP_IOEND_BPF_FUNC(name) \
+SEC("struct_ops/iomap_ioend") \
+enum fuse_iomap_bpf_ret BPF_PROG(name, struct fuse_inode *fi, \
+		uint64_t pos, int64_t written, uint32_t ioendflags, int error, \
+		uint32_t dev, uint64_t new_addr, \
+		struct fuse_iomap_ioend_out *outarg)
+
+/*
+ * XXX: The BPF compiler plays some weird shenanigans with argument passing
+ * conventions, which means that the actual function signature of BPF_PROG
+ * functions does not actually match the C definitions.  Hence the horrible
+ * (void *) casts below.
+ */
+#define DEFINE_FUSE_IOMAP_BPF_OPS(ops_name, fancy_name, begin_fn, end_fn, \
+				  ioend_fn) \
+SEC(".struct_ops.link") \
+struct fuse_iomap_bpf_ops ops_name = { \
+	.iomap_begin	= (void *)begin_fn, \
+	.iomap_end	= (void *)end_fn, \
+	.iomap_ioend	= (void *)ioend_fn, \
+	.name		= fancy_name, \
+}
+
+#endif /* FUSE_IOMAP_BPF_H_ */
diff --git a/include/meson.build b/include/meson.build
index 5ab4ecf052bf56..17f03df560475a 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -1,5 +1,6 @@
 libfuse_headers = [ 'fuse.h', 'fuse_common.h', 'fuse_lowlevel.h',
-	            'fuse_opt.h', 'cuse_lowlevel.h', 'fuse_log.h' ]
+	            'fuse_opt.h', 'cuse_lowlevel.h', 'fuse_log.h',
+                    'fuse_iomap_bpf.h' ]
 
 if private_cfg.get('FUSE_LOOPDEV_ENABLED')
   libfuse_headers += [ 'fuse_loopdev.h' ]


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/3] libfuse: add kfuncs for iomap bpf programs to manage the cache
  2026-02-23 23:04 ` [PATCHSET RFC 6/6] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
  2026-02-23 23:35   ` [PATCH 1/3] libfuse: allow fuse servers to upload bpf code for iomap functions Darrick J. Wong
@ 2026-02-23 23:35   ` Darrick J. Wong
  2026-02-23 23:36   ` [PATCH 3/3] libfuse: make fuse_inode opaque to iomap bpf programs Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:35 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, john, linux-fsdevel, bpf,
	joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Add a couple of kfuncs so that a BPF program that generates iomappings
can add them to the inode's mapping cache, thereby avoiding the need to
go into BPF program on the next access.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_iomap_bpf.h |   28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)


diff --git a/include/fuse_iomap_bpf.h b/include/fuse_iomap_bpf.h
index 3e69fb33cbdd7c..1ff8f1831e12f6 100644
--- a/include/fuse_iomap_bpf.h
+++ b/include/fuse_iomap_bpf.h
@@ -149,6 +149,14 @@ fuse_iomap_begin_pure_overwrite(struct fuse_iomap_begin_out *outarg)
 	outarg->write.dev = FUSE_IOMAP_DEV_NULL;
 }
 
+struct fuse_range {
+	uint64_t offset;
+	uint64_t length;
+};
+
+/* invalidate all cached iomap mappings up to EOF */
+#define FUSE_IOMAP_INVAL_TO_EOF		(~0ULL)
+
 enum fuse_iomap_bpf_ret {
 	/* fall back to fuse server upcall */
 	FIB_FALLBACK = 0,
@@ -204,20 +212,20 @@ struct fuse_iomap_bpf_ops {
 
 /* Macros to handle creating iomap_ops override functions */
 #define FUSE_IOMAP_BEGIN_BPF_FUNC(name) \
-SEC("struct_ops/iomap_begin") \
-enum fuse_iomap_bpf_ret BPF_PROG(name, struct fuse_inode *fi, \
+SEC("struct_ops.s/iomap_begin") \
+enum fuse_iomap_bpf_ret BPF_PROG(name, struct struct fuse_inode *fi, \
 		uint64_t pos, uint64_t count, uint32_t opflags, \
 		struct fuse_iomap_begin_out *outarg)
 
 #define FUSE_IOMAP_END_BPF_FUNC(name) \
-SEC("struct_ops/iomap_end") \
-enum fuse_iomap_bpf_ret BPF_PROG(name, struct fuse_inode *fi, \
+SEC("struct_ops.s/iomap_end") \
+enum fuse_iomap_bpf_ret BPF_PROG(name, struct struct fuse_inode *fi, \
 		uint64_t pos, uint64_t count, int64_t written, \
 		uint32_t opflags)
 
 #define FUSE_IOMAP_IOEND_BPF_FUNC(name) \
-SEC("struct_ops/iomap_ioend") \
-enum fuse_iomap_bpf_ret BPF_PROG(name, struct fuse_inode *fi, \
+SEC("struct_ops.s/iomap_ioend") \
+enum fuse_iomap_bpf_ret BPF_PROG(name, struct struct fuse_inode *fi, \
 		uint64_t pos, int64_t written, uint32_t ioendflags, int error, \
 		uint32_t dev, uint64_t new_addr, \
 		struct fuse_iomap_ioend_out *outarg)
@@ -238,4 +246,12 @@ struct fuse_iomap_bpf_ops ops_name = { \
 	.name		= fancy_name, \
 }
 
+/* kfuncs; these require __ksym to link correctly! */
+int __ksym fuse_bpf_iomap_inval_mappings(struct fuse_inode *fi,
+		const struct fuse_range *read__nullable,
+		const struct fuse_range *write__nullable);
+int __ksym fuse_bpf_iomap_upsert_mappings(struct fuse_inode *fi,
+		const struct fuse_iomap_io *read__nullable,
+		const struct fuse_iomap_io *write__nullable);
+
 #endif /* FUSE_IOMAP_BPF_H_ */


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/3] libfuse: make fuse_inode opaque to iomap bpf programs
  2026-02-23 23:04 ` [PATCHSET RFC 6/6] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
  2026-02-23 23:35   ` [PATCH 1/3] libfuse: allow fuse servers to upload bpf code for iomap functions Darrick J. Wong
  2026-02-23 23:35   ` [PATCH 2/3] libfuse: add kfuncs for iomap bpf programs to manage the cache Darrick J. Wong
@ 2026-02-23 23:36   ` Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:36 UTC (permalink / raw)
  To: djwong, bschubert
  Cc: bernd, miklos, neal, linux-ext4, john, linux-fsdevel, bpf,
	joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Introduce an opaque type (and some casting helpers) for struct
fuse_inode.  This tricks BTF/BPF into thinking that the "inode" object
we pass to BPF programs is an empty structure, which means that the BPF
program cannot even look at the contents.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 include/fuse_iomap_bpf.h |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)


diff --git a/include/fuse_iomap_bpf.h b/include/fuse_iomap_bpf.h
index 1ff8f1831e12f6..ec2c3a1e5655af 100644
--- a/include/fuse_iomap_bpf.h
+++ b/include/fuse_iomap_bpf.h
@@ -164,12 +164,15 @@ enum fuse_iomap_bpf_ret {
 	FIB_HANDLED = 1,
 };
 
+/* opaque structure for calling bpf kfuncs */
+struct fuse_bpf_inode { };
+
 struct fuse_iomap_bpf_ops {
 	/**
 	 * @iomap_begin: override iomap_begin.  See FUSE_IOMAP_BEGIN for
 	 * details.
 	 */
-	enum fuse_iomap_bpf_ret (*iomap_begin)(struct fuse_inode *fi,
+	enum fuse_iomap_bpf_ret (*iomap_begin)(struct fuse_bpf_inode *fbi,
 			uint64_t pos, uint64_t count, uint32_t opflags,
 			struct fuse_iomap_begin_out *outarg);
 
@@ -177,7 +180,7 @@ struct fuse_iomap_bpf_ops {
 	 * @iomap_end: override iomap_end.  See FUSE_IOMAP_END for
 	 * details.
 	 */
-	enum fuse_iomap_bpf_ret (*iomap_end)(struct fuse_inode *fi,
+	enum fuse_iomap_bpf_ret (*iomap_end)(struct fuse_bpf_inode *fbi,
 			uint64_t pos, uint64_t count, int64_t written,
 			uint32_t opflags);
 
@@ -185,7 +188,7 @@ struct fuse_iomap_bpf_ops {
 	 * @iomap_ioend: override iomap_ioend.  See FUSE_IOMAP_IOEND for
 	 * details.
 	 */
-	enum fuse_iomap_bpf_ret (*iomap_ioend)(struct fuse_inode *fi,
+	enum fuse_iomap_bpf_ret (*iomap_ioend)(struct fuse_bpf_inode *fbi,
 			uint64_t pos, int64_t written, uint32_t ioendflags,
 			int error, uint32_t dev, uint64_t new_addr,
 			struct fuse_iomap_ioend_out *outarg);
@@ -213,19 +216,19 @@ struct fuse_iomap_bpf_ops {
 /* Macros to handle creating iomap_ops override functions */
 #define FUSE_IOMAP_BEGIN_BPF_FUNC(name) \
 SEC("struct_ops.s/iomap_begin") \
-enum fuse_iomap_bpf_ret BPF_PROG(name, struct struct fuse_inode *fi, \
+enum fuse_iomap_bpf_ret BPF_PROG(name, struct fuse_bpf_inode *fbi, \
 		uint64_t pos, uint64_t count, uint32_t opflags, \
 		struct fuse_iomap_begin_out *outarg)
 
 #define FUSE_IOMAP_END_BPF_FUNC(name) \
 SEC("struct_ops.s/iomap_end") \
-enum fuse_iomap_bpf_ret BPF_PROG(name, struct struct fuse_inode *fi, \
+enum fuse_iomap_bpf_ret BPF_PROG(name, struct fuse_bpf_inode *fbi, \
 		uint64_t pos, uint64_t count, int64_t written, \
 		uint32_t opflags)
 
 #define FUSE_IOMAP_IOEND_BPF_FUNC(name) \
 SEC("struct_ops.s/iomap_ioend") \
-enum fuse_iomap_bpf_ret BPF_PROG(name, struct struct fuse_inode *fi, \
+enum fuse_iomap_bpf_ret BPF_PROG(name, struct fuse_bpf_inode *fbi, \
 		uint64_t pos, int64_t written, uint32_t ioendflags, int error, \
 		uint32_t dev, uint64_t new_addr, \
 		struct fuse_iomap_ioend_out *outarg)
@@ -247,11 +250,14 @@ struct fuse_iomap_bpf_ops ops_name = { \
 }
 
 /* kfuncs; these require __ksym to link correctly! */
-int __ksym fuse_bpf_iomap_inval_mappings(struct fuse_inode *fi,
+int __ksym fuse_bpf_iomap_inval_mappings(struct fuse_bpf_inode *fbi,
 		const struct fuse_range *read__nullable,
 		const struct fuse_range *write__nullable);
-int __ksym fuse_bpf_iomap_upsert_mappings(struct fuse_inode *fi,
+int __ksym fuse_bpf_iomap_upsert_mappings(struct fuse_bpf_inode *fbi,
 		const struct fuse_iomap_io *read__nullable,
 		const struct fuse_iomap_io *write__nullable);
 
+uint64_t __ksym fuse_bpf_inode_nodeid(const struct fuse_bpf_inode *fbi);
+uint64_t __ksym fuse_bpf_inode_orig_ino(const struct fuse_bpf_inode *fbi);
+
 #endif /* FUSE_IOMAP_BPF_H_ */


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 01/19] fuse2fs: implement bare minimum iomap for file mapping reporting
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
@ 2026-02-23 23:36   ` Darrick J. Wong
  2026-02-23 23:36   ` [PATCH 02/19] fuse2fs: add iomap= mount option Darrick J. Wong
                     ` (17 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:36 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Add enough of an iomap implementation that we can do FIEMAP and
SEEK_DATA and SEEK_HOLE.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 configure         |   49 +++++
 configure.ac      |   31 +++
 fuse4fs/fuse4fs.c |  533 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/config.h.in   |    3 
 misc/fuse2fs.c    |  533 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1147 insertions(+), 2 deletions(-)


diff --git a/configure b/configure
index d189adbdeb896d..03b17d07771117 100755
--- a/configure
+++ b/configure
@@ -14578,6 +14578,7 @@ printf "%s\n" "yes" >&6; }
 fi
 
 
+have_fuse_iomap=
 if test -n "$FUSE_LIB"
 then
 	FUSE_USE_VERSION=314
@@ -14604,12 +14605,60 @@ esac
 fi
 
 done
+
+					{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for iomap_begin in libfuse" >&5
+printf %s "checking for iomap_begin in libfuse... " >&6; }
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+	#define _GNU_SOURCE
+	#define _FILE_OFFSET_BITS	64
+	#define FUSE_USE_VERSION	399
+	#include <fuse.h>
+
+int
+main (void)
+{
+
+	struct fuse_operations fs_ops = {
+		.iomap_begin = NULL,
+		.iomap_end = NULL,
+	};
+	struct fuse_file_iomap narf = { };
+
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"
+then :
+  have_fuse_iomap=yes
+	   { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
+else case e in #(
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; } ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext conftest.$ac_ext
+	if test "$have_fuse_iomap" = yes
+	then
+		FUSE_USE_VERSION=399
+	fi
 fi
 if test -n "$FUSE_USE_VERSION"
 then
 
 printf "%s\n" "#define FUSE_USE_VERSION $FUSE_USE_VERSION" >>confdefs.h
 
+fi
+if test -n "$have_fuse_iomap"
+then
+
+printf "%s\n" "#define HAVE_FUSE_IOMAP 1" >>confdefs.h
+
 fi
 
 have_fuse_lowlevel=
diff --git a/configure.ac b/configure.ac
index 39f2dfebf3b4ee..6ccb1fdc444adc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1382,6 +1382,7 @@ dnl
 dnl Set FUSE_USE_VERSION, which is how fuse servers build against a particular
 dnl libfuse ABI.  Currently we link against the libfuse 3.14 ABI (hence 314)
 dnl
+have_fuse_iomap=
 if test -n "$FUSE_LIB"
 then
 	FUSE_USE_VERSION=314
@@ -1391,12 +1392,42 @@ then
 		[AC_MSG_FAILURE([Cannot build against fuse3 headers])],
 [#define _FILE_OFFSET_BITS	64
 #define FUSE_USE_VERSION	314])
+
+	dnl
+	dnl Check if the fuse library supports iomap, which requires a higher
+	dnl FUSE_USE_VERSION ABI version (3.99)
+	dnl
+	AC_MSG_CHECKING(for iomap_begin in libfuse)
+	AC_LINK_IFELSE(
+	[	AC_LANG_PROGRAM([[
+	#define _GNU_SOURCE
+	#define _FILE_OFFSET_BITS	64
+	#define FUSE_USE_VERSION	399
+	#include <fuse.h>
+		]], [[
+	struct fuse_operations fs_ops = {
+		.iomap_begin = NULL,
+		.iomap_end = NULL,
+	};
+	struct fuse_file_iomap narf = { };
+		]])
+	], have_fuse_iomap=yes
+	   AC_MSG_RESULT(yes),
+	   AC_MSG_RESULT(no))
+	if test "$have_fuse_iomap" = yes
+	then
+		FUSE_USE_VERSION=399
+	fi
 fi
 if test -n "$FUSE_USE_VERSION"
 then
 	AC_DEFINE_UNQUOTED(FUSE_USE_VERSION, $FUSE_USE_VERSION,
 		[Define to the version of FUSE to use])
 fi
+if test -n "$have_fuse_iomap"
+then
+	AC_DEFINE(HAVE_FUSE_IOMAP, 1, [Define to 1 if fuse supports iomap])
+fi
 
 dnl
 dnl Check if the FUSE lowlevel library is supported
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 9dfc6d57c35a71..a98cbc5234715d 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -143,6 +143,9 @@ static inline uint64_t round_down(uint64_t b, unsigned int align)
 	return b - m;
 }
 
+#define max(a, b)	((a) > (b) ? (a) : (b))
+#define min(a, b)	((a) < (b) ? (a) : (b))
+
 #define dbg_printf(fuse4fs, format, ...) \
 	while ((fuse4fs)->debug) { \
 		printf("FUSE4FS (%s): tid=%d " format, (fuse4fs)->shortdev, gettid(), ##__VA_ARGS__); \
@@ -221,6 +224,14 @@ enum fuse4fs_opstate {
 	F4OP_SHUTDOWN,
 };
 
+#ifdef HAVE_FUSE_IOMAP
+enum fuse4fs_iomap_state {
+	IOMAP_DISABLED,
+	IOMAP_UNKNOWN,
+	IOMAP_ENABLED,
+};
+#endif
+
 /* Main program context */
 #define FUSE4FS_MAGIC		(0xEF53DEADUL)
 struct fuse4fs {
@@ -248,6 +259,9 @@ struct fuse4fs {
 	int logfd;
 	int blocklog;
 	int oom_score_adj;
+#ifdef HAVE_FUSE_IOMAP
+	enum fuse4fs_iomap_state iomap_state;
+#endif
 	unsigned int blockmask;
 	unsigned long offset;
 	unsigned int next_generation;
@@ -854,6 +868,15 @@ fuse4fs_set_handle(struct fuse_file_info *fp, struct fuse4fs_file_handle *fh)
 	fp->keep_cache = 1;
 }
 
+#ifdef HAVE_FUSE_IOMAP
+static inline int fuse4fs_iomap_enabled(const struct fuse4fs *ff)
+{
+	return ff->iomap_state >= IOMAP_ENABLED;
+}
+#else
+# define fuse4fs_iomap_enabled(...)	(0)
+#endif
+
 static void get_now(struct timespec *now)
 {
 #ifdef CLOCK_REALTIME
@@ -1309,7 +1332,7 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 	char options[128];
 	double deadline;
 	int flags = EXT2_FLAG_64BITS | EXT2_FLAG_THREADS | EXT2_FLAG_RW |
-		    EXT2_FLAG_EXCLUSIVE;
+		    EXT2_FLAG_EXCLUSIVE | EXT2_FLAG_WRITE_FULL_SUPER;
 	errcode_t err;
 
 	if (ff->lockfile) {
@@ -1600,6 +1623,15 @@ static void op_destroy(void *userdata)
 				(stats->cache_hits + stats->cache_misses));
 	}
 
+	/*
+	 * If we're mounting in iomap mode, we need to unmount in op_destroy so
+	 * that the block device will be released before umount(2) returns.
+	 */
+	if (ff->iomap_state == IOMAP_ENABLED) {
+		fuse4fs_mmp_cancel(ff);
+		fuse4fs_unmount(ff);
+	}
+
 	fuse4fs_finish(ff, 0);
 }
 
@@ -1736,6 +1768,37 @@ static inline int fuse_set_feature_flag(struct fuse_conn_info *conn,
 }
 #endif
 
+#ifdef HAVE_FUSE_IOMAP
+static inline bool fuse4fs_wants_iomap(struct fuse4fs *ff)
+{
+	if (ff->iomap_state == IOMAP_DISABLED)
+		return false;
+
+	/* iomap only works with block devices */
+	if (!(ff->fs->io->flags & CHANNEL_FLAGS_BLOCK_DEVICE))
+		return false;
+
+	return true;
+}
+
+static void fuse4fs_iomap_enable(struct fuse_conn_info *conn,
+				 struct fuse4fs *ff)
+{
+	/* Don't let anyone touch iomap until the end of the patchset. */
+	ff->iomap_state = IOMAP_DISABLED;
+	return;
+
+	if (fuse4fs_wants_iomap(ff) &&
+	    fuse_set_feature_flag(conn, FUSE_CAP_IOMAP))
+		ff->iomap_state = IOMAP_ENABLED;
+
+	if (ff->iomap_state == IOMAP_UNKNOWN)
+		ff->iomap_state = IOMAP_DISABLED;
+}
+#else
+# define fuse4fs_iomap_enable(...)	((void)0)
+#endif
+
 static void op_init(void *userdata, struct fuse_conn_info *conn)
 {
 	struct fuse4fs *ff = userdata;
@@ -1758,6 +1821,7 @@ static void op_init(void *userdata, struct fuse_conn_info *conn)
 #ifdef FUSE_CAP_NO_EXPORT_SUPPORT
 	fuse_set_feature_flag(conn, FUSE_CAP_NO_EXPORT_SUPPORT);
 #endif
+	fuse4fs_iomap_enable(conn, ff);
 	conn->time_gran = 1;
 
 	if (ff->opstate == F4OP_WRITABLE)
@@ -5705,6 +5769,466 @@ static void op_fallocate(fuse_req_t req, fuse_ino_t fino EXT2FS_ATTR((unused)),
 }
 #endif /* SUPPORT_FALLOCATE */
 
+#ifdef HAVE_FUSE_IOMAP
+static void fuse4fs_iomap_hole(struct fuse4fs *ff, struct fuse_file_iomap *iomap,
+			       off_t pos, uint64_t count)
+{
+	iomap->dev = FUSE_IOMAP_DEV_NULL;
+	iomap->addr = FUSE_IOMAP_NULL_ADDR;
+	iomap->offset = pos;
+	iomap->length = count;
+	iomap->type = FUSE_IOMAP_TYPE_HOLE;
+}
+
+static void fuse4fs_iomap_hole_to_eof(struct fuse4fs *ff,
+				      struct fuse_file_iomap *iomap, off_t pos,
+				      off_t count,
+				      const struct ext2_inode_large *inode)
+{
+	ext2_filsys fs = ff->fs;
+	uint64_t isize = EXT2_I_SIZE(inode);
+
+	/*
+	 * We have to be careful about handling a hole to the right of the
+	 * entire mapping tree.  First, the mapping must start and end on a
+	 * block boundary because they must be aligned to at least an LBA for
+	 * the block layer; and to the fsblock for smoother operation.
+	 *
+	 * As for the length -- we could return a mapping all the way to
+	 * i_size, but i_size could be less than pos/count if we're zeroing the
+	 * EOF block in anticipation of a truncate operation.  Similarly, we
+	 * don't want to end the mapping at pos+count because we know there's
+	 * nothing mapped byeond here.
+	 */
+	uint64_t startoff = round_down(pos, fs->blocksize);
+	uint64_t eofoff = round_up(max(pos + count, isize), fs->blocksize);
+
+	dbg_printf(ff,
+ "pos=0x%llx count=0x%llx isize=0x%llx startoff=0x%llx eofoff=0x%llx\n",
+		   (unsigned long long)pos,
+		   (unsigned long long)count,
+		   (unsigned long long)isize,
+		   (unsigned long long)startoff,
+		   (unsigned long long)eofoff);
+
+	fuse4fs_iomap_hole(ff, iomap, startoff, eofoff - startoff);
+}
+
+#define DEBUG_IOMAP
+#ifdef DEBUG_IOMAP
+# define __DUMP_EXTENT(ff, func, tag, startoff, err, extent) \
+	do { \
+		dbg_printf((ff), \
+ "%s: %s startoff 0x%llx err %ld lblk 0x%llx pblk 0x%llx len 0x%x flags 0x%x\n", \
+			   (func), (tag), (startoff), (err), (extent)->e_lblk, \
+			   (extent)->e_pblk, (extent)->e_len, \
+			   (extent)->e_flags & EXT2_EXTENT_FLAGS_UNINIT); \
+	} while(0)
+# define DUMP_EXTENT(ff, tag, startoff, err, extent) \
+	__DUMP_EXTENT((ff), __func__, (tag), (startoff), (err), (extent))
+
+# define __DUMP_INFO(ff, func, tag, startoff, err, info) \
+	do { \
+		dbg_printf((ff), \
+ "%s: %s startoff 0x%llx err %ld entry %d/%d/%d level  %d/%d\n", \
+			   (func), (tag), (startoff), (err), \
+			   (info)->curr_entry, (info)->num_entries, \
+			   (info)->max_entries, (info)->curr_level, \
+			   (info)->max_depth); \
+	} while(0)
+# define DUMP_INFO(ff, tag, startoff, err, info) \
+	__DUMP_INFO((ff), __func__, (tag), (startoff), (err), (info))
+#else
+# define __DUMP_EXTENT(...)	((void)0)
+# define DUMP_EXTENT(...)	((void)0)
+# define DUMP_INFO(...)		((void)0)
+#endif
+
+static inline errcode_t __fuse4fs_get_mapping_at(struct fuse4fs *ff,
+						 ext2_extent_handle_t handle,
+						 blk64_t startoff,
+						 struct ext2fs_extent *bmap,
+						 const char *func)
+{
+	errcode_t err;
+
+	/*
+	 * Find the file mapping at startoff.  We don't check the return value
+	 * of _goto because _get will error out if _goto failed.  There's a
+	 * subtlety to the outcome of _goto when startoff falls in a sparse
+	 * hole however:
+	 *
+	 * Most of the time, _goto points the cursor at the mapping whose lblk
+	 * is just to the left of startoff.  The mapping may or may not overlap
+	 * startoff; this is ok.  In other words, the tree lookup behaves as if
+	 * we asked it to use a less than or equals comparison.
+	 *
+	 * However, if startoff is to the left of the first mapping in the
+	 * extent tree, _goto points the cursor at that first mapping because
+	 * it doesn't know how to deal with this situation.  In this case,
+	 * the tree lookup behaves as if we asked it to use a greater than
+	 * or equals comparison.
+	 *
+	 * Note: If _get() returns 'no current node', that means that there
+	 * aren't any mappings at all.
+	 */
+	ext2fs_extent_goto(handle, startoff);
+	err = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, bmap);
+	__DUMP_EXTENT(ff, func, "lookup", startoff, err, bmap);
+	if (err == EXT2_ET_NO_CURRENT_NODE)
+		err = EXT2_ET_EXTENT_NOT_FOUND;
+	return err;
+}
+
+static inline errcode_t __fuse4fs_get_next_mapping(struct fuse4fs *ff,
+						   ext2_extent_handle_t handle,
+						   blk64_t startoff,
+						   struct ext2fs_extent *bmap,
+						   const char *func)
+{
+	struct ext2fs_extent newex;
+	struct ext2_extent_info info;
+	errcode_t err;
+
+	/*
+	 * The extent tree code has this (probably broken) behavior that if
+	 * more than two of the highest levels of the cursor point at the
+	 * rightmost edge of an extent tree block, a _NEXT_LEAF movement fails
+	 * to move the cursor position of any of the lower levels.  IOWs, if
+	 * leaf level N is at the right edge, it will only advance level N-1
+	 * to the right.  If N-1 was at the right edge, the cursor resets to
+	 * record 0 of that level and goes down to the wrong leaf.
+	 *
+	 * Work around this by walking up (towards root level 0) the extent
+	 * tree until we find a level where we're not already at the rightmost
+	 * edge.  The _NEXT_LEAF movement will walk down the tree to find the
+	 * leaves.
+	 */
+	err = ext2fs_extent_get_info(handle, &info);
+	DUMP_INFO(ff, "UP?", startoff, err, &info);
+	if (err)
+		return err;
+
+	while (info.curr_entry == info.num_entries && info.curr_level > 0) {
+		err = ext2fs_extent_get(handle, EXT2_EXTENT_UP, &newex);
+		DUMP_EXTENT(ff, "UP", startoff, err, &newex);
+		if (err)
+			return err;
+		err = ext2fs_extent_get_info(handle, &info);
+		DUMP_INFO(ff, "UP", startoff, err, &info);
+		if (err)
+			return err;
+	}
+
+	/*
+	 * If we're at the root and there are no more entries, there's nothing
+	 * else to be found.
+	 */
+	if (info.curr_level == 0 && info.curr_entry == info.num_entries)
+		return EXT2_ET_EXTENT_NOT_FOUND;
+
+	/* Otherwise grab this next leaf and return it. */
+	err = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT_LEAF, &newex);
+	DUMP_EXTENT(ff, "NEXT", startoff, err, &newex);
+	if (err)
+		return err;
+
+	*bmap = newex;
+	return 0;
+}
+
+#define fuse4fs_get_mapping_at(ff, handle, startoff, bmap) \
+	__fuse4fs_get_mapping_at((ff), (handle), (startoff), (bmap), __func__)
+#define fuse4fs_get_next_mapping(ff, handle, startoff, bmap) \
+	__fuse4fs_get_next_mapping((ff), (handle), (startoff), (bmap), __func__)
+
+static errcode_t fuse4fs_iomap_begin_extent(struct fuse4fs *ff, uint64_t ino,
+					    struct ext2_inode_large *inode,
+					    off_t pos, uint64_t count,
+					    uint32_t opflags,
+					    struct fuse_file_iomap *iomap)
+{
+	ext2_extent_handle_t handle;
+	struct ext2fs_extent extent = { };
+	ext2_filsys fs = ff->fs;
+	const blk64_t startoff = FUSE4FS_B_TO_FSBT(ff, pos);
+	errcode_t err;
+	int ret = 0;
+
+	err = ext2fs_extent_open2(fs, ino, EXT2_INODE(inode), &handle);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	err = fuse4fs_get_mapping_at(ff, handle, startoff, &extent);
+	if (err == EXT2_ET_EXTENT_NOT_FOUND) {
+		/* No mappings at all; the whole range is a hole. */
+		fuse4fs_iomap_hole_to_eof(ff, iomap, pos, count, inode);
+		goto out_handle;
+	}
+	if (err) {
+		ret = translate_error(fs, ino, err);
+		goto out_handle;
+	}
+
+	if (startoff < extent.e_lblk) {
+		/*
+		 * Mapping starts to the right of the current position.
+		 * Synthesize a hole going to that next extent.
+		 */
+		fuse4fs_iomap_hole(ff, iomap, FUSE4FS_FSB_TO_B(ff, startoff),
+				FUSE4FS_FSB_TO_B(ff, extent.e_lblk - startoff));
+		goto out_handle;
+	}
+
+	if (startoff >= extent.e_lblk + extent.e_len) {
+		/*
+		 * Mapping ends to the left of the current position.  Try to
+		 * find the next mapping.  If there is no next mapping, the
+		 * whole range is in a hole.
+		 */
+		err = fuse4fs_get_next_mapping(ff, handle, startoff, &extent);
+		if (err == EXT2_ET_EXTENT_NOT_FOUND) {
+			fuse4fs_iomap_hole_to_eof(ff, iomap, pos, count, inode);
+			goto out_handle;
+		}
+
+		/*
+		 * If the new mapping starts to the right of startoff, there's
+		 * a hole from startoff to the start of the new mapping.
+		 */
+		if (startoff < extent.e_lblk) {
+			fuse4fs_iomap_hole(ff, iomap,
+				FUSE4FS_FSB_TO_B(ff, startoff),
+				FUSE4FS_FSB_TO_B(ff, extent.e_lblk - startoff));
+			goto out_handle;
+		}
+
+		/*
+		 * The new mapping starts at startoff.  Something weird
+		 * happened in the extent tree lookup, but we found a valid
+		 * mapping so we'll run with it.
+		 */
+	}
+
+	/* Mapping overlaps startoff, report this. */
+	iomap->dev = FUSE_IOMAP_DEV_NULL;
+	iomap->addr = FUSE4FS_FSB_TO_B(ff, extent.e_pblk);
+	iomap->offset = FUSE4FS_FSB_TO_B(ff, extent.e_lblk);
+	iomap->length = FUSE4FS_FSB_TO_B(ff, extent.e_len);
+	if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT)
+		iomap->type = FUSE_IOMAP_TYPE_UNWRITTEN;
+	else
+		iomap->type = FUSE_IOMAP_TYPE_MAPPED;
+
+out_handle:
+	ext2fs_extent_free(handle);
+	return ret;
+}
+
+static int fuse4fs_iomap_begin_indirect(struct fuse4fs *ff, uint64_t ino,
+					struct ext2_inode_large *inode,
+					off_t pos, uint64_t count,
+					uint32_t opflags,
+					struct fuse_file_iomap *iomap)
+{
+	ext2_filsys fs = ff->fs;
+	blk64_t startoff = FUSE4FS_B_TO_FSBT(ff, pos);
+	uint64_t isize = EXT2_I_SIZE(inode);
+	uint64_t real_count = min(count, 131072);
+	const blk64_t endoff = FUSE4FS_B_TO_FSB(ff, pos + real_count);
+	blk64_t startblock;
+	errcode_t err;
+
+	err = ext2fs_bmap2(fs, ino, EXT2_INODE(inode), NULL, 0, startoff, NULL,
+			   &startblock);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	iomap->dev = FUSE_IOMAP_DEV_NULL;
+	iomap->offset = FUSE4FS_FSB_TO_B(ff, startoff);
+	iomap->flags |= FUSE_IOMAP_F_MERGED;
+	if (startblock) {
+		iomap->addr = FUSE4FS_FSB_TO_B(ff, startblock);
+		iomap->type = FUSE_IOMAP_TYPE_MAPPED;
+	} else {
+		iomap->addr = FUSE_IOMAP_NULL_ADDR;
+		iomap->type = FUSE_IOMAP_TYPE_HOLE;
+	}
+	iomap->length = fs->blocksize;
+
+	/* See how long the mapping goes for. */
+	for (startoff++; startoff < endoff; startoff++) {
+		blk64_t prev_startblock = startblock;
+
+		err = ext2fs_bmap2(fs, ino, EXT2_INODE(inode), NULL, 0,
+				   startoff, NULL, &startblock);
+		if (err)
+			break;
+
+		if (iomap->type == FUSE_IOMAP_TYPE_MAPPED) {
+			if (startblock == prev_startblock + 1)
+				iomap->length += fs->blocksize;
+			else
+				break;
+		} else {
+			if (startblock == 0)
+				iomap->length += fs->blocksize;
+			else
+				break;
+		}
+	}
+
+	/*
+	 * If this is a hole that goes beyond EOF, report this as a hole to the
+	 * end of the range queried so that FIEMAP doesn't go mad.
+	 */
+	if (iomap->type == FUSE_IOMAP_TYPE_HOLE &&
+	    iomap->offset + iomap->length >= isize)
+		fuse4fs_iomap_hole_to_eof(ff, iomap, pos, count, inode);
+
+	return 0;
+}
+
+static int fuse4fs_iomap_begin_inline(struct fuse4fs *ff, ext2_ino_t ino,
+				      struct ext2_inode_large *inode, off_t pos,
+				      uint64_t count, struct fuse_file_iomap *iomap)
+{
+	uint64_t one_fsb = FUSE4FS_FSB_TO_B(ff, 1);
+
+	if (pos >= one_fsb) {
+		fuse4fs_iomap_hole_to_eof(ff, iomap, pos, count, inode);
+	} else {
+		/* ext4 only supports inline data files up to 1 fsb */
+		iomap->dev = FUSE_IOMAP_DEV_NULL;
+		iomap->addr = FUSE_IOMAP_NULL_ADDR;
+		iomap->offset = 0;
+		iomap->length = one_fsb;
+		iomap->type = FUSE_IOMAP_TYPE_INLINE;
+	}
+
+	return 0;
+}
+
+static int fuse4fs_iomap_begin_report(struct fuse4fs *ff, ext2_ino_t ino,
+				      struct ext2_inode_large *inode,
+				      off_t pos, uint64_t count,
+				      uint32_t opflags,
+				      struct fuse_file_iomap *read)
+{
+	if (inode->i_flags & EXT4_INLINE_DATA_FL)
+		return fuse4fs_iomap_begin_inline(ff, ino, inode, pos, count,
+						  read);
+
+	if (inode->i_flags & EXT4_EXTENTS_FL)
+		return fuse4fs_iomap_begin_extent(ff, ino, inode, pos, count,
+						  opflags, read);
+
+	return fuse4fs_iomap_begin_indirect(ff, ino, inode, pos, count,
+					    opflags, read);
+}
+
+static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino,
+				    struct ext2_inode_large *inode, off_t pos,
+				    uint64_t count, uint32_t opflags,
+				    struct fuse_file_iomap *read)
+{
+	return -ENOSYS;
+}
+
+static int fuse4fs_iomap_begin_write(struct fuse4fs *ff, ext2_ino_t ino,
+				     struct ext2_inode_large *inode, off_t pos,
+				     uint64_t count, uint32_t opflags,
+				     struct fuse_file_iomap *read)
+{
+	return -ENOSYS;
+}
+
+static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
+			   off_t pos, uint64_t count, uint32_t opflags)
+{
+	struct fuse4fs *ff = fuse4fs_get(req);
+	struct ext2_inode_large inode;
+	struct fuse_file_iomap read = { };
+	ext2_filsys fs;
+	ext2_ino_t ino;
+	errcode_t err;
+	int ret = 0;
+
+	FUSE4FS_CHECK_CONTEXT(req);
+	FUSE4FS_CONVERT_FINO(req, &ino, fino);
+
+	dbg_printf(ff, "%s: ino=%d pos=0x%llx count=0x%llx opflags=0x%x\n",
+		   __func__, ino,
+		   (unsigned long long)pos,
+		   (unsigned long long)count,
+		   opflags);
+
+	fs = fuse4fs_start(ff);
+	err = fuse4fs_read_inode(fs, ino, &inode);
+	if (err) {
+		ret = translate_error(fs, ino, err);
+		goto out_unlock;
+	}
+
+	if (opflags & FUSE_IOMAP_OP_REPORT)
+		ret = fuse4fs_iomap_begin_report(ff, ino, &inode, pos, count,
+						 opflags, &read);
+	else if (fuse_iomap_is_write(opflags))
+		ret = fuse4fs_iomap_begin_write(ff, ino, &inode, pos, count,
+						opflags, &read);
+	else
+		ret = fuse4fs_iomap_begin_read(ff, ino, &inode, pos, count,
+					       opflags, &read);
+	if (ret)
+		goto out_unlock;
+
+	dbg_printf(ff,
+ "%s: ino=%d pos=0x%llx -> addr=0x%llx offset=0x%llx length=0x%llx type=%u flags=0x%x\n",
+		   __func__, ino,
+		   (unsigned long long)pos,
+		   (unsigned long long)read.addr,
+		   (unsigned long long)read.offset,
+		   (unsigned long long)read.length,
+		   read.type,
+		   read.flags);
+
+	/* Not filling even the first byte will make the kernel unhappy. */
+	if (read.offset > pos || read.offset + read.length <= pos) {
+		ret = translate_error(fs, ino, EXT2_ET_INODE_CORRUPTED);
+		goto out_unlock;
+	}
+
+out_unlock:
+	fuse4fs_finish(ff, ret);
+	if (ret)
+		fuse_reply_err(req, -ret);
+	else
+		fuse_reply_iomap_begin(req, &read, NULL);
+}
+
+static void op_iomap_end(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
+			 off_t pos, uint64_t count, uint32_t opflags,
+			 ssize_t written, const struct fuse_file_iomap *iomap)
+{
+	struct fuse4fs *ff = fuse4fs_get(req);
+	ext2_ino_t ino;
+
+	FUSE4FS_CHECK_CONTEXT(req);
+	FUSE4FS_CONVERT_FINO(req, &ino, fino);
+
+	dbg_printf(ff,
+ "%s: ino=%d pos=0x%llx count=0x%llx opflags=0x%x written=0x%zx mapflags=0x%x\n",
+		   __func__, ino,
+		   (unsigned long long)pos,
+		   (unsigned long long)count,
+		   opflags,
+		   written,
+		   iomap->flags);
+
+	fuse_reply_err(req, 0);
+}
+#endif /* HAVE_FUSE_IOMAP */
+
 static struct fuse_lowlevel_ops fs_ops = {
 	.lookup = op_lookup,
 	.setattr = op_setattr,
@@ -5748,6 +6272,10 @@ static struct fuse_lowlevel_ops fs_ops = {
 #ifdef SUPPORT_FALLOCATE
 	.fallocate = op_fallocate,
 #endif
+#ifdef HAVE_FUSE_IOMAP
+	.iomap_begin = op_iomap_begin,
+	.iomap_end = op_iomap_end,
+#endif /* HAVE_FUSE_IOMAP */
 };
 
 static int get_random_bytes(void *p, size_t sz)
@@ -6125,6 +6653,9 @@ int main(int argc, char *argv[])
 		.bfl = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER,
 		.oom_score_adj = -500,
 		.opstate = F4OP_WRITABLE,
+#ifdef HAVE_FUSE_IOMAP
+		.iomap_state = IOMAP_UNKNOWN,
+#endif
 	};
 	errcode_t err;
 	FILE *orig_stderr = stderr;
diff --git a/lib/config.h.in b/lib/config.h.in
index 274659b660ad4e..41598dcc1d7c5a 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -79,6 +79,9 @@
 /* Define to 1 if fuse supports lowlevel API */
 #undef HAVE_FUSE_LOWLEVEL
 
+/* Define to 1 if fuse supports iomap */
+#undef HAVE_FUSE_IOMAP
+
 /* Define to 1 if you have the Mac OS X function
    CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */
 #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index f95e9f96bcae56..e92e66dad63b2d 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -137,6 +137,9 @@ static inline uint64_t round_down(uint64_t b, unsigned int align)
 	return b - m;
 }
 
+#define max(a, b)	((a) > (b) ? (a) : (b))
+#define min(a, b)	((a) < (b) ? (a) : (b))
+
 #define dbg_printf(fuse2fs, format, ...) \
 	while ((fuse2fs)->debug) { \
 		printf("FUSE2FS (%s): tid=%d " format, (fuse2fs)->shortdev, gettid(), ##__VA_ARGS__); \
@@ -214,6 +217,14 @@ enum fuse2fs_opstate {
 	F2OP_SHUTDOWN,
 };
 
+#ifdef HAVE_FUSE_IOMAP
+enum fuse2fs_iomap_state {
+	IOMAP_DISABLED,
+	IOMAP_UNKNOWN,
+	IOMAP_ENABLED,
+};
+#endif
+
 /* Main program context */
 #define FUSE2FS_MAGIC		(0xEF53DEADUL)
 struct fuse2fs {
@@ -241,6 +252,9 @@ struct fuse2fs {
 	int logfd;
 	int blocklog;
 	int oom_score_adj;
+#ifdef HAVE_FUSE_IOMAP
+	enum fuse2fs_iomap_state iomap_state;
+#endif
 	unsigned int blockmask;
 	unsigned long offset;
 	unsigned int next_generation;
@@ -692,6 +706,15 @@ fuse2fs_set_handle(struct fuse_file_info *fp, struct fuse2fs_file_handle *fh)
 	fp->fh = (uintptr_t)fh;
 }
 
+#ifdef HAVE_FUSE_IOMAP
+static inline int fuse2fs_iomap_enabled(const struct fuse2fs *ff)
+{
+	return ff->iomap_state >= IOMAP_ENABLED;
+}
+#else
+# define fuse2fs_iomap_enabled(...)	(0)
+#endif
+
 static void get_now(struct timespec *now)
 {
 #ifdef CLOCK_REALTIME
@@ -1121,7 +1144,7 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff)
 	char options[128];
 	double deadline;
 	int flags = EXT2_FLAG_64BITS | EXT2_FLAG_THREADS | EXT2_FLAG_RW |
-		    EXT2_FLAG_EXCLUSIVE;
+		    EXT2_FLAG_EXCLUSIVE | EXT2_FLAG_WRITE_FULL_SUPER;
 	errcode_t err;
 
 	if (ff->lockfile) {
@@ -1408,6 +1431,15 @@ static void op_destroy(void *p EXT2FS_ATTR((unused)))
 				(stats->cache_hits + stats->cache_misses));
 	}
 
+	/*
+	 * If we're mounting in iomap mode, we need to unmount in op_destroy so
+	 * that the block device will be released before umount(2) returns.
+	 */
+	if (ff->iomap_state == IOMAP_ENABLED) {
+		fuse2fs_mmp_cancel(ff);
+		fuse2fs_unmount(ff);
+	}
+
 	fuse2fs_finish(ff, 0);
 }
 
@@ -1544,6 +1576,37 @@ static inline int fuse_set_feature_flag(struct fuse_conn_info *conn,
 }
 #endif
 
+#ifdef HAVE_FUSE_IOMAP
+static inline bool fuse2fs_wants_iomap(struct fuse2fs *ff)
+{
+	if (ff->iomap_state == IOMAP_DISABLED)
+		return false;
+
+	/* iomap only works with block devices */
+	if (!(ff->fs->io->flags & CHANNEL_FLAGS_BLOCK_DEVICE))
+		return false;
+
+	return true;
+}
+
+static void fuse2fs_iomap_enable(struct fuse_conn_info *conn,
+				 struct fuse2fs *ff)
+{
+	/* Don't let anyone touch iomap until the end of the patchset. */
+	ff->iomap_state = IOMAP_DISABLED;
+	return;
+
+	if (fuse2fs_wants_iomap(ff) &&
+	    fuse_set_feature_flag(conn, FUSE_CAP_IOMAP))
+		ff->iomap_state = IOMAP_ENABLED;
+
+	if (ff->iomap_state == IOMAP_UNKNOWN)
+		ff->iomap_state = IOMAP_DISABLED;
+}
+#else
+# define fuse2fs_iomap_enable(...)	((void)0)
+#endif
+
 static void *op_init(struct fuse_conn_info *conn,
 		     struct fuse_config *cfg EXT2FS_ATTR((unused)))
 {
@@ -1577,6 +1640,8 @@ static void *op_init(struct fuse_conn_info *conn,
 #ifdef FUSE_CAP_NO_EXPORT_SUPPORT
 	fuse_set_feature_flag(conn, FUSE_CAP_NO_EXPORT_SUPPORT);
 #endif
+	fuse2fs_iomap_enable(conn, ff);
+
 	conn->time_gran = 1;
 	cfg->use_ino = 1;
 	if (ff->debug)
@@ -5149,6 +5214,465 @@ static int op_fallocate(const char *path EXT2FS_ATTR((unused)), int mode,
 }
 #endif /* SUPPORT_FALLOCATE */
 
+#ifdef HAVE_FUSE_IOMAP
+static void fuse2fs_iomap_hole(struct fuse2fs *ff, struct fuse_file_iomap *iomap,
+			       off_t pos, uint64_t count)
+{
+	iomap->dev = FUSE_IOMAP_DEV_NULL;
+	iomap->addr = FUSE_IOMAP_NULL_ADDR;
+	iomap->offset = pos;
+	iomap->length = count;
+	iomap->type = FUSE_IOMAP_TYPE_HOLE;
+}
+
+static void fuse2fs_iomap_hole_to_eof(struct fuse2fs *ff,
+				      struct fuse_file_iomap *iomap, off_t pos,
+				      off_t count,
+				      const struct ext2_inode_large *inode)
+{
+	ext2_filsys fs = ff->fs;
+	uint64_t isize = EXT2_I_SIZE(inode);
+
+	/*
+	 * We have to be careful about handling a hole to the right of the
+	 * entire mapping tree.  First, the mapping must start and end on a
+	 * block boundary because they must be aligned to at least an LBA for
+	 * the block layer; and to the fsblock for smoother operation.
+	 *
+	 * As for the length -- we could return a mapping all the way to
+	 * i_size, but i_size could be less than pos/count if we're zeroing the
+	 * EOF block in anticipation of a truncate operation.  Similarly, we
+	 * don't want to end the mapping at pos+count because we know there's
+	 * nothing mapped byeond here.
+	 */
+	uint64_t startoff = round_down(pos, fs->blocksize);
+	uint64_t eofoff = round_up(max(pos + count, isize), fs->blocksize);
+
+	dbg_printf(ff,
+ "pos=0x%llx count=0x%llx isize=0x%llx startoff=0x%llx eofoff=0x%llx\n",
+		   (unsigned long long)pos,
+		   (unsigned long long)count,
+		   (unsigned long long)isize,
+		   (unsigned long long)startoff,
+		   (unsigned long long)eofoff);
+
+	fuse2fs_iomap_hole(ff, iomap, startoff, eofoff - startoff);
+}
+
+#define DEBUG_IOMAP
+#ifdef DEBUG_IOMAP
+# define __DUMP_EXTENT(ff, func, tag, startoff, err, extent) \
+	do { \
+		dbg_printf((ff), \
+ "%s: %s startoff 0x%llx err %ld lblk 0x%llx pblk 0x%llx len 0x%x flags 0x%x\n", \
+			   (func), (tag), (startoff), (err), (extent)->e_lblk, \
+			   (extent)->e_pblk, (extent)->e_len, \
+			   (extent)->e_flags & EXT2_EXTENT_FLAGS_UNINIT); \
+	} while(0)
+# define DUMP_EXTENT(ff, tag, startoff, err, extent) \
+	__DUMP_EXTENT((ff), __func__, (tag), (startoff), (err), (extent))
+
+# define __DUMP_INFO(ff, func, tag, startoff, err, info) \
+	do { \
+		dbg_printf((ff), \
+ "%s: %s startoff 0x%llx err %ld entry %d/%d/%d level  %d/%d\n", \
+			   (func), (tag), (startoff), (err), \
+			   (info)->curr_entry, (info)->num_entries, \
+			   (info)->max_entries, (info)->curr_level, \
+			   (info)->max_depth); \
+	} while(0)
+# define DUMP_INFO(ff, tag, startoff, err, info) \
+	__DUMP_INFO((ff), __func__, (tag), (startoff), (err), (info))
+#else
+# define __DUMP_EXTENT(...)	((void)0)
+# define DUMP_EXTENT(...)	((void)0)
+# define DUMP_INFO(...)		((void)0)
+#endif
+
+static inline errcode_t __fuse2fs_get_mapping_at(struct fuse2fs *ff,
+						 ext2_extent_handle_t handle,
+						 blk64_t startoff,
+						 struct ext2fs_extent *bmap,
+						 const char *func)
+{
+	errcode_t err;
+
+	/*
+	 * Find the file mapping at startoff.  We don't check the return value
+	 * of _goto because _get will error out if _goto failed.  There's a
+	 * subtlety to the outcome of _goto when startoff falls in a sparse
+	 * hole however:
+	 *
+	 * Most of the time, _goto points the cursor at the mapping whose lblk
+	 * is just to the left of startoff.  The mapping may or may not overlap
+	 * startoff; this is ok.  In other words, the tree lookup behaves as if
+	 * we asked it to use a less than or equals comparison.
+	 *
+	 * However, if startoff is to the left of the first mapping in the
+	 * extent tree, _goto points the cursor at that first mapping because
+	 * it doesn't know how to deal with this situation.  In this case,
+	 * the tree lookup behaves as if we asked it to use a greater than
+	 * or equals comparison.
+	 *
+	 * Note: If _get() returns 'no current node', that means that there
+	 * aren't any mappings at all.
+	 */
+	ext2fs_extent_goto(handle, startoff);
+	err = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, bmap);
+	__DUMP_EXTENT(ff, func, "lookup", startoff, err, bmap);
+	if (err == EXT2_ET_NO_CURRENT_NODE)
+		err = EXT2_ET_EXTENT_NOT_FOUND;
+	return err;
+}
+
+static inline errcode_t __fuse2fs_get_next_mapping(struct fuse2fs *ff,
+						   ext2_extent_handle_t handle,
+						   blk64_t startoff,
+						   struct ext2fs_extent *bmap,
+						   const char *func)
+{
+	struct ext2fs_extent newex;
+	struct ext2_extent_info info;
+	errcode_t err;
+
+	/*
+	 * The extent tree code has this (probably broken) behavior that if
+	 * more than two of the highest levels of the cursor point at the
+	 * rightmost edge of an extent tree block, a _NEXT_LEAF movement fails
+	 * to move the cursor position of any of the lower levels.  IOWs, if
+	 * leaf level N is at the right edge, it will only advance level N-1
+	 * to the right.  If N-1 was at the right edge, the cursor resets to
+	 * record 0 of that level and goes down to the wrong leaf.
+	 *
+	 * Work around this by walking up (towards root level 0) the extent
+	 * tree until we find a level where we're not already at the rightmost
+	 * edge.  The _NEXT_LEAF movement will walk down the tree to find the
+	 * leaves.
+	 */
+	err = ext2fs_extent_get_info(handle, &info);
+	DUMP_INFO(ff, "UP?", startoff, err, &info);
+	if (err)
+		return err;
+
+	while (info.curr_entry == info.num_entries && info.curr_level > 0) {
+		err = ext2fs_extent_get(handle, EXT2_EXTENT_UP, &newex);
+		DUMP_EXTENT(ff, "UP", startoff, err, &newex);
+		if (err)
+			return err;
+		err = ext2fs_extent_get_info(handle, &info);
+		DUMP_INFO(ff, "UP", startoff, err, &info);
+		if (err)
+			return err;
+	}
+
+	/*
+	 * If we're at the root and there are no more entries, there's nothing
+	 * else to be found.
+	 */
+	if (info.curr_level == 0 && info.curr_entry == info.num_entries)
+		return EXT2_ET_EXTENT_NOT_FOUND;
+
+	/* Otherwise grab this next leaf and return it. */
+	err = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT_LEAF, &newex);
+	DUMP_EXTENT(ff, "NEXT", startoff, err, &newex);
+	if (err)
+		return err;
+
+	*bmap = newex;
+	return 0;
+}
+
+#define fuse2fs_get_mapping_at(ff, handle, startoff, bmap) \
+	__fuse2fs_get_mapping_at((ff), (handle), (startoff), (bmap), __func__)
+#define fuse2fs_get_next_mapping(ff, handle, startoff, bmap) \
+	__fuse2fs_get_next_mapping((ff), (handle), (startoff), (bmap), __func__)
+
+static errcode_t fuse2fs_iomap_begin_extent(struct fuse2fs *ff, uint64_t ino,
+					    struct ext2_inode_large *inode,
+					    off_t pos, uint64_t count,
+					    uint32_t opflags,
+					    struct fuse_file_iomap *iomap)
+{
+	ext2_extent_handle_t handle;
+	struct ext2fs_extent extent = { };
+	ext2_filsys fs = ff->fs;
+	const blk64_t startoff = FUSE2FS_B_TO_FSBT(ff, pos);
+	errcode_t err;
+	int ret = 0;
+
+	err = ext2fs_extent_open2(fs, ino, EXT2_INODE(inode), &handle);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	err = fuse2fs_get_mapping_at(ff, handle, startoff, &extent);
+	if (err == EXT2_ET_EXTENT_NOT_FOUND) {
+		/* No mappings at all; the whole range is a hole. */
+		fuse2fs_iomap_hole_to_eof(ff, iomap, pos, count, inode);
+		goto out_handle;
+	}
+	if (err) {
+		ret = translate_error(fs, ino, err);
+		goto out_handle;
+	}
+
+	if (startoff < extent.e_lblk) {
+		/*
+		 * Mapping starts to the right of the current position.
+		 * Synthesize a hole going to that next extent.
+		 */
+		fuse2fs_iomap_hole(ff, iomap, FUSE2FS_FSB_TO_B(ff, startoff),
+				FUSE2FS_FSB_TO_B(ff, extent.e_lblk - startoff));
+		goto out_handle;
+	}
+
+	if (startoff >= extent.e_lblk + extent.e_len) {
+		/*
+		 * Mapping ends to the left of the current position.  Try to
+		 * find the next mapping.  If there is no next mapping, the
+		 * whole range is in a hole.
+		 */
+		err = fuse2fs_get_next_mapping(ff, handle, startoff, &extent);
+		if (err == EXT2_ET_EXTENT_NOT_FOUND) {
+			fuse2fs_iomap_hole_to_eof(ff, iomap, pos, count, inode);
+			goto out_handle;
+		}
+
+		/*
+		 * If the new mapping starts to the right of startoff, there's
+		 * a hole from startoff to the start of the new mapping.
+		 */
+		if (startoff < extent.e_lblk) {
+			fuse2fs_iomap_hole(ff, iomap,
+				FUSE2FS_FSB_TO_B(ff, startoff),
+				FUSE2FS_FSB_TO_B(ff, extent.e_lblk - startoff));
+			goto out_handle;
+		}
+
+		/*
+		 * The new mapping starts at startoff.  Something weird
+		 * happened in the extent tree lookup, but we found a valid
+		 * mapping so we'll run with it.
+		 */
+	}
+
+	/* Mapping overlaps startoff, report this. */
+	iomap->dev = FUSE_IOMAP_DEV_NULL;
+	iomap->addr = FUSE2FS_FSB_TO_B(ff, extent.e_pblk);
+	iomap->offset = FUSE2FS_FSB_TO_B(ff, extent.e_lblk);
+	iomap->length = FUSE2FS_FSB_TO_B(ff, extent.e_len);
+	if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT)
+		iomap->type = FUSE_IOMAP_TYPE_UNWRITTEN;
+	else
+		iomap->type = FUSE_IOMAP_TYPE_MAPPED;
+
+out_handle:
+	ext2fs_extent_free(handle);
+	return ret;
+}
+
+static int fuse2fs_iomap_begin_indirect(struct fuse2fs *ff, uint64_t ino,
+					struct ext2_inode_large *inode,
+					off_t pos, uint64_t count,
+					uint32_t opflags,
+					struct fuse_file_iomap *iomap)
+{
+	ext2_filsys fs = ff->fs;
+	blk64_t startoff = FUSE2FS_B_TO_FSBT(ff, pos);
+	uint64_t isize = EXT2_I_SIZE(inode);
+	uint64_t real_count = min(count, 131072);
+	const blk64_t endoff = FUSE2FS_B_TO_FSB(ff, pos + real_count);
+	blk64_t startblock;
+	errcode_t err;
+
+	err = ext2fs_bmap2(fs, ino, EXT2_INODE(inode), NULL, 0, startoff, NULL,
+			   &startblock);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	iomap->dev = FUSE_IOMAP_DEV_NULL;
+	iomap->offset = FUSE2FS_FSB_TO_B(ff, startoff);
+	iomap->flags |= FUSE_IOMAP_F_MERGED;
+	if (startblock) {
+		iomap->addr = FUSE2FS_FSB_TO_B(ff, startblock);
+		iomap->type = FUSE_IOMAP_TYPE_MAPPED;
+	} else {
+		iomap->addr = FUSE_IOMAP_NULL_ADDR;
+		iomap->type = FUSE_IOMAP_TYPE_HOLE;
+	}
+	iomap->length = fs->blocksize;
+
+	/* See how long the mapping goes for. */
+	for (startoff++; startoff < endoff; startoff++) {
+		blk64_t prev_startblock = startblock;
+
+		err = ext2fs_bmap2(fs, ino, EXT2_INODE(inode), NULL, 0,
+				   startoff, NULL, &startblock);
+		if (err)
+			break;
+
+		if (iomap->type == FUSE_IOMAP_TYPE_MAPPED) {
+			if (startblock == prev_startblock + 1)
+				iomap->length += fs->blocksize;
+			else
+				break;
+		} else {
+			if (startblock == 0)
+				iomap->length += fs->blocksize;
+			else
+				break;
+		}
+	}
+
+	/*
+	 * If this is a hole that goes beyond EOF, report this as a hole to the
+	 * end of the range queried so that FIEMAP doesn't go mad.
+	 */
+	if (iomap->type == FUSE_IOMAP_TYPE_HOLE &&
+	    iomap->offset + iomap->length >= isize)
+		fuse2fs_iomap_hole_to_eof(ff, iomap, pos, count, inode);
+
+	return 0;
+}
+
+static int fuse2fs_iomap_begin_inline(struct fuse2fs *ff, ext2_ino_t ino,
+				      struct ext2_inode_large *inode, off_t pos,
+				      uint64_t count, struct fuse_file_iomap *iomap)
+{
+	uint64_t one_fsb = FUSE2FS_FSB_TO_B(ff, 1);
+
+	if (pos >= one_fsb) {
+		fuse2fs_iomap_hole_to_eof(ff, iomap, pos, count, inode);
+	} else {
+		/* ext4 only supports inline data files up to 1 fsb */
+		iomap->dev = FUSE_IOMAP_DEV_NULL;
+		iomap->addr = FUSE_IOMAP_NULL_ADDR;
+		iomap->offset = 0;
+		iomap->length = one_fsb;
+		iomap->type = FUSE_IOMAP_TYPE_INLINE;
+	}
+
+	return 0;
+}
+
+static int fuse2fs_iomap_begin_report(struct fuse2fs *ff, ext2_ino_t ino,
+				      struct ext2_inode_large *inode,
+				      off_t pos, uint64_t count,
+				      uint32_t opflags,
+				      struct fuse_file_iomap *read)
+{
+	if (inode->i_flags & EXT4_INLINE_DATA_FL)
+		return fuse2fs_iomap_begin_inline(ff, ino, inode, pos, count,
+						  read);
+
+	if (inode->i_flags & EXT4_EXTENTS_FL)
+		return fuse2fs_iomap_begin_extent(ff, ino, inode, pos, count,
+						  opflags, read);
+
+	return fuse2fs_iomap_begin_indirect(ff, ino, inode, pos, count,
+					    opflags, read);
+}
+
+static int fuse2fs_iomap_begin_read(struct fuse2fs *ff, ext2_ino_t ino,
+				    struct ext2_inode_large *inode, off_t pos,
+				    uint64_t count, uint32_t opflags,
+				    struct fuse_file_iomap *read)
+{
+	return -ENOSYS;
+}
+
+static int fuse2fs_iomap_begin_write(struct fuse2fs *ff, ext2_ino_t ino,
+				     struct ext2_inode_large *inode, off_t pos,
+				     uint64_t count, uint32_t opflags,
+				     struct fuse_file_iomap *read)
+{
+	return -ENOSYS;
+}
+
+static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
+			  off_t pos, uint64_t count, uint32_t opflags,
+			  struct fuse_file_iomap *read,
+			  struct fuse_file_iomap *write)
+{
+	struct fuse2fs *ff = fuse2fs_get();
+	struct ext2_inode_large inode;
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	FUSE2FS_CHECK_CONTEXT(ff);
+
+	dbg_printf(ff,
+ "%s: path=%s nodeid=%llu attr_ino=%llu pos=0x%llx count=0x%llx opflags=0x%x\n",
+		   __func__, path,
+		   (unsigned long long)nodeid,
+		   (unsigned long long)attr_ino,
+		   (unsigned long long)pos,
+		   (unsigned long long)count,
+		   opflags);
+
+	fs = fuse2fs_start(ff);
+	err = fuse2fs_read_inode(fs, attr_ino, &inode);
+	if (err) {
+		ret = translate_error(fs, attr_ino, err);
+		goto out_unlock;
+	}
+
+	if (opflags & FUSE_IOMAP_OP_REPORT)
+		ret = fuse2fs_iomap_begin_report(ff, attr_ino, &inode, pos,
+						 count, opflags, read);
+	else if (fuse_iomap_is_write(opflags))
+		ret = fuse2fs_iomap_begin_write(ff, attr_ino, &inode, pos,
+						count, opflags, read);
+	else
+		ret = fuse2fs_iomap_begin_read(ff, attr_ino, &inode, pos,
+					       count, opflags, read);
+	if (ret)
+		goto out_unlock;
+
+	dbg_printf(ff, "%s: nodeid=%llu attr_ino=%llu pos=0x%llx -> addr=0x%llx offset=0x%llx length=0x%llx type=%u\n",
+		   __func__,
+		   (unsigned long long)nodeid,
+		   (unsigned long long)attr_ino,
+		   (unsigned long long)pos,
+		   (unsigned long long)read->addr,
+		   (unsigned long long)read->offset,
+		   (unsigned long long)read->length,
+		   read->type);
+
+	/* Not filling even the first byte will make the kernel unhappy. */
+	if (read->offset > pos || read->offset + read->length <= pos) {
+		ret = translate_error(fs, attr_ino, EXT2_ET_INODE_CORRUPTED);
+		goto out_unlock;
+	}
+
+out_unlock:
+	fuse2fs_finish(ff, ret);
+	return ret;
+}
+
+static int op_iomap_end(const char *path, uint64_t nodeid, uint64_t attr_ino,
+			off_t pos, uint64_t count, uint32_t opflags,
+			ssize_t written, const struct fuse_file_iomap *iomap)
+{
+	struct fuse2fs *ff = fuse2fs_get();
+
+	FUSE2FS_CHECK_CONTEXT(ff);
+
+	dbg_printf(ff,
+ "%s: path=%s nodeid=%llu attr_ino=%llu pos=0x%llx count=0x%llx opflags=0x%x written=0x%zx mapflags=0x%x\n",
+		   __func__, path,
+		   (unsigned long long)nodeid,
+		   (unsigned long long)attr_ino,
+		   (unsigned long long)pos,
+		   (unsigned long long)count,
+		   opflags,
+		   written,
+		   iomap->flags);
+
+	return 0;
+}
+#endif /* HAVE_FUSE_IOMAP */
+
 static struct fuse_operations fs_ops = {
 	.init = op_init,
 	.destroy = op_destroy,
@@ -5190,6 +5714,10 @@ static struct fuse_operations fs_ops = {
 #ifdef SUPPORT_FALLOCATE
 	.fallocate = op_fallocate,
 #endif
+#ifdef HAVE_FUSE_IOMAP
+	.iomap_begin = op_iomap_begin,
+	.iomap_end = op_iomap_end,
+#endif /* HAVE_FUSE_IOMAP */
 };
 
 static int get_random_bytes(void *p, size_t sz)
@@ -5476,6 +6004,9 @@ int main(int argc, char *argv[])
 		.bfl = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER,
 		.oom_score_adj = -500,
 		.opstate = F2OP_WRITABLE,
+#ifdef HAVE_FUSE_IOMAP
+		.iomap_state = IOMAP_UNKNOWN,
+#endif
 	};
 	errcode_t err;
 	FILE *orig_stderr = stderr;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 02/19] fuse2fs: add iomap= mount option
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
  2026-02-23 23:36   ` [PATCH 01/19] fuse2fs: implement bare minimum iomap for file mapping reporting Darrick J. Wong
@ 2026-02-23 23:36   ` Darrick J. Wong
  2026-02-23 23:36   ` [PATCH 03/19] fuse2fs: implement iomap configuration Darrick J. Wong
                     ` (16 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:36 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Add a mount option to control iomap usage so that we can test before and
after scenarios.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.1.in |    6 ++++++
 fuse4fs/fuse4fs.c    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 misc/fuse2fs.1.in    |    6 ++++++
 misc/fuse2fs.c       |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 104 insertions(+)


diff --git a/fuse4fs/fuse4fs.1.in b/fuse4fs/fuse4fs.1.in
index 8bef5f48802385..8855867d27101d 100644
--- a/fuse4fs/fuse4fs.1.in
+++ b/fuse4fs/fuse4fs.1.in
@@ -75,6 +75,12 @@ .SS "fuse4fs options:"
 \fB-o\fR fuse4fs_debug
 enable fuse4fs debugging
 .TP
+\fB-o\fR iomap=
+If set to \fI1\fR, requires iomap to be enabled.
+If set to \fI0\fR, forbids use of iomap.
+If set to \fIdefault\fR (or not set), enables iomap if present.
+This substantially improves the performance of the fuse4fs server.
+.TP
 \fB-o\fR kernel
 Behave more like the kernel ext4 driver in the following ways:
 Allows processes owned by other users to access the filesystem.
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index a98cbc5234715d..d5476eb0ab90a4 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -224,6 +224,12 @@ enum fuse4fs_opstate {
 	F4OP_SHUTDOWN,
 };
 
+enum fuse4fs_feature_toggle {
+	FT_DISABLE,
+	FT_ENABLE,
+	FT_DEFAULT,
+};
+
 #ifdef HAVE_FUSE_IOMAP
 enum fuse4fs_iomap_state {
 	IOMAP_DISABLED,
@@ -260,6 +266,7 @@ struct fuse4fs {
 	int blocklog;
 	int oom_score_adj;
 #ifdef HAVE_FUSE_IOMAP
+	enum fuse4fs_feature_toggle iomap_want;
 	enum fuse4fs_iomap_state iomap_state;
 #endif
 	unsigned int blockmask;
@@ -1794,6 +1801,12 @@ static void fuse4fs_iomap_enable(struct fuse_conn_info *conn,
 
 	if (ff->iomap_state == IOMAP_UNKNOWN)
 		ff->iomap_state = IOMAP_DISABLED;
+
+	if (!fuse4fs_iomap_enabled(ff)) {
+		if (ff->iomap_want == FT_ENABLE)
+			err_printf(ff, "%s\n", _("Could not enable iomap."));
+		return;
+	}
 }
 #else
 # define fuse4fs_iomap_enable(...)	((void)0)
@@ -6303,6 +6316,9 @@ enum {
 	FUSE4FS_CACHE_SIZE,
 	FUSE4FS_DIRSYNC,
 	FUSE4FS_ERRORS_BEHAVIOR,
+#ifdef HAVE_FUSE_IOMAP
+	FUSE4FS_IOMAP,
+#endif
 };
 
 #define FUSE4FS_OPT(t, p, v) { t, offsetof(struct fuse4fs, p), v }
@@ -6334,6 +6350,10 @@ static struct fuse_opt fuse4fs_opts[] = {
 	FUSE_OPT_KEY("cache_size=%s",	FUSE4FS_CACHE_SIZE),
 	FUSE_OPT_KEY("dirsync",		FUSE4FS_DIRSYNC),
 	FUSE_OPT_KEY("errors=%s",	FUSE4FS_ERRORS_BEHAVIOR),
+#ifdef HAVE_FUSE_IOMAP
+	FUSE_OPT_KEY("iomap=%s",	FUSE4FS_IOMAP),
+	FUSE_OPT_KEY("iomap",		FUSE4FS_IOMAP),
+#endif
 
 	FUSE_OPT_KEY("-V",             FUSE4FS_VERSION),
 	FUSE_OPT_KEY("--version",      FUSE4FS_VERSION),
@@ -6385,6 +6405,23 @@ static int fuse4fs_opt_proc(void *data, const char *arg,
 
 		/* do not pass through to libfuse */
 		return 0;
+#ifdef HAVE_FUSE_IOMAP
+	case FUSE4FS_IOMAP:
+		if (strcmp(arg, "iomap") == 0 || strcmp(arg + 6, "1") == 0)
+			ff->iomap_want = FT_ENABLE;
+		else if (strcmp(arg + 6, "0") == 0)
+			ff->iomap_want = FT_DISABLE;
+		else if (strcmp(arg + 6, "default") == 0)
+			ff->iomap_want = FT_DEFAULT;
+		else {
+			fprintf(stderr, "%s: %s\n", arg,
+ _("unknown iomap= behavior."));
+			return -1;
+		}
+
+		/* do not pass through to libfuse */
+		return 0;
+#endif
 	case FUSE4FS_IGNORED:
 		return 0;
 	case FUSE4FS_HELP:
@@ -6412,6 +6449,9 @@ static int fuse4fs_opt_proc(void *data, const char *arg,
 	"    -o cache_size=N[KMG]   use a disk cache of this size\n"
 	"    -o errors=             behavior when an error is encountered:\n"
 	"                           continue|remount-ro|panic\n"
+#ifdef HAVE_FUSE_IOMAP
+	"    -o iomap=              0 to disable iomap, 1 to enable iomap\n"
+#endif
 	"\n",
 			outargs->argv[0]);
 		if (key == FUSE4FS_HELPFULL) {
@@ -6654,6 +6694,7 @@ int main(int argc, char *argv[])
 		.oom_score_adj = -500,
 		.opstate = F4OP_WRITABLE,
 #ifdef HAVE_FUSE_IOMAP
+		.iomap_want = FT_DEFAULT,
 		.iomap_state = IOMAP_UNKNOWN,
 #endif
 	};
@@ -6670,6 +6711,11 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
+#ifdef HAVE_FUSE_IOMAP
+	if (fctx.iomap_want == FT_DISABLE)
+		fctx.iomap_state = IOMAP_DISABLED;
+#endif
+
 	/* /dev/sda -> sda for reporting */
 	fctx.shortdev = strrchr(fctx.device, '/');
 	if (fctx.shortdev)
diff --git a/misc/fuse2fs.1.in b/misc/fuse2fs.1.in
index 6acfa092851292..2b55fa0e723966 100644
--- a/misc/fuse2fs.1.in
+++ b/misc/fuse2fs.1.in
@@ -75,6 +75,12 @@ .SS "fuse2fs options:"
 \fB-o\fR fuse2fs_debug
 enable fuse2fs debugging
 .TP
+\fB-o\fR iomap=
+If set to \fI1\fR, requires iomap to be enabled.
+If set to \fI0\fR, forbids use of iomap.
+If set to \fIdefault\fR (or not set), enables iomap if present.
+This substantially improves the performance of the fuse2fs server.
+.TP
 \fB-o\fR kernel
 Behave more like the kernel ext4 driver in the following ways:
 Allows processes owned by other users to access the filesystem.
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index e92e66dad63b2d..fafd99aa64e911 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -217,6 +217,12 @@ enum fuse2fs_opstate {
 	F2OP_SHUTDOWN,
 };
 
+enum fuse2fs_feature_toggle {
+	FT_DISABLE,
+	FT_ENABLE,
+	FT_DEFAULT,
+};
+
 #ifdef HAVE_FUSE_IOMAP
 enum fuse2fs_iomap_state {
 	IOMAP_DISABLED,
@@ -253,6 +259,7 @@ struct fuse2fs {
 	int blocklog;
 	int oom_score_adj;
 #ifdef HAVE_FUSE_IOMAP
+	enum fuse2fs_feature_toggle iomap_want;
 	enum fuse2fs_iomap_state iomap_state;
 #endif
 	unsigned int blockmask;
@@ -1602,6 +1609,12 @@ static void fuse2fs_iomap_enable(struct fuse_conn_info *conn,
 
 	if (ff->iomap_state == IOMAP_UNKNOWN)
 		ff->iomap_state = IOMAP_DISABLED;
+
+	if (!fuse2fs_iomap_enabled(ff)) {
+		if (ff->iomap_want == FT_ENABLE)
+			err_printf(ff, "%s\n", _("Could not enable iomap."));
+		return;
+	}
 }
 #else
 # define fuse2fs_iomap_enable(...)	((void)0)
@@ -5745,6 +5758,9 @@ enum {
 	FUSE2FS_CACHE_SIZE,
 	FUSE2FS_DIRSYNC,
 	FUSE2FS_ERRORS_BEHAVIOR,
+#ifdef HAVE_FUSE_IOMAP
+	FUSE2FS_IOMAP,
+#endif
 };
 
 #define FUSE2FS_OPT(t, p, v) { t, offsetof(struct fuse2fs, p), v }
@@ -5776,6 +5792,10 @@ static struct fuse_opt fuse2fs_opts[] = {
 	FUSE_OPT_KEY("cache_size=%s",	FUSE2FS_CACHE_SIZE),
 	FUSE_OPT_KEY("dirsync",		FUSE2FS_DIRSYNC),
 	FUSE_OPT_KEY("errors=%s",	FUSE2FS_ERRORS_BEHAVIOR),
+#ifdef HAVE_FUSE_IOMAP
+	FUSE_OPT_KEY("iomap=%s",	FUSE2FS_IOMAP),
+	FUSE_OPT_KEY("iomap",		FUSE2FS_IOMAP),
+#endif
 
 	FUSE_OPT_KEY("-V",             FUSE2FS_VERSION),
 	FUSE_OPT_KEY("--version",      FUSE2FS_VERSION),
@@ -5827,6 +5847,23 @@ static int fuse2fs_opt_proc(void *data, const char *arg,
 
 		/* do not pass through to libfuse */
 		return 0;
+#ifdef HAVE_FUSE_IOMAP
+	case FUSE2FS_IOMAP:
+		if (strcmp(arg, "iomap") == 0 || strcmp(arg + 6, "1") == 0)
+			ff->iomap_want = FT_ENABLE;
+		else if (strcmp(arg + 6, "0") == 0)
+			ff->iomap_want = FT_DISABLE;
+		else if (strcmp(arg + 6, "default") == 0)
+			ff->iomap_want = FT_DEFAULT;
+		else {
+			fprintf(stderr, "%s: %s\n", arg,
+ _("unknown iomap= behavior."));
+			return -1;
+		}
+
+		/* do not pass through to libfuse */
+		return 0;
+#endif
 	case FUSE2FS_IGNORED:
 		return 0;
 	case FUSE2FS_HELP:
@@ -5854,6 +5891,9 @@ static int fuse2fs_opt_proc(void *data, const char *arg,
 	"    -o cache_size=N[KMG]   use a disk cache of this size\n"
 	"    -o errors=             behavior when an error is encountered:\n"
 	"                           continue|remount-ro|panic\n"
+#ifdef HAVE_FUSE_IOMAP
+	"    -o iomap=              0 to disable iomap, 1 to enable iomap\n"
+#endif
 	"\n",
 			outargs->argv[0]);
 		if (key == FUSE2FS_HELPFULL) {
@@ -6005,6 +6045,7 @@ int main(int argc, char *argv[])
 		.oom_score_adj = -500,
 		.opstate = F2OP_WRITABLE,
 #ifdef HAVE_FUSE_IOMAP
+		.iomap_want = FT_DEFAULT,
 		.iomap_state = IOMAP_UNKNOWN,
 #endif
 	};
@@ -6021,6 +6062,11 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
+#ifdef HAVE_FUSE_IOMAP
+	if (fctx.iomap_want == FT_DISABLE)
+		fctx.iomap_state = IOMAP_DISABLED;
+#endif
+
 	/* /dev/sda -> sda for reporting */
 	fctx.shortdev = strrchr(fctx.device, '/');
 	if (fctx.shortdev)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 03/19] fuse2fs: implement iomap configuration
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
  2026-02-23 23:36   ` [PATCH 01/19] fuse2fs: implement bare minimum iomap for file mapping reporting Darrick J. Wong
  2026-02-23 23:36   ` [PATCH 02/19] fuse2fs: add iomap= mount option Darrick J. Wong
@ 2026-02-23 23:36   ` Darrick J. Wong
  2026-02-23 23:37   ` [PATCH 04/19] fuse2fs: register block devices for use with iomap Darrick J. Wong
                     ` (15 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:36 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Upload the filesystem geometry to the kernel when asked.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   96 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 misc/fuse2fs.c    |   96 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 186 insertions(+), 6 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index d5476eb0ab90a4..617ef259133cba 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -196,6 +196,10 @@ static inline uint64_t round_down(uint64_t b, unsigned int align)
 # define FL_ZERO_RANGE_FLAG (0)
 #endif
 
+#ifndef NSEC_PER_SEC
+# define NSEC_PER_SEC	(1000000000L)
+#endif
+
 errcode_t ext2fs_check_ext3_journal(ext2_filsys fs);
 errcode_t ext2fs_run_ext3_journal(ext2_filsys *fs);
 
@@ -967,9 +971,9 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)
 	EXT4_INODE_GET_XTIME(i_mtime, &mtime, pinode);
 	get_now(&now);
 
-	datime = atime.tv_sec + ((double)atime.tv_nsec / 1000000000);
-	dmtime = mtime.tv_sec + ((double)mtime.tv_nsec / 1000000000);
-	dnow = now.tv_sec + ((double)now.tv_nsec / 1000000000);
+	datime = atime.tv_sec + ((double)atime.tv_nsec / NSEC_PER_SEC);
+	dmtime = mtime.tv_sec + ((double)mtime.tv_nsec / NSEC_PER_SEC);
+	dnow = now.tv_sec + ((double)now.tv_nsec / NSEC_PER_SEC);
 
 	/*
 	 * If atime is newer than mtime and atime hasn't been updated in thirty
@@ -6240,6 +6244,91 @@ static void op_iomap_end(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 
 	fuse_reply_err(req, 0);
 }
+
+/*
+ * Maximal extent format file size.
+ * Resulting logical blkno at s_maxbytes must fit in our on-disk
+ * extent format containers, within a sector_t, and within i_blocks
+ * in the vfs.  ext4 inode has 48 bits of i_block in fsblock units,
+ * so that won't be a limiting factor.
+ *
+ * However there is other limiting factor. We do store extents in the form
+ * of starting block and length, hence the resulting length of the extent
+ * covering maximum file size must fit into on-disk format containers as
+ * well. Given that length is always by 1 unit bigger than max unit (because
+ * we count 0 as well) we have to lower the s_maxbytes by one fs block.
+ *
+ * Note, this does *not* consider any metadata overhead for vfs i_blocks.
+ */
+static off_t fuse4fs_max_size(struct fuse4fs *ff, off_t upper_limit)
+{
+	off_t res;
+
+	if (!ext2fs_has_feature_huge_file(ff->fs->super)) {
+		upper_limit = (1LL << 32) - 1;
+
+		/* total blocks in file system block size */
+		upper_limit >>= (ff->blocklog - 9);
+		upper_limit <<= ff->blocklog;
+	}
+
+	/*
+	 * 32-bit extent-start container, ee_block. We lower the maxbytes
+	 * by one fs block, so ee_len can cover the extent of maximum file
+	 * size
+	 */
+	res = (1LL << 32) - 1;
+	res <<= ff->blocklog;
+
+	/* Sanity check against vm- & vfs- imposed limits */
+	if (res > upper_limit)
+		res = upper_limit;
+
+	return res;
+}
+
+static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
+{
+	struct fuse_iomap_config cfg = { };
+	struct fuse4fs *ff = fuse4fs_get(req);
+	ext2_filsys fs;
+
+	FUSE4FS_CHECK_CONTEXT(req);
+
+	dbg_printf(ff, "%s: flags=0x%llx maxbytes=0x%llx\n", __func__,
+		   (unsigned long long)flags,
+		   (unsigned long long)maxbytes);
+	fs = fuse4fs_start(ff);
+
+	cfg.flags |= FUSE_IOMAP_CONFIG_UUID;
+	memcpy(cfg.s_uuid, fs->super->s_uuid, sizeof(cfg.s_uuid));
+	cfg.s_uuid_len = sizeof(fs->super->s_uuid);
+
+	cfg.flags |= FUSE_IOMAP_CONFIG_BLOCKSIZE;
+	cfg.s_blocksize = FUSE4FS_FSB_TO_B(ff, 1);
+
+	/*
+	 * If there inode is large enough to house i_[acm]time_extra then we
+	 * can turn on nanosecond timestamps; i_crtime was the next field added
+	 * after i_atime_extra.
+	 */
+	cfg.flags |= FUSE_IOMAP_CONFIG_TIME;
+	if (fs->super->s_inode_size >=
+	    offsetof(struct ext2_inode_large, i_crtime)) {
+		cfg.s_time_gran = 1;
+		cfg.s_time_max = EXT4_EXTRA_TIMESTAMP_MAX;
+	} else {
+		cfg.s_time_gran = NSEC_PER_SEC;
+		cfg.s_time_max = EXT4_NON_EXTRA_TIMESTAMP_MAX;
+	}
+	cfg.s_time_min = EXT4_TIMESTAMP_MIN;
+
+	cfg.flags |= FUSE_IOMAP_CONFIG_MAXBYTES;
+	cfg.s_maxbytes = fuse4fs_max_size(ff, maxbytes);
+
+	fuse4fs_finish(ff, 0);
+	fuse_reply_iomap_config(req, &cfg);
+}
 #endif /* HAVE_FUSE_IOMAP */
 
 static struct fuse_lowlevel_ops fs_ops = {
@@ -6288,6 +6377,7 @@ static struct fuse_lowlevel_ops fs_ops = {
 #ifdef HAVE_FUSE_IOMAP
 	.iomap_begin = op_iomap_begin,
 	.iomap_end = op_iomap_end,
+	.iomap_config = op_iomap_config,
 #endif /* HAVE_FUSE_IOMAP */
 };
 
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index fafd99aa64e911..45ac61ff02957b 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -190,6 +190,10 @@ static inline uint64_t round_down(uint64_t b, unsigned int align)
 # define FL_ZERO_RANGE_FLAG (0)
 #endif
 
+#ifndef NSEC_PER_SEC
+# define NSEC_PER_SEC	(1000000000L)
+#endif
+
 errcode_t ext2fs_check_ext3_journal(ext2_filsys fs);
 errcode_t ext2fs_run_ext3_journal(ext2_filsys *fs);
 
@@ -805,9 +809,9 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)
 	EXT4_INODE_GET_XTIME(i_mtime, &mtime, pinode);
 	get_now(&now);
 
-	datime = atime.tv_sec + ((double)atime.tv_nsec / 1000000000);
-	dmtime = mtime.tv_sec + ((double)mtime.tv_nsec / 1000000000);
-	dnow = now.tv_sec + ((double)now.tv_nsec / 1000000000);
+	datime = atime.tv_sec + ((double)atime.tv_nsec / NSEC_PER_SEC);
+	dmtime = mtime.tv_sec + ((double)mtime.tv_nsec / NSEC_PER_SEC);
+	dnow = now.tv_sec + ((double)now.tv_nsec / NSEC_PER_SEC);
 
 	/*
 	 * If atime is newer than mtime and atime hasn't been updated in thirty
@@ -5684,6 +5688,91 @@ static int op_iomap_end(const char *path, uint64_t nodeid, uint64_t attr_ino,
 
 	return 0;
 }
+
+/*
+ * Maximal extent format file size.
+ * Resulting logical blkno at s_maxbytes must fit in our on-disk
+ * extent format containers, within a sector_t, and within i_blocks
+ * in the vfs.  ext4 inode has 48 bits of i_block in fsblock units,
+ * so that won't be a limiting factor.
+ *
+ * However there is other limiting factor. We do store extents in the form
+ * of starting block and length, hence the resulting length of the extent
+ * covering maximum file size must fit into on-disk format containers as
+ * well. Given that length is always by 1 unit bigger than max unit (because
+ * we count 0 as well) we have to lower the s_maxbytes by one fs block.
+ *
+ * Note, this does *not* consider any metadata overhead for vfs i_blocks.
+ */
+static off_t fuse2fs_max_size(struct fuse2fs *ff, off_t upper_limit)
+{
+	off_t res;
+
+	if (!ext2fs_has_feature_huge_file(ff->fs->super)) {
+		upper_limit = (1LL << 32) - 1;
+
+		/* total blocks in file system block size */
+		upper_limit >>= (ff->blocklog - 9);
+		upper_limit <<= ff->blocklog;
+	}
+
+	/*
+	 * 32-bit extent-start container, ee_block. We lower the maxbytes
+	 * by one fs block, so ee_len can cover the extent of maximum file
+	 * size
+	 */
+	res = (1LL << 32) - 1;
+	res <<= ff->blocklog;
+
+	/* Sanity check against vm- & vfs- imposed limits */
+	if (res > upper_limit)
+		res = upper_limit;
+
+	return res;
+}
+
+static int op_iomap_config(uint64_t flags, off_t maxbytes,
+			   struct fuse_iomap_config *cfg)
+{
+	struct fuse2fs *ff = fuse2fs_get();
+	ext2_filsys fs;
+
+	FUSE2FS_CHECK_CONTEXT(ff);
+
+	dbg_printf(ff, "%s: flags=0x%llx maxbytes=0x%llx\n", __func__,
+		   (unsigned long long)flags,
+		   (unsigned long long)maxbytes);
+	fs = fuse2fs_start(ff);
+
+	cfg->flags |= FUSE_IOMAP_CONFIG_UUID;
+	memcpy(cfg->s_uuid, fs->super->s_uuid, sizeof(cfg->s_uuid));
+	cfg->s_uuid_len = sizeof(fs->super->s_uuid);
+
+	cfg->flags |= FUSE_IOMAP_CONFIG_BLOCKSIZE;
+	cfg->s_blocksize = FUSE2FS_FSB_TO_B(ff, 1);
+
+	/*
+	 * If there inode is large enough to house i_[acm]time_extra then we
+	 * can turn on nanosecond timestamps; i_crtime was the next field added
+	 * after i_atime_extra.
+	 */
+	cfg->flags |= FUSE_IOMAP_CONFIG_TIME;
+	if (fs->super->s_inode_size >=
+	    offsetof(struct ext2_inode_large, i_crtime)) {
+		cfg->s_time_gran = 1;
+		cfg->s_time_max = EXT4_EXTRA_TIMESTAMP_MAX;
+	} else {
+		cfg->s_time_gran = NSEC_PER_SEC;
+		cfg->s_time_max = EXT4_NON_EXTRA_TIMESTAMP_MAX;
+	}
+	cfg->s_time_min = EXT4_TIMESTAMP_MIN;
+
+	cfg->flags |= FUSE_IOMAP_CONFIG_MAXBYTES;
+	cfg->s_maxbytes = fuse2fs_max_size(ff, maxbytes);
+
+	fuse2fs_finish(ff, 0);
+	return 0;
+}
 #endif /* HAVE_FUSE_IOMAP */
 
 static struct fuse_operations fs_ops = {
@@ -5730,6 +5819,7 @@ static struct fuse_operations fs_ops = {
 #ifdef HAVE_FUSE_IOMAP
 	.iomap_begin = op_iomap_begin,
 	.iomap_end = op_iomap_end,
+	.iomap_config = op_iomap_config,
 #endif /* HAVE_FUSE_IOMAP */
 };
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 04/19] fuse2fs: register block devices for use with iomap
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:36   ` [PATCH 03/19] fuse2fs: implement iomap configuration Darrick J. Wong
@ 2026-02-23 23:37   ` Darrick J. Wong
  2026-02-23 23:37   ` [PATCH 05/19] fuse2fs: implement directio file reads Darrick J. Wong
                     ` (14 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:37 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Register the ext4 block device with the kernel for use with iomap.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   44 ++++++++++++++++++++++++++++++++++++++++----
 misc/fuse2fs.c    |   42 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 78 insertions(+), 8 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 617ef259133cba..e6a60f4ea637f3 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -272,6 +272,7 @@ struct fuse4fs {
 #ifdef HAVE_FUSE_IOMAP
 	enum fuse4fs_feature_toggle iomap_want;
 	enum fuse4fs_iomap_state iomap_state;
+	uint32_t iomap_dev;
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -6028,7 +6029,7 @@ static errcode_t fuse4fs_iomap_begin_extent(struct fuse4fs *ff, uint64_t ino,
 	}
 
 	/* Mapping overlaps startoff, report this. */
-	iomap->dev = FUSE_IOMAP_DEV_NULL;
+	iomap->dev = ff->iomap_dev;
 	iomap->addr = FUSE4FS_FSB_TO_B(ff, extent.e_pblk);
 	iomap->offset = FUSE4FS_FSB_TO_B(ff, extent.e_lblk);
 	iomap->length = FUSE4FS_FSB_TO_B(ff, extent.e_len);
@@ -6061,13 +6062,14 @@ static int fuse4fs_iomap_begin_indirect(struct fuse4fs *ff, uint64_t ino,
 	if (err)
 		return translate_error(fs, ino, err);
 
-	iomap->dev = FUSE_IOMAP_DEV_NULL;
 	iomap->offset = FUSE4FS_FSB_TO_B(ff, startoff);
 	iomap->flags |= FUSE_IOMAP_F_MERGED;
 	if (startblock) {
+		iomap->dev = ff->iomap_dev;
 		iomap->addr = FUSE4FS_FSB_TO_B(ff, startblock);
 		iomap->type = FUSE_IOMAP_TYPE_MAPPED;
 	} else {
+		iomap->dev = FUSE_IOMAP_DEV_NULL;
 		iomap->addr = FUSE_IOMAP_NULL_ADDR;
 		iomap->type = FUSE_IOMAP_TYPE_HOLE;
 	}
@@ -6287,11 +6289,36 @@ static off_t fuse4fs_max_size(struct fuse4fs *ff, off_t upper_limit)
 	return res;
 }
 
+static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
+{
+	errcode_t err;
+	int fd;
+	int ret;
+
+	err = io_channel_get_fd(ff->fs->io, &fd);
+	if (err)
+		return translate_error(ff->fs, 0, err);
+
+	ret = fuse_lowlevel_iomap_device_add(ff->fuse, fd, 0);
+	if (ret < 0) {
+		dbg_printf(ff, "%s: cannot register iomap dev fd=%d, err=%d\n",
+			   __func__, fd, -ret);
+		return translate_error(ff->fs, 0, -ret);
+	}
+
+	dbg_printf(ff, "%s: registered iomap dev fd=%d iomap_dev=%u\n",
+		   __func__, fd, ff->iomap_dev);
+
+	ff->iomap_dev = ret;
+	return 0;
+}
+
 static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
 {
 	struct fuse_iomap_config cfg = { };
 	struct fuse4fs *ff = fuse4fs_get(req);
 	ext2_filsys fs;
+	int ret = 0;
 
 	FUSE4FS_CHECK_CONTEXT(req);
 
@@ -6326,8 +6353,16 @@ static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
 	cfg.flags |= FUSE_IOMAP_CONFIG_MAXBYTES;
 	cfg.s_maxbytes = fuse4fs_max_size(ff, maxbytes);
 
-	fuse4fs_finish(ff, 0);
-	fuse_reply_iomap_config(req, &cfg);
+	ret = fuse4fs_iomap_config_devices(ff);
+	if (ret)
+		goto out_unlock;
+
+out_unlock:
+	fuse4fs_finish(ff, ret);
+	if (ret)
+		fuse_reply_err(req, -ret);
+	else
+		fuse_reply_iomap_config(req, &cfg);
 }
 #endif /* HAVE_FUSE_IOMAP */
 
@@ -6786,6 +6821,7 @@ int main(int argc, char *argv[])
 #ifdef HAVE_FUSE_IOMAP
 		.iomap_want = FT_DEFAULT,
 		.iomap_state = IOMAP_UNKNOWN,
+		.iomap_dev = FUSE_IOMAP_DEV_NULL,
 #endif
 	};
 	errcode_t err;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 45ac61ff02957b..70ded520cd318a 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -40,6 +40,7 @@
 # define _FILE_OFFSET_BITS 64
 #endif /* _FILE_OFFSET_BITS */
 #include <fuse.h>
+#include <fuse_lowlevel.h>
 #ifdef __SET_FOB_FOR_FUSE
 # undef _FILE_OFFSET_BITS
 #endif /* __SET_FOB_FOR_FUSE */
@@ -265,6 +266,7 @@ struct fuse2fs {
 #ifdef HAVE_FUSE_IOMAP
 	enum fuse2fs_feature_toggle iomap_want;
 	enum fuse2fs_iomap_state iomap_state;
+	uint32_t iomap_dev;
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -5473,7 +5475,7 @@ static errcode_t fuse2fs_iomap_begin_extent(struct fuse2fs *ff, uint64_t ino,
 	}
 
 	/* Mapping overlaps startoff, report this. */
-	iomap->dev = FUSE_IOMAP_DEV_NULL;
+	iomap->dev = ff->iomap_dev;
 	iomap->addr = FUSE2FS_FSB_TO_B(ff, extent.e_pblk);
 	iomap->offset = FUSE2FS_FSB_TO_B(ff, extent.e_lblk);
 	iomap->length = FUSE2FS_FSB_TO_B(ff, extent.e_len);
@@ -5506,13 +5508,14 @@ static int fuse2fs_iomap_begin_indirect(struct fuse2fs *ff, uint64_t ino,
 	if (err)
 		return translate_error(fs, ino, err);
 
-	iomap->dev = FUSE_IOMAP_DEV_NULL;
 	iomap->offset = FUSE2FS_FSB_TO_B(ff, startoff);
 	iomap->flags |= FUSE_IOMAP_F_MERGED;
 	if (startblock) {
+		iomap->dev = ff->iomap_dev;
 		iomap->addr = FUSE2FS_FSB_TO_B(ff, startblock);
 		iomap->type = FUSE_IOMAP_TYPE_MAPPED;
 	} else {
+		iomap->dev = FUSE_IOMAP_DEV_NULL;
 		iomap->addr = FUSE_IOMAP_NULL_ADDR;
 		iomap->type = FUSE_IOMAP_TYPE_HOLE;
 	}
@@ -5731,11 +5734,36 @@ static off_t fuse2fs_max_size(struct fuse2fs *ff, off_t upper_limit)
 	return res;
 }
 
+static int fuse2fs_iomap_config_devices(struct fuse2fs *ff)
+{
+	errcode_t err;
+	int fd;
+	int ret;
+
+	err = io_channel_get_fd(ff->fs->io, &fd);
+	if (err)
+		return translate_error(ff->fs, 0, err);
+
+	ret = fuse_fs_iomap_device_add(fd, 0);
+	if (ret < 0) {
+		dbg_printf(ff, "%s: cannot register iomap dev fd=%d, err=%d\n",
+			   __func__, fd, -ret);
+		return translate_error(ff->fs, 0, -ret);
+	}
+
+	dbg_printf(ff, "%s: registered iomap dev fd=%d iomap_dev=%u\n",
+		   __func__, fd, ff->iomap_dev);
+
+	ff->iomap_dev = ret;
+	return 0;
+}
+
 static int op_iomap_config(uint64_t flags, off_t maxbytes,
 			   struct fuse_iomap_config *cfg)
 {
 	struct fuse2fs *ff = fuse2fs_get();
 	ext2_filsys fs;
+	int ret = 0;
 
 	FUSE2FS_CHECK_CONTEXT(ff);
 
@@ -5770,8 +5798,13 @@ static int op_iomap_config(uint64_t flags, off_t maxbytes,
 	cfg->flags |= FUSE_IOMAP_CONFIG_MAXBYTES;
 	cfg->s_maxbytes = fuse2fs_max_size(ff, maxbytes);
 
-	fuse2fs_finish(ff, 0);
-	return 0;
+	ret = fuse2fs_iomap_config_devices(ff);
+	if (ret)
+		goto out_unlock;
+
+out_unlock:
+	fuse2fs_finish(ff, ret);
+	return ret;
 }
 #endif /* HAVE_FUSE_IOMAP */
 
@@ -6137,6 +6170,7 @@ int main(int argc, char *argv[])
 #ifdef HAVE_FUSE_IOMAP
 		.iomap_want = FT_DEFAULT,
 		.iomap_state = IOMAP_UNKNOWN,
+		.iomap_dev = FUSE_IOMAP_DEV_NULL,
 #endif
 	};
 	errcode_t err;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 05/19] fuse2fs: implement directio file reads
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:37   ` [PATCH 04/19] fuse2fs: register block devices for use with iomap Darrick J. Wong
@ 2026-02-23 23:37   ` Darrick J. Wong
  2026-02-23 23:37   ` [PATCH 06/19] fuse2fs: add extent dump function for debugging Darrick J. Wong
                     ` (13 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:37 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Implement file reads via iomap.  Currently only directio is supported.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   14 +++++++++++++-
 misc/fuse2fs.c    |   14 +++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index e6a60f4ea637f3..9fa875d1d99ae8 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -6151,7 +6151,19 @@ static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino,
 				    uint64_t count, uint32_t opflags,
 				    struct fuse_file_iomap *read)
 {
-	return -ENOSYS;
+	if (!(opflags & FUSE_IOMAP_OP_DIRECT))
+		return -ENOSYS;
+
+	/* fall back to slow path for inline data reads */
+	if (inode->i_flags & EXT4_INLINE_DATA_FL)
+		return -ENOSYS;
+
+	if (inode->i_flags & EXT4_EXTENTS_FL)
+		return fuse4fs_iomap_begin_extent(ff, ino, inode, pos, count,
+						  opflags, read);
+
+	return fuse4fs_iomap_begin_indirect(ff, ino, inode, pos, count,
+					    opflags, read);
 }
 
 static int fuse4fs_iomap_begin_write(struct fuse4fs *ff, ext2_ino_t ino,
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 70ded520cd318a..a5105855f1669a 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -5597,7 +5597,19 @@ static int fuse2fs_iomap_begin_read(struct fuse2fs *ff, ext2_ino_t ino,
 				    uint64_t count, uint32_t opflags,
 				    struct fuse_file_iomap *read)
 {
-	return -ENOSYS;
+	if (!(opflags & FUSE_IOMAP_OP_DIRECT))
+		return -ENOSYS;
+
+	/* fall back to slow path for inline data reads */
+	if (inode->i_flags & EXT4_INLINE_DATA_FL)
+		return -ENOSYS;
+
+	if (inode->i_flags & EXT4_EXTENTS_FL)
+		return fuse2fs_iomap_begin_extent(ff, ino, inode, pos, count,
+						  opflags, read);
+
+	return fuse2fs_iomap_begin_indirect(ff, ino, inode, pos, count,
+					    opflags, read);
 }
 
 static int fuse2fs_iomap_begin_write(struct fuse2fs *ff, ext2_ino_t ino,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 06/19] fuse2fs: add extent dump function for debugging
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (4 preceding siblings ...)
  2026-02-23 23:37   ` [PATCH 05/19] fuse2fs: implement directio file reads Darrick J. Wong
@ 2026-02-23 23:37   ` Darrick J. Wong
  2026-02-23 23:37   ` [PATCH 07/19] fuse2fs: implement direct write support Darrick J. Wong
                     ` (12 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:37 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Add a function to dump an inode's extent map for debugging purposes.
This helped debug a problem with generic/299 failing on 1k fsblock
filesystems:

 --- a/tests/generic/299.out	2025-07-15 14:45:15.030113607 -0700
 +++ b/tests/generic/299.out.bad	2025-07-16 19:33:50.889344998 -0700
 @@ -3,3 +3,4 @@ QA output created by 299
  Run fio with random aio-dio pattern

  Start fallocate/truncate loop
 +fio: io_u error on file /opt/direct_aio.0.0: Input/output error: write offset=2602827776, buflen=131072

(The cause of this was misuse of the libext2fs extent code)

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/fuse2fs.c    |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 9fa875d1d99ae8..9d434294613d0d 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -889,6 +889,74 @@ static inline int fuse4fs_iomap_enabled(const struct fuse4fs *ff)
 # define fuse4fs_iomap_enabled(...)	(0)
 #endif
 
+static inline void fuse4fs_dump_extents(struct fuse4fs *ff, ext2_ino_t ino,
+					struct ext2_inode_large *inode,
+					const char *why)
+{
+	ext2_filsys fs = ff->fs;
+	unsigned int nr = 0;
+	blk64_t blockcount = 0;
+	struct ext2_inode_large xinode;
+	struct ext2fs_extent extent;
+	ext2_extent_handle_t extents;
+	int op = EXT2_EXTENT_ROOT;
+	errcode_t retval;
+
+	if (!inode) {
+		inode = &xinode;
+
+		retval = fuse4fs_read_inode(fs, ino, inode);
+		if (retval) {
+			com_err(__func__, retval, _("reading ino %u"), ino);
+			return;
+		}
+	}
+
+	if (!(inode->i_flags & EXT4_EXTENTS_FL))
+		return;
+
+	printf("%s: %s ino=%u isize %llu iblocks %llu\n", __func__, why, ino,
+	       EXT2_I_SIZE(inode),
+	       (ext2fs_get_stat_i_blocks(fs, EXT2_INODE(inode)) * 512) /
+	        fs->blocksize);
+	fflush(stdout);
+
+	retval = ext2fs_extent_open(fs, ino, &extents);
+	if (retval) {
+		com_err(__func__, retval, _("opening extents of ino \"%u\""),
+			ino);
+		return;
+	}
+
+	while ((retval = ext2fs_extent_get(extents, op, &extent)) == 0) {
+		op = EXT2_EXTENT_NEXT;
+
+		if (extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT)
+			continue;
+
+		printf("[%u]: %s ino=%u lblk 0x%llx pblk 0x%llx len 0x%x flags 0x%x\n",
+		       nr++, why, ino, extent.e_lblk, extent.e_pblk,
+		       extent.e_len, extent.e_flags);
+		fflush(stdout);
+		if (extent.e_flags & EXT2_EXTENT_FLAGS_LEAF)
+			blockcount += extent.e_len;
+		else
+			blockcount++;
+	}
+	if (retval == EXT2_ET_EXTENT_NO_NEXT)
+		retval = 0;
+	if (retval) {
+		com_err(__func__, retval, ("getting extents of ino %u"),
+			ino);
+	}
+	if (inode->i_file_acl)
+		blockcount++;
+	printf("%s: %s sum(e_len) %llu\n", __func__, why, blockcount);
+	fflush(stdout);
+
+	ext2fs_extent_free(extents);
+}
+
 static void get_now(struct timespec *now)
 {
 #ifdef CLOCK_REALTIME
@@ -6225,6 +6293,8 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 
 	/* Not filling even the first byte will make the kernel unhappy. */
 	if (read.offset > pos || read.offset + read.length <= pos) {
+		if (ff->debug)
+			fuse4fs_dump_extents(ff, ino, &inode, "BAD DATA");
 		ret = translate_error(fs, ino, EXT2_ET_INODE_CORRUPTED);
 		goto out_unlock;
 	}
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index a5105855f1669a..a039d2af0201ff 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -728,6 +728,74 @@ static inline int fuse2fs_iomap_enabled(const struct fuse2fs *ff)
 # define fuse2fs_iomap_enabled(...)	(0)
 #endif
 
+static inline void fuse2fs_dump_extents(struct fuse2fs *ff, ext2_ino_t ino,
+					struct ext2_inode_large *inode,
+					const char *why)
+{
+	ext2_filsys fs = ff->fs;
+	unsigned int nr = 0;
+	blk64_t blockcount = 0;
+	struct ext2_inode_large xinode;
+	struct ext2fs_extent extent;
+	ext2_extent_handle_t extents;
+	int op = EXT2_EXTENT_ROOT;
+	errcode_t retval;
+
+	if (!inode) {
+		inode = &xinode;
+
+		retval = fuse2fs_read_inode(fs, ino, inode);
+		if (retval) {
+			com_err(__func__, retval, _("reading ino %u"), ino);
+			return;
+		}
+	}
+
+	if (!(inode->i_flags & EXT4_EXTENTS_FL))
+		return;
+
+	printf("%s: %s ino=%u isize %llu iblocks %llu\n", __func__, why, ino,
+	       EXT2_I_SIZE(inode),
+	       (ext2fs_get_stat_i_blocks(fs, EXT2_INODE(inode)) * 512) /
+	        fs->blocksize);
+	fflush(stdout);
+
+	retval = ext2fs_extent_open(fs, ino, &extents);
+	if (retval) {
+		com_err(__func__, retval, _("opening extents of ino \"%u\""),
+			ino);
+		return;
+	}
+
+	while ((retval = ext2fs_extent_get(extents, op, &extent)) == 0) {
+		op = EXT2_EXTENT_NEXT;
+
+		if (extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT)
+			continue;
+
+		printf("[%u]: %s ino=%u lblk 0x%llx pblk 0x%llx len 0x%x flags 0x%x\n",
+		       nr++, why, ino, extent.e_lblk, extent.e_pblk,
+		       extent.e_len, extent.e_flags);
+		fflush(stdout);
+		if (extent.e_flags & EXT2_EXTENT_FLAGS_LEAF)
+			blockcount += extent.e_len;
+		else
+			blockcount++;
+	}
+	if (retval == EXT2_ET_EXTENT_NO_NEXT)
+		retval = 0;
+	if (retval) {
+		com_err(__func__, retval, ("getting extents of ino %u"),
+			ino);
+	}
+	if (inode->i_file_acl)
+		blockcount++;
+	printf("%s: %s sum(e_len) %llu\n", __func__, why, blockcount);
+	fflush(stdout);
+
+	ext2fs_extent_free(extents);
+}
+
 static void get_now(struct timespec *now)
 {
 #ifdef CLOCK_REALTIME
@@ -5673,6 +5741,8 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
 
 	/* Not filling even the first byte will make the kernel unhappy. */
 	if (read->offset > pos || read->offset + read->length <= pos) {
+		if (ff->debug)
+			fuse2fs_dump_extents(ff, attr_ino, &inode, "BAD DATA");
 		ret = translate_error(fs, attr_ino, EXT2_ET_INODE_CORRUPTED);
 		goto out_unlock;
 	}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 07/19] fuse2fs: implement direct write support
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (5 preceding siblings ...)
  2026-02-23 23:37   ` [PATCH 06/19] fuse2fs: add extent dump function for debugging Darrick J. Wong
@ 2026-02-23 23:37   ` Darrick J. Wong
  2026-02-23 23:38   ` [PATCH 08/19] fuse2fs: turn on iomap for pagecache IO Darrick J. Wong
                     ` (11 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:37 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Wire up an iomap_begin method that can allocate into holes so that we
can do directio writes.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |  477 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/fuse2fs.c    |  471 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 942 insertions(+), 6 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 9d434294613d0d..2f95a1ecbfa330 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -6234,12 +6234,106 @@ static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino,
 					    opflags, read);
 }
 
+static int fuse4fs_iomap_write_allocate(struct fuse4fs *ff, ext2_ino_t ino,
+					struct ext2_inode_large *inode,
+					off_t pos, uint64_t count,
+					uint32_t opflags,
+					struct fuse_file_iomap *read,
+					bool *dirty)
+{
+	ext2_filsys fs = ff->fs;
+	blk64_t startoff = FUSE4FS_B_TO_FSBT(ff, pos);
+	blk64_t stopoff = FUSE4FS_B_TO_FSB(ff, pos + count);
+	blk64_t old_iblocks;
+	errcode_t err;
+	int ret;
+
+	dbg_printf(ff,
+ "%s: ino=%d startoff 0x%llx blockcount 0x%llx\n",
+		   __func__, ino, startoff, stopoff - startoff);
+
+	if (!fuse4fs_can_allocate(ff, stopoff - startoff))
+		return -ENOSPC;
+
+	old_iblocks = ext2fs_get_stat_i_blocks(fs, EXT2_INODE(inode));
+	err = ext2fs_fallocate(fs, EXT2_FALLOCATE_FORCE_UNINIT, ino,
+			       EXT2_INODE(inode), ~0ULL, startoff,
+			       stopoff - startoff);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/*
+	 * New allocations for file data blocks on indirect mapped files are
+	 * zeroed through the IO manager so we have to flush it to disk.
+	 */
+	if (!(inode->i_flags & EXT4_EXTENTS_FL) &&
+	    old_iblocks != ext2fs_get_stat_i_blocks(fs, EXT2_INODE(inode))) {
+		err = io_channel_flush(fs->io);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	/* pick up the newly allocated mapping */
+	ret = fuse4fs_iomap_begin_read(ff, ino, inode, pos, count, opflags,
+				       read);
+	if (ret)
+		return ret;
+
+	read->flags |= FUSE_IOMAP_F_DIRTY;
+	*dirty = true;
+	return 0;
+}
+
+static off_t fuse4fs_max_file_size(const struct fuse4fs *ff,
+				   const struct ext2_inode_large *inode)
+{
+	ext2_filsys fs = ff->fs;
+	blk64_t addr_per_block, max_map_block;
+
+	if (inode->i_flags & EXT4_EXTENTS_FL) {
+		max_map_block = (1ULL << 32) - 1;
+	} else {
+		addr_per_block = fs->blocksize >> 2;
+		max_map_block = addr_per_block;
+		max_map_block += addr_per_block * addr_per_block;
+		max_map_block += addr_per_block * addr_per_block * addr_per_block;
+		max_map_block += 12;
+	}
+
+	return FUSE4FS_FSB_TO_B(ff, max_map_block) + (fs->blocksize - 1);
+}
+
 static int fuse4fs_iomap_begin_write(struct fuse4fs *ff, ext2_ino_t ino,
 				     struct ext2_inode_large *inode, off_t pos,
 				     uint64_t count, uint32_t opflags,
-				     struct fuse_file_iomap *read)
+				     struct fuse_file_iomap *read,
+				     bool *dirty)
 {
-	return -ENOSYS;
+	off_t max_size = fuse4fs_max_file_size(ff, inode);
+	int ret;
+
+	if (!(opflags & FUSE_IOMAP_OP_DIRECT))
+		return -ENOSYS;
+
+	if (pos >= max_size)
+		return -EFBIG;
+
+	if (pos >= max_size - count)
+		count = max_size - pos;
+
+	ret = fuse4fs_iomap_begin_read(ff, ino, inode, pos, count, opflags,
+				       read);
+	if (ret)
+		return ret;
+
+	if (fuse_iomap_need_write_allocate(opflags, read)) {
+		ret = fuse4fs_iomap_write_allocate(ff, ino, inode, pos, count,
+						   opflags, read, dirty);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
 }
 
 static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
@@ -6251,6 +6345,7 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 	ext2_filsys fs;
 	ext2_ino_t ino;
 	errcode_t err;
+	bool dirty = false;
 	int ret = 0;
 
 	FUSE4FS_CHECK_CONTEXT(req);
@@ -6274,7 +6369,7 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 						 opflags, &read);
 	else if (fuse_iomap_is_write(opflags))
 		ret = fuse4fs_iomap_begin_write(ff, ino, &inode, pos, count,
-						opflags, &read);
+						opflags, &read, &dirty);
 	else
 		ret = fuse4fs_iomap_begin_read(ff, ino, &inode, pos, count,
 					       opflags, &read);
@@ -6299,6 +6394,14 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 		goto out_unlock;
 	}
 
+	if (dirty) {
+		err = fuse4fs_write_inode(fs, ino, &inode);
+		if (err) {
+			ret = translate_error(fs, ino, err);
+			goto out_unlock;
+		}
+	}
+
 out_unlock:
 	fuse4fs_finish(ff, ret);
 	if (ret)
@@ -6446,6 +6549,373 @@ static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
 	else
 		fuse_reply_iomap_config(req, &cfg);
 }
+
+static inline bool fuse4fs_can_merge_mappings(const struct ext2fs_extent *left,
+					      const struct ext2fs_extent *right)
+{
+	uint64_t max_len = (left->e_flags & EXT2_EXTENT_FLAGS_UNINIT) ?
+				EXT_UNINIT_MAX_LEN : EXT_INIT_MAX_LEN;
+
+	return left->e_lblk + left->e_len == right->e_lblk &&
+	       left->e_pblk + left->e_len == right->e_pblk &&
+	       (left->e_flags & EXT2_EXTENT_FLAGS_UNINIT) ==
+	        (right->e_flags & EXT2_EXTENT_FLAGS_UNINIT) &&
+	       (uint64_t)left->e_len + right->e_len <= max_len;
+}
+
+static int fuse4fs_try_merge_mappings(struct fuse4fs *ff, ext2_ino_t ino,
+				      ext2_extent_handle_t handle,
+				      blk64_t startoff)
+{
+	ext2_filsys fs = ff->fs;
+	struct ext2fs_extent left, right;
+	errcode_t err;
+
+	/* Look up the mappings before startoff */
+	err = fuse4fs_get_mapping_at(ff, handle, startoff - 1, &left);
+	if (err == EXT2_ET_EXTENT_NOT_FOUND)
+		return 0;
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/* Look up the mapping at startoff */
+	err = fuse4fs_get_mapping_at(ff, handle, startoff, &right);
+	if (err == EXT2_ET_EXTENT_NOT_FOUND)
+		return 0;
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/* Can we combine them? */
+	if (!fuse4fs_can_merge_mappings(&left, &right))
+		return 0;
+
+	/*
+	 * Delete the mapping after startoff because libext2fs cannot handle
+	 * overlapping mappings.
+	 */
+	err = ext2fs_extent_delete(handle, 0);
+	DUMP_EXTENT(ff, "remover", startoff, err, &right);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	err = ext2fs_extent_fix_parents(handle);
+	DUMP_EXTENT(ff, "fixremover", startoff, err, &right);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/* Move back and lengthen the mapping before startoff */
+	err = ext2fs_extent_goto(handle, left.e_lblk);
+	DUMP_EXTENT(ff, "movel", startoff - 1, err, &left);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	left.e_len += right.e_len;
+	err = ext2fs_extent_replace(handle, 0, &left);
+	DUMP_EXTENT(ff, "replacel", startoff - 1, err, &left);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	err = ext2fs_extent_fix_parents(handle);
+	DUMP_EXTENT(ff, "fixreplacel", startoff - 1, err, &left);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	return 0;
+}
+
+static int fuse4fs_convert_unwritten_mapping(struct fuse4fs *ff,
+					     ext2_ino_t ino,
+					     struct ext2_inode_large *inode,
+					     ext2_extent_handle_t handle,
+					     blk64_t *cursor, blk64_t stopoff)
+{
+	ext2_filsys fs = ff->fs;
+	struct ext2fs_extent extent;
+	blk64_t startoff = *cursor;
+	errcode_t err;
+
+	/*
+	 * Find the mapping at startoff.  Note that we can find holes because
+	 * the mapping data can change due to racing writes.
+	 */
+	err = fuse4fs_get_mapping_at(ff, handle, startoff, &extent);
+	if (err == EXT2_ET_EXTENT_NOT_FOUND) {
+		/*
+		 * If we didn't find any mappings at all then the file is
+		 * completely sparse.  There's nothing to convert.
+		 */
+		*cursor = stopoff;
+		return 0;
+	}
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/*
+	 * The mapping is completely to the left of the range that we want.
+	 * Let's see what's in the next extent, if there is one.
+	 */
+	if (startoff >= extent.e_lblk + extent.e_len) {
+		/*
+		 * Mapping ends to the left of the current position.  Try to
+		 * find the next mapping.  If there is no next mapping, then
+		 * we're done.
+		 */
+		err = fuse4fs_get_next_mapping(ff, handle, startoff, &extent);
+		if (err == EXT2_ET_EXTENT_NOT_FOUND) {
+			*cursor = stopoff;
+			return 0;
+		}
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	/*
+	 * The mapping is completely to the right of the range that we want,
+	 * so we're done.
+	 */
+	if (extent.e_lblk >= stopoff) {
+		*cursor = stopoff;
+		return 0;
+	}
+
+	/*
+	 * At this point, we have a mapping that overlaps (startoff, stopoff].
+	 * If the mapping is already written, move on to the next one.
+	 */
+	if (!(extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT))
+		goto next;
+
+	if (startoff > extent.e_lblk) {
+		struct ext2fs_extent newex = extent;
+
+		/*
+		 * Unwritten mapping starts before startoff.  Shorten
+		 * the previous mapping...
+		 */
+		newex.e_len = startoff - extent.e_lblk;
+		err = ext2fs_extent_replace(handle, 0, &newex);
+		DUMP_EXTENT(ff, "shortenp", startoff, err, &newex);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixshortenp", startoff, err, &newex);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		/* ...and create new written mapping at startoff. */
+		extent.e_len -= newex.e_len;
+		extent.e_lblk += newex.e_len;
+		extent.e_pblk += newex.e_len;
+		extent.e_flags = newex.e_flags & ~EXT2_EXTENT_FLAGS_UNINIT;
+
+		err = ext2fs_extent_insert(handle,
+					   EXT2_EXTENT_INSERT_AFTER,
+					   &extent);
+		DUMP_EXTENT(ff, "insertx", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixinsertx", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	if (extent.e_lblk + extent.e_len > stopoff) {
+		struct ext2fs_extent newex = extent;
+
+		/*
+		 * Unwritten mapping ends after stopoff.  Shorten the current
+		 * mapping...
+		 */
+		extent.e_len = stopoff - extent.e_lblk;
+		extent.e_flags &= ~EXT2_EXTENT_FLAGS_UNINIT;
+
+		err = ext2fs_extent_replace(handle, 0, &extent);
+		DUMP_EXTENT(ff, "shortenn", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixshortenn", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		/* ..and create a new unwritten mapping at stopoff. */
+		newex.e_pblk += extent.e_len;
+		newex.e_lblk += extent.e_len;
+		newex.e_len -= extent.e_len;
+		newex.e_flags |= EXT2_EXTENT_FLAGS_UNINIT;
+
+		err = ext2fs_extent_insert(handle,
+					   EXT2_EXTENT_INSERT_AFTER,
+					   &newex);
+		DUMP_EXTENT(ff, "insertn", startoff, err, &newex);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixinsertn", startoff, err, &newex);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	/* Still unwritten?  Update the state. */
+	if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) {
+		extent.e_flags &= ~EXT2_EXTENT_FLAGS_UNINIT;
+
+		err = ext2fs_extent_replace(handle, 0, &extent);
+		DUMP_EXTENT(ff, "replacex", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixreplacex", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+next:
+	/* Try to merge with the previous extent */
+	if (startoff > 0) {
+		err = fuse4fs_try_merge_mappings(ff, ino, handle, startoff);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	*cursor = extent.e_lblk + extent.e_len;
+	return 0;
+}
+
+static int fuse4fs_convert_unwritten_mappings(struct fuse4fs *ff,
+					      ext2_ino_t ino,
+					      struct ext2_inode_large *inode,
+					      off_t pos, size_t written)
+{
+	ext2_extent_handle_t handle;
+	ext2_filsys fs = ff->fs;
+	blk64_t startoff = FUSE4FS_B_TO_FSBT(ff, pos);
+	const blk64_t stopoff = FUSE4FS_B_TO_FSB(ff, pos + written);
+	errcode_t err;
+	int ret;
+
+	err = ext2fs_extent_open2(fs, ino, EXT2_INODE(inode), &handle);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/* Walk every mapping in the range, converting them. */
+	while (startoff < stopoff) {
+		blk64_t old_startoff = startoff;
+
+		ret = fuse4fs_convert_unwritten_mapping(ff, ino, inode, handle,
+							&startoff, stopoff);
+		if (ret)
+			goto out_handle;
+		if (startoff <= old_startoff) {
+			/* Do not go backwards. */
+			ret = translate_error(fs, ino, EXT2_ET_INODE_CORRUPTED);
+			goto out_handle;
+		}
+	}
+
+	/* Try to merge the right edge */
+	ret = fuse4fs_try_merge_mappings(ff, ino, handle, stopoff);
+out_handle:
+	ext2fs_extent_free(handle);
+	return ret;
+}
+
+static void op_iomap_ioend(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
+			   off_t pos, size_t written, uint32_t ioendflags,
+			   int error, uint32_t dev, uint64_t new_addr)
+{
+	struct fuse4fs *ff = fuse4fs_get(req);
+	struct ext2_inode_large inode;
+	ext2_filsys fs;
+	ext2_ino_t ino;
+	ext2_off64_t isize;
+	errcode_t err;
+	bool dirty = false;
+	off_t newsize = -1;
+	int ret = 0;
+
+	FUSE4FS_CHECK_CONTEXT(req);
+	FUSE4FS_CONVERT_FINO(req, &ino, fino);
+
+	dbg_printf(ff,
+ "%s: ino=%d pos=0x%llx written=0x%zx ioendflags=0x%x error=%d dev=%u new_addr=0x%llx\n",
+		   __func__, ino,
+		   (unsigned long long)pos,
+		   written,
+		   ioendflags,
+		   error,
+		   dev,
+		   (unsigned long long)new_addr);
+
+	if (error) {
+		fuse_reply_err(req, -error);
+		return;
+	}
+
+	fs = fuse4fs_start(ff);
+
+	/* should never see these ioend types */
+	if (ioendflags & FUSE_IOMAP_IOEND_SHARED) {
+		ret = translate_error(fs, ino, EXT2_ET_FILESYSTEM_CORRUPTED);
+		goto out_unlock;
+	}
+
+	err = fuse4fs_read_inode(fs, ino, &inode);
+	if (err) {
+		ret = translate_error(fs, ino, err);
+		goto out_unlock;
+	}
+
+	if (ioendflags & FUSE_IOMAP_IOEND_UNWRITTEN) {
+		/* unwritten extents are only supported on extents files */
+		if (!(inode.i_flags & EXT4_EXTENTS_FL)) {
+			ret = translate_error(fs, ino,
+					      EXT2_ET_FILESYSTEM_CORRUPTED);
+			goto out_unlock;
+		}
+
+		ret = fuse4fs_convert_unwritten_mappings(ff, ino, &inode,
+							 pos, written);
+		if (ret)
+			goto out_unlock;
+
+		dirty = true;
+	}
+
+	isize = EXT2_I_SIZE(&inode);
+	if (pos + written > isize) {
+		err = ext2fs_inode_size_set(fs, EXT2_INODE(&inode),
+					    pos + written);
+		if (err) {
+			ret = translate_error(fs, ino, err);
+			goto out_unlock;
+		}
+
+		dirty = true;
+	}
+
+	if (dirty) {
+		err = fuse4fs_write_inode(fs, ino, &inode);
+		if (err) {
+			ret = translate_error(fs, ino, err);
+			goto out_unlock;
+		}
+	}
+
+	newsize = EXT2_I_SIZE(&inode);
+out_unlock:
+	fuse4fs_finish(ff, ret);
+	if (ret)
+		fuse_reply_err(req, -ret);
+	else
+		fuse_reply_iomap_ioend(req, newsize);
+}
 #endif /* HAVE_FUSE_IOMAP */
 
 static struct fuse_lowlevel_ops fs_ops = {
@@ -6495,6 +6965,7 @@ static struct fuse_lowlevel_ops fs_ops = {
 	.iomap_begin = op_iomap_begin,
 	.iomap_end = op_iomap_end,
 	.iomap_config = op_iomap_config,
+	.iomap_ioend = op_iomap_ioend,
 #endif /* HAVE_FUSE_IOMAP */
 };
 
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index a039d2af0201ff..4b64a37aa0e029 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -5680,12 +5680,103 @@ static int fuse2fs_iomap_begin_read(struct fuse2fs *ff, ext2_ino_t ino,
 					    opflags, read);
 }
 
+static int fuse2fs_iomap_write_allocate(struct fuse2fs *ff, ext2_ino_t ino,
+				     struct ext2_inode_large *inode, off_t pos,
+				     uint64_t count, uint32_t opflags,
+				     struct fuse_file_iomap *read, bool *dirty)
+{
+	ext2_filsys fs = ff->fs;
+	blk64_t startoff = FUSE2FS_B_TO_FSBT(ff, pos);
+	blk64_t stopoff = FUSE2FS_B_TO_FSB(ff, pos + count);
+	blk64_t old_iblocks;
+	errcode_t err;
+	int ret;
+
+	dbg_printf(ff, "%s: write_alloc ino=%u startoff 0x%llx blockcount 0x%llx\n",
+		   __func__, ino, startoff, stopoff - startoff);
+
+	if (!fs_can_allocate(ff, stopoff - startoff))
+		return -ENOSPC;
+
+	old_iblocks = ext2fs_get_stat_i_blocks(fs, EXT2_INODE(inode));
+	err = ext2fs_fallocate(fs, EXT2_FALLOCATE_FORCE_UNINIT, ino,
+			       EXT2_INODE(inode), ~0ULL, startoff,
+			       stopoff - startoff);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/*
+	 * New allocations for file data blocks on indirect mapped files are
+	 * zeroed through the IO manager so we have to flush it to disk.
+	 */
+	if (!(inode->i_flags & EXT4_EXTENTS_FL) &&
+	    old_iblocks != ext2fs_get_stat_i_blocks(fs, EXT2_INODE(inode))) {
+		err = io_channel_flush(fs->io);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	/* pick up the newly allocated mapping */
+	ret = fuse2fs_iomap_begin_read(ff, ino, inode, pos, count, opflags,
+				       read);
+	if (ret)
+		return ret;
+
+	read->flags |= FUSE_IOMAP_F_DIRTY;
+	*dirty = true;
+	return 0;
+}
+
+static off_t fuse2fs_max_file_size(const struct fuse2fs *ff,
+				   const struct ext2_inode_large *inode)
+{
+	ext2_filsys fs = ff->fs;
+	blk64_t addr_per_block, max_map_block;
+
+	if (inode->i_flags & EXT4_EXTENTS_FL) {
+		max_map_block = (1ULL << 32) - 1;
+	} else {
+		addr_per_block = fs->blocksize >> 2;
+		max_map_block = addr_per_block;
+		max_map_block += addr_per_block * addr_per_block;
+		max_map_block += addr_per_block * addr_per_block * addr_per_block;
+		max_map_block += 12;
+	}
+
+	return FUSE2FS_FSB_TO_B(ff, max_map_block) + (fs->blocksize - 1);
+}
+
 static int fuse2fs_iomap_begin_write(struct fuse2fs *ff, ext2_ino_t ino,
 				     struct ext2_inode_large *inode, off_t pos,
 				     uint64_t count, uint32_t opflags,
-				     struct fuse_file_iomap *read)
+				     struct fuse_file_iomap *read,
+				     bool *dirty)
 {
-	return -ENOSYS;
+	off_t max_size = fuse2fs_max_file_size(ff, inode);
+	int ret;
+
+	if (!(opflags & FUSE_IOMAP_OP_DIRECT))
+		return -ENOSYS;
+
+	if (pos >= max_size)
+		return -EFBIG;
+
+	if (pos >= max_size - count)
+		count = max_size - pos;
+
+	ret = fuse2fs_iomap_begin_read(ff, ino, inode, pos, count, opflags,
+				       read);
+	if (ret)
+		return ret;
+
+	if (fuse_iomap_need_write_allocate(opflags, read)) {
+		ret = fuse2fs_iomap_write_allocate(ff, ino, inode, pos, count,
+						   opflags, read, dirty);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
 }
 
 static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
@@ -5697,6 +5788,7 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
 	struct ext2_inode_large inode;
 	ext2_filsys fs;
 	errcode_t err;
+	bool dirty = false;
 	int ret = 0;
 
 	FUSE2FS_CHECK_CONTEXT(ff);
@@ -5722,7 +5814,7 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
 						 count, opflags, read);
 	else if (fuse_iomap_is_write(opflags))
 		ret = fuse2fs_iomap_begin_write(ff, attr_ino, &inode, pos,
-						count, opflags, read);
+						count, opflags, read, &dirty);
 	else
 		ret = fuse2fs_iomap_begin_read(ff, attr_ino, &inode, pos,
 					       count, opflags, read);
@@ -5747,6 +5839,14 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
 		goto out_unlock;
 	}
 
+	if (dirty) {
+		err = fuse2fs_write_inode(fs, attr_ino, &inode);
+		if (err) {
+			ret = translate_error(fs, attr_ino, err);
+			goto out_unlock;
+		}
+	}
+
 out_unlock:
 	fuse2fs_finish(ff, ret);
 	return ret;
@@ -5888,6 +5988,370 @@ static int op_iomap_config(uint64_t flags, off_t maxbytes,
 	fuse2fs_finish(ff, ret);
 	return ret;
 }
+
+static inline bool fuse2fs_can_merge_mappings(const struct ext2fs_extent *left,
+					      const struct ext2fs_extent *right)
+{
+	uint64_t max_len = (left->e_flags & EXT2_EXTENT_FLAGS_UNINIT) ?
+				EXT_UNINIT_MAX_LEN : EXT_INIT_MAX_LEN;
+
+	return left->e_lblk + left->e_len == right->e_lblk &&
+	       left->e_pblk + left->e_len == right->e_pblk &&
+	       (left->e_flags & EXT2_EXTENT_FLAGS_UNINIT) ==
+	        (right->e_flags & EXT2_EXTENT_FLAGS_UNINIT) &&
+	       (uint64_t)left->e_len + right->e_len <= max_len;
+}
+
+static int fuse2fs_try_merge_mappings(struct fuse2fs *ff, ext2_ino_t ino,
+				      ext2_extent_handle_t handle,
+				      blk64_t startoff)
+{
+	ext2_filsys fs = ff->fs;
+	struct ext2fs_extent left, right;
+	errcode_t err;
+
+	/* Look up the mappings before startoff */
+	err = fuse2fs_get_mapping_at(ff, handle, startoff - 1, &left);
+	if (err == EXT2_ET_EXTENT_NOT_FOUND)
+		return 0;
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/* Look up the mapping at startoff */
+	err = fuse2fs_get_mapping_at(ff, handle, startoff, &right);
+	if (err == EXT2_ET_EXTENT_NOT_FOUND)
+		return 0;
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/* Can we combine them? */
+	if (!fuse2fs_can_merge_mappings(&left, &right))
+		return 0;
+
+	/*
+	 * Delete the mapping after startoff because libext2fs cannot handle
+	 * overlapping mappings.
+	 */
+	err = ext2fs_extent_delete(handle, 0);
+	DUMP_EXTENT(ff, "remover", startoff, err, &right);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	err = ext2fs_extent_fix_parents(handle);
+	DUMP_EXTENT(ff, "fixremover", startoff, err, &right);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/* Move back and lengthen the mapping before startoff */
+	err = ext2fs_extent_goto(handle, left.e_lblk);
+	DUMP_EXTENT(ff, "movel", startoff - 1, err, &left);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	left.e_len += right.e_len;
+	err = ext2fs_extent_replace(handle, 0, &left);
+	DUMP_EXTENT(ff, "replacel", startoff - 1, err, &left);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	err = ext2fs_extent_fix_parents(handle);
+	DUMP_EXTENT(ff, "fixreplacel", startoff - 1, err, &left);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	return 0;
+}
+
+static int fuse2fs_convert_unwritten_mapping(struct fuse2fs *ff,
+					     ext2_ino_t ino,
+					     struct ext2_inode_large *inode,
+					     ext2_extent_handle_t handle,
+					     blk64_t *cursor, blk64_t stopoff)
+{
+	ext2_filsys fs = ff->fs;
+	struct ext2fs_extent extent;
+	blk64_t startoff = *cursor;
+	errcode_t err;
+
+	/*
+	 * Find the mapping at startoff.  Note that we can find holes because
+	 * the mapping data can change due to racing writes.
+	 */
+	err = fuse2fs_get_mapping_at(ff, handle, startoff, &extent);
+	if (err == EXT2_ET_EXTENT_NOT_FOUND) {
+		/*
+		 * If we didn't find any mappings at all then the file is
+		 * completely sparse.  There's nothing to convert.
+		 */
+		*cursor = stopoff;
+		return 0;
+	}
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/*
+	 * The mapping is completely to the left of the range that we want.
+	 * Let's see what's in the next extent, if there is one.
+	 */
+	if (startoff >= extent.e_lblk + extent.e_len) {
+		/*
+		 * Mapping ends to the left of the current position.  Try to
+		 * find the next mapping.  If there is no next mapping, then
+		 * we're done.
+		 */
+		err = fuse2fs_get_next_mapping(ff, handle, startoff, &extent);
+		if (err == EXT2_ET_EXTENT_NOT_FOUND) {
+			*cursor = stopoff;
+			return 0;
+		}
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	/*
+	 * The mapping is completely to the right of the range that we want,
+	 * so we're done.
+	 */
+	if (extent.e_lblk >= stopoff) {
+		*cursor = stopoff;
+		return 0;
+	}
+
+	/*
+	 * At this point, we have a mapping that overlaps (startoff, stopoff].
+	 * If the mapping is already written, move on to the next one.
+	 */
+	if (!(extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT))
+		goto next;
+
+	if (startoff > extent.e_lblk) {
+		struct ext2fs_extent newex = extent;
+
+		/*
+		 * Unwritten mapping starts before startoff.  Shorten
+		 * the previous mapping...
+		 */
+		newex.e_len = startoff - extent.e_lblk;
+		err = ext2fs_extent_replace(handle, 0, &newex);
+		DUMP_EXTENT(ff, "shortenp", startoff, err, &newex);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixshortenp", startoff, err, &newex);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		/* ...and create new written mapping at startoff. */
+		extent.e_len -= newex.e_len;
+		extent.e_lblk += newex.e_len;
+		extent.e_pblk += newex.e_len;
+		extent.e_flags = newex.e_flags & ~EXT2_EXTENT_FLAGS_UNINIT;
+
+		err = ext2fs_extent_insert(handle,
+					   EXT2_EXTENT_INSERT_AFTER,
+					   &extent);
+		DUMP_EXTENT(ff, "insertx", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixinsertx", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	if (extent.e_lblk + extent.e_len > stopoff) {
+		struct ext2fs_extent newex = extent;
+
+		/*
+		 * Unwritten mapping ends after stopoff.  Shorten the current
+		 * mapping...
+		 */
+		extent.e_len = stopoff - extent.e_lblk;
+		extent.e_flags &= ~EXT2_EXTENT_FLAGS_UNINIT;
+
+		err = ext2fs_extent_replace(handle, 0, &extent);
+		DUMP_EXTENT(ff, "shortenn", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixshortenn", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		/* ..and create a new unwritten mapping at stopoff. */
+		newex.e_pblk += extent.e_len;
+		newex.e_lblk += extent.e_len;
+		newex.e_len -= extent.e_len;
+		newex.e_flags |= EXT2_EXTENT_FLAGS_UNINIT;
+
+		err = ext2fs_extent_insert(handle,
+					   EXT2_EXTENT_INSERT_AFTER,
+					   &newex);
+		DUMP_EXTENT(ff, "insertn", startoff, err, &newex);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixinsertn", startoff, err, &newex);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	/* Still unwritten?  Update the state. */
+	if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) {
+		extent.e_flags &= ~EXT2_EXTENT_FLAGS_UNINIT;
+
+		err = ext2fs_extent_replace(handle, 0, &extent);
+		DUMP_EXTENT(ff, "replacex", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+
+		err = ext2fs_extent_fix_parents(handle);
+		DUMP_EXTENT(ff, "fixreplacex", startoff, err, &extent);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+next:
+	/* Try to merge with the previous extent */
+	if (startoff > 0) {
+		err = fuse2fs_try_merge_mappings(ff, ino, handle, startoff);
+		if (err)
+			return translate_error(fs, ino, err);
+	}
+
+	*cursor = extent.e_lblk + extent.e_len;
+	return 0;
+}
+
+static int fuse2fs_convert_unwritten_mappings(struct fuse2fs *ff,
+					      ext2_ino_t ino,
+					      struct ext2_inode_large *inode,
+					      off_t pos, size_t written)
+{
+	ext2_extent_handle_t handle;
+	ext2_filsys fs = ff->fs;
+	blk64_t startoff = FUSE2FS_B_TO_FSBT(ff, pos);
+	const blk64_t stopoff = FUSE2FS_B_TO_FSB(ff, pos + written);
+	errcode_t err;
+	int ret;
+
+	err = ext2fs_extent_open2(fs, ino, EXT2_INODE(inode), &handle);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	/* Walk every mapping in the range, converting them. */
+	while (startoff < stopoff) {
+		blk64_t old_startoff = startoff;
+
+		ret = fuse2fs_convert_unwritten_mapping(ff, ino, inode, handle,
+							&startoff, stopoff);
+		if (ret)
+			goto out_handle;
+		if (startoff <= old_startoff) {
+			/* Do not go backwards. */
+			ret = translate_error(fs, ino, EXT2_ET_INODE_CORRUPTED);
+			goto out_handle;
+		}
+	}
+
+	/* Try to merge the right edge */
+	ret = fuse2fs_try_merge_mappings(ff, ino, handle, stopoff);
+out_handle:
+	ext2fs_extent_free(handle);
+	return ret;
+}
+
+static int op_iomap_ioend(const char *path, uint64_t nodeid, uint64_t attr_ino,
+			  off_t pos, size_t written, uint32_t ioendflags,
+			  int error, uint32_t dev, uint64_t new_addr,
+			  off_t *newsize)
+{
+	struct fuse2fs *ff = fuse2fs_get();
+	struct ext2_inode_large inode;
+	ext2_filsys fs;
+	errcode_t err;
+	ext2_off64_t isize;
+	bool dirty = false;
+	int ret = 0;
+
+	FUSE2FS_CHECK_CONTEXT(ff);
+
+	dbg_printf(ff,
+ "%s: path=%s nodeid=%llu attr_ino=%llu pos=0x%llx written=0x%zx ioendflags=0x%x error=%d dev=%u new_addr=%llu\n",
+		   __func__, path,
+		   (unsigned long long)nodeid,
+		   (unsigned long long)attr_ino,
+		   (unsigned long long)pos,
+		   written,
+		   ioendflags,
+		   error,
+		   dev,
+		   (unsigned long long)new_addr);
+
+	fs = fuse2fs_start(ff);
+	if (error) {
+		ret = error;
+		goto out_unlock;
+	}
+
+	/* should never see these ioend types */
+	if (ioendflags & FUSE_IOMAP_IOEND_SHARED) {
+		ret = translate_error(fs, attr_ino,
+				      EXT2_ET_FILESYSTEM_CORRUPTED);
+		goto out_unlock;
+	}
+
+	err = fuse2fs_read_inode(fs, attr_ino, &inode);
+	if (err) {
+		ret = translate_error(fs, attr_ino, err);
+		goto out_unlock;
+	}
+
+	if (ioendflags & FUSE_IOMAP_IOEND_UNWRITTEN) {
+		/* unwritten extents are only supported on extents files */
+		if (!(inode.i_flags & EXT4_EXTENTS_FL)) {
+			ret = translate_error(fs, attr_ino,
+					      EXT2_ET_FILESYSTEM_CORRUPTED);
+			goto out_unlock;
+		}
+
+		ret = fuse2fs_convert_unwritten_mappings(ff, attr_ino, &inode,
+							 pos, written);
+		if (ret)
+			goto out_unlock;
+
+		dirty = true;
+	}
+
+	isize = EXT2_I_SIZE(&inode);
+	if (pos + written > isize) {
+		err = ext2fs_inode_size_set(fs, EXT2_INODE(&inode),
+					    pos + written);
+		if (err) {
+			ret = translate_error(fs, attr_ino, err);
+			goto out_unlock;
+		}
+
+		dirty = true;
+	}
+
+	if (dirty) {
+		err = fuse2fs_write_inode(fs, attr_ino, &inode);
+		if (err) {
+			ret = translate_error(fs, attr_ino, err);
+			goto out_unlock;
+		}
+	}
+
+	*newsize = EXT2_I_SIZE(&inode);
+out_unlock:
+	fuse2fs_finish(ff, ret);
+	return ret;
+}
 #endif /* HAVE_FUSE_IOMAP */
 
 static struct fuse_operations fs_ops = {
@@ -5935,6 +6399,7 @@ static struct fuse_operations fs_ops = {
 	.iomap_begin = op_iomap_begin,
 	.iomap_end = op_iomap_end,
 	.iomap_config = op_iomap_config,
+	.iomap_ioend = op_iomap_ioend,
 #endif /* HAVE_FUSE_IOMAP */
 };
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 08/19] fuse2fs: turn on iomap for pagecache IO
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (6 preceding siblings ...)
  2026-02-23 23:37   ` [PATCH 07/19] fuse2fs: implement direct write support Darrick J. Wong
@ 2026-02-23 23:38   ` Darrick J. Wong
  2026-02-23 23:38   ` [PATCH 09/19] fuse2fs: don't zero bytes in punch hole Darrick J. Wong
                     ` (10 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:38 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Turn on iomap for pagecache IO to regular files.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++------
 misc/fuse2fs.c    |   61 +++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 108 insertions(+), 14 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 2f95a1ecbfa330..39737c72e6133f 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -6219,9 +6219,6 @@ static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino,
 				    uint64_t count, uint32_t opflags,
 				    struct fuse_file_iomap *read)
 {
-	if (!(opflags & FUSE_IOMAP_OP_DIRECT))
-		return -ENOSYS;
-
 	/* fall back to slow path for inline data reads */
 	if (inode->i_flags & EXT4_INLINE_DATA_FL)
 		return -ENOSYS;
@@ -6312,9 +6309,6 @@ static int fuse4fs_iomap_begin_write(struct fuse4fs *ff, ext2_ino_t ino,
 	off_t max_size = fuse4fs_max_file_size(ff, inode);
 	int ret;
 
-	if (!(opflags & FUSE_IOMAP_OP_DIRECT))
-		return -ENOSYS;
-
 	if (pos >= max_size)
 		return -EFBIG;
 
@@ -6410,12 +6404,51 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 		fuse_reply_iomap_begin(req, &read, NULL);
 }
 
+static int fuse4fs_iomap_append_setsize(struct fuse4fs *ff, ext2_ino_t ino,
+					loff_t newsize)
+{
+	ext2_filsys fs = ff->fs;
+	struct ext2_inode_large inode;
+	ext2_off64_t isize;
+	errcode_t err;
+
+	dbg_printf(ff, "%s: ino=%u newsize=%llu\n", __func__, ino,
+		   (unsigned long long)newsize);
+
+	err = fuse4fs_read_inode(fs, ino, &inode);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	isize = EXT2_I_SIZE(&inode);
+	if (newsize <= isize)
+		return 0;
+
+	dbg_printf(ff, "%s: ino=%u oldsize=%llu newsize=%llu\n", __func__, ino,
+		   (unsigned long long)isize,
+		   (unsigned long long)newsize);
+
+	/*
+	 * XXX cheesily update the ondisk size even though we only want to do
+	 * the incore size until writeback happens
+	 */
+	err = ext2fs_inode_size_set(fs, EXT2_INODE(&inode), newsize);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	err = fuse4fs_write_inode(fs, ino, &inode);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	return 0;
+}
+
 static void op_iomap_end(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 			 off_t pos, uint64_t count, uint32_t opflags,
 			 ssize_t written, const struct fuse_file_iomap *iomap)
 {
 	struct fuse4fs *ff = fuse4fs_get(req);
 	ext2_ino_t ino;
+	int ret = 0;
 
 	FUSE4FS_CHECK_CONTEXT(req);
 	FUSE4FS_CONVERT_FINO(req, &ino, fino);
@@ -6429,7 +6462,21 @@ static void op_iomap_end(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 		   written,
 		   iomap->flags);
 
-	fuse_reply_err(req, 0);
+	fuse4fs_start(ff);
+
+	/* XXX is this really necessary? */
+	if ((opflags & FUSE_IOMAP_OP_WRITE) &&
+	    !(opflags & FUSE_IOMAP_OP_DIRECT) &&
+	    (iomap->flags & FUSE_IOMAP_F_SIZE_CHANGED) &&
+	    written > 0) {
+		ret = fuse4fs_iomap_append_setsize(ff, ino, pos + written);
+		if (ret)
+			goto out_unlock;
+	}
+
+out_unlock:
+	fuse4fs_finish(ff, ret);
+	fuse_reply_err(req, -ret);
 }
 
 /*
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 4b64a37aa0e029..afb50a7e498694 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -5665,9 +5665,6 @@ static int fuse2fs_iomap_begin_read(struct fuse2fs *ff, ext2_ino_t ino,
 				    uint64_t count, uint32_t opflags,
 				    struct fuse_file_iomap *read)
 {
-	if (!(opflags & FUSE_IOMAP_OP_DIRECT))
-		return -ENOSYS;
-
 	/* fall back to slow path for inline data reads */
 	if (inode->i_flags & EXT4_INLINE_DATA_FL)
 		return -ENOSYS;
@@ -5755,9 +5752,6 @@ static int fuse2fs_iomap_begin_write(struct fuse2fs *ff, ext2_ino_t ino,
 	off_t max_size = fuse2fs_max_file_size(ff, inode);
 	int ret;
 
-	if (!(opflags & FUSE_IOMAP_OP_DIRECT))
-		return -ENOSYS;
-
 	if (pos >= max_size)
 		return -EFBIG;
 
@@ -5852,11 +5846,50 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
 	return ret;
 }
 
+static int fuse2fs_iomap_append_setsize(struct fuse2fs *ff, ext2_ino_t ino,
+					loff_t newsize)
+{
+	ext2_filsys fs = ff->fs;
+	struct ext2_inode_large inode;
+	ext2_off64_t isize;
+	errcode_t err;
+
+	dbg_printf(ff, "%s: ino=%u newsize=%llu\n", __func__, ino,
+		   (unsigned long long)newsize);
+
+	err = fuse2fs_read_inode(fs, ino, &inode);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	isize = EXT2_I_SIZE(&inode);
+	if (newsize <= isize)
+		return 0;
+
+	dbg_printf(ff, "%s: ino=%u oldsize=%llu newsize=%llu\n", __func__, ino,
+		   (unsigned long long)isize,
+		   (unsigned long long)newsize);
+
+	/*
+	 * XXX cheesily update the ondisk size even though we only want to do
+	 * the incore size until writeback happens
+	 */
+	err = ext2fs_inode_size_set(fs, EXT2_INODE(&inode), newsize);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	err = fuse2fs_write_inode(fs, ino, &inode);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	return 0;
+}
+
 static int op_iomap_end(const char *path, uint64_t nodeid, uint64_t attr_ino,
 			off_t pos, uint64_t count, uint32_t opflags,
 			ssize_t written, const struct fuse_file_iomap *iomap)
 {
 	struct fuse2fs *ff = fuse2fs_get();
+	int ret = 0;
 
 	FUSE2FS_CHECK_CONTEXT(ff);
 
@@ -5871,7 +5904,21 @@ static int op_iomap_end(const char *path, uint64_t nodeid, uint64_t attr_ino,
 		   written,
 		   iomap->flags);
 
-	return 0;
+	fuse2fs_start(ff);
+
+	/* XXX is this really necessary? */
+	if ((opflags & FUSE_IOMAP_OP_WRITE) &&
+	    !(opflags & FUSE_IOMAP_OP_DIRECT) &&
+	    (iomap->flags & FUSE_IOMAP_F_SIZE_CHANGED) &&
+	    written > 0) {
+		ret = fuse2fs_iomap_append_setsize(ff, attr_ino, pos + written);
+		if (ret)
+			goto out_unlock;
+	}
+
+out_unlock:
+	fuse2fs_finish(ff, ret);
+	return ret;
 }
 
 /*


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 09/19] fuse2fs: don't zero bytes in punch hole
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (7 preceding siblings ...)
  2026-02-23 23:38   ` [PATCH 08/19] fuse2fs: turn on iomap for pagecache IO Darrick J. Wong
@ 2026-02-23 23:38   ` Darrick J. Wong
  2026-02-23 23:38   ` [PATCH 10/19] fuse2fs: don't do file data block IO when iomap is enabled Darrick J. Wong
                     ` (9 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:38 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

When iomap is in use for the pagecache, it will take care of zeroing the
unaligned parts of punched out regions so we don't have to do it
ourselves.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |    8 ++++++++
 misc/fuse2fs.c    |    9 +++++++++
 2 files changed, 17 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 39737c72e6133f..b28e92ed5f2e65 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -5649,6 +5649,10 @@ static errcode_t fuse4fs_zero_middle(struct fuse4fs *ff, ext2_ino_t ino,
 	int retflags;
 	errcode_t err;
 
+	/* the kernel does this for us in iomap mode */
+	if (fuse4fs_iomap_enabled(ff))
+		return 0;
+
 	if (!*buf) {
 		err = ext2fs_get_mem(fs->blocksize, buf);
 		if (err)
@@ -5685,6 +5689,10 @@ static errcode_t fuse4fs_zero_edge(struct fuse4fs *ff, ext2_ino_t ino,
 	off_t residue;
 	errcode_t err;
 
+	/* the kernel does this for us in iomap mode */
+	if (fuse4fs_iomap_enabled(ff))
+		return 0;
+
 	residue = FUSE4FS_OFF_IN_FSB(ff, offset);
 	if (residue == 0)
 		return 0;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index afb50a7e498694..be7004bb95cb8f 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -726,6 +726,7 @@ static inline int fuse2fs_iomap_enabled(const struct fuse2fs *ff)
 }
 #else
 # define fuse2fs_iomap_enabled(...)	(0)
+# define fuse2fs_iomap_enabled(...)	(0)
 #endif
 
 static inline void fuse2fs_dump_extents(struct fuse2fs *ff, ext2_ino_t ino,
@@ -5096,6 +5097,10 @@ static errcode_t clean_block_middle(struct fuse2fs *ff, ext2_ino_t ino,
 	int retflags;
 	errcode_t err;
 
+	/* the kernel does this for us in iomap mode */
+	if (fuse2fs_iomap_enabled(ff))
+		return 0;
+
 	if (!*buf) {
 		err = ext2fs_get_mem(fs->blocksize, buf);
 		if (err)
@@ -5132,6 +5137,10 @@ static errcode_t clean_block_edge(struct fuse2fs *ff, ext2_ino_t ino,
 	off_t residue;
 	errcode_t err;
 
+	/* the kernel does this for us in iomap mode */
+	if (fuse2fs_iomap_enabled(ff))
+		return 0;
+
 	residue = FUSE2FS_OFF_IN_FSB(ff, offset);
 	if (residue == 0)
 		return 0;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 10/19] fuse2fs: don't do file data block IO when iomap is enabled
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (8 preceding siblings ...)
  2026-02-23 23:38   ` [PATCH 09/19] fuse2fs: don't zero bytes in punch hole Darrick J. Wong
@ 2026-02-23 23:38   ` Darrick J. Wong
  2026-02-23 23:38   ` [PATCH 11/19] fuse2fs: try to create loop device when ext4 device is a regular file Darrick J. Wong
                     ` (8 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:38 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

When iomap is in use for the page cache, the kernel will take care of
all the file data block IO for us, including zeroing of punched ranges
and post-EOF bytes.  fuse2fs only needs to do IO for inline data.

Therefore, set the NOBLOCKIO ext2_file flag so that libext2fs will not
do any regular file IO to or from disk blocks at all.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   11 +++++++-
 misc/fuse2fs.c    |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 2 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index b28e92ed5f2e65..b95ff73b7d9d8e 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -3714,9 +3714,14 @@ static int fuse4fs_truncate(struct fuse4fs *ff, ext2_ino_t ino, off_t new_size)
 	ext2_file_t file;
 	__u64 old_isize;
 	errcode_t err;
+	int flags = EXT2_FILE_WRITE;
 	int ret = 0;
 
-	err = ext2fs_file_open(fs, ino, EXT2_FILE_WRITE, &file);
+	/* the kernel handles all eof zeroing for us in iomap mode */
+	if (fuse4fs_iomap_enabled(ff))
+		flags |= EXT2_FILE_NOBLOCKIO;
+
+	err = ext2fs_file_open(fs, ino, flags, &file);
 	if (err)
 		return translate_error(fs, ino, err);
 
@@ -3811,6 +3816,10 @@ static int fuse4fs_open_file(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 	if (linked)
 		check |= L_OK;
 
+	/* the kernel handles all block IO for us in iomap mode */
+	if (fuse4fs_iomap_enabled(ff))
+		file->open_flags |= EXT2_FILE_NOBLOCKIO;
+
 	/*
 	 * If the caller wants to truncate the file, we need to ask for full
 	 * write access even if the caller claims to be appending.
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index be7004bb95cb8f..5731da1cbae7e5 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -3455,15 +3455,72 @@ static int fuse2fs_punch_posteof(struct fuse2fs *ff, ext2_ino_t ino,
 	return 0;
 }
 
+/*
+ * Decide if file IO for this inode can use iomap.
+ *
+ * It turns out that libfuse creates internal node ids that have nothing to do
+ * with the ext2_ino_t that we give it.  These internal node ids are what
+ * actually gets igetted in the kernel, which means that there can be multiple
+ * fuse_inode objects in the kernel for a single hardlinked ondisk ext2 inode.
+ *
+ * What this means, horrifyingly, is that on a fuse filesystem that supports
+ * hard links, the in-kernel i_rwsem does not protect against concurrent writes
+ * between files that point to the same inode.  That in turn means that the
+ * file mode and size can get desynchronized between the multiple fuse_inode
+ * objects.  This also means that we cannot cache iomaps in the kernel AT ALL
+ * because the caches will get out of sync, leading to WARN_ONs from the iomap
+ * zeroing code and probably data corruption after that.
+ *
+ * Therefore, libfuse won't let us create hardlinks of iomap files, and we must
+ * never turn on iomap for existing hardlinked files.  Long term it means we
+ * have to find a way around this loss of functionality.  fuse4fs gets around
+ * this by being a low level fuse driver and controlling the nodeids itself.
+ *
+ * Returns 0 for no, 1 for yes, or a negative errno.
+ */
+#ifdef HAVE_FUSE_IOMAP
+static int fuse2fs_file_uses_iomap(struct fuse2fs *ff, ext2_ino_t ino)
+{
+	struct stat statbuf;
+	int ret;
+
+	if (!fuse2fs_iomap_enabled(ff))
+		return 0;
+
+	ret = stat_inode(ff->fs, ino, &statbuf);
+	if (ret)
+		return ret;
+
+	/* the kernel handles all block IO for us in iomap mode */
+	return fuse_fs_can_enable_iomap(&statbuf);
+}
+#else
+# define fuse2fs_file_uses_iomap(...)	(0)
+#endif
+
 static int fuse2fs_truncate(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size)
 {
 	ext2_filsys fs = ff->fs;
 	ext2_file_t file;
 	__u64 old_isize;
 	errcode_t err;
+	int flags = EXT2_FILE_WRITE;
 	int ret = 0;
 
-	err = ext2fs_file_open(fs, ino, EXT2_FILE_WRITE, &file);
+	/* the kernel handles all eof zeroing for us in iomap mode */
+	ret = fuse2fs_file_uses_iomap(ff, ino);
+	switch (ret) {
+	case 0:
+		break;
+	case 1:
+		flags |= EXT2_FILE_NOBLOCKIO;
+		ret = 0;
+		break;
+	default:
+		return ret;
+	}
+
+	err = ext2fs_file_open(fs, ino, flags, &file);
 	if (err)
 		return translate_error(fs, ino, err);
 
@@ -3618,6 +3675,19 @@ static int __op_open(struct fuse2fs *ff, const char *path,
 			goto out;
 	}
 
+	/* the kernel handles all block IO for us in iomap mode */
+	ret = fuse2fs_file_uses_iomap(ff, file->ino);
+	switch (ret) {
+	case 0:
+		break;
+	case 1:
+		file->open_flags |= EXT2_FILE_NOBLOCKIO;
+		ret = 0;
+		break;
+	default:
+		goto out;
+	}
+
 	if (fp->flags & O_TRUNC) {
 		ret = fuse2fs_truncate(ff, file->ino, 0);
 		if (ret)


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 11/19] fuse2fs: try to create loop device when ext4 device is a regular file
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (9 preceding siblings ...)
  2026-02-23 23:38   ` [PATCH 10/19] fuse2fs: don't do file data block IO when iomap is enabled Darrick J. Wong
@ 2026-02-23 23:38   ` Darrick J. Wong
  2026-02-23 23:39   ` [PATCH 12/19] fuse2fs: enable file IO to inline data files Darrick J. Wong
                     ` (7 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:38 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

If the filesystem device is a regular file, try to create a loop device
for it so that we can take advantage of iomap.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 configure         |   41 +++++++++++++++++++
 configure.ac      |   23 +++++++++++
 fuse4fs/fuse4fs.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/config.h.in   |    3 +
 misc/fuse2fs.c    |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 287 insertions(+), 3 deletions(-)


diff --git a/configure b/configure
index 03b17d07771117..5db59894242aab 100755
--- a/configure
+++ b/configure
@@ -14661,6 +14661,47 @@ printf "%s\n" "#define HAVE_FUSE_IOMAP 1" >>confdefs.h
 
 fi
 
+if test -n "$have_fuse_iomap"; then
+	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fuse_loopdev.h in libfuse" >&5
+printf %s "checking for fuse_loopdev.h in libfuse... " >&6; }
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+	#define _GNU_SOURCE
+	#define _FILE_OFFSET_BITS	64
+	#define FUSE_USE_VERSION	399
+	#include <fuse_loopdev.h>
+
+int
+main (void)
+{
+
+
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"
+then :
+  have_fuse_loopdev=yes
+	   { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
+else case e in #(
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; } ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+if test -n "$have_fuse_loopdev"
+then
+
+printf "%s\n" "#define HAVE_FUSE_LOOPDEV 1" >>confdefs.h
+
+fi
+
 have_fuse_lowlevel=
 if test -n "$FUSE_USE_VERSION"
 then
diff --git a/configure.ac b/configure.ac
index 6ccb1fdc444adc..f1bffa88b80fa4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1429,6 +1429,29 @@ then
 	AC_DEFINE(HAVE_FUSE_IOMAP, 1, [Define to 1 if fuse supports iomap])
 fi
 
+dnl
+dnl Check if fuse library has fuse_loopdev.h, which it only gained after adding
+dnl iomap support.
+dnl
+if test -n "$have_fuse_iomap"; then
+	AC_MSG_CHECKING(for fuse_loopdev.h in libfuse)
+	AC_LINK_IFELSE(
+	[	AC_LANG_PROGRAM([[
+	#define _GNU_SOURCE
+	#define _FILE_OFFSET_BITS	64
+	#define FUSE_USE_VERSION	399
+	#include <fuse_loopdev.h>
+		]], [[
+		]])
+	], have_fuse_loopdev=yes
+	   AC_MSG_RESULT(yes),
+	   AC_MSG_RESULT(no))
+fi
+if test -n "$have_fuse_loopdev"
+then
+	AC_DEFINE(HAVE_FUSE_LOOPDEV, 1, [Define to 1 if fuse supports loopdev operations])
+fi
+
 dnl
 dnl Check if the FUSE lowlevel library is supported
 dnl
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index b95ff73b7d9d8e..58a67252b7b613 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -27,6 +27,9 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <assert.h>
+#ifdef HAVE_FUSE_LOOPDEV
+# include <fuse_loopdev.h>
+#endif
 #define FUSE_DARWIN_ENABLE_EXTENSIONS 0
 #ifdef __SET_FOB_FOR_FUSE
 # error Do not set magic value __SET_FOB_FOR_FUSE!!!!
@@ -250,6 +253,10 @@ struct fuse4fs {
 	pthread_mutex_t bfl;
 	char *device;
 	char *shortdev;
+#ifdef HAVE_FUSE_LOOPDEV
+	char *loop_device;
+	int loop_fd;
+#endif
 
 	/* options set by fuse_opt_parse must be of type int */
 	int ro;
@@ -273,6 +280,7 @@ struct fuse4fs {
 	enum fuse4fs_feature_toggle iomap_want;
 	enum fuse4fs_iomap_state iomap_state;
 	uint32_t iomap_dev;
+	uint64_t iomap_cap;
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -885,8 +893,23 @@ static inline int fuse4fs_iomap_enabled(const struct fuse4fs *ff)
 {
 	return ff->iomap_state >= IOMAP_ENABLED;
 }
+
+static inline void fuse4fs_discover_iomap(struct fuse4fs *ff)
+{
+	if (ff->iomap_want == FT_DISABLE)
+		return;
+
+	ff->iomap_cap = fuse_lowlevel_discover_iomap(-1);
+}
+
+static inline bool fuse4fs_can_iomap(const struct fuse4fs *ff)
+{
+	return ff->iomap_cap & FUSE_IOMAP_SUPPORT_FILEIO;
+}
 #else
 # define fuse4fs_iomap_enabled(...)	(0)
+# define fuse4fs_discover_iomap(...)	((void)0)
+# define fuse4fs_can_iomap(...)		(false)
 #endif
 
 static inline void fuse4fs_dump_extents(struct fuse4fs *ff, ext2_ino_t ino,
@@ -1381,6 +1404,72 @@ static void fuse4fs_release_lockfile(struct fuse4fs *ff)
 	free(ff->lockfile);
 }
 
+#ifdef HAVE_FUSE_LOOPDEV
+static int fuse4fs_try_losetup(struct fuse4fs *ff, int flags)
+{
+	bool rw = flags & EXT2_FLAG_RW;
+	int dev_fd;
+	int ret;
+
+	/* Only transform a regular file into a loopdev for iomap */
+	if (!fuse4fs_can_iomap(ff))
+		return 0;
+
+	/* open the actual target device, see if it's a regular file */
+	dev_fd = open(ff->device, rw ? O_RDWR : O_RDONLY);
+	if (dev_fd < 0) {
+		err_printf(ff, "%s: %s\n", _("while opening fs"),
+			   error_message(errno));
+		return -1;
+	}
+
+	ret = fuse_loopdev_setup(dev_fd, rw ? O_RDWR : O_RDONLY, ff->device, 5,
+			   &ff->loop_fd, &ff->loop_device);
+	if (ret && errno == EBUSY) {
+		/*
+		 * If the setup function returned EBUSY, there is already a
+		 * loop device backed by this file.  Report that the file is
+		 * already in use.
+		 */
+		err_printf(ff, "%s: %s\n", _("while opening fs loopdev"),
+				   error_message(errno));
+		close(dev_fd);
+		return -1;
+	}
+
+	close(dev_fd);
+	return 0;
+}
+
+static void fuse4fs_detach_losetup(struct fuse4fs *ff)
+{
+	if (ff->loop_fd >= 0)
+		close(ff->loop_fd);
+	ff->loop_fd = -1;
+}
+
+static void fuse4fs_undo_losetup(struct fuse4fs *ff)
+{
+	fuse4fs_detach_losetup(ff);
+	free(ff->loop_device);
+	ff->loop_device = NULL;
+}
+
+static inline const char *fuse4fs_device(const struct fuse4fs *ff)
+{
+	/*
+	 * If we created a loop device for the file passed in, open that.
+	 * Otherwise open the path the user gave us.
+	 */
+	return ff->loop_device ? ff->loop_device : ff->device;
+}
+#else
+# define fuse4fs_try_losetup(...)	(0)
+# define fuse4fs_detach_losetup(...)	((void)0)
+# define fuse4fs_undo_losetup(...)	((void)0)
+# define fuse4fs_device(ff)		((ff)->device)
+#endif
+
 static void fuse4fs_unmount(struct fuse4fs *ff)
 {
 	char uuid[UUID_STR_SIZE];
@@ -1403,6 +1492,8 @@ static void fuse4fs_unmount(struct fuse4fs *ff)
 				   uuid);
 	}
 
+	fuse4fs_undo_losetup(ff);
+
 	if (ff->lockfile)
 		fuse4fs_release_lockfile(ff);
 }
@@ -1415,6 +1506,8 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 		    EXT2_FLAG_EXCLUSIVE | EXT2_FLAG_WRITE_FULL_SUPER;
 	errcode_t err;
 
+	fuse4fs_discover_iomap(ff);
+
 	if (ff->lockfile) {
 		err = fuse4fs_acquire_lockfile(ff);
 		if (err)
@@ -1427,6 +1520,12 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 	if (ff->directio)
 		flags |= EXT2_FLAG_DIRECT_IO;
 
+	dbg_printf(ff, "opening with flags=0x%x\n", flags);
+
+	err = fuse4fs_try_losetup(ff, flags);
+	if (err)
+		return err;
+
 	/*
 	 * If the filesystem is stored on a block device, the _EXCLUSIVE flag
 	 * causes libext2fs to try to open the block device with O_EXCL.  If
@@ -1458,7 +1557,7 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 	 */
 	deadline = init_deadline(FUSE4FS_OPEN_TIMEOUT);
 	do {
-		err = ext2fs_open2(ff->device, options, flags, 0, 0,
+		err = ext2fs_open2(fuse4fs_device(ff), options, flags, 0, 0,
 				   unix_io_manager, &ff->fs);
 		if ((err == EPERM || err == EACCES) &&
 		    (!ff->ro || (flags & EXT2_FLAG_RW))) {
@@ -1473,6 +1572,11 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 			flags &= ~EXT2_FLAG_RW;
 			ff->ro = 1;
 
+			fuse4fs_undo_losetup(ff);
+			err = fuse4fs_try_losetup(ff, flags);
+			if (err)
+				return err;
+
 			/* Force the loop to run once more */
 			err = -1;
 		}
@@ -1910,6 +2014,8 @@ static void op_init(void *userdata, struct fuse_conn_info *conn)
 	fuse4fs_iomap_enable(conn, ff);
 	conn->time_gran = 1;
 
+	fuse4fs_detach_losetup(ff);
+
 	if (ff->opstate == F4OP_WRITABLE)
 		fuse4fs_read_bitmaps(ff);
 
@@ -7439,6 +7545,9 @@ int main(int argc, char *argv[])
 		.iomap_want = FT_DEFAULT,
 		.iomap_state = IOMAP_UNKNOWN,
 		.iomap_dev = FUSE_IOMAP_DEV_NULL,
+#endif
+#ifdef HAVE_FUSE_LOOPDEV
+		.loop_fd = -1,
 #endif
 	};
 	errcode_t err;
diff --git a/lib/config.h.in b/lib/config.h.in
index 41598dcc1d7c5a..7e045b65131522 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -82,6 +82,9 @@
 /* Define to 1 if fuse supports iomap */
 #undef HAVE_FUSE_IOMAP
 
+/* Define to 1 if fuse supports loopdev operations */
+#undef HAVE_FUSE_LOOPDEV
+
 /* Define to 1 if you have the Mac OS X function
    CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */
 #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 5731da1cbae7e5..8079ace3d30e3f 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -25,6 +25,9 @@
 #include <sys/ioctl.h>
 #include <unistd.h>
 #include <ctype.h>
+#ifdef HAVE_FUSE_LOOPDEV
+# include <fuse_loopdev.h>
+#endif
 #define FUSE_DARWIN_ENABLE_EXTENSIONS 0
 #ifdef __SET_FOB_FOR_FUSE
 # error Do not set magic value __SET_FOB_FOR_FUSE!!!!
@@ -244,6 +247,10 @@ struct fuse2fs {
 	pthread_mutex_t bfl;
 	char *device;
 	char *shortdev;
+#ifdef HAVE_FUSE_LOOPDEV
+	char *loop_device;
+	int loop_fd;
+#endif
 
 	/* options set by fuse_opt_parse must be of type int */
 	int ro;
@@ -267,6 +274,7 @@ struct fuse2fs {
 	enum fuse2fs_feature_toggle iomap_want;
 	enum fuse2fs_iomap_state iomap_state;
 	uint32_t iomap_dev;
+	uint64_t iomap_cap;
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -724,9 +732,23 @@ static inline int fuse2fs_iomap_enabled(const struct fuse2fs *ff)
 {
 	return ff->iomap_state >= IOMAP_ENABLED;
 }
+
+static inline void fuse2fs_discover_iomap(struct fuse2fs *ff)
+{
+	if (ff->iomap_want == FT_DISABLE)
+		return;
+
+	ff->iomap_cap = fuse_lowlevel_discover_iomap(-1);
+}
+
+static inline bool fuse2fs_can_iomap(const struct fuse2fs *ff)
+{
+	return ff->iomap_cap & FUSE_IOMAP_SUPPORT_FILEIO;
+}
 #else
 # define fuse2fs_iomap_enabled(...)	(0)
-# define fuse2fs_iomap_enabled(...)	(0)
+# define fuse2fs_discover_iomap(...)	((void)0)
+# define fuse2fs_can_iomap(...)		(false)
 #endif
 
 static inline void fuse2fs_dump_extents(struct fuse2fs *ff, ext2_ino_t ino,
@@ -1200,6 +1222,72 @@ static void fuse2fs_release_lockfile(struct fuse2fs *ff)
 	free(ff->lockfile);
 }
 
+#ifdef HAVE_FUSE_LOOPDEV
+static int fuse2fs_try_losetup(struct fuse2fs *ff, int flags)
+{
+	bool rw = flags & EXT2_FLAG_RW;
+	int dev_fd;
+	int ret;
+
+	/* Only transform a regular file into a loopdev for iomap */
+	if (!fuse2fs_can_iomap(ff))
+		return 0;
+
+	/* open the actual target device, see if it's a regular file */
+	dev_fd = open(ff->device, rw ? O_RDWR : O_RDONLY);
+	if (dev_fd < 0) {
+		err_printf(ff, "%s: %s\n", _("while opening fs"),
+			   error_message(errno));
+		return -1;
+	}
+
+	ret = fuse_loopdev_setup(dev_fd, rw ? O_RDWR : O_RDONLY, ff->device, 5,
+			   &ff->loop_fd, &ff->loop_device);
+	if (ret && errno == EBUSY) {
+		/*
+		 * If the setup function returned EBUSY, there is already a
+		 * loop device backed by this file.  Report that the file is
+		 * already in use.
+		 */
+		err_printf(ff, "%s: %s\n", _("while opening fs loopdev"),
+				   error_message(errno));
+		close(dev_fd);
+		return -1;
+	}
+
+	close(dev_fd);
+	return 0;
+}
+
+static void fuse2fs_detach_losetup(struct fuse2fs *ff)
+{
+	if (ff->loop_fd >= 0)
+		close(ff->loop_fd);
+	ff->loop_fd = -1;
+}
+
+static void fuse2fs_undo_losetup(struct fuse2fs *ff)
+{
+	fuse2fs_detach_losetup(ff);
+	free(ff->loop_device);
+	ff->loop_device = NULL;
+}
+
+static inline const char *fuse2fs_device(const struct fuse2fs *ff)
+{
+	/*
+	 * If we created a loop device for the file passed in, open that.
+	 * Otherwise open the path the user gave us.
+	 */
+	return ff->loop_device ? ff->loop_device : ff->device;
+}
+#else
+# define fuse2fs_try_losetup(...)	(0)
+# define fuse2fs_detach_losetup(...)	((void)0)
+# define fuse2fs_undo_losetup(...)	((void)0)
+# define fuse2fs_device(ff)		((ff)->device)
+#endif
+
 static void fuse2fs_unmount(struct fuse2fs *ff)
 {
 	char uuid[UUID_STR_SIZE];
@@ -1217,6 +1305,8 @@ static void fuse2fs_unmount(struct fuse2fs *ff)
 				   uuid);
 	}
 
+	fuse2fs_undo_losetup(ff);
+
 	if (ff->lockfile)
 		fuse2fs_release_lockfile(ff);
 }
@@ -1229,6 +1319,8 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff)
 		    EXT2_FLAG_EXCLUSIVE | EXT2_FLAG_WRITE_FULL_SUPER;
 	errcode_t err;
 
+	fuse2fs_discover_iomap(ff);
+
 	if (ff->lockfile) {
 		err = fuse2fs_acquire_lockfile(ff);
 		if (err)
@@ -1241,6 +1333,12 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff)
 	if (ff->directio)
 		flags |= EXT2_FLAG_DIRECT_IO;
 
+	dbg_printf(ff, "opening with flags=0x%x\n", flags);
+
+	err = fuse2fs_try_losetup(ff, flags);
+	if (err)
+		return err;
+
 	/*
 	 * If the filesystem is stored on a block device, the _EXCLUSIVE flag
 	 * causes libext2fs to try to open the block device with O_EXCL.  If
@@ -1272,7 +1370,7 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff)
 	 */
 	deadline = init_deadline(FUSE2FS_OPEN_TIMEOUT);
 	do {
-		err = ext2fs_open2(ff->device, options, flags, 0, 0,
+		err = ext2fs_open2(fuse2fs_device(ff), options, flags, 0, 0,
 				   unix_io_manager, &ff->fs);
 		if ((err == EPERM || err == EACCES) &&
 		    (!ff->ro || (flags & EXT2_FLAG_RW))) {
@@ -1287,6 +1385,11 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff)
 			flags &= ~EXT2_FLAG_RW;
 			ff->ro = 1;
 
+			fuse2fs_undo_losetup(ff);
+			err = fuse2fs_try_losetup(ff, flags);
+			if (err)
+				return err;
+
 			/* Force the loop to run once more */
 			err = -1;
 		}
@@ -1736,6 +1839,8 @@ static void *op_init(struct fuse_conn_info *conn,
 		cfg->debug = 1;
 	cfg->nullpath_ok = 1;
 
+	fuse2fs_detach_losetup(ff);
+
 	if (ff->opstate == F2OP_WRITABLE)
 		fuse2fs_read_bitmaps(ff);
 
@@ -6844,6 +6949,9 @@ int main(int argc, char *argv[])
 		.iomap_want = FT_DEFAULT,
 		.iomap_state = IOMAP_UNKNOWN,
 		.iomap_dev = FUSE_IOMAP_DEV_NULL,
+#endif
+#ifdef HAVE_FUSE_LOOPDEV
+		.loop_fd = -1,
 #endif
 	};
 	errcode_t err;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 12/19] fuse2fs: enable file IO to inline data files
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (10 preceding siblings ...)
  2026-02-23 23:38   ` [PATCH 11/19] fuse2fs: try to create loop device when ext4 device is a regular file Darrick J. Wong
@ 2026-02-23 23:39   ` Darrick J. Wong
  2026-02-23 23:39   ` [PATCH 13/19] fuse2fs: set iomap-related inode flags Darrick J. Wong
                     ` (6 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:39 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Enable file reads and writes from inline data files.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |    3 ++-
 misc/fuse2fs.c    |   42 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 3 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 58a67252b7b613..59c8d7de7e4533 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -6344,7 +6344,8 @@ static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino,
 {
 	/* fall back to slow path for inline data reads */
 	if (inode->i_flags & EXT4_INLINE_DATA_FL)
-		return -ENOSYS;
+		return fuse4fs_iomap_begin_inline(ff, ino, inode, pos, count,
+						  read);
 
 	if (inode->i_flags & EXT4_EXTENTS_FL)
 		return fuse4fs_iomap_begin_extent(ff, ino, inode, pos, count,
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 8079ace3d30e3f..5651b9633c5bb6 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1837,7 +1837,16 @@ static void *op_init(struct fuse_conn_info *conn,
 	cfg->use_ino = 1;
 	if (ff->debug)
 		cfg->debug = 1;
-	cfg->nullpath_ok = 1;
+
+	/*
+	 * Inline data file io depends on op_read/write being fed a path, so we
+	 * have to slow everyone down to look up the path from the nodeid.
+	 */
+	if (fuse2fs_iomap_enabled(ff) &&
+	    ext2fs_has_feature_inline_data(ff->fs->super))
+		cfg->nullpath_ok = 0;
+	else
+		cfg->nullpath_ok = 1;
 
 	fuse2fs_detach_losetup(ff);
 
@@ -3831,6 +3840,9 @@ static int op_read(const char *path EXT2FS_ATTR((unused)), char *buf,
 		   size_t len, off_t offset,
 		   struct fuse_file_info *fp)
 {
+	struct fuse2fs_file_handle fhurk = {
+		.magic = FUSE2FS_FILE_MAGIC,
+	};
 	struct fuse2fs *ff = fuse2fs_get();
 	struct fuse2fs_file_handle *fh = fuse2fs_get_handle(fp);
 	ext2_filsys fs;
@@ -3840,10 +3852,21 @@ static int op_read(const char *path EXT2FS_ATTR((unused)), char *buf,
 	int ret = 0;
 
 	FUSE2FS_CHECK_CONTEXT(ff);
+
+	if (!fh)
+		fh = &fhurk;
+
 	FUSE2FS_CHECK_HANDLE(ff, fh);
 	dbg_printf(ff, "%s: ino=%d off=0x%llx len=0x%zx\n", __func__, fh->ino,
 		   (unsigned long long)offset, len);
 	fs = fuse2fs_start(ff);
+
+	if (fh == &fhurk) {
+		ret = fuse2fs_file_ino(ff, path, NULL, &fhurk.ino);
+		if (ret)
+			goto out;
+	}
+
 	err = ext2fs_file_open(fs, fh->ino, fh->open_flags, &efp);
 	if (err) {
 		ret = translate_error(fs, fh->ino, err);
@@ -3885,6 +3908,10 @@ static int op_write(const char *path EXT2FS_ATTR((unused)),
 		    const char *buf, size_t len, off_t offset,
 		    struct fuse_file_info *fp)
 {
+	struct fuse2fs_file_handle fhurk = {
+		.magic = FUSE2FS_FILE_MAGIC,
+		.open_flags = EXT2_FILE_WRITE,
+	};
 	struct fuse2fs *ff = fuse2fs_get();
 	struct fuse2fs_file_handle *fh = fuse2fs_get_handle(fp);
 	ext2_filsys fs;
@@ -3894,6 +3921,10 @@ static int op_write(const char *path EXT2FS_ATTR((unused)),
 	int ret = 0;
 
 	FUSE2FS_CHECK_CONTEXT(ff);
+
+	if (!fh)
+		fh = &fhurk;
+
 	FUSE2FS_CHECK_HANDLE(ff, fh);
 	dbg_printf(ff, "%s: ino=%d off=0x%llx len=0x%zx\n", __func__, fh->ino,
 		   (unsigned long long) offset, len);
@@ -3908,6 +3939,12 @@ static int op_write(const char *path EXT2FS_ATTR((unused)),
 		goto out;
 	}
 
+	if (fh == &fhurk) {
+		ret = fuse2fs_file_ino(ff, path, NULL, &fhurk.ino);
+		if (ret)
+			goto out;
+	}
+
 	err = ext2fs_file_open(fs, fh->ino, fh->open_flags, &efp);
 	if (err) {
 		ret = translate_error(fs, fh->ino, err);
@@ -5851,7 +5888,8 @@ static int fuse2fs_iomap_begin_read(struct fuse2fs *ff, ext2_ino_t ino,
 {
 	/* fall back to slow path for inline data reads */
 	if (inode->i_flags & EXT4_INLINE_DATA_FL)
-		return -ENOSYS;
+		return fuse2fs_iomap_begin_inline(ff, ino, inode, pos, count,
+						  read);
 
 	if (inode->i_flags & EXT4_EXTENTS_FL)
 		return fuse2fs_iomap_begin_extent(ff, ino, inode, pos, count,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 13/19] fuse2fs: set iomap-related inode flags
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (11 preceding siblings ...)
  2026-02-23 23:39   ` [PATCH 12/19] fuse2fs: enable file IO to inline data files Darrick J. Wong
@ 2026-02-23 23:39   ` Darrick J. Wong
  2026-02-23 23:39   ` [PATCH 14/19] fuse2fs: configure block device block size Darrick J. Wong
                     ` (5 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:39 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Set FUSE_IFLAG_* when we do a getattr, so that all files will have iomap
enabled.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   46 +++++++++++++++++++++++++++++++++++-----------
 misc/fuse2fs.c    |   20 ++++++++++++++++++++
 2 files changed, 55 insertions(+), 11 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 59c8d7de7e4533..395f2fcd067633 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -2043,6 +2043,7 @@ static void op_init(void *userdata, struct fuse_conn_info *conn)
 
 struct fuse4fs_stat {
 	struct fuse_entry_param	entry;
+	unsigned int iflags;
 };
 
 static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino,
@@ -2108,9 +2109,29 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino,
 	entry->attr_timeout = FUSE4FS_ATTR_TIMEOUT;
 	entry->entry_timeout = FUSE4FS_ATTR_TIMEOUT;
 
+	fstat->iflags = 0;
+#ifdef HAVE_FUSE_IOMAP
+	if (fuse4fs_iomap_enabled(ff))
+		fstat->iflags |= FUSE_IFLAG_IOMAP | FUSE_IFLAG_EXCLUSIVE;
+#endif
+
 	return 0;
 }
 
+#if FUSE_VERSION < FUSE_MAKE_VERSION(3, 99)
+#define fuse_reply_entry_iflags(req, entry, iflags) \
+	fuse_reply_entry((req), (entry))
+
+#define fuse_reply_attr_iflags(req, entry, iflags, timeout) \
+	fuse_reply_attr((req), (entry), (timeout))
+
+#define fuse_add_direntry_plus_iflags(req, buf, sz, name, iflags, entry, dirpos) \
+	fuse_add_direntry_plus((req), (buf), (sz), (name), (entry), (dirpos))
+
+#define fuse_reply_create_iflags(req, entry, iflags, fp) \
+	fuse_reply_create((req), (entry), (fp))
+#endif
+
 static void op_lookup(fuse_req_t req, fuse_ino_t fino, const char *name)
 {
 	struct fuse4fs_stat fstat;
@@ -2141,7 +2162,7 @@ static void op_lookup(fuse_req_t req, fuse_ino_t fino, const char *name)
 	if (ret)
 		fuse_reply_err(req, -ret);
 	else
-		fuse_reply_entry(req, &fstat.entry);
+		fuse_reply_entry_iflags(req, &fstat.entry, fstat.iflags);
 }
 
 static void op_getattr(fuse_req_t req, fuse_ino_t fino,
@@ -2161,8 +2182,8 @@ static void op_getattr(fuse_req_t req, fuse_ino_t fino,
 	if (ret)
 		fuse_reply_err(req, -ret);
 	else
-		fuse_reply_attr(req, &fstat.entry.attr,
-				fstat.entry.attr_timeout);
+		fuse_reply_attr_iflags(req, &fstat.entry.attr, fstat.iflags,
+				       fstat.entry.attr_timeout);
 }
 
 static void op_readlink(fuse_req_t req, fuse_ino_t fino)
@@ -2440,7 +2461,7 @@ static void fuse4fs_reply_entry(fuse_req_t req, ext2_ino_t ino,
 		return;
 	}
 
-	fuse_reply_entry(req, &fstat.entry);
+	fuse_reply_entry_iflags(req, &fstat.entry, fstat.iflags);
 }
 
 static void op_mknod(fuse_req_t req, fuse_ino_t fino, const char *name,
@@ -4768,10 +4789,13 @@ static int op_readdir_iter(ext2_ino_t dir EXT2FS_ATTR((unused)),
 	namebuf[dirent->name_len & 0xFF] = 0;
 
 	if (i->readdirplus) {
-		entrysize = fuse_add_direntry_plus(i->req, i->buf + i->bufused,
-						   i->bufsz - i->bufused,
-						   namebuf, &fstat.entry,
-						   i->dirpos);
+		entrysize = fuse_add_direntry_plus_iflags(i->req,
+							  i->buf + i->bufused,
+							  i->bufsz - i->bufused,
+							  namebuf,
+							  fstat.iflags,
+							  &fstat.entry,
+							  i->dirpos);
 	} else {
 		entrysize = fuse_add_direntry(i->req, i->buf + i->bufused,
 					      i->bufsz - i->bufused, namebuf,
@@ -4996,7 +5020,7 @@ static void op_create(fuse_req_t req, fuse_ino_t fino, const char *name,
 	if (ret)
 		fuse_reply_err(req, -ret);
 	else
-		fuse_reply_create(req, &fstat.entry, fp);
+		fuse_reply_create_iflags(req, &fstat.entry, fstat.iflags, fp);
 }
 
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 17)
@@ -5195,8 +5219,8 @@ static void op_setattr(fuse_req_t req, fuse_ino_t fino, struct stat *attr,
 	if (ret)
 		fuse_reply_err(req, -ret);
 	else
-		fuse_reply_attr(req, &fstat.entry.attr,
-				fstat.entry.attr_timeout);
+		fuse_reply_attr_iflags(req, &fstat.entry.attr, fstat.iflags,
+				       fstat.entry.attr_timeout);
 }
 
 #define FUSE4FS_MODIFIABLE_IFLAGS \
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 5651b9633c5bb6..ed1b3068f22931 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1978,6 +1978,23 @@ static int op_getattr(const char *path, struct stat *statbuf,
 	return ret;
 }
 
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 99)
+static int op_getattr_iflags(const char *path, struct stat *statbuf,
+			     unsigned int *iflags, struct fuse_file_info *fi)
+{
+	int ret = op_getattr(path, statbuf, fi);
+
+	if (ret)
+		return ret;
+
+	if (fuse_fs_can_enable_iomap(statbuf))
+		*iflags |= FUSE_IFLAG_IOMAP | FUSE_IFLAG_EXCLUSIVE;
+
+	return 0;
+}
+#endif
+
+
 static int op_readlink(const char *path, char *buf, size_t len)
 {
 	struct fuse2fs *ff = fuse2fs_get();
@@ -6664,6 +6681,9 @@ static struct fuse_operations fs_ops = {
 #ifdef SUPPORT_FALLOCATE
 	.fallocate = op_fallocate,
 #endif
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 99)
+	.getattr_iflags = op_getattr_iflags,
+#endif
 #ifdef HAVE_FUSE_IOMAP
 	.iomap_begin = op_iomap_begin,
 	.iomap_end = op_iomap_end,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 14/19] fuse2fs: configure block device block size
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (12 preceding siblings ...)
  2026-02-23 23:39   ` [PATCH 13/19] fuse2fs: set iomap-related inode flags Darrick J. Wong
@ 2026-02-23 23:39   ` Darrick J. Wong
  2026-02-23 23:39   ` [PATCH 15/19] fuse4fs: separate invalidation Darrick J. Wong
                     ` (4 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:39 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Set the blocksize of the block device to the filesystem blocksize.
This prevents the bdev pagecache from caching file data blocks that
iomap will read and write directly.  Cache duplication is dangerous.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 misc/fuse2fs.c    |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 395f2fcd067633..9dd694be943255 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -6669,6 +6669,45 @@ static off_t fuse4fs_max_size(struct fuse4fs *ff, off_t upper_limit)
 	return res;
 }
 
+/*
+ * Set the block device's blocksize to the fs blocksize.
+ *
+ * This is required to avoid creating uptodate bdev pagecache that aliases file
+ * data blocks because iomap reads and writes directly to file data blocks.
+ */
+static int fuse4fs_set_bdev_blocksize(struct fuse4fs *ff, int fd)
+{
+	int blocksize = ff->fs->blocksize;
+	int set_error;
+	int ret;
+
+	ret = ioctl(fd, BLKBSZSET, &blocksize);
+	if (!ret)
+		return 0;
+
+	/*
+	 * Save the original errno so we can report that if the block device
+	 * blocksize isn't set in an agreeable way.
+	 */
+	set_error = errno;
+
+	ret = ioctl(fd, BLKBSZGET, &blocksize);
+	if (ret)
+		goto out_bad;
+
+	/* Pretend that BLKBSZSET rejected our proposed block size */
+	if (blocksize > ff->fs->blocksize) {
+		set_error = EINVAL;
+		goto out_bad;
+	}
+
+	return 0;
+out_bad:
+	err_printf(ff, "%s: cannot set blocksize %u: %s\n", __func__,
+		   blocksize, strerror(set_error));
+	return -EIO;
+}
+
 static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
 {
 	errcode_t err;
@@ -6679,6 +6718,10 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
 	if (err)
 		return translate_error(ff->fs, 0, err);
 
+	ret = fuse4fs_set_bdev_blocksize(ff, fd);
+	if (ret)
+		return ret;
+
 	ret = fuse_lowlevel_iomap_device_add(ff->fuse, fd, 0);
 	if (ret < 0) {
 		dbg_printf(ff, "%s: cannot register iomap dev fd=%d, err=%d\n",
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index ed1b3068f22931..b270c51e82cd4a 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -6202,6 +6202,45 @@ static off_t fuse2fs_max_size(struct fuse2fs *ff, off_t upper_limit)
 	return res;
 }
 
+/*
+ * Set the block device's blocksize to the fs blocksize.
+ *
+ * This is required to avoid creating uptodate bdev pagecache that aliases file
+ * data blocks because iomap reads and writes directly to file data blocks.
+ */
+static int fuse2fs_set_bdev_blocksize(struct fuse2fs *ff, int fd)
+{
+	int blocksize = ff->fs->blocksize;
+	int set_error;
+	int ret;
+
+	ret = ioctl(fd, BLKBSZSET, &blocksize);
+	if (!ret)
+		return 0;
+
+	/*
+	 * Save the original errno so we can report that if the block device
+	 * blocksize isn't set in an agreeable way.
+	 */
+	set_error = errno;
+
+	ret = ioctl(fd, BLKBSZGET, &blocksize);
+	if (ret)
+		goto out_bad;
+
+	/* Pretend that BLKBSZSET rejected our proposed block size */
+	if (blocksize > ff->fs->blocksize) {
+		set_error = EINVAL;
+		goto out_bad;
+	}
+
+	return 0;
+out_bad:
+	err_printf(ff, "%s: cannot set blocksize %u: %s\n", __func__,
+		   blocksize, strerror(set_error));
+	return -EIO;
+}
+
 static int fuse2fs_iomap_config_devices(struct fuse2fs *ff)
 {
 	errcode_t err;
@@ -6212,6 +6251,10 @@ static int fuse2fs_iomap_config_devices(struct fuse2fs *ff)
 	if (err)
 		return translate_error(ff->fs, 0, err);
 
+	ret = fuse2fs_set_bdev_blocksize(ff, fd);
+	if (ret)
+		return ret;
+
 	ret = fuse_fs_iomap_device_add(fd, 0);
 	if (ret < 0) {
 		dbg_printf(ff, "%s: cannot register iomap dev fd=%d, err=%d\n",


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 15/19] fuse4fs: separate invalidation
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (13 preceding siblings ...)
  2026-02-23 23:39   ` [PATCH 14/19] fuse2fs: configure block device block size Darrick J. Wong
@ 2026-02-23 23:39   ` Darrick J. Wong
  2026-02-23 23:40   ` [PATCH 16/19] fuse2fs: implement statx Darrick J. Wong
                     ` (3 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:39 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Use the new stuff

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/fuse2fs.c    |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 9dd694be943255..90b365149910c9 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -281,6 +281,9 @@ struct fuse4fs {
 	enum fuse4fs_iomap_state iomap_state;
 	uint32_t iomap_dev;
 	uint64_t iomap_cap;
+	void (*old_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
+	void (*old_alloc_stats_range)(ext2_filsys fs, blk64_t blk, blk_t num,
+				      int inuse);
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -6736,6 +6739,51 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
 	return 0;
 }
 
+static void fuse4fs_invalidate_bdev(struct fuse4fs *ff, blk64_t blk, blk_t num)
+{
+	off_t offset = FUSE4FS_FSB_TO_B(ff, blk);
+	off_t length = FUSE4FS_FSB_TO_B(ff, num);
+	int ret;
+
+	ret = fuse_lowlevel_iomap_device_invalidate(ff->fuse, ff->iomap_dev,
+						    offset, length);
+	if (!ret)
+		return;
+
+	if (num == 1)
+		err_printf(ff, "%s %llu: %s\n",
+			   _("error invalidating block"),
+			   (unsigned long long)blk,
+			   strerror(ret));
+	else
+		err_printf(ff, "%s %llu-%llu: %s\n",
+			   _("error invalidating blocks"),
+			   (unsigned long long)blk,
+			   (unsigned long long)blk + num - 1,
+			   strerror(ret));
+}
+
+static void fuse4fs_alloc_stats(ext2_filsys fs, blk64_t blk, int inuse)
+{
+	struct fuse4fs *ff = fs->priv_data;
+
+	if (inuse < 0)
+		fuse4fs_invalidate_bdev(ff, blk, 1);
+	if (ff->old_alloc_stats)
+		ff->old_alloc_stats(fs, blk, inuse);
+}
+
+static void fuse4fs_alloc_stats_range(ext2_filsys fs, blk64_t blk, blk_t num,
+				      int inuse)
+{
+	struct fuse4fs *ff = fs->priv_data;
+
+	if (inuse < 0)
+		fuse4fs_invalidate_bdev(ff, blk, num);
+	if (ff->old_alloc_stats_range)
+		ff->old_alloc_stats_range(fs, blk, num, inuse);
+}
+
 static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
 {
 	struct fuse_iomap_config cfg = { };
@@ -6780,6 +6828,19 @@ static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
 	if (ret)
 		goto out_unlock;
 
+	/*
+	 * If we let iomap do all file block IO, then we need to watch for
+	 * freed blocks so that we can invalidate any page cache that might
+	 * get written to the block deivce.
+	 */
+	if (fuse4fs_iomap_enabled(ff)) {
+		ext2fs_set_block_alloc_stats_callback(ff->fs,
+				fuse4fs_alloc_stats, &ff->old_alloc_stats);
+		ext2fs_set_block_alloc_stats_range_callback(ff->fs,
+				fuse4fs_alloc_stats_range,
+				&ff->old_alloc_stats_range);
+	}
+
 out_unlock:
 	fuse4fs_finish(ff, ret);
 	if (ret)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index b270c51e82cd4a..ffcaf56314bdfd 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -275,6 +275,9 @@ struct fuse2fs {
 	enum fuse2fs_iomap_state iomap_state;
 	uint32_t iomap_dev;
 	uint64_t iomap_cap;
+	void (*old_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
+	void (*old_alloc_stats_range)(ext2_filsys fs, blk64_t blk, blk_t num,
+				      int inuse);
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -6269,6 +6272,50 @@ static int fuse2fs_iomap_config_devices(struct fuse2fs *ff)
 	return 0;
 }
 
+static void fuse2fs_invalidate_bdev(struct fuse2fs *ff, blk64_t blk, blk_t num)
+{
+	off_t offset = FUSE2FS_FSB_TO_B(ff, blk);
+	off_t length = FUSE2FS_FSB_TO_B(ff, num);
+	int ret;
+
+	ret = fuse_fs_iomap_device_invalidate(ff->iomap_dev, offset, length);
+	if (!ret)
+		return;
+
+	if (num == 1)
+		err_printf(ff, "%s %llu: %s\n",
+			   _("error invalidating block"),
+			   (unsigned long long)blk,
+			   strerror(ret));
+	else
+		err_printf(ff, "%s %llu-%llu: %s\n",
+			   _("error invalidating blocks"),
+			   (unsigned long long)blk,
+			   (unsigned long long)blk + num - 1,
+			   strerror(ret));
+}
+
+static void fuse2fs_alloc_stats(ext2_filsys fs, blk64_t blk, int inuse)
+{
+	struct fuse2fs *ff = fs->priv_data;
+
+	if (inuse < 0)
+		fuse2fs_invalidate_bdev(ff, blk, 1);
+	if (ff->old_alloc_stats)
+		ff->old_alloc_stats(fs, blk, inuse);
+}
+
+static void fuse2fs_alloc_stats_range(ext2_filsys fs, blk64_t blk, blk_t num,
+				      int inuse)
+{
+	struct fuse2fs *ff = fs->priv_data;
+
+	if (inuse < 0)
+		fuse2fs_invalidate_bdev(ff, blk, num);
+	if (ff->old_alloc_stats_range)
+		ff->old_alloc_stats_range(fs, blk, num, inuse);
+}
+
 static int op_iomap_config(uint64_t flags, off_t maxbytes,
 			   struct fuse_iomap_config *cfg)
 {
@@ -6313,6 +6360,19 @@ static int op_iomap_config(uint64_t flags, off_t maxbytes,
 	if (ret)
 		goto out_unlock;
 
+	/*
+	 * If we let iomap do all file block IO, then we need to watch for
+	 * freed blocks so that we can invalidate any page cache that might
+	 * get written to the block deivce.
+	 */
+	if (fuse2fs_iomap_enabled(ff)) {
+		ext2fs_set_block_alloc_stats_callback(ff->fs,
+				fuse2fs_alloc_stats, &ff->old_alloc_stats);
+		ext2fs_set_block_alloc_stats_range_callback(ff->fs,
+				fuse2fs_alloc_stats_range,
+				&ff->old_alloc_stats_range);
+	}
+
 out_unlock:
 	fuse2fs_finish(ff, ret);
 	return ret;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 16/19] fuse2fs: implement statx
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (14 preceding siblings ...)
  2026-02-23 23:39   ` [PATCH 15/19] fuse4fs: separate invalidation Darrick J. Wong
@ 2026-02-23 23:40   ` Darrick J. Wong
  2026-02-23 23:40   ` [PATCH 17/19] fuse2fs: enable atomic writes Darrick J. Wong
                     ` (2 subsequent siblings)
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:40 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Implement statx.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |  136 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/fuse2fs.c    |  131 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 267 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 90b365149910c9..62ab8f618015e9 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -24,6 +24,7 @@
 #include <sys/xattr.h>
 #endif
 #include <sys/ioctl.h>
+#include <sys/sysmacros.h>
 #include <unistd.h>
 #include <ctype.h>
 #include <assert.h>
@@ -2189,6 +2190,138 @@ static void op_getattr(fuse_req_t req, fuse_ino_t fino,
 				       fstat.entry.attr_timeout);
 }
 
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 18) && defined(STATX_BASIC_STATS)
+static inline void fuse4fs_set_statx_attr(struct statx *stx,
+					  uint64_t statx_flag, int set)
+{
+	if (set)
+		stx->stx_attributes |= statx_flag;
+	stx->stx_attributes_mask |= statx_flag;
+}
+
+static void fuse4fs_statx_directio(struct fuse4fs *ff, struct statx *stx)
+{
+	struct statx devx;
+	errcode_t err;
+	int fd;
+
+	err = io_channel_get_fd(ff->fs->io, &fd);
+	if (err)
+		return;
+
+	err = statx(fd, "", AT_EMPTY_PATH, STATX_DIOALIGN, &devx);
+	if (err)
+		return;
+	if (!(devx.stx_mask & STATX_DIOALIGN))
+		return;
+
+	stx->stx_mask |= STATX_DIOALIGN;
+	stx->stx_dio_mem_align = devx.stx_dio_mem_align;
+	stx->stx_dio_offset_align = devx.stx_dio_offset_align;
+}
+
+static int fuse4fs_statx(struct fuse4fs *ff, ext2_ino_t ino, int statx_mask,
+			 struct statx *stx)
+{
+	struct ext2_inode_large inode;
+	ext2_filsys fs = ff->fs;;
+	dev_t fakedev = 0;
+	errcode_t err;
+	struct timespec tv;
+
+	err = fuse4fs_read_inode(fs, ino, &inode);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	memcpy(&fakedev, fs->super->s_uuid, sizeof(fakedev));
+	stx->stx_mask = STATX_BASIC_STATS;
+	stx->stx_dev_major = major(fakedev);
+	stx->stx_dev_minor = minor(fakedev);
+	stx->stx_ino = ino;
+	stx->stx_mode = inode.i_mode;
+	stx->stx_nlink = inode.i_links_count;
+	stx->stx_uid = inode_uid(inode);
+	stx->stx_gid = inode_gid(inode);
+	stx->stx_size = EXT2_I_SIZE(&inode);
+	stx->stx_blksize = fs->blocksize;
+	stx->stx_blocks = ext2fs_get_stat_i_blocks(fs,
+						EXT2_INODE(&inode));
+	EXT4_INODE_GET_XTIME(i_atime, &tv, &inode);
+	stx->stx_atime.tv_sec = tv.tv_sec;
+	stx->stx_atime.tv_nsec = tv.tv_nsec;
+
+	EXT4_INODE_GET_XTIME(i_mtime, &tv, &inode);
+	stx->stx_mtime.tv_sec = tv.tv_sec;
+	stx->stx_mtime.tv_nsec = tv.tv_nsec;
+
+	EXT4_INODE_GET_XTIME(i_ctime, &tv, &inode);
+	stx->stx_ctime.tv_sec = tv.tv_sec;
+	stx->stx_ctime.tv_nsec = tv.tv_nsec;
+
+	if (EXT4_FITS_IN_INODE(&inode, i_crtime)) {
+		stx->stx_mask |= STATX_BTIME;
+		EXT4_INODE_GET_XTIME(i_crtime, &tv, &inode);
+		stx->stx_btime.tv_sec = tv.tv_sec;
+		stx->stx_btime.tv_nsec = tv.tv_nsec;
+	}
+
+	dbg_printf(ff, "%s: ino=%d atime=%lld.%d mtime=%lld.%d ctime=%lld.%d btime=%lld.%d\n",
+		   __func__, ino,
+		   (long long int)stx->stx_atime.tv_sec, stx->stx_atime.tv_nsec,
+		   (long long int)stx->stx_mtime.tv_sec, stx->stx_mtime.tv_nsec,
+		   (long long int)stx->stx_ctime.tv_sec, stx->stx_ctime.tv_nsec,
+		   (long long int)stx->stx_btime.tv_sec, stx->stx_btime.tv_nsec);
+
+	if (LINUX_S_ISCHR(inode.i_mode) ||
+	    LINUX_S_ISBLK(inode.i_mode)) {
+		if (inode.i_block[0]) {
+			stx->stx_rdev_major = major(inode.i_block[0]);
+			stx->stx_rdev_minor = minor(inode.i_block[0]);
+		} else {
+			stx->stx_rdev_major = major(inode.i_block[1]);
+			stx->stx_rdev_minor = minor(inode.i_block[1]);
+		}
+	}
+
+	fuse4fs_set_statx_attr(stx, STATX_ATTR_COMPRESSED,
+			       inode.i_flags & EXT2_COMPR_FL);
+	fuse4fs_set_statx_attr(stx, STATX_ATTR_IMMUTABLE,
+			       inode.i_flags & EXT2_IMMUTABLE_FL);
+	fuse4fs_set_statx_attr(stx, STATX_ATTR_APPEND,
+			       inode.i_flags & EXT2_APPEND_FL);
+	fuse4fs_set_statx_attr(stx, STATX_ATTR_NODUMP,
+			       inode.i_flags & EXT2_NODUMP_FL);
+
+	fuse4fs_statx_directio(ff, stx);
+
+	return 0;
+}
+
+static void op_statx(fuse_req_t req, fuse_ino_t fino, int flags, int mask,
+		     struct fuse_file_info *fi)
+{
+	struct statx stx = { };
+	struct fuse4fs *ff = fuse4fs_get(req);
+	ext2_ino_t ino;
+	int ret = 0;
+
+	FUSE4FS_CHECK_CONTEXT(req);
+	FUSE4FS_CONVERT_FINO(req, &ino, fino);
+	fuse4fs_start(ff);
+	ret = fuse4fs_statx(ff, ino, mask, &stx);
+	if (ret)
+		goto out;
+out:
+	fuse4fs_finish(ff, ret);
+	if (ret)
+		fuse_reply_err(req, -ret);
+	else
+		fuse_reply_statx(req, 0, &stx, FUSE4FS_ATTR_TIMEOUT);
+}
+#else
+# define op_statx		NULL
+#endif
+
 static void op_readlink(fuse_req_t req, fuse_ino_t fino)
 {
 	struct ext2_inode inode;
@@ -7260,6 +7393,9 @@ static struct fuse_lowlevel_ops fs_ops = {
 #ifdef SUPPORT_FALLOCATE
 	.fallocate = op_fallocate,
 #endif
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 18)
+	.statx = op_statx,
+#endif
 #ifdef HAVE_FUSE_IOMAP
 	.iomap_begin = op_iomap_begin,
 	.iomap_end = op_iomap_end,
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index ffcaf56314bdfd..f6f0eb9f54c7bf 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -23,6 +23,7 @@
 #include <sys/xattr.h>
 #endif
 #include <sys/ioctl.h>
+#include <sys/sysmacros.h>
 #include <unistd.h>
 #include <ctype.h>
 #ifdef HAVE_FUSE_LOOPDEV
@@ -1997,6 +1998,133 @@ static int op_getattr_iflags(const char *path, struct stat *statbuf,
 }
 #endif
 
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 18) && defined(STATX_BASIC_STATS)
+static inline void fuse2fs_set_statx_attr(struct statx *stx,
+					  uint64_t statx_flag, int set)
+{
+	if (set)
+		stx->stx_attributes |= statx_flag;
+	stx->stx_attributes_mask |= statx_flag;
+}
+
+static void fuse2fs_statx_directio(struct fuse2fs *ff, struct statx *stx)
+{
+	struct statx devx;
+	errcode_t err;
+	int fd;
+
+	err = io_channel_get_fd(ff->fs->io, &fd);
+	if (err)
+		return;
+
+	err = statx(fd, "", AT_EMPTY_PATH, STATX_DIOALIGN, &devx);
+	if (err)
+		return;
+	if (!(devx.stx_mask & STATX_DIOALIGN))
+		return;
+
+	stx->stx_mask |= STATX_DIOALIGN;
+	stx->stx_dio_mem_align = devx.stx_dio_mem_align;
+	stx->stx_dio_offset_align = devx.stx_dio_offset_align;
+}
+
+static int fuse2fs_statx(struct fuse2fs *ff, ext2_ino_t ino, int statx_mask,
+			 struct statx *stx)
+{
+	struct ext2_inode_large inode;
+	ext2_filsys fs = ff->fs;;
+	dev_t fakedev = 0;
+	errcode_t err;
+	struct timespec tv;
+
+	err = fuse2fs_read_inode(fs, ino, &inode);
+	if (err)
+		return translate_error(fs, ino, err);
+
+	memcpy(&fakedev, fs->super->s_uuid, sizeof(fakedev));
+	stx->stx_mask = STATX_BASIC_STATS;
+	stx->stx_dev_major = major(fakedev);
+	stx->stx_dev_minor = minor(fakedev);
+	stx->stx_ino = ino;
+	stx->stx_mode = inode.i_mode;
+	stx->stx_nlink = inode.i_links_count;
+	stx->stx_uid = inode_uid(inode);
+	stx->stx_gid = inode_gid(inode);
+	stx->stx_size = EXT2_I_SIZE(&inode);
+	stx->stx_blksize = fs->blocksize;
+	stx->stx_blocks = ext2fs_get_stat_i_blocks(fs,
+						EXT2_INODE(&inode));
+	EXT4_INODE_GET_XTIME(i_atime, &tv, &inode);
+	stx->stx_atime.tv_sec = tv.tv_sec;
+	stx->stx_atime.tv_nsec = tv.tv_nsec;
+
+	EXT4_INODE_GET_XTIME(i_mtime, &tv, &inode);
+	stx->stx_mtime.tv_sec = tv.tv_sec;
+	stx->stx_mtime.tv_nsec = tv.tv_nsec;
+
+	EXT4_INODE_GET_XTIME(i_ctime, &tv, &inode);
+	stx->stx_ctime.tv_sec = tv.tv_sec;
+	stx->stx_ctime.tv_nsec = tv.tv_nsec;
+
+	if (EXT4_FITS_IN_INODE(&inode, i_crtime)) {
+		stx->stx_mask |= STATX_BTIME;
+		EXT4_INODE_GET_XTIME(i_crtime, &tv, &inode);
+		stx->stx_btime.tv_sec = tv.tv_sec;
+		stx->stx_btime.tv_nsec = tv.tv_nsec;
+	}
+
+	dbg_printf(ff, "%s: ino=%d atime=%lld.%d mtime=%lld.%d ctime=%lld.%d btime=%lld.%d\n",
+		   __func__, ino,
+		   (long long int)stx->stx_atime.tv_sec, stx->stx_atime.tv_nsec,
+		   (long long int)stx->stx_mtime.tv_sec, stx->stx_mtime.tv_nsec,
+		   (long long int)stx->stx_ctime.tv_sec, stx->stx_ctime.tv_nsec,
+		   (long long int)stx->stx_btime.tv_sec, stx->stx_btime.tv_nsec);
+
+	if (LINUX_S_ISCHR(inode.i_mode) ||
+	    LINUX_S_ISBLK(inode.i_mode)) {
+		if (inode.i_block[0]) {
+			stx->stx_rdev_major = major(inode.i_block[0]);
+			stx->stx_rdev_minor = minor(inode.i_block[0]);
+		} else {
+			stx->stx_rdev_major = major(inode.i_block[1]);
+			stx->stx_rdev_minor = minor(inode.i_block[1]);
+		}
+	}
+
+	fuse2fs_set_statx_attr(stx, STATX_ATTR_COMPRESSED,
+			       inode.i_flags & EXT2_COMPR_FL);
+	fuse2fs_set_statx_attr(stx, STATX_ATTR_IMMUTABLE,
+			       inode.i_flags & EXT2_IMMUTABLE_FL);
+	fuse2fs_set_statx_attr(stx, STATX_ATTR_APPEND,
+			       inode.i_flags & EXT2_APPEND_FL);
+	fuse2fs_set_statx_attr(stx, STATX_ATTR_NODUMP,
+			       inode.i_flags & EXT2_NODUMP_FL);
+
+	fuse2fs_statx_directio(ff, stx);
+
+	return 0;
+}
+
+static int op_statx(const char *path, int statx_flags, int statx_mask,
+		    struct statx *stx, struct fuse_file_info *fi)
+{
+	struct fuse2fs *ff = fuse2fs_get();
+	ext2_ino_t ino;
+	int ret = 0;
+
+	FUSE2FS_CHECK_CONTEXT(ff);
+	fuse2fs_start(ff);
+	ret = fuse2fs_file_ino(ff, path, fi, &ino);
+	if (ret)
+		goto out;
+	ret = fuse2fs_statx(ff, ino, statx_mask, stx);
+out:
+	fuse2fs_finish(ff, ret);
+	return ret;
+}
+#else
+# define op_statx		NULL
+#endif
 
 static int op_readlink(const char *path, char *buf, size_t len)
 {
@@ -6784,6 +6912,9 @@ static struct fuse_operations fs_ops = {
 #ifdef SUPPORT_FALLOCATE
 	.fallocate = op_fallocate,
 #endif
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 18)
+	.statx = op_statx,
+#endif
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 99)
 	.getattr_iflags = op_getattr_iflags,
 #endif


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 17/19] fuse2fs: enable atomic writes
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (15 preceding siblings ...)
  2026-02-23 23:40   ` [PATCH 16/19] fuse2fs: implement statx Darrick J. Wong
@ 2026-02-23 23:40   ` Darrick J. Wong
  2026-02-23 23:40   ` [PATCH 18/19] fuse4fs: disable fs reclaim and write throttling Darrick J. Wong
  2026-02-23 23:41   ` [PATCH 19/19] fuse2fs: implement freeze and shutdown requests Darrick J. Wong
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:40 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Advertise the single-fsblock atomic write capability that iomap can do.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/fuse2fs.c    |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 134 insertions(+), 2 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 62ab8f618015e9..77207bae19e544 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -285,6 +285,9 @@ struct fuse4fs {
 	void (*old_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
 	void (*old_alloc_stats_range)(ext2_filsys fs, blk64_t blk, blk_t num,
 				      int inuse);
+#ifdef STATX_WRITE_ATOMIC
+	unsigned int awu_min, awu_max;
+#endif
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -910,10 +913,22 @@ static inline bool fuse4fs_can_iomap(const struct fuse4fs *ff)
 {
 	return ff->iomap_cap & FUSE_IOMAP_SUPPORT_FILEIO;
 }
+
+static inline bool fuse4fs_iomap_supports_hw_atomic(const struct fuse4fs *ff)
+{
+	return fuse4fs_iomap_enabled(ff) &&
+	       (ff->iomap_cap & FUSE_IOMAP_SUPPORT_ATOMIC) &&
+#ifdef STATX_WRITE_ATOMIC
+		ff->awu_min > 0 && ff->awu_min > 0;
+#else
+		0;
+#endif
+}
 #else
 # define fuse4fs_iomap_enabled(...)	(0)
 # define fuse4fs_discover_iomap(...)	((void)0)
 # define fuse4fs_can_iomap(...)		(false)
+# define fuse4fs_iomap_supports_hw_atomic(...)	(0)
 #endif
 
 static inline void fuse4fs_dump_extents(struct fuse4fs *ff, ext2_ino_t ino,
@@ -2115,8 +2130,12 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino,
 
 	fstat->iflags = 0;
 #ifdef HAVE_FUSE_IOMAP
-	if (fuse4fs_iomap_enabled(ff))
+	if (fuse4fs_iomap_enabled(ff)) {
 		fstat->iflags |= FUSE_IFLAG_IOMAP | FUSE_IFLAG_EXCLUSIVE;
+
+		if (fuse4fs_iomap_supports_hw_atomic(ff))
+			fstat->iflags |= FUSE_IFLAG_ATOMIC;
+	}
 #endif
 
 	return 0;
@@ -2294,6 +2313,15 @@ static int fuse4fs_statx(struct fuse4fs *ff, ext2_ino_t ino, int statx_mask,
 
 	fuse4fs_statx_directio(ff, stx);
 
+#ifdef STATX_WRITE_ATOMIC
+	if (fuse4fs_iomap_supports_hw_atomic(ff)) {
+		stx->stx_mask |= STATX_WRITE_ATOMIC;
+		stx->stx_atomic_write_unit_min = ff->awu_min;
+		stx->stx_atomic_write_unit_max = ff->awu_max;
+		stx->stx_atomic_write_segments_max = 1;
+	}
+#endif
+
 	return 0;
 }
 
@@ -6680,6 +6708,9 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 		}
 	}
 
+	if (opflags & FUSE_IOMAP_OP_ATOMIC)
+		read.flags |= FUSE_IOMAP_F_ATOMIC_BIO;
+
 out_unlock:
 	fuse4fs_finish(ff, ret);
 	if (ret)
@@ -6844,6 +6875,38 @@ static int fuse4fs_set_bdev_blocksize(struct fuse4fs *ff, int fd)
 	return -EIO;
 }
 
+#ifdef STATX_WRITE_ATOMIC
+static void fuse4fs_configure_atomic_write(struct fuse4fs *ff, int bdev_fd)
+{
+	struct statx devx;
+	unsigned int awu_min, awu_max;
+	int ret;
+
+	if (!ext2fs_has_feature_extents(ff->fs->super))
+		return;
+
+	ret = statx(bdev_fd, "", AT_EMPTY_PATH, STATX_WRITE_ATOMIC, &devx);
+	if (ret)
+		return;
+	if (!(devx.stx_mask & STATX_WRITE_ATOMIC))
+		return;
+
+	awu_min = max(ff->fs->blocksize, devx.stx_atomic_write_unit_min);
+	awu_max = min(ff->fs->blocksize, devx.stx_atomic_write_unit_max);
+	if (awu_min > awu_max)
+		return;
+
+	log_printf(ff, "%s awu_min: %u, awu_max: %u\n",
+		   _("Supports (experimental) DIO atomic writes"),
+		   awu_min, awu_max);
+
+	ff->awu_min = awu_min;
+	ff->awu_max = awu_max;
+}
+#else
+# define fuse4fs_configure_atomic_write(...)	((void)0)
+#endif
+
 static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
 {
 	errcode_t err;
@@ -6868,6 +6931,8 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
 	dbg_printf(ff, "%s: registered iomap dev fd=%d iomap_dev=%u\n",
 		   __func__, fd, ff->iomap_dev);
 
+	fuse4fs_configure_atomic_write(ff, fd);
+
 	ff->iomap_dev = ret;
 	return 0;
 }
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index f6f0eb9f54c7bf..6266c1de163694 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -279,6 +279,9 @@ struct fuse2fs {
 	void (*old_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
 	void (*old_alloc_stats_range)(ext2_filsys fs, blk64_t blk, blk_t num,
 				      int inuse);
+#ifdef STATX_WRITE_ATOMIC
+	unsigned int awu_min, awu_max;
+#endif
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -749,10 +752,22 @@ static inline bool fuse2fs_can_iomap(const struct fuse2fs *ff)
 {
 	return ff->iomap_cap & FUSE_IOMAP_SUPPORT_FILEIO;
 }
+
+static inline bool fuse2fs_iomap_supports_hw_atomic(const struct fuse2fs *ff)
+{
+	return fuse2fs_iomap_enabled(ff) &&
+	       (ff->iomap_cap & FUSE_IOMAP_SUPPORT_ATOMIC) &&
+#ifdef STATX_WRITE_ATOMIC
+		ff->awu_min > 0 && ff->awu_min > 0;
+#else
+		0;
+#endif
+}
 #else
 # define fuse2fs_iomap_enabled(...)	(0)
 # define fuse2fs_discover_iomap(...)	((void)0)
 # define fuse2fs_can_iomap(...)		(false)
+# define fuse2fs_iomap_supports_hw_atomic(...)	(0)
 #endif
 
 static inline void fuse2fs_dump_extents(struct fuse2fs *ff, ext2_ino_t ino,
@@ -1986,14 +2001,19 @@ static int op_getattr(const char *path, struct stat *statbuf,
 static int op_getattr_iflags(const char *path, struct stat *statbuf,
 			     unsigned int *iflags, struct fuse_file_info *fi)
 {
+	struct fuse2fs *ff = fuse2fs_get();
 	int ret = op_getattr(path, statbuf, fi);
 
 	if (ret)
 		return ret;
 
-	if (fuse_fs_can_enable_iomap(statbuf))
+	if (fuse_fs_can_enable_iomap(statbuf)) {
 		*iflags |= FUSE_IFLAG_IOMAP | FUSE_IFLAG_EXCLUSIVE;
 
+		if (fuse2fs_iomap_supports_hw_atomic(ff))
+			*iflags |= FUSE_IFLAG_ATOMIC;
+	}
+
 	return 0;
 }
 #endif
@@ -2102,6 +2122,16 @@ static int fuse2fs_statx(struct fuse2fs *ff, ext2_ino_t ino, int statx_mask,
 
 	fuse2fs_statx_directio(ff, stx);
 
+#ifdef STATX_WRITE_ATOMIC
+	if (fuse_fs_can_enable_iomapx(stx) &&
+	    fuse2fs_iomap_supports_hw_atomic(ff)) {
+		stx->stx_mask |= STATX_WRITE_ATOMIC;
+		stx->stx_atomic_write_unit_min = ff->awu_min;
+		stx->stx_atomic_write_unit_max = ff->awu_max;
+		stx->stx_atomic_write_segments_max = 1;
+	}
+#endif
+
 	return 0;
 }
 
@@ -6211,6 +6241,9 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
 		}
 	}
 
+	if (opflags & FUSE_IOMAP_OP_ATOMIC)
+		read->flags |= FUSE_IOMAP_F_ATOMIC_BIO;
+
 out_unlock:
 	fuse2fs_finish(ff, ret);
 	return ret;
@@ -6372,6 +6405,38 @@ static int fuse2fs_set_bdev_blocksize(struct fuse2fs *ff, int fd)
 	return -EIO;
 }
 
+#ifdef STATX_WRITE_ATOMIC
+static void fuse2fs_configure_atomic_write(struct fuse2fs *ff, int bdev_fd)
+{
+	struct statx devx;
+	unsigned int awu_min, awu_max;
+	int ret;
+
+	if (!ext2fs_has_feature_extents(ff->fs->super))
+		return;
+
+	ret = statx(bdev_fd, "", AT_EMPTY_PATH, STATX_WRITE_ATOMIC, &devx);
+	if (ret)
+		return;
+	if (!(devx.stx_mask & STATX_WRITE_ATOMIC))
+		return;
+
+	awu_min = max(ff->fs->blocksize, devx.stx_atomic_write_unit_min);
+	awu_max = min(ff->fs->blocksize, devx.stx_atomic_write_unit_max);
+	if (awu_min > awu_max)
+		return;
+
+	log_printf(ff, "%s awu_min: %u, awu_max: %u\n",
+		   _("Supports (experimental) DIO atomic writes"),
+		   awu_min, awu_max);
+
+	ff->awu_min = awu_min;
+	ff->awu_max = awu_max;
+}
+#else
+# define fuse2fs_configure_atomic_write(...)	((void)0)
+#endif
+
 static int fuse2fs_iomap_config_devices(struct fuse2fs *ff)
 {
 	errcode_t err;
@@ -6396,6 +6461,8 @@ static int fuse2fs_iomap_config_devices(struct fuse2fs *ff)
 	dbg_printf(ff, "%s: registered iomap dev fd=%d iomap_dev=%u\n",
 		   __func__, fd, ff->iomap_dev);
 
+	fuse2fs_configure_atomic_write(ff, fd);
+
 	ff->iomap_dev = ret;
 	return 0;
 }


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 18/19] fuse4fs: disable fs reclaim and write throttling
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (16 preceding siblings ...)
  2026-02-23 23:40   ` [PATCH 17/19] fuse2fs: enable atomic writes Darrick J. Wong
@ 2026-02-23 23:40   ` Darrick J. Wong
  2026-02-23 23:41   ` [PATCH 19/19] fuse2fs: implement freeze and shutdown requests Darrick J. Wong
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:40 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Ask the kernel if we can disable fs reclaim and write throttling.

Disabling fs reclaim prevents livelocks where the fuse server can
allocate memory, fault into the kernel, and then the allocation tries to
initiate writeback by calling back into the same fuse server.

Disabling BDI write throttling means that writeback won't be throttled
by metadata writes to the filesystem.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 77207bae19e544..4499f4083f85dd 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -7737,6 +7737,19 @@ static void try_set_io_flusher(struct fuse4fs *ff)
 #endif
 }
 
+/* Undo try_set_io_flusher */
+static void try_clear_io_flusher(struct fuse4fs *ff)
+{
+#ifdef HAVE_PR_SET_IO_FLUSHER
+	/*
+	 * zero ret means it's already set, negative means we can't even
+	 * look at the value so don't bother clearing it
+	 */
+	if (prctl(PR_GET_IO_FLUSHER, 0, 0, 0, 0) > 0)
+		prctl(PR_SET_IO_FLUSHER, 0, 0, 0, 0);
+#endif
+}
+
 /* Try to adjust the OOM score so that we don't get killed */
 static void try_adjust_oom_score(struct fuse4fs *ff)
 {
@@ -7842,12 +7855,27 @@ static int fuse4fs_main(struct fuse_args *args, struct fuse4fs *ff)
 	fuse_loop_cfg_set_idle_threads(loop_config, opts.max_idle_threads);
 	fuse_loop_cfg_set_max_threads(loop_config, 4);
 
+	/*
+	 * Try to set ourselves up with fs reclaim disabled to prevent
+	 * recursive reclaim and throttling.  This must be done before starting
+	 * the worker threads so that they inherit the process flags.
+	 */
+	ret = fuse_lowlevel_disable_fsreclaim(ff->fuse, 1);
+	if (ret) {
+		err_printf(ff, "%s: %s.\n",
+ _("Could not register as FS flusher thread"),
+			   strerror(errno));
+		try_set_io_flusher(ff);
+		ret = 0;
+	}
+
 	if (fuse_session_loop_mt(se, loop_config) != 0) {
 		ret = 8;
-		goto out_loopcfg;
+		goto out_flusher;
 	}
 
-out_loopcfg:
+out_flusher:
+	try_clear_io_flusher(ff);
 	fuse_loop_cfg_destroy(loop_config);
 out_remove_signal_handlers:
 	fuse_remove_signal_handlers(se);
@@ -7925,7 +7953,6 @@ int main(int argc, char *argv[])
 		goto out;
 	}
 
-	try_set_io_flusher(&fctx);
 	try_adjust_oom_score(&fctx);
 
 	/* Will we allow users to allocate every last block? */


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 19/19] fuse2fs: implement freeze and shutdown requests
  2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
                     ` (17 preceding siblings ...)
  2026-02-23 23:40   ` [PATCH 18/19] fuse4fs: disable fs reclaim and write throttling Darrick J. Wong
@ 2026-02-23 23:41   ` Darrick J. Wong
  18 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:41 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Handle freezing and shutting down the filesystem if requested.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/fuse2fs.c    |   84 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 175 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 4499f4083f85dd..170accabfd9fd6 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -228,6 +228,7 @@ struct fuse4fs_file_handle {
 
 enum fuse4fs_opstate {
 	F4OP_READONLY,
+	F4OP_WRITABLE_FROZEN,
 	F4OP_WRITABLE,
 	F4OP_SHUTDOWN,
 };
@@ -6166,6 +6167,91 @@ static void op_fallocate(fuse_req_t req, fuse_ino_t fino EXT2FS_ATTR((unused)),
 }
 #endif /* SUPPORT_FALLOCATE */
 
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 99)
+static void op_freezefs(fuse_req_t req, fuse_ino_t ino, uint64_t unlinked)
+{
+	struct fuse4fs *ff = fuse4fs_get(req);
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	FUSE4FS_CHECK_CONTEXT(req);
+	fs = fuse4fs_start(ff);
+
+	if (ff->opstate == F4OP_WRITABLE) {
+		if (fs->super->s_error_count)
+			fs->super->s_state |= EXT2_ERROR_FS;
+		else if (!unlinked)
+			fs->super->s_state |= EXT2_VALID_FS;
+		ext2fs_mark_super_dirty(fs);
+		err = ext2fs_set_gdt_csum(fs);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		err = ext2fs_flush2(fs, 0);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		ff->opstate = F4OP_WRITABLE_FROZEN;
+	}
+
+out_unlock:
+	fs->super->s_state &= ~EXT2_VALID_FS;
+	fuse4fs_finish(ff, ret);
+	fuse_reply_err(req, -ret);
+}
+
+static void op_unfreezefs(fuse_req_t req, fuse_ino_t ino)
+{
+	struct fuse4fs *ff = fuse4fs_get(req);
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	FUSE4FS_CHECK_CONTEXT(req);
+	fs = fuse4fs_start(ff);
+
+	if (ff->opstate == F4OP_WRITABLE_FROZEN) {
+		if (fs->super->s_error_count)
+			fs->super->s_state |= EXT2_ERROR_FS;
+		fs->super->s_state &= ~EXT2_VALID_FS;
+		ext2fs_mark_super_dirty(fs);
+		err = ext2fs_set_gdt_csum(fs);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		err = ext2fs_flush2(fs, 0);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		ff->opstate = F4OP_WRITABLE;
+	}
+
+out_unlock:
+	fuse4fs_finish(ff, ret);
+	fuse_reply_err(req, -ret);
+}
+
+static void op_shutdownfs(fuse_req_t req, fuse_ino_t ino, uint64_t flags)
+{
+	const struct fuse_ctx *ctxt = fuse_req_ctx(req);
+	struct fuse4fs *ff = fuse4fs_get(req);
+	int ret;
+
+	ret = ioctl_shutdown(ff, ctxt, NULL, NULL, 0);
+
+	fuse_reply_err(req, -ret);
+}
+#endif
+
 #ifdef HAVE_FUSE_IOMAP
 static void fuse4fs_iomap_hole(struct fuse4fs *ff, struct fuse_file_iomap *iomap,
 			       off_t pos, uint64_t count)
@@ -7461,6 +7547,11 @@ static struct fuse_lowlevel_ops fs_ops = {
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 18)
 	.statx = op_statx,
 #endif
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 99)
+	.freezefs = op_freezefs,
+	.unfreezefs = op_unfreezefs,
+	.shutdownfs = op_shutdownfs,
+#endif
 #ifdef HAVE_FUSE_IOMAP
 	.iomap_begin = op_iomap_begin,
 	.iomap_end = op_iomap_end,
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 6266c1de163694..4535bb16efd586 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -222,6 +222,7 @@ struct fuse2fs_file_handle {
 
 enum fuse2fs_opstate {
 	F2OP_READONLY,
+	F2OP_WRITABLE_FROZEN,
 	F2OP_WRITABLE,
 	F2OP_SHUTDOWN,
 };
@@ -5700,6 +5701,86 @@ static int op_fallocate(const char *path EXT2FS_ATTR((unused)), int mode,
 }
 #endif /* SUPPORT_FALLOCATE */
 
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 99)
+static int op_freezefs(const char *path, uint64_t unlinked)
+{
+	struct fuse2fs *ff = fuse2fs_get();
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	FUSE2FS_CHECK_CONTEXT(ff);
+	fs = fuse2fs_start(ff);
+
+	if (ff->opstate == F2OP_WRITABLE) {
+		if (fs->super->s_error_count)
+			fs->super->s_state |= EXT2_ERROR_FS;
+		else if (!unlinked)
+			fs->super->s_state |= EXT2_VALID_FS;
+		ext2fs_mark_super_dirty(fs);
+		err = ext2fs_set_gdt_csum(fs);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		err = ext2fs_flush2(fs, 0);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		ff->opstate = F2OP_WRITABLE_FROZEN;
+	}
+
+out_unlock:
+	fs->super->s_state &= ~EXT2_VALID_FS;
+	fuse2fs_finish(ff, ret);
+	return ret;
+}
+
+static int op_unfreezefs(const char *path)
+{
+	struct fuse2fs *ff = fuse2fs_get();
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	FUSE2FS_CHECK_CONTEXT(ff);
+	fs = fuse2fs_start(ff);
+
+	if (ff->opstate == F2OP_WRITABLE_FROZEN) {
+		if (fs->super->s_error_count)
+			fs->super->s_state |= EXT2_ERROR_FS;
+		ext2fs_mark_super_dirty(fs);
+		err = ext2fs_set_gdt_csum(fs);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		err = ext2fs_flush2(fs, 0);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		ff->opstate = F2OP_WRITABLE;
+	}
+
+out_unlock:
+	fuse2fs_finish(ff, ret);
+	return ret;
+}
+
+static int op_shutdownfs(const char *path, uint64_t flags)
+{
+	struct fuse2fs *ff = fuse2fs_get();
+
+	return ioctl_shutdown(ff, NULL, NULL);
+}
+#endif
+
 #ifdef HAVE_FUSE_IOMAP
 static void fuse2fs_iomap_hole(struct fuse2fs *ff, struct fuse_file_iomap *iomap,
 			       off_t pos, uint64_t count)
@@ -6984,6 +7065,9 @@ static struct fuse_operations fs_ops = {
 #endif
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 99)
 	.getattr_iflags = op_getattr_iflags,
+	.freezefs = op_freezefs,
+	.unfreezefs = op_unfreezefs,
+	.shutdownfs = op_shutdownfs,
 #endif
 #ifdef HAVE_FUSE_IOMAP
 	.iomap_begin = op_iomap_begin,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/1] fuse4fs: don't use inode number translation when possible
  2026-02-23 23:04 ` [PATCHSET v7 2/8] fuse4fs: specify the root node id Darrick J. Wong
@ 2026-02-23 23:41   ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:41 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Prior to the integration of iomap into fuse, the fuse client (aka the
kernel) required that the root directory have an inumber of
FUSE_ROOT_ID, which is 1.  However, the ext2 filesystem defines the root
inode number to be EXT2_ROOT_INO, which is 2.  This dissonance means
that we have to have translator functions, and that any access to
inumber 1 (the ext2 badblocks file) will instead redirect to the root
directory.

That's horrible.  Use the new mount option to set the root directory
nodeid to EXT2_ROOT_INO so that we don't need this translation.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 170accabfd9fd6..bebc2410af382e 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -273,6 +273,7 @@ struct fuse4fs {
 	int directio;
 	int acl;
 	int dirsync;
+	int translate_inums;
 
 	enum fuse4fs_opstate opstate;
 	int logfd;
@@ -345,17 +346,19 @@ struct fuse4fs {
 #define FUSE4FS_CHECK_CONTEXT_INIT(req) \
 	__FUSE4FS_CHECK_CONTEXT((req), abort(), abort())
 
-static inline void fuse4fs_ino_from_fuse(ext2_ino_t *inop, fuse_ino_t fino)
+static inline void fuse4fs_ino_from_fuse(const struct fuse4fs *ff,
+					 ext2_ino_t *inop, fuse_ino_t fino)
 {
-	if (fino == FUSE_ROOT_ID)
+	if (ff->translate_inums && fino == FUSE_ROOT_ID)
 		*inop = EXT2_ROOT_INO;
 	else
 		*inop = fino;
 }
 
-static inline void fuse4fs_ino_to_fuse(fuse_ino_t *finop, ext2_ino_t ino)
+static inline void fuse4fs_ino_to_fuse(const struct fuse4fs *ff,
+				       fuse_ino_t *finop, ext2_ino_t ino)
 {
-	if (ino == EXT2_ROOT_INO)
+	if (ff->translate_inums && ino == EXT2_ROOT_INO)
 		*finop = FUSE_ROOT_ID;
 	else
 		*finop = ino;
@@ -371,7 +374,7 @@ static inline void fuse4fs_ino_to_fuse(fuse_ino_t *finop, ext2_ino_t ino)
 			fuse_reply_err((req), EIO); \
 			return; \
 		} \
-		fuse4fs_ino_from_fuse(ext2_inop, fuse_ino); \
+		fuse4fs_ino_from_fuse(fuse4fs_get(req), ext2_inop, fuse_ino); \
 	} while (0)
 
 static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
@@ -2124,7 +2127,7 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino,
 			statbuf->st_rdev = inodep->i_block[1];
 	}
 
-	fuse4fs_ino_to_fuse(&entry->ino, ino);
+	fuse4fs_ino_to_fuse(ff, &entry->ino, ino);
 	entry->generation = inodep->i_generation;
 	entry->attr_timeout = FUSE4FS_ATTR_TIMEOUT;
 	entry->entry_timeout = FUSE4FS_ATTR_TIMEOUT;
@@ -7793,6 +7796,20 @@ static void fuse4fs_compute_libfuse_args(struct fuse4fs *ff,
  "-oallow_other,default_permissions,suid,dev");
 	}
 
+	if (fuse4fs_can_iomap(ff)) {
+		/*
+		 * The root_nodeid mount option was added when iomap support
+		 * was added to fuse.  This enables us to control the root
+		 * nodeid in the kernel, which enables a 1:1 translation of
+		 * ext2 to kernel inumbers.
+		 */
+		snprintf(extra_args, BUFSIZ, "-oroot_nodeid=%d",
+			 EXT2_ROOT_INO);
+		fuse_opt_add_arg(args, extra_args);
+		ff->translate_inums = 0;
+	}
+
+
 	if (ff->debug) {
 		int	i;
 
@@ -7998,6 +8015,7 @@ int main(int argc, char *argv[])
 #ifdef HAVE_FUSE_LOOPDEV
 		.loop_fd = -1,
 #endif
+		.translate_inums = 1,
 	};
 	errcode_t err;
 	FILE *orig_stderr = stderr;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 01/10] fuse2fs: add strictatime/lazytime mount options
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
@ 2026-02-23 23:41   ` Darrick J. Wong
  2026-02-23 23:41   ` [PATCH 02/10] fuse2fs: skip permission checking on utimens when iomap is enabled Darrick J. Wong
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:41 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

In iomap mode, we can support the strictatime/lazytime mount options.
Add them to fuse2fs.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.1.in |    6 ++++++
 fuse4fs/fuse4fs.c    |   28 +++++++++++++++++++++++++++-
 misc/fuse2fs.1.in    |    6 ++++++
 misc/fuse2fs.c       |   27 +++++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 1 deletion(-)


diff --git a/fuse4fs/fuse4fs.1.in b/fuse4fs/fuse4fs.1.in
index 8855867d27101d..119cbcc903d8af 100644
--- a/fuse4fs/fuse4fs.1.in
+++ b/fuse4fs/fuse4fs.1.in
@@ -90,6 +90,9 @@ .SS "fuse4fs options:"
 .I nosuid
 ) later.
 .TP
+\fB-o\fR lazytime
+if iomap is enabled, enable lazy updates of timestamps
+.TP
 \fB-o\fR lockfile=path
 use this file to control access to the filesystem
 .TP
@@ -98,6 +101,9 @@ .SS "fuse4fs options:"
 .TP
 \fB-o\fR norecovery
 do not replay the journal and mount the file system read-only
+.TP
+\fB-o\fR strictatime
+if iomap is enabled, update atime on every access
 .SS "FUSE options:"
 .TP
 \fB-d -o\fR debug
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index bebc2410af382e..428e4cb404cb45 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -274,6 +274,7 @@ struct fuse4fs {
 	int acl;
 	int dirsync;
 	int translate_inums;
+	int iomap_passthrough_options;
 
 	enum fuse4fs_opstate opstate;
 	int logfd;
@@ -1376,6 +1377,12 @@ static errcode_t fuse4fs_check_support(struct fuse4fs *ff)
 		return EXT2_ET_FILESYSTEM_CORRUPTED;
 	}
 
+	if (ff->iomap_passthrough_options && !fuse4fs_can_iomap(ff)) {
+		err_printf(ff, "%s\n",
+			   _("Some mount options require iomap."));
+		return EINVAL;
+	}
+
 	return 0;
 }
 
@@ -2005,6 +2012,8 @@ static void fuse4fs_iomap_enable(struct fuse_conn_info *conn,
 	if (!fuse4fs_iomap_enabled(ff)) {
 		if (ff->iomap_want == FT_ENABLE)
 			err_printf(ff, "%s\n", _("Could not enable iomap."));
+		if (ff->iomap_passthrough_options)
+			err_printf(ff, "%s\n", _("Some mount options require iomap."));
 		return;
 	}
 }
@@ -7590,6 +7599,7 @@ enum {
 	FUSE4FS_ERRORS_BEHAVIOR,
 #ifdef HAVE_FUSE_IOMAP
 	FUSE4FS_IOMAP,
+	FUSE4FS_IOMAP_PASSTHROUGH,
 #endif
 };
 
@@ -7616,6 +7626,17 @@ static struct fuse_opt fuse4fs_opts[] = {
 	FUSE4FS_OPT("timing",		timing,			1),
 #endif
 
+#ifdef HAVE_FUSE_IOMAP
+#ifdef MS_LAZYTIME
+	FUSE_OPT_KEY("lazytime",	FUSE4FS_IOMAP_PASSTHROUGH),
+	FUSE_OPT_KEY("nolazytime",	FUSE4FS_IOMAP_PASSTHROUGH),
+#endif
+#ifdef MS_STRICTATIME
+	FUSE_OPT_KEY("strictatime",	FUSE4FS_IOMAP_PASSTHROUGH),
+	FUSE_OPT_KEY("nostrictatime",	FUSE4FS_IOMAP_PASSTHROUGH),
+#endif
+#endif
+
 	FUSE_OPT_KEY("user_xattr",	FUSE4FS_IGNORED),
 	FUSE_OPT_KEY("noblock_validity", FUSE4FS_IGNORED),
 	FUSE_OPT_KEY("nodelalloc",	FUSE4FS_IGNORED),
@@ -7642,6 +7663,12 @@ static int fuse4fs_opt_proc(void *data, const char *arg,
 	struct fuse4fs *ff = data;
 
 	switch (key) {
+#ifdef HAVE_FUSE_IOMAP
+	case FUSE4FS_IOMAP_PASSTHROUGH:
+		ff->iomap_passthrough_options = 1;
+		/* pass through to libfuse */
+		return 1;
+#endif
 	case FUSE4FS_DIRSYNC:
 		ff->dirsync = 1;
 		/* pass through to libfuse */
@@ -7809,7 +7836,6 @@ static void fuse4fs_compute_libfuse_args(struct fuse4fs *ff,
 		ff->translate_inums = 0;
 	}
 
-
 	if (ff->debug) {
 		int	i;
 
diff --git a/misc/fuse2fs.1.in b/misc/fuse2fs.1.in
index 2b55fa0e723966..0c0934f03c9543 100644
--- a/misc/fuse2fs.1.in
+++ b/misc/fuse2fs.1.in
@@ -90,6 +90,9 @@ .SS "fuse2fs options:"
 .I nosuid
 ) later.
 .TP
+\fB-o\fR lazytime
+if iomap is enabled, enable lazy updates of timestamps
+.TP
 \fB-o\fR lockfile=path
 use this file to control access to the filesystem
 .TP
@@ -98,6 +101,9 @@ .SS "fuse2fs options:"
 .TP
 \fB-o\fR norecovery
 do not replay the journal and mount the file system read-only
+.TP
+\fB-o\fR strictatime
+if iomap is enabled, update atime on every access
 .SS "FUSE options:"
 .TP
 \fB-d -o\fR debug
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 4535bb16efd586..3cb875d0d29481 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -267,6 +267,7 @@ struct fuse2fs {
 	int directio;
 	int acl;
 	int dirsync;
+	int iomap_passthrough_options;
 
 	enum fuse2fs_opstate opstate;
 	int logfd;
@@ -1191,6 +1192,12 @@ static errcode_t fuse2fs_check_support(struct fuse2fs *ff)
 		return EXT2_ET_FILESYSTEM_CORRUPTED;
 	}
 
+	if (ff->iomap_passthrough_options && !fuse2fs_can_iomap(ff)) {
+		err_printf(ff, "%s\n",
+			   _("Some mount options require iomap."));
+		return EINVAL;
+	}
+
 	return 0;
 }
 
@@ -1811,6 +1818,8 @@ static void fuse2fs_iomap_enable(struct fuse_conn_info *conn,
 	if (!fuse2fs_iomap_enabled(ff)) {
 		if (ff->iomap_want == FT_ENABLE)
 			err_printf(ff, "%s\n", _("Could not enable iomap."));
+		if (ff->iomap_passthrough_options)
+			err_printf(ff, "%s\n", _("Some mount options require iomap."));
 		return;
 	}
 }
@@ -7104,6 +7113,7 @@ enum {
 	FUSE2FS_ERRORS_BEHAVIOR,
 #ifdef HAVE_FUSE_IOMAP
 	FUSE2FS_IOMAP,
+	FUSE2FS_IOMAP_PASSTHROUGH,
 #endif
 };
 
@@ -7130,6 +7140,17 @@ static struct fuse_opt fuse2fs_opts[] = {
 	FUSE2FS_OPT("timing",		timing,			1),
 #endif
 
+#ifdef HAVE_FUSE_IOMAP
+#ifdef MS_LAZYTIME
+	FUSE_OPT_KEY("lazytime",	FUSE2FS_IOMAP_PASSTHROUGH),
+	FUSE_OPT_KEY("nolazytime",	FUSE2FS_IOMAP_PASSTHROUGH),
+#endif
+#ifdef MS_STRICTATIME
+	FUSE_OPT_KEY("strictatime",	FUSE2FS_IOMAP_PASSTHROUGH),
+	FUSE_OPT_KEY("nostrictatime",	FUSE2FS_IOMAP_PASSTHROUGH),
+#endif
+#endif
+
 	FUSE_OPT_KEY("user_xattr",	FUSE2FS_IGNORED),
 	FUSE_OPT_KEY("noblock_validity", FUSE2FS_IGNORED),
 	FUSE_OPT_KEY("nodelalloc",	FUSE2FS_IGNORED),
@@ -7156,6 +7177,12 @@ static int fuse2fs_opt_proc(void *data, const char *arg,
 	struct fuse2fs *ff = data;
 
 	switch (key) {
+#ifdef HAVE_FUSE_IOMAP
+	case FUSE2FS_IOMAP_PASSTHROUGH:
+		ff->iomap_passthrough_options = 1;
+		/* pass through to libfuse */
+		return 1;
+#endif
 	case FUSE2FS_DIRSYNC:
 		ff->dirsync = 1;
 		/* pass through to libfuse */


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 02/10] fuse2fs: skip permission checking on utimens when iomap is enabled
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
  2026-02-23 23:41   ` [PATCH 01/10] fuse2fs: add strictatime/lazytime mount options Darrick J. Wong
@ 2026-02-23 23:41   ` Darrick J. Wong
  2026-02-23 23:42   ` [PATCH 03/10] fuse2fs: let the kernel tell us about acl/mode updates Darrick J. Wong
                     ` (7 subsequent siblings)
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:41 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

When iomap is enabled, the kernel is in charge of enforcing permissions
checks on timestamp updates for files.  We needn't do that in userspace
anymore.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   11 +++++++----
 misc/fuse2fs.c    |   11 +++++++----
 2 files changed, 14 insertions(+), 8 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 428e4cb404cb45..b7ee336b5e4546 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -5276,13 +5276,16 @@ static int fuse4fs_utimens(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 
 	/*
 	 * ext4 allows timestamp updates of append-only files but only if we're
-	 * setting to current time
+	 * setting to current time.  If iomap is enabled, the kernel does the
+	 * permission checking for timestamp updates; skip the access check.
 	 */
 	if (aact == TA_NOW && mact == TA_NOW)
 		access |= A_OK;
-	ret = fuse4fs_inum_access(ff, ctxt, ino, access);
-	if (ret)
-		return ret;
+	if (!fuse4fs_iomap_enabled(ff)) {
+		ret = fuse4fs_inum_access(ff, ctxt, ino, access);
+		if (ret)
+			return ret;
+	}
 
 	if (aact != TA_OMIT)
 		EXT4_INODE_SET_XTIME(i_atime, &atime, inode);
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 3cb875d0d29481..473a9124016712 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -4930,13 +4930,16 @@ static int op_utimens(const char *path, const struct timespec ctv[2],
 
 	/*
 	 * ext4 allows timestamp updates of append-only files but only if we're
-	 * setting to current time
+	 * setting to current time.  If iomap is enabled, the kernel does the
+	 * permission checking for timestamp updates; skip the access check.
 	 */
 	if (ctv[0].tv_nsec == UTIME_NOW && ctv[1].tv_nsec == UTIME_NOW)
 		access |= A_OK;
-	ret = check_inum_access(ff, ino, access);
-	if (ret)
-		goto out;
+	if (!fuse2fs_iomap_enabled(ff)) {
+		ret = check_inum_access(ff, ino, access);
+		if (ret)
+			goto out;
+	}
 
 	err = fuse2fs_read_inode(fs, ino, &inode);
 	if (err) {


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 03/10] fuse2fs: let the kernel tell us about acl/mode updates
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
  2026-02-23 23:41   ` [PATCH 01/10] fuse2fs: add strictatime/lazytime mount options Darrick J. Wong
  2026-02-23 23:41   ` [PATCH 02/10] fuse2fs: skip permission checking on utimens when iomap is enabled Darrick J. Wong
@ 2026-02-23 23:42   ` Darrick J. Wong
  2026-02-23 23:42   ` [PATCH 04/10] fuse2fs: better debugging for file mode updates Darrick J. Wong
                     ` (6 subsequent siblings)
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:42 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

When the kernel is running in iomap mode, it will also manage all the
ACL updates and the resulting file mode changes for us.  Disable the
manual implementation of it in fuse2fs.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |    4 ++--
 misc/fuse2fs.c    |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index b7ee336b5e4546..2cbbd1ed19a00c 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -2505,7 +2505,7 @@ static int fuse4fs_propagate_default_acls(struct fuse4fs *ff, ext2_ino_t parent,
 	size_t deflen;
 	int ret;
 
-	if (!ff->acl || S_ISDIR(mode))
+	if (!ff->acl || S_ISDIR(mode) || fuse4fs_iomap_enabled(ff))
 		return 0;
 
 	ret = fuse4fs_getxattr(ff, parent, XATTR_NAME_POSIX_ACL_DEFAULT, &def,
@@ -3931,7 +3931,7 @@ static int fuse4fs_chmod(struct fuse4fs *ff, fuse_req_t req, ext2_ino_t ino,
 	 * of the user's groups, but FUSE only tells us about the primary
 	 * group.
 	 */
-	if (!fuse4fs_is_superuser(ff, ctxt)) {
+	if (!fuse4fs_iomap_enabled(ff) && !fuse4fs_is_superuser(ff, ctxt)) {
 		ret = fuse4fs_in_file_group(ff, req, inode);
 		if (ret < 0)
 			return ret;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 473a9124016712..503d3c1cba5fd4 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -2307,7 +2307,7 @@ static int propagate_default_acls(struct fuse2fs *ff, ext2_ino_t parent,
 	size_t deflen;
 	int ret;
 
-	if (!ff->acl || S_ISDIR(mode))
+	if (!ff->acl || S_ISDIR(mode) || fuse2fs_iomap_enabled(ff))
 		return 0;
 
 	ret = __getxattr(ff, parent, XATTR_NAME_POSIX_ACL_DEFAULT, &def,
@@ -3636,7 +3636,7 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi)
 	 * of the user's groups, but FUSE only tells us about the primary
 	 * group.
 	 */
-	if (!is_superuser(ff, ctxt)) {
+	if (!fuse2fs_iomap_enabled(ff) && !is_superuser(ff, ctxt)) {
 		ret = in_file_group(ctxt, &inode);
 		if (ret < 0)
 			goto out;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 04/10] fuse2fs: better debugging for file mode updates
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:42   ` [PATCH 03/10] fuse2fs: let the kernel tell us about acl/mode updates Darrick J. Wong
@ 2026-02-23 23:42   ` Darrick J. Wong
  2026-02-23 23:42   ` [PATCH 05/10] fuse2fs: debug timestamp updates Darrick J. Wong
                     ` (5 subsequent siblings)
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:42 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Improve the tracing of a chmod operation so that we can debug file mode
updates.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   10 ++++++----
 misc/fuse2fs.c    |   12 +++++++-----
 2 files changed, 13 insertions(+), 9 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 2cbbd1ed19a00c..97747d42a64a52 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -3914,6 +3914,7 @@ static int fuse4fs_chmod(struct fuse4fs *ff, fuse_req_t req, ext2_ino_t ino,
 			 mode_t mode, struct ext2_inode_large *inode)
 {
 	const struct fuse_ctx *ctxt = fuse_req_ctx(req);
+	mode_t new_mode;
 	int ret = 0;
 
 	dbg_printf(ff, "%s: ino=%d mode=0%o\n", __func__, ino, mode);
@@ -3940,11 +3941,12 @@ static int fuse4fs_chmod(struct fuse4fs *ff, fuse_req_t req, ext2_ino_t ino,
 			mode &= ~S_ISGID;
 	}
 
-	inode->i_mode &= ~0xFFF;
-	inode->i_mode |= mode & 0xFFF;
+	new_mode = (inode->i_mode & ~0xFFF) | (mode & 0xFFF);
 
-	dbg_printf(ff, "%s: ino=%d new_mode=0%o\n",
-		   __func__, ino, inode->i_mode);
+	dbg_printf(ff, "%s: ino=%d old_mode=0%o new_mode=0%o\n",
+		   __func__, ino, inode->i_mode, new_mode);
+
+	inode->i_mode = new_mode;
 
 	return 0;
 }
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 503d3c1cba5fd4..90f537efe525ce 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -3607,6 +3607,7 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi)
 	errcode_t err;
 	ext2_ino_t ino;
 	struct ext2_inode_large inode;
+	mode_t new_mode;
 	int ret = 0;
 
 	FUSE2FS_CHECK_CONTEXT(ff);
@@ -3645,11 +3646,12 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi)
 			mode &= ~S_ISGID;
 	}
 
-	inode.i_mode &= ~0xFFF;
-	inode.i_mode |= mode & 0xFFF;
+	new_mode = (inode.i_mode & ~0xFFF) | (mode & 0xFFF);
 
-	dbg_printf(ff, "%s: path=%s new_mode=0%o ino=%d\n", __func__,
-		   path, inode.i_mode, ino);
+	dbg_printf(ff, "%s: path=%s old_mode=0%o new_mode=0%o ino=%d\n",
+		   __func__, path, inode.i_mode, new_mode, ino);
+
+	inode.i_mode = new_mode;
 
 	ret = update_ctime(fs, ino, &inode);
 	if (ret)
@@ -3669,12 +3671,12 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi)
 static int op_chown(const char *path, uid_t owner, gid_t group,
 		    struct fuse_file_info *fi)
 {
+	struct ext2_inode_large inode;
 	struct fuse_context *ctxt = fuse_get_context();
 	struct fuse2fs *ff = fuse2fs_get();
 	ext2_filsys fs;
 	errcode_t err;
 	ext2_ino_t ino;
-	struct ext2_inode_large inode;
 	int ret = 0;
 
 	FUSE2FS_CHECK_CONTEXT(ff);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 05/10] fuse2fs: debug timestamp updates
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:42   ` [PATCH 04/10] fuse2fs: better debugging for file mode updates Darrick J. Wong
@ 2026-02-23 23:42   ` Darrick J. Wong
  2026-02-23 23:42   ` [PATCH 06/10] fuse2fs: use coarse timestamps for iomap mode Darrick J. Wong
                     ` (4 subsequent siblings)
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:42 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Add tracing for timestamp updates to files.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |   97 +++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 61 insertions(+), 36 deletions(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 90f537efe525ce..21e27efb835659 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -864,7 +864,8 @@ static void increment_version(struct ext2_inode_large *inode)
 		inode->i_version_hi = ver >> 32;
 }
 
-static void init_times(struct ext2_inode_large *inode)
+static void fuse2fs_init_timestamps(struct fuse2fs *ff, ext2_ino_t ino,
+				    struct ext2_inode_large *inode)
 {
 	struct timespec now;
 
@@ -874,11 +875,15 @@ static void init_times(struct ext2_inode_large *inode)
 	EXT4_INODE_SET_XTIME(i_mtime, &now, inode);
 	EXT4_EINODE_SET_XTIME(i_crtime, &now, inode);
 	increment_version(inode);
+
+	dbg_printf(ff, "%s: ino=%u time %ld:%lu\n", __func__, ino, now.tv_sec,
+		   now.tv_nsec);
 }
 
-static int update_ctime(ext2_filsys fs, ext2_ino_t ino,
-			struct ext2_inode_large *pinode)
+static int fuse2fs_update_ctime(struct fuse2fs *ff, ext2_ino_t ino,
+				struct ext2_inode_large *pinode)
 {
+	ext2_filsys fs = ff->fs;
 	errcode_t err;
 	struct timespec now;
 	struct ext2_inode_large inode;
@@ -889,6 +894,10 @@ static int update_ctime(ext2_filsys fs, ext2_ino_t ino,
 	if (pinode) {
 		increment_version(pinode);
 		EXT4_INODE_SET_XTIME(i_ctime, &now, pinode);
+
+		dbg_printf(ff, "%s: ino=%u ctime %ld:%lu\n", __func__, ino,
+			   now.tv_sec, now.tv_nsec);
+
 		return 0;
 	}
 
@@ -900,6 +909,9 @@ static int update_ctime(ext2_filsys fs, ext2_ino_t ino,
 	increment_version(&inode);
 	EXT4_INODE_SET_XTIME(i_ctime, &now, &inode);
 
+	dbg_printf(ff, "%s: ino=%u ctime %ld:%lu\n", __func__, ino,
+		   now.tv_sec, now.tv_nsec);
+
 	err = fuse2fs_write_inode(fs, ino, &inode);
 	if (err)
 		return translate_error(fs, ino, err);
@@ -907,8 +919,9 @@ static int update_ctime(ext2_filsys fs, ext2_ino_t ino,
 	return 0;
 }
 
-static int update_atime(ext2_filsys fs, ext2_ino_t ino)
+static int fuse2fs_update_atime(struct fuse2fs *ff, ext2_ino_t ino)
 {
+	ext2_filsys fs = ff->fs;
 	errcode_t err;
 	struct ext2_inode_large inode, *pinode;
 	struct timespec atime, mtime, now;
@@ -927,6 +940,10 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)
 	dmtime = mtime.tv_sec + ((double)mtime.tv_nsec / NSEC_PER_SEC);
 	dnow = now.tv_sec + ((double)now.tv_nsec / NSEC_PER_SEC);
 
+	dbg_printf(ff, "%s: ino=%u atime %ld:%lu mtime %ld:%lu now %ld:%lu\n",
+		   __func__, ino, atime.tv_sec, atime.tv_nsec, mtime.tv_sec,
+		   mtime.tv_nsec, now.tv_sec, now.tv_nsec);
+
 	/*
 	 * If atime is newer than mtime and atime hasn't been updated in thirty
 	 * seconds, skip the atime update.  Same idea as Linux "relatime".  Use
@@ -943,9 +960,10 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)
 	return 0;
 }
 
-static int update_mtime(ext2_filsys fs, ext2_ino_t ino,
-			struct ext2_inode_large *pinode)
+static int fuse2fs_update_mtime(struct fuse2fs *ff, ext2_ino_t ino,
+				struct ext2_inode_large *pinode)
 {
+	ext2_filsys fs = ff->fs;
 	errcode_t err;
 	struct ext2_inode_large inode;
 	struct timespec now;
@@ -955,6 +973,10 @@ static int update_mtime(ext2_filsys fs, ext2_ino_t ino,
 		EXT4_INODE_SET_XTIME(i_mtime, &now, pinode);
 		EXT4_INODE_SET_XTIME(i_ctime, &now, pinode);
 		increment_version(pinode);
+
+		dbg_printf(ff, "%s: ino=%u mtime/ctime %ld:%lu\n",
+			   __func__, ino, now.tv_sec, now.tv_nsec);
+
 		return 0;
 	}
 
@@ -967,6 +989,9 @@ static int update_mtime(ext2_filsys fs, ext2_ino_t ino,
 	EXT4_INODE_SET_XTIME(i_ctime, &now, &inode);
 	increment_version(&inode);
 
+	dbg_printf(ff, "%s: ino=%u mtime/ctime %ld:%lu\n",
+		   __func__, ino, now.tv_sec, now.tv_nsec);
+
 	err = fuse2fs_write_inode(fs, ino, &inode);
 	if (err)
 		return translate_error(fs, ino, err);
@@ -2228,7 +2253,7 @@ static int op_readlink(const char *path, char *buf, size_t len)
 	buf[len] = 0;
 
 	if (fuse2fs_is_writeable(ff)) {
-		ret = update_atime(fs, ino);
+		ret = fuse2fs_update_atime(ff, ino);
 		if (ret)
 			goto out;
 	}
@@ -2502,7 +2527,7 @@ static int op_mknod(const char *path, mode_t mode, dev_t dev)
 		goto out2;
 	}
 
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse2fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out2;
 
@@ -2525,7 +2550,7 @@ static int op_mknod(const char *path, mode_t mode, dev_t dev)
 	}
 
 	inode.i_generation = ff->next_generation++;
-	init_times(&inode);
+	fuse2fs_init_timestamps(ff, child, &inode);
 	err = fuse2fs_write_inode(fs, child, &inode);
 	if (err) {
 		ret = translate_error(fs, child, err);
@@ -2611,7 +2636,7 @@ static int op_mkdir(const char *path, mode_t mode)
 		goto out2;
 	}
 
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse2fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out2;
 
@@ -2638,7 +2663,7 @@ static int op_mkdir(const char *path, mode_t mode)
 	if (parent_sgid)
 		inode.i_mode |= S_ISGID;
 	inode.i_generation = ff->next_generation++;
-	init_times(&inode);
+	fuse2fs_init_timestamps(ff, child, &inode);
 
 	err = fuse2fs_write_inode(fs, child, &inode);
 	if (err) {
@@ -2721,7 +2746,7 @@ static int fuse2fs_unlink(struct fuse2fs *ff, const char *path,
 	if (err)
 		return translate_error(fs, dir, err);
 
-	ret = update_mtime(fs, dir, NULL);
+	ret = fuse2fs_update_mtime(ff, dir, NULL);
 	if (ret)
 		return ret;
 
@@ -2812,7 +2837,7 @@ static int remove_inode(struct fuse2fs *ff, ext2_ino_t ino)
 			ext2fs_set_dtime(fs, EXT2_INODE(&inode));
 	}
 
-	ret = update_ctime(fs, ino, &inode);
+	ret = fuse2fs_update_ctime(ff, ino, &inode);
 	if (ret)
 		return ret;
 
@@ -2982,7 +3007,7 @@ static int __op_rmdir(struct fuse2fs *ff, const char *path)
 			goto out;
 		}
 		ext2fs_dec_nlink(EXT2_INODE(&inode));
-		ret = update_mtime(fs, rds.parent, &inode);
+		ret = fuse2fs_update_mtime(ff, rds.parent, &inode);
 		if (ret)
 			goto out;
 		err = fuse2fs_write_inode(fs, rds.parent, &inode);
@@ -3079,7 +3104,7 @@ static int op_symlink(const char *src, const char *dest)
 	}
 
 	/* Update parent dir's mtime */
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse2fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out2;
 
@@ -3103,7 +3128,7 @@ static int op_symlink(const char *src, const char *dest)
 	fuse2fs_set_uid(&inode, ctxt->uid);
 	fuse2fs_set_gid(&inode, gid);
 	inode.i_generation = ff->next_generation++;
-	init_times(&inode);
+	fuse2fs_init_timestamps(ff, child, &inode);
 
 	err = fuse2fs_write_inode(fs, child, &inode);
 	if (err) {
@@ -3388,11 +3413,11 @@ static int op_rename(const char *from, const char *to,
 	}
 
 	/* Update timestamps */
-	ret = update_ctime(fs, from_ino, NULL);
+	ret = fuse2fs_update_ctime(ff, from_ino, NULL);
 	if (ret)
 		goto out2;
 
-	ret = update_mtime(fs, to_dir_ino, NULL);
+	ret = fuse2fs_update_mtime(ff, to_dir_ino, NULL);
 	if (ret)
 		goto out2;
 
@@ -3486,7 +3511,7 @@ static int op_link(const char *src, const char *dest)
 	}
 
 	ext2fs_inc_nlink(fs, EXT2_INODE(&inode));
-	ret = update_ctime(fs, ino, &inode);
+	ret = fuse2fs_update_ctime(ff, ino, &inode);
 	if (ret)
 		goto out2;
 
@@ -3505,7 +3530,7 @@ static int op_link(const char *src, const char *dest)
 		goto out2;
 	}
 
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse2fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out2;
 
@@ -3653,7 +3678,7 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi)
 
 	inode.i_mode = new_mode;
 
-	ret = update_ctime(fs, ino, &inode);
+	ret = fuse2fs_update_ctime(ff, ino, &inode);
 	if (ret)
 		goto out;
 
@@ -3720,7 +3745,7 @@ static int op_chown(const char *path, uid_t owner, gid_t group,
 		fuse2fs_set_gid(&inode, group);
 	}
 
-	ret = update_ctime(fs, ino, &inode);
+	ret = fuse2fs_update_ctime(ff, ino, &inode);
 	if (ret)
 		goto out;
 
@@ -3850,7 +3875,7 @@ static int fuse2fs_truncate(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size)
 	if (err)
 		return translate_error(fs, ino, err);
 
-	ret = update_mtime(fs, ino, NULL);
+	ret = fuse2fs_update_mtime(ff, ino, NULL);
 	if (ret)
 		return ret;
 
@@ -4085,7 +4110,7 @@ static int op_read(const char *path EXT2FS_ATTR((unused)), char *buf,
 	}
 
 	if (fh->check_flags != X_OK && fuse2fs_is_writeable(ff)) {
-		ret = update_atime(fs, fh->ino);
+		ret = fuse2fs_update_atime(ff, fh->ino);
 		if (ret)
 			goto out;
 	}
@@ -4169,7 +4194,7 @@ static int op_write(const char *path EXT2FS_ATTR((unused)),
 		goto out;
 	}
 
-	ret = update_mtime(fs, fh->ino, NULL);
+	ret = fuse2fs_update_mtime(ff, fh->ino, NULL);
 	if (ret)
 		goto out;
 
@@ -4531,7 +4556,7 @@ static int op_setxattr(const char *path EXT2FS_ATTR((unused)),
 		goto out2;
 	}
 
-	ret = update_ctime(fs, ino, NULL);
+	ret = fuse2fs_update_ctime(ff, ino, NULL);
 out2:
 	err = ext2fs_xattrs_close(&h);
 	if (!ret && err)
@@ -4625,7 +4650,7 @@ static int op_removexattr(const char *path, const char *key)
 		goto out2;
 	}
 
-	ret = update_ctime(fs, ino, NULL);
+	ret = fuse2fs_update_ctime(ff, ino, NULL);
 out2:
 	err = ext2fs_xattrs_close(&h);
 	if (err && !ret)
@@ -4743,7 +4768,7 @@ static int op_readdir(const char *path EXT2FS_ATTR((unused)), void *buf,
 	}
 
 	if (fuse2fs_is_writeable(ff)) {
-		ret = update_atime(i.fs, fh->ino);
+		ret = fuse2fs_update_atime(ff, fh->ino);
 		if (ret)
 			goto out;
 	}
@@ -4848,7 +4873,7 @@ static int op_create(const char *path, mode_t mode, struct fuse_file_info *fp)
 		goto out2;
 	}
 
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse2fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out2;
 
@@ -4879,7 +4904,7 @@ static int op_create(const char *path, mode_t mode, struct fuse_file_info *fp)
 	}
 
 	inode.i_generation = ff->next_generation++;
-	init_times(&inode);
+	fuse2fs_init_timestamps(ff, child, &inode);
 	err = fuse2fs_write_inode(fs, child, &inode);
 	if (err) {
 		ret = translate_error(fs, child, err);
@@ -4963,7 +4988,7 @@ static int op_utimens(const char *path, const struct timespec ctv[2],
 	if (tv[1].tv_nsec != UTIME_OMIT)
 		EXT4_INODE_SET_XTIME(i_mtime, &tv[1], &inode);
 #endif /* UTIME_OMIT */
-	ret = update_ctime(fs, ino, &inode);
+	ret = fuse2fs_update_ctime(ff, ino, &inode);
 	if (ret)
 		goto out;
 
@@ -5031,7 +5056,7 @@ static int ioctl_setflags(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
 	if (ret)
 		return ret;
 
-	ret = update_ctime(fs, fh->ino, &inode);
+	ret = fuse2fs_update_ctime(ff, fh->ino, &inode);
 	if (ret)
 		return ret;
 
@@ -5078,7 +5103,7 @@ static int ioctl_setversion(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
 
 	inode.i_generation = generation;
 
-	ret = update_ctime(fs, fh->ino, &inode);
+	ret = fuse2fs_update_ctime(ff, fh->ino, &inode);
 	if (ret)
 		return ret;
 
@@ -5209,7 +5234,7 @@ static int ioctl_fssetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
 	if (ext2fs_inode_includes(inode_size, i_projid))
 		inode.i_projid = fsx->fsx_projid;
 
-	ret = update_ctime(fs, fh->ino, &inode);
+	ret = fuse2fs_update_ctime(ff, fh->ino, &inode);
 	if (ret)
 		return ret;
 
@@ -5481,7 +5506,7 @@ static int fuse2fs_allocate_range(struct fuse2fs *ff,
 		}
 	}
 
-	err = update_mtime(fs, fh->ino, &inode);
+	err = fuse2fs_update_mtime(ff, fh->ino, &inode);
 	if (err)
 		return err;
 
@@ -5654,7 +5679,7 @@ static int fuse2fs_punch_range(struct fuse2fs *ff,
 			return translate_error(fs, fh->ino, err);
 	}
 
-	err = update_mtime(fs, fh->ino, &inode);
+	err = fuse2fs_update_mtime(ff, fh->ino, &inode);
 	if (err)
 		return err;
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 06/10] fuse2fs: use coarse timestamps for iomap mode
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (4 preceding siblings ...)
  2026-02-23 23:42   ` [PATCH 05/10] fuse2fs: debug timestamp updates Darrick J. Wong
@ 2026-02-23 23:42   ` Darrick J. Wong
  2026-02-23 23:43   ` [PATCH 07/10] fuse2fs: add tracing for retrieving timestamps Darrick J. Wong
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:42 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

In iomap mode, the kernel is responsible for maintaining timestamps
because file writes don't upcall to fuse2fs.  The kernel's predicate for
deciding if [cm]time should be updated bases its decisions off [cm]time
being an exact match for the coarse clock (instead of checking that
[cm]time < coarse_clock) which means that fuse2fs setting a fine-grained
timestamp that is slightly ahead of the coarse clock can result in
timestamps appearing to go backwards.  generic/423 doesn't like seeing
btime > ctime from statx, so we'll use the coarse clock in iomap mode.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |  110 +++++++++++++++++++++++++++++++----------------------
 misc/fuse2fs.c    |   34 ++++++++++++----
 2 files changed, 90 insertions(+), 54 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 97747d42a64a52..6cda267ad5cf40 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -1004,8 +1004,24 @@ static inline void fuse4fs_dump_extents(struct fuse4fs *ff, ext2_ino_t ino,
 	ext2fs_extent_free(extents);
 }
 
-static void get_now(struct timespec *now)
+static void fuse4fs_get_now(struct fuse4fs *ff, struct timespec *now)
 {
+#ifdef CLOCK_REALTIME_COARSE
+	/*
+	 * In iomap mode, the kernel is responsible for maintaining timestamps
+	 * because file writes don't upcall to fuse4fs.  The kernel's predicate
+	 * for deciding if [cm]time should be updated bases its decisions off
+	 * [cm]time being an exact match for the coarse clock (instead of
+	 * checking that [cm]time < coarse_clock) which means that fuse4fs
+	 * setting a fine-grained timestamp that is slightly ahead of the
+	 * coarse clock can result in timestamps appearing to go backwards.
+	 * generic/423 doesn't like seeing btime > ctime from statx, so we'll
+	 * use the coarse clock in iomap mode.
+	 */
+	if (fuse4fs_iomap_enabled(ff) &&
+	    !clock_gettime(CLOCK_REALTIME_COARSE, now))
+		return;
+#endif
 #ifdef CLOCK_REALTIME
 	if (!clock_gettime(CLOCK_REALTIME, now))
 		return;
@@ -1028,11 +1044,12 @@ static void increment_version(struct ext2_inode_large *inode)
 		inode->i_version_hi = ver >> 32;
 }
 
-static void init_times(struct ext2_inode_large *inode)
+static void fuse4fs_init_timestamps(struct fuse4fs *ff,
+				    struct ext2_inode_large *inode)
 {
 	struct timespec now;
 
-	get_now(&now);
+	fuse4fs_get_now(ff, &now);
 	EXT4_INODE_SET_XTIME(i_atime, &now, inode);
 	EXT4_INODE_SET_XTIME(i_ctime, &now, inode);
 	EXT4_INODE_SET_XTIME(i_mtime, &now, inode);
@@ -1040,14 +1057,15 @@ static void init_times(struct ext2_inode_large *inode)
 	increment_version(inode);
 }
 
-static int update_ctime(ext2_filsys fs, ext2_ino_t ino,
-			struct ext2_inode_large *pinode)
+static int fuse4fs_update_ctime(struct fuse4fs *ff, ext2_ino_t ino,
+				struct ext2_inode_large *pinode)
 {
-	errcode_t err;
 	struct timespec now;
 	struct ext2_inode_large inode;
+	ext2_filsys fs = ff->fs;
+	errcode_t err;
 
-	get_now(&now);
+	fuse4fs_get_now(ff, &now);
 
 	/* If user already has a inode buffer, just update that */
 	if (pinode) {
@@ -1071,12 +1089,13 @@ static int update_ctime(ext2_filsys fs, ext2_ino_t ino,
 	return 0;
 }
 
-static int update_atime(ext2_filsys fs, ext2_ino_t ino)
+static int fuse4fs_update_atime(struct fuse4fs *ff, ext2_ino_t ino)
 {
-	errcode_t err;
 	struct ext2_inode_large inode, *pinode;
 	struct timespec atime, mtime, now;
+	ext2_filsys fs = ff->fs;
 	double datime, dmtime, dnow;
+	errcode_t err;
 
 	err = fuse4fs_read_inode(fs, ino, &inode);
 	if (err)
@@ -1085,7 +1104,7 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)
 	pinode = &inode;
 	EXT4_INODE_GET_XTIME(i_atime, &atime, pinode);
 	EXT4_INODE_GET_XTIME(i_mtime, &mtime, pinode);
-	get_now(&now);
+	fuse4fs_get_now(ff, &now);
 
 	datime = atime.tv_sec + ((double)atime.tv_nsec / NSEC_PER_SEC);
 	dmtime = mtime.tv_sec + ((double)mtime.tv_nsec / NSEC_PER_SEC);
@@ -1107,15 +1126,16 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)
 	return 0;
 }
 
-static int update_mtime(ext2_filsys fs, ext2_ino_t ino,
-			struct ext2_inode_large *pinode)
+static int fuse4fs_update_mtime(struct fuse4fs *ff, ext2_ino_t ino,
+				struct ext2_inode_large *pinode)
 {
-	errcode_t err;
 	struct ext2_inode_large inode;
 	struct timespec now;
+	ext2_filsys fs = ff->fs;
+	errcode_t err;
 
 	if (pinode) {
-		get_now(&now);
+		fuse4fs_get_now(ff, &now);
 		EXT4_INODE_SET_XTIME(i_mtime, &now, pinode);
 		EXT4_INODE_SET_XTIME(i_ctime, &now, pinode);
 		increment_version(pinode);
@@ -1126,7 +1146,7 @@ static int update_mtime(ext2_filsys fs, ext2_ino_t ino,
 	if (err)
 		return translate_error(fs, ino, err);
 
-	get_now(&now);
+	fuse4fs_get_now(ff, &now);
 	EXT4_INODE_SET_XTIME(i_mtime, &now, &inode);
 	EXT4_INODE_SET_XTIME(i_ctime, &now, &inode);
 	increment_version(&inode);
@@ -2422,7 +2442,7 @@ static void op_readlink(fuse_req_t req, fuse_ino_t fino)
 	buf[len] = 0;
 
 	if (fuse4fs_is_writeable(ff)) {
-		ret = update_atime(fs, ino);
+		ret = fuse4fs_update_atime(ff, ino);
 		if (ret)
 			goto out;
 	}
@@ -2691,7 +2711,7 @@ static void op_mknod(fuse_req_t req, fuse_ino_t fino, const char *name,
 		goto out2;
 	}
 
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse4fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out2;
 
@@ -2714,7 +2734,7 @@ static void op_mknod(fuse_req_t req, fuse_ino_t fino, const char *name,
 	}
 
 	inode.i_generation = ff->next_generation++;
-	init_times(&inode);
+	fuse4fs_init_timestamps(ff, &inode);
 	err = fuse4fs_write_inode(fs, child, &inode);
 	if (err) {
 		ret = translate_error(fs, child, err);
@@ -2776,7 +2796,7 @@ static void op_mkdir(fuse_req_t req, fuse_ino_t fino, const char *name,
 		goto out2;
 	}
 
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse4fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out2;
 
@@ -2802,7 +2822,7 @@ static void op_mkdir(fuse_req_t req, fuse_ino_t fino, const char *name,
 	if (parent_sgid)
 		inode.i_mode |= S_ISGID;
 	inode.i_generation = ff->next_generation++;
-	init_times(&inode);
+	fuse4fs_init_timestamps(ff, &inode);
 
 	err = fuse4fs_write_inode(fs, child, &inode);
 	if (err) {
@@ -3153,7 +3173,7 @@ static int fuse4fs_remove_inode(struct fuse4fs *ff, ext2_ino_t ino)
 		inode.i_links_count--;
 	}
 
-	ret = update_ctime(fs, ino, &inode);
+	ret = fuse4fs_update_ctime(ff, ino, &inode);
 	if (ret)
 		return ret;
 
@@ -3225,7 +3245,7 @@ static int fuse4fs_unlink(struct fuse4fs *ff, ext2_ino_t parent,
 		goto out;
 	}
 
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse4fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out;
 out:
@@ -3359,7 +3379,7 @@ static int fuse4fs_rmdir(struct fuse4fs *ff, ext2_ino_t parent,
 			goto out;
 		}
 		ext2fs_dec_nlink(EXT2_INODE(&inode));
-		ret = update_mtime(fs, rds.parent, &inode);
+		ret = fuse4fs_update_mtime(ff, rds.parent, &inode);
 		if (ret)
 			goto out;
 		err = fuse4fs_write_inode(fs, rds.parent, &inode);
@@ -3463,7 +3483,7 @@ static void op_symlink(fuse_req_t req, const char *target, fuse_ino_t fino,
 	}
 
 	/* Update parent dir's mtime */
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse4fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out2;
 
@@ -3486,7 +3506,7 @@ static void op_symlink(fuse_req_t req, const char *target, fuse_ino_t fino,
 	fuse4fs_set_uid(&inode, ctxt->uid);
 	fuse4fs_set_gid(&inode, gid);
 	inode.i_generation = ff->next_generation++;
-	init_times(&inode);
+	fuse4fs_init_timestamps(ff, &inode);
 
 	err = fuse4fs_write_inode(fs, child, &inode);
 	if (err) {
@@ -3717,11 +3737,11 @@ static void op_rename(fuse_req_t req, fuse_ino_t from_parent, const char *from,
 	}
 
 	/* Update timestamps */
-	ret = update_ctime(fs, from_ino, NULL);
+	ret = fuse4fs_update_ctime(ff, from_ino, NULL);
 	if (ret)
 		goto out;
 
-	ret = update_mtime(fs, to_dir_ino, NULL);
+	ret = fuse4fs_update_mtime(ff, to_dir_ino, NULL);
 	if (ret)
 		goto out;
 
@@ -3800,7 +3820,7 @@ static void op_link(fuse_req_t req, fuse_ino_t child_fino,
 	}
 
 	ext2fs_inc_nlink(fs, EXT2_INODE(&inode));
-	ret = update_ctime(fs, child, &inode);
+	ret = fuse4fs_update_ctime(ff, child, &inode);
 	if (ret)
 		goto out2;
 
@@ -3817,7 +3837,7 @@ static void op_link(fuse_req_t req, fuse_ino_t child_fino,
 		goto out2;
 	}
 
-	ret = update_mtime(fs, parent, NULL);
+	ret = fuse4fs_update_mtime(ff, parent, NULL);
 	if (ret)
 		goto out2;
 
@@ -4053,7 +4073,7 @@ static int fuse4fs_truncate(struct fuse4fs *ff, ext2_ino_t ino, off_t new_size)
 	if (err)
 		return translate_error(fs, ino, err);
 
-	ret = update_mtime(fs, ino, NULL);
+	ret = fuse4fs_update_mtime(ff, ino, NULL);
 	if (ret)
 		return ret;
 
@@ -4262,7 +4282,7 @@ static void op_read(fuse_req_t req, fuse_ino_t fino EXT2FS_ATTR((unused)),
 	}
 
 	if (fh->check_flags != X_OK && fuse4fs_is_writeable(ff)) {
-		ret = update_atime(fs, fh->ino);
+		ret = fuse4fs_update_atime(ff, fh->ino);
 		if (ret)
 			goto out;
 	}
@@ -4336,7 +4356,7 @@ static void op_write(fuse_req_t req, fuse_ino_t fino EXT2FS_ATTR((unused)),
 		goto out;
 	}
 
-	ret = update_mtime(fs, fh->ino, NULL);
+	ret = fuse4fs_update_mtime(ff, fh->ino, NULL);
 	if (ret)
 		goto out;
 
@@ -4783,7 +4803,7 @@ static void op_setxattr(fuse_req_t req, fuse_ino_t fino, const char *key,
 		goto out2;
 	}
 
-	ret = update_ctime(fs, ino, NULL);
+	ret = fuse4fs_update_ctime(ff, ino, NULL);
 out2:
 	err = ext2fs_xattrs_close(&h);
 	if (!ret && err)
@@ -4877,7 +4897,7 @@ static void op_removexattr(fuse_req_t req, fuse_ino_t fino, const char *key)
 		goto out2;
 	}
 
-	ret = update_ctime(fs, ino, NULL);
+	ret = fuse4fs_update_ctime(ff, ino, NULL);
 out2:
 	err = ext2fs_xattrs_close(&h);
 	if (err && !ret)
@@ -5024,7 +5044,7 @@ static void __op_readdir(fuse_req_t req, fuse_ino_t fino, size_t size,
 	}
 
 	if (fuse4fs_is_writeable(ff)) {
-		ret = update_atime(i.fs, fh->ino);
+		ret = fuse4fs_update_atime(i.ff, fh->ino);
 		if (ret)
 			goto out;
 	}
@@ -5124,7 +5144,7 @@ static void op_create(fuse_req_t req, fuse_ino_t fino, const char *name,
 			goto out2;
 		}
 
-		ret = update_mtime(fs, parent, NULL);
+		ret = fuse4fs_update_mtime(ff, parent, NULL);
 		if (ret)
 			goto out2;
 	} else {
@@ -5165,7 +5185,7 @@ static void op_create(fuse_req_t req, fuse_ino_t fino, const char *name,
 	}
 
 	inode.i_generation = ff->next_generation++;
-	init_times(&inode);
+	fuse4fs_init_timestamps(ff, &inode);
 	err = fuse4fs_write_inode(fs, child, &inode);
 	if (err) {
 		ret = translate_error(fs, child, err);
@@ -5244,7 +5264,7 @@ static int fuse4fs_utimens(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 	int ret = 0;
 
 	if (to_set & (FUSE_SET_ATTR_ATIME_NOW | FUSE_SET_ATTR_MTIME_NOW))
-		get_now(&now);
+		fuse4fs_get_now(ff, &now);
 
 	if (to_set & FUSE_SET_ATTR_ATIME_NOW) {
 		atime = now;
@@ -5382,7 +5402,7 @@ static void op_setattr(fuse_req_t req, fuse_ino_t fino, struct stat *attr,
 	}
 
 	/* Update ctime for any attribute change */
-	ret = update_ctime(fs, ino, &inode);
+	ret = fuse4fs_update_ctime(ff, ino, &inode);
 	if (ret)
 		goto out;
 
@@ -5464,7 +5484,7 @@ static int ioctl_setflags(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 	if (ret)
 		return ret;
 
-	ret = update_ctime(fs, fh->ino, &inode);
+	ret = fuse4fs_update_ctime(ff, fh->ino, &inode);
 	if (ret)
 		return ret;
 
@@ -5517,7 +5537,7 @@ static int ioctl_setversion(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 
 	inode.i_generation = *indata;
 
-	ret = update_ctime(fs, fh->ino, &inode);
+	ret = fuse4fs_update_ctime(ff, fh->ino, &inode);
 	if (ret)
 		return ret;
 
@@ -5653,7 +5673,7 @@ static int ioctl_fssetxattr(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 	if (ext2fs_inode_includes(inode_size, i_projid))
 		inode.i_projid = fsx->fsx_projid;
 
-	ret = update_ctime(fs, fh->ino, &inode);
+	ret = fuse4fs_update_ctime(ff, fh->ino, &inode);
 	if (ret)
 		return ret;
 
@@ -5949,7 +5969,7 @@ static int fuse4fs_allocate_range(struct fuse4fs *ff,
 		}
 	}
 
-	err = update_mtime(fs, fh->ino, &inode);
+	err = fuse4fs_update_mtime(ff, fh->ino, &inode);
 	if (err)
 		return err;
 
@@ -6122,7 +6142,7 @@ static int fuse4fs_punch_range(struct fuse4fs *ff,
 			return translate_error(fs, fh->ino, err);
 	}
 
-	err = update_mtime(fs, fh->ino, &inode);
+	err = fuse4fs_update_mtime(ff, fh->ino, &inode);
 	if (err)
 		return err;
 
@@ -8329,7 +8349,7 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
 			error_message(err), func, line);
 
 	/* Make a note in the error log */
-	get_now(&now);
+	fuse4fs_get_now(ff, &now);
 	ext2fs_set_tstamp(fs->super, s_last_error_time, now.tv_sec);
 	fs->super->s_last_error_ino = ino;
 	fs->super->s_last_error_line = line;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 21e27efb835659..9b536fe77dda37 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -840,8 +840,24 @@ static inline void fuse2fs_dump_extents(struct fuse2fs *ff, ext2_ino_t ino,
 	ext2fs_extent_free(extents);
 }
 
-static void get_now(struct timespec *now)
+static void fuse2fs_get_now(struct fuse2fs *ff, struct timespec *now)
 {
+#ifdef CLOCK_REALTIME_COARSE
+	/*
+	 * In iomap mode, the kernel is responsible for maintaining timestamps
+	 * because file writes don't upcall to fuse2fs.  The kernel's predicate
+	 * for deciding if [cm]time should be updated bases its decisions off
+	 * [cm]time being an exact match for the coarse clock (instead of
+	 * checking that [cm]time < coarse_clock) which means that fuse2fs
+	 * setting a fine-grained timestamp that is slightly ahead of the
+	 * coarse clock can result in timestamps appearing to go backwards.
+	 * generic/423 doesn't like seeing btime > ctime from statx, so we'll
+	 * use the coarse clock in iomap mode.
+	 */
+	if (fuse2fs_iomap_enabled(ff) &&
+	    !clock_gettime(CLOCK_REALTIME_COARSE, now))
+		return;
+#endif
 #ifdef CLOCK_REALTIME
 	if (!clock_gettime(CLOCK_REALTIME, now))
 		return;
@@ -869,7 +885,7 @@ static void fuse2fs_init_timestamps(struct fuse2fs *ff, ext2_ino_t ino,
 {
 	struct timespec now;
 
-	get_now(&now);
+	fuse2fs_get_now(ff, &now);
 	EXT4_INODE_SET_XTIME(i_atime, &now, inode);
 	EXT4_INODE_SET_XTIME(i_ctime, &now, inode);
 	EXT4_INODE_SET_XTIME(i_mtime, &now, inode);
@@ -888,7 +904,7 @@ static int fuse2fs_update_ctime(struct fuse2fs *ff, ext2_ino_t ino,
 	struct timespec now;
 	struct ext2_inode_large inode;
 
-	get_now(&now);
+	fuse2fs_get_now(ff, &now);
 
 	/* If user already has a inode buffer, just update that */
 	if (pinode) {
@@ -934,7 +950,7 @@ static int fuse2fs_update_atime(struct fuse2fs *ff, ext2_ino_t ino)
 	pinode = &inode;
 	EXT4_INODE_GET_XTIME(i_atime, &atime, pinode);
 	EXT4_INODE_GET_XTIME(i_mtime, &mtime, pinode);
-	get_now(&now);
+	fuse2fs_get_now(ff, &now);
 
 	datime = atime.tv_sec + ((double)atime.tv_nsec / NSEC_PER_SEC);
 	dmtime = mtime.tv_sec + ((double)mtime.tv_nsec / NSEC_PER_SEC);
@@ -969,7 +985,7 @@ static int fuse2fs_update_mtime(struct fuse2fs *ff, ext2_ino_t ino,
 	struct timespec now;
 
 	if (pinode) {
-		get_now(&now);
+		fuse2fs_get_now(ff, &now);
 		EXT4_INODE_SET_XTIME(i_mtime, &now, pinode);
 		EXT4_INODE_SET_XTIME(i_ctime, &now, pinode);
 		increment_version(pinode);
@@ -984,7 +1000,7 @@ static int fuse2fs_update_mtime(struct fuse2fs *ff, ext2_ino_t ino,
 	if (err)
 		return translate_error(fs, ino, err);
 
-	get_now(&now);
+	fuse2fs_get_now(ff, &now);
 	EXT4_INODE_SET_XTIME(i_mtime, &now, &inode);
 	EXT4_INODE_SET_XTIME(i_ctime, &now, &inode);
 	increment_version(&inode);
@@ -4978,9 +4994,9 @@ static int op_utimens(const char *path, const struct timespec ctv[2],
 	tv[1] = ctv[1];
 #ifdef UTIME_NOW
 	if (tv[0].tv_nsec == UTIME_NOW)
-		get_now(tv);
+		fuse2fs_get_now(ff, tv);
 	if (tv[1].tv_nsec == UTIME_NOW)
-		get_now(tv + 1);
+		fuse2fs_get_now(ff, tv + 1);
 #endif /* UTIME_NOW */
 #ifdef UTIME_OMIT
 	if (tv[0].tv_nsec != UTIME_OMIT)
@@ -7736,7 +7752,7 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
 			error_message(err), func, line);
 
 	/* Make a note in the error log */
-	get_now(&now);
+	fuse2fs_get_now(ff, &now);
 	ext2fs_set_tstamp(fs->super, s_last_error_time, now.tv_sec);
 	fs->super->s_last_error_ino = ino;
 	fs->super->s_last_error_line = line;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 07/10] fuse2fs: add tracing for retrieving timestamps
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (5 preceding siblings ...)
  2026-02-23 23:42   ` [PATCH 06/10] fuse2fs: use coarse timestamps for iomap mode Darrick J. Wong
@ 2026-02-23 23:43   ` Darrick J. Wong
  2026-02-23 23:43   ` [PATCH 08/10] fuse2fs: enable syncfs Darrick J. Wong
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:43 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Add tracing for retrieving timestamps so we can debug the weird
behavior.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 9b536fe77dda37..b11ffec3603bf9 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1946,9 +1946,11 @@ static void *op_init(struct fuse_conn_info *conn,
 	return ff;
 }
 
-static int stat_inode(ext2_filsys fs, ext2_ino_t ino, struct stat *statbuf)
+static int fuse2fs_stat(struct fuse2fs *ff, ext2_ino_t ino,
+			struct stat *statbuf)
 {
 	struct ext2_inode_large inode;
+	ext2_filsys fs = ff->fs;
 	dev_t fakedev = 0;
 	errcode_t err;
 	int ret = 0;
@@ -1987,6 +1989,13 @@ static int stat_inode(ext2_filsys fs, ext2_ino_t ino, struct stat *statbuf)
 #else
 	statbuf->st_ctime = tv.tv_sec;
 #endif
+
+	dbg_printf(ff, "%s: ino=%d atime=%lld.%ld mtime=%lld.%ld ctime=%lld.%ld\n",
+		   __func__, ino,
+		   (long long int)statbuf->st_atim.tv_sec, statbuf->st_atim.tv_nsec,
+		   (long long int)statbuf->st_mtim.tv_sec, statbuf->st_mtim.tv_nsec,
+		   (long long int)statbuf->st_ctim.tv_sec, statbuf->st_ctim.tv_nsec);
+
 	if (LINUX_S_ISCHR(inode.i_mode) ||
 	    LINUX_S_ISBLK(inode.i_mode)) {
 		if (inode.i_block[0])
@@ -2033,16 +2042,15 @@ static int op_getattr(const char *path, struct stat *statbuf,
 		      struct fuse_file_info *fi)
 {
 	struct fuse2fs *ff = fuse2fs_get();
-	ext2_filsys fs;
 	ext2_ino_t ino;
 	int ret = 0;
 
 	FUSE2FS_CHECK_CONTEXT(ff);
-	fs = fuse2fs_start(ff);
+	fuse2fs_start(ff);
 	ret = fuse2fs_file_ino(ff, path, fi, &ino);
 	if (ret)
 		goto out;
-	ret = stat_inode(fs, ino, statbuf);
+	ret = fuse2fs_stat(ff, ino, statbuf);
 out:
 	fuse2fs_finish(ff, ret);
 	return ret;
@@ -3832,7 +3840,7 @@ static int fuse2fs_file_uses_iomap(struct fuse2fs *ff, ext2_ino_t ino)
 	if (!fuse2fs_iomap_enabled(ff))
 		return 0;
 
-	ret = stat_inode(ff->fs, ino, &statbuf);
+	ret = fuse2fs_stat(ff, ino, &statbuf);
 	if (ret)
 		return ret;
 
@@ -4741,7 +4749,7 @@ static int op_readdir_iter(ext2_ino_t dir EXT2FS_ATTR((unused)),
 			(unsigned long long)i->dirpos);
 
 	if (i->flags == FUSE_READDIR_PLUS) {
-		ret = stat_inode(i->fs, dirent->inode, &stat);
+		ret = fuse2fs_stat(i->ff, dirent->inode, &stat);
 		if (ret)
 			return DIRENT_ABORT;
 	}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 08/10] fuse2fs: enable syncfs
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (6 preceding siblings ...)
  2026-02-23 23:43   ` [PATCH 07/10] fuse2fs: add tracing for retrieving timestamps Darrick J. Wong
@ 2026-02-23 23:43   ` Darrick J. Wong
  2026-02-23 23:43   ` [PATCH 09/10] fuse2fs: set sync, immutable, and append at file load time Darrick J. Wong
  2026-02-23 23:43   ` [PATCH 10/10] fuse4fs: increase attribute timeout in iomap mode Darrick J. Wong
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:43 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Enable syncfs calls in fuse2fs.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   32 ++++++++++++++++++++++++++++++++
 misc/fuse2fs.c    |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 6cda267ad5cf40..3d48eb79948ad3 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -6284,7 +6284,38 @@ static void op_shutdownfs(fuse_req_t req, fuse_ino_t ino, uint64_t flags)
 	int ret;
 
 	ret = ioctl_shutdown(ff, ctxt, NULL, NULL, 0);
+	fuse_reply_err(req, -ret);
+}
 
+static void op_syncfs(fuse_req_t req, fuse_ino_t ino)
+{
+	struct fuse4fs *ff = fuse4fs_get(req);
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	FUSE4FS_CHECK_CONTEXT(req);
+	fs = fuse4fs_start(ff);
+
+	if (ff->opstate == F4OP_WRITABLE) {
+		if (fs->super->s_error_count)
+			fs->super->s_state |= EXT2_ERROR_FS;
+		ext2fs_mark_super_dirty(fs);
+		err = ext2fs_set_gdt_csum(fs);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		err = ext2fs_flush2(fs, 0);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+	}
+
+out_unlock:
+	fuse4fs_finish(ff, ret);
 	fuse_reply_err(req, -ret);
 }
 #endif
@@ -7588,6 +7619,7 @@ static struct fuse_lowlevel_ops fs_ops = {
 	.freezefs = op_freezefs,
 	.unfreezefs = op_unfreezefs,
 	.shutdownfs = op_shutdownfs,
+	.syncfs = op_syncfs,
 #endif
 #ifdef HAVE_FUSE_IOMAP
 	.iomap_begin = op_iomap_begin,
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index b11ffec3603bf9..f7c759ed86c7fb 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -5842,6 +5842,39 @@ static int op_shutdownfs(const char *path, uint64_t flags)
 
 	return ioctl_shutdown(ff, NULL, NULL);
 }
+
+static int op_syncfs(const char *path)
+{
+	struct fuse2fs *ff = fuse2fs_get();
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	FUSE2FS_CHECK_CONTEXT(ff);
+	dbg_printf(ff, "%s: path=%s\n", __func__, path);
+	fs = fuse2fs_start(ff);
+
+	if (ff->opstate == F2OP_WRITABLE) {
+		if (fs->super->s_error_count)
+			fs->super->s_state |= EXT2_ERROR_FS;
+		ext2fs_mark_super_dirty(fs);
+		err = ext2fs_set_gdt_csum(fs);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+
+		err = ext2fs_flush2(fs, 0);
+		if (err) {
+			ret = translate_error(fs, 0, err);
+			goto out_unlock;
+		}
+	}
+
+out_unlock:
+	fuse2fs_finish(ff, ret);
+	return ret;
+}
 #endif
 
 #ifdef HAVE_FUSE_IOMAP
@@ -7131,6 +7164,7 @@ static struct fuse_operations fs_ops = {
 	.freezefs = op_freezefs,
 	.unfreezefs = op_unfreezefs,
 	.shutdownfs = op_shutdownfs,
+	.syncfs = op_syncfs,
 #endif
 #ifdef HAVE_FUSE_IOMAP
 	.iomap_begin = op_iomap_begin,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 09/10] fuse2fs: set sync, immutable, and append at file load time
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (7 preceding siblings ...)
  2026-02-23 23:43   ` [PATCH 08/10] fuse2fs: enable syncfs Darrick J. Wong
@ 2026-02-23 23:43   ` Darrick J. Wong
  2026-02-23 23:43   ` [PATCH 10/10] fuse4fs: increase attribute timeout in iomap mode Darrick J. Wong
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:43 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Convey these three inode flags to the kernel when we're loading a file.
This way the kernel can advertise and enforce those flags so that the
fuse server doesn't have to.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   16 ++++++++++++++++
 misc/fuse2fs.c    |   53 ++++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 54 insertions(+), 15 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 3d48eb79948ad3..8ba904ec2fc9d9 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -2162,6 +2162,22 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino,
 	entry->entry_timeout = FUSE4FS_ATTR_TIMEOUT;
 
 	fstat->iflags = 0;
+
+#ifdef FUSE_IFLAG_SYNC
+	if (inodep->i_flags & EXT2_SYNC_FL)
+		fstat->iflags |= FUSE_IFLAG_SYNC;
+#endif
+
+#ifdef FUSE_IFLAG_IMMUTABLE
+	if (inodep->i_flags & EXT2_IMMUTABLE_FL)
+		fstat->iflags |= FUSE_IFLAG_IMMUTABLE;
+#endif
+
+#ifdef FUSE_IFLAG_APPEND
+	if (inodep->i_flags & EXT2_APPEND_FL)
+		fstat->iflags |= FUSE_IFLAG_APPEND;
+#endif
+
 #ifdef HAVE_FUSE_IOMAP
 	if (fuse4fs_iomap_enabled(ff)) {
 		fstat->iflags |= FUSE_IFLAG_IOMAP | FUSE_IFLAG_EXCLUSIVE;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index f7c759ed86c7fb..58ea8e1f2f1e51 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1947,7 +1947,7 @@ static void *op_init(struct fuse_conn_info *conn,
 }
 
 static int fuse2fs_stat(struct fuse2fs *ff, ext2_ino_t ino,
-			struct stat *statbuf)
+			struct stat *statbuf, unsigned int *iflags)
 {
 	struct ext2_inode_large inode;
 	ext2_filsys fs = ff->fs;
@@ -2004,6 +2004,7 @@ static int fuse2fs_stat(struct fuse2fs *ff, ext2_ino_t ino,
 			statbuf->st_rdev = inode.i_block[1];
 	}
 
+	*iflags = inode.i_flags;
 	return ret;
 }
 
@@ -2038,22 +2039,31 @@ static int __fuse2fs_file_ino(struct fuse2fs *ff, const char *path,
 # define fuse2fs_file_ino(ff, path, fp, inop) \
 	__fuse2fs_file_ino((ff), (path), (fp), (inop), __func__, __LINE__)
 
+static int fuse2fs_getattr(struct fuse2fs *ff, const char *path,
+			   struct stat *statbuf, struct fuse_file_info *fi,
+			   unsigned int *iflags)
+{
+	ext2_ino_t ino;
+	int ret = 0;
+
+	FUSE2FS_CHECK_CONTEXT(ff);
+	fuse2fs_start(ff);
+	ret = fuse2fs_file_ino(ff, path, fi, &ino);
+	if (ret)
+		goto out;
+	ret = fuse2fs_stat(ff, ino, statbuf, iflags);
+out:
+	fuse2fs_finish(ff, ret);
+	return ret;
+}
+
 static int op_getattr(const char *path, struct stat *statbuf,
 		      struct fuse_file_info *fi)
 {
 	struct fuse2fs *ff = fuse2fs_get();
-	ext2_ino_t ino;
-	int ret = 0;
+	unsigned int dontcare;
 
-	FUSE2FS_CHECK_CONTEXT(ff);
-	fuse2fs_start(ff);
-	ret = fuse2fs_file_ino(ff, path, fi, &ino);
-	if (ret)
-		goto out;
-	ret = fuse2fs_stat(ff, ino, statbuf);
-out:
-	fuse2fs_finish(ff, ret);
-	return ret;
+	return fuse2fs_getattr(ff, path, statbuf, fi, &dontcare);
 }
 
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 99)
@@ -2061,11 +2071,21 @@ static int op_getattr_iflags(const char *path, struct stat *statbuf,
 			     unsigned int *iflags, struct fuse_file_info *fi)
 {
 	struct fuse2fs *ff = fuse2fs_get();
-	int ret = op_getattr(path, statbuf, fi);
+	unsigned int i_flags;
+	int ret = fuse2fs_getattr(ff, path, statbuf, fi, &i_flags);
 
 	if (ret)
 		return ret;
 
+	if (i_flags & EXT2_SYNC_FL)
+		*iflags |= FUSE_IFLAG_SYNC;
+
+	if (i_flags & EXT2_IMMUTABLE_FL)
+		*iflags |= FUSE_IFLAG_IMMUTABLE;
+
+	if (i_flags & EXT2_APPEND_FL)
+		*iflags |= FUSE_IFLAG_APPEND;
+
 	if (fuse_fs_can_enable_iomap(statbuf)) {
 		*iflags |= FUSE_IFLAG_IOMAP | FUSE_IFLAG_EXCLUSIVE;
 
@@ -3835,12 +3855,13 @@ static int fuse2fs_punch_posteof(struct fuse2fs *ff, ext2_ino_t ino,
 static int fuse2fs_file_uses_iomap(struct fuse2fs *ff, ext2_ino_t ino)
 {
 	struct stat statbuf;
+	unsigned int dontcare;
 	int ret;
 
 	if (!fuse2fs_iomap_enabled(ff))
 		return 0;
 
-	ret = fuse2fs_stat(ff, ino, &statbuf);
+	ret = fuse2fs_stat(ff, ino, &statbuf, &dontcare);
 	if (ret)
 		return ret;
 
@@ -4749,7 +4770,9 @@ static int op_readdir_iter(ext2_ino_t dir EXT2FS_ATTR((unused)),
 			(unsigned long long)i->dirpos);
 
 	if (i->flags == FUSE_READDIR_PLUS) {
-		ret = fuse2fs_stat(i->ff, dirent->inode, &stat);
+		unsigned int dontcare;
+
+		ret = fuse2fs_stat(i->ff, dirent->inode, &stat, &dontcare);
 		if (ret)
 			return DIRENT_ABORT;
 	}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 10/10] fuse4fs: increase attribute timeout in iomap mode
  2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
                     ` (8 preceding siblings ...)
  2026-02-23 23:43   ` [PATCH 09/10] fuse2fs: set sync, immutable, and append at file load time Darrick J. Wong
@ 2026-02-23 23:43   ` Darrick J. Wong
  9 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:43 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

In iomap mode, we trust the kernel to cache file attributes, because it
is critical to keep all of the file IO permissions checking in the
kernel as part of keeping all the file IO paths in the kernel.
Therefore, increase the attribute timeout to 30 seconds to reduce the
number of upcalls even further.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 8ba904ec2fc9d9..0f62d5a04fc4a4 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -123,7 +123,8 @@
 #endif
 #endif /* !defined(ENODATA) */
 
-#define FUSE4FS_ATTR_TIMEOUT	(0.0)
+#define FUSE4FS_IOMAP_ATTR_TIMEOUT	(0.0)
+#define FUSE4FS_ATTR_TIMEOUT		(30.0)
 
 static inline uint64_t round_up(uint64_t b, unsigned int align)
 {
@@ -2158,8 +2159,14 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino,
 
 	fuse4fs_ino_to_fuse(ff, &entry->ino, ino);
 	entry->generation = inodep->i_generation;
-	entry->attr_timeout = FUSE4FS_ATTR_TIMEOUT;
-	entry->entry_timeout = FUSE4FS_ATTR_TIMEOUT;
+
+	if (fuse4fs_iomap_enabled(ff)) {
+		entry->attr_timeout = FUSE4FS_IOMAP_ATTR_TIMEOUT;
+		entry->entry_timeout = FUSE4FS_IOMAP_ATTR_TIMEOUT;
+	} else {
+		entry->attr_timeout = FUSE4FS_ATTR_TIMEOUT;
+		entry->entry_timeout = FUSE4FS_ATTR_TIMEOUT;
+	}
 
 	fstat->iflags = 0;
 
@@ -2392,6 +2399,8 @@ static void op_statx(fuse_req_t req, fuse_ino_t fino, int flags, int mask,
 	fuse4fs_finish(ff, ret);
 	if (ret)
 		fuse_reply_err(req, -ret);
+	else if (fuse4fs_iomap_enabled(ff))
+		fuse_reply_statx(req, 0, &stx, FUSE4FS_IOMAP_ATTR_TIMEOUT);
 	else
 		fuse_reply_statx(req, 0, &stx, FUSE4FS_ATTR_TIMEOUT);
 }


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/3] fuse2fs: enable caching of iomaps
  2026-02-23 23:05 ` [PATCHSET v7 4/8] fuse2fs: cache iomap mappings for even better file IO performance Darrick J. Wong
@ 2026-02-23 23:44   ` Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 2/3] fuse2fs: constrain iomap mapping cache size Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 3/3] fuse2fs: enable iomap Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:44 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Cache the iomaps we generate in the kernel for better performance.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   31 +++++++++++++++++++++++++++++++
 misc/fuse2fs.c    |   30 ++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 0f62d5a04fc4a4..d7238db25261dc 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -292,6 +292,8 @@ struct fuse4fs {
 #ifdef STATX_WRITE_ATOMIC
 	unsigned int awu_min, awu_max;
 #endif
+	/* options set by fuse_opt_parse must be of type int */
+	int iomap_cache;
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -6890,6 +6892,30 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
 	if (opflags & FUSE_IOMAP_OP_ATOMIC)
 		read.flags |= FUSE_IOMAP_F_ATOMIC_BIO;
 
+	/*
+	 * Cache the mapping in the kernel so that we can reuse them for
+	 * subsequent IO.
+	 */
+	if (ff->iomap_cache) {
+		ret = fuse_lowlevel_iomap_upsert_mappings(ff->fuse, fino, ino,
+							  &read, NULL);
+		if (ret) {
+			/*
+			 * Log the cache upsert error, but we can still return
+			 * the mapping via the reply.  EINVAL is the magic code
+			 * for the kernel declining to cache the mapping.
+			 */
+			if (ret != -ENOMEM && ret != -EINVAL)
+				translate_error(fs, ino, -ret);
+			goto out_unlock;
+		}
+
+		/* Tell the kernel to retry from cache */
+		read.type = FUSE_IOMAP_TYPE_RETRY_CACHE;
+		read.dev = FUSE_IOMAP_DEV_NULL;
+		read.addr = FUSE_IOMAP_NULL_ADDR;
+	}
+
 out_unlock:
 	fuse4fs_finish(ff, ret);
 	if (ret)
@@ -7707,6 +7733,10 @@ static struct fuse_opt fuse4fs_opts[] = {
 #ifdef HAVE_CLOCK_MONOTONIC
 	FUSE4FS_OPT("timing",		timing,			1),
 #endif
+#ifdef HAVE_FUSE_IOMAP
+	FUSE4FS_OPT("iomap_cache",	iomap_cache,		1),
+	FUSE4FS_OPT("noiomap_cache",	iomap_cache,		0),
+#endif
 
 #ifdef HAVE_FUSE_IOMAP
 #ifdef MS_LAZYTIME
@@ -8119,6 +8149,7 @@ int main(int argc, char *argv[])
 		.iomap_want = FT_DEFAULT,
 		.iomap_state = IOMAP_UNKNOWN,
 		.iomap_dev = FUSE_IOMAP_DEV_NULL,
+		.iomap_cache = 1,
 #endif
 #ifdef HAVE_FUSE_LOOPDEV
 		.loop_fd = -1,
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 58ea8e1f2f1e51..5a217b821c2d4a 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -284,6 +284,8 @@ struct fuse2fs {
 #ifdef STATX_WRITE_ATOMIC
 	unsigned int awu_min, awu_max;
 #endif
+	/* options set by fuse_opt_parse must be of type int */
+	int iomap_cache;
 #endif
 	unsigned int blockmask;
 	unsigned long offset;
@@ -6444,6 +6446,29 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
 	if (opflags & FUSE_IOMAP_OP_ATOMIC)
 		read->flags |= FUSE_IOMAP_F_ATOMIC_BIO;
 
+	/*
+	 * Cache the mapping in the kernel so that we can reuse them for
+	 * subsequent IO.
+	 */
+	if (ff->iomap_cache) {
+		ret = fuse_fs_iomap_upsert(nodeid, attr_ino, read, NULL);
+		if (ret) {
+			/*
+			 * Log the cache upsert error, but we can still return
+			 * the mapping via the reply.  EINVAL is the magic code
+			 * for the kernel declining to cache the mapping.
+			 */
+			if (ret != -ENOMEM && ret != -EINVAL)
+				translate_error(fs, attr_ino, -ret);
+			goto out_unlock;
+		}
+
+		/* Tell the kernel to retry from cache */
+		read->type = FUSE_IOMAP_TYPE_RETRY_CACHE;
+		read->dev = FUSE_IOMAP_DEV_NULL;
+		read->addr = FUSE_IOMAP_NULL_ADDR;
+	}
+
 out_unlock:
 	fuse2fs_finish(ff, ret);
 	return ret;
@@ -7250,6 +7275,10 @@ static struct fuse_opt fuse2fs_opts[] = {
 #ifdef HAVE_CLOCK_MONOTONIC
 	FUSE2FS_OPT("timing",		timing,			1),
 #endif
+#ifdef HAVE_FUSE_IOMAP
+	FUSE2FS_OPT("iomap_cache",	iomap_cache,		1),
+	FUSE2FS_OPT("noiomap_cache",	iomap_cache,		0),
+#endif
 
 #ifdef HAVE_FUSE_IOMAP
 #ifdef MS_LAZYTIME
@@ -7530,6 +7559,7 @@ int main(int argc, char *argv[])
 		.iomap_want = FT_DEFAULT,
 		.iomap_state = IOMAP_UNKNOWN,
 		.iomap_dev = FUSE_IOMAP_DEV_NULL,
+		.iomap_cache = 1,
 #endif
 #ifdef HAVE_FUSE_LOOPDEV
 		.loop_fd = -1,


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/3] fuse2fs: constrain iomap mapping cache size
  2026-02-23 23:05 ` [PATCHSET v7 4/8] fuse2fs: cache iomap mappings for even better file IO performance Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 1/3] fuse2fs: enable caching of iomaps Darrick J. Wong
@ 2026-02-23 23:44   ` Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 3/3] fuse2fs: enable iomap Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:44 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Update the iomap config functions to handle the new iomap mapping cache
size restriction knob.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |    9 ++++++---
 misc/fuse2fs.c    |    6 ++++--
 2 files changed, 10 insertions(+), 5 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index d7238db25261dc..c5cf471d630451 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -7187,7 +7187,8 @@ static void fuse4fs_alloc_stats_range(ext2_filsys fs, blk64_t blk, blk_t num,
 		ff->old_alloc_stats_range(fs, blk, num, inuse);
 }
 
-static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
+static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes,
+			    uint32_t cache_maxbytes)
 {
 	struct fuse_iomap_config cfg = { };
 	struct fuse4fs *ff = fuse4fs_get(req);
@@ -7196,9 +7197,11 @@ static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
 
 	FUSE4FS_CHECK_CONTEXT(req);
 
-	dbg_printf(ff, "%s: flags=0x%llx maxbytes=0x%llx\n", __func__,
+	dbg_printf(ff, "%s: flags=0x%llx maxbytes=0x%llx cache_maxbytes=0x%x\n",
+		   __func__,
 		   (unsigned long long)flags,
-		   (unsigned long long)maxbytes);
+		   (unsigned long long)maxbytes,
+		   cache_maxbytes);
 	fs = fuse4fs_start(ff);
 
 	cfg.flags |= FUSE_IOMAP_CONFIG_UUID;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 5a217b821c2d4a..4dab8034ebb317 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -6737,6 +6737,7 @@ static void fuse2fs_alloc_stats_range(ext2_filsys fs, blk64_t blk, blk_t num,
 }
 
 static int op_iomap_config(uint64_t flags, off_t maxbytes,
+			   uint32_t cache_maxbytes,
 			   struct fuse_iomap_config *cfg)
 {
 	struct fuse2fs *ff = fuse2fs_get();
@@ -6745,9 +6746,10 @@ static int op_iomap_config(uint64_t flags, off_t maxbytes,
 
 	FUSE2FS_CHECK_CONTEXT(ff);
 
-	dbg_printf(ff, "%s: flags=0x%llx maxbytes=0x%llx\n", __func__,
+	dbg_printf(ff, "%s: flags=0x%llx maxbytes=0x%llx cache_maxbytes=%u\n", __func__,
 		   (unsigned long long)flags,
-		   (unsigned long long)maxbytes);
+		   (unsigned long long)maxbytes,
+		   cache_maxbytes);
 	fs = fuse2fs_start(ff);
 
 	cfg->flags |= FUSE_IOMAP_CONFIG_UUID;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/3] fuse2fs: enable iomap
  2026-02-23 23:05 ` [PATCHSET v7 4/8] fuse2fs: cache iomap mappings for even better file IO performance Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 1/3] fuse2fs: enable caching of iomaps Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 2/3] fuse2fs: constrain iomap mapping cache size Darrick J. Wong
@ 2026-02-23 23:44   ` Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:44 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Now that iomap functionality is complete, enable this for users.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |    4 ----
 misc/fuse2fs.c    |    4 ----
 2 files changed, 8 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index c5cf471d630451..e8edeb8f62e88a 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -2021,10 +2021,6 @@ static inline bool fuse4fs_wants_iomap(struct fuse4fs *ff)
 static void fuse4fs_iomap_enable(struct fuse_conn_info *conn,
 				 struct fuse4fs *ff)
 {
-	/* Don't let anyone touch iomap until the end of the patchset. */
-	ff->iomap_state = IOMAP_DISABLED;
-	return;
-
 	if (fuse4fs_wants_iomap(ff) &&
 	    fuse_set_feature_flag(conn, FUSE_CAP_IOMAP))
 		ff->iomap_state = IOMAP_ENABLED;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 4dab8034ebb317..96118942c324ba 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1847,10 +1847,6 @@ static inline bool fuse2fs_wants_iomap(struct fuse2fs *ff)
 static void fuse2fs_iomap_enable(struct fuse_conn_info *conn,
 				 struct fuse2fs *ff)
 {
-	/* Don't let anyone touch iomap until the end of the patchset. */
-	ff->iomap_state = IOMAP_DISABLED;
-	return;
-
 	if (fuse2fs_wants_iomap(ff) &&
 	    fuse_set_feature_flag(conn, FUSE_CAP_IOMAP))
 		ff->iomap_state = IOMAP_ENABLED;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/6] libsupport: add caching IO manager
  2026-02-23 23:05 ` [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
@ 2026-02-23 23:44   ` Darrick J. Wong
  2026-02-23 23:45   ` [PATCH 2/6] iocache: add the actual buffer cache Darrick J. Wong
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:44 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Start creating a caching IO manager so that we can have better caching
of metadata blocks in fuse2fs.  For now it's just a passthrough cache.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/support/iocache.h   |   17 +++
 lib/ext2fs/io_manager.c |    3 
 lib/support/Makefile.in |    6 +
 lib/support/iocache.c   |  317 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 342 insertions(+), 1 deletion(-)
 create mode 100644 lib/support/iocache.h
 create mode 100644 lib/support/iocache.c


diff --git a/lib/support/iocache.h b/lib/support/iocache.h
new file mode 100644
index 00000000000000..502eede08aadc5
--- /dev/null
+++ b/lib/support/iocache.h
@@ -0,0 +1,17 @@
+/*
+ * iocache.h - IO cache
+ *
+ * Copyright (C) 2025-2026 Oracle.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+#ifndef __IOCACHE_H__
+#define __IOCACHE_H__
+
+errcode_t iocache_set_backing_manager(io_manager manager);
+extern io_manager iocache_io_manager;
+
+#endif /* __IOCACHE_H__ */
diff --git a/lib/ext2fs/io_manager.c b/lib/ext2fs/io_manager.c
index a92dba7b9dc880..a93415c151ffa0 100644
--- a/lib/ext2fs/io_manager.c
+++ b/lib/ext2fs/io_manager.c
@@ -16,9 +16,12 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
+#include <stdbool.h>
 
 #include "ext2_fs.h"
 #include "ext2fs.h"
+#include "support/list.h"
+#include "support/cache.h"
 
 errcode_t io_channel_set_options(io_channel channel, const char *opts)
 {
diff --git a/lib/support/Makefile.in b/lib/support/Makefile.in
index a09814f574008c..2950e80222ee72 100644
--- a/lib/support/Makefile.in
+++ b/lib/support/Makefile.in
@@ -15,6 +15,7 @@ all::
 
 OBJS=		bthread.o \
 		cstring.o \
+		iocache.o \
 		mkquota.o \
 		plausible.o \
 		profile.o \
@@ -44,7 +45,8 @@ SRCS=		$(srcdir)/argv_parse.c \
 		$(srcdir)/quotaio_v2.c \
 		$(srcdir)/dict.c \
 		$(srcdir)/devname.c \
-		$(srcdir)/cache.c
+		$(srcdir)/cache.c \
+		$(srcdir)/iocache.c
 
 LIBRARY= libsupport
 LIBDIR= support
@@ -191,3 +193,5 @@ devname.o: $(srcdir)/devname.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(srcdir)/devname.h $(srcdir)/nls-enable.h
 cache.o: $(srcdir)/cache.c $(top_builddir)/lib/config.h \
  $(srcdir)/cache.h $(srcdir)/list.h $(srcdir)/xbitops.h
+iocache.o: $(srcdir)/iocache.c $(top_builddir)/lib/config.h \
+ $(srcdir)/iocache.h $(srcdir)/cache.h $(srcdir)/list.h $(srcdir)/xbitops.h
diff --git a/lib/support/iocache.c b/lib/support/iocache.c
new file mode 100644
index 00000000000000..615f1fcc2d7f84
--- /dev/null
+++ b/lib/support/iocache.c
@@ -0,0 +1,317 @@
+/*
+ * iocache.c - caching IO manager
+ *
+ * Copyright (C) 2025-2026 Oracle.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+#include "config.h"
+#include "ext2fs/ext2_fs.h"
+#include "ext2fs/ext2fs.h"
+#include "ext2fs/ext2fsP.h"
+#include "support/iocache.h"
+
+#define IOCACHE_IO_CHANNEL_MAGIC	0x424F5254	/* BORT */
+
+static io_manager iocache_backing_manager;
+
+struct iocache_private_data {
+	int			magic;
+	io_channel		real;
+};
+
+static struct iocache_private_data *IOCACHE(io_channel channel)
+{
+	return (struct iocache_private_data *)channel->private_data;
+}
+
+static errcode_t iocache_read_error(io_channel channel, unsigned long block,
+				    int count, void *data, size_t size,
+				    int actual_bytes_read, errcode_t error)
+{
+	io_channel iocache_channel = channel->app_data;
+
+	return iocache_channel->read_error(iocache_channel, block, count, data,
+					   size, actual_bytes_read, error);
+}
+
+static errcode_t iocache_write_error(io_channel channel, unsigned long block,
+				     int count, const void *data, size_t size,
+				     int actual_bytes_written,
+				     errcode_t error)
+{
+	io_channel iocache_channel = channel->app_data;
+
+	return iocache_channel->write_error(iocache_channel, block, count, data,
+					    size, actual_bytes_written, error);
+}
+
+static errcode_t iocache_open(const char *name, int flags, io_channel *channel)
+{
+	io_channel	io = NULL;
+	io_channel	real;
+	struct iocache_private_data *data = NULL;
+	errcode_t	retval;
+
+	if (!name)
+		return EXT2_ET_BAD_DEVICE_NAME;
+	if (!iocache_backing_manager)
+		return EXT2_ET_INVALID_ARGUMENT;
+
+	retval = iocache_backing_manager->open(name, flags, &real);
+	if (retval)
+		return retval;
+
+	retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io);
+	if (retval)
+		goto out_backing;
+	memset(io, 0, sizeof(struct struct_io_channel));
+	io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
+
+	retval = ext2fs_get_mem(sizeof(struct iocache_private_data), &data);
+	if (retval)
+		goto out_channel;
+	memset(data, 0, sizeof(struct iocache_private_data));
+	data->magic = IOCACHE_IO_CHANNEL_MAGIC;
+
+	io->manager = iocache_io_manager;
+	retval = ext2fs_get_mem(strlen(name) + 1, &io->name);
+	if (retval)
+		goto out_data;
+
+	strcpy(io->name, name);
+	io->private_data = data;
+	io->block_size = real->block_size;
+	io->read_error = 0;
+	io->write_error = 0;
+	io->refcount = 1;
+	io->flags = real->flags;
+	data->real = real;
+	real->app_data = io;
+	real->read_error = iocache_read_error;
+	real->write_error = iocache_write_error;
+
+	*channel = io;
+	return 0;
+
+out_data:
+	ext2fs_free_mem(&data);
+out_channel:
+	ext2fs_free_mem(&io);
+out_backing:
+	io_channel_close(real);
+	return retval;
+}
+
+static errcode_t iocache_close(io_channel channel)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+	errcode_t	retval = 0;
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	if (--channel->refcount > 0)
+		return 0;
+	if (data->real)
+		retval = io_channel_close(data->real);
+	ext2fs_free_mem(&channel->private_data);
+	if (channel->name)
+		ext2fs_free_mem(&channel->name);
+	ext2fs_free_mem(&channel);
+
+	return retval;
+}
+
+static errcode_t iocache_set_blksize(io_channel channel, int blksize)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+	errcode_t retval;
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	retval = io_channel_set_blksize(data->real, blksize);
+	if (retval)
+		return retval;
+
+	channel->block_size = data->real->block_size;
+	return 0;
+}
+
+static errcode_t iocache_flush(io_channel channel)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_flush(data->real);
+}
+
+static errcode_t iocache_write_byte(io_channel channel, unsigned long offset,
+				    int count, const void *buf)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_write_byte(data->real, offset, count, buf);
+}
+
+static errcode_t iocache_set_option(io_channel channel, const char *option,
+				    const char *arg)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return data->real->manager->set_option(data->real, option, arg);
+}
+
+static errcode_t iocache_get_stats(io_channel channel, io_stats *io_stats)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return data->real->manager->get_stats(data->real, io_stats);
+}
+
+static errcode_t iocache_read_blk64(io_channel channel,
+				    unsigned long long block, int count,
+				    void *buf)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_read_blk64(data->real, block, count, buf);
+}
+
+static errcode_t iocache_write_blk64(io_channel channel,
+				     unsigned long long block, int count,
+				     const void *buf)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_write_blk64(data->real, block, count, buf);
+}
+
+static errcode_t iocache_read_blk(io_channel channel, unsigned long block,
+				  int count, void *buf)
+{
+	return iocache_read_blk64(channel, block, count, buf);
+}
+
+static errcode_t iocache_write_blk(io_channel channel, unsigned long block,
+				   int count, const void *buf)
+{
+	return iocache_write_blk64(channel, block, count, buf);
+}
+
+static errcode_t iocache_discard(io_channel channel, unsigned long long block,
+				 unsigned long long count)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_discard(data->real, block, count);
+}
+
+static errcode_t iocache_cache_readahead(io_channel channel,
+					 unsigned long long block,
+					 unsigned long long count)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_cache_readahead(data->real, block, count);
+}
+
+static errcode_t iocache_zeroout(io_channel channel, unsigned long long block,
+				 unsigned long long count)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_zeroout(data->real, block, count);
+}
+
+static errcode_t iocache_get_fd(io_channel channel, int *fd)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_get_fd(data->real, fd);
+}
+
+static errcode_t iocache_invalidate_blocks(io_channel channel,
+					   unsigned long long block,
+					   unsigned long long count)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_invalidate_blocks(data->real, block, count);
+}
+
+static errcode_t iocache_flock(io_channel channel, unsigned int flock_flags)
+{
+	struct iocache_private_data *data = IOCACHE(channel);
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+
+	return io_channel_flock(data->real, flock_flags);
+}
+
+static struct struct_io_manager struct_iocache_manager = {
+	.magic			= EXT2_ET_MAGIC_IO_MANAGER,
+	.name			= "iocache I/O manager",
+	.open			= iocache_open,
+	.close			= iocache_close,
+	.set_blksize		= iocache_set_blksize,
+	.read_blk		= iocache_read_blk,
+	.write_blk		= iocache_write_blk,
+	.flush			= iocache_flush,
+	.write_byte		= iocache_write_byte,
+	.set_option		= iocache_set_option,
+	.get_stats		= iocache_get_stats,
+	.read_blk64		= iocache_read_blk64,
+	.write_blk64		= iocache_write_blk64,
+	.discard		= iocache_discard,
+	.cache_readahead	= iocache_cache_readahead,
+	.zeroout		= iocache_zeroout,
+	.get_fd			= iocache_get_fd,
+	.invalidate_blocks	= iocache_invalidate_blocks,
+	.flock			= iocache_flock,
+};
+
+io_manager iocache_io_manager = &struct_iocache_manager;
+
+errcode_t iocache_set_backing_manager(io_manager manager)
+{
+	iocache_backing_manager = manager;
+	return 0;
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/6] iocache: add the actual buffer cache
  2026-02-23 23:05 ` [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 1/6] libsupport: add caching IO manager Darrick J. Wong
@ 2026-02-23 23:45   ` Darrick J. Wong
  2026-02-23 23:45   ` [PATCH 3/6] iocache: bump buffer mru priority every 50 accesses Darrick J. Wong
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:45 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Wire up buffer caching into our new caching IO manager.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/support/iocache.c |  483 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 461 insertions(+), 22 deletions(-)


diff --git a/lib/support/iocache.c b/lib/support/iocache.c
index 615f1fcc2d7f84..b72dcb7ebb470a 100644
--- a/lib/support/iocache.c
+++ b/lib/support/iocache.c
@@ -9,46 +9,287 @@
  * %End-Header%
  */
 #include "config.h"
+#include <assert.h>
+#include <stdbool.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <limits.h>
 #include "ext2fs/ext2_fs.h"
 #include "ext2fs/ext2fs.h"
 #include "ext2fs/ext2fsP.h"
 #include "support/iocache.h"
+#include "support/list.h"
+#include "support/cache.h"
 
 #define IOCACHE_IO_CHANNEL_MAGIC	0x424F5254	/* BORT */
 
 static io_manager iocache_backing_manager;
 
+static inline uint64_t B_TO_FSBT(io_channel channel, uint64_t number) {
+	return number / channel->block_size;
+}
+
+static inline uint64_t B_TO_FSB(io_channel channel, uint64_t number) {
+	return (number + channel->block_size - 1) / channel->block_size;
+}
+
 struct iocache_private_data {
 	int			magic;
-	io_channel		real;
+	io_channel		real;		/* lower level io channel */
+	io_channel		channel;	/* cache channel */
+	struct cache		cache;
+	pthread_mutex_t		stats_lock;
+	struct struct_io_stats	io_stats;
+	unsigned long long	write_errors;
 };
 
+#define IOCACHEDATA(cache) \
+	(container_of(cache, struct iocache_private_data, cache))
+
 static struct iocache_private_data *IOCACHE(io_channel channel)
 {
 	return (struct iocache_private_data *)channel->private_data;
 }
 
-static errcode_t iocache_read_error(io_channel channel, unsigned long block,
-				    int count, void *data, size_t size,
-				    int actual_bytes_read, errcode_t error)
+struct iocache_buf {
+	struct cache_node	node;
+	struct list_head	list;
+	blk64_t			block;
+	void			*buf;
+	errcode_t		write_error;
+	unsigned int		uptodate:1;
+	unsigned int		dirty:1;
+};
+
+static inline void iocache_buf_lock(struct iocache_buf *ubuf)
+{
+	pthread_mutex_lock(&ubuf->node.cn_mutex);
+}
+
+static inline void iocache_buf_unlock(struct iocache_buf *ubuf)
+{
+	pthread_mutex_unlock(&ubuf->node.cn_mutex);
+}
+
+struct iocache_key {
+	blk64_t			block;
+};
+
+#define IOKEY(key)	((struct iocache_key *)(key))
+#define IOBUF(node)	(container_of((node), struct iocache_buf, node))
+
+static unsigned int
+iocache_hash(cache_key_t key, unsigned int hashsize, unsigned int hashshift)
+{
+	uint64_t	hashval = IOKEY(key)->block;
+	uint64_t	tmp;
+
+	tmp = hashval ^ (GOLDEN_RATIO_PRIME + hashval) / CACHE_LINE_SIZE;
+	tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME) >> hashshift);
+	return tmp % hashsize;
+}
+
+static int iocache_compare(struct cache_node *node, cache_key_t key)
+{
+	struct iocache_buf *ubuf = IOBUF(node);
+	struct iocache_key *ukey = IOKEY(key);
+
+	if (ubuf->block == ukey->block)
+		return CACHE_HIT;
+
+	return CACHE_MISS;
+}
+
+static struct cache_node *iocache_alloc_node(struct cache *cache,
+					     cache_key_t key)
+{
+	struct iocache_private_data *data = IOCACHEDATA(cache);
+	struct iocache_key *ukey = IOKEY(key);
+	struct iocache_buf *ubuf;
+	errcode_t retval;
+
+	retval = ext2fs_get_mem(sizeof(struct iocache_buf), &ubuf);
+	if (retval)
+		return NULL;
+	memset(ubuf, 0, sizeof(*ubuf));
+
+	retval = io_channel_alloc_buf(data->channel, 0, &ubuf->buf);
+	if (retval) {
+		free(ubuf);
+		return NULL;
+	}
+	memset(ubuf->buf, 0, data->channel->block_size);
+
+	INIT_LIST_HEAD(&ubuf->list);
+	ubuf->block = ukey->block;
+	return &ubuf->node;
+}
+
+static bool iocache_flush_node(struct cache *cache, struct cache_node *node)
+{
+	struct iocache_private_data *data = IOCACHEDATA(cache);
+	struct iocache_buf *ubuf = IOBUF(node);
+	errcode_t retval;
+
+	if (ubuf->dirty) {
+		retval = io_channel_write_blk64(data->real, ubuf->block, 1,
+						ubuf->buf);
+		if (retval) {
+			ubuf->write_error = retval;
+			data->write_errors++;
+		} else {
+			ubuf->dirty = 0;
+			ubuf->write_error = 0;
+		}
+	}
+
+	return ubuf->dirty;
+}
+
+static void iocache_relse(struct cache *cache, struct cache_node *node)
+{
+	struct iocache_buf *ubuf = IOBUF(node);
+
+	ext2fs_free_mem(&ubuf->buf);
+	ext2fs_free_mem(&ubuf);
+}
+
+static unsigned int iocache_bulkrelse(struct cache *cache,
+				      struct list_head *list)
+{
+	struct cache_node *cn, *n;
+	int count = 0;
+
+	if (list_empty(list))
+		return 0;
+
+	list_for_each_entry_safe(cn, n, list, cn_mru) {
+		iocache_relse(cache, cn);
+		count++;
+	}
+
+	return count;
+}
+
+/* Flush all dirty buffers in the cache to disk. */
+static errcode_t iocache_flush_cache(struct iocache_private_data *data)
+{
+	return cache_flush(&data->cache) ? 0 : EIO;
+}
+
+/* Flush all dirty buffers in this range of the cache to disk. */
+static errcode_t iocache_flush_range(struct iocache_private_data *data,
+				     blk64_t block, uint64_t count)
+{
+	uint64_t i;
+	bool still_dirty = false;
+
+	for (i = 0; i < count; i++) {
+		struct iocache_key ukey = {
+			.block = block + i,
+		};
+		struct cache_node *node;
+
+		cache_node_get(&data->cache, &ukey, CACHE_GET_INCORE,
+			       &node);
+		if (!node)
+			continue;
+
+		/* cache_flush holds cn_mutex across the node flush */
+		pthread_mutex_unlock(&node->cn_mutex);
+		still_dirty |= iocache_flush_node(&data->cache, node);
+		pthread_mutex_unlock(&node->cn_mutex);
+
+		cache_node_put(&data->cache, node);
+	}
+
+	return still_dirty ? EIO : 0;
+}
+
+static void iocache_add_list(struct cache *cache, struct cache_node *node,
+			     void *data)
+{
+	struct iocache_buf *ubuf = IOBUF(node);
+	struct list_head *list = data;
+
+	assert(node->cn_count == 0 || node->cn_count == 1);
+
+	iocache_buf_lock(ubuf);
+	cache_node_grab(cache, node);
+	list_add_tail(&ubuf->list, list);
+	iocache_buf_unlock(ubuf);
+}
+
+static void iocache_invalidate_bufs(struct iocache_private_data *data,
+				    struct list_head *list)
+{
+	struct iocache_buf *ubuf, *n;
+
+	list_for_each_entry_safe(ubuf, n, list, list) {
+		struct iocache_key ukey = {
+			.block = ubuf->block,
+		};
+
+		assert(ubuf->node.cn_count == 1);
+
+		iocache_buf_lock(ubuf);
+		ubuf->dirty = 0;
+		list_del_init(&ubuf->list);
+		iocache_buf_unlock(ubuf);
+
+		cache_node_put(&data->cache, &ubuf->node);
+		cache_node_purge(&data->cache, &ukey, &ubuf->node);
+	}
+}
+
+/*
+ * Remove all blocks from the cache.  Dirty contents are discarded.  Buffer
+ * refcounts must be zero!
+ */
+static void iocache_invalidate_cache(struct iocache_private_data *data)
 {
-	io_channel iocache_channel = channel->app_data;
+	LIST_HEAD(list);
 
-	return iocache_channel->read_error(iocache_channel, block, count, data,
-					   size, actual_bytes_read, error);
+	cache_walk(&data->cache, iocache_add_list, &list);
+	iocache_invalidate_bufs(data, &list);
 }
 
-static errcode_t iocache_write_error(io_channel channel, unsigned long block,
-				     int count, const void *data, size_t size,
-				     int actual_bytes_written,
-				     errcode_t error)
+/*
+ * Remove a range of blocks from the cache.  Dirty contents are discarded.
+ * Buffer refcounts must be zero!
+ */
+static void iocache_invalidate_range(struct iocache_private_data *data,
+				     blk64_t block, uint64_t count)
 {
-	io_channel iocache_channel = channel->app_data;
+	LIST_HEAD(list);
+	uint64_t i;
 
-	return iocache_channel->write_error(iocache_channel, block, count, data,
-					    size, actual_bytes_written, error);
+	for (i = 0; i < count; i++) {
+		struct iocache_key ukey = {
+			.block = block + i,
+		};
+		struct cache_node *node;
+
+		cache_node_get(&data->cache, &ukey, CACHE_GET_INCORE,
+			       &node);
+		if (node) {
+			iocache_add_list(&data->cache, node, &list);
+			cache_node_put(&data->cache, node);
+		}
+	}
+	iocache_invalidate_bufs(data, &list);
 }
 
+static const struct cache_operations iocache_ops = {
+	.hash		= iocache_hash,
+	.alloc		= iocache_alloc_node,
+	.flush		= iocache_flush_node,
+	.relse		= iocache_relse,
+	.compare	= iocache_compare,
+	.bulkrelse	= iocache_bulkrelse,
+	.resize		= cache_gradual_resize,
+};
+
 static errcode_t iocache_open(const char *name, int flags, io_channel *channel)
 {
 	io_channel	io = NULL;
@@ -65,6 +306,9 @@ static errcode_t iocache_open(const char *name, int flags, io_channel *channel)
 	if (retval)
 		return retval;
 
+	/* disable any static cache in the lower io manager */
+	io_channel_set_options(real, "cache=off");
+
 	retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io);
 	if (retval)
 		goto out_backing;
@@ -76,12 +320,19 @@ static errcode_t iocache_open(const char *name, int flags, io_channel *channel)
 		goto out_channel;
 	memset(data, 0, sizeof(struct iocache_private_data));
 	data->magic = IOCACHE_IO_CHANNEL_MAGIC;
+	data->io_stats.num_fields = 4;
+	data->channel = io;
 
 	io->manager = iocache_io_manager;
 	retval = ext2fs_get_mem(strlen(name) + 1, &io->name);
 	if (retval)
 		goto out_data;
 
+	retval = cache_init(CACHE_AUTO_SHRINK, 1U << 10, &iocache_ops,
+			    &data->cache);
+	if (retval)
+		goto out_name;
+
 	strcpy(io->name, name);
 	io->private_data = data;
 	io->block_size = real->block_size;
@@ -91,12 +342,14 @@ static errcode_t iocache_open(const char *name, int flags, io_channel *channel)
 	io->flags = real->flags;
 	data->real = real;
 	real->app_data = io;
-	real->read_error = iocache_read_error;
-	real->write_error = iocache_write_error;
+
+	pthread_mutex_init(&data->stats_lock, NULL);
 
 	*channel = io;
 	return 0;
 
+out_name:
+	ext2fs_free_mem(&io->name);
 out_data:
 	ext2fs_free_mem(&data);
 out_channel:
@@ -116,6 +369,10 @@ static errcode_t iocache_close(io_channel channel)
 
 	if (--channel->refcount > 0)
 		return 0;
+	pthread_mutex_destroy(&data->stats_lock);
+	cache_flush(&data->cache);
+	cache_purge(&data->cache);
+	cache_destroy(&data->cache);
 	if (data->real)
 		retval = io_channel_close(data->real);
 	ext2fs_free_mem(&channel->private_data);
@@ -134,6 +391,11 @@ static errcode_t iocache_set_blksize(io_channel channel, int blksize)
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
 
+	retval = iocache_flush_cache(data);
+	if (retval)
+		return retval;
+	iocache_invalidate_cache(data);
+
 	retval = io_channel_set_blksize(data->real, blksize);
 	if (retval)
 		return retval;
@@ -145,21 +407,34 @@ static errcode_t iocache_set_blksize(io_channel channel, int blksize)
 static errcode_t iocache_flush(io_channel channel)
 {
 	struct iocache_private_data *data = IOCACHE(channel);
+	errcode_t retval = 0;
+	errcode_t retval2;
 
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
 
-	return io_channel_flush(data->real);
+	retval = iocache_flush_cache(data);
+	retval2 = io_channel_flush(data->real);
+	if (retval)
+		return retval;
+	return retval2;
 }
 
 static errcode_t iocache_write_byte(io_channel channel, unsigned long offset,
 				    int count, const void *buf)
 {
 	struct iocache_private_data *data = IOCACHE(channel);
+	blk64_t bno = B_TO_FSBT(channel, offset);
+	blk64_t next_bno = B_TO_FSB(channel, offset + count);
+	errcode_t retval;
 
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
 
+	retval = iocache_flush_range(data, bno, next_bno - bno);
+	if (retval)
+		return retval;
+	iocache_invalidate_range(data, bno, next_bno - bno);
 	return io_channel_write_byte(data->real, offset, count, buf);
 }
 
@@ -170,6 +445,31 @@ static errcode_t iocache_set_option(io_channel channel, const char *option,
 
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
+	errcode_t retval;
+
+	/* don't let unix io cache= options leak through */
+	if (!strcmp(option, "cache"))
+		return 0;
+
+	if (!strcmp(option, "cache_blocks")) {
+		long long size;
+
+		if (!arg)
+			return EXT2_ET_INVALID_ARGUMENT;
+
+		errno = 0;
+		size = strtoll(arg, NULL, 0);
+		if (errno || size == 0 || size > UINT_MAX)
+			return EXT2_ET_INVALID_ARGUMENT;
+
+		cache_set_maxcount(&data->cache, size);
+		return 0;
+	}
+
+	retval = iocache_flush_cache(data);
+	if (retval)
+		return retval;
+	iocache_invalidate_cache(data);
 
 	return data->real->manager->set_option(data->real, option, arg);
 }
@@ -181,31 +481,157 @@ static errcode_t iocache_get_stats(io_channel channel, io_stats *io_stats)
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
 
-	return data->real->manager->get_stats(data->real, io_stats);
+	/*
+	 * Yes, io_stats is a double-pointer, and we let the caller scribble on
+	 * our stats struct WITHOUT LOCKING!
+	 */
+	if (io_stats)
+		*io_stats = &data->io_stats;
+	return 0;
+}
+
+static void iocache_update_stats(struct iocache_private_data *data,
+				 unsigned long long bytes_read,
+				 unsigned long long bytes_written,
+				 int cache_op)
+{
+	pthread_mutex_lock(&data->stats_lock);
+	data->io_stats.bytes_read += bytes_read;
+	data->io_stats.bytes_written += bytes_written;
+	if (cache_op == CACHE_HIT)
+		data->io_stats.cache_hits++;
+	else
+		data->io_stats.cache_misses++;
+	pthread_mutex_unlock(&data->stats_lock);
 }
 
 static errcode_t iocache_read_blk64(io_channel channel,
 				    unsigned long long block, int count,
 				    void *buf)
 {
+	struct iocache_key ukey = {
+		.block = block,
+	};
 	struct iocache_private_data *data = IOCACHE(channel);
+	unsigned long long i;
+	errcode_t retval;
 
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
 
-	return io_channel_read_blk64(data->real, block, count, buf);
+	/*
+	 * If we're doing an odd-sized read, flush out the cache and then do a
+	 * direct read.
+	 */
+	if (count < 0) {
+		uint64_t fsbcount = B_TO_FSB(channel, -count);
+
+		retval = iocache_flush_range(data, block, fsbcount);
+		if (retval)
+			return retval;
+		iocache_invalidate_range(data, block, fsbcount);
+		iocache_update_stats(data, 0, 0, CACHE_MISS);
+		return io_channel_read_blk64(data->real, block, count, buf);
+	}
+
+	for (i = 0; i < count; i++, ukey.block++, buf += channel->block_size) {
+		struct cache_node *node;
+		struct iocache_buf *ubuf;
+
+		cache_node_get(&data->cache, &ukey, 0, &node);
+		if (!node) {
+			/* cannot instantiate cache, just do a direct read */
+			retval = io_channel_read_blk64(data->real, ukey.block,
+						       1, buf);
+			if (retval)
+				return retval;
+			iocache_update_stats(data, channel->block_size, 0,
+					     CACHE_MISS);
+			continue;
+		}
+
+		ubuf = IOBUF(node);
+		iocache_buf_lock(ubuf);
+		if (!ubuf->uptodate) {
+			retval = io_channel_read_blk64(data->real, ukey.block,
+						       1, ubuf->buf);
+			if (!retval) {
+				ubuf->uptodate = 1;
+				iocache_update_stats(data, channel->block_size,
+						     0, CACHE_MISS);
+			}
+		} else {
+			iocache_update_stats(data, channel->block_size, 0,
+					     CACHE_HIT);
+		}
+		if (ubuf->uptodate)
+			memcpy(buf, ubuf->buf, channel->block_size);
+		iocache_buf_unlock(ubuf);
+		cache_node_put(&data->cache, node);
+		if (retval)
+			return retval;
+	}
+
+	return 0;
 }
 
 static errcode_t iocache_write_blk64(io_channel channel,
 				     unsigned long long block, int count,
 				     const void *buf)
 {
+	struct iocache_key ukey = {
+		.block = block,
+	};
 	struct iocache_private_data *data = IOCACHE(channel);
+	unsigned long long i;
+	errcode_t retval;
 
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
 
-	return io_channel_write_blk64(data->real, block, count, buf);
+	/*
+	 * If we're doing an odd-sized write, flush out the cache and then do a
+	 * direct write.
+	 */
+	if (count < 0) {
+		uint64_t fsbcount = B_TO_FSB(channel, -count);
+
+		retval = iocache_flush_range(data, block, fsbcount);
+		if (retval)
+			return retval;
+		iocache_invalidate_range(data, block, fsbcount);
+		iocache_update_stats(data, 0, 0, CACHE_MISS);
+		return io_channel_write_blk64(data->real, block, count, buf);
+	}
+
+	for (i = 0; i < count; i++, ukey.block++, buf += channel->block_size) {
+		struct cache_node *node;
+		struct iocache_buf *ubuf;
+
+		cache_node_get(&data->cache, &ukey, 0, &node);
+		if (!node) {
+			/* cannot instantiate cache, do a direct write */
+			retval = io_channel_write_blk64(data->real, ukey.block,
+							1, buf);
+			if (retval)
+				return retval;
+			iocache_update_stats(data, 0, channel->block_size,
+					     CACHE_MISS);
+			continue;
+		}
+
+		ubuf = IOBUF(node);
+		iocache_buf_lock(ubuf);
+		memcpy(ubuf->buf, buf, channel->block_size);
+		iocache_update_stats(data, 0, channel->block_size,
+				     ubuf->uptodate ? CACHE_HIT : CACHE_MISS);
+		ubuf->dirty = 1;
+		ubuf->uptodate = 1;
+		iocache_buf_unlock(ubuf);
+		cache_node_put(&data->cache, node);
+	}
+
+	return 0;
 }
 
 static errcode_t iocache_read_blk(io_channel channel, unsigned long block,
@@ -224,11 +650,17 @@ static errcode_t iocache_discard(io_channel channel, unsigned long long block,
 				 unsigned long long count)
 {
 	struct iocache_private_data *data = IOCACHE(channel);
+	errcode_t retval;
 
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
 
-	return io_channel_discard(data->real, block, count);
+	retval = io_channel_discard(data->real, block, count);
+	if (retval)
+		return retval;
+
+	iocache_invalidate_range(data, block, count);
+	return 0;
 }
 
 static errcode_t iocache_cache_readahead(io_channel channel,
@@ -247,11 +679,17 @@ static errcode_t iocache_zeroout(io_channel channel, unsigned long long block,
 				 unsigned long long count)
 {
 	struct iocache_private_data *data = IOCACHE(channel);
+	errcode_t retval;
 
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
 
-	return io_channel_zeroout(data->real, block, count);
+	retval = io_channel_zeroout(data->real, block, count);
+	if (retval)
+		return retval;
+
+	iocache_invalidate_range(data, block, count);
+	return 0;
 }
 
 static errcode_t iocache_get_fd(io_channel channel, int *fd)
@@ -273,6 +711,7 @@ static errcode_t iocache_invalidate_blocks(io_channel channel,
 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
 	EXT2_CHECK_MAGIC(data, IOCACHE_IO_CHANNEL_MAGIC);
 
+	iocache_invalidate_range(data, block, count);
 	return io_channel_invalidate_blocks(data->real, block, count);
 }
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/6] iocache: bump buffer mru priority every 50 accesses
  2026-02-23 23:05 ` [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
  2026-02-23 23:44   ` [PATCH 1/6] libsupport: add caching IO manager Darrick J. Wong
  2026-02-23 23:45   ` [PATCH 2/6] iocache: add the actual buffer cache Darrick J. Wong
@ 2026-02-23 23:45   ` Darrick J. Wong
  2026-02-23 23:45   ` [PATCH 4/6] fuse2fs: enable caching IO manager Darrick J. Wong
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:45 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

If a buffer is hot enough to survive more than 50 access without being
reclaimed, bump its priority to the next MRU so it sticks around longer.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/support/cache.h   |    1 +
 lib/support/cache.c   |   16 ++++++++++++++++
 lib/support/iocache.c |    9 +++++++++
 3 files changed, 26 insertions(+)


diff --git a/lib/support/cache.h b/lib/support/cache.h
index 71fb9762f97866..d81726288bdc88 100644
--- a/lib/support/cache.h
+++ b/lib/support/cache.h
@@ -180,5 +180,6 @@ int cache_node_purge(struct cache *, cache_key_t, struct cache_node *);
 void cache_report(FILE *fp, const char *, struct cache *);
 int cache_overflowed(struct cache *);
 struct cache_node *cache_node_grab(struct cache *cache, struct cache_node *node);
+void cache_node_bump_priority(struct cache *cache, struct cache_node *node);
 
 #endif	/* __CACHE_H__ */
diff --git a/lib/support/cache.c b/lib/support/cache.c
index 3a9e276f11af72..513a71829193a8 100644
--- a/lib/support/cache.c
+++ b/lib/support/cache.c
@@ -678,6 +678,22 @@ cache_node_put(
 		cache_shrink(cache);
 }
 
+/* Bump the priority of a cache node.  Caller must hold cn_mutex. */
+void
+cache_node_bump_priority(
+	struct cache		*cache,
+	struct cache_node	*node)
+{
+	int			*priop;
+
+	if (node->cn_priority == CACHE_DIRTY_PRIORITY)
+		priop = &node->cn_old_priority;
+	else
+		priop = &node->cn_priority;
+	if (*priop < CACHE_MAX_PRIORITY)
+		(*priop)++;
+}
+
 void
 cache_node_set_priority(
 	struct cache *		cache,
diff --git a/lib/support/iocache.c b/lib/support/iocache.c
index b72dcb7ebb470a..478d89174422df 100644
--- a/lib/support/iocache.c
+++ b/lib/support/iocache.c
@@ -57,6 +57,7 @@ struct iocache_buf {
 	blk64_t			block;
 	void			*buf;
 	errcode_t		write_error;
+	uint8_t			access;
 	unsigned int		uptodate:1;
 	unsigned int		dirty:1;
 };
@@ -566,6 +567,10 @@ static errcode_t iocache_read_blk64(io_channel channel,
 		}
 		if (ubuf->uptodate)
 			memcpy(buf, ubuf->buf, channel->block_size);
+		if (++ubuf->access > 50) {
+			cache_node_bump_priority(&data->cache, node);
+			ubuf->access = 0;
+		}
 		iocache_buf_unlock(ubuf);
 		cache_node_put(&data->cache, node);
 		if (retval)
@@ -627,6 +632,10 @@ static errcode_t iocache_write_blk64(io_channel channel,
 				     ubuf->uptodate ? CACHE_HIT : CACHE_MISS);
 		ubuf->dirty = 1;
 		ubuf->uptodate = 1;
+		if (++ubuf->access > 50) {
+			cache_node_bump_priority(&data->cache, node);
+			ubuf->access = 0;
+		}
 		iocache_buf_unlock(ubuf);
 		cache_node_put(&data->cache, node);
 	}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 4/6] fuse2fs: enable caching IO manager
  2026-02-23 23:05 ` [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:45   ` [PATCH 3/6] iocache: bump buffer mru priority every 50 accesses Darrick J. Wong
@ 2026-02-23 23:45   ` Darrick J. Wong
  2026-02-23 23:45   ` [PATCH 5/6] fuse2fs: increase inode cache size Darrick J. Wong
  2026-02-23 23:46   ` [PATCH 6/6] libext2fs: improve caching for inodes Darrick J. Wong
  5 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:45 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Enable the new dynamic iocache I/O manager in the fuse server, and turn
off all the other cache control.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/Makefile.in |    3 ++-
 fuse4fs/fuse4fs.c   |    4 +++-
 misc/Makefile.in    |    4 +++-
 misc/fuse2fs.c      |    6 +++++-
 4 files changed, 13 insertions(+), 4 deletions(-)


diff --git a/fuse4fs/Makefile.in b/fuse4fs/Makefile.in
index 9f3547c271638f..0a558da23ced81 100644
--- a/fuse4fs/Makefile.in
+++ b/fuse4fs/Makefile.in
@@ -147,7 +147,8 @@ fuse4fs.o: $(srcdir)/fuse4fs.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/ext2fsP.h \
  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/version.h \
  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/cache.h \
- $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h
+ $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h \
+ $(top_srcdir)/lib/support/iocache.h
 journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(srcdir)/../debugfs/journal.h \
  $(top_srcdir)/e2fsck/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index e8edeb8f62e88a..d91817f362674a 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -56,6 +56,7 @@
 #include "support/bthread.h"
 #include "support/list.h"
 #include "support/cache.h"
+#include "support/iocache.h"
 
 #include "../version.h"
 #include "uuid/uuid.h"
@@ -1574,6 +1575,7 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 		flags |= EXT2_FLAG_DIRECT_IO;
 
 	dbg_printf(ff, "opening with flags=0x%x\n", flags);
+	iocache_set_backing_manager(unix_io_manager);
 
 	err = fuse4fs_try_losetup(ff, flags);
 	if (err)
@@ -1611,7 +1613,7 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 	deadline = init_deadline(FUSE4FS_OPEN_TIMEOUT);
 	do {
 		err = ext2fs_open2(fuse4fs_device(ff), options, flags, 0, 0,
-				   unix_io_manager, &ff->fs);
+				   iocache_io_manager, &ff->fs);
 		if ((err == EPERM || err == EACCES) &&
 		    (!ff->ro || (flags & EXT2_FLAG_RW))) {
 			/*
diff --git a/misc/Makefile.in b/misc/Makefile.in
index ec964688acd623..8a3adc70fb736e 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -880,7 +880,9 @@ fuse2fs.o: $(srcdir)/fuse2fs.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \
  $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/ext2fsP.h \
  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/version.h \
- $(top_srcdir)/lib/e2p/e2p.h
+ $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/cache.h \
+ $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h \
+ $(top_srcdir)/lib/support/iocache.h
 e2fuzz.o: $(srcdir)/e2fuzz.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 96118942c324ba..3d78a3967f7d9a 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -53,6 +53,9 @@
 #include "ext2fs/ext2_fs.h"
 #include "ext2fs/ext2fsP.h"
 #include "support/bthread.h"
+#include "support/list.h"
+#include "support/cache.h"
+#include "support/iocache.h"
 
 #include "../version.h"
 #include "uuid/uuid.h"
@@ -1404,6 +1407,7 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff)
 		flags |= EXT2_FLAG_DIRECT_IO;
 
 	dbg_printf(ff, "opening with flags=0x%x\n", flags);
+	iocache_set_backing_manager(unix_io_manager);
 
 	err = fuse2fs_try_losetup(ff, flags);
 	if (err)
@@ -1441,7 +1445,7 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff)
 	deadline = init_deadline(FUSE2FS_OPEN_TIMEOUT);
 	do {
 		err = ext2fs_open2(fuse2fs_device(ff), options, flags, 0, 0,
-				   unix_io_manager, &ff->fs);
+				   iocache_io_manager, &ff->fs);
 		if ((err == EPERM || err == EACCES) &&
 		    (!ff->ro || (flags & EXT2_FLAG_RW))) {
 			/*


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 5/6] fuse2fs: increase inode cache size
  2026-02-23 23:05 ` [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:45   ` [PATCH 4/6] fuse2fs: enable caching IO manager Darrick J. Wong
@ 2026-02-23 23:45   ` Darrick J. Wong
  2026-02-23 23:46   ` [PATCH 6/6] libext2fs: improve caching for inodes Darrick J. Wong
  5 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:45 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Increase the internal inode cache size.  Does this improve performance
any?

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |    4 ++++
 misc/fuse2fs.c    |    4 ++++
 2 files changed, 8 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index d91817f362674a..1a4ac0cd9a038f 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -1686,6 +1686,10 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 	if (err)
 		return translate_error(ff->fs, 0, err);
 
+	err = ext2fs_create_inode_cache(ff->fs, 1024);
+	if (err)
+		return translate_error(ff->fs, 0, err);
+
 	ff->fs->priv_data = ff;
 	ff->blocklog = u_log2(ff->fs->blocksize);
 	ff->blockmask = ff->fs->blocksize - 1;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 3d78a3967f7d9a..4d62b5d44279f9 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1514,6 +1514,10 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff)
 		log_printf(ff, "%s %s.\n", _("mounted filesystem"), uuid);
 	}
 
+	err = ext2fs_create_inode_cache(ff->fs, 1024);
+	if (err)
+		return translate_error(ff->fs, 0, err);
+
 	ff->fs->priv_data = ff;
 	ff->blocklog = u_log2(ff->fs->blocksize);
 	ff->blockmask = ff->fs->blocksize - 1;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 6/6] libext2fs: improve caching for inodes
  2026-02-23 23:05 ` [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
                     ` (4 preceding siblings ...)
  2026-02-23 23:45   ` [PATCH 5/6] fuse2fs: increase inode cache size Darrick J. Wong
@ 2026-02-23 23:46   ` Darrick J. Wong
  5 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:46 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Use our new cache code to improve the ondisk inode cache inside
libext2fs.  Oops, list.h duplication, and libext2fs needs to link
against libsupport now.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/ext2fs/ext2fsP.h     |   13 ++-
 debugfs/Makefile.in      |    8 +-
 e2fsck/Makefile.in       |   12 +--
 fuse4fs/Makefile.in      |    8 +-
 lib/ext2fs/Makefile.in   |   70 ++++++++-------
 lib/ext2fs/inline_data.c |    4 -
 lib/ext2fs/inode.c       |  215 ++++++++++++++++++++++++++++++++++++----------
 misc/Makefile.in         |    8 +-
 resize/Makefile.in       |   11 +-
 tests/fuzz/Makefile.in   |    4 -
 tests/progs/Makefile.in  |    4 -
 11 files changed, 240 insertions(+), 117 deletions(-)


diff --git a/lib/ext2fs/ext2fsP.h b/lib/ext2fs/ext2fsP.h
index 428081c9e2ff38..8490dd5139d543 100644
--- a/lib/ext2fs/ext2fsP.h
+++ b/lib/ext2fs/ext2fsP.h
@@ -82,21 +82,26 @@ struct dir_context {
 	errcode_t	errcode;
 };
 
+#include "support/list.h"
+#include "support/cache.h"
+
 /*
  * Inode cache structure
  */
 struct ext2_inode_cache {
 	void *				buffer;
 	blk64_t				buffer_blk;
-	int				cache_last;
-	unsigned int			cache_size;
 	int				refcount;
-	struct ext2_inode_cache_ent	*cache;
+	struct cache			cache;
 };
 
 struct ext2_inode_cache_ent {
+	struct cache_node	node;
 	ext2_ino_t		ino;
-	struct ext2_inode	*inode;
+	uint8_t			access;
+
+	/* bytes representing a host-endian ext2_inode_large object */
+	char			raw[];
 };
 
 /*
diff --git a/debugfs/Makefile.in b/debugfs/Makefile.in
index 700ae87418c268..8bee4b67fc2de7 100644
--- a/debugfs/Makefile.in
+++ b/debugfs/Makefile.in
@@ -38,15 +38,15 @@ SRCS= debug_cmds.c $(srcdir)/debugfs.c $(srcdir)/util.c $(srcdir)/ls.c \
 	$(srcdir)/../e2fsck/recovery.c $(srcdir)/do_journal.c \
 	$(srcdir)/do_orphan.c
 
-LIBS= $(LIBSUPPORT) $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \
+LIBS= $(LIBEXT2FS) $(LIBSUPPORT) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \
 	$(LIBUUID) $(LIBMAGIC) $(SYSLIBS) $(LIBARCHIVE)
-DEPLIBS= $(DEPLIBSUPPORT) $(LIBEXT2FS) $(LIBE2P) $(DEPLIBSS) $(DEPLIBCOM_ERR) \
+DEPLIBS= $(LIBEXT2FS) $(DEPLIBSUPPORT) $(LIBE2P) $(DEPLIBSS) $(DEPLIBCOM_ERR) \
 	$(DEPLIBBLKID) $(DEPLIBUUID)
 
-STATIC_LIBS= $(STATIC_LIBSUPPORT) $(STATIC_LIBEXT2FS) $(STATIC_LIBSS) \
+STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBSS) \
 	$(STATIC_LIBCOM_ERR) $(STATIC_LIBBLKID) $(STATIC_LIBUUID) \
 	$(STATIC_LIBE2P) $(LIBMAGIC) $(SYSLIBS)
-STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSS) \
+STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) $(DEPSTATIC_LIBSS) \
 		$(DEPSTATIC_LIBCOM_ERR) $(DEPSTATIC_LIBUUID) \
 		$(DEPSTATIC_LIBE2P)
 
diff --git a/e2fsck/Makefile.in b/e2fsck/Makefile.in
index 52fad9cbfd2b23..d72244f47e47c0 100644
--- a/e2fsck/Makefile.in
+++ b/e2fsck/Makefile.in
@@ -16,22 +16,22 @@ PROGS=		e2fsck
 MANPAGES=	e2fsck.8
 FMANPAGES=	e2fsck.conf.5
 
-LIBS= $(LIBSUPPORT) $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBBLKID) $(LIBUUID) \
+LIBS= $(LIBEXT2FS) $(LIBSUPPORT) $(LIBCOM_ERR) $(LIBBLKID) $(LIBUUID) \
 	$(LIBINTL) $(LIBE2P) $(LIBMAGIC) $(SYSLIBS)
-DEPLIBS= $(DEPLIBSUPPORT) $(LIBEXT2FS) $(DEPLIBCOM_ERR) $(DEPLIBBLKID) \
+DEPLIBS= $(LIBEXT2FS) $(DEPLIBSUPPORT) $(DEPLIBCOM_ERR) $(DEPLIBBLKID) \
 	 $(DEPLIBUUID) $(DEPLIBE2P)
 
-STATIC_LIBS= $(STATIC_LIBSUPPORT) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \
+STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) \
 	     $(STATIC_LIBBLKID) $(STATIC_LIBUUID) $(LIBINTL) $(STATIC_LIBE2P) \
 	     $(LIBMAGIC) $(SYSLIBS)
-STATIC_DEPLIBS= $(DEPSTATIC_LIBSUPPORT) $(STATIC_LIBEXT2FS) \
+STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) \
 		$(DEPSTATIC_LIBCOM_ERR) $(DEPSTATIC_LIBBLKID) \
 		$(DEPSTATIC_LIBUUID) $(DEPSTATIC_LIBE2P)
 
-PROFILED_LIBS= $(PROFILED_LIBSUPPORT) $(PROFILED_LIBEXT2FS) \
+PROFILED_LIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBSUPPORT) \
 	       $(PROFILED_LIBCOM_ERR) $(PROFILED_LIBBLKID) $(PROFILED_LIBUUID) \
 	       $(PROFILED_LIBE2P) $(LIBINTL) $(LIBMAGIC) $(SYSLIBS)
-PROFILED_DEPLIBS= $(DEPPROFILED_LIBSUPPORT) $(PROFILED_LIBEXT2FS) \
+PROFILED_DEPLIBS= $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBSUPPORT) \
 		  $(DEPPROFILED_LIBCOM_ERR) $(DEPPROFILED_LIBBLKID) \
 		  $(DEPPROFILED_LIBUUID) $(DEPPROFILED_LIBE2P)
 
diff --git a/fuse4fs/Makefile.in b/fuse4fs/Makefile.in
index 0a558da23ced81..31afbd8def1de6 100644
--- a/fuse4fs/Makefile.in
+++ b/fuse4fs/Makefile.in
@@ -30,11 +30,11 @@ SRCS=\
 
 LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBSUPPORT)
 DEPLIBS= $(LIBEXT2FS) $(DEPLIBCOM_ERR) $(DEPLIBSUPPORT)
-PROFILED_LIBS= $(LIBSUPPORT) $(PROFILED_LIBEXT2FS) $(PROFILED_LIBCOM_ERR)
-PROFILED_DEPLIBS= $(DEPLIBSUPPORT) $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBCOM_ERR)
+PROFILED_LIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBSUPPORT) $(PROFILED_LIBCOM_ERR)
+PROFILED_DEPLIBS= $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBSUPPORT) $(DEPPROFILED_LIBCOM_ERR)
 
-STATIC_LIBS= $(LIBSUPPORT) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR)
-STATIC_DEPLIBS= $(DEPLIBSUPPORT) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR)
+STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 
 LIBS_E2P= $(LIBE2P) $(LIBCOM_ERR)
 DEPLIBS_E2P= $(LIBE2P) $(DEPLIBCOM_ERR)
diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in
index 1d0991defff804..ea8785a26829c2 100644
--- a/lib/ext2fs/Makefile.in
+++ b/lib/ext2fs/Makefile.in
@@ -246,7 +246,7 @@ ELF_SO_VERSION = 2
 ELF_IMAGE = libext2fs
 ELF_MYDIR = ext2fs
 ELF_INSTALL_DIR = $(root_libdir)
-ELF_OTHER_LIBS = -lcom_err
+ELF_OTHER_LIBS = -lcom_err $(top_builddir)/../lib/libsupport.a
 
 BSDLIB_VERSION = 2.1
 BSDLIB_IMAGE = libext2fs
@@ -283,54 +283,54 @@ ext2fs.pc: $(srcdir)/ext2fs.pc.in $(top_builddir)/config.status
 	$(E) "	CONFIG.STATUS $@"
 	$(Q) cd $(top_builddir); CONFIG_FILES=lib/ext2fs/ext2fs.pc ./config.status
 
-tst_badblocks: tst_badblocks.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_badblocks: tst_badblocks.o $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_badblocks tst_badblocks.o $(ALL_LDFLAGS) \
-		$(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
 tst_digest_encode: $(srcdir)/digest_encode.c $(srcdir)/ext2_fs.h
 	$(E) "	CC $@"
 	$(Q) $(CC) $(ALL_LDFLAGS) $(ALL_CFLAGS) -o tst_digest_encode \
 		$(srcdir)/digest_encode.c -DUNITTEST $(SYSLIBS)
 
-tst_icount: $(srcdir)/icount.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_icount: $(srcdir)/icount.c $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_icount $(srcdir)/icount.c -DDEBUG \
 		$(ALL_CFLAGS) $(ALL_LDFLAGS) \
-		$(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
-tst_iscan: tst_iscan.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_iscan: tst_iscan.o $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_iscan tst_iscan.o $(ALL_LDFLAGS) \
-		$(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
-tst_getsize: tst_getsize.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_getsize: tst_getsize.o $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_getsize tst_getsize.o $(ALL_LDFLAGS) \
-		$(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
-tst_ismounted: $(srcdir)/ismounted.c $(STATIC_LIBEXT2FS) \
+tst_ismounted: $(srcdir)/ismounted.c $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \
 		$(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_ismounted $(srcdir)/ismounted.c \
-		$(STATIC_LIBEXT2FS) -DDEBUG $(ALL_CFLAGS) $(ALL_LDFLAGS) \
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) -DDEBUG $(ALL_CFLAGS) $(ALL_LDFLAGS) \
 		$(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
-tst_byteswap: tst_byteswap.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_byteswap: tst_byteswap.o $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_byteswap tst_byteswap.o $(ALL_LDFLAGS) \
-		$(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
-tst_bitops: tst_bitops.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_bitops: tst_bitops.o $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_bitops tst_bitops.o $(ALL_CFLAGS) $(ALL_LDFLAGS) \
-		$(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
-tst_getsectsize: tst_getsectsize.o getsectsize.o $(STATIC_LIBEXT2FS) \
+tst_getsectsize: tst_getsectsize.o getsectsize.o $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \
 			$(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_getsectsize tst_getsectsize.o getsectsize.o \
-		$(ALL_LDFLAGS) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \
+		$(ALL_LDFLAGS) $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) \
 		$(SYSLIBS)
 
 tst_types.o: $(srcdir)/tst_types.c ext2_types.h 
@@ -490,11 +490,11 @@ tst_bitmaps_cmd.c: tst_bitmaps_cmd.ct
 	$(Q) DIR=$(srcdir) $(MK_CMDS) $(srcdir)/tst_bitmaps_cmd.ct
 
 tst_bitmaps: tst_bitmaps.o tst_bitmaps_cmd.o $(srcdir)/blkmap64_rb.c \
-		$(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSS) $(DEPSTATIC_LIBCOM_ERR)
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBSS) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o $@ tst_bitmaps.o tst_bitmaps_cmd.o \
 		-DDEBUG_RB $(srcdir)/blkmap64_rb.c $(ALL_CFLAGS) \
-		$(ALL_LDFLAGS) $(STATIC_LIBEXT2FS) $(STATIC_LIBSS) \
+		$(ALL_LDFLAGS) $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBSS) \
 		$(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
 tst_extents: $(srcdir)/extent.c $(DEBUG_OBJS) $(DEPSTATIC_LIBSS) libext2fs.a \
@@ -503,8 +503,8 @@ tst_extents: $(srcdir)/extent.c $(DEBUG_OBJS) $(DEPSTATIC_LIBSS) libext2fs.a \
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_extents $(srcdir)/extent.c \
 		$(ALL_CFLAGS) $(ALL_LDFLAGS) -DDEBUG $(DEBUG_OBJS) \
-		$(STATIC_LIBSS) $(STATIC_LIBE2P) $(LIBSUPPORT) \
-		$(STATIC_LIBEXT2FS) $(LIBBLKID) $(LIBUUID) \
+		$(STATIC_LIBSS) $(STATIC_LIBE2P) \
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(LIBSUPPORT) $(LIBBLKID) $(LIBUUID) \
 		$(STATIC_LIBCOM_ERR) $(SYSLIBS) -I $(top_srcdir)/debugfs
 
 tst_libext2fs: $(DEBUG_OBJS) \
@@ -512,38 +512,38 @@ tst_libext2fs: $(DEBUG_OBJS) \
 	$(DEPLIBBLKID) $(DEPSTATIC_LIBCOM_ERR) $(DEPLIBSUPPORT)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_libext2fs $(ALL_LDFLAGS) -DDEBUG $(DEBUG_OBJS) \
-		$(STATIC_LIBSS) $(STATIC_LIBE2P) $(LIBSUPPORT) \
-		$(STATIC_LIBEXT2FS) $(LIBBLKID) $(LIBUUID) $(LIBMAGIC) \
+		$(STATIC_LIBSS) $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \
+		$(LIBSUPPORT) $(LIBBLKID) $(LIBUUID) $(LIBMAGIC) \
 		$(STATIC_LIBCOM_ERR) $(SYSLIBS) $(LIBARCHIVE) -I $(top_srcdir)/debugfs
 
-tst_inline: $(srcdir)/inline.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_inline: $(srcdir)/inline.c $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_inline $(srcdir)/inline.c $(ALL_CFLAGS) \
-		$(ALL_LDFLAGS) -DDEBUG $(STATIC_LIBEXT2FS) \
+		$(ALL_LDFLAGS) -DDEBUG $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \
 		$(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
-tst_inline_data: inline_data.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_inline_data: inline_data.c $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_inline_data $(srcdir)/inline_data.c $(ALL_CFLAGS) \
-		$(ALL_LDFLAGS) -DDEBUG $(STATIC_LIBEXT2FS) \
+		$(ALL_LDFLAGS) -DDEBUG $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \
 		$(STATIC_LIBCOM_ERR) $(SYSLIBS)
 
-tst_csum: csum.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) $(STATIC_LIBE2P) \
+tst_csum: csum.c $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR) $(STATIC_LIBE2P) \
 		$(top_srcdir)/lib/e2p/e2p.h
 	$(E) "	LD $@"
 	$(Q) $(CC) -o tst_csum $(srcdir)/csum.c -DDEBUG \
-		$(ALL_CFLAGS) $(ALL_LDFLAGS) $(STATIC_LIBEXT2FS) \
+		$(ALL_CFLAGS) $(ALL_LDFLAGS) $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \
 		$(STATIC_LIBCOM_ERR) $(STATIC_LIBE2P) $(SYSLIBS)
 
-tst_crc32c: $(srcdir)/crc32c.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_crc32c: $(srcdir)/crc32c.c $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 	$(Q) $(CC) $(ALL_LDFLAGS) $(ALL_CFLAGS) -o tst_crc32c $(srcdir)/crc32c.c \
-		-DUNITTEST $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \
+		-DUNITTEST $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) \
 		$(SYSLIBS)
 
-mkjournal: mkjournal.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR)
+mkjournal: mkjournal.c $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(DEPLIBCOM_ERR)
 	$(E) "	LD $@"
 	$(Q) $(CC) -o mkjournal $(srcdir)/mkjournal.c -DDEBUG \
-		$(STATIC_LIBEXT2FS) $(LIBCOM_ERR) $(ALL_CFLAGS) $(SYSLIBS)
+		$(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(LIBCOM_ERR) $(ALL_CFLAGS) $(SYSLIBS)
 
 fullcheck check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount \
     tst_super_size tst_types tst_inode_size tst_csum tst_crc32c tst_bitmaps \
@@ -976,7 +976,9 @@ inode.o: $(srcdir)/inode.c $(top_builddir)/lib/config.h \
  $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \
  $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \
  $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \
- $(srcdir)/hashmap.h $(srcdir)/bitops.h $(srcdir)/e2image.h
+ $(srcdir)/hashmap.h $(srcdir)/bitops.h $(srcdir)/e2image.h \
+ $(srcdir)/../support/cache.h $(srcdir)/../support/list.h \
+ $(srcdir)/../support/xbitops.h 
 inode_io.o: $(srcdir)/inode_io.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
diff --git a/lib/ext2fs/inline_data.c b/lib/ext2fs/inline_data.c
index bd52e37708ccad..8ff4a23397f499 100644
--- a/lib/ext2fs/inline_data.c
+++ b/lib/ext2fs/inline_data.c
@@ -817,10 +817,6 @@ int main(int argc, char *argv[])
 				"tst_inline_data: init inode cache failed\n");
 			exit(1);
 		}
-
-		/* setup inode cache */
-		for (i = 0; i < fs->icache->cache_size; i++)
-			fs->icache->cache[i].ino = first_ino++;
 	}
 
 	/* test */
diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c
index c9389a2324be07..8ca82af1ab35d3 100644
--- a/lib/ext2fs/inode.c
+++ b/lib/ext2fs/inode.c
@@ -59,18 +59,145 @@ struct ext2_struct_inode_scan {
 	int			reserved[6];
 };
 
+struct ext2_inode_cache_key {
+	ext2_filsys		fs;
+	ext2_ino_t		ino;
+};
+
+#define ICKEY(key)	((struct ext2_inode_cache_key *)(key))
+#define ICNODE(node)	(container_of((node), struct ext2_inode_cache_ent, node))
+
+static unsigned int
+ext2_inode_cache_hash(cache_key_t key, unsigned int hashsize,
+		      unsigned int hashshift)
+{
+	uint64_t	hashval = ICKEY(key)->ino;
+	uint64_t	tmp;
+
+	tmp = hashval ^ (GOLDEN_RATIO_PRIME + hashval) / CACHE_LINE_SIZE;
+	tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME) >> hashshift);
+	return tmp % hashsize;
+}
+
+static int ext2_inode_cache_compare(struct cache_node *node, cache_key_t key)
+{
+	struct ext2_inode_cache_ent *ent = ICNODE(node);
+	struct ext2_inode_cache_key *ikey = ICKEY(key);
+
+	if (ent->ino == ikey->ino)
+		return CACHE_HIT;
+
+	return CACHE_MISS;
+}
+
+static struct cache_node *ext2_inode_cache_alloc(struct cache *c,
+						 cache_key_t key)
+{
+	struct ext2_inode_cache_key *ikey = ICKEY(key);
+	struct ext2_inode_cache_ent *ent;
+
+	ent = calloc(1, sizeof(struct ext2_inode_cache_ent) +
+			EXT2_INODE_SIZE(ikey->fs->super));
+	if (!ent)
+		return NULL;
+
+	ent->ino = ikey->ino;
+	return &ent->node;
+}
+
+static bool ext2_inode_cache_flush(struct cache *c, struct cache_node *node)
+{
+	/* can always drop inode cache */
+	return 0;
+}
+
+static void ext2_inode_cache_relse(struct cache *c, struct cache_node *node)
+{
+	struct ext2_inode_cache_ent *ent = ICNODE(node);
+
+	free(ent);
+}
+
+static unsigned int ext2_inode_cache_bulkrelse(struct cache *cache,
+					       struct list_head *list)
+{
+	struct cache_node *cn, *n;
+	int count = 0;
+
+	if (list_empty(list))
+		return 0;
+
+	list_for_each_entry_safe(cn, n, list, cn_mru) {
+		ext2_inode_cache_relse(cache, cn);
+		count++;
+	}
+
+	return count;
+}
+
+static const struct cache_operations ext2_inode_cache_ops = {
+	.hash		= ext2_inode_cache_hash,
+	.alloc		= ext2_inode_cache_alloc,
+	.flush		= ext2_inode_cache_flush,
+	.relse		= ext2_inode_cache_relse,
+	.compare	= ext2_inode_cache_compare,
+	.bulkrelse	= ext2_inode_cache_bulkrelse,
+	.resize		= cache_gradual_resize,
+};
+
+static errcode_t ext2_inode_cache_iget(ext2_filsys fs, ext2_ino_t ino,
+				       unsigned int getflags,
+				       struct ext2_inode_cache_ent **entp)
+{
+	struct ext2_inode_cache_key ikey = {
+		.fs = fs,
+		.ino = ino,
+	};
+	struct cache_node *node = NULL;
+
+	cache_node_get(&fs->icache->cache, &ikey, getflags, &node);
+	if (!node)
+		return ENOMEM;
+
+	*entp = ICNODE(node);
+	return 0;
+}
+
+static void ext2_inode_cache_iput(ext2_filsys fs,
+				  struct ext2_inode_cache_ent *ent)
+{
+	cache_node_put(&fs->icache->cache, &ent->node);
+}
+
+static int ext2_inode_cache_ipurge(ext2_filsys fs, ext2_ino_t ino,
+				   struct ext2_inode_cache_ent *ent)
+{
+	struct ext2_inode_cache_key ikey = {
+		.fs = fs,
+		.ino = ino,
+	};
+
+	return cache_node_purge(&fs->icache->cache, &ikey, &ent->node);
+}
+
+static void ext2_inode_cache_ibump(ext2_filsys fs,
+				   struct ext2_inode_cache_ent *ent)
+{
+	if (++ent->access > 50) {
+		cache_node_bump_priority(&fs->icache->cache, &ent->node);
+		ent->access = 0;
+	}
+}
+
 /*
  * This routine flushes the icache, if it exists.
  */
 errcode_t ext2fs_flush_icache(ext2_filsys fs)
 {
-	unsigned	i;
-
 	if (!fs->icache)
 		return 0;
 
-	for (i=0; i < fs->icache->cache_size; i++)
-		fs->icache->cache[i].ino = 0;
+	cache_purge(&fs->icache->cache);
 
 	fs->icache->buffer_blk = 0;
 	return 0;
@@ -81,23 +208,20 @@ errcode_t ext2fs_flush_icache(ext2_filsys fs)
  */
 void ext2fs_free_inode_cache(struct ext2_inode_cache *icache)
 {
-	unsigned i;
-
 	if (--icache->refcount)
 		return;
 	if (icache->buffer)
 		ext2fs_free_mem(&icache->buffer);
-	for (i = 0; i < icache->cache_size; i++)
-		ext2fs_free_mem(&icache->cache[i].inode);
-	if (icache->cache)
-		ext2fs_free_mem(&icache->cache);
+	if (cache_initialized(&icache->cache)) {
+		cache_purge(&icache->cache);
+		cache_destroy(&icache->cache);
+	}
 	icache->buffer_blk = 0;
 	ext2fs_free_mem(&icache);
 }
 
 errcode_t ext2fs_create_inode_cache(ext2_filsys fs, unsigned int cache_size)
 {
-	unsigned	i;
 	errcode_t	retval;
 
 	if (fs->icache)
@@ -112,22 +236,12 @@ errcode_t ext2fs_create_inode_cache(ext2_filsys fs, unsigned int cache_size)
 		goto errout;
 
 	fs->icache->buffer_blk = 0;
-	fs->icache->cache_last = -1;
-	fs->icache->cache_size = cache_size;
 	fs->icache->refcount = 1;
-	retval = ext2fs_get_array(fs->icache->cache_size,
-				  sizeof(struct ext2_inode_cache_ent),
-				  &fs->icache->cache);
+	retval = cache_init(0, cache_size, &ext2_inode_cache_ops,
+			    &fs->icache->cache);
 	if (retval)
 		goto errout;
 
-	for (i = 0; i < fs->icache->cache_size; i++) {
-		retval = ext2fs_get_mem(EXT2_INODE_SIZE(fs->super),
-					&fs->icache->cache[i].inode);
-		if (retval)
-			goto errout;
-	}
-
 	ext2fs_flush_icache(fs);
 	return 0;
 errout:
@@ -762,12 +876,12 @@ errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
 	unsigned long 	block, offset;
 	char 		*ptr;
 	errcode_t	retval;
-	unsigned	i;
 	int		clen, inodes_per_block;
 	io_channel	io;
 	int		length = EXT2_INODE_SIZE(fs->super);
 	struct ext2_inode_large	*iptr;
-	int		cache_slot, fail_csum;
+	struct ext2_inode_cache_ent *ent = NULL;
+	int		fail_csum;
 
 	EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
 
@@ -794,12 +908,12 @@ errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
 			return retval;
 	}
 	/* Check to see if it's in the inode cache */
-	for (i = 0; i < fs->icache->cache_size; i++) {
-		if (fs->icache->cache[i].ino == ino) {
-			memcpy(inode, fs->icache->cache[i].inode,
-			       (bufsize > length) ? length : bufsize);
-			return 0;
-		}
+	ext2_inode_cache_iget(fs, ino, CACHE_GET_INCORE, &ent);
+	if (ent) {
+		memcpy(inode, ent->raw, (bufsize > length) ? length : bufsize);
+		ext2_inode_cache_ibump(fs, ent);
+		ext2_inode_cache_iput(fs, ent);
+		return 0;
 	}
 	if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
 		inodes_per_block = fs->blocksize / EXT2_INODE_SIZE(fs->super);
@@ -827,8 +941,10 @@ errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
 	}
 	offset &= (EXT2_BLOCK_SIZE(fs->super) - 1);
 
-	cache_slot = (fs->icache->cache_last + 1) % fs->icache->cache_size;
-	iptr = (struct ext2_inode_large *)fs->icache->cache[cache_slot].inode;
+	retval = ext2_inode_cache_iget(fs, ino, 0, &ent);
+	if (retval)
+		return retval;
+	iptr = (struct ext2_inode_large *)ent->raw;
 
 	ptr = (char *) iptr;
 	while (length) {
@@ -863,13 +979,15 @@ errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
 			       0, length);
 #endif
 
-	/* Update the inode cache bookkeeping */
-	if (!fail_csum) {
-		fs->icache->cache_last = cache_slot;
-		fs->icache->cache[cache_slot].ino = ino;
-	}
 	memcpy(inode, iptr, (bufsize > length) ? length : bufsize);
 
+	/* Update the inode cache bookkeeping */
+	if (!fail_csum)
+		ext2_inode_cache_ibump(fs, ent);
+	ext2_inode_cache_iput(fs, ent);
+	if (fail_csum)
+		ext2_inode_cache_ipurge(fs, ino, ent);
+
 	if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) &&
 	    !(flags & READ_INODE_NOCSUM) && fail_csum)
 		return EXT2_ET_INODE_CSUM_INVALID;
@@ -899,8 +1017,8 @@ errcode_t ext2fs_write_inode2(ext2_filsys fs, ext2_ino_t ino,
 	unsigned long block, offset;
 	errcode_t retval = 0;
 	struct ext2_inode_large *w_inode;
+	struct ext2_inode_cache_ent *ent;
 	char *ptr;
-	unsigned i;
 	int clen;
 	int length = EXT2_INODE_SIZE(fs->super);
 
@@ -933,19 +1051,20 @@ errcode_t ext2fs_write_inode2(ext2_filsys fs, ext2_ino_t ino,
 	}
 
 	/* Check to see if the inode cache needs to be updated */
-	if (fs->icache) {
-		for (i=0; i < fs->icache->cache_size; i++) {
-			if (fs->icache->cache[i].ino == ino) {
-				memcpy(fs->icache->cache[i].inode, inode,
-				       (bufsize > length) ? length : bufsize);
-				break;
-			}
-		}
-	} else {
+	if (!fs->icache) {
 		retval = ext2fs_create_inode_cache(fs, 4);
 		if (retval)
 			goto errout;
 	}
+
+	retval = ext2_inode_cache_iget(fs, ino, 0, &ent);
+	if (retval)
+		goto errout;
+
+	memcpy(ent->raw, inode, (bufsize > length) ? length : bufsize);
+	ext2_inode_cache_ibump(fs, ent);
+	ext2_inode_cache_iput(fs, ent);
+
 	memcpy(w_inode, inode, (bufsize > length) ? length : bufsize);
 
 	if (!(fs->flags & EXT2_FLAG_RW)) {
diff --git a/misc/Makefile.in b/misc/Makefile.in
index 8a3adc70fb736e..5b19cdc96bf4f7 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -115,11 +115,11 @@ SRCS=	$(srcdir)/tune2fs.c $(srcdir)/mklost+found.c $(srcdir)/mke2fs.c $(srcdir)/
 
 LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBSUPPORT)
 DEPLIBS= $(LIBEXT2FS) $(DEPLIBCOM_ERR) $(DEPLIBSUPPORT)
-PROFILED_LIBS= $(LIBSUPPORT) $(PROFILED_LIBEXT2FS) $(PROFILED_LIBCOM_ERR)
-PROFILED_DEPLIBS= $(DEPLIBSUPPORT) $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBCOM_ERR)
+PROFILED_LIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBSUPPORT) $(PROFILED_LIBCOM_ERR)
+PROFILED_DEPLIBS= $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBSUPPORT) $(DEPPROFILED_LIBCOM_ERR)
 
-STATIC_LIBS= $(LIBSUPPORT) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR)
-STATIC_DEPLIBS= $(DEPLIBSUPPORT) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR)
+STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 
 LIBS_E2P= $(LIBE2P) $(LIBCOM_ERR)
 DEPLIBS_E2P= $(LIBE2P) $(DEPLIBCOM_ERR)
diff --git a/resize/Makefile.in b/resize/Makefile.in
index 27f721305e052e..101cdbeaa9f1ef 100644
--- a/resize/Makefile.in
+++ b/resize/Makefile.in
@@ -28,12 +28,13 @@ SRCS= $(srcdir)/extent.c \
 	$(srcdir)/resource_track.c \
 	$(srcdir)/sim_progress.c
 
-LIBS= $(LIBE2P) $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBINTL) $(SYSLIBS)
-DEPLIBS= $(LIBE2P) $(LIBEXT2FS) $(DEPLIBCOM_ERR)
+LIBS= $(LIBE2P) $(LIBEXT2FS) $(LIBSUPPORT) $(LIBCOM_ERR) $(LIBINTL) $(SYSLIBS)
+DEPLIBS= $(LIBE2P) $(LIBEXT2FS) $(DEPLIBSUPPORT) $(DEPLIBCOM_ERR)
 
-STATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \
-	$(LIBINTL) $(SYSLIBS)
-DEPSTATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) 
+STATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \
+	     $(STATIC_LIBCOM_ERR) $(LIBINTL) $(SYSLIBS)
+DEPSTATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) \
+		$(DEPSTATIC_LIBCOM_ERR)
 
 .c.o:
 	$(E) "	CC $<"
diff --git a/tests/fuzz/Makefile.in b/tests/fuzz/Makefile.in
index 949579e7c6501f..2b959f612e2079 100644
--- a/tests/fuzz/Makefile.in
+++ b/tests/fuzz/Makefile.in
@@ -24,9 +24,9 @@ LOCAL_LDFLAGS= @fuzzer_ldflags@
 LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBSUPPORT)
 DEPLIBS= $(LIBEXT2FS) $(DEPLIBCOM_ERR) $(DEPLIBSUPPORT)
 
-STATIC_LIBS= $(LIBSUPPORT) $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) \
+STATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \
 	$(STATIC_LIBCOM_ERR)
-STATIC_DEPLIBS= $(DEPLIBSUPPORT) $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) \
+STATIC_DEPLIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) \
 	$(DEPSTATIC_LIBCOM_ERR)
 
 FUZZ_LDFLAGS= $(ALL_LDFLAGS)
diff --git a/tests/progs/Makefile.in b/tests/progs/Makefile.in
index 1a8e9299a1c1ca..64069a52c57cd3 100644
--- a/tests/progs/Makefile.in
+++ b/tests/progs/Makefile.in
@@ -23,8 +23,8 @@ TEST_ICOUNT_OBJS=	test_icount.o test_icount_cmds.o
 SRCS=	$(srcdir)/test_icount.c \
 	$(srcdir)/test_rel.c
 
-LIBS= $(LIBEXT2FS) $(LIBSS) $(LIBCOM_ERR) $(SYSLIBS)
-DEPLIBS= $(LIBEXT2FS) $(DEPLIBSS) $(DEPLIBCOM_ERR)
+LIBS= $(LIBEXT2FS) $(LIBSUPPORT) $(LIBSS) $(LIBCOM_ERR) $(SYSLIBS)
+DEPLIBS= $(LIBEXT2FS) $(DEPLIBSUPPORT) $(DEPLIBSS) $(DEPLIBCOM_ERR)
 
 .c.o:
 	$(E) "	CC $<"


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/8] libext2fs: fix MMP code to work with unixfd IO manager
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
@ 2026-02-23 23:46   ` Darrick J. Wong
  2026-02-23 23:46   ` [PATCH 2/8] fuse4fs: enable safe service mode Darrick J. Wong
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:46 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

The MMP code wants to be able to read and write the MMP block directly
to storage so that the pagecache does not get in the way.  This is
critical for correct operation of MMP, because it is guarding against
two cluster nodes trying to change the filesystem at the same time.

Unfortunately there's no convenient way to tell an IO manager to perform
a particular IO in directio mode, so the MMP code open()s the filesystem
source device a second time so that it can set O_DIRECT and maintain its
own file position independently of the IO channel.  This is a gross
layering violation.

For unprivileged containerized fuse4fs, we're going to have a privileged
mount helper pass us the fd to the block device, so we'll be using the
unixfd IO manager.  Unfortunately, if the unixfd IO manager is in use,
the filesystem "source" will be a string representation of the fd
number, and MMP breaks.

Fix this (sort of) by detecting the unixfd IO manager and duplicating
the open fd if it's in use.  This adds a requirement that the unixfd
originally be opened in O_DIRECT mode if the filesystem is on a block
device, but that's the best we can do here.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/ext2fs/ext2fs.h |    1 +
 lib/ext2fs/mmp.c    |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 1 deletion(-)


diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 38d6074fdbbc87..23b0695a32d150 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -229,6 +229,7 @@ typedef struct ext2_file *ext2_file_t;
  * Internal flags for use by the ext2fs library only
  */
 #define EXT2_FLAG2_USE_FAKE_TIME	0x000000001
+#define EXT2_FLAG2_MMP_USE_IOCHANNEL	0x000000002
 
 /*
  * Special flag in the ext2 inode i_flag field that means that this is
diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c
index e2823732e2b6a2..5e7c0be5a48aeb 100644
--- a/lib/ext2fs/mmp.c
+++ b/lib/ext2fs/mmp.c
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <limits.h>
 
 #include "ext2fs/ext2_fs.h"
 #include "ext2fs/ext2fs.h"
@@ -48,6 +49,74 @@ errcode_t ext2fs_mmp_get_mem(ext2_filsys fs, void **ptr)
 	return ext2fs_get_memalign(fs->blocksize, align, ptr);
 }
 
+static int possibly_unixfd(ext2_filsys fs)
+{
+	char *endptr = NULL;
+
+	if (fs->io->manager == unixfd_io_manager)
+		return 1;
+
+	/*
+	 * Due to the possibility of stacking IO managers, it's possible that
+	 * there's a unixfd IO manager under all of this.  We can guess the
+	 * presence of one if the device_name is a string representation of an
+	 * integer (fd) number.
+	 */
+	errno = 0;
+	strtol(fs->device_name, &endptr, 10);
+	return !errno && endptr == fs->device_name + strlen(fs->device_name);
+}
+
+static int ext2fs_mmp_open_device(ext2_filsys fs, int flags)
+{
+	struct stat st;
+	int maybe_fd = -1;
+	int new_fd;
+	int want_directio = 1;
+	int ret;
+	errcode_t retval = 0;
+
+	/*
+	 * If the unixfd IO manager is in use, extract the fd number from the
+	 * unixfd IO manager so we can reuse it below.
+	 *
+	 * If that fails, fall back to opening the filesystem device, which is
+	 * the preferred method.
+	 */
+	if (possibly_unixfd(fs))
+		retval = io_channel_get_fd(fs->io, &maybe_fd);
+	if (retval || maybe_fd < 0)
+		return open(fs->device_name, flags);
+
+	/*
+	 * We extracted the fd from the unixfd IO manager.  Skip directio if
+	 * this is a regular file, just ext2fs_mmp_read does.
+	 */
+	ret = fstat(maybe_fd, &st);
+	if (ret == 0 && S_ISREG(st.st_mode))
+		want_directio = 0;
+
+	/* Duplicate the fd so that the MMP code can close it later */
+	new_fd = dup(maybe_fd);
+	if (new_fd < 0)
+		return -1;
+
+	/* Make sure we actually got directio if that's required */
+	if (want_directio) {
+		ret = fcntl(new_fd, F_GETFL);
+		if (ret < 0 || !(ret & O_DIRECT))
+			return -1;
+	}
+
+	/*
+	 * The MMP fd is a duplicate of the io channel fd, so we must use that
+	 * for all MMP block accesses because the two fds share the same file
+	 * position and O_DIRECT state.
+	 */
+	fs->flags2 |= EXT2_FLAG2_MMP_USE_IOCHANNEL;
+	return new_fd;
+}
+
 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 {
 #ifdef CONFIG_MMP
@@ -77,7 +146,7 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 		    S_ISREG(st.st_mode))
 			flags &= ~O_DIRECT;
 
-		fs->mmp_fd = open(fs->device_name, flags);
+		fs->mmp_fd = ext2fs_mmp_open_device(fs, flags);
 		if (fs->mmp_fd < 0) {
 			retval = EXT2_ET_MMP_OPEN_DIRECT;
 			goto out;
@@ -90,6 +159,15 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 			return retval;
 	}
 
+	if (fs->flags2 & EXT2_FLAG2_MMP_USE_IOCHANNEL) {
+		retval = io_channel_read_blk64(fs->io, mmp_blk, -fs->blocksize,
+					       fs->mmp_cmp);
+		if (retval)
+			return retval;
+
+		goto read_compare;
+	}
+
 	if ((blk64_t) ext2fs_llseek(fs->mmp_fd, mmp_blk * fs->blocksize,
 				    SEEK_SET) !=
 	    mmp_blk * fs->blocksize) {
@@ -102,6 +180,7 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 		goto out;
 	}
 
+read_compare:
 	mmp_cmp = fs->mmp_cmp;
 
 	if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) &&
@@ -428,6 +507,7 @@ errcode_t ext2fs_mmp_stop(ext2_filsys fs)
 
 mmp_error:
 	if (fs->mmp_fd > 0) {
+		fs->flags2 &= ~EXT2_FLAG2_MMP_USE_IOCHANNEL;
 		close(fs->mmp_fd);
 		fs->mmp_fd = -1;
 	}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/8] fuse4fs: enable safe service mode
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
  2026-02-23 23:46   ` [PATCH 1/8] libext2fs: fix MMP code to work with unixfd IO manager Darrick J. Wong
@ 2026-02-23 23:46   ` Darrick J. Wong
  2026-02-23 23:47   ` [PATCH 3/8] fuse4fs: set proc title when in fuse " Darrick J. Wong
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:46 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Make it possible to run fuse4fs as a safe systemd service, wherein the
fuse server only has access to the fds that we pass in.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 MCONFIG.in                  |    1 
 configure                   |  135 +++++++++++++++++++++
 configure.ac                |   45 +++++++
 fuse4fs/Makefile.in         |   40 ++++++
 fuse4fs/fuse4fs.c           |  276 ++++++++++++++++++++++++++++++++++++++++++-
 fuse4fs/fuse4fs.socket.in   |   17 +++
 fuse4fs/fuse4fs@.service.in |   99 +++++++++++++++
 lib/config.h.in             |    3 
 util/subst.conf.in          |    2 
 9 files changed, 606 insertions(+), 12 deletions(-)
 create mode 100644 fuse4fs/fuse4fs.socket.in
 create mode 100644 fuse4fs/fuse4fs@.service.in


diff --git a/MCONFIG.in b/MCONFIG.in
index d66e2f3bc1d552..2fcb71d898fef7 100644
--- a/MCONFIG.in
+++ b/MCONFIG.in
@@ -42,6 +42,7 @@ HAVE_CROND = @have_crond@
 CROND_DIR = @crond_dir@
 HAVE_SYSTEMD = @have_systemd@
 SYSTEMD_SYSTEM_UNIT_DIR = @systemd_system_unit_dir@
+HAVE_FUSE_SERVICE = @have_fuse_service@
 
 @SET_MAKE@
 
diff --git a/configure b/configure
index 5db59894242aab..15e9fd92eaf6e7 100755
--- a/configure
+++ b/configure
@@ -697,6 +697,8 @@ UNI_DIFF_OPTS
 SEM_INIT_LIB
 FUSE4FS_CMT
 FUSE2FS_CMT
+fuse_service_socket_dir
+have_fuse_service
 FUSE_LIB
 fuse3_LIBS
 fuse3_CFLAGS
@@ -929,6 +931,7 @@ with_libiconv_prefix
 with_libintl_prefix
 enable_largefile
 with_libarchive
+with_fuse_service_socket_dir
 enable_fuse2fs
 enable_fuse4fs
 enable_lto
@@ -1652,6 +1655,8 @@ Optional Packages:
   --with-libintl-prefix[=DIR]  search for libintl in DIR/include and DIR/lib
   --without-libintl-prefix     don't search for libintl in includedir and libdir
   --without-libarchive    disable use of libarchive
+  --with-fuse-service-socket-dir[=DIR]
+                          Create fuse3 filesystem service sockets in DIR.
   --with-multiarch=ARCH   specify the multiarch triplet
   --with-udev-rules-dir[=DIR]
                           Install udev rules into DIR.
@@ -14746,6 +14751,136 @@ printf "%s\n" "#define HAVE_FUSE_LOWLEVEL 1" >>confdefs.h
 
 fi
 
+have_fuse_service=
+fuse_service_socket_dir=
+if test -n "$have_fuse_lowlevel"
+then
+
+# Check whether --with-fuse_service_socket_dir was given.
+if test ${with_fuse_service_socket_dir+y}
+then :
+  withval=$with_fuse_service_socket_dir;
+else case e in #(
+  e) with_fuse_service_socket_dir=yes ;;
+esac
+fi
+
+	if test "x${with_fuse_service_socket_dir}" != "xno"
+then :
+
+		if test "x${with_fuse_service_socket_dir}" = "xyes"
+then :
+
+
+pkg_failed=no
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fuse3" >&5
+printf %s "checking for fuse3... " >&6; }
+
+if test -n "$fuse3_CFLAGS"; then
+    pkg_cv_fuse3_CFLAGS="$fuse3_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"fuse3\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "fuse3") 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_fuse3_CFLAGS=`$PKG_CONFIG --cflags "fuse3" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$fuse3_LIBS"; then
+    pkg_cv_fuse3_LIBS="$fuse3_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"fuse3\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "fuse3") 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_fuse3_LIBS=`$PKG_CONFIG --libs "fuse3" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+                fuse3_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "fuse3" 2>&1`
+        else
+                fuse3_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "fuse3" 2>&1`
+        fi
+        # Put the nasty error message in config.log where it belongs
+        echo "$fuse3_PKG_ERRORS" >&5
+
+
+				with_fuse_service_socket_dir=""
+
+elif test $pkg_failed = untried; then
+        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+
+				with_fuse_service_socket_dir=""
+
+else
+        fuse3_CFLAGS=$pkg_cv_fuse3_CFLAGS
+        fuse3_LIBS=$pkg_cv_fuse3_LIBS
+        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
+
+				with_fuse_service_socket_dir="$($PKG_CONFIG --variable=service_socket_dir fuse3)"
+
+fi
+
+
+fi
+		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fuse3 service socket dir" >&5
+printf %s "checking for fuse3 service socket dir... " >&6; }
+		fuse_service_socket_dir="${with_fuse_service_socket_dir}"
+		if test -n "${fuse_service_socket_dir}"
+then :
+
+			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${fuse_service_socket_dir}" >&5
+printf "%s\n" "${fuse_service_socket_dir}" >&6; }
+			have_fuse_service="yes"
+
+else case e in #(
+  e)
+			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+			have_fuse_service="no"
+		   ;;
+esac
+fi
+
+fi
+fi
+
+
+if test "$have_fuse_service" = yes
+then
+
+printf "%s\n" "#define HAVE_FUSE_SERVICE 1" >>confdefs.h
+
+fi
+
 FUSE2FS_CMT=
 # Check whether --enable-fuse2fs was given.
 if test ${enable_fuse2fs+y}
diff --git a/configure.ac b/configure.ac
index f1bffa88b80fa4..8aa25ca7585f32 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1478,6 +1478,51 @@ then
 		  [Define to 1 if fuse supports lowlevel API])
 fi
 
+dnl
+dnl Check if the FUSE library tells us where to put fs service sockets
+dnl
+have_fuse_service=
+fuse_service_socket_dir=
+if test -n "$have_fuse_lowlevel"
+then
+	AC_ARG_WITH([fuse_service_socket_dir],
+	  [AS_HELP_STRING([--with-fuse-service-socket-dir@<:@=DIR@:>@],
+		  [Create fuse3 filesystem service sockets in DIR.])],
+	  [],
+	  [with_fuse_service_socket_dir=yes])
+	AS_IF([test "x${with_fuse_service_socket_dir}" != "xno"],
+	  [
+		AS_IF([test "x${with_fuse_service_socket_dir}" = "xyes"],
+		  [
+			PKG_CHECK_MODULES([fuse3], [fuse3],
+			  [
+				with_fuse_service_socket_dir="$($PKG_CONFIG --variable=service_socket_dir fuse3)"
+			  ], [
+				with_fuse_service_socket_dir=""
+			  ])
+			m4_pattern_allow([^PKG_(MAJOR|MINOR|BUILD|REVISION)$])
+		  ])
+		AC_MSG_CHECKING([for fuse3 service socket dir])
+		fuse_service_socket_dir="${with_fuse_service_socket_dir}"
+		AS_IF([test -n "${fuse_service_socket_dir}"],
+		  [
+			AC_MSG_RESULT(${fuse_service_socket_dir})
+			have_fuse_service="yes"
+		  ],
+		  [
+			AC_MSG_RESULT(no)
+			have_fuse_service="no"
+		  ])
+	  ],
+	  [])
+fi
+AC_SUBST(have_fuse_service)
+AC_SUBST(fuse_service_socket_dir)
+if test "$have_fuse_service" = yes
+then
+	AC_DEFINE(HAVE_FUSE_SERVICE, 1, [Define to 1 if fuse supports service])
+fi
+
 dnl
 dnl Check if fuse2fs is actually built.
 dnl
diff --git a/fuse4fs/Makefile.in b/fuse4fs/Makefile.in
index 31afbd8def1de6..119fb1f37ad1ae 100644
--- a/fuse4fs/Makefile.in
+++ b/fuse4fs/Makefile.in
@@ -17,6 +17,13 @@ UMANPAGES=
 @FUSE4FS_CMT@UPROGS+=fuse4fs
 @FUSE4FS_CMT@UMANPAGES+=fuse4fs.1
 
+ifeq ($(HAVE_SYSTEMD),yes)
+SERVICE_FILES	+= fuse4fs.socket fuse4fs@.service
+INSTALLDIRS_TGT	+= installdirs-systemd
+INSTALL_TGT	+= install-systemd
+UNINSTALL_TGT	+= uninstall-systemd
+endif
+
 FUSE4FS_OBJS=	fuse4fs.o journal.o recovery.o revoke.o
 
 PROFILED_FUSE4FS_OJBS=	profiled/fuse4fs.o profiled/journal.o \
@@ -54,7 +61,7 @@ DEPEND_CFLAGS = -I$(top_srcdir)/e2fsck
 @PROFILE_CMT@	$(Q) $(CC) $(ALL_CFLAGS) -g -pg -o profiled/$*.o -c $<
 
 all:: profiled $(SPROGS) $(UPROGS) $(USPROGS) $(SMANPAGES) $(UMANPAGES) \
-	$(FMANPAGES) $(LPROGS)
+	$(FMANPAGES) $(LPROGS) $(SERVICE_FILES)
 
 all-static::
 
@@ -71,6 +78,14 @@ fuse4fs: $(FUSE4FS_OBJS) $(DEPLIBS) $(DEPLIBBLKID) $(DEPLIBUUID) \
 		$(LIBFUSE) $(LIBBLKID) $(LIBUUID) $(LIBEXT2FS) $(LIBINTL) \
 		$(CLOCK_GETTIME_LIB) $(SYSLIBS) $(LIBS_E2P)
 
+%.socket: %.socket.in $(DEP_SUBSTITUTE)
+	$(E) "	SUBST $@"
+	$(Q) $(SUBSTITUTE_UPTIME) $< $@
+
+%.service: %.service.in $(DEP_SUBSTITUTE)
+	$(E) "	SUBST $@"
+	$(Q) $(SUBSTITUTE_UPTIME) $< $@
+
 journal.o: $(srcdir)/../debugfs/journal.c
 	$(E) "	CC $<"
 	$(Q) $(CC) -c $(JOURNAL_CFLAGS) -I$(srcdir) \
@@ -93,11 +108,15 @@ fuse4fs.1: $(DEP_SUBSTITUTE) $(srcdir)/fuse4fs.1.in
 	$(E) "	SUBST $@"
 	$(Q) $(SUBSTITUTE_UPTIME) $(srcdir)/fuse4fs.1.in fuse4fs.1
 
-installdirs:
+installdirs: $(INSTALLDIRS_TGT)
 	$(E) "	MKDIR_P $(bindir) $(man1dir)"
 	$(Q) $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir)
 
-install: all $(UMANPAGES) installdirs
+installdirs-systemd:
+	$(E) "	MKDIR_P $(SYSTEMD_SYSTEM_UNIT_DIR)"
+	$(Q) $(MKDIR_P) $(DESTDIR)$(SYSTEMD_SYSTEM_UNIT_DIR)
+
+install: all $(UMANPAGES) installdirs $(INSTALL_TGT)
 	$(Q) for i in $(UPROGS); do \
 		$(ES) "	INSTALL $(bindir)/$$i"; \
 		$(INSTALL_PROGRAM) $$i $(DESTDIR)$(bindir)/$$i; \
@@ -110,13 +129,19 @@ install: all $(UMANPAGES) installdirs
 		$(INSTALL_DATA) $$i $(DESTDIR)$(man1dir)/$$i; \
 	done
 
+install-systemd: $(SERVICE_FILES) installdirs-systemd
+	$(Q) for i in $(SERVICE_FILES); do \
+		$(ES) "	INSTALL_DATA $(SYSTEMD_SYSTEM_UNIT_DIR)/$$i"; \
+		$(INSTALL_DATA) $$i $(DESTDIR)$(SYSTEMD_SYSTEM_UNIT_DIR)/$$i; \
+	done
+
 install-strip: install
 	$(Q) for i in $(UPROGS); do \
 		$(E) "	STRIP $(bindir)/$$i"; \
 		$(STRIP) $(DESTDIR)$(bindir)/$$i; \
 	done
 
-uninstall:
+uninstall: $(UNINSTALL_TGT)
 	for i in $(UPROGS); do \
 		$(RM) -f $(DESTDIR)$(bindir)/$$i; \
 	done
@@ -124,9 +149,16 @@ uninstall:
 		$(RM) -f $(DESTDIR)$(man1dir)/$$i; \
 	done
 
+uninstall-systemd:
+	for i in $(SERVICE_FILES); do \
+		$(RM) -f $(DESTDIR)$(SYSTEMD_SYSTEM_UNIT_DIR)/$$i; \
+	done
+
 clean::
 	$(RM) -f $(UPROGS) $(UMANPAGES) profile.h \
 		fuse4fs.profiled \
+		$(SERVICE_FILES) \
+		fuse4fs.socket \
 		profiled/*.o \#* *.s *.o *.a *~ core gmon.out
 
 mostlyclean: clean
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 1a4ac0cd9a038f..acb6402a174ad3 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -46,6 +46,10 @@
 # define _FILE_OFFSET_BITS 64
 #endif /* _FILE_OFFSET_BITS */
 #include <fuse_lowlevel.h>
+#ifdef HAVE_FUSE_SERVICE
+# include <sys/mount.h>
+# include <fuse_service.h>
+#endif
 #ifdef __SET_FOB_FOR_FUSE
 # undef _FILE_OFFSET_BITS
 #endif /* __SET_FOB_FOR_FUSE */
@@ -314,8 +318,22 @@ struct fuse4fs {
 #endif
 	struct fuse_session *fuse;
 	struct cache inodes;
+#ifdef HAVE_FUSE_SERVICE
+	struct fuse_service *service;
+	int bdev_fd;
+	int fusedev_fd;
+#endif
 };
 
+#ifdef HAVE_FUSE_SERVICE
+static inline bool fuse4fs_is_service(const struct fuse4fs *ff)
+{
+	return fuse_service_accepted(ff->service);
+}
+#else
+# define fuse4fs_is_service(...)		(false)
+#endif
+
 #define FUSE4FS_CHECK_HANDLE(req, fh) \
 	do { \
 		if ((fh) == NULL || (fh)->magic != FUSE4FS_FILE_MAGIC) { \
@@ -915,7 +933,11 @@ static inline void fuse4fs_discover_iomap(struct fuse4fs *ff)
 	if (ff->iomap_want == FT_DISABLE)
 		return;
 
+#ifdef HAVE_FUSE_SERVICE
+	ff->iomap_cap = fuse_lowlevel_discover_iomap(ff->fusedev_fd);
+#else
 	ff->iomap_cap = fuse_lowlevel_discover_iomap(-1);
+#endif
 }
 
 static inline bool fuse4fs_can_iomap(const struct fuse4fs *ff)
@@ -1410,6 +1432,176 @@ static errcode_t fuse4fs_check_support(struct fuse4fs *ff)
 	return 0;
 }
 
+#ifdef HAVE_FUSE_SERVICE
+static int fuse4fs_service_connect(struct fuse4fs *ff, struct fuse_args *args)
+{
+	int ret;
+
+	ret = fuse_service_accept(&ff->service);
+	if (ret)
+		return ret;
+
+	if (fuse4fs_is_service(ff))
+		fuse_service_append_args(ff->service, args);
+
+	return 0;
+}
+
+static inline int
+fuse4fs_service_parse_cmdline(struct fuse_args *args,
+			      struct fuse_cmdline_opts *opts)
+{
+	return fuse_service_parse_cmdline_opts(args, opts);
+}
+
+static void fuse4fs_service_release(struct fuse4fs *ff, int mount_ret)
+{
+	if (fuse4fs_is_service(ff)) {
+		fuse_service_send_goodbye(ff->service, mount_ret);
+		fuse_service_release(ff->service);
+	}
+}
+
+static void fuse4fs_service_close_bdev(struct fuse4fs *ff)
+{
+	if (ff->bdev_fd >= 0)
+		close(ff->bdev_fd);
+	ff->bdev_fd = -1;
+}
+
+static int fuse4fs_service_finish(struct fuse4fs *ff, int ret)
+{
+	if (!fuse4fs_is_service(ff))
+		return ret;
+
+	fuse_service_destroy(&ff->service);
+	close(ff->bdev_fd);
+	ff->bdev_fd = -1;
+
+	/*
+	 * If we're being run as a service, the return code must fit the LSB
+	 * init script action error guidelines, which is to say that we
+	 * compress all errors to 1 ("generic or unspecified error", LSB 5.0
+	 * section 22.2) and hope the admin will scan the log for what actually
+	 * happened.
+	 *
+	 * We have to sleep 2 seconds here because journald uses the pid to
+	 * connect our log messages to the systemd service.  This is critical
+	 * for capturing all the log messages if fuse4fs fails, because any
+	 * program scraping the journalctl output needs to see all of our
+	 * output.
+	 */
+	sleep(2);
+	if (ret != EXIT_SUCCESS)
+		return EXIT_FAILURE;
+	return EXIT_SUCCESS;
+}
+
+static int fuse4fs_service_get_config(struct fuse4fs *ff)
+{
+	double deadline = init_deadline(FUSE4FS_OPEN_TIMEOUT);
+	int open_flags = O_RDWR | O_EXCL;
+	int ret;
+
+	do {
+		ret = fuse_service_request_file(ff->service, ff->device,
+						open_flags, 0, 0);
+		if (ret)
+			return ret;
+
+		ret = fuse_service_receive_file(ff->service, ff->device,
+						&ff->bdev_fd);
+		if (ret)
+			return ret;
+
+		if (ff->bdev_fd < 0 &&
+		    (errno == EPERM || errno == EACCES) &&
+		    (open_flags & O_ACCMODE) != O_RDONLY) {
+			open_flags = O_RDONLY | O_EXCL;
+
+			/* Force the loop to run once more */
+			ret = 1;
+		}
+	} while (ret == 1 ||
+		 (ff->bdev_fd < 0 && errno == EBUSY &&
+		  retry_before_deadline(deadline)));
+	if (ff->bdev_fd < 0) {
+		err_printf(ff, "%s %s: %s.\n", _("opening device"), ff->device,
+			   strerror(errno));
+		return -1;
+	}
+
+	ret = fuse_service_finish_file_requests(ff->service);
+	if (ret)
+		return ret;
+
+	ff->fusedev_fd = fuse_service_take_fusedev(ff->service);
+	return 0;
+}
+
+static errcode_t fuse4fs_service_openfs(struct fuse4fs *ff, char *options,
+					int flags)
+{
+	char path[32];
+
+	snprintf(path, sizeof(path), "%d", ff->bdev_fd);
+	iocache_set_backing_manager(unixfd_io_manager);
+	return ext2fs_open2(path, options, flags, 0, 0, iocache_io_manager,
+			&ff->fs);
+}
+
+static int fuse4fs_service_configure_iomap(struct fuse4fs *ff)
+{
+	int error = 0;
+	int ret;
+
+	ret = fuse_service_configure_iomap(ff->service,
+					   ff->iomap_want == FT_ENABLE,
+					   &error);
+	if (ret)
+		return -1;
+
+	if (error) {
+		err_printf(ff, "%s: %s.\n", _("enabling iomap"),
+			   strerror(error));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int fuse4fs_service(struct fuse4fs *ff, struct fuse_session *se,
+			   const char *mountpoint)
+{
+	char path[32];
+	int ret = 0;
+
+	snprintf(path, sizeof(path), "/dev/fd/%d", ff->fusedev_fd);
+	ret = fuse_session_mount(se, path);
+	if (ret)
+		return ret;
+
+	ret = fuse_service_mount(ff->service, se, mountpoint);
+	if (ret) {
+		err_printf(ff, "%s: %s\n", _("mounting filesystem"),
+			   strerror(errno));
+		return ret;
+	}
+
+	return 0;
+}
+#else
+# define fuse4fs_service_connect(...)		(0)
+# define fuse4fs_service_parse_cmdline(...)	(EOPNOTSUPP)
+# define fuse4fs_service_release(...)		((void)0)
+# define fuse4fs_service_close_bdev(...)	((void)0)
+# define fuse4fs_service_finish(fctx, ret)	(ret)
+# define fuse4fs_service_get_config(...)	(EOPNOTSUPP)
+# define fuse4fs_service_openfs(...)		(EOPNOTSUPP)
+# define fuse4fs_service_configure_iomap(...)	(EOPNOTSUPP)
+# define fuse4fs_service(...)			(EOPNOTSUPP)
+#endif
+
 static errcode_t fuse4fs_acquire_lockfile(struct fuse4fs *ff)
 {
 	char *resolved;
@@ -1469,6 +1661,10 @@ static int fuse4fs_try_losetup(struct fuse4fs *ff, int flags)
 	if (!fuse4fs_can_iomap(ff))
 		return 0;
 
+	/* Service helper does the losetup */
+	if (fuse4fs_is_service(ff))
+		return 0;
+
 	/* open the actual target device, see if it's a regular file */
 	dev_fd = open(ff->device, rw ? O_RDWR : O_RDONLY);
 	if (dev_fd < 0) {
@@ -1546,6 +1742,7 @@ static void fuse4fs_unmount(struct fuse4fs *ff)
 				   uuid);
 	}
 
+	fuse4fs_service_close_bdev(ff);
 	fuse4fs_undo_losetup(ff);
 
 	if (ff->lockfile)
@@ -1612,8 +1809,11 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 	 */
 	deadline = init_deadline(FUSE4FS_OPEN_TIMEOUT);
 	do {
-		err = ext2fs_open2(fuse4fs_device(ff), options, flags, 0, 0,
-				   iocache_io_manager, &ff->fs);
+		if (fuse4fs_is_service(ff))
+			err = fuse4fs_service_openfs(ff, options, flags);
+		else
+			err = ext2fs_open2(fuse4fs_device(ff), options, flags,
+					   0, 0, iocache_io_manager, &ff->fs);
 		if ((err == EPERM || err == EACCES) &&
 		    (!ff->ro || (flags & EXT2_FLAG_RW))) {
 			/*
@@ -1976,6 +2176,10 @@ static int fuse4fs_setup_logging(struct fuse4fs *ff)
 	if (logfile)
 		return fuse4fs_capture_output(ff, logfile);
 
+	/* systemd already hooked us up to /dev/ttyprintk */
+	if (fuse4fs_is_service(ff))
+		return 0;
+
 	/* in kernel mode, try to log errors to the kernel log */
 	if (ff->kernel)
 		fuse4fs_capture_output(ff, "/dev/ttyprintk");
@@ -7906,14 +8110,13 @@ static const char *get_subtype(const char *argv0)
 }
 
 static void fuse4fs_compute_libfuse_args(struct fuse4fs *ff,
-					 struct fuse_args *args,
-					 const char *argv0)
+					 struct fuse_args *args)
 {
 	char extra_args[BUFSIZ];
 
 	/* Set up default fuse parameters */
 	snprintf(extra_args, BUFSIZ, "-osubtype=%s,fsname=%s",
-		 get_subtype(argv0),
+		 get_subtype(args->argv[0]),
 		 ff->device);
 	if (ff->no_default_opts == 0)
 		fuse_opt_add_arg(args, extra_args);
@@ -8032,7 +8235,11 @@ static int fuse4fs_main(struct fuse_args *args, struct fuse4fs *ff)
 	struct fuse_loop_config *loop_config = NULL;
 	int ret;
 
-	if (fuse_parse_cmdline(args, &opts) != 0) {
+	if (fuse4fs_is_service(ff))
+		ret = fuse4fs_service_parse_cmdline(args, &opts);
+	else
+		ret = fuse_parse_cmdline(args, &opts);
+	if (ret != 0) {
 		ret = 1;
 		goto out;
 	}
@@ -8065,7 +8272,18 @@ static int fuse4fs_main(struct fuse_args *args, struct fuse4fs *ff)
 	}
 	ff->fuse = se;
 
-	if (fuse_session_mount(se, opts.mountpoint) != 0) {
+	if (fuse4fs_is_service(ff)) {
+		/*
+		 * foreground mode is needed so that systemd actually tracks
+		 * the service correctly and doesnt try to kill it; and so that
+		 * stdout/stderr don't get zapped
+		 */
+		opts.foreground = 1;
+		ret = fuse4fs_service(ff, se, opts.mountpoint);
+	} else {
+		ret = fuse_session_mount(se, opts.mountpoint);
+	}
+	if (ret != 0) {
 		ret = 4;
 		goto out_destroy_session;
 	}
@@ -8106,6 +8324,8 @@ static int fuse4fs_main(struct fuse_args *args, struct fuse4fs *ff)
 	fuse_loop_cfg_set_idle_threads(loop_config, opts.max_idle_threads);
 	fuse_loop_cfg_set_max_threads(loop_config, 4);
 
+	fuse4fs_service_release(ff, 0);
+
 	/*
 	 * Try to set ourselves up with fs reclaim disabled to prevent
 	 * recursive reclaim and throttling.  This must be done before starting
@@ -8138,6 +8358,7 @@ static int fuse4fs_main(struct fuse_args *args, struct fuse4fs *ff)
 out_free_opts:
 	free(opts.mountpoint);
 out:
+	fuse4fs_service_release(ff, ret);
 	return ret;
 }
 
@@ -8160,11 +8381,31 @@ int main(int argc, char *argv[])
 		.loop_fd = -1,
 #endif
 		.translate_inums = 1,
+#ifdef HAVE_FUSE_SERVICE
+		.bdev_fd = -1,
+		.fusedev_fd = -1,
+#endif
 	};
 	errcode_t err;
 	FILE *orig_stderr = stderr;
 	int ret;
 
+	/* XXX */
+	if (getenv("FUSE4FS_DEBUGGER")) {
+		char *moo = getenv("FUSE4FS_DEBUGGER");
+		int del = atoi(moo);
+
+		fprintf(stderr, "WAITING %ds FOR DEBUGGER\n", del);
+		fflush(stderr);
+		sleep(del);
+	}
+
+	ret = fuse4fs_service_connect(&fctx, &args);
+	if (ret) {
+		fprintf(stderr, "Could not connect to service socket!\n");
+		exit(1);
+	}
+
 	ret = fuse_opt_parse(&args, &fctx, fuse4fs_opts, fuse4fs_opt_proc);
 	if (ret)
 		exit(1);
@@ -8206,6 +8447,24 @@ int main(int argc, char *argv[])
 		goto out;
 	}
 
+	if (fuse4fs_is_service(&fctx)) {
+		ret = fuse4fs_service_get_config(&fctx);
+		if (ret) {
+			ret = 2;
+			goto out;
+		}
+
+#ifdef HAVE_FUSE_IOMAP
+		if (fctx.iomap_want != FT_DISABLE) {
+			ret = fuse4fs_service_configure_iomap(&fctx);
+			if (ret) {
+				ret = 2;
+				goto out;
+			}
+		}
+#endif
+	}
+
 	try_adjust_oom_score(&fctx);
 
 	/* Will we allow users to allocate every last block? */
@@ -8260,7 +8519,7 @@ int main(int argc, char *argv[])
 	/* Initialize generation counter */
 	get_random_bytes(&fctx.next_generation, sizeof(unsigned int));
 
-	fuse4fs_compute_libfuse_args(&fctx, &args, argv[0]);
+	fuse4fs_compute_libfuse_args(&fctx, &args);
 
 	ret = fuse4fs_main(&args, &fctx);
 	switch(ret) {
@@ -8304,6 +8563,7 @@ int main(int argc, char *argv[])
 	if (fctx.device)
 		free(fctx.device);
 	pthread_mutex_destroy(&fctx.bfl);
+	ret = fuse4fs_service_finish(&fctx, ret);
 	fuse_opt_free_args(&args);
 	return ret;
 }
diff --git a/fuse4fs/fuse4fs.socket.in b/fuse4fs/fuse4fs.socket.in
new file mode 100644
index 00000000000000..0e90a4f0c97f6e
--- /dev/null
+++ b/fuse4fs/fuse4fs.socket.in
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
+# Author: Darrick J. Wong <djwong@kernel.org>
+[Unit]
+Description=Socket for ext4 Service
+
+[Socket]
+ListenSequentialPacket=@fuse_service_socket_dir@/ext2
+ListenSequentialPacket=@fuse_service_socket_dir@/ext3
+ListenSequentialPacket=@fuse_service_socket_dir@/ext4
+Accept=yes
+SocketMode=0660
+RemoveOnStop=yes
+
+[Install]
+WantedBy=sockets.target
diff --git a/fuse4fs/fuse4fs@.service.in b/fuse4fs/fuse4fs@.service.in
new file mode 100644
index 00000000000000..2b9b3e0a69d2ee
--- /dev/null
+++ b/fuse4fs/fuse4fs@.service.in
@@ -0,0 +1,99 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
+# Author: Darrick J. Wong <djwong@kernel.org>
+[Unit]
+Description=ext4 Service
+
+[Service]
+Type=exec
+ExecStart=@bindir@/fuse4fs -o kernel
+
+# Try to capture core dumps
+LimitCORE=infinity
+
+SyslogIdentifier=%N
+
+# No realtime CPU scheduling
+RestrictRealtime=true
+
+# Don't let us see anything in the regular system, and don't run as root
+DynamicUser=true
+ProtectSystem=strict
+ProtectHome=true
+PrivateTmp=true
+PrivateDevices=true
+PrivateUsers=true
+
+# No network access
+PrivateNetwork=true
+ProtectHostname=true
+RestrictAddressFamilies=none
+IPAddressDeny=any
+
+# Don't let the program mess with the kernel configuration at all
+ProtectKernelLogs=true
+ProtectKernelModules=true
+ProtectKernelTunables=true
+ProtectControlGroups=true
+ProtectProc=invisible
+RestrictNamespaces=true
+RestrictFileSystems=
+
+# Hide everything in /proc, even /proc/mounts
+ProcSubset=pid
+
+# Only allow the default personality Linux
+LockPersonality=true
+
+# No writable memory pages
+MemoryDenyWriteExecute=true
+
+# Don't let our mounts leak out to the host
+PrivateMounts=true
+
+# Restrict system calls to the native arch and only enough to get things going
+SystemCallArchitectures=native
+SystemCallFilter=@system-service
+SystemCallFilter=~@privileged
+SystemCallFilter=~@resources
+
+SystemCallFilter=~@clock
+SystemCallFilter=~@cpu-emulation
+SystemCallFilter=~@debug
+SystemCallFilter=~@module
+SystemCallFilter=~@reboot
+SystemCallFilter=~@swap
+
+SystemCallFilter=~@mount
+
+# libfuse io_uring wants to pin cores and memory
+SystemCallFilter=mbind
+SystemCallFilter=sched_setaffinity
+
+# Leave a breadcrumb if we get whacked by the system call filter
+SystemCallErrorNumber=EL3RST
+
+# Log to the kernel dmesg, just like an in-kernel ext4 driver
+StandardOutput=append:/dev/ttyprintk
+StandardError=append:/dev/ttyprintk
+
+# Run with no capabilities at all
+CapabilityBoundingSet=
+AmbientCapabilities=
+NoNewPrivileges=true
+
+# fuse4fs doesn't create files
+UMask=7777
+
+# No access to hardware /dev files at all
+ProtectClock=true
+DevicePolicy=closed
+
+# Don't mess with set[ug]id anything.
+RestrictSUIDSGID=true
+
+# Don't let OOM kills of processes in this containment group kill the whole
+# service, because we don't want filesystem drivers to go down.
+OOMPolicy=continue
+OOMScoreAdjust=-1000
diff --git a/lib/config.h.in b/lib/config.h.in
index 7e045b65131522..8c5ba567a748a8 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -85,6 +85,9 @@
 /* Define to 1 if fuse supports loopdev operations */
 #undef HAVE_FUSE_LOOPDEV
 
+/* Define to 1 if fuse supports service */
+#undef HAVE_FUSE_SERVICE
+
 /* Define to 1 if you have the Mac OS X function
    CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */
 #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES
diff --git a/util/subst.conf.in b/util/subst.conf.in
index 5af5e356d46ac7..5fc7cf8f33fa76 100644
--- a/util/subst.conf.in
+++ b/util/subst.conf.in
@@ -24,3 +24,5 @@ root_bindir		@root_bindir@
 libdir			@libdir@
 $exec_prefix		@exec_prefix@
 pkglibexecdir		@libexecdir@/e2fsprogs
+bindir			@bindir@
+fuse_service_socket_dir	@fuse_service_socket_dir@


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/8] fuse4fs: set proc title when in fuse service mode
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
  2026-02-23 23:46   ` [PATCH 1/8] libext2fs: fix MMP code to work with unixfd IO manager Darrick J. Wong
  2026-02-23 23:46   ` [PATCH 2/8] fuse4fs: enable safe service mode Darrick J. Wong
@ 2026-02-23 23:47   ` Darrick J. Wong
  2026-02-23 23:47   ` [PATCH 4/8] fuse4fs: upsert first file mapping to kernel on open Darrick J. Wong
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:47 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

When in fuse service mode, set the process title so that we can identify
fuse servers by mount arguments.  When the service ends, amend the title
again to say that we're cleaning up.  This is done to make ps aux a bit
more communicative as to what is going on.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 configure           |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac        |    9 ++++++++
 fuse4fs/Makefile.in |    2 +-
 fuse4fs/fuse4fs.c   |   28 +++++++++++++++++++++++++-
 lib/config.h.in     |    3 +++
 5 files changed, 95 insertions(+), 2 deletions(-)


diff --git a/configure b/configure
index 15e9fd92eaf6e7..44bd0e73a74279 100755
--- a/configure
+++ b/configure
@@ -695,6 +695,7 @@ gcc_ranlib
 gcc_ar
 UNI_DIFF_OPTS
 SEM_INIT_LIB
+LIBBSD_LIB
 FUSE4FS_CMT
 FUSE2FS_CMT
 fuse_service_socket_dir
@@ -15061,6 +15062,60 @@ printf "%s\n" "#define HAVE_FUSE_CACHE_READDIR 1" >>confdefs.h
 
 fi
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for setproctitle in -lbsd" >&5
+printf %s "checking for setproctitle in -lbsd... " >&6; }
+if test ${ac_cv_lib_bsd_setproctitle+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) ac_check_lib_save_LIBS=$LIBS
+LIBS="-lbsd  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.
+   The 'extern "C"' is for builds by C++ compilers;
+   although this is not generally supported in C code supporting it here
+   has little cost and some practical benefit (sr 110532).  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char setproctitle (void);
+int
+main (void)
+{
+return setproctitle ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"
+then :
+  ac_cv_lib_bsd_setproctitle=yes
+else case e in #(
+  e) ac_cv_lib_bsd_setproctitle=no ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bsd_setproctitle" >&5
+printf "%s\n" "$ac_cv_lib_bsd_setproctitle" >&6; }
+if test "x$ac_cv_lib_bsd_setproctitle" = xyes
+then :
+  LIBBSD_LIB=-lbsd
+fi
+
+
+if test "$ac_cv_lib_bsd_setproctitle" = yes ; then
+	printf "%s\n" "#define HAVE_SETPROCTITLE 1" >>confdefs.h
+
+fi
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for PR_SET_IO_FLUSHER" >&5
 printf %s "checking for PR_SET_IO_FLUSHER... " >&6; }
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
diff --git a/configure.ac b/configure.ac
index 8aa25ca7585f32..a3162a64123d20 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1625,6 +1625,15 @@ then
 		  [Define to 1 if fuse supports cache_readdir])
 fi
 
+dnl
+dnl see if setproctitle exists
+dnl
+AC_CHECK_LIB(bsd, setproctitle, [LIBBSD_LIB=-lbsd])
+AC_SUBST(LIBBSD_LIB)
+if test "$ac_cv_lib_bsd_setproctitle" = yes ; then
+	AC_DEFINE(HAVE_SETPROCTITLE, 1, Define to 1 if setproctitle])
+fi
+
 dnl
 dnl see if PR_SET_IO_FLUSHER exists
 dnl
diff --git a/fuse4fs/Makefile.in b/fuse4fs/Makefile.in
index 119fb1f37ad1ae..f6473ad0027e51 100644
--- a/fuse4fs/Makefile.in
+++ b/fuse4fs/Makefile.in
@@ -76,7 +76,7 @@ fuse4fs: $(FUSE4FS_OBJS) $(DEPLIBS) $(DEPLIBBLKID) $(DEPLIBUUID) \
 	$(E) "	LD $@"
 	$(Q) $(CC) $(ALL_LDFLAGS) -o fuse4fs $(FUSE4FS_OBJS) $(LIBS) \
 		$(LIBFUSE) $(LIBBLKID) $(LIBUUID) $(LIBEXT2FS) $(LIBINTL) \
-		$(CLOCK_GETTIME_LIB) $(SYSLIBS) $(LIBS_E2P)
+		$(CLOCK_GETTIME_LIB) $(SYSLIBS) $(LIBS_E2P) @LIBBSD_LIB@
 
 %.socket: %.socket.in $(DEP_SUBSTITUTE)
 	$(E) "	SUBST $@"
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index acb6402a174ad3..522afde7c9356b 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -49,6 +49,9 @@
 #ifdef HAVE_FUSE_SERVICE
 # include <sys/mount.h>
 # include <fuse_service.h>
+# ifdef HAVE_SETPROCTITLE
+#  include <bsd/unistd.h>
+# endif
 #endif
 #ifdef __SET_FOB_FOR_FUSE
 # undef _FILE_OFFSET_BITS
@@ -320,6 +323,7 @@ struct fuse4fs {
 	struct cache inodes;
 #ifdef HAVE_FUSE_SERVICE
 	struct fuse_service *service;
+	char *svc_cmdline;
 	int bdev_fd;
 	int fusedev_fd;
 #endif
@@ -1443,10 +1447,21 @@ static int fuse4fs_service_connect(struct fuse4fs *ff, struct fuse_args *args)
 
 	if (fuse4fs_is_service(ff))
 		fuse_service_append_args(ff->service, args);
-
 	return 0;
 }
 
+static void fuse4fs_service_set_proc_cmdline(struct fuse4fs *ff, int argc,
+					     char *argv[],
+					     struct fuse_args *args)
+{
+	setproctitle_init(argc, argv, environ);
+	ff->svc_cmdline = fuse_service_cmdline(argc, argv, args);
+	if (!ff->svc_cmdline)
+		return;
+
+	setproctitle("-%s", ff->svc_cmdline);
+}
+
 static inline int
 fuse4fs_service_parse_cmdline(struct fuse_args *args,
 			      struct fuse_cmdline_opts *opts)
@@ -1491,6 +1506,8 @@ static int fuse4fs_service_finish(struct fuse4fs *ff, int ret)
 	 * program scraping the journalctl output needs to see all of our
 	 * output.
 	 */
+	setproctitle("-%s [cleaning up]", ff->svc_cmdline);
+	free(ff->svc_cmdline);
 	sleep(2);
 	if (ret != EXIT_SUCCESS)
 		return EXIT_FAILURE;
@@ -1592,6 +1609,7 @@ static int fuse4fs_service(struct fuse4fs *ff, struct fuse_session *se,
 }
 #else
 # define fuse4fs_service_connect(...)		(0)
+# define fuse4fs_service_set_proc_cmdline(...)	((void)0)
 # define fuse4fs_service_parse_cmdline(...)	(EOPNOTSUPP)
 # define fuse4fs_service_release(...)		((void)0)
 # define fuse4fs_service_close_bdev(...)	((void)0)
@@ -4341,6 +4359,11 @@ static void detect_linux_executable_open(int kernel_flags, int *access_check,
 }
 #endif /* __linux__ */
 
+static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino,
+				    struct ext2_inode_large *inode, off_t pos,
+				    uint64_t count, uint32_t opflags,
+				    struct fuse_file_iomap *read);
+
 static int fuse4fs_open_file(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 			     ext2_ino_t ino, bool linked,
 			     struct fuse_file_info *fp)
@@ -8406,6 +8429,9 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
+	if (fuse4fs_is_service(&fctx))
+		fuse4fs_service_set_proc_cmdline(&fctx, argc, argv, &args);
+
 	ret = fuse_opt_parse(&args, &fctx, fuse4fs_opts, fuse4fs_opt_proc);
 	if (ret)
 		exit(1);
diff --git a/lib/config.h.in b/lib/config.h.in
index 8c5ba567a748a8..129f7ffcf060f3 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -714,4 +714,7 @@
 /* Define to 1 if CLOCK_MONOTONIC is present */
 #undef HAVE_CLOCK_MONOTONIC
 
+/* Define to 1 if you have the 'setproctitle' function. */
+#undef HAVE_SETPROCTITLE
+
 #include <dirpaths.h>


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 4/8] fuse4fs: upsert first file mapping to kernel on open
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:47   ` [PATCH 3/8] fuse4fs: set proc title when in fuse " Darrick J. Wong
@ 2026-02-23 23:47   ` Darrick J. Wong
  2026-02-23 23:47   ` [PATCH 5/8] fuse4fs: set iomap backing device blocksize Darrick J. Wong
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:47 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Try to speed up the first access to a file by upserting the first
file space mapping to the kernel at open time.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 522afde7c9356b..ad701649886380 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -4364,6 +4364,37 @@ static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino,
 				    uint64_t count, uint32_t opflags,
 				    struct fuse_file_iomap *read);
 
+static void fuse4fs_try_upsert_first_mapping(struct fuse4fs *ff, ext2_ino_t ino,
+					     struct fuse_file_info *fp)
+{
+	struct ext2_inode_large inode;
+	struct fuse_file_iomap read = { };
+	uint64_t fsize;
+	errcode_t err;
+
+	if (!ff->iomap_cache || (fp->flags & O_TRUNC))
+		return;
+
+	err = fuse4fs_read_inode(ff->fs, ino, &inode);
+	if (err)
+		return;
+
+	if (!S_ISREG(inode.i_mode))
+		return;
+
+	fsize = EXT2_I_SIZE(&inode);
+	if (!fsize)
+		return;
+
+	/* try to map the first 64k */
+	err = fuse4fs_iomap_begin_read(ff, ino, &inode, 0, min(fsize, 65536),
+			0, &read);
+	if (err)
+		return;
+
+	fuse_lowlevel_iomap_upsert_mappings(ff->fuse, ino, ino, &read, NULL);
+}
+
 static int fuse4fs_open_file(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 			     ext2_ino_t ino, bool linked,
 			     struct fuse_file_info *fp)
@@ -4458,7 +4489,7 @@ static int fuse4fs_open_file(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 	/* fuse 3.5: cache dirents from readdir contents */
 	fp->cache_readdir = 1;
 #endif
-
+	fuse4fs_try_upsert_first_mapping(ff, ino, fp);
 out:
 	if (ret)
 		ext2fs_free_mem(&file);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 5/8] fuse4fs: set iomap backing device blocksize
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
                     ` (3 preceding siblings ...)
  2026-02-23 23:47   ` [PATCH 4/8] fuse4fs: upsert first file mapping to kernel on open Darrick J. Wong
@ 2026-02-23 23:47   ` Darrick J. Wong
  2026-02-23 23:47   ` [PATCH 6/8] fuse4fs: ask for loop devices when opening via fuservicemount Darrick J. Wong
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:47 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

If we're running as an unprivileged iomap fuse server, we must ask the
kernel to set the blocksize of the block device.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   41 +++++++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 10 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index ad701649886380..9d8dfde95e7256 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -1607,6 +1607,21 @@ static int fuse4fs_service(struct fuse4fs *ff, struct fuse_session *se,
 
 	return 0;
 }
+
+int fuse4fs_service_set_bdev_blocksize(struct fuse4fs *ff, int dev_index)
+{
+	int ret;
+
+	ret = fuse_lowlevel_iomap_set_blocksize(ff->fusedev_fd, dev_index,
+						ff->fs->blocksize);
+	if (ret) {
+		err_printf(ff, "%s: cannot set blocksize %u: %s\n", __func__,
+			   ff->fs->blocksize, strerror(errno));
+		return -EIO;
+	}
+
+	return 0;
+}
 #else
 # define fuse4fs_service_connect(...)		(0)
 # define fuse4fs_service_set_proc_cmdline(...)	((void)0)
@@ -1618,6 +1633,7 @@ static int fuse4fs_service(struct fuse4fs *ff, struct fuse_session *se,
 # define fuse4fs_service_openfs(...)		(EOPNOTSUPP)
 # define fuse4fs_service_configure_iomap(...)	(EOPNOTSUPP)
 # define fuse4fs_service(...)			(EOPNOTSUPP)
+# define fuse4fs_service_set_bdev_blocksize(...) (EOPNOTSUPP)
 #endif
 
 static errcode_t fuse4fs_acquire_lockfile(struct fuse4fs *ff)
@@ -7376,21 +7392,19 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
 {
 	errcode_t err;
 	int fd;
+	int dev_index;
 	int ret;
 
 	err = io_channel_get_fd(ff->fs->io, &fd);
 	if (err)
 		return translate_error(ff->fs, 0, err);
 
-	ret = fuse4fs_set_bdev_blocksize(ff, fd);
-	if (ret)
-		return ret;
-
-	ret = fuse_lowlevel_iomap_device_add(ff->fuse, fd, 0);
-	if (ret < 0) {
-		dbg_printf(ff, "%s: cannot register iomap dev fd=%d, err=%d\n",
-			   __func__, fd, -ret);
-		return translate_error(ff->fs, 0, -ret);
+	dev_index = fuse_lowlevel_iomap_device_add(ff->fuse, fd, 0);
+	if (dev_index < 0) {
+		ret = -dev_index;
+		dbg_printf(ff, "%s: cannot register iomap dev fd=%d: %s\n",
+			   __func__, fd, strerror(ret));
+		return translate_error(ff->fs, 0, ret);
 	}
 
 	dbg_printf(ff, "%s: registered iomap dev fd=%d iomap_dev=%u\n",
@@ -7398,7 +7412,14 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
 
 	fuse4fs_configure_atomic_write(ff, fd);
 
-	ff->iomap_dev = ret;
+	if (fuse4fs_is_service(ff))
+		ret = fuse4fs_service_set_bdev_blocksize(ff, dev_index);
+	else
+		ret = fuse4fs_set_bdev_blocksize(ff, fd);
+	if (ret)
+		return ret;
+
+	ff->iomap_dev = dev_index;
 	return 0;
 }
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 6/8] fuse4fs: ask for loop devices when opening via fuservicemount
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
                     ` (4 preceding siblings ...)
  2026-02-23 23:47   ` [PATCH 5/8] fuse4fs: set iomap backing device blocksize Darrick J. Wong
@ 2026-02-23 23:47   ` Darrick J. Wong
  2026-02-23 23:48   ` [PATCH 7/8] fuse4fs: make MMP work correctly in safe service mode Darrick J. Wong
  2026-02-23 23:48   ` [PATCH 8/8] debian: update packaging for fuse4fs service Darrick J. Wong
  7 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:47 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

When requesting a file, ask the fuservicemount program to transform an
open regular file into a loop device for us, so that we can use iomap
even when the filesystem is actually an image file.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 9d8dfde95e7256..e3d1e080822e16 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -1522,7 +1522,8 @@ static int fuse4fs_service_get_config(struct fuse4fs *ff)
 
 	do {
 		ret = fuse_service_request_file(ff->service, ff->device,
-						open_flags, 0, 0);
+						open_flags, 0,
+						FUSE_SERVICE_REQUEST_FILE_TRYLOOP);
 		if (ret)
 			return ret;
 


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 7/8] fuse4fs: make MMP work correctly in safe service mode
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
                     ` (5 preceding siblings ...)
  2026-02-23 23:47   ` [PATCH 6/8] fuse4fs: ask for loop devices when opening via fuservicemount Darrick J. Wong
@ 2026-02-23 23:48   ` Darrick J. Wong
  2026-02-23 23:48   ` [PATCH 8/8] debian: update packaging for fuse4fs service Darrick J. Wong
  7 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:48 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Normally, the libext2fs MMP code open()s a complete separate file
descriptor to read and write the MMP block so that it can have its own
private open file with its own access mode and file position.  However,
if the unixfd IO manager is in use, it will reuse the io channel, which
means that MMP and the unixfd share the same open file and hence the
access mode and file position.

MMP requires directio access to block devices so that changes are
immediately visible on other nodes.  Therefore, we need the IO channel
(and thus the filesystem) to be running in directio mode if MMP is in
use.

To make this work correctly with the sole unixfd IO manager user
(fuse4fs in unprivileged service mode), we must set O_DIRECT on the
bdev fd and mount the filesystem in directio mode.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 3 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index e3d1e080822e16..b12bd926931a69 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -1558,13 +1558,57 @@ static int fuse4fs_service_get_config(struct fuse4fs *ff)
 }
 
 static errcode_t fuse4fs_service_openfs(struct fuse4fs *ff, char *options,
-					int flags)
+					int *flags)
 {
+	struct stat statbuf;
 	char path[32];
+	errcode_t retval;
+	int ret;
+
+	ret = fstat(ff->bdev_fd, &statbuf);
+	if (ret)
+		return errno;
 
 	snprintf(path, sizeof(path), "%d", ff->bdev_fd);
 	iocache_set_backing_manager(unixfd_io_manager);
-	return ext2fs_open2(path, options, flags, 0, 0, iocache_io_manager,
+
+	/*
+	 * Open the filesystem with SKIP_MMP so that we can find out if the
+	 * filesystem actually has MMP.
+	 */
+	retval = ext2fs_open2(path, options, *flags | EXT2_FLAG_SKIP_MMP, 0, 0,
+			      iocache_io_manager, &ff->fs);
+	if (retval)
+		return retval;
+
+	/*
+	 * If the fs doesn't have MMP then we're good to go.  Otherwise close
+	 * the filesystem so that we can reopen it with MMP enabled.
+	 */
+	if (!ext2fs_has_feature_mmp(ff->fs->super))
+		return 0;
+
+	retval = ext2fs_close_free(&ff->fs);
+	if (retval)
+		return retval;
+
+	/*
+	 * If the filesystem is not on a regular file, MMP will share the same
+	 * fd as the unixfd IO channel.  We need to set O_DIRECT on the bdev_fd
+	 * and open the filesystem in directio mode.
+	 */
+	if (!S_ISREG(statbuf.st_mode)) {
+		int fflags = fcntl(ff->bdev_fd, F_GETFL);
+
+		ret = fcntl(ff->bdev_fd, F_SETFL, fflags | O_DIRECT);
+		if (ret)
+			return EXT2_ET_MMP_OPEN_DIRECT;
+
+		ff->directio = 1;
+		*flags |= EXT2_FLAG_DIRECT_IO;
+	}
+
+	return ext2fs_open2(path, options, *flags, 0, 0, iocache_io_manager,
 			&ff->fs);
 }
 
@@ -1845,7 +1889,7 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)
 	deadline = init_deadline(FUSE4FS_OPEN_TIMEOUT);
 	do {
 		if (fuse4fs_is_service(ff))
-			err = fuse4fs_service_openfs(ff, options, flags);
+			err = fuse4fs_service_openfs(ff, options, &flags);
 		else
 			err = ext2fs_open2(fuse4fs_device(ff), options, flags,
 					   0, 0, iocache_io_manager, &ff->fs);


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 8/8] debian: update packaging for fuse4fs service
  2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
                     ` (6 preceding siblings ...)
  2026-02-23 23:48   ` [PATCH 7/8] fuse4fs: make MMP work correctly in safe service mode Darrick J. Wong
@ 2026-02-23 23:48   ` Darrick J. Wong
  7 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:48 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Update the Debian packaging code so that we can create fuse4fs service
containers.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 debian/e2fsprogs.install |    7 ++++++-
 debian/fuse4fs.install   |    3 +++
 debian/rules             |    3 +++
 3 files changed, 12 insertions(+), 1 deletion(-)
 mode change 100644 => 100755 debian/fuse4fs.install


diff --git a/debian/e2fsprogs.install b/debian/e2fsprogs.install
index 17a80e3922dcee..808474bcab1717 100755
--- a/debian/e2fsprogs.install
+++ b/debian/e2fsprogs.install
@@ -50,4 +50,9 @@ usr/share/man/man8/resize2fs.8
 usr/share/man/man8/tune2fs.8
 etc
 [linux-any] ${deb_udevudevdir}/rules.d
-[linux-any] ${deb_systemdsystemunitdir}
+[linux-any] ${deb_systemdsystemunitdir}/e2scrub@.service
+[linux-any] ${deb_systemdsystemunitdir}/e2scrub@.service
+[linux-any] ${deb_systemdsystemunitdir}/e2scrub_all.service
+[linux-any] ${deb_systemdsystemunitdir}/e2scrub_all.timer
+[linux-any] ${deb_systemdsystemunitdir}/e2scrub_fail@.service
+[linux-any] ${deb_systemdsystemunitdir}/e2scrub_reap.service
diff --git a/debian/fuse4fs.install b/debian/fuse4fs.install
old mode 100644
new mode 100755
index 17bdc90e33cb67..56048136c2b28b
--- a/debian/fuse4fs.install
+++ b/debian/fuse4fs.install
@@ -1,2 +1,5 @@
+#!/usr/bin/dh-exec
 usr/bin/fuse4fs
 usr/share/man/man1/fuse4fs.1
+[linux-any] ${deb_systemdsystemunitdir}/fuse4fs.socket
+[linux-any] ${deb_systemdsystemunitdir}/fuse4fs@.service
diff --git a/debian/rules b/debian/rules
index b680eb33ceac9e..b5c669c58c3a9b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -173,6 +173,9 @@ override_dh_installinfo:
 ifneq ($(DEB_HOST_ARCH_OS), hurd)
 override_dh_installsystemd:
 	dh_installsystemd -p e2fsprogs --no-restart-after-upgrade --no-stop-on-upgrade e2scrub_all.timer e2scrub_reap.service
+ifeq ($(SKIP_FUSE2FS),)
+	dh_installsystemd -p fuse4fs fuse4fs.socket
+endif
 endif
 
 override_dh_makeshlibs:


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/4] libsupport: add pressure stall monitor
  2026-02-23 23:06 ` [PATCHSET v7 7/8] fuse4fs: reclaim buffer cache under memory pressure Darrick J. Wong
@ 2026-02-23 23:48   ` Darrick J. Wong
  2026-02-23 23:48   ` [PATCH 2/4] fuse2fs: only reclaim buffer cache when there is memory pressure Darrick J. Wong
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:48 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Create some monitoring code that will sit in the background and watch
for resource pressure stalls and call some sort of handler when this
happens.  This will be useful for shrinking the buffer cache when memory
gets tight.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/support/psi.h       |   57 +++++
 lib/support/Makefile.in |    4 
 lib/support/iocache.c   |   19 ++
 lib/support/psi.c       |  510 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 590 insertions(+)
 create mode 100644 lib/support/psi.h
 create mode 100644 lib/support/psi.c


diff --git a/lib/support/psi.h b/lib/support/psi.h
new file mode 100644
index 00000000000000..675ebeb553da3e
--- /dev/null
+++ b/lib/support/psi.h
@@ -0,0 +1,57 @@
+/*
+ * psi.h - Pressure stall monitor
+ *
+ * Copyright (C) 2025-2026 Oracle.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+#ifndef __PSI_H__
+#define __PSI_H__
+
+struct psi;
+struct psi_handler;
+
+enum psi_type {
+	PSI_MEMORY,
+};
+
+void psi_destroy(struct psi **psip);
+
+/* call malloc_trim after calling handlers */
+#define PSI_TRIM_HEAP		(1U << 0)
+
+#define PSI_FLAGS		(PSI_TRIM_HEAP)
+
+int psi_create(enum psi_type type, unsigned int psi_flags,
+	       uint64_t stall_us, uint64_t window_us, uint64_t timeout_us,
+	       struct psi **psip);
+
+/* psi triggered due to timeout (and not pressure) */
+#define PSI_REASON_TIMEOUT	(1U << 0)
+
+/*
+ * Prototype of a function to call when a stall occurs.  Implementations must
+ * not block on any resources that are held if psi_stop_thread is called.
+ */
+typedef void (*psi_handler_fn)(const struct psi *psi, unsigned int reasons,
+			       void *data);
+
+int psi_add_handler(struct psi *psi, psi_handler_fn callback, void *data,
+		    struct psi_handler **hanp);
+void psi_del_handler(struct psi *psi, struct psi_handler **hanp);
+void psi_cancel_handler(struct psi *psi, struct psi_handler **hanp);
+
+int psi_start_thread(struct psi *psi);
+void psi_stop_thread(struct psi *psi);
+
+bool psi_thread_cancelled(const struct psi *psi);
+
+static inline bool psi_active(struct psi *psi)
+{
+	return psi != NULL;
+}
+
+#endif /* __PSI_H__ */
diff --git a/lib/support/Makefile.in b/lib/support/Makefile.in
index 2950e80222ee72..dd4cee928fee5c 100644
--- a/lib/support/Makefile.in
+++ b/lib/support/Makefile.in
@@ -23,6 +23,7 @@ OBJS=		bthread.o \
 		print_fs_flags.o \
 		profile_helpers.o \
 		prof_err.o \
+		psi.o \
 		quotaio.o \
 		quotaio_v2.o \
 		quotaio_tree.o \
@@ -40,6 +41,7 @@ SRCS=		$(srcdir)/argv_parse.c \
 		$(srcdir)/profile.c \
 		$(srcdir)/profile_helpers.c \
 		prof_err.c \
+		$(srcdir)/psi.c \
 		$(srcdir)/quotaio.c \
 		$(srcdir)/quotaio_tree.c \
 		$(srcdir)/quotaio_v2.c \
@@ -195,3 +197,5 @@ cache.o: $(srcdir)/cache.c $(top_builddir)/lib/config.h \
  $(srcdir)/cache.h $(srcdir)/list.h $(srcdir)/xbitops.h
 iocache.o: $(srcdir)/iocache.c $(top_builddir)/lib/config.h \
  $(srcdir)/iocache.h $(srcdir)/cache.h $(srcdir)/list.h $(srcdir)/xbitops.h
+psi.o: $(srcdir)/psi.c $(top_builddir)/lib/config.h \
+ $(srcdir)/psi.h $(srcdir)/list.h $(srcdir)/xbitops.h
diff --git a/lib/support/iocache.c b/lib/support/iocache.c
index 478d89174422df..dfb81d3cf58513 100644
--- a/lib/support/iocache.c
+++ b/lib/support/iocache.c
@@ -452,6 +452,20 @@ static errcode_t iocache_set_option(io_channel channel, const char *option,
 	if (!strcmp(option, "cache"))
 		return 0;
 
+	if (!strcmp(option, "cache_auto_shrink")) {
+		if (!arg)
+			return EXT2_ET_INVALID_ARGUMENT;
+		if (!strcmp(arg, "on")) {
+			cache_set_flag(&data->cache, CACHE_AUTO_SHRINK);
+			return 0;
+		}
+		if (!strcmp(arg, "off")) {
+			cache_clear_flag(&data->cache, CACHE_AUTO_SHRINK);
+			return 0;
+		}
+		return EXT2_ET_INVALID_ARGUMENT;
+	}
+
 	if (!strcmp(option, "cache_blocks")) {
 		long long size;
 
@@ -467,6 +481,11 @@ static errcode_t iocache_set_option(io_channel channel, const char *option,
 		return 0;
 	}
 
+	if (!strcmp(option, "cache_shrink")) {
+		cache_shrink(&data->cache);
+		return 0;
+	}
+
 	retval = iocache_flush_cache(data);
 	if (retval)
 		return retval;
diff --git a/lib/support/psi.c b/lib/support/psi.c
new file mode 100644
index 00000000000000..26ce6ee1985641
--- /dev/null
+++ b/lib/support/psi.c
@@ -0,0 +1,510 @@
+/*
+ * psi.c - Pressure stall monitor
+ *
+ * Copyright (C) 2025-2026 Oracle.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+#include "config.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <poll.h>
+#include <pthread.h>
+#include <malloc.h>
+#include <signal.h>
+#include <limits.h>
+
+#include "support/list.h"
+#include "support/psi.h"
+
+enum psi_state {
+	/* waiting to be put in the running state */
+	PSI_WAITING,
+	/* running */
+	PSI_RUNNING,
+	/* cancelled */
+	PSI_CANCELLED,
+};
+
+struct psi_handler {
+	struct list_head list;
+	psi_handler_fn callback;
+	void *data;
+};
+
+struct psi {
+	int system_fd;
+	int cgroup_fd;
+	unsigned int flags;
+	uint64_t timeout_us;
+
+	pthread_t thread;
+	pthread_mutex_t lock;
+	struct list_head handlers;
+
+	enum psi_type type;
+	enum psi_state state;
+};
+
+static const char *psi_system_path(enum psi_type type)
+{
+	switch (type) {
+	case PSI_MEMORY:
+		return "/proc/pressure/memory";
+	default:
+		return NULL;
+	}
+}
+
+static const char *psi_cgroup_fname(enum psi_type type)
+{
+	switch (type) {
+	case PSI_MEMORY:
+		return "memory.pressure";
+	default:
+		return NULL;
+	}
+}
+
+static const char *psi_shortname(enum psi_type type)
+{
+	switch (type) {
+	case PSI_MEMORY:
+		return "psi:memory";
+	default:
+		return NULL;
+	}
+}
+
+static void psi_run_callbacks(struct psi *psi, unsigned int reasons)
+{
+	struct psi_handler *h, *i;
+
+	pthread_mutex_lock(&psi->lock);
+	list_for_each_entry_safe(h, i, &psi->handlers, list)
+		h->callback(psi, reasons, h->data);
+	pthread_mutex_unlock(&psi->lock);
+
+	if (psi->flags & PSI_TRIM_HEAP)
+		malloc_trim(0);
+}
+
+static inline void psi_fill_pollfd(struct pollfd *pfd, int fd)
+{
+	memset(pfd, 0, sizeof(*pfd));
+	pfd->fd = fd;
+	pfd->events = POLLPRI | POLLRDHUP | POLLERR | POLLHUP;
+}
+
+static unsigned int psi_fill_pollfds(struct psi *psi, struct pollfd *pfds)
+{
+	unsigned int ret = 0;
+
+	if (psi->system_fd >= 0) {
+		psi_fill_pollfd(pfds, psi->system_fd);
+		pfds++;
+		ret++;
+	}
+
+	if (psi->cgroup_fd >= 0) {
+		psi_fill_pollfd(pfds, psi->cgroup_fd);
+		pfds++;
+		ret++;
+	}
+
+	return ret;
+}
+
+static void *psi_thread(void *arg)
+{
+	struct psi *psi = arg;
+	int oldstate;
+
+	/*
+	 * Don't let pthread_cancel kill us except while we're in poll()
+	 * because we don't hold any resources during that call.  Everywhere
+	 * else, there could be resource cleanups that would have to be done.
+	 * Hence we just turn off cancelling for simplicity's sake.
+	 */
+	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
+
+	pthread_mutex_lock(&psi->lock);
+	psi->state = PSI_RUNNING;
+	pthread_mutex_unlock(&psi->lock);
+
+	while (1) {
+		struct pollfd pfds[2];
+		unsigned int nr_pfds;
+		int timeout_ms;
+		int n;
+
+		pthread_mutex_lock(&psi->lock);
+		if (psi_thread_cancelled(psi)) {
+			pthread_mutex_unlock(&psi->lock);
+			break;
+		}
+
+		nr_pfds = psi_fill_pollfds(psi, pfds);
+		timeout_ms = psi->timeout_us ? psi->timeout_us / 1000 : -1;
+		pthread_mutex_unlock(&psi->lock);
+
+		pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+		n = poll(pfds, nr_pfds, timeout_ms);
+		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
+		if (n == 0) {
+			/* run callbacks on timeout */
+			psi_run_callbacks(psi, PSI_REASON_TIMEOUT);
+			continue;
+		}
+		if (n < 0) {
+			perror(psi_shortname(psi->type));
+			break;
+		}
+
+		/* psi fd closed */
+		if ((pfds[0].revents & POLLNVAL) ||
+		    (pfds[1].revents & POLLNVAL))
+			break;
+
+		if ((pfds[0].revents & POLLERR) ||
+		    (pfds[1].revents & POLLERR)) {
+			fprintf(stderr, "%s: event source dead?\n",
+				psi_shortname(psi->type));
+			break;
+		}
+
+		/* POLLPRI on a psi fd means we hit the pressure threshold */
+		if ((pfds[0].revents & POLLPRI) ||
+		    (pfds[1].revents & POLLPRI)) {
+			psi_run_callbacks(psi, 0);
+			continue;
+		}
+
+		fprintf(stderr, "%s: unknown events 0x%x/0x%x, ignoring.\n",
+			psi_shortname(psi->type), pfds[0].revents,
+			pfds[1].revents);
+	}
+
+	pthread_setcancelstate(oldstate, NULL);
+	return NULL;
+}
+
+/* Call a function whenever there is resource pressure */
+int psi_add_handler(struct psi *psi, psi_handler_fn callback, void *data,
+		    struct psi_handler **hanp)
+{
+	struct psi_handler *handler;
+
+	handler = malloc(sizeof(*handler));
+	if (!handler)
+		return -1;
+
+	INIT_LIST_HEAD(&handler->list);
+	handler->callback = callback;
+	handler->data = data;
+
+	pthread_mutex_lock(&psi->lock);
+	list_add_tail(&handler->list, &psi->handlers);
+	pthread_mutex_unlock(&psi->lock);
+
+	*hanp = handler;
+	return 0;
+}
+
+/* Stop calling this handler when there is resource pressure */
+void psi_del_handler(struct psi *psi, struct psi_handler **hanp)
+{
+	struct psi_handler *handler = *hanp;
+
+	if (handler) {
+		pthread_mutex_lock(&psi->lock);
+		list_del_init(&handler->list);
+		pthread_mutex_unlock(&psi->lock);
+		free(handler);
+	}
+
+	*hanp = NULL;
+}
+
+/* Cancel a running handler. */
+void psi_cancel_handler(struct psi *psi, struct psi_handler **hanp)
+{
+	struct psi_handler *handler = *hanp;
+
+	if (handler) {
+		list_del_init(&handler->list);
+		free(handler);
+	}
+
+	*hanp = NULL;
+}
+
+/*
+ * Stop monitoring for resource pressure stalls.  The monitor cannot be
+ * restarted after this call completes.
+ */
+void psi_stop_thread(struct psi *psi)
+{
+	int system_fd;
+	int cgroup_fd;
+	enum psi_state old_state;
+
+	pthread_mutex_lock(&psi->lock);
+	system_fd = psi->system_fd;
+	cgroup_fd = psi->cgroup_fd;
+	old_state = psi->state;
+	psi->system_fd = -1;
+	psi->cgroup_fd = -1;
+	psi->state = PSI_CANCELLED;
+	pthread_mutex_unlock(&psi->lock);
+
+	if (system_fd >= 0)
+		close(system_fd);
+	if (cgroup_fd >= 0)
+		close(cgroup_fd);
+
+	if (old_state == PSI_RUNNING) {
+		/* Cancelling the thread interrupts the poll() call */
+		pthread_cancel(psi->thread);
+		pthread_join(psi->thread, NULL);
+	}
+}
+
+/* Is this stall monitor active and its thread running? */
+bool psi_thread_cancelled(const struct psi *psi)
+{
+	return !psi || psi->state == PSI_CANCELLED;
+}
+
+/* Destroy this resource pressure stall monitor having stopped the thread */
+void psi_destroy(struct psi **psip)
+{
+	struct psi *psi = *psip;
+
+	if (psi) {
+		psi_stop_thread(psi);
+		pthread_mutex_destroy(&psi->lock);
+		free(psi);
+	}
+
+	*psip = NULL;
+}
+
+static int psi_open_control(const char *path)
+{
+	return open(path, O_RDWR | O_NONBLOCK);
+}
+
+static void psi_open_system_control(struct psi *psi)
+{
+	/* PSI may not exist, so we don't error if it's not there */
+	psi->system_fd = psi_open_control(psi_system_path(psi->type));
+}
+
+static ssize_t psi_cgroup_path(enum psi_type type, char *path, size_t pathsize)
+{
+	char cgpath[PATH_MAX];
+	char *p = cgpath;
+	ssize_t bytes;
+	int pscgroupfd = open("/proc/self/cgroup", O_RDONLY);
+	int nr_colons = 0;
+
+	/*
+	 * Read the contents of /proc/self/cgroup, which should have the
+	 * format:
+	 *
+	 * <id>:<stuff>:<absolute path under cgroupfs>\n
+	 *
+	 * We care about the cgroupfs path (column 3) and not the newline.
+	 */
+	if (pscgroupfd < 0)
+		return 0;
+
+	bytes = read(pscgroupfd, cgpath, sizeof(cgpath) - 1);
+	close(pscgroupfd);
+	if (bytes < 0)
+		return 0;
+	cgpath[bytes] = 0;
+
+	/*
+	 * Find the second colon, turn it into a dot so that we have a relative
+	 * path.  sysfs paths can contain colons, so this will always be the
+	 * last column... right?
+	 */
+	while (*p != 0) {
+		if (*p == ':')
+			nr_colons++;
+		if (nr_colons == 2) {
+			*p = '.';
+			break;
+		}
+
+		p++;
+	}
+
+	if (nr_colons != 2)
+		return 0;
+
+	/* Trim trailing newline, p points to column 3 */
+	bytes = strlen(p);
+	if (p[bytes - 1] == '\n')
+		p[bytes - 1] = 0;
+
+	/* /sys/fs/cgroup/$col3/$psi_cgroup_fname */
+	return snprintf(path, pathsize, "/sys/fs/cgroup/%s/%s", p,
+			psi_cgroup_fname(type));
+}
+
+static void psi_open_cgroup_control(struct psi *psi)
+{
+	char path[PATH_MAX];
+	ssize_t pathlen;
+
+	pathlen = psi_cgroup_path(psi->type, path, sizeof(path));
+	if (!pathlen || pathlen >= sizeof(path)) {
+		psi->cgroup_fd = -1;
+		return;
+	}
+
+	/* PSI may not exist, so we don't error if it's not there */
+	psi->cgroup_fd = psi_open_control(path);
+}
+
+static int psi_config_fd(struct psi *psi, int fd, uint64_t stall_us,
+			 uint64_t window_us)
+{
+	char buf[256];
+	size_t bytes;
+	ssize_t written;
+
+	if (fd < 0)
+		return 0;
+
+	/*
+	 * The kernel blindly nulls out the last byte we write into the psi
+	 * file, so put a newline at the end because I bet they're only testing
+	 * this with bash scripts.
+	 */
+	bytes = snprintf(buf, sizeof(buf), "some %llu %llu\n",
+			 (unsigned long long)stall_us,
+			 (unsigned long long)window_us);
+	if (bytes > sizeof(buf))
+		return -1;
+
+	written = write(fd, buf, bytes);
+	if (written >= 0 && written != bytes) {
+		written = -1;
+		errno = EMSGSIZE;
+	}
+	if (written < 0) {
+		perror(psi_shortname(psi->type));
+		return -1;
+	}
+
+	return 0;
+}
+
+static inline struct psi *psi_alloc(enum psi_type type, unsigned int psi_flags,
+				    uint64_t timeout_us)
+{
+	struct psi *psi = calloc(1, sizeof(*psi));
+	if (!psi)
+		return NULL;
+
+	psi->type = type;
+	psi->flags = psi_flags;
+	psi->timeout_us = timeout_us;
+	psi->state = PSI_WAITING;
+	INIT_LIST_HEAD(&psi->handlers);
+	pthread_mutex_init(&psi->lock, NULL);
+
+	return psi;
+}
+
+/*
+ * Create a pressure stall indicator monitor thread that monitors for
+ * resource availability stalls exceeding @stall_us in any @window_us time
+ * period and calls any attached handlers.  If @timeout_us is nonzero, the
+ * handlers will be called at that interval with PSI_REASON_TIMEOUT.
+ *
+ * Unprivileged processes are not allowed to set a @window_us that is not a
+ * multiple of 2 seconds(!)
+ *
+ * Returns 0 on success.  On error, returns -1 and sets errno.  errno values
+ * are as follows:
+ *
+ *    ENOENT means the monitor file cannot be found
+ *    EACCESS or EPERM mean that monitoring is not available
+ *    EINVAL means the window values are not valid
+ *    Any other errno is a sign of deeper problems
+ */
+int psi_create(enum psi_type type, unsigned int psi_flags, uint64_t stall_us,
+	       uint64_t window_us, uint64_t timeout_us, struct psi **psip)
+{
+	struct psi *psi;
+	int ret;
+
+	if (psi_flags & ~PSI_FLAGS) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	psi = psi_alloc(type, psi_flags, timeout_us);
+	if (!psi)
+		return -1;
+
+	psi_open_system_control(psi);
+	psi_open_cgroup_control(psi);
+
+	if (psi->system_fd < 0 && psi->cgroup_fd < 0 && !psi->timeout_us) {
+		errno = ENOENT;
+		goto out_fds;
+	}
+
+	ret = psi_config_fd(psi, psi->system_fd, stall_us, window_us);
+	if (ret)
+		goto out_fds;
+
+	ret = psi_config_fd(psi, psi->cgroup_fd, stall_us, window_us);
+	if (ret)
+		goto out_fds;
+
+	*psip = psi;
+	return 0;
+
+out_fds:
+	psi_destroy(&psi);
+	return -1;
+}
+
+/* Start monitoring for resource pressure stalls */
+int psi_start_thread(struct psi *psi)
+{
+	int error;
+
+	if (psi->state != PSI_WAITING) {
+		fprintf(stderr, "%s: psi already torn down\n",
+			psi_shortname(psi->type));
+		errno = EINVAL;
+		return -1;
+	}
+
+	error = pthread_create(&psi->thread, NULL, psi_thread, psi);
+	if (error) {
+		fprintf(stderr, "%s: could not create thread: %s\n",
+			psi_shortname(psi->type), strerror(error));
+		errno = error;
+		return -1;
+	}
+
+	pthread_setname_np(psi->thread, psi_shortname(psi->type));
+	return 0;
+}


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/4] fuse2fs: only reclaim buffer cache when there is memory pressure
  2026-02-23 23:06 ` [PATCHSET v7 7/8] fuse4fs: reclaim buffer cache under memory pressure Darrick J. Wong
  2026-02-23 23:48   ` [PATCH 1/4] libsupport: add pressure stall monitor Darrick J. Wong
@ 2026-02-23 23:48   ` Darrick J. Wong
  2026-02-23 23:49   ` [PATCH 3/4] fuse4fs: enable memory pressure monitoring with service containers Darrick J. Wong
  2026-02-23 23:49   ` [PATCH 4/4] fuse2fs: flush dirty metadata periodically Darrick J. Wong
  3 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:48 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Use the pressure stall indicator library that we added in the previous
patch to make it so that we only shrink the cache when there's memory
pressure.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/Makefile.in |    2 +
 fuse4fs/fuse4fs.c   |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/Makefile.in    |    2 +
 misc/fuse2fs.c      |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 170 insertions(+), 2 deletions(-)


diff --git a/fuse4fs/Makefile.in b/fuse4fs/Makefile.in
index f6473ad0027e51..0600485b074158 100644
--- a/fuse4fs/Makefile.in
+++ b/fuse4fs/Makefile.in
@@ -180,7 +180,7 @@ fuse4fs.o: $(srcdir)/fuse4fs.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/version.h \
  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/cache.h \
  $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h \
- $(top_srcdir)/lib/support/iocache.h
+ $(top_srcdir)/lib/support/iocache.h $(top_srcdir)/lib/support/psi.h
 journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(srcdir)/../debugfs/journal.h \
  $(top_srcdir)/e2fsck/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index b12bd926931a69..87b17491beae13 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -64,6 +64,7 @@
 #include "support/list.h"
 #include "support/cache.h"
 #include "support/iocache.h"
+#include "support/psi.h"
 
 #include "../version.h"
 #include "uuid/uuid.h"
@@ -327,6 +328,8 @@ struct fuse4fs {
 	int bdev_fd;
 	int fusedev_fd;
 #endif
+	struct psi *mem_psi;
+	struct psi_handler *mem_psi_handler;
 };
 
 #ifdef HAVE_FUSE_SERVICE
@@ -908,6 +911,74 @@ static void fuse4fs_mmp_destroy(struct fuse4fs *ff)
 # define fuse4fs_mmp_destroy(...)	((void)0)
 #endif
 
+static void fuse4fs_psi_memory(const struct psi *psi, unsigned int reasons,
+			       void *data)
+{
+	struct fuse4fs *ff = data;
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	fs = fuse4fs_start(ff);
+	dbg_printf(ff, "%s:\n", __func__);
+	if (fs && !psi_thread_cancelled(ff->mem_psi)) {
+		err = io_channel_set_options(fs->io, "cache_shrink");
+		if (err)
+			ret = translate_error(fs, 0, err);
+	} else {
+		psi_cancel_handler(ff->mem_psi, &ff->mem_psi_handler);
+	}
+	fuse4fs_finish(ff, ret);
+}
+
+static int fuse4fs_psi_config(struct fuse4fs *ff)
+{
+	errcode_t err;
+
+	/*
+	 * Activate when there are memory stalls for 200ms every 2s; or
+	 * 5min goes by.  Unprivileged processes can only use 2s windows.
+	 */
+	err = psi_create(PSI_MEMORY, PSI_TRIM_HEAP, 20100, 2000000,
+			 5 * 60 * 1000000, &ff->mem_psi);
+	if (err) {
+		switch (errno) {
+		case ENOENT:
+		case EINVAL:
+		case EACCES:
+		case EPERM:
+			break;
+		default:
+			err_printf(ff, "PSI: %s.\n", error_message(errno));
+			return -1;
+		}
+	}
+
+	err = psi_add_handler(ff->mem_psi, fuse4fs_psi_memory, ff,
+			      &ff->mem_psi_handler);
+	if (err) {
+		err_printf(ff, "PSI: %s.\n", error_message(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+static void fuse4fs_psi_start(struct fuse4fs *ff)
+{
+	if (psi_active(ff->mem_psi))
+		psi_start_thread(ff->mem_psi);
+}
+
+static void fuse4fs_psi_destroy(struct fuse4fs *ff)
+{
+	if (!psi_active(ff->mem_psi))
+		return;
+
+	psi_del_handler(ff->mem_psi, &ff->mem_psi_handler);
+	psi_destroy(&ff->mem_psi);
+}
+
 static inline struct fuse4fs *fuse4fs_get(fuse_req_t req)
 {
 	return (struct fuse4fs *)fuse_req_userdata(req);
@@ -2020,6 +2091,11 @@ static errcode_t fuse4fs_config_cache(struct fuse4fs *ff)
 		return err;
 	}
 
+	if (psi_active(ff->mem_psi)) {
+		snprintf(buf, sizeof(buf), "cache_auto_shrink=off");
+		io_channel_set_options(ff->fs->io, buf);
+	}
+
 	return 0;
 }
 
@@ -2365,6 +2441,7 @@ static void op_init(void *userdata, struct fuse_conn_info *conn)
 	 * conveyed to the new child process.
 	 */
 	fuse4fs_mmp_start(ff);
+	fuse4fs_psi_start(ff);
 
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 17)
 	/*
@@ -8590,6 +8667,12 @@ int main(int argc, char *argv[])
 
 	try_adjust_oom_score(&fctx);
 
+	err = fuse4fs_psi_config(&fctx);
+	if (err) {
+		ret |= 32;
+		goto out;
+	}
+
 	/* Will we allow users to allocate every last block? */
 	if (getenv("FUSE4FS_ALLOC_ALL_BLOCKS")) {
 		log_printf(&fctx, "%s\n",
@@ -8679,6 +8762,7 @@ int main(int argc, char *argv[])
  _("Mount failed while opening filesystem.  Check dmesg(1) for details."));
 		fflush(orig_stderr);
 	}
+	fuse4fs_psi_destroy(&fctx);
 	fuse4fs_mmp_destroy(&fctx);
 	fuse4fs_unmount(&fctx);
 	reset_com_err_hook();
diff --git a/misc/Makefile.in b/misc/Makefile.in
index 5b19cdc96bf4f7..5a37c942188ddc 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -882,7 +882,7 @@ fuse2fs.o: $(srcdir)/fuse2fs.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/version.h \
  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/cache.h \
  $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h \
- $(top_srcdir)/lib/support/iocache.h
+ $(top_srcdir)/lib/support/iocache.h $(top_srcdir)/lib/support/psi.h
 e2fuzz.o: $(srcdir)/e2fuzz.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 4d62b5d44279f9..f2929ae0045bc9 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -56,6 +56,7 @@
 #include "support/list.h"
 #include "support/cache.h"
 #include "support/iocache.h"
+#include "support/psi.h"
 
 #include "../version.h"
 #include "uuid/uuid.h"
@@ -306,6 +307,8 @@ struct fuse2fs {
 	/* options set by fuse_opt_parse must be of type int */
 	int timing;
 #endif
+	struct psi *mem_psi;
+	struct psi_handler *mem_psi_handler;
 };
 
 #define FUSE2FS_CHECK_HANDLE(ff, fh) \
@@ -722,6 +725,74 @@ static void fuse2fs_mmp_destroy(struct fuse2fs *ff)
 # define fuse2fs_mmp_destroy(...)	((void)0)
 #endif
 
+static void fuse2fs_psi_memory(const struct psi *psi, unsigned int reasons,
+			       void *data)
+{
+	struct fuse2fs *ff = data;
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	fs = fuse2fs_start(ff);
+	dbg_printf(ff, "%s:\n", __func__);
+	if (fs && !psi_thread_cancelled(ff->mem_psi)) {
+		err = io_channel_set_options(fs->io, "cache_shrink");
+		if (err)
+			ret = translate_error(fs, 0, err);
+	} else {
+		psi_cancel_handler(ff->mem_psi, &ff->mem_psi_handler);
+	}
+	fuse2fs_finish(ff, ret);
+}
+
+static int fuse2fs_psi_config(struct fuse2fs *ff)
+{
+	errcode_t err;
+
+	/*
+	 * Activate when there are memory stalls for 200ms every 2s; or
+	 * 5min goes by.  Unprivileged processes can only use 2s windows.
+	 */
+	err = psi_create(PSI_MEMORY, PSI_TRIM_HEAP, 20100, 2000000,
+			 5 * 60 * 1000000, &ff->mem_psi);
+	if (err) {
+		switch (errno) {
+		case ENOENT:
+		case EINVAL:
+		case EACCES:
+		case EPERM:
+			break;
+		default:
+			err_printf(ff, "PSI: %s.\n", error_message(errno));
+			return -1;
+		}
+	}
+
+	err = psi_add_handler(ff->mem_psi, fuse2fs_psi_memory, ff,
+			      &ff->mem_psi_handler);
+	if (err) {
+		err_printf(ff, "PSI: %s.\n", error_message(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+static void fuse2fs_psi_start(struct fuse2fs *ff)
+{
+	if (psi_active(ff->mem_psi))
+		psi_start_thread(ff->mem_psi);
+}
+
+static void fuse2fs_psi_destroy(struct fuse2fs *ff)
+{
+	if (!psi_active(ff->mem_psi))
+		return;
+
+	psi_del_handler(ff->mem_psi, &ff->mem_psi_handler);
+	psi_destroy(&ff->mem_psi);
+}
+
 static inline struct fuse2fs *fuse2fs_get(void)
 {
 	struct fuse_context *ctxt = fuse_get_context();
@@ -1569,6 +1640,11 @@ static errcode_t fuse2fs_config_cache(struct fuse2fs *ff)
 		return err;
 	}
 
+	if (psi_active(ff->mem_psi)) {
+		snprintf(buf, sizeof(buf), "cache_auto_shrink=off");
+		err = io_channel_set_options(ff->fs->io, buf);
+	}
+
 	return 0;
 }
 
@@ -1935,6 +2011,7 @@ static void *op_init(struct fuse_conn_info *conn,
 	 * conveyed to the new child process.
 	 */
 	fuse2fs_mmp_start(ff);
+	fuse2fs_psi_start(ff);
 
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 17)
 	/*
@@ -7619,6 +7696,12 @@ int main(int argc, char *argv[])
 	try_set_io_flusher(&fctx);
 	try_adjust_oom_score(&fctx);
 
+	err = fuse2fs_psi_config(&fctx);
+	if (err) {
+		ret |= 32;
+		goto out;
+	}
+
 	/* Will we allow users to allocate every last block? */
 	if (getenv("FUSE2FS_ALLOC_ALL_BLOCKS")) {
 		log_printf(&fctx, "%s\n",
@@ -7708,6 +7791,7 @@ int main(int argc, char *argv[])
  _("Mount failed while opening filesystem.  Check dmesg(1) for details."));
 		fflush(orig_stderr);
 	}
+	fuse2fs_psi_destroy(&fctx);
 	fuse2fs_mmp_destroy(&fctx);
 	fuse2fs_unmount(&fctx);
 	reset_com_err_hook();


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/4] fuse4fs: enable memory pressure monitoring with service containers
  2026-02-23 23:06 ` [PATCHSET v7 7/8] fuse4fs: reclaim buffer cache under memory pressure Darrick J. Wong
  2026-02-23 23:48   ` [PATCH 1/4] libsupport: add pressure stall monitor Darrick J. Wong
  2026-02-23 23:48   ` [PATCH 2/4] fuse2fs: only reclaim buffer cache when there is memory pressure Darrick J. Wong
@ 2026-02-23 23:49   ` Darrick J. Wong
  2026-02-23 23:49   ` [PATCH 4/4] fuse2fs: flush dirty metadata periodically Darrick J. Wong
  3 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:49 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Ask the fuse filesystem service mount helper to open the memory pressure
stall files because we cannot open them ourselves.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/support/psi.h |    9 +++++++
 fuse4fs/fuse4fs.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/support/psi.c |   53 +++++++++++++++++++++++++++++++++++++---
 3 files changed, 128 insertions(+), 5 deletions(-)


diff --git a/lib/support/psi.h b/lib/support/psi.h
index 675ebeb553da3e..916ebf15d17431 100644
--- a/lib/support/psi.h
+++ b/lib/support/psi.h
@@ -54,4 +54,13 @@ static inline bool psi_active(struct psi *psi)
 	return psi != NULL;
 }
 
+char *psi_system_path(enum psi_type type);
+ssize_t psi_cgroup_path(enum psi_type type, char *path, size_t pathsize);
+
+#define PSI_OPEN_FLAGS (O_RDWR | O_NONBLOCK)
+
+int psi_create_from(enum psi_type type, unsigned int psi_flags,
+		    uint64_t stall_us, uint64_t window_us, uint64_t timeout_us,
+		    int *system_fd, int *cgroup_fd, struct psi **psip);
+
 #endif /* __PSI_H__ */
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 87b17491beae13..4d48521fa8f763 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -327,6 +327,8 @@ struct fuse4fs {
 	char *svc_cmdline;
 	int bdev_fd;
 	int fusedev_fd;
+	int psi_sys_mem_fd;
+	int psi_cgroup_mem_fd;
 #endif
 	struct psi *mem_psi;
 	struct psi_handler *mem_psi_handler;
@@ -939,8 +941,16 @@ static int fuse4fs_psi_config(struct fuse4fs *ff)
 	 * Activate when there are memory stalls for 200ms every 2s; or
 	 * 5min goes by.  Unprivileged processes can only use 2s windows.
 	 */
-	err = psi_create(PSI_MEMORY, PSI_TRIM_HEAP, 20100, 2000000,
-			 5 * 60 * 1000000, &ff->mem_psi);
+#ifdef HAVE_FUSE_SERVICE
+	if (fuse4fs_is_service(ff))
+		err = psi_create_from(PSI_MEMORY, PSI_TRIM_HEAP, 202002,
+				      2000000, 5 * 60 * 1000000,
+				      &ff->psi_sys_mem_fd,
+				      &ff->psi_cgroup_mem_fd, &ff->mem_psi);
+	else
+#endif
+		err = psi_create(PSI_MEMORY, PSI_TRIM_HEAP, 202002, 2000000,
+				 5 * 60 * 1000000, &ff->mem_psi);
 	if (err) {
 		switch (errno) {
 		case ENOENT:
@@ -1564,6 +1574,14 @@ static int fuse4fs_service_finish(struct fuse4fs *ff, int ret)
 	close(ff->bdev_fd);
 	ff->bdev_fd = -1;
 
+	if (ff->psi_sys_mem_fd >= 0)
+		close(ff->psi_sys_mem_fd);
+	ff->psi_sys_mem_fd = -1;
+
+	if (ff->psi_cgroup_mem_fd >= 0)
+		close(ff->psi_cgroup_mem_fd);
+	ff->psi_cgroup_mem_fd = -1;
+
 	/*
 	 * If we're being run as a service, the return code must fit the LSB
 	 * init script action error guidelines, which is to say that we
@@ -1585,6 +1603,49 @@ static int fuse4fs_service_finish(struct fuse4fs *ff, int ret)
 	return EXIT_SUCCESS;
 }
 
+/* Open PSI control files */
+static int fuse_service_open_psi_controls(struct fuse4fs *ff)
+{
+	const char *psifile = psi_system_path(PSI_MEMORY);
+	char cgpath[PATH_MAX];
+	ssize_t cgpathlen;
+	int ret;
+
+	ret = fuse_service_request_file(ff->service, psifile, PSI_OPEN_FLAGS,
+					0, 0);
+	if (ret)
+		return ret;
+
+	ret = fuse_service_receive_file(ff->service, psifile,
+					&ff->psi_sys_mem_fd);
+	if (ret)
+		return ret;
+	if (ff->psi_sys_mem_fd < 0)
+		err_printf(ff, "%s %s: %s.\n",
+			   _("opening system memory pressure monitor"),
+			   psifile, strerror(errno));
+
+	cgpathlen = psi_cgroup_path(PSI_MEMORY, cgpath, sizeof(cgpath));
+	if (!cgpathlen || cgpathlen >= sizeof(cgpath))
+		return 0;
+
+	ret = fuse_service_request_file(ff->service, cgpath, PSI_OPEN_FLAGS,
+					0, 0);
+	if (ret)
+		return ret;
+
+	ret = fuse_service_receive_file(ff->service, cgpath,
+					&ff->psi_cgroup_mem_fd);
+	if (ret)
+		return ret;
+	if (ff->psi_cgroup_mem_fd < 0)
+		err_printf(ff, "%s %s: %s.\n",
+			   _("opening cgroup memory pressure monitor"),
+			   cgpath, strerror(errno));
+
+	return 0;
+}
+
 static int fuse4fs_service_get_config(struct fuse4fs *ff)
 {
 	double deadline = init_deadline(FUSE4FS_OPEN_TIMEOUT);
@@ -1620,6 +1681,10 @@ static int fuse4fs_service_get_config(struct fuse4fs *ff)
 		return -1;
 	}
 
+	ret = fuse_service_open_psi_controls(ff);
+	if (ret)
+		return ret;
+
 	ret = fuse_service_finish_file_requests(ff->service);
 	if (ret)
 		return ret;
@@ -8581,6 +8646,8 @@ int main(int argc, char *argv[])
 #ifdef HAVE_FUSE_SERVICE
 		.bdev_fd = -1,
 		.fusedev_fd = -1,
+		.psi_sys_mem_fd = -1,
+		.psi_cgroup_mem_fd = -1,
 #endif
 	};
 	errcode_t err;
diff --git a/lib/support/psi.c b/lib/support/psi.c
index 26ce6ee1985641..531ae935701edf 100644
--- a/lib/support/psi.c
+++ b/lib/support/psi.c
@@ -54,7 +54,7 @@ struct psi {
 	enum psi_state state;
 };
 
-static const char *psi_system_path(enum psi_type type)
+char *psi_system_path(enum psi_type type)
 {
 	switch (type) {
 	case PSI_MEMORY:
@@ -300,7 +300,7 @@ void psi_destroy(struct psi **psip)
 
 static int psi_open_control(const char *path)
 {
-	return open(path, O_RDWR | O_NONBLOCK);
+	return open(path, PSI_OPEN_FLAGS);
 }
 
 static void psi_open_system_control(struct psi *psi)
@@ -309,7 +309,7 @@ static void psi_open_system_control(struct psi *psi)
 	psi->system_fd = psi_open_control(psi_system_path(psi->type));
 }
 
-static ssize_t psi_cgroup_path(enum psi_type type, char *path, size_t pathsize)
+ssize_t psi_cgroup_path(enum psi_type type, char *path, size_t pathsize)
 {
 	char cgpath[PATH_MAX];
 	char *p = cgpath;
@@ -485,6 +485,53 @@ int psi_create(enum psi_type type, unsigned int psi_flags, uint64_t stall_us,
 	return -1;
 }
 
+/*
+ * Same as psi_create, but you can specify the whole-system and per-cgroup
+ * monitoring fds.
+ */
+int psi_create_from(enum psi_type type, unsigned int psi_flags,
+		    uint64_t stall_us, uint64_t window_us, uint64_t timeout_us,
+		    int *system_fd, int *cgroup_fd, struct psi **psip)
+{
+	struct psi *psi;
+	int ret;
+
+	if (psi_flags & ~PSI_FLAGS) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	psi = psi_alloc(type, psi_flags, timeout_us);
+	if (!psi)
+		return -1;
+
+	psi->system_fd = *system_fd;
+	psi->cgroup_fd = *cgroup_fd;
+
+	*system_fd = -1;
+	*cgroup_fd = -1;
+
+	if (psi->system_fd < 0 && psi->cgroup_fd < 0 && !psi->timeout_us) {
+		errno = ENOENT;
+		goto out_fds;
+	}
+
+	ret = psi_config_fd(psi, psi->system_fd, stall_us, window_us);
+	if (ret)
+		goto out_fds;
+
+	ret = psi_config_fd(psi, psi->cgroup_fd, stall_us, window_us);
+	if (ret)
+		goto out_fds;
+
+	*psip = psi;
+	return 0;
+
+out_fds:
+	psi_destroy(&psi);
+	return -1;
+}
+
 /* Start monitoring for resource pressure stalls */
 int psi_start_thread(struct psi *psi)
 {


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 4/4] fuse2fs: flush dirty metadata periodically
  2026-02-23 23:06 ` [PATCHSET v7 7/8] fuse4fs: reclaim buffer cache under memory pressure Darrick J. Wong
                     ` (2 preceding siblings ...)
  2026-02-23 23:49   ` [PATCH 3/4] fuse4fs: enable memory pressure monitoring with service containers Darrick J. Wong
@ 2026-02-23 23:49   ` Darrick J. Wong
  3 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:49 UTC (permalink / raw)
  To: tytso; +Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal

From: Darrick J. Wong <djwong@kernel.org>

Flush dirty metadata out to disk periodically like the kernel, to reduce
the potential for data loss if userspace doesn't explicitly fsync.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |  112 +++++++++++++++++++++++++++++++++++++++++++++++++----
 misc/fuse2fs.c    |  112 +++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 206 insertions(+), 18 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 4d48521fa8f763..1fbf5e48af8724 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -28,6 +28,7 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <assert.h>
+#include <limits.h>
 #ifdef HAVE_FUSE_LOOPDEV
 # include <fuse_loopdev.h>
 #endif
@@ -332,6 +333,10 @@ struct fuse4fs {
 #endif
 	struct psi *mem_psi;
 	struct psi_handler *mem_psi_handler;
+
+	struct bthread *flush_thread;
+	unsigned int flush_interval;
+	double last_flush;
 };
 
 #ifdef HAVE_FUSE_SERVICE
@@ -1007,6 +1012,71 @@ fuse4fs_set_handle(struct fuse_file_info *fp, struct fuse4fs_file_handle *fh)
 	fp->keep_cache = 1;
 }
 
+static errcode_t fuse4fs_flush(struct fuse4fs *ff, int flags)
+{
+	double last_flush = gettime_monotonic();
+	errcode_t err;
+
+	err = ext2fs_flush2(ff->fs, flags);
+	if (err)
+		return err;
+
+	ff->last_flush = last_flush;
+	return 0;
+}
+
+static inline int fuse4fs_flush_wanted(struct fuse4fs *ff)
+{
+	return ff->fs != NULL && ff->opstate == F4OP_WRITABLE &&
+	       ff->last_flush + ff->flush_interval <= gettime_monotonic();
+}
+
+static void fuse4fs_flush_bthread(void *data)
+{
+	struct fuse4fs *ff = data;
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	fs = fuse4fs_start(ff);
+	if (fuse4fs_flush_wanted(ff) && !bthread_cancelled(ff->flush_thread)) {
+		err = fuse4fs_flush(ff, 0);
+		if (err)
+			ret = translate_error(fs, 0, err);
+	}
+	fuse4fs_finish(ff, ret);
+}
+
+static void fuse4fs_flush_start(struct fuse4fs *ff)
+{
+	int ret;
+
+	if (!ff->flush_interval)
+		return;
+
+	ret = bthread_create("fuse4fs_flush", fuse4fs_flush_bthread, ff,
+			     ff->flush_interval, &ff->flush_thread);
+	if (ret) {
+		err_printf(ff, "flusher: %s.\n", error_message(ret));
+		return;
+	}
+
+	ret = bthread_start(ff->flush_thread);
+	if (ret)
+		err_printf(ff, "flusher: %s.\n", error_message(ret));
+}
+
+static void fuse4fs_flush_cancel(struct fuse4fs *ff)
+{
+	if (ff->flush_thread)
+		bthread_cancel(ff->flush_thread);
+}
+
+static void fuse4fs_flush_destroy(struct fuse4fs *ff)
+{
+	bthread_destroy(&ff->flush_thread);
+}
+
 #ifdef HAVE_FUSE_IOMAP
 static inline int fuse4fs_iomap_enabled(const struct fuse4fs *ff)
 {
@@ -2240,7 +2310,7 @@ static int fuse4fs_mount(struct fuse4fs *ff)
 		ext2fs_set_tstamp(fs->super, s_mtime, time(NULL));
 		fs->super->s_state &= ~EXT2_VALID_FS;
 		ext2fs_mark_super_dirty(fs);
-		err = ext2fs_flush2(fs, 0);
+		err = fuse4fs_flush(ff, 0);
 		if (err)
 			return translate_error(fs, 0, err);
 	}
@@ -2268,7 +2338,7 @@ static void op_destroy(void *userdata)
 		if (err)
 			translate_error(fs, 0, err);
 
-		err = ext2fs_flush2(fs, 0);
+		err = fuse4fs_flush(ff, 0);
 		if (err)
 			translate_error(fs, 0, err);
 	}
@@ -2291,6 +2361,7 @@ static void op_destroy(void *userdata)
 	 * that the block device will be released before umount(2) returns.
 	 */
 	if (ff->iomap_state == IOMAP_ENABLED) {
+		fuse4fs_flush_cancel(ff);
 		fuse4fs_mmp_cancel(ff);
 		fuse4fs_unmount(ff);
 	}
@@ -2507,6 +2578,7 @@ static void op_init(void *userdata, struct fuse_conn_info *conn)
 	 */
 	fuse4fs_mmp_start(ff);
 	fuse4fs_psi_start(ff);
+	fuse4fs_flush_start(ff);
 
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 17)
 	/*
@@ -3064,7 +3136,7 @@ static inline int fuse4fs_dirsync_flush(struct fuse4fs *ff, ext2_ino_t ino,
 		*flushed = 0;
 	return 0;
 flush:
-	err = ext2fs_flush2(fs, 0);
+	err = fuse4fs_flush(ff, 0);
 	if (err)
 		return translate_error(fs, 0, err);
 
@@ -4936,7 +5008,7 @@ static void op_release(fuse_req_t req, fuse_ino_t fino EXT2FS_ATTR((unused)),
 	if ((fp->flags & O_SYNC) &&
 	    fuse4fs_is_writeable(ff) &&
 	    (fh->open_flags & EXT2_FILE_WRITE)) {
-		err = ext2fs_flush2(fs, EXT2_FLAG_FLUSH_NO_SYNC);
+		err = fuse4fs_flush(ff, EXT2_FLAG_FLUSH_NO_SYNC);
 		if (err)
 			ret = translate_error(fs, fh->ino, err);
 	}
@@ -4967,7 +5039,7 @@ static void op_fsync(fuse_req_t req, fuse_ino_t fino EXT2FS_ATTR((unused)),
 	fs = fuse4fs_start(ff);
 	/* For now, flush everything, even if it's slow */
 	if (fuse4fs_is_writeable(ff) && fh->open_flags & EXT2_FILE_WRITE) {
-		err = ext2fs_flush2(fs, 0);
+		err = fuse4fs_flush(ff, 0);
 		if (err)
 			ret = translate_error(fs, fh->ino, err);
 	}
@@ -6294,6 +6366,7 @@ static int ioctl_shutdown(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 
 	err_printf(ff, "%s.\n", _("shut down requested"));
 
+	fuse4fs_flush_cancel(ff);
 	fuse4fs_mmp_cancel(ff);
 
 	/*
@@ -6302,7 +6375,7 @@ static int ioctl_shutdown(struct fuse4fs *ff, const struct fuse_ctx *ctxt,
 	 * any of the flags.  Flush whatever is dirty and shut down.
 	 */
 	if (ff->opstate == F4OP_WRITABLE)
-		ext2fs_flush2(fs, 0);
+		fuse4fs_flush(ff, 0);
 	ff->opstate = F4OP_SHUTDOWN;
 	fs->flags &= ~EXT2_FLAG_RW;
 
@@ -6717,7 +6790,7 @@ static void op_freezefs(fuse_req_t req, fuse_ino_t ino, uint64_t unlinked)
 			goto out_unlock;
 		}
 
-		err = ext2fs_flush2(fs, 0);
+		err = fuse4fs_flush(ff, 0);
 		if (err) {
 			ret = translate_error(fs, 0, err);
 			goto out_unlock;
@@ -6753,7 +6826,7 @@ static void op_unfreezefs(fuse_req_t req, fuse_ino_t ino)
 			goto out_unlock;
 		}
 
-		err = ext2fs_flush2(fs, 0);
+		err = fuse4fs_flush(ff, 0);
 		if (err) {
 			ret = translate_error(fs, 0, err);
 			goto out_unlock;
@@ -6797,7 +6870,7 @@ static void op_syncfs(fuse_req_t req, fuse_ino_t ino)
 			goto out_unlock;
 		}
 
-		err = ext2fs_flush2(fs, 0);
+		err = fuse4fs_flush(ff, 0);
 		if (err) {
 			ret = translate_error(fs, 0, err);
 			goto out_unlock;
@@ -8176,6 +8249,7 @@ enum {
 	FUSE4FS_CACHE_SIZE,
 	FUSE4FS_DIRSYNC,
 	FUSE4FS_ERRORS_BEHAVIOR,
+	FUSE4FS_FLUSH_INTERVAL,
 #ifdef HAVE_FUSE_IOMAP
 	FUSE4FS_IOMAP,
 	FUSE4FS_IOMAP_PASSTHROUGH,
@@ -8204,6 +8278,7 @@ static struct fuse_opt fuse4fs_opts[] = {
 #ifdef HAVE_CLOCK_MONOTONIC
 	FUSE4FS_OPT("timing",		timing,			1),
 #endif
+	FUSE_OPT_KEY("flush_interval=%s", FUSE4FS_FLUSH_INTERVAL),
 #ifdef HAVE_FUSE_IOMAP
 	FUSE4FS_OPT("iomap_cache",	iomap_cache,		1),
 	FUSE4FS_OPT("noiomap_cache",	iomap_cache,		0),
@@ -8287,6 +8362,21 @@ static int fuse4fs_opt_proc(void *data, const char *arg,
 
 		/* do not pass through to libfuse */
 		return 0;
+	case FUSE4FS_FLUSH_INTERVAL:
+		char *p;
+		unsigned long val;
+
+		errno = 0;
+		val = strtoul(arg + 15, &p, 0);
+		if (p != arg + strlen(arg) || errno || val > UINT_MAX) {
+			fprintf(stderr, "%s: %s.\n", arg,
+				_("Unrecognized flush interval"));
+			return -1;
+		}
+
+		/* do not pass through to libfuse */
+		ff->flush_interval = val;
+		return 0;
 #ifdef HAVE_FUSE_IOMAP
 	case FUSE4FS_IOMAP:
 		if (strcmp(arg, "iomap") == 0 || strcmp(arg + 6, "1") == 0)
@@ -8334,6 +8424,7 @@ static int fuse4fs_opt_proc(void *data, const char *arg,
 #ifdef HAVE_FUSE_IOMAP
 	"    -o iomap=              0 to disable iomap, 1 to enable iomap\n"
 #endif
+	"    -o flush=<time>        flush dirty metadata on this interval\n"
 	"\n",
 			outargs->argv[0]);
 		if (key == FUSE4FS_HELPFULL) {
@@ -8643,6 +8734,7 @@ int main(int argc, char *argv[])
 		.loop_fd = -1,
 #endif
 		.translate_inums = 1,
+		.flush_interval = 30,
 #ifdef HAVE_FUSE_SERVICE
 		.bdev_fd = -1,
 		.fusedev_fd = -1,
@@ -8829,6 +8921,7 @@ int main(int argc, char *argv[])
  _("Mount failed while opening filesystem.  Check dmesg(1) for details."));
 		fflush(orig_stderr);
 	}
+	fuse4fs_flush_destroy(&fctx);
 	fuse4fs_psi_destroy(&fctx);
 	fuse4fs_mmp_destroy(&fctx);
 	fuse4fs_unmount(&fctx);
@@ -9007,6 +9100,7 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
  _("Remounting read-only due to errors."));
 			ff->opstate = F4OP_READONLY;
 		}
+		fuse4fs_flush_cancel(ff);
 		fuse4fs_mmp_cancel(ff);
 		fs->flags &= ~EXT2_FLAG_RW;
 		break;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index f2929ae0045bc9..ac6de48b008433 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -26,6 +26,7 @@
 #include <sys/sysmacros.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <limits.h>
 #ifdef HAVE_FUSE_LOOPDEV
 # include <fuse_loopdev.h>
 #endif
@@ -309,6 +310,10 @@ struct fuse2fs {
 #endif
 	struct psi *mem_psi;
 	struct psi_handler *mem_psi_handler;
+
+	struct bthread *flush_thread;
+	unsigned int flush_interval;
+	double last_flush;
 };
 
 #define FUSE2FS_CHECK_HANDLE(ff, fh) \
@@ -812,6 +817,71 @@ fuse2fs_set_handle(struct fuse_file_info *fp, struct fuse2fs_file_handle *fh)
 	fp->fh = (uintptr_t)fh;
 }
 
+static errcode_t fuse2fs_flush(struct fuse2fs *ff, int flags)
+{
+	double last_flush = gettime_monotonic();
+	errcode_t err;
+
+	err = ext2fs_flush2(ff->fs, flags);
+	if (err)
+		return err;
+
+	ff->last_flush = last_flush;
+	return 0;
+}
+
+static inline int fuse2fs_flush_wanted(struct fuse2fs *ff)
+{
+	return ff->fs != NULL && ff->opstate == F2OP_WRITABLE &&
+	       ff->last_flush + ff->flush_interval <= gettime_monotonic();
+}
+
+static void fuse2fs_flush_bthread(void *data)
+{
+	struct fuse2fs *ff = data;
+	ext2_filsys fs;
+	errcode_t err;
+	int ret = 0;
+
+	fs = fuse2fs_start(ff);
+	if (fuse2fs_flush_wanted(ff) && !bthread_cancelled(ff->flush_thread)) {
+		err = fuse2fs_flush(ff, 0);
+		if (err)
+			ret = translate_error(fs, 0, err);
+	}
+	fuse2fs_finish(ff, ret);
+}
+
+static void fuse2fs_flush_start(struct fuse2fs *ff)
+{
+	int ret;
+
+	if (!ff->flush_interval)
+		return;
+
+	ret = bthread_create("fuse2fs_flush", fuse2fs_flush_bthread, ff,
+			     ff->flush_interval, &ff->flush_thread);
+	if (ret) {
+		err_printf(ff, "flusher: %s.\n", error_message(ret));
+		return;
+	}
+
+	ret = bthread_start(ff->flush_thread);
+	if (ret)
+		err_printf(ff, "flusher: %s.\n", error_message(ret));
+}
+
+static void fuse2fs_flush_cancel(struct fuse2fs *ff)
+{
+	if (ff->flush_thread)
+		bthread_cancel(ff->flush_thread);
+}
+
+static void fuse2fs_flush_destroy(struct fuse2fs *ff)
+{
+	bthread_destroy(&ff->flush_thread);
+}
+
 #ifdef HAVE_FUSE_IOMAP
 static inline int fuse2fs_iomap_enabled(const struct fuse2fs *ff)
 {
@@ -1724,7 +1794,7 @@ static int fuse2fs_mount(struct fuse2fs *ff)
 		ext2fs_set_tstamp(fs->super, s_mtime, time(NULL));
 		fs->super->s_state &= ~EXT2_VALID_FS;
 		ext2fs_mark_super_dirty(fs);
-		err = ext2fs_flush2(fs, 0);
+		err = fuse2fs_flush(ff, 0);
 		if (err)
 			return translate_error(fs, 0, err);
 	}
@@ -1752,7 +1822,7 @@ static void op_destroy(void *p EXT2FS_ATTR((unused)))
 		if (err)
 			translate_error(fs, 0, err);
 
-		err = ext2fs_flush2(fs, 0);
+		err = fuse2fs_flush(ff, 0);
 		if (err)
 			translate_error(fs, 0, err);
 	}
@@ -1775,6 +1845,7 @@ static void op_destroy(void *p EXT2FS_ATTR((unused)))
 	 * that the block device will be released before umount(2) returns.
 	 */
 	if (ff->iomap_state == IOMAP_ENABLED) {
+		fuse2fs_flush_cancel(ff);
 		fuse2fs_mmp_cancel(ff);
 		fuse2fs_unmount(ff);
 	}
@@ -2012,6 +2083,7 @@ static void *op_init(struct fuse_conn_info *conn,
 	 */
 	fuse2fs_mmp_start(ff);
 	fuse2fs_psi_start(ff);
+	fuse2fs_flush_start(ff);
 
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 17)
 	/*
@@ -2542,7 +2614,7 @@ static inline int fuse2fs_dirsync_flush(struct fuse2fs *ff, ext2_ino_t ino,
 		*flushed = 0;
 	return 0;
 flush:
-	err = ext2fs_flush2(fs, 0);
+	err = fuse2fs_flush(ff, 0);
 	if (err)
 		return translate_error(fs, 0, err);
 
@@ -4348,7 +4420,7 @@ static int op_release(const char *path EXT2FS_ATTR((unused)),
 	if ((fp->flags & O_SYNC) &&
 	    fuse2fs_is_writeable(ff) &&
 	    (fh->open_flags & EXT2_FILE_WRITE)) {
-		err = ext2fs_flush2(fs, EXT2_FLAG_FLUSH_NO_SYNC);
+		err = fuse2fs_flush(ff, EXT2_FLAG_FLUSH_NO_SYNC);
 		if (err)
 			ret = translate_error(fs, fh->ino, err);
 	}
@@ -4377,7 +4449,7 @@ static int op_fsync(const char *path EXT2FS_ATTR((unused)),
 	fs = fuse2fs_start(ff);
 	/* For now, flush everything, even if it's slow */
 	if (fuse2fs_is_writeable(ff) && fh->open_flags & EXT2_FILE_WRITE) {
-		err = ext2fs_flush2(fs, 0);
+		err = fuse2fs_flush(ff, 0);
 		if (err)
 			ret = translate_error(fs, fh->ino, err);
 	}
@@ -5487,6 +5559,7 @@ static int ioctl_shutdown(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
 
 	err_printf(ff, "%s.\n", _("shut down requested"));
 
+	fuse2fs_flush_cancel(ff);
 	fuse2fs_mmp_cancel(ff);
 
 	/*
@@ -5495,7 +5568,7 @@ static int ioctl_shutdown(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
 	 * any of the flags.  Flush whatever is dirty and shut down.
 	 */
 	if (ff->opstate == F2OP_WRITABLE)
-		ext2fs_flush2(fs, 0);
+		fuse2fs_flush(ff, 0);
 	ff->opstate = F2OP_SHUTDOWN;
 	fs->flags &= ~EXT2_FLAG_RW;
 
@@ -5893,7 +5966,7 @@ static int op_freezefs(const char *path, uint64_t unlinked)
 			goto out_unlock;
 		}
 
-		err = ext2fs_flush2(fs, 0);
+		err = fuse2fs_flush(ff, 0);
 		if (err) {
 			ret = translate_error(fs, 0, err);
 			goto out_unlock;
@@ -5928,7 +6001,7 @@ static int op_unfreezefs(const char *path)
 			goto out_unlock;
 		}
 
-		err = ext2fs_flush2(fs, 0);
+		err = fuse2fs_flush(ff, 0);
 		if (err) {
 			ret = translate_error(fs, 0, err);
 			goto out_unlock;
@@ -5970,7 +6043,7 @@ static int op_syncfs(const char *path)
 			goto out_unlock;
 		}
 
-		err = ext2fs_flush2(fs, 0);
+		err = fuse2fs_flush(ff, 0);
 		if (err) {
 			ret = translate_error(fs, 0, err);
 			goto out_unlock;
@@ -7330,6 +7403,7 @@ enum {
 	FUSE2FS_CACHE_SIZE,
 	FUSE2FS_DIRSYNC,
 	FUSE2FS_ERRORS_BEHAVIOR,
+	FUSE2FS_FLUSH_INTERVAL,
 #ifdef HAVE_FUSE_IOMAP
 	FUSE2FS_IOMAP,
 	FUSE2FS_IOMAP_PASSTHROUGH,
@@ -7358,6 +7432,7 @@ static struct fuse_opt fuse2fs_opts[] = {
 #ifdef HAVE_CLOCK_MONOTONIC
 	FUSE2FS_OPT("timing",		timing,			1),
 #endif
+	FUSE_OPT_KEY("flush_interval=%s", FUSE2FS_FLUSH_INTERVAL),
 #ifdef HAVE_FUSE_IOMAP
 	FUSE2FS_OPT("iomap_cache",	iomap_cache,		1),
 	FUSE2FS_OPT("noiomap_cache",	iomap_cache,		0),
@@ -7441,6 +7516,21 @@ static int fuse2fs_opt_proc(void *data, const char *arg,
 
 		/* do not pass through to libfuse */
 		return 0;
+	case FUSE2FS_FLUSH_INTERVAL:
+		char *p;
+		unsigned long val;
+
+		errno = 0;
+		val = strtoul(arg + 15, &p, 0);
+		if (p != arg + strlen(arg) || errno || val > UINT_MAX) {
+			fprintf(stderr, "%s: %s.\n", arg,
+				_("Unrecognized flush interval"));
+			return -1;
+		}
+
+		/* do not pass through to libfuse */
+		ff->flush_interval = val;
+		return 0;
 #ifdef HAVE_FUSE_IOMAP
 	case FUSE2FS_IOMAP:
 		if (strcmp(arg, "iomap") == 0 || strcmp(arg + 6, "1") == 0)
@@ -7488,6 +7578,7 @@ static int fuse2fs_opt_proc(void *data, const char *arg,
 #ifdef HAVE_FUSE_IOMAP
 	"    -o iomap=              0 to disable iomap, 1 to enable iomap\n"
 #endif
+	"    -o flush=<time>        flush dirty metadata on this interval\n"
 	"\n",
 			outargs->argv[0]);
 		if (key == FUSE2FS_HELPFULL) {
@@ -7647,6 +7738,7 @@ int main(int argc, char *argv[])
 #ifdef HAVE_FUSE_LOOPDEV
 		.loop_fd = -1,
 #endif
+		.flush_interval = 30,
 	};
 	errcode_t err;
 	FILE *orig_stderr = stderr;
@@ -7791,6 +7883,7 @@ int main(int argc, char *argv[])
  _("Mount failed while opening filesystem.  Check dmesg(1) for details."));
 		fflush(orig_stderr);
 	}
+	fuse2fs_flush_destroy(&fctx);
 	fuse2fs_psi_destroy(&fctx);
 	fuse2fs_mmp_destroy(&fctx);
 	fuse2fs_unmount(&fctx);
@@ -7968,6 +8061,7 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
  _("Remounting read-only due to errors."));
 			ff->opstate = F2OP_READONLY;
 		}
+		fuse2fs_flush_cancel(ff);
 		fuse2fs_mmp_cancel(ff);
 		fs->flags &= ~EXT2_FLAG_RW;
 		break;


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 1/3] fuse4fs: add dynamic iomap bpf prototype which will break FIEMAP
  2026-02-23 23:06 ` [PATCHSET RFC 8/8] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
@ 2026-02-23 23:49   ` Darrick J. Wong
  2026-02-23 23:49   ` [PATCH 2/3] fuse4fs: wire up caching examples to fuse iomap bpf program Darrick J. Wong
  2026-02-23 23:50   ` [PATCH 3/3] fuse4fs: adjust test bpf program to deal with opaque inodes Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:49 UTC (permalink / raw)
  To: tytso
  Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal,
	john

From: Darrick J. Wong <djwong@kernel.org>

Enhance fuse4fs to report rogue results from FIEMAP to prove that iomap
bpf actually works.  This patch employs dynamic compilation of the bpf
program so that the filesystem can tailor the bpf code to the needs of
the filesystem it's serving.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs_bpf.h |   54 +++++++
 MCONFIG.in            |    5 +
 configure             |  188 +++++++++++++++++++++++
 configure.ac          |   94 +++++++++++
 fuse4fs/Makefile.in   |   22 ++-
 fuse4fs/fuse4fs.c     |   82 ++++++++++
 fuse4fs/fuse4fs_bpf.c |  404 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/config.h.in       |   12 +
 8 files changed, 859 insertions(+), 2 deletions(-)
 create mode 100644 fuse4fs/fuse4fs_bpf.h
 create mode 100644 fuse4fs/fuse4fs_bpf.c


diff --git a/fuse4fs/fuse4fs_bpf.h b/fuse4fs/fuse4fs_bpf.h
new file mode 100644
index 00000000000000..4fcede160a3731
--- /dev/null
+++ b/fuse4fs/fuse4fs_bpf.h
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#ifndef __FUSE4FS_BPF_H__
+#define __FUSE4FS_BPF_H__
+
+struct fuse4fs_bpf_attrs {
+	/* vector to the binary elf data */
+	const void *elf_data;
+	size_t elf_size;
+
+	/* name associated with this bpf skeleton */
+	const char *skel_name;
+
+	/* name of the fuse_iomap_bpf_ops object in the bpf code */
+	const char *ops_name;
+
+	/* name of the iomap_begin bpf function, if provided */
+	const char *begin_fn_name;
+
+	/* name of the iomap_end bpf function, if provided */
+	const char *end_fn_name;
+
+	/* name of the iomap_ioend bpf function, if provided */
+	const char *ioend_fn_name;
+};
+
+struct fuse4fs_bpf_compile {
+	/* C source code */
+	const char *source_code;
+
+	/* directory containing vmlinux.h */
+	const char *vmlinux_h_dir;
+
+	/* directory containing fuse_iomap_bpf.h */
+	const char *fuse_include_dir;
+};
+
+struct fuse4fs_bpf_ctl {
+	struct fuse4fs_bpf *skel;
+	struct bpf_link *link;
+};
+
+int fuse4fs_bpf_ctl_setup(struct fuse4fs_bpf_ctl *arg, struct fuse_session *se,
+			  const struct fuse4fs_bpf_attrs *attrs);
+void fuse4fs_bpf_ctl_drop_skeleton(struct fuse4fs_bpf_ctl *arg);
+void fuse4fs_bpf_ctl_cleanup(struct fuse4fs_bpf_ctl *arg);
+
+int fuse4fs_bpf_compile(struct fuse4fs_bpf_attrs *attrs,
+			const struct fuse4fs_bpf_compile *cc);
+
+#endif /* __FUSE4FS_BPF_H__ */
diff --git a/MCONFIG.in b/MCONFIG.in
index 2fcb71d898fef7..9b25cbb78d3f00 100644
--- a/MCONFIG.in
+++ b/MCONFIG.in
@@ -44,6 +44,11 @@ HAVE_SYSTEMD = @have_systemd@
 SYSTEMD_SYSTEM_UNIT_DIR = @systemd_system_unit_dir@
 HAVE_FUSE_SERVICE = @have_fuse_service@
 
+VMLINUX_H_DIR = @VMLINUX_H_DIR@
+FUSE_INCLUDE_PATH = @FUSE_INCLUDE_PATH@
+HAVE_IOMAP_BPF = @have_iomap_bpf@
+LIBBPF = @BPF_LIB@
+
 @SET_MAKE@
 
 @ifGNUmake@ V =
diff --git a/configure b/configure
index 44bd0e73a74279..a9ffadc8793647 100755
--- a/configure
+++ b/configure
@@ -696,6 +696,11 @@ gcc_ar
 UNI_DIFF_OPTS
 SEM_INIT_LIB
 LIBBSD_LIB
+have_iomap_bpf
+VMLINUX_H_DIR
+BPF_LIB
+libbpf_LIBS
+libbpf_CFLAGS
 FUSE4FS_CMT
 FUSE2FS_CMT
 fuse_service_socket_dir
@@ -935,6 +940,9 @@ with_libarchive
 with_fuse_service_socket_dir
 enable_fuse2fs
 enable_fuse4fs
+enable_bpf
+with_vmlinux_h_path
+with_fuse_include_path
 enable_lto
 enable_ubsan
 enable_addrsan
@@ -962,6 +970,8 @@ ARCHIVE_CFLAGS
 ARCHIVE_LIBS
 fuse3_CFLAGS
 fuse3_LIBS
+libbpf_CFLAGS
+libbpf_LIBS
 CXX
 CXXFLAGS
 CCC
@@ -1632,6 +1642,7 @@ Optional Features:
   --disable-largefile     omit support for large files
   --disable-fuse2fs       do not build fuse2fs
   --disable-fuse4fs       do not build fuse4fs
+  --disable-bpf           disable use of bpf in fuse4fs
   --enable-lto            enable link time optimization
   --enable-ubsan          enable undefined behavior sanitizer
   --enable-addrsan        enable address sanitizer
@@ -1658,6 +1669,12 @@ Optional Packages:
   --without-libarchive    disable use of libarchive
   --with-fuse-service-socket-dir[=DIR]
                           Create fuse3 filesystem service sockets in DIR.
+  --with-vmlinux-h-path[=PATH]
+                          Use this vmlinux.h file on the target for compiling
+                          BPF programs.
+  --with-fuse-include-path[=PATH]
+                          Use this path on the target to libfuse headers for
+                          compiling BPF programs.
   --with-multiarch=ARCH   specify the multiarch triplet
   --with-udev-rules-dir[=DIR]
                           Install udev rules into DIR.
@@ -1686,6 +1703,9 @@ Some influential environment variables:
   fuse3_CFLAGS
               C compiler flags for fuse3, overriding pkg-config
   fuse3_LIBS  linker flags for fuse3, overriding pkg-config
+  libbpf_CFLAGS
+              C compiler flags for libbpf, overriding pkg-config
+  libbpf_LIBS linker flags for libbpf, overriding pkg-config
   CXX         C++ compiler command
   CXXFLAGS    C++ compiler flags
   udev_CFLAGS C compiler flags for udev, overriding pkg-config
@@ -13641,6 +13661,12 @@ if test "x$ac_cv_func_chflags" = xyes
 then :
   printf "%s\n" "#define HAVE_CHFLAGS 1" >>confdefs.h
 
+fi
+ac_fn_c_check_func "$LINENO" "close_range" "ac_cv_func_close_range"
+if test "x$ac_cv_func_close_range" = xyes
+then :
+  printf "%s\n" "#define HAVE_CLOSE_RANGE 1" >>confdefs.h
+
 fi
 ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen"
 if test "x$ac_cv_func_dlopen" = xyes
@@ -15062,6 +15088,168 @@ printf "%s\n" "#define HAVE_FUSE_CACHE_READDIR 1" >>confdefs.h
 
 fi
 
+# Check whether --enable-bpf was given.
+if test ${enable_bpf+y}
+then :
+  enableval=$enable_bpf;
+fi
+
+
+
+# Check whether --with-vmlinux_h_path was given.
+if test ${with_vmlinux_h_path+y}
+then :
+  withval=$with_vmlinux_h_path;
+else case e in #(
+  e) with_vmlinux_h_path=yes ;;
+esac
+fi
+
+vmlinux_h_path="$withval"
+
+# Check whether --with-fuse_include_path was given.
+if test ${with_fuse_include_path+y}
+then :
+  withval=$with_fuse_include_path;
+else case e in #(
+  e) with_fuse_include_path=yes ;;
+esac
+fi
+
+fuse_include_path="$withval"
+
+if test "x$enable_bpf" != "xno" && test -n "$have_fuse_lowlevel" && test -n "$have_fuse_iomap"; then
+	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can find vmlinux.h" >&5
+printf %s "checking if we can find vmlinux.h... " >&6; }
+
+
+		if test -n "$vmlinux_h_path"; then
+		VMLINUX_H_DIR="$(dirname "$vmlinux_h_path")"
+	fi
+
+		location="/usr/src/kernels/$(uname -r)/vmlinux.h"
+	if test -z "$VMLINUX_H_DIR" && test -s "$location"; then
+		VMLINUX_H_DIR="$(dirname "$location")"
+	fi
+
+		location="/usr/include/$(gcc -print-multiarch)/linux/bpf/vmlinux.h"
+	if test -z "$VMLINUX_H_DIR" && test -s "$location"; then
+		VMLINUX_H_DIR="$(dirname "$location")"
+	fi
+
+	if test -n "$VMLINUX_H_DIR"; then
+		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
+	else
+		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+	fi
+
+						if test -n "$fuse_include_path"; then
+		FUSE_INCLUDE_PATH="$fuse_include_path"
+	else
+		FUSE_INCLUDE_PATH="/usr/include/fuse3"
+	fi
+
+				BPF_LIB=
+
+pkg_failed=no
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libbpf" >&5
+printf %s "checking for libbpf... " >&6; }
+
+if test -n "$libbpf_CFLAGS"; then
+    pkg_cv_libbpf_CFLAGS="$libbpf_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libbpf\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libbpf") 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_libbpf_CFLAGS=`$PKG_CONFIG --cflags "libbpf" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$libbpf_LIBS"; then
+    pkg_cv_libbpf_LIBS="$libbpf_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libbpf\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libbpf") 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_libbpf_LIBS=`$PKG_CONFIG --libs "libbpf" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+                libbpf_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libbpf" 2>&1`
+        else
+                libbpf_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libbpf" 2>&1`
+        fi
+        # Put the nasty error message in config.log where it belongs
+        echo "$libbpf_PKG_ERRORS" >&5
+
+        BPF_LIB=
+elif test $pkg_failed = untried; then
+        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+        BPF_LIB=
+else
+        libbpf_CFLAGS=$pkg_cv_libbpf_CFLAGS
+        libbpf_LIBS=$pkg_cv_libbpf_LIBS
+        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
+        BPF_LIB=-lbpf
+fi
+
+
+				{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can enable iomap bpf overrides" >&5
+printf %s "checking if we can enable iomap bpf overrides... " >&6; }
+	if test -n "$VMLINUX_H_DIR" && test -n "$FUSE_INCLUDE_PATH" && test -n "$BPF_LIB"; then
+		printf "%s\n" "#define HAVE_IOMAP_BPF 1" >>confdefs.h
+
+		printf "%s\n" "#define VMLINUX_H_DIR \"$VMLINUX_H_DIR\"" >>confdefs.h
+
+		printf "%s\n" "#define FUSE_INCLUDE_PATH \"$FUSE_INCLUDE_PATH\"" >>confdefs.h
+
+		have_iomap_bpf=yes
+
+		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
+	else
+		have_iomap_bpf=
+		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+	fi
+fi
+
+
+if test "x$enable_bpf" = "xyes" && test -z "$have_iomap_bpf"; then
+	as_fn_error $? "cannot find bpf override library" "$LINENO" 5
+fi
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for setproctitle in -lbsd" >&5
 printf %s "checking for setproctitle in -lbsd... " >&6; }
 if test ${ac_cv_lib_bsd_setproctitle+y}
diff --git a/configure.ac b/configure.ac
index a3162a64123d20..b749096fc6e062 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1226,6 +1226,7 @@ AC_CHECK_FUNCS(m4_flatten([
 	add_key
 	backtrace
 	chflags
+	close_range
 	dlopen
 	fadvise64
 	fallocate
@@ -1625,6 +1626,99 @@ then
 		  [Define to 1 if fuse supports cache_readdir])
 fi
 
+AC_ARG_ENABLE([bpf],
+AS_HELP_STRING([--disable-bpf],[disable use of bpf in fuse4fs]), [] [])
+
+dnl
+dnl If we have fuse and iomap, let's see if we can build BPF
+dnl
+AC_ARG_WITH([vmlinux_h_path],
+  [AS_HELP_STRING([--with-vmlinux-h-path@<:@=PATH@:>@],
+		  [Use this vmlinux.h file on the target for compiling BPF programs.])],
+  [],
+  [with_vmlinux_h_path=yes])
+vmlinux_h_path="$withval"
+AC_ARG_WITH([fuse_include_path],
+  [AS_HELP_STRING([--with-fuse-include-path@<:@=PATH@:>@],
+		  [Use this path on the target to libfuse headers for compiling BPF programs.])],
+  [],
+  [with_fuse_include_path=yes])
+fuse_include_path="$withval"
+
+if test "x$enable_bpf" != "xno" && test -n "$have_fuse_lowlevel" && test -n "$have_fuse_iomap"; then
+	AC_MSG_CHECKING(if we can find vmlinux.h)
+
+	dnl
+	dnl fuse4fs needs to have a vmlinux.h to compile bpf on the fly.
+	dnl Either the user gave us a path to one in the target environment,
+	dnl or we need to detect it based on the OS kernel.  If this were to
+	dnl be made production-ready you'd have to detect the path at
+	dnl runtime.  Not sure what you do for SUSE or Debian.
+	dnl
+
+	dnl User-provided path
+	if test -n "$vmlinux_h_path"; then
+		VMLINUX_H_DIR="$(dirname "$vmlinux_h_path")"
+	fi
+
+	dnl RHEL/Fedora
+	location="/usr/src/kernels/$(uname -r)/vmlinux.h"
+	if test -z "$VMLINUX_H_DIR" && test -s "$location"; then
+		VMLINUX_H_DIR="$(dirname "$location")"
+	fi
+
+	dnl Debian
+	location="/usr/include/$(gcc -print-multiarch)/linux/bpf/vmlinux.h"
+	if test -z "$VMLINUX_H_DIR" && test -s "$location"; then
+		VMLINUX_H_DIR="$(dirname "$location")"
+	fi
+
+	if test -n "$VMLINUX_H_DIR"; then
+		AC_MSG_RESULT(yes)
+	else
+		AC_MSG_RESULT(no)
+	fi
+
+	dnl
+	dnl fuse4fs also needs to know the path to the fuse library headers
+	dnl to compile bpf on the fly.  If the user gave us one, cool;
+	dnl otherwise just default to /usr/include/fuse3.
+	dnl
+	if test -n "$fuse_include_path"; then
+		FUSE_INCLUDE_PATH="$fuse_include_path"
+	else
+		FUSE_INCLUDE_PATH="/usr/include/fuse3"
+	fi
+
+	dnl
+	dnl Check for libbpf.  It's not fatal to configure if we don't find it.
+	dnl
+	BPF_LIB=
+	PKG_CHECK_MODULES([libbpf], [libbpf], [BPF_LIB=-lbpf], [BPF_LIB=])
+	AC_SUBST(BPF_LIB)
+
+	dnl
+	dnl Only enable iomap bpf if the compilers work and libbpf is present
+	dnl
+	AC_MSG_CHECKING(if we can enable iomap bpf overrides)
+	if test -n "$VMLINUX_H_DIR" && test -n "$FUSE_INCLUDE_PATH" && test -n "$BPF_LIB"; then
+		AC_DEFINE(HAVE_IOMAP_BPF, 1, Define to 1 if fuse iomap bpf present])
+		AC_DEFINE_UNQUOTED(VMLINUX_H_DIR, ["$VMLINUX_H_DIR"], Location of vmlinux.h])
+		AC_DEFINE_UNQUOTED(FUSE_INCLUDE_PATH, ["$FUSE_INCLUDE_PATH"], Location of fuse headers])
+		have_iomap_bpf=yes
+		AC_SUBST(VMLINUX_H_DIR)
+		AC_MSG_RESULT(yes)
+	else
+		have_iomap_bpf=
+		AC_MSG_RESULT(no)
+	fi
+fi
+AC_SUBST(have_iomap_bpf)
+
+if test "x$enable_bpf" = "xyes" && test -z "$have_iomap_bpf"; then
+	AC_MSG_ERROR([cannot find bpf override library])
+fi
+
 dnl
 dnl see if setproctitle exists
 dnl
diff --git a/fuse4fs/Makefile.in b/fuse4fs/Makefile.in
index 0600485b074158..cb2d6c54a73f07 100644
--- a/fuse4fs/Makefile.in
+++ b/fuse4fs/Makefile.in
@@ -35,12 +35,18 @@ SRCS=\
 	$(srcdir)/../e2fsck/revoke.c \
 	$(srcdir)/../e2fsck/recovery.c
 
-LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBSUPPORT)
+ifeq ($(HAVE_IOMAP_BPF),yes)
+SRCS += $(srcdir)/fuse4fs_bpf.c
+FUSE4FS_OBJS += fuse4fs_bpf.o
+BPF_SKEL=fuse4fs_bpf.h
+endif
+
+LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBSUPPORT) $(LIBBPF)
 DEPLIBS= $(LIBEXT2FS) $(DEPLIBCOM_ERR) $(DEPLIBSUPPORT)
 PROFILED_LIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBSUPPORT) $(PROFILED_LIBCOM_ERR)
 PROFILED_DEPLIBS= $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBSUPPORT) $(DEPPROFILED_LIBCOM_ERR)
 
-STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR)
+STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) $(LIBBPF)
 STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR)
 
 LIBS_E2P= $(LIBE2P) $(LIBCOM_ERR)
@@ -171,6 +177,18 @@ distclean: clean
 # the Makefile.in file
 #
 fuse4fs.o: $(srcdir)/fuse4fs.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
+ $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \
+ $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/ext2fsP.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/version.h \
+ $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/cache.h \
+ $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h \
+ $(top_srcdir)/lib/support/iocache.h $(top_srcdir)/lib/support/psi.h \
+ $(BPF_SKEL)
+fuse4fs_bpf.o: $(srcdir)/fuse4fs_bpf.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
  $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 1fbf5e48af8724..b5deed0ef767e9 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -71,6 +71,10 @@
 #include "uuid/uuid.h"
 #include "e2p/e2p.h"
 
+#ifdef HAVE_IOMAP_BPF
+#include "fuse4fs_bpf.h"
+#endif
+
 #ifdef ENABLE_NLS
 #include <libintl.h>
 #include <locale.h>
@@ -304,7 +308,11 @@ struct fuse4fs {
 #endif
 	/* options set by fuse_opt_parse must be of type int */
 	int iomap_cache;
+#ifdef HAVE_IOMAP_BPF
+	int bpf_crap;
+	struct fuse4fs_bpf_ctl bpf;
 #endif
+#endif /* HAVE_FUSE_IOMAP */
 	unsigned int blockmask;
 	unsigned long offset;
 	unsigned int next_generation;
@@ -2010,6 +2018,10 @@ static void fuse4fs_unmount(struct fuse4fs *ff)
 	char uuid[UUID_STR_SIZE];
 	errcode_t err;
 
+#ifdef HAVE_IOMAP_BPF
+	fuse4fs_bpf_ctl_cleanup(&ff->bpf);
+#endif
+
 	if (ff->fs) {
 		if (cache_initialized(&ff->inodes)) {
 			cache_purge(&ff->inodes);
@@ -7788,6 +7800,73 @@ static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes,
 				&ff->old_alloc_stats_range);
 	}
 
+#ifdef HAVE_IOMAP_BPF
+	if (ff->bpf_crap) {
+		char source_code[4096];
+		struct fuse4fs_bpf_attrs attrs = {
+			.skel_name	= "bogus_iomap_bpf",
+			.ops_name	= "bogus_iomap_bpf_ops",
+			.begin_fn_name	= "bogus_iomap_begin_bpf",
+//			.end_fn_name	= "bogus_iomap_end_bpf",
+//			.ioend_fn_name	= "bogus_iomap_ioend_bpf",
+		};
+		struct fuse4fs_bpf_compile cc = {
+			.source_code = source_code,
+			.vmlinux_h_dir	= VMLINUX_H_DIR,
+			.fuse_include_dir = FUSE_INCLUDE_PATH,
+		};
+		int ret2;
+
+		snprintf(source_code, sizeof(source_code),
+"#include <vmlinux.h>\n\
+#include <bpf/bpf_helpers.h>\n\
+#include <bpf/bpf_tracing.h>\n\
+\n\
+#include <fuse_iomap_bpf.h>\n\
+\n\
+DECLARE_GPL2_LICENSE_FOR_FUSE_IOMAP_BPF;\n\
+\n\
+FUSE_IOMAP_BEGIN_BPF_FUNC(bogus_iomap_begin_bpf)\n\
+{\n\
+	const uint32_t dev = %u;\n\
+	const uint32_t blocksize = %u;\n\
+\n\
+	/*\n\
+	 * Create an alternating pattern of written and unwritten mappings\n\
+	 * for FIEMAP as a demonstration of using BPF for iomapping.  Do NOT\n\
+	 * run this in production!\n\
+	 */\n\
+	if ((opflags & FUSE_IOMAP_OP_REPORT) && pos <= (16 * blocksize)) {\n\
+		outarg->read.offset = pos;\n\
+		outarg->read.length = blocksize;\n\
+		outarg->read.type = ((pos / blocksize) %% 2) + FUSE_IOMAP_TYPE_MAPPED;\n\
+		outarg->read.dev = dev;\n\
+		outarg->read.addr = (99 * blocksize) + pos;\n\
+\n\
+		fuse_iomap_begin_pure_overwrite(outarg);\n\
+		return FIB_HANDLED;\n\
+	}\n\
+\n\
+	return FIB_FALLBACK;\n\
+}\n\
+\n\
+DEFINE_FUSE_IOMAP_BPF_OPS(bogus_iomap_bpf_ops, \"bogus_bpf\",\n\
+		bogus_iomap_begin_bpf, NULL, NULL);\n",
+				ff->iomap_dev,
+				ff->fs->blocksize);
+
+		ret2 = fuse4fs_bpf_compile(&attrs, &cc);
+		if (!ret2) {
+			ret2 = fuse4fs_bpf_ctl_setup(&ff->bpf, ff->fuse, &attrs);
+			fuse4fs_bpf_ctl_drop_skeleton(&ff->bpf);
+		}
+		if (ret2) {
+			fprintf(stderr,
+ _("Setting up bogus bpf prog failed with err=%d\n"), ret2);
+		}
+	}
+#endif
+
 out_unlock:
 	fuse4fs_finish(ff, ret);
 	if (ret)
@@ -8282,7 +8361,10 @@ static struct fuse_opt fuse4fs_opts[] = {
 #ifdef HAVE_FUSE_IOMAP
 	FUSE4FS_OPT("iomap_cache",	iomap_cache,		1),
 	FUSE4FS_OPT("noiomap_cache",	iomap_cache,		0),
+#ifdef HAVE_IOMAP_BPF
+	FUSE4FS_OPT("bpf_crap",		bpf_crap,		1),
 #endif
+#endif /* HAVE_FUSE_IOMAP */
 
 #ifdef HAVE_FUSE_IOMAP
 #ifdef MS_LAZYTIME
diff --git a/fuse4fs/fuse4fs_bpf.c b/fuse4fs/fuse4fs_bpf.c
new file mode 100644
index 00000000000000..fb66b72febe729
--- /dev/null
+++ b/fuse4fs/fuse4fs_bpf.c
@@ -0,0 +1,404 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include "config.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+#include <bpf/libbpf.h>
+#include <fuse_lowlevel.h>
+
+#include "fuse4fs_bpf.h"
+
+#define max(a, b)	((a) > (b) ? (a) : (b))
+#define BPF_SKEL_SUPPORTS_MAP_AUTO_ATTACH 1
+
+struct fuse4fs_bpf {
+	struct bpf_object_skeleton *skeleton;
+	struct bpf_object *obj;
+	struct {
+		struct bpf_map *fuse4fs_bpf_ops;
+	} maps;
+	struct {
+		struct fuse4fs_bpf__fuse4fs_bpf_ops__fuse_iomap_bpf_ops {
+			struct bpf_program *iomap_begin;
+			struct bpf_program *iomap_end;
+			struct bpf_program *iomap_ioend;
+			int fuse_fd;
+			unsigned int zeropad;
+			char __unsupported_5[16];
+		} *fuse4fs_bpf_ops;
+	} struct_ops;
+	struct {
+		struct bpf_program *crazy_begin_bpf;
+		struct bpf_program *crazy_end_bpf;
+		struct bpf_program *crazy_ioend_bpf;
+	} progs;
+	struct {
+		struct bpf_link *crazy_begin_bpf;
+		struct bpf_link *crazy_end_bpf;
+		struct bpf_link *crazy_ioend_bpf;
+		struct bpf_link *fuse4fs_bpf_ops;
+	} links;
+};
+
+static void
+fuse4fs_bpf__destroy(struct fuse4fs_bpf *obj)
+{
+	if (!obj)
+		return;
+	if (obj->skeleton)
+		bpf_object__destroy_skeleton(obj->skeleton);
+	free(obj);
+}
+
+static inline size_t
+fuse4fs_bpf_nr_progs(const struct fuse4fs_bpf_attrs *attrs)
+{
+	size_t ret = 0;
+
+	if (attrs->begin_fn_name)
+		ret++;
+	if (attrs->end_fn_name)
+		ret++;
+	if (attrs->ioend_fn_name)
+		ret++;
+	return ret;
+}
+
+static int
+fuse4fs_bpf__create_skeleton(struct fuse4fs_bpf *obj,
+			   const struct fuse4fs_bpf_attrs *attrs)
+{
+	struct bpf_object_skeleton *s;
+	struct bpf_map_skeleton *map __attribute__((unused));
+	int err;
+
+	s = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));
+	if (!s)	{
+		err = -ENOMEM;
+		goto err;
+	}
+
+	s->sz = sizeof(*s);
+	s->name = attrs->skel_name;
+	s->obj = &obj->obj;
+
+	/* maps */
+	s->map_cnt = 1;
+	s->map_skel_sz = 32;
+	s->maps = (struct bpf_map_skeleton *)calloc(s->map_cnt,
+			sizeof(*s->maps) > 32 ? sizeof(*s->maps) : 32);
+	if (!s->maps) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	map = (struct bpf_map_skeleton *)((char *)s->maps + 0 * s->map_skel_sz);
+	map->name = attrs->ops_name;
+	map->map = &obj->maps.fuse4fs_bpf_ops;
+	map->link = &obj->links.fuse4fs_bpf_ops;
+
+	/* programs */
+	s->prog_cnt = 0;
+	s->prog_skel_sz = sizeof(*s->progs);
+	s->progs = calloc(fuse4fs_bpf_nr_progs(attrs), s->prog_skel_sz);
+	if (!s->progs) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	if (attrs->begin_fn_name) {
+		s->progs[s->prog_cnt].name = attrs->begin_fn_name;
+		s->progs[s->prog_cnt].prog = &obj->progs.crazy_begin_bpf;
+		s->progs[s->prog_cnt].link = &obj->links.crazy_begin_bpf;
+		s->prog_cnt++;
+	}
+
+	if (attrs->end_fn_name) {
+		s->progs[s->prog_cnt].name = attrs->end_fn_name;
+		s->progs[s->prog_cnt].prog = &obj->progs.crazy_end_bpf;
+		s->progs[s->prog_cnt].link = &obj->links.crazy_end_bpf;
+		s->prog_cnt++;
+	}
+
+	if (attrs->ioend_fn_name) {
+		s->progs[s->prog_cnt].name = attrs->ioend_fn_name;
+		s->progs[s->prog_cnt].prog = &obj->progs.crazy_ioend_bpf;
+		s->progs[s->prog_cnt].link = &obj->links.crazy_ioend_bpf;
+		s->prog_cnt++;
+	}
+
+	s->data = attrs->elf_data;
+	s->data_sz = attrs->elf_size;
+
+	obj->skeleton = s;
+	return 0;
+err:
+	bpf_object__destroy_skeleton(s);
+	return err;
+}
+
+static struct fuse4fs_bpf *
+fuse4fs_bpf__open_opts(const struct bpf_object_open_opts *opts,
+		     const struct fuse4fs_bpf_attrs *attrs)
+{
+	struct fuse4fs_bpf *obj;
+	int err;
+
+	obj = (struct fuse4fs_bpf *)calloc(1, sizeof(*obj));
+	if (!obj) {
+		errno = ENOMEM;
+		return NULL;
+	}
+
+	err = fuse4fs_bpf__create_skeleton(obj, attrs);
+	if (err)
+		goto err_out;
+
+	err = bpf_object__open_skeleton(obj->skeleton, opts);
+	if (err)
+		goto err_out;
+
+	obj->struct_ops.fuse4fs_bpf_ops = (__typeof__(obj->struct_ops.fuse4fs_bpf_ops))
+		bpf_map__initial_value(obj->maps.fuse4fs_bpf_ops, NULL);
+
+	return obj;
+err_out:
+	fuse4fs_bpf__destroy(obj);
+	errno = -err;
+	return NULL;
+}
+
+static inline int
+fuse4fs_bpf__load(struct fuse4fs_bpf *obj)
+{
+	return bpf_object__load_skeleton(obj->skeleton);
+}
+
+static inline int
+fuse4fs_bpf__attach(struct fuse4fs_bpf *obj)
+{
+	return bpf_object__attach_skeleton(obj->skeleton);
+}
+
+static inline void
+fuse4fs_bpf__detach(struct fuse4fs_bpf *obj)
+{
+	bpf_object__detach_skeleton(obj->skeleton);
+}
+
+/* Put compiled BPF program in the kernel and link it to the fuse connection */
+int
+fuse4fs_bpf_ctl_setup(struct fuse4fs_bpf_ctl *arg, struct fuse_session *se,
+		      const struct fuse4fs_bpf_attrs *attrs)
+{
+	int err;
+
+	arg->skel = fuse4fs_bpf__open_opts(NULL, attrs);
+	if (!arg->skel)
+		return -ENOENT;
+
+	arg->skel->struct_ops.fuse4fs_bpf_ops->fuse_fd = fuse_session_fd(se);
+
+	err = fuse4fs_bpf__load(arg->skel);
+	if (err) {
+		err = -EINVAL;
+		goto cleanup;
+	}
+
+	arg->link = bpf_map__attach_struct_ops(arg->skel->maps.fuse4fs_bpf_ops);
+	if (!arg->link) {
+		err = -errno;
+		goto cleanup;
+	}
+
+	return 0;
+
+cleanup:
+	fuse4fs_bpf__destroy(arg->skel);
+	arg->skel = NULL;
+	return err;
+}
+
+/* Drop the BPF object code but leave the overrides running */
+void
+fuse4fs_bpf_ctl_drop_skeleton(struct fuse4fs_bpf_ctl *arg)
+{
+	if (arg->skel) {
+		fuse4fs_bpf__destroy(arg->skel);
+		arg->skel = NULL;
+	}
+}
+
+/* Drop all the BPF artifacts, disabling the override */
+void
+fuse4fs_bpf_ctl_cleanup(struct fuse4fs_bpf_ctl *arg)
+{
+	if (arg->link) {
+		bpf_link__destroy(arg->link);
+		arg->link = NULL;
+	}
+
+	if (arg->skel) {
+		fuse4fs_bpf__destroy(arg->skel);
+		arg->skel = NULL;
+	}
+}
+
+static void
+close_fds(int start_fd)
+{
+	int max_fd = sysconf(_SC_OPEN_MAX);
+	int fd;
+#ifdef HAVE_CLOSE_RANGE
+	int ret;
+#endif
+
+	if (max_fd < 1)
+		max_fd = 1024;
+
+#ifdef HAVE_CLOSE_RANGE
+	ret = close_range(start_fd, max_fd, 0);
+	if (!ret)
+		return;
+#endif
+
+	for (fd = start_fd; fd < max_fd; fd++)
+		close(fd);
+}
+
+/* Compile some BPF source code into binary format */
+int
+fuse4fs_bpf_compile(struct fuse4fs_bpf_attrs *attrs,
+		    const struct fuse4fs_bpf_compile *cc)
+{
+	char infile[64];
+	char outfile[64];
+	// clang --target=bpf -Wall -O2 -g -x c -c /dev/fd/37 -o /dev/fd/38
+	// -I /usr/include/x86_64-linux-gnu/linux/bpf/ -I ../../include/
+	char *args[] = {
+		"clang", "--target=bpf", "-Wall", "-O2", "-g", "-x", "c",
+		"-c", infile, "-o", outfile,
+		"-I", (char *)cc->vmlinux_h_dir,
+		"-I", (char *)cc->fuse_include_dir,
+		NULL
+	};
+	struct stat statbuf;
+	void *buf, *read_ptr;
+	const void *write_ptr;
+	size_t to_read, to_write;
+	pid_t child;
+	int child_status;
+	int infd;
+	int outfd;
+	int ret = 0;
+
+	infd = memfd_create("infile", 0);
+	if (infd < 0)
+		return -1;
+
+	outfd = memfd_create("outfile", 0);
+	if (outfd < 0) {
+		ret = -1;
+		goto out_infd;
+	}
+
+	snprintf(infile, sizeof(infile), "/dev/fd/%d", infd);
+	snprintf(outfile, sizeof(outfile), "/dev/fd/%d", outfd);
+
+	write_ptr = cc->source_code;
+	to_write = strlen(cc->source_code);
+	while (to_write > 0) {
+		ssize_t bytes_written = write(infd, write_ptr, to_write);
+		if (bytes_written < 0) {
+			ret = -1;
+			goto out_outfd;
+		}
+		if (bytes_written == 0) {
+			errno = EIO;
+			ret = -1;
+			goto out_outfd;
+		}
+
+		write_ptr += bytes_written;
+		to_write -= bytes_written;
+	}
+
+	child = fork();
+	switch (child) {
+	case -1:
+		ret = -1;
+		goto out_outfd;
+	case 0:
+		close_fds(max(infd, outfd) + 1);
+		execvp(args[0], args);
+		perror(args[0]);
+		exit(EXIT_FAILURE);
+		break;
+	default:
+		waitpid(child, &child_status, 0);
+		break;
+	}
+
+	if (!WIFEXITED(child_status) || WEXITSTATUS(child_status) != 0) {
+		errno = ENOMEM;
+		ret = -1;
+		goto out_outfd;
+	}
+
+	ret = fstat(outfd, &statbuf);
+	if (ret)
+		goto out_outfd;
+
+	if (statbuf.st_size >= SIZE_MAX) {
+		errno = EFBIG;
+		ret = -1;
+		goto out_outfd;
+	}
+	to_read = statbuf.st_size;
+
+	buf = malloc(to_read);
+	if (!buf)
+		goto out_outfd;
+	read_ptr = buf;
+
+	while (to_read > 0) {
+		ssize_t bytes_read = read(outfd, read_ptr, to_read);
+		if (bytes_read < 0) {
+			ret = -1;
+			goto out_buf;
+		}
+		if (bytes_read == 0) {
+			errno = EIO;
+			ret = -1;
+			goto out_buf;
+		}
+
+		read_ptr += bytes_read;
+		to_read -= bytes_read;
+	}
+
+	attrs->elf_data = buf;
+	attrs->elf_size = statbuf.st_size;
+	buf = NULL;
+	ret = 0;
+
+out_buf:
+	free(buf);
+out_outfd:
+	close(outfd);
+out_infd:
+	close(infd);
+	return ret;
+}
diff --git a/lib/config.h.in b/lib/config.h.in
index 129f7ffcf060f3..ecc81eea839f16 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -99,6 +99,9 @@
 /* Define to 1 if you have the 'chflags' function. */
 #undef HAVE_CHFLAGS
 
+/* Define to 1 if you have the 'close_range' function. */
+#undef HAVE_CLOSE_RANGE
+
 /* Define if the GNU dcgettext() function is already present or preinstalled.
    */
 #undef HAVE_DCGETTEXT
@@ -717,4 +720,13 @@
 /* Define to 1 if you have the 'setproctitle' function. */
 #undef HAVE_SETPROCTITLE
 
+/* Define to 1 if fuse iomap bpf present */
+#undef HAVE_IOMAP_BPF
+
+/* Location of vmlinux.h */
+#undef VMLINUX_H_DIR
+
+/* Location of fuse headers */
+#undef FUSE_INCLUDE_PATH
+
 #include <dirpaths.h>


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 2/3] fuse4fs: wire up caching examples to fuse iomap bpf program
  2026-02-23 23:06 ` [PATCHSET RFC 8/8] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
  2026-02-23 23:49   ` [PATCH 1/3] fuse4fs: add dynamic iomap bpf prototype which will break FIEMAP Darrick J. Wong
@ 2026-02-23 23:49   ` Darrick J. Wong
  2026-02-23 23:50   ` [PATCH 3/3] fuse4fs: adjust test bpf program to deal with opaque inodes Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:49 UTC (permalink / raw)
  To: tytso
  Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal,
	john

From: Darrick J. Wong <djwong@kernel.org>

Continue our demonstration of fuse iomap bpf by enabling the test
program to update the iomap cache.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |   10 ++++++++++
 1 file changed, 10 insertions(+)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index b5deed0ef767e9..b3c5d571d52448 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -7830,6 +7830,9 @@ FUSE_IOMAP_BEGIN_BPF_FUNC(bogus_iomap_begin_bpf)\n\
 {\n\
 	const uint32_t dev = %u;\n\
 	const uint32_t blocksize = %u;\n\
+\n\
+	bpf_printk(\"ino %%llu pos %%llu\\n\",\n\
+		   fi->nodeid,  pos);\n\
 \n\
 	/*\n\
 	 * Create an alternating pattern of written and unwritten mappings\n\
@@ -7837,6 +7840,11 @@ FUSE_IOMAP_BEGIN_BPF_FUNC(bogus_iomap_begin_bpf)\n\
 	 * run this in production!\n\
 	 */\n\
 	if ((opflags & FUSE_IOMAP_OP_REPORT) && pos <= (16 * blocksize)) {\n\
+		struct fuse_range fubar = {\n\
+			.offset = 325 * blocksize,\n\
+			.length = 37 * blocksize,\n\
+		};\n\
+\n\
 		outarg->read.offset = pos;\n\
 		outarg->read.length = blocksize;\n\
 		outarg->read.type = ((pos / blocksize) %% 2) + FUSE_IOMAP_TYPE_MAPPED;\n\
@@ -7844,6 +7852,8 @@ FUSE_IOMAP_BEGIN_BPF_FUNC(bogus_iomap_begin_bpf)\n\
 		outarg->read.addr = (99 * blocksize) + pos;\n\
 \n\
 		fuse_iomap_begin_pure_overwrite(outarg);\n\
+		fuse_bpf_iomap_inval_mappings(fi, &fubar, NULL);\n\
+		fuse_bpf_iomap_upsert_mappings(fi, &outarg->read, NULL);\n\
 		return FIB_HANDLED;\n\
 	}\n\
 \n\


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* [PATCH 3/3] fuse4fs: adjust test bpf program to deal with opaque inodes
  2026-02-23 23:06 ` [PATCHSET RFC 8/8] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
  2026-02-23 23:49   ` [PATCH 1/3] fuse4fs: add dynamic iomap bpf prototype which will break FIEMAP Darrick J. Wong
  2026-02-23 23:49   ` [PATCH 2/3] fuse4fs: wire up caching examples to fuse iomap bpf program Darrick J. Wong
@ 2026-02-23 23:50   ` Darrick J. Wong
  2 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-23 23:50 UTC (permalink / raw)
  To: tytso
  Cc: bpf, linux-fsdevel, linux-ext4, miklos, bernd, joannelkoong, neal,
	john

From: Darrick J. Wong <djwong@kernel.org>

Adjust the test program to deal with fuse_bpf_inode.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fuse4fs/fuse4fs.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index b3c5d571d52448..09ffd93c72724e 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -7832,7 +7832,7 @@ FUSE_IOMAP_BEGIN_BPF_FUNC(bogus_iomap_begin_bpf)\n\
 	const uint32_t blocksize = %u;\n\
 \n\
 	bpf_printk(\"ino %%llu pos %%llu\\n\",\n\
-		   fi->nodeid,  pos);\n\
+		   fuse_bpf_inode_nodeid(fbi),  pos);\n\
 \n\
 	/*\n\
 	 * Create an alternating pattern of written and unwritten mappings\n\
@@ -7852,8 +7852,8 @@ FUSE_IOMAP_BEGIN_BPF_FUNC(bogus_iomap_begin_bpf)\n\
 		outarg->read.addr = (99 * blocksize) + pos;\n\
 \n\
 		fuse_iomap_begin_pure_overwrite(outarg);\n\
-		fuse_bpf_iomap_inval_mappings(fi, &fubar, NULL);\n\
-		fuse_bpf_iomap_upsert_mappings(fi, &outarg->read, NULL);\n\
+		fuse_bpf_iomap_inval_mappings(fbi, &fubar, NULL);\n\
+		fuse_bpf_iomap_upsert_mappings(fbi, &outarg->read, NULL);\n\
 		return FIB_HANDLED;\n\
 	}\n\
 \n\


^ permalink raw reply related	[flat|nested] 234+ messages in thread

* Re: [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write
  2026-02-23 23:06   ` [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write Darrick J. Wong
@ 2026-02-24  8:36     ` Horst Birthelmer
  2026-02-24 19:17       ` Darrick J. Wong
  2026-02-24 20:09     ` Joanne Koong
  2026-02-27 16:05     ` Miklos Szeredi
  2 siblings, 1 reply; 234+ messages in thread
From: Horst Birthelmer @ 2026-02-24  8:36 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: miklos, stable, joannelkoong, bpf, bernd, neal, linux-fsdevel,
	linux-ext4

On Mon, Feb 23, 2026 at 03:06:50PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> gcc 15 complains about an uninitialized variable val that is passed by
> reference into fuse_conn_limit_write:
> 
>  control.c: In function ‘fuse_conn_congestion_threshold_write’:
>  include/asm-generic/rwonce.h:55:37: warning: ‘val’ may be used uninitialized [-Wmaybe-uninitialized]
>     55 |         *(volatile typeof(x) *)&(x) = (val);                            \
>        |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
>  include/asm-generic/rwonce.h:61:9: note: in expansion of macro ‘__WRITE_ONCE’
>     61 |         __WRITE_ONCE(x, val);                                           \
>        |         ^~~~~~~~~~~~
>  control.c:178:9: note: in expansion of macro ‘WRITE_ONCE’
>    178 |         WRITE_ONCE(fc->congestion_threshold, val);
>        |         ^~~~~~~~~~
>  control.c:166:18: note: ‘val’ was declared here
>    166 |         unsigned val;
>        |                  ^~~
> 
> Unfortunately there's enough macro spew involved in kstrtoul_from_user
> that I think gcc gives up on its analysis and sprays the above warning.
> AFAICT it's not actually a bug, but we could just zero-initialize the
> variable to enable using -Wmaybe-uninitialized to find real problems.
> 
> Previously we would use some weird uninitialized_var annotation to quiet
> down the warnings, so clearly this code has been like this for quite
> some time.
> 
> Cc: <stable@vger.kernel.org> # v5.9
> Fixes: 3f649ab728cda8 ("treewide: Remove uninitialized_var() usage")
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> ---
>  fs/fuse/control.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> 
> diff --git a/fs/fuse/control.c b/fs/fuse/control.c
> index 140bd5730d9984..073c2d8e4dfc7c 100644
> --- a/fs/fuse/control.c
> +++ b/fs/fuse/control.c
> @@ -121,7 +121,7 @@ static ssize_t fuse_conn_max_background_write(struct file *file,
>  					      const char __user *buf,
>  					      size_t count, loff_t *ppos)
>  {
> -	unsigned val;
> +	unsigned val = 0;
>  	ssize_t ret;
>  
>  	ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
> @@ -163,7 +163,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
>  						    const char __user *buf,
>  						    size_t count, loff_t *ppos)
>  {
> -	unsigned val;
> +	unsigned val = 0;
>  	struct fuse_conn *fc;
>  	ssize_t ret;
>  
> 
> 

This looks good to me. Trivial fix for an annoying problem.
Reviewed-by: Horst Birthelmer <hbirthelmer@ddn.com>

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 29/33] fuse: support atomic writes with iomap
  2026-02-23 23:16   ` [PATCH 29/33] fuse: support atomic writes with iomap Darrick J. Wong
@ 2026-02-24 12:58     ` Pankaj Raghav (Samsung)
  2026-02-24 19:30       ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Pankaj Raghav (Samsung) @ 2026-02-24 12:58 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: miklos, joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

> +	}
> +
>  	/*
>  	 * Unaligned direct writes require zeroing of unwritten head and tail
>  	 * blocks.  Extending writes require zeroing of post-EOF tail blocks.
> @@ -1873,6 +1909,12 @@ static ssize_t fuse_iomap_buffered_write(struct kiocb *iocb,
>  	if (!iov_iter_count(from))
>  		return 0;
>  
> +	if (iocb->ki_flags & IOCB_ATOMIC) {
> +		ret = fuse_iomap_atomic_write_valid(iocb, from);
> +		if (ret)
> +			return ret;
> +	}
> +

I still haven't gone through the whole patch blizzard but I had a
general question here: we don't give ATOMIC guarantees to buffered IO,
so I am wondering how we give that here. For example, we might mix
atomic and non atomic buffered IO during writeback. Am I missing some
implementation detail that makes it possible here? I don't think we
should enable this for buffered IO.

-- 
Pankaj

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 1/2] iomap: allow directio callers to supply _COMP_WORK
  2026-02-23 23:07   ` [PATCH 1/2] iomap: allow directio callers to supply _COMP_WORK Darrick J. Wong
@ 2026-02-24 14:00     ` Christoph Hellwig
  2026-02-24 19:17       ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Christoph Hellwig @ 2026-02-24 14:00 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: brauner, miklos, bpf, hch, linux-fsdevel, linux-ext4

On Mon, Feb 23, 2026 at 03:07:53PM -0800, Darrick J. Wong wrote:
>  #define IOMAP_DIO_NO_INVALIDATE	(1U << 26)
> -#define IOMAP_DIO_COMP_WORK	(1U << 27)
>  #define IOMAP_DIO_WRITE_THROUGH	(1U << 28)
>  #define IOMAP_DIO_NEED_SYNC	(1U << 29)
>  #define IOMAP_DIO_WRITE		(1U << 30)

Maybe move up IOMAP_DIO_NO_INVALIDATE to avoid unused bits?

Otherwise this looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile
  2026-02-23 23:08   ` [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile Darrick J. Wong
@ 2026-02-24 14:01     ` Christoph Hellwig
  2026-02-24 19:26       ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Christoph Hellwig @ 2026-02-24 14:01 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: brauner, miklos, bpf, hch, linux-fsdevel, linux-ext4

On Mon, Feb 23, 2026 at 03:08:08PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> All current users of the iomap swapfile activation mechanism are block
> device filesystems.  This means that claim_swapfile will set
> swap_info_struct::bdev to inode->i_sb->s_bdev of the swap file.
> 
> However, a subsequent patch to fuse will add iomap infrastructure so
> that fuse servers can be asked to provide file mappings specifically for
> swap files.

That sounds pretty sketchy.  How do you make sure that is safe vs
memory reclaim deadlocks?  Does someone really need this feature?


^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 1/2] iomap: allow directio callers to supply _COMP_WORK
  2026-02-24 14:00     ` Christoph Hellwig
@ 2026-02-24 19:17       ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-24 19:17 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: brauner, miklos, bpf, linux-fsdevel, linux-ext4

On Tue, Feb 24, 2026 at 03:00:30PM +0100, Christoph Hellwig wrote:
> On Mon, Feb 23, 2026 at 03:07:53PM -0800, Darrick J. Wong wrote:
> >  #define IOMAP_DIO_NO_INVALIDATE	(1U << 26)
> > -#define IOMAP_DIO_COMP_WORK	(1U << 27)
> >  #define IOMAP_DIO_WRITE_THROUGH	(1U << 28)
> >  #define IOMAP_DIO_NEED_SYNC	(1U << 29)
> >  #define IOMAP_DIO_WRITE		(1U << 30)
> 
> Maybe move up IOMAP_DIO_NO_INVALIDATE to avoid unused bits?
> 
> Otherwise this looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Done, and thanks for the review!

--D

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write
  2026-02-24  8:36     ` Horst Birthelmer
@ 2026-02-24 19:17       ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-24 19:17 UTC (permalink / raw)
  To: Horst Birthelmer
  Cc: miklos, stable, joannelkoong, bpf, bernd, neal, linux-fsdevel,
	linux-ext4

On Tue, Feb 24, 2026 at 09:36:38AM +0100, Horst Birthelmer wrote:
> On Mon, Feb 23, 2026 at 03:06:50PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > gcc 15 complains about an uninitialized variable val that is passed by
> > reference into fuse_conn_limit_write:
> > 
> >  control.c: In function ‘fuse_conn_congestion_threshold_write’:
> >  include/asm-generic/rwonce.h:55:37: warning: ‘val’ may be used uninitialized [-Wmaybe-uninitialized]
> >     55 |         *(volatile typeof(x) *)&(x) = (val);                            \
> >        |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
> >  include/asm-generic/rwonce.h:61:9: note: in expansion of macro ‘__WRITE_ONCE’
> >     61 |         __WRITE_ONCE(x, val);                                           \
> >        |         ^~~~~~~~~~~~
> >  control.c:178:9: note: in expansion of macro ‘WRITE_ONCE’
> >    178 |         WRITE_ONCE(fc->congestion_threshold, val);
> >        |         ^~~~~~~~~~
> >  control.c:166:18: note: ‘val’ was declared here
> >    166 |         unsigned val;
> >        |                  ^~~
> > 
> > Unfortunately there's enough macro spew involved in kstrtoul_from_user
> > that I think gcc gives up on its analysis and sprays the above warning.
> > AFAICT it's not actually a bug, but we could just zero-initialize the
> > variable to enable using -Wmaybe-uninitialized to find real problems.
> > 
> > Previously we would use some weird uninitialized_var annotation to quiet
> > down the warnings, so clearly this code has been like this for quite
> > some time.
> > 
> > Cc: <stable@vger.kernel.org> # v5.9
> > Fixes: 3f649ab728cda8 ("treewide: Remove uninitialized_var() usage")
> > Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> > ---
> >  fs/fuse/control.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > 
> > diff --git a/fs/fuse/control.c b/fs/fuse/control.c
> > index 140bd5730d9984..073c2d8e4dfc7c 100644
> > --- a/fs/fuse/control.c
> > +++ b/fs/fuse/control.c
> > @@ -121,7 +121,7 @@ static ssize_t fuse_conn_max_background_write(struct file *file,
> >  					      const char __user *buf,
> >  					      size_t count, loff_t *ppos)
> >  {
> > -	unsigned val;
> > +	unsigned val = 0;
> >  	ssize_t ret;
> >  
> >  	ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
> > @@ -163,7 +163,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
> >  						    const char __user *buf,
> >  						    size_t count, loff_t *ppos)
> >  {
> > -	unsigned val;
> > +	unsigned val = 0;
> >  	struct fuse_conn *fc;
> >  	ssize_t ret;
> >  
> > 
> > 
> 
> This looks good to me. Trivial fix for an annoying problem.
> Reviewed-by: Horst Birthelmer <hbirthelmer@ddn.com>

Thanks for the review!

--D

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile
  2026-02-24 14:01     ` Christoph Hellwig
@ 2026-02-24 19:26       ` Darrick J. Wong
  2026-02-25 14:16         ` Christoph Hellwig
  0 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-24 19:26 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: brauner, miklos, bpf, linux-fsdevel, linux-ext4

On Tue, Feb 24, 2026 at 03:01:18PM +0100, Christoph Hellwig wrote:
> On Mon, Feb 23, 2026 at 03:08:08PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > All current users of the iomap swapfile activation mechanism are block
> > device filesystems.  This means that claim_swapfile will set
> > swap_info_struct::bdev to inode->i_sb->s_bdev of the swap file.
> > 
> > However, a subsequent patch to fuse will add iomap infrastructure so
> > that fuse servers can be asked to provide file mappings specifically for
> > swap files.
> 
> That sounds pretty sketchy.  How do you make sure that is safe vs
> memory reclaim deadlocks?  Does someone really need this feature?

Err, which part is sketchy, specifically?  This patch that adjusts stuff
in fs/iomap/, or the (much later) patch to fuse-iomap?

If it's the second part (activating swapfiles via fuse-iomap) then I'll
state that fuse-iomap swapfiles work mostly the same way that they do in
xfs: iomap_swapfile_activate calls ->iomap_begin, which calls the fuse
server to get iomappings.  Each iomap is passed to the mm, which
constructs its own internal mapping of swapfile range to disk addresses.
The swap code then submits bios to read/write swapfile contents
directly, which means that there are no upcalls to the fuse server after
the initial activation.

Obviously this means that the fuse server is granting a longterm layout
lease to the kernel swapfile code, so it should reply to
fuse_iomap_begin with a error code if it doesn't want to do that.

I don't know that anyone really needs this feature, but pre-iomap
fuse2fs supports swapfiles, as does any other fuse server that
implements bmap.

--D

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 29/33] fuse: support atomic writes with iomap
  2026-02-24 12:58     ` Pankaj Raghav (Samsung)
@ 2026-02-24 19:30       ` Darrick J. Wong
  2026-02-24 21:18         ` Pankaj Raghav (Samsung)
  0 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-24 19:30 UTC (permalink / raw)
  To: Pankaj Raghav (Samsung)
  Cc: miklos, joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Tue, Feb 24, 2026 at 12:58:31PM +0000, Pankaj Raghav (Samsung) wrote:
> > +	}
> > +
> >  	/*
> >  	 * Unaligned direct writes require zeroing of unwritten head and tail
> >  	 * blocks.  Extending writes require zeroing of post-EOF tail blocks.
> > @@ -1873,6 +1909,12 @@ static ssize_t fuse_iomap_buffered_write(struct kiocb *iocb,
> >  	if (!iov_iter_count(from))
> >  		return 0;
> >  
> > +	if (iocb->ki_flags & IOCB_ATOMIC) {
> > +		ret = fuse_iomap_atomic_write_valid(iocb, from);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> 
> I still haven't gone through the whole patch blizzard but I had a
> general question here: we don't give ATOMIC guarantees to buffered IO,
> so I am wondering how we give that here.

Oh, we don't.  generic_atomic_write_valid rejects !IOCB_DIRECT iocbs.

> For example, we might mix
> atomic and non atomic buffered IO during writeback. Am I missing some
> implementation detail that makes it possible here? I don't think we
> should enable this for buffered IO.

<nod> Now that y'all have an lsf thread on this, I agree that not
supporting buffered writes in fuse-iomap should be more explicit.

	if (iocb->ki_flags & IOCB_ATOMIC)
		return -EOPNOTSUPP;

--D

> -- 
> Pankaj
> 

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 1/5] fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY
  2026-02-23 23:06   ` [PATCH 1/5] fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY Darrick J. Wong
@ 2026-02-24 19:33     ` Joanne Koong
  2026-02-24 19:57       ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Joanne Koong @ 2026-02-24 19:33 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: miklos, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Mon, Feb 23, 2026 at 3:06 PM Darrick J. Wong <djwong@kernel.org> wrote:
>
> From: Darrick J. Wong <djwong@kernel.org>
>
> generic/488 fails with fuse2fs in the following fashion:
>
> generic/488       _check_generic_filesystem: filesystem on /dev/sdf is inconsistent
> (see /var/tmp/fstests/generic/488.full for details)
>
> This test opens a large number of files, unlinks them (which really just
> renames them to fuse hidden files), closes the program, unmounts the
> filesystem, and runs fsck to check that there aren't any inconsistencies
> in the filesystem.
>
> Unfortunately, the 488.full file shows that there are a lot of hidden
> files left over in the filesystem, with incorrect link counts.  Tracing
> fuse_request_* shows that there are a large number of FUSE_RELEASE
> commands that are queued up on behalf of the unlinked files at the time
> that fuse_conn_destroy calls fuse_abort_conn.  Had the connection not
> aborted, the fuse server would have responded to the RELEASE commands by
> removing the hidden files; instead they stick around.
>
> For upper-level fuse servers that don't use fuseblk mode this isn't a
> problem because libfuse responds to the connection going down by pruning
> its inode cache and calling the fuse server's ->release for any open
> files before calling the server's ->destroy function.
>
> For fuseblk servers this is a problem, however, because the kernel sends
> FUSE_DESTROY to the fuse server, and the fuse server has to write all of
> its pending changes to the block device before replying to the DESTROY
> request because the kernel releases its O_EXCL hold on the block device.
> This means that the kernel must flush all pending FUSE_RELEASE requests
> before issuing FUSE_DESTROY.
>
> For fuse-iomap servers this will also be a problem because iomap servers
> are expected to release all exclusively-held resources before unmount
> returns from the kernel.
>
> Create a function to push all the background requests to the queue
> before sending FUSE_DESTROY.  That way, all the pending file release
> events are processed by the fuse server before it tears itself down, and
> we don't end up with a corrupt filesystem.
>
> Note that multithreaded fuse servers will need to track the number of
> open files and defer a FUSE_DESTROY request until that number reaches
> zero.  An earlier version of this patch made the kernel wait for the
> RELEASE acknowledgements before sending DESTROY, but the kernel people
> weren't comfortable with adding blocking waits to unmount.
>
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>

Overall LGTM, left a few comments below

Reviewed-by: Joanne Koong <joannelkoong@gmail.com>

> ---
>  fs/fuse/fuse_i.h |    5 +++++
>  fs/fuse/dev.c    |   19 +++++++++++++++++++
>  fs/fuse/inode.c  |   12 +++++++++++-
>  3 files changed, 35 insertions(+), 1 deletion(-)
>
>
> diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> index 7f16049387d15e..1d4beca5c7018d 100644
> --- a/fs/fuse/fuse_i.h
> +++ b/fs/fuse/fuse_i.h
> @@ -1287,6 +1287,11 @@ void fuse_request_end(struct fuse_req *req);
>  void fuse_abort_conn(struct fuse_conn *fc);
>  void fuse_wait_aborted(struct fuse_conn *fc);
>
> +/**
> + * Flush all pending requests but do not wait for them.
> + */

nit: /*  */ comment style

> +void fuse_flush_requests(struct fuse_conn *fc);
> +
>  /* Check if any requests timed out */
>  void fuse_check_timeout(struct work_struct *work);
>
> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> index 0b0241f47170d4..ac9d7a7b3f5e68 100644
> --- a/fs/fuse/dev.c
> +++ b/fs/fuse/dev.c
> @@ -24,6 +24,7 @@
>  #include <linux/splice.h>
>  #include <linux/sched.h>
>  #include <linux/seq_file.h>
> +#include <linux/nmi.h>

I don't think you meant to add this?

>
>  #include "fuse_trace.h"
>
> @@ -2430,6 +2431,24 @@ static void end_polls(struct fuse_conn *fc)
>         }
>  }
>
> +/*
> + * Flush all pending requests and wait for them.  Only call this function when

I think you meant "don't wait" for them?
> + * it is no longer possible for other threads to add requests.
> + */
> +void fuse_flush_requests(struct fuse_conn *fc)
> +{
> +       spin_lock(&fc->lock);
> +       spin_lock(&fc->bg_lock);
> +       if (fc->connected) {
> +               /* Push all the background requests to the queue. */
> +               fc->blocked = 0;
> +               fc->max_background = UINT_MAX;
> +               flush_bg_queue(fc);
> +       }
> +       spin_unlock(&fc->bg_lock);
> +       spin_unlock(&fc->lock);
> +}
> +
>  /*
>   * Abort all requests.
>   *
> diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
> index e57b8af06be93e..58c3351b467221 100644
> --- a/fs/fuse/inode.c
> +++ b/fs/fuse/inode.c
> @@ -2086,8 +2086,18 @@ void fuse_conn_destroy(struct fuse_mount *fm)
>  {
>         struct fuse_conn *fc = fm->fc;
>
> -       if (fc->destroy)
> +       if (fc->destroy) {
> +               /*
> +                * Flush all pending requests (most of which will be
> +                * FUSE_RELEASE) before sending FUSE_DESTROY, because the fuse
> +                * server must close the filesystem before replying to the
> +                * destroy message, because unmount is about to release its
> +                * O_EXCL hold on the block device.  We don't wait, so libfuse
> +                * has to do that for us.

nit: imo the "because the fuse server must close the filesystem before
replying to the destroy message, because..." part is confusing. Even
if that weren't true, the pending requests would still have to be sent
before the destroy, no? i think it would be less confusing if that
part of the paragraph was removed. I think it might be better to
remove the "we don't wait, so libfuse has to do that for us" part too
or rewording it to something like "flushed requests are sent before
the FUSE_DESTROY. Userspace is responsible for ensuring flushed
requests are handled before replying to the FUSE_DESTROY".

Thanks,
Joanne

> +                */
> +               fuse_flush_requests(fc);
>                 fuse_send_destroy(fm);
> +       }
>
>         fuse_abort_conn(fc);
>         fuse_wait_aborted(fc);
>

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 1/5] fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY
  2026-02-24 19:33     ` Joanne Koong
@ 2026-02-24 19:57       ` Darrick J. Wong
  2026-02-24 20:03         ` Joanne Koong
  0 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-24 19:57 UTC (permalink / raw)
  To: Joanne Koong; +Cc: miklos, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Tue, Feb 24, 2026 at 11:33:12AM -0800, Joanne Koong wrote:
> On Mon, Feb 23, 2026 at 3:06 PM Darrick J. Wong <djwong@kernel.org> wrote:
> >
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > generic/488 fails with fuse2fs in the following fashion:
> >
> > generic/488       _check_generic_filesystem: filesystem on /dev/sdf is inconsistent
> > (see /var/tmp/fstests/generic/488.full for details)
> >
> > This test opens a large number of files, unlinks them (which really just
> > renames them to fuse hidden files), closes the program, unmounts the
> > filesystem, and runs fsck to check that there aren't any inconsistencies
> > in the filesystem.
> >
> > Unfortunately, the 488.full file shows that there are a lot of hidden
> > files left over in the filesystem, with incorrect link counts.  Tracing
> > fuse_request_* shows that there are a large number of FUSE_RELEASE
> > commands that are queued up on behalf of the unlinked files at the time
> > that fuse_conn_destroy calls fuse_abort_conn.  Had the connection not
> > aborted, the fuse server would have responded to the RELEASE commands by
> > removing the hidden files; instead they stick around.
> >
> > For upper-level fuse servers that don't use fuseblk mode this isn't a
> > problem because libfuse responds to the connection going down by pruning
> > its inode cache and calling the fuse server's ->release for any open
> > files before calling the server's ->destroy function.
> >
> > For fuseblk servers this is a problem, however, because the kernel sends
> > FUSE_DESTROY to the fuse server, and the fuse server has to write all of
> > its pending changes to the block device before replying to the DESTROY
> > request because the kernel releases its O_EXCL hold on the block device.
> > This means that the kernel must flush all pending FUSE_RELEASE requests
> > before issuing FUSE_DESTROY.
> >
> > For fuse-iomap servers this will also be a problem because iomap servers
> > are expected to release all exclusively-held resources before unmount
> > returns from the kernel.
> >
> > Create a function to push all the background requests to the queue
> > before sending FUSE_DESTROY.  That way, all the pending file release
> > events are processed by the fuse server before it tears itself down, and
> > we don't end up with a corrupt filesystem.
> >
> > Note that multithreaded fuse servers will need to track the number of
> > open files and defer a FUSE_DESTROY request until that number reaches
> > zero.  An earlier version of this patch made the kernel wait for the
> > RELEASE acknowledgements before sending DESTROY, but the kernel people
> > weren't comfortable with adding blocking waits to unmount.
> >
> > Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> 
> Overall LGTM, left a few comments below
> 
> Reviewed-by: Joanne Koong <joannelkoong@gmail.com>

Thanks!

> > ---
> >  fs/fuse/fuse_i.h |    5 +++++
> >  fs/fuse/dev.c    |   19 +++++++++++++++++++
> >  fs/fuse/inode.c  |   12 +++++++++++-
> >  3 files changed, 35 insertions(+), 1 deletion(-)
> >
> >
> > diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> > index 7f16049387d15e..1d4beca5c7018d 100644
> > --- a/fs/fuse/fuse_i.h
> > +++ b/fs/fuse/fuse_i.h
> > @@ -1287,6 +1287,11 @@ void fuse_request_end(struct fuse_req *req);
> >  void fuse_abort_conn(struct fuse_conn *fc);
> >  void fuse_wait_aborted(struct fuse_conn *fc);
> >
> > +/**
> > + * Flush all pending requests but do not wait for them.
> > + */
> 
> nit: /*  */ comment style

I'm very confused by the comment style in this header file.  Some of
them look like kerneldoc comments (albeit not documenting the sole
parameter), but others are just regular C comments.

<shrug> I sorta dislike kerneldoc's fussiness so I'll change it to a C
comment so that I don't have to propagate this "@param fc fuse
connection" verbosity.

> > +void fuse_flush_requests(struct fuse_conn *fc);
> > +
> >  /* Check if any requests timed out */
> >  void fuse_check_timeout(struct work_struct *work);
> >
> > diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> > index 0b0241f47170d4..ac9d7a7b3f5e68 100644
> > --- a/fs/fuse/dev.c
> > +++ b/fs/fuse/dev.c
> > @@ -24,6 +24,7 @@
> >  #include <linux/splice.h>
> >  #include <linux/sched.h>
> >  #include <linux/seq_file.h>
> > +#include <linux/nmi.h>
> 
> I don't think you meant to add this?

Yep, that was added for a previous iteration and can go away now.

> >
> >  #include "fuse_trace.h"
> >
> > @@ -2430,6 +2431,24 @@ static void end_polls(struct fuse_conn *fc)
> >         }
> >  }
> >
> > +/*
> > + * Flush all pending requests and wait for them.  Only call this function when
> 
> I think you meant "don't wait" for them?

Right.  Fixed.

> > + * it is no longer possible for other threads to add requests.
> > + */
> > +void fuse_flush_requests(struct fuse_conn *fc)
> > +{
> > +       spin_lock(&fc->lock);
> > +       spin_lock(&fc->bg_lock);
> > +       if (fc->connected) {
> > +               /* Push all the background requests to the queue. */
> > +               fc->blocked = 0;
> > +               fc->max_background = UINT_MAX;
> > +               flush_bg_queue(fc);
> > +       }
> > +       spin_unlock(&fc->bg_lock);
> > +       spin_unlock(&fc->lock);
> > +}
> > +
> >  /*
> >   * Abort all requests.
> >   *
> > diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
> > index e57b8af06be93e..58c3351b467221 100644
> > --- a/fs/fuse/inode.c
> > +++ b/fs/fuse/inode.c
> > @@ -2086,8 +2086,18 @@ void fuse_conn_destroy(struct fuse_mount *fm)
> >  {
> >         struct fuse_conn *fc = fm->fc;
> >
> > -       if (fc->destroy)
> > +       if (fc->destroy) {
> > +               /*
> > +                * Flush all pending requests (most of which will be
> > +                * FUSE_RELEASE) before sending FUSE_DESTROY, because the fuse
> > +                * server must close the filesystem before replying to the
> > +                * destroy message, because unmount is about to release its
> > +                * O_EXCL hold on the block device.  We don't wait, so libfuse
> > +                * has to do that for us.
> 
> nit: imo the "because the fuse server must close the filesystem before
> replying to the destroy message, because..." part is confusing. Even
> if that weren't true, the pending requests would still have to be sent
> before the destroy, no? i think it would be less confusing if that
> part of the paragraph was removed. I think it might be better to
> remove the "we don't wait, so libfuse has to do that for us" part too
> or rewording it to something like "flushed requests are sent before
> the FUSE_DESTROY. Userspace is responsible for ensuring flushed
> requests are handled before replying to the FUSE_DESTROY".

How about I simplify it to:

	/*
	 * Flush all pending requests before sending FUSE_DESTROY.  The
	 * fuse server must reply to the flushed requests before
	 * handling FUSE_DESTROY because unmount is about to release
	 * its O_EXCL hold on the block device.
	 */

--D

> 
> Thanks,
> Joanne
> 
> > +                */
> > +               fuse_flush_requests(fc);
> >                 fuse_send_destroy(fm);
> > +       }
> >
> >         fuse_abort_conn(fc);
> >         fuse_wait_aborted(fc);
> >
> 

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 1/5] fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY
  2026-02-24 19:57       ` Darrick J. Wong
@ 2026-02-24 20:03         ` Joanne Koong
  0 siblings, 0 replies; 234+ messages in thread
From: Joanne Koong @ 2026-02-24 20:03 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: miklos, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Tue, Feb 24, 2026 at 11:57 AM Darrick J. Wong <djwong@kernel.org> wrote:
>
> On Tue, Feb 24, 2026 at 11:33:12AM -0800, Joanne Koong wrote:
> > On Mon, Feb 23, 2026 at 3:06 PM Darrick J. Wong <djwong@kernel.org> wrote:
> > >
> > > From: Darrick J. Wong <djwong@kernel.org>
> > >
> > > generic/488 fails with fuse2fs in the following fashion:
> > >
> > > generic/488       _check_generic_filesystem: filesystem on /dev/sdf is inconsistent
> > > (see /var/tmp/fstests/generic/488.full for details)
> > >
> > > This test opens a large number of files, unlinks them (which really just
> > > renames them to fuse hidden files), closes the program, unmounts the
> > > filesystem, and runs fsck to check that there aren't any inconsistencies
> > > in the filesystem.
> > >
> > > Unfortunately, the 488.full file shows that there are a lot of hidden
> > > files left over in the filesystem, with incorrect link counts.  Tracing
> > > fuse_request_* shows that there are a large number of FUSE_RELEASE
> > > commands that are queued up on behalf of the unlinked files at the time
> > > that fuse_conn_destroy calls fuse_abort_conn.  Had the connection not
> > > aborted, the fuse server would have responded to the RELEASE commands by
> > > removing the hidden files; instead they stick around.
> > >
> > > For upper-level fuse servers that don't use fuseblk mode this isn't a
> > > problem because libfuse responds to the connection going down by pruning
> > > its inode cache and calling the fuse server's ->release for any open
> > > files before calling the server's ->destroy function.
> > >
> > > For fuseblk servers this is a problem, however, because the kernel sends
> > > FUSE_DESTROY to the fuse server, and the fuse server has to write all of
> > > its pending changes to the block device before replying to the DESTROY
> > > request because the kernel releases its O_EXCL hold on the block device.
> > > This means that the kernel must flush all pending FUSE_RELEASE requests
> > > before issuing FUSE_DESTROY.
> > >
> > > For fuse-iomap servers this will also be a problem because iomap servers
> > > are expected to release all exclusively-held resources before unmount
> > > returns from the kernel.
> > >
> > > Create a function to push all the background requests to the queue
> > > before sending FUSE_DESTROY.  That way, all the pending file release
> > > events are processed by the fuse server before it tears itself down, and
> > > we don't end up with a corrupt filesystem.
> > >
> > > Note that multithreaded fuse servers will need to track the number of
> > > open files and defer a FUSE_DESTROY request until that number reaches
> > > zero.  An earlier version of this patch made the kernel wait for the
> > > RELEASE acknowledgements before sending DESTROY, but the kernel people
> > > weren't comfortable with adding blocking waits to unmount.
> > >
> > > Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> >
> > Overall LGTM, left a few comments below
> >
> > Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
>
> Thanks!
>
> > > ---
> > >  fs/fuse/fuse_i.h |    5 +++++
> > >  fs/fuse/dev.c    |   19 +++++++++++++++++++
> > >  fs/fuse/inode.c  |   12 +++++++++++-
> > >  3 files changed, 35 insertions(+), 1 deletion(-)
> > >
> > >
> > > diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> > > index 7f16049387d15e..1d4beca5c7018d 100644
> > > --- a/fs/fuse/fuse_i.h
> > > +++ b/fs/fuse/fuse_i.h
> > > @@ -1287,6 +1287,11 @@ void fuse_request_end(struct fuse_req *req);
> > >  void fuse_abort_conn(struct fuse_conn *fc);
> > >  void fuse_wait_aborted(struct fuse_conn *fc);
> > >
> > > +/**
> > > + * Flush all pending requests but do not wait for them.
> > > + */
> >
> > nit: /*  */ comment style
>
> I'm very confused by the comment style in this header file.  Some of
> them look like kerneldoc comments (albeit not documenting the sole
> parameter), but others are just regular C comments.

Oh I see your confusion now. Yeah the comment styles in this .h file
are kind of all over the place. Most of the functions don't even have
comments.

>
> <shrug> I sorta dislike kerneldoc's fussiness so I'll change it to a C
> comment so that I don't have to propagate this "@param fc fuse
> connection" verbosity.
>
> > > +void fuse_flush_requests(struct fuse_conn *fc);
> > > +
> > >  /* Check if any requests timed out */
> > >  void fuse_check_timeout(struct work_struct *work);
> > >
> > > diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> > > index 0b0241f47170d4..ac9d7a7b3f5e68 100644
> > > --- a/fs/fuse/dev.c
> > > +++ b/fs/fuse/dev.c
> > > @@ -24,6 +24,7 @@
> > >  #include <linux/splice.h>
> > >  #include <linux/sched.h>
> > >  #include <linux/seq_file.h>
> > > +#include <linux/nmi.h>
> >
> > I don't think you meant to add this?
>
> Yep, that was added for a previous iteration and can go away now.
>
> > >
> > >  #include "fuse_trace.h"
> > >
> > > @@ -2430,6 +2431,24 @@ static void end_polls(struct fuse_conn *fc)
> > >         }
> > >  }
> > >
> > > +/*
> > > + * Flush all pending requests and wait for them.  Only call this function when
> >
> > I think you meant "don't wait" for them?
>
> Right.  Fixed.
>
> > > + * it is no longer possible for other threads to add requests.
> > > + */
> > > +void fuse_flush_requests(struct fuse_conn *fc)
> > > +{
> > > +       spin_lock(&fc->lock);
> > > +       spin_lock(&fc->bg_lock);
> > > +       if (fc->connected) {
> > > +               /* Push all the background requests to the queue. */
> > > +               fc->blocked = 0;
> > > +               fc->max_background = UINT_MAX;
> > > +               flush_bg_queue(fc);
> > > +       }
> > > +       spin_unlock(&fc->bg_lock);
> > > +       spin_unlock(&fc->lock);
> > > +}
> > > +
> > >  /*
> > >   * Abort all requests.
> > >   *
> > > diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
> > > index e57b8af06be93e..58c3351b467221 100644
> > > --- a/fs/fuse/inode.c
> > > +++ b/fs/fuse/inode.c
> > > @@ -2086,8 +2086,18 @@ void fuse_conn_destroy(struct fuse_mount *fm)
> > >  {
> > >         struct fuse_conn *fc = fm->fc;
> > >
> > > -       if (fc->destroy)
> > > +       if (fc->destroy) {
> > > +               /*
> > > +                * Flush all pending requests (most of which will be
> > > +                * FUSE_RELEASE) before sending FUSE_DESTROY, because the fuse
> > > +                * server must close the filesystem before replying to the
> > > +                * destroy message, because unmount is about to release its
> > > +                * O_EXCL hold on the block device.  We don't wait, so libfuse
> > > +                * has to do that for us.
> >
> > nit: imo the "because the fuse server must close the filesystem before
> > replying to the destroy message, because..." part is confusing. Even
> > if that weren't true, the pending requests would still have to be sent
> > before the destroy, no? i think it would be less confusing if that
> > part of the paragraph was removed. I think it might be better to
> > remove the "we don't wait, so libfuse has to do that for us" part too
> > or rewording it to something like "flushed requests are sent before
> > the FUSE_DESTROY. Userspace is responsible for ensuring flushed
> > requests are handled before replying to the FUSE_DESTROY".
>
> How about I simplify it to:
>
>         /*
>          * Flush all pending requests before sending FUSE_DESTROY.  The
>          * fuse server must reply to the flushed requests before
>          * handling FUSE_DESTROY because unmount is about to release
>          * its O_EXCL hold on the block device.
>          */

This sounds a lot better to me.

Thanks,
Joanne
>
> --D
>
> >
> > Thanks,
> > Joanne
> >
> > > +                */
> > > +               fuse_flush_requests(fc);
> > >                 fuse_send_destroy(fm);
> > > +       }
> > >
> > >         fuse_abort_conn(fc);
> > >         fuse_wait_aborted(fc);
> > >
> >

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write
  2026-02-23 23:06   ` [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write Darrick J. Wong
  2026-02-24  8:36     ` Horst Birthelmer
@ 2026-02-24 20:09     ` Joanne Koong
  2026-02-27 16:05     ` Miklos Szeredi
  2 siblings, 0 replies; 234+ messages in thread
From: Joanne Koong @ 2026-02-24 20:09 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: miklos, stable, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Mon, Feb 23, 2026 at 3:06 PM Darrick J. Wong <djwong@kernel.org> wrote:
>
> From: Darrick J. Wong <djwong@kernel.org>
>
> gcc 15 complains about an uninitialized variable val that is passed by
> reference into fuse_conn_limit_write:
>
>  control.c: In function ‘fuse_conn_congestion_threshold_write’:
>  include/asm-generic/rwonce.h:55:37: warning: ‘val’ may be used uninitialized [-Wmaybe-uninitialized]
>     55 |         *(volatile typeof(x) *)&(x) = (val);                            \
>        |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
>  include/asm-generic/rwonce.h:61:9: note: in expansion of macro ‘__WRITE_ONCE’
>     61 |         __WRITE_ONCE(x, val);                                           \
>        |         ^~~~~~~~~~~~
>  control.c:178:9: note: in expansion of macro ‘WRITE_ONCE’
>    178 |         WRITE_ONCE(fc->congestion_threshold, val);
>        |         ^~~~~~~~~~
>  control.c:166:18: note: ‘val’ was declared here
>    166 |         unsigned val;
>        |                  ^~~
>
> Unfortunately there's enough macro spew involved in kstrtoul_from_user
> that I think gcc gives up on its analysis and sprays the above warning.
> AFAICT it's not actually a bug, but we could just zero-initialize the
> variable to enable using -Wmaybe-uninitialized to find real problems.
>
> Previously we would use some weird uninitialized_var annotation to quiet
> down the warnings, so clearly this code has been like this for quite
> some time.
>
> Cc: <stable@vger.kernel.org> # v5.9
> Fixes: 3f649ab728cda8 ("treewide: Remove uninitialized_var() usage")
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>

Makes sense to me.

Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
> ---
>  fs/fuse/control.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
>
> diff --git a/fs/fuse/control.c b/fs/fuse/control.c
> index 140bd5730d9984..073c2d8e4dfc7c 100644
> --- a/fs/fuse/control.c
> +++ b/fs/fuse/control.c
> @@ -121,7 +121,7 @@ static ssize_t fuse_conn_max_background_write(struct file *file,
>                                               const char __user *buf,
>                                               size_t count, loff_t *ppos)
>  {
> -       unsigned val;
> +       unsigned val = 0;
>         ssize_t ret;
>
>         ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
> @@ -163,7 +163,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
>                                                     const char __user *buf,
>                                                     size_t count, loff_t *ppos)
>  {
> -       unsigned val;
> +       unsigned val = 0;
>         struct fuse_conn *fc;
>         ssize_t ret;
>
>

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 29/33] fuse: support atomic writes with iomap
  2026-02-24 19:30       ` Darrick J. Wong
@ 2026-02-24 21:18         ` Pankaj Raghav (Samsung)
  0 siblings, 0 replies; 234+ messages in thread
From: Pankaj Raghav (Samsung) @ 2026-02-24 21:18 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: miklos, joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

> > 
> > I still haven't gone through the whole patch blizzard but I had a
> > general question here: we don't give ATOMIC guarantees to buffered IO,
> > so I am wondering how we give that here.
> 
> Oh, we don't.  generic_atomic_write_valid rejects !IOCB_DIRECT iocbs.

Ah, that is true. I was secretly hoping you added support for buffered
IO atomics ;)

> 
> > For example, we might mix
> > atomic and non atomic buffered IO during writeback. Am I missing some
> > implementation detail that makes it possible here? I don't think we
> > should enable this for buffered IO.
> 
> <nod> Now that y'all have an lsf thread on this, I agree that not
> supporting buffered writes in fuse-iomap should be more explicit.
> 
> 	if (iocb->ki_flags & IOCB_ATOMIC)
> 		return -EOPNOTSUPP;
> 

Yeah. This looks more explicit. Of course this change does not warrant a
new series as it is not changing anything functionally. If you plan to
send a new series anyway, then this could be folded in.

-- 
Pankaj

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile
  2026-02-24 19:26       ` Darrick J. Wong
@ 2026-02-25 14:16         ` Christoph Hellwig
  2026-02-25 17:03           ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Christoph Hellwig @ 2026-02-25 14:16 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Christoph Hellwig, brauner, miklos, bpf, linux-fsdevel,
	linux-ext4

On Tue, Feb 24, 2026 at 11:26:53AM -0800, Darrick J. Wong wrote:
> > That sounds pretty sketchy.  How do you make sure that is safe vs
> > memory reclaim deadlocks?  Does someone really need this feature?
> 
> Err, which part is sketchy, specifically?  This patch that adjusts stuff
> in fs/iomap/, or the (much later) patch to fuse-iomap?

The concept of swapping to fuse.

> Obviously this means that the fuse server is granting a longterm layout
> lease to the kernel swapfile code, so it should reply to
> fuse_iomap_begin with a error code if it doesn't want to do that.
> 
> I don't know that anyone really needs this feature, but pre-iomap
> fuse2fs supports swapfiles, as does any other fuse server that
> implements bmap.

Eww, I didn't know people were already trying to support swap to fuse.

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile
  2026-02-25 14:16         ` Christoph Hellwig
@ 2026-02-25 17:03           ` Darrick J. Wong
  2026-02-25 17:49             ` Christoph Hellwig
  0 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-25 17:03 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: brauner, miklos, bpf, linux-fsdevel, linux-ext4

On Wed, Feb 25, 2026 at 03:16:39PM +0100, Christoph Hellwig wrote:
> On Tue, Feb 24, 2026 at 11:26:53AM -0800, Darrick J. Wong wrote:
> > > That sounds pretty sketchy.  How do you make sure that is safe vs
> > > memory reclaim deadlocks?  Does someone really need this feature?
> > 
> > Err, which part is sketchy, specifically?  This patch that adjusts stuff
> > in fs/iomap/, or the (much later) patch to fuse-iomap?
> 
> The concept of swapping to fuse.
> 
> > Obviously this means that the fuse server is granting a longterm layout
> > lease to the kernel swapfile code, so it should reply to
> > fuse_iomap_begin with a error code if it doesn't want to do that.
> > 
> > I don't know that anyone really needs this feature, but pre-iomap
> > fuse2fs supports swapfiles, as does any other fuse server that
> > implements bmap.
> 
> Eww, I didn't know people were already trying to support swap to fuse.

It was merged in the kernel via commit b2d2272fae1e1d ("[PATCH] fuse:
add bmap support"), which was 2.6.20.  So people have been using it for
~20 years now.  At least it's the mm-managed bio swap path and we're not
actually upcalling the fuse server to do swapins/swapouts.

--D

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile
  2026-02-25 17:03           ` Darrick J. Wong
@ 2026-02-25 17:49             ` Christoph Hellwig
  0 siblings, 0 replies; 234+ messages in thread
From: Christoph Hellwig @ 2026-02-25 17:49 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Christoph Hellwig, brauner, miklos, bpf, linux-fsdevel,
	linux-ext4

On Wed, Feb 25, 2026 at 09:03:22AM -0800, Darrick J. Wong wrote:
> > > I don't know that anyone really needs this feature, but pre-iomap
> > > fuse2fs supports swapfiles, as does any other fuse server that
> > > implements bmap.
> > 
> > Eww, I didn't know people were already trying to support swap to fuse.
> 
> It was merged in the kernel via commit b2d2272fae1e1d ("[PATCH] fuse:
> add bmap support"), which was 2.6.20.  So people have been using it for
> ~20 years now.  At least it's the mm-managed bio swap path and we're not
> actually upcalling the fuse server to do swapins/swapouts.

Assuming it actually gets used, but yes, it's been there forever.
:(

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write
  2026-02-23 23:06   ` [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write Darrick J. Wong
  2026-02-24  8:36     ` Horst Birthelmer
  2026-02-24 20:09     ` Joanne Koong
@ 2026-02-27 16:05     ` Miklos Szeredi
  2 siblings, 0 replies; 234+ messages in thread
From: Miklos Szeredi @ 2026-02-27 16:05 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: stable, joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Tue, 24 Feb 2026 at 00:06, Darrick J. Wong <djwong@kernel.org> wrote:
>
> From: Darrick J. Wong <djwong@kernel.org>
>
> gcc 15 complains about an uninitialized variable val that is passed by
> reference into fuse_conn_limit_write:
>
>  control.c: In function ‘fuse_conn_congestion_threshold_write’:
>  include/asm-generic/rwonce.h:55:37: warning: ‘val’ may be used uninitialized [-Wmaybe-uninitialized]
>     55 |         *(volatile typeof(x) *)&(x) = (val);                            \
>        |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
>  include/asm-generic/rwonce.h:61:9: note: in expansion of macro ‘__WRITE_ONCE’
>     61 |         __WRITE_ONCE(x, val);                                           \
>        |         ^~~~~~~~~~~~
>  control.c:178:9: note: in expansion of macro ‘WRITE_ONCE’
>    178 |         WRITE_ONCE(fc->congestion_threshold, val);
>        |         ^~~~~~~~~~
>  control.c:166:18: note: ‘val’ was declared here
>    166 |         unsigned val;
>        |                  ^~~
>
> Unfortunately there's enough macro spew involved in kstrtoul_from_user
> that I think gcc gives up on its analysis and sprays the above warning.
> AFAICT it's not actually a bug, but we could just zero-initialize the
> variable to enable using -Wmaybe-uninitialized to find real problems.
>
> Previously we would use some weird uninitialized_var annotation to quiet
> down the warnings, so clearly this code has been like this for quite
> some time.
>
> Cc: <stable@vger.kernel.org> # v5.9
> Fixes: 3f649ab728cda8 ("treewide: Remove uninitialized_var() usage")
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>

Applied, thanks.

Miklos

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 26/33] fuse: implement inline data file IO via iomap
  2026-02-23 23:15   ` [PATCH 26/33] fuse: implement inline data file IO via iomap Darrick J. Wong
@ 2026-02-27 18:02     ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-27 18:02 UTC (permalink / raw)
  To: miklos; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Mon, Feb 23, 2026 at 03:15:27PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Implement inline data file IO by issuing FUSE_READ/FUSE_WRITE commands
> in response to an inline data mapping.
> 
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> ---
>  fs/fuse/fuse_iomap.c |  205 ++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 197 insertions(+), 8 deletions(-)
> 
> 
> diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
> index e8a0c1ceb409c4..1c3d99f11634d2 100644
> --- a/fs/fuse/fuse_iomap.c
> +++ b/fs/fuse/fuse_iomap.c
> @@ -398,6 +398,152 @@ fuse_iomap_find_dev(struct fuse_conn *fc, const struct fuse_iomap_io *map)
>  	return ret;
>  }
>  
> +static inline int fuse_iomap_inline_alloc(struct iomap *iomap)
> +{
> +	ASSERT(iomap->inline_data == NULL);
> +	ASSERT(iomap->length > 0);
> +
> +	iomap->inline_data = kvzalloc(iomap->length, GFP_KERNEL);
> +	return iomap->inline_data ? 0 : -ENOMEM;
> +}
> +
> +static inline void fuse_iomap_inline_free(struct iomap *iomap)
> +{
> +	kvfree(iomap->inline_data);
> +	iomap->inline_data = NULL;
> +}
> +
> +/*
> + * Use the FUSE_READ command to read inline file data from the fuse server.
> + * Note that there's no file handle attached, so the fuse server must be able
> + * to reconnect to the inode via the nodeid.
> + */
> +static int fuse_iomap_inline_read(struct inode *inode, loff_t pos,
> +				  loff_t count, struct iomap *iomap)
> +{
> +	struct fuse_read_in in = {
> +		.offset = pos,
> +		.size = count,
> +	};
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	struct fuse_mount *fm = get_fuse_mount(inode);
> +	FUSE_ARGS(args);
> +	ssize_t ret;
> +
> +	if (BAD_DATA(!iomap_inline_data_valid(iomap))) {
> +		fuse_iomap_inline_free(iomap);
> +		return -EFSCORRUPTED;
> +	}
> +
> +	args.opcode = FUSE_READ;
> +	args.nodeid = fi->nodeid;
> +	args.in_numargs = 1;
> +	args.in_args[0].size = sizeof(in);
> +	args.in_args[0].value = &in;
> +	args.out_argvar = true;
> +	args.out_numargs = 1;
> +	args.out_args[0].size = count;
> +	args.out_args[0].value = iomap_inline_data(iomap, pos);
> +
> +	ret = fuse_simple_request(fm, &args);
> +	if (ret < 0) {

For both the read and write functions, we should treat ENOSYS as a short
read/write and not allow "Function not implemented" to bubble up to
userspace.

--D

> +		fuse_iomap_inline_free(iomap);
> +		return ret;
> +	}
> +	/* no readahead means something bad happened */
> +	if (ret == 0) {
> +		fuse_iomap_inline_free(iomap);
> +		return -EIO;
> +	}
> +
> +	return 0;
> +}
> +
> +/*
> + * Use the FUSE_WRITE command to write inline file data from the fuse server.
> + * Note that there's no file handle attached, so the fuse server must be able
> + * to reconnect to the inode via the nodeid.
> + */
> +static int fuse_iomap_inline_write(struct inode *inode, loff_t pos,
> +				   loff_t count, struct iomap *iomap)
> +{
> +	struct fuse_write_in in = {
> +		.offset = pos,
> +		.size = count,
> +	};
> +	struct fuse_write_out out = { };
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	struct fuse_mount *fm = get_fuse_mount(inode);
> +	FUSE_ARGS(args);
> +	ssize_t ret;
> +
> +	if (BAD_DATA(!iomap_inline_data_valid(iomap)))
> +		return -EFSCORRUPTED;
> +
> +	args.opcode = FUSE_WRITE;
> +	args.nodeid = fi->nodeid;
> +	args.in_numargs = 2;
> +	args.in_args[0].size = sizeof(in);
> +	args.in_args[0].value = &in;
> +	args.in_args[1].size = count;
> +	args.in_args[1].value = iomap_inline_data(iomap, pos);
> +	args.out_numargs = 1;
> +	args.out_args[0].size = sizeof(out);
> +	args.out_args[0].value = &out;
> +
> +	ret = fuse_simple_request(fm, &args);
> +	if (ret < 0) {
> +		fuse_iomap_inline_free(iomap);
> +		return ret;
> +	}
> +	/* short write means something bad happened */
> +	if (out.size < count) {
> +		fuse_iomap_inline_free(iomap);
> +		return -EIO;
> +	}
> +
> +	return 0;
> +}
> +
> +/* Set up inline data buffers for iomap_begin */
> +static int fuse_iomap_set_inline(struct inode *inode, unsigned opflags,
> +				 loff_t pos, loff_t count,
> +				 struct iomap *iomap, struct iomap *srcmap)
> +{
> +	int err;
> +
> +	if (opflags & IOMAP_REPORT)
> +		return 0;
> +
> +	if (fuse_is_iomap_file_write(opflags)) {
> +		if (iomap->type == IOMAP_INLINE) {
> +			err = fuse_iomap_inline_alloc(iomap);
> +			if (err)
> +				return err;
> +		}
> +
> +		if (srcmap->type == IOMAP_INLINE) {
> +			err = fuse_iomap_inline_alloc(srcmap);
> +			if (!err)
> +				err = fuse_iomap_inline_read(inode, pos, count,
> +							     srcmap);
> +			if (err) {
> +				fuse_iomap_inline_free(iomap);
> +				return err;
> +			}
> +		}
> +	} else if (iomap->type == IOMAP_INLINE) {
> +		/* inline data read */
> +		err = fuse_iomap_inline_alloc(iomap);
> +		if (!err)
> +			err = fuse_iomap_inline_read(inode, pos, count, iomap);
> +		if (err)
> +			return err;
> +	}
> +
> +	return 0;
> +}
> +
>  static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
>  			    unsigned opflags, struct iomap *iomap,
>  			    struct iomap *srcmap)
> @@ -467,12 +613,20 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
>  		fuse_iomap_from_server(iomap, read_dev, &outarg.read);
>  	}
>  
> +	if (iomap->type == IOMAP_INLINE || srcmap->type == IOMAP_INLINE) {
> +		err = fuse_iomap_set_inline(inode, opflags, pos, count, iomap,
> +					    srcmap);
> +		if (err)
> +			goto out_write_dev;
> +	}
> +
>  	/*
>  	 * XXX: if we ever want to support closing devices, we need a way to
>  	 * track the fuse_backing refcount all the way through bio endios.
>  	 * For now we put the refcount here because you can't remove an iomap
>  	 * device until unmount time.
>  	 */
> +out_write_dev:
>  	fuse_backing_put(write_dev);
>  out_read_dev:
>  	fuse_backing_put(read_dev);
> @@ -511,8 +665,28 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t count,
>  {
>  	struct fuse_inode *fi = get_fuse_inode(inode);
>  	struct fuse_mount *fm = get_fuse_mount(inode);
> +	struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
> +	struct iomap *srcmap = &iter->srcmap;
>  	int err;
>  
> +	if (srcmap->inline_data)
> +		fuse_iomap_inline_free(srcmap);
> +
> +	if (iomap->inline_data) {
> +		if (fuse_is_iomap_file_write(opflags) && written > 0) {
> +			err = fuse_iomap_inline_write(inode, pos, written,
> +						      iomap);
> +			fuse_iomap_inline_free(iomap);
> +			if (err)
> +				return err;
> +		} else {
> +			fuse_iomap_inline_free(iomap);
> +		}
> +
> +		/* fuse server should already be aware of what happened */
> +		return 0;
> +	}
> +
>  	if (fuse_should_send_iomap_end(fm, iomap, opflags, count, written)) {
>  		struct fuse_iomap_end_in inarg = {
>  			.opflags = fuse_iomap_op_to_server(opflags),
> @@ -1461,7 +1635,6 @@ static ssize_t fuse_iomap_writeback_range(struct iomap_writepage_ctx *wpc,
>  					  unsigned int len, u64 end_pos)
>  {
>  	struct inode *inode = wpc->inode;
> -	struct iomap write_iomap, dontcare;
>  	ssize_t ret;
>  
>  	if (fuse_is_bad(inode)) {
> @@ -1474,23 +1647,39 @@ static ssize_t fuse_iomap_writeback_range(struct iomap_writepage_ctx *wpc,
>  	trace_fuse_iomap_writeback_range(inode, offset, len, end_pos);
>  
>  	if (!fuse_iomap_revalidate_writeback(wpc, offset)) {
> +		struct iomap_iter fake_iter = { };
> +		struct iomap *write_iomap = &fake_iter.iomap;
> +
>  		ret = fuse_iomap_begin(inode, offset, len,
> -				       FUSE_IOMAP_OP_WRITEBACK,
> -				       &write_iomap, &dontcare);
> +				       FUSE_IOMAP_OP_WRITEBACK, write_iomap,
> +				       &fake_iter.srcmap);
>  		if (ret)
>  			goto discard_folio;
>  
> +		if (BAD_DATA(write_iomap->type == IOMAP_INLINE)) {
> +			/*
> +			 * iomap assumes that inline data writes are completed
> +			 * by the time ->iomap_end completes, so it should
> +			 * never mark a pagecache folio dirty.
> +			 */
> +			fuse_iomap_end(inode, offset, len, 0,
> +				       FUSE_IOMAP_OP_WRITEBACK,
> +				       write_iomap);
> +			ret = -EIO;
> +			goto discard_folio;
> +		}
> +
>  		/*
>  		 * Landed in a hole or beyond EOF?  Send that to iomap, it'll
>  		 * skip writing back the file range.
>  		 */
> -		if (write_iomap.offset > offset) {
> -			write_iomap.length = write_iomap.offset - offset;
> -			write_iomap.offset = offset;
> -			write_iomap.type = IOMAP_HOLE;
> +		if (write_iomap->offset > offset) {
> +			write_iomap->length = write_iomap->offset - offset;
> +			write_iomap->offset = offset;
> +			write_iomap->type = IOMAP_HOLE;
>  		}
>  
> -		memcpy(&wpc->iomap, &write_iomap, sizeof(struct iomap));
> +		memcpy(&wpc->iomap, write_iomap, sizeof(struct iomap));
>  	}
>  
>  	ret = iomap_add_to_ioend(wpc, folio, offset, end_pos, len);
> 
> 

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 16/33] fuse: implement buffered IO with iomap
  2026-02-23 23:12   ` [PATCH 16/33] fuse: implement buffered " Darrick J. Wong
@ 2026-02-27 18:04     ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-27 18:04 UTC (permalink / raw)
  To: miklos; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Mon, Feb 23, 2026 at 03:12:51PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Implement pagecache IO with iomap, complete with hooks into truncate and
> fallocate so that the fuse server needn't implement disk block zeroing
> of post-EOF and unaligned punch/zero regions.
> 
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> ---
>  fs/fuse/fuse_i.h          |    7 
>  fs/fuse/fuse_iomap.h      |   11 +
>  include/uapi/linux/fuse.h |    5 
>  fs/fuse/dir.c             |   23 +
>  fs/fuse/file.c            |   61 +++-
>  fs/fuse/fuse_iomap.c      |  696 ++++++++++++++++++++++++++++++++++++++++++++-
>  6 files changed, 772 insertions(+), 31 deletions(-)
> 
> 
> diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> index d1724bf8e87b93..b9f41c08cc8fb0 100644
> --- a/fs/fuse/fuse_i.h
> +++ b/fs/fuse/fuse_i.h
> @@ -192,6 +192,11 @@ struct fuse_inode {
>  #ifdef CONFIG_FUSE_IOMAP
>  			/* file size as reported by fuse server */
>  			loff_t i_disk_size;
> +
> +			/* pending io completions */
> +			spinlock_t ioend_lock;
> +			struct work_struct ioend_work;
> +			struct list_head ioend_list;
>  #endif
>  		};
>  
> @@ -1741,4 +1746,6 @@ extern void fuse_sysctl_unregister(void);
>  #define fuse_sysctl_unregister()	do { } while (0)
>  #endif /* CONFIG_SYSCTL */
>  
> +sector_t fuse_bmap(struct address_space *mapping, sector_t block);
> +
>  #endif /* _FS_FUSE_I_H */
> diff --git a/fs/fuse/fuse_iomap.h b/fs/fuse/fuse_iomap.h
> index 07433c33535b2d..4b12af01ff00f5 100644
> --- a/fs/fuse/fuse_iomap.h
> +++ b/fs/fuse/fuse_iomap.h
> @@ -53,6 +53,13 @@ int fuse_iomap_setsize_finish(struct inode *inode, loff_t newsize);
>  
>  ssize_t fuse_iomap_read_iter(struct kiocb *iocb, struct iov_iter *to);
>  ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from);
> +
> +int fuse_iomap_mmap(struct file *file, struct vm_area_struct *vma);
> +int fuse_iomap_setsize_start(struct inode *inode, loff_t newsize);
> +int fuse_iomap_fallocate(struct file *file, int mode, loff_t offset,
> +			 loff_t length, loff_t new_size);
> +int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
> +				 loff_t endpos);
>  #else
>  # define fuse_iomap_enabled(...)		(false)
>  # define fuse_has_iomap(...)			(false)
> @@ -72,6 +79,10 @@ ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from);
>  # define fuse_iomap_setsize_finish(...)		(-ENOSYS)
>  # define fuse_iomap_read_iter(...)		(-ENOSYS)
>  # define fuse_iomap_write_iter(...)		(-ENOSYS)
> +# define fuse_iomap_mmap(...)			(-ENOSYS)
> +# define fuse_iomap_setsize_start(...)		(-ENOSYS)
> +# define fuse_iomap_fallocate(...)		(-ENOSYS)
> +# define fuse_iomap_flush_unmap_range(...)	(-ENOSYS)
>  #endif /* CONFIG_FUSE_IOMAP */
>  
>  #endif /* _FS_FUSE_IOMAP_H */
> diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
> index 543965b2f8fb37..71b216262c84cb 100644
> --- a/include/uapi/linux/fuse.h
> +++ b/include/uapi/linux/fuse.h
> @@ -1373,6 +1373,9 @@ struct fuse_uring_cmd_req {
>  #define FUSE_IOMAP_OP_ATOMIC		(1U << 9)
>  #define FUSE_IOMAP_OP_DONTCACHE		(1U << 10)
>  
> +/* pagecache writeback operation */
> +#define FUSE_IOMAP_OP_WRITEBACK		(1U << 31)
> +
>  #define FUSE_IOMAP_NULL_ADDR		(-1ULL)	/* addr is not valid */
>  
>  struct fuse_iomap_io {
> @@ -1422,6 +1425,8 @@ struct fuse_iomap_end_in {
>  #define FUSE_IOMAP_IOEND_DIRECT		(1U << 3)
>  /* is append ioend */
>  #define FUSE_IOMAP_IOEND_APPEND		(1U << 4)
> +/* is pagecache writeback */
> +#define FUSE_IOMAP_IOEND_WRITEBACK	(1U << 5)
>  
>  struct fuse_iomap_ioend_in {
>  	uint32_t flags;		/* FUSE_IOMAP_IOEND_* */
> diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
> index dcf5ccbc57c7be..fc0751deebfd20 100644
> --- a/fs/fuse/dir.c
> +++ b/fs/fuse/dir.c
> @@ -2225,7 +2225,10 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
>  		is_truncate = true;
>  	}
>  
> -	if (FUSE_IS_DAX(inode) && is_truncate) {
> +	if (is_iomap && is_truncate) {
> +		filemap_invalidate_lock(mapping);
> +		fault_blocked = true;
> +	} else if (FUSE_IS_DAX(inode) && is_truncate) {
>  		filemap_invalidate_lock(mapping);
>  		fault_blocked = true;
>  		err = fuse_dax_break_layouts(inode, 0, -1);
> @@ -2240,6 +2243,18 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
>  		WARN_ON(!(attr->ia_valid & ATTR_SIZE));
>  		WARN_ON(attr->ia_size != 0);
>  		if (fc->atomic_o_trunc) {
> +			if (is_iomap) {
> +				/*
> +				 * fuse_open already set the size to zero and
> +				 * truncated the pagecache, and we've since
> +				 * cycled the inode locks.  Another thread
> +				 * could have performed an appending write, so
> +				 * we don't want to touch the file further.
> +				 */
> +				filemap_invalidate_unlock(mapping);
> +				return 0;
> +			}
> +
>  			/*
>  			 * No need to send request to userspace, since actual
>  			 * truncation has already been done by OPEN.  But still
> @@ -2273,6 +2288,12 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
>  		set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
>  		if (trust_local_cmtime && attr->ia_size != inode->i_size)
>  			attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
> +
> +		if (is_iomap) {
> +			err = fuse_iomap_setsize_start(inode, attr->ia_size);
> +			if (err)
> +				goto error;
> +		}
>  	}
>  
>  	memset(&inarg, 0, sizeof(inarg));
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index ae320026f0648f..0828ecb20a828c 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -402,7 +402,7 @@ static int fuse_release(struct inode *inode, struct file *file)
>  	 * Dirty pages might remain despite write_inode_now() call from
>  	 * fuse_flush() due to writes racing with the close.
>  	 */
> -	if (fc->writeback_cache)
> +	if (fc->writeback_cache || fuse_inode_has_iomap(inode))
>  		write_inode_now(inode, 1);
>  
>  	fuse_release_common(file, false);
> @@ -2395,6 +2395,9 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
>  	struct inode *inode = file_inode(file);
>  	int rc;
>  
> +	if (fuse_inode_has_iomap(inode))
> +		return fuse_iomap_mmap(file, vma);
> +
>  	/* DAX mmap is superior to direct_io mmap */
>  	if (FUSE_IS_DAX(inode))
>  		return fuse_dax_mmap(file, vma);
> @@ -2593,7 +2596,7 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl)
>  	return err;
>  }
>  
> -static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
> +sector_t fuse_bmap(struct address_space *mapping, sector_t block)
>  {
>  	struct inode *inode = mapping->host;
>  	struct fuse_mount *fm = get_fuse_mount(inode);
> @@ -2947,8 +2950,12 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
>  
>  static int fuse_writeback_range(struct inode *inode, loff_t start, loff_t end)
>  {
> -	int err = filemap_write_and_wait_range(inode->i_mapping, start, LLONG_MAX);
> +	int err;
>  
> +	if (fuse_inode_has_iomap(inode))
> +		return fuse_iomap_flush_unmap_range(inode, start, end);
> +
> +	err = filemap_write_and_wait_range(inode->i_mapping, start, LLONG_MAX);
>  	if (!err)
>  		fuse_sync_writes(inode);
>  
> @@ -2984,7 +2991,10 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
>  		return -EOPNOTSUPP;
>  
>  	inode_lock(inode);
> -	if (block_faults) {
> +	if (is_iomap) {
> +		filemap_invalidate_lock(inode->i_mapping);
> +		block_faults = true;
> +	} else if (block_faults) {
>  		filemap_invalidate_lock(inode->i_mapping);
>  		err = fuse_dax_break_layouts(inode, 0, -1);
>  		if (err)
> @@ -2999,6 +3009,17 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
>  			goto out;
>  	}
>  
> +	/*
> +	 * If we are using iomap for file IO, fallocate must wait for all AIO
> +	 * to complete before we continue as AIO can change the file size on
> +	 * completion without holding any locks we currently hold. We must do
> +	 * this first because AIO can update the in-memory inode size, and the
> +	 * operations that follow require the in-memory size to be fully
> +	 * up-to-date.
> +	 */
> +	if (is_iomap)
> +		inode_dio_wait(inode);
> +
>  	if (!(mode & FALLOC_FL_KEEP_SIZE) &&
>  	    offset + length > i_size_read(inode)) {
>  		err = inode_newsize_ok(inode, offset + length);
> @@ -3027,21 +3048,23 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
>  	if (err)
>  		goto out;
>  
> -	/* we could have extended the file */
> -	if (!(mode & FALLOC_FL_KEEP_SIZE)) {
> -		if (is_iomap && newsize > 0) {
> -			err = fuse_iomap_setsize_finish(inode, newsize);
> -			if (err)
> -				goto out;
> +	if (is_iomap) {
> +		err = fuse_iomap_fallocate(file, mode, offset, length,
> +					   newsize);
> +		if (err)
> +			goto out;
> +	} else {
> +		/* we could have extended the file */
> +		if (!(mode & FALLOC_FL_KEEP_SIZE)) {
> +			if (fuse_write_update_attr(inode, newsize, length))
> +				file_update_time(file);
>  		}
>  
> -		if (fuse_write_update_attr(inode, offset + length, length))
> -			file_update_time(file);
> +		if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE))
> +			truncate_pagecache_range(inode, offset,
> +						 offset + length - 1);
>  	}
>  
> -	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE))
> -		truncate_pagecache_range(inode, offset, offset + length - 1);
> -
>  	fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
>  
>  out:
> @@ -3085,6 +3108,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
>  	ssize_t err;
>  	/* mark unstable when write-back is not used, and file_out gets
>  	 * extended */
> +	const bool is_iomap = fuse_inode_has_iomap(inode_out);
>  	bool is_unstable = (!fc->writeback_cache) &&
>  			   ((pos_out + len) > inode_out->i_size);
>  
> @@ -3128,6 +3152,10 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
>  	if (err)
>  		goto out;
>  
> +	/* See inode_dio_wait comment in fuse_file_fallocate */
> +	if (is_iomap)
> +		inode_dio_wait(inode_out);
> +
>  	if (is_unstable)
>  		set_bit(FUSE_I_SIZE_UNSTABLE, &fi_out->state);
>  
> @@ -3168,7 +3196,8 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
>  		goto out;
>  	}
>  
> -	truncate_inode_pages_range(inode_out->i_mapping,
> +	if (!is_iomap)
> +		truncate_inode_pages_range(inode_out->i_mapping,
>  				   ALIGN_DOWN(pos_out, PAGE_SIZE),
>  				   ALIGN(pos_out + bytes_copied, PAGE_SIZE) - 1);
>  
> diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
> index f0b5ea49b6e2ac..2097a83af833d5 100644
> --- a/fs/fuse/fuse_iomap.c
> +++ b/fs/fuse/fuse_iomap.c
> @@ -5,6 +5,8 @@
>   */
>  #include <linux/iomap.h>
>  #include <linux/fiemap.h>
> +#include <linux/pagemap.h>
> +#include <linux/falloc.h>
>  #include "fuse_i.h"
>  #include "fuse_trace.h"
>  #include "fuse_iomap.h"
> @@ -204,7 +206,7 @@ static inline uint16_t fuse_iomap_flags_from_server(uint16_t fuse_f_flags)
>  		ret |= FUSE_IOMAP_OP_##word
>  static inline uint32_t fuse_iomap_op_to_server(unsigned iomap_op_flags)
>  {
> -	uint32_t ret = 0;
> +	uint32_t ret = iomap_op_flags & FUSE_IOMAP_OP_WRITEBACK;
>  
>  	XMAP(WRITE);
>  	XMAP(ZERO);
> @@ -370,7 +372,8 @@ fuse_iomap_begin_validate(const struct inode *inode,
>  
>  static inline bool fuse_is_iomap_file_write(unsigned int opflags)
>  {
> -	return opflags & (IOMAP_WRITE | IOMAP_ZERO | IOMAP_UNSHARE);
> +	return opflags & (IOMAP_WRITE | IOMAP_ZERO | IOMAP_UNSHARE |
> +			  FUSE_IOMAP_OP_WRITEBACK);
>  }
>  
>  static inline struct fuse_backing *
> @@ -747,12 +750,7 @@ void fuse_iomap_unmount(struct fuse_mount *fm)
>  	fuse_send_destroy(fm);
>  }
>  
> -static inline void fuse_inode_set_iomap(struct inode *inode)
> -{
> -	struct fuse_inode *fi = get_fuse_inode(inode);
> -
> -	set_bit(FUSE_I_IOMAP, &fi->state);
> -}
> +static inline void fuse_inode_set_iomap(struct inode *inode);
>  
>  static inline void fuse_inode_clear_iomap(struct inode *inode)
>  {
> @@ -979,17 +977,107 @@ static const struct iomap_dio_ops fuse_iomap_dio_write_ops = {
>  	.end_io		= fuse_iomap_dio_write_end_io,
>  };
>  
> +static const struct iomap_write_ops fuse_iomap_write_ops = {
> +};
> +
> +static int
> +fuse_iomap_zero_range(
> +	struct inode		*inode,
> +	loff_t			pos,
> +	loff_t			len,
> +	bool			*did_zero)
> +{
> +	return iomap_zero_range(inode, pos, len, did_zero, &fuse_iomap_ops,
> +				&fuse_iomap_write_ops, NULL);
> +}
> +
> +/* Take care of zeroing post-EOF blocks when they might exist. */
> +static ssize_t
> +fuse_iomap_write_zero_eof(
> +	struct kiocb		*iocb,
> +	struct iov_iter		*from,
> +	bool			*drained_dio)
> +{
> +	struct inode *inode = file_inode(iocb->ki_filp);
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	struct address_space *mapping = iocb->ki_filp->f_mapping;
> +	loff_t			isize;
> +	int			error;
> +
> +	/*
> +	 * We need to serialise against EOF updates that occur in IO
> +	 * completions here. We want to make sure that nobody is changing the
> +	 * size while we do this check until we have placed an IO barrier (i.e.
> +	 * hold i_rwsem exclusively) that prevents new IO from being
> +	 * dispatched.  The spinlock effectively forms a memory barrier once we
> +	 * have i_rwsem exclusively so we are guaranteed to see the latest EOF
> +	 * value and hence be able to correctly determine if we need to run
> +	 * zeroing.
> +	 */
> +	spin_lock(&fi->lock);
> +	isize = i_size_read(inode);
> +	if (iocb->ki_pos <= isize) {
> +		spin_unlock(&fi->lock);
> +		return 0;
> +	}
> +	spin_unlock(&fi->lock);
> +
> +	if (iocb->ki_flags & IOCB_NOWAIT)
> +		return -EAGAIN;
> +
> +	if (!(*drained_dio)) {
> +		/*
> +		 * We now have an IO submission barrier in place, but AIO can
> +		 * do EOF updates during IO completion and hence we now need to
> +		 * wait for all of them to drain.  Non-AIO DIO will have
> +		 * drained before we are given the exclusive i_rwsem, and so
> +		 * for most cases this wait is a no-op.
> +		 */
> +		inode_dio_wait(inode);
> +		*drained_dio = true;
> +		return 1;
> +	}
> +
> +	filemap_invalidate_lock(mapping);
> +	error = fuse_iomap_zero_range(inode, isize, iocb->ki_pos - isize, NULL);
> +	filemap_invalidate_unlock(mapping);
> +
> +	return error;
> +}
> +
>  static ssize_t
>  fuse_iomap_write_checks(
>  	struct kiocb		*iocb,
>  	struct iov_iter		*from)
>  {
> +	struct inode		*inode = iocb->ki_filp->f_mapping->host;
>  	ssize_t			error;
> +	bool			drained_dio = false;
>  
> +restart:
>  	error = generic_write_checks(iocb, from);
>  	if (error <= 0)
>  		return error;
>  
> +	/*
> +	 * If the offset is beyond the size of the file, we need to zero all
> +	 * blocks that fall between the existing EOF and the start of this
> +	 * write.
> +	 *
> +	 * We can do an unlocked check for i_size here safely as I/O completion
> +	 * can only extend EOF.  Truncate is locked out at this point, so the
> +	 * EOF cannot move backwards, only forwards. Hence we only need to take
> +	 * the slow path when we are at or beyond the current EOF.
> +	 */
> +	if (fuse_inode_has_iomap(inode) &&
> +	    iocb->ki_pos > i_size_read(inode)) {
> +		error = fuse_iomap_write_zero_eof(iocb, from, &drained_dio);
> +		if (error == 1)
> +			goto restart;
> +		if (error)
> +			return error;
> +	}
> +
>  	return kiocb_modified(iocb);
>  }
>  
> @@ -1059,6 +1147,366 @@ void fuse_iomap_open_truncate(struct inode *inode)
>  	fi->i_disk_size = 0;
>  }
>  
> +struct fuse_writepage_ctx {
> +	struct iomap_writepage_ctx ctx;
> +};
> +
> +static void fuse_iomap_end_ioend(struct iomap_ioend *ioend)
> +{
> +	struct inode *inode = ioend->io_inode;
> +	unsigned int ioendflags = FUSE_IOMAP_IOEND_WRITEBACK;
> +	unsigned int nofs_flag;
> +	int error = blk_status_to_errno(ioend->io_bio.bi_status);
> +
> +	ASSERT(fuse_inode_has_iomap(inode));
> +
> +	/* We still have to clean up the ioend even if the inode is dead */
> +	if (!error && fuse_is_bad(inode))
> +		error = -EIO;
> +
> +	if (ioend->io_flags & IOMAP_IOEND_SHARED)
> +		ioendflags |= FUSE_IOMAP_IOEND_SHARED;
> +	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
> +		ioendflags |= FUSE_IOMAP_IOEND_UNWRITTEN;
> +
> +	/*
> +	 * We can allocate memory here while doing writeback on behalf of
> +	 * memory reclaim.  To avoid memory allocation deadlocks set the
> +	 * task-wide nofs context for the following operations.
> +	 */
> +	nofs_flag = memalloc_nofs_save();
> +	fuse_iomap_ioend(inode, ioend->io_offset, ioend->io_size, error,
> +			 ioendflags, ioend->io_bio.bi_bdev, ioend->io_sector);
> +	iomap_finish_ioends(ioend, error);
> +	memalloc_nofs_restore(nofs_flag);
> +}
> +
> +/*
> + * Finish all pending IO completions that require transactional modifications.
> + *
> + * We try to merge physical and logically contiguous ioends before completion to
> + * minimise the number of transactions we need to perform during IO completion.
> + * Both unwritten extent conversion and COW remapping need to iterate and modify
> + * one physical extent at a time, so we gain nothing by merging physically
> + * discontiguous extents here.
> + *
> + * The ioend chain length that we can be processing here is largely unbound in
> + * length and we may have to perform significant amounts of work on each ioend
> + * to complete it. Hence we have to be careful about holding the CPU for too
> + * long in this loop.
> + */
> +static void fuse_iomap_end_io(struct work_struct *work)
> +{
> +	struct fuse_inode *fi =
> +		container_of(work, struct fuse_inode, ioend_work);
> +	struct iomap_ioend *ioend;
> +	struct list_head tmp;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&fi->ioend_lock, flags);
> +	list_replace_init(&fi->ioend_list, &tmp);
> +	spin_unlock_irqrestore(&fi->ioend_lock, flags);
> +
> +	iomap_sort_ioends(&tmp);
> +	while ((ioend = list_first_entry_or_null(&tmp, struct iomap_ioend,
> +			io_list))) {
> +		list_del_init(&ioend->io_list);
> +		iomap_ioend_try_merge(ioend, &tmp);
> +		fuse_iomap_end_ioend(ioend);
> +		cond_resched();
> +	}
> +}
> +
> +static void fuse_iomap_end_bio(struct bio *bio)
> +{
> +	struct iomap_ioend *ioend = iomap_ioend_from_bio(bio);
> +	struct inode *inode = ioend->io_inode;
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	unsigned long flags;
> +
> +	ASSERT(fuse_inode_has_iomap(inode));
> +
> +	spin_lock_irqsave(&fi->ioend_lock, flags);
> +	if (list_empty(&fi->ioend_list))
> +		WARN_ON_ONCE(!queue_work(system_unbound_wq, &fi->ioend_work));
> +	list_add_tail(&ioend->io_list, &fi->ioend_list);
> +	spin_unlock_irqrestore(&fi->ioend_lock, flags);
> +}
> +
> +/*
> + * Fast revalidation of the cached writeback mapping. Return true if the current
> + * mapping is valid, false otherwise.
> + */
> +static bool fuse_iomap_revalidate_writeback(struct iomap_writepage_ctx *wpc,
> +					    loff_t offset)
> +{
> +	if (offset < wpc->iomap.offset ||
> +	    offset >= wpc->iomap.offset + wpc->iomap.length)
> +		return false;
> +
> +	/* XXX actually use revalidation cookie */
> +	return true;
> +}
> +
> +/*
> + * If the folio has delalloc blocks on it, the caller is asking us to punch them
> + * out. If we don't, we can leave a stale delalloc mapping covered by a clean
> + * page that needs to be dirtied again before the delalloc mapping can be
> + * converted. This stale delalloc mapping can trip up a later direct I/O read
> + * operation on the same region.
> + *
> + * We prevent this by truncating away the delalloc regions on the folio. Because
> + * they are delalloc, we can do this without needing a transaction. Indeed - if
> + * we get ENOSPC errors, we have to be able to do this truncation without a
> + * transaction as there is no space left for block reservation (typically why
> + * we see a ENOSPC in writeback).
> + */
> +static void fuse_iomap_discard_folio(struct folio *folio, loff_t pos, int error)
> +{
> +	struct inode *inode = folio->mapping->host;
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	loff_t end = folio_pos(folio) + folio_size(folio);
> +
> +	if (fuse_is_bad(inode))
> +		return;
> +
> +	ASSERT(fuse_inode_has_iomap(inode));
> +
> +	printk_ratelimited(KERN_ERR
> +		"page discard on page %px, inode 0x%llx, pos %llu.",
> +			folio, fi->orig_ino, pos);
> +
> +	/* Userspace may need to remove delayed allocations */
> +	fuse_iomap_ioend(inode, pos, end - pos, error, 0, NULL,
> +			 FUSE_IOMAP_NULL_ADDR);
> +}
> +
> +static ssize_t fuse_iomap_writeback_range(struct iomap_writepage_ctx *wpc,
> +					  struct folio *folio, u64 offset,
> +					  unsigned int len, u64 end_pos)
> +{
> +	struct inode *inode = wpc->inode;
> +	struct iomap write_iomap, dontcare;
> +	ssize_t ret;
> +
> +	if (fuse_is_bad(inode)) {
> +		ret = -EIO;
> +		goto discard_folio;
> +	}
> +
> +	ASSERT(fuse_inode_has_iomap(inode));
> +
> +	if (!fuse_iomap_revalidate_writeback(wpc, offset)) {
> +		ret = fuse_iomap_begin(inode, offset, len,
> +				       FUSE_IOMAP_OP_WRITEBACK,
> +				       &write_iomap, &dontcare);
> +		if (ret)
> +			goto discard_folio;
> +
> +		/*
> +		 * Landed in a hole or beyond EOF?  Send that to iomap, it'll
> +		 * skip writing back the file range.
> +		 */
> +		if (write_iomap.offset > offset) {
> +			write_iomap.length = write_iomap.offset - offset;
> +			write_iomap.offset = offset;
> +			write_iomap.type = IOMAP_HOLE;
> +		}
> +
> +		memcpy(&wpc->iomap, &write_iomap, sizeof(struct iomap));
> +	}
> +
> +	ret = iomap_add_to_ioend(wpc, folio, offset, end_pos, len);
> +	if (ret < 0)
> +		goto discard_folio;
> +
> +	return ret;
> +discard_folio:
> +	fuse_iomap_discard_folio(folio, offset, ret);
> +	return ret;
> +}
> +
> +static int fuse_iomap_writeback_submit(struct iomap_writepage_ctx *wpc,
> +				       int error)
> +{
> +	struct iomap_ioend *ioend = wpc->wb_ctx;
> +
> +	ASSERT(fuse_inode_has_iomap(ioend->io_inode));
> +
> +	/* always call our ioend function, even if we cancel the bio */
> +	ioend->io_bio.bi_end_io = fuse_iomap_end_bio;
> +	return iomap_ioend_writeback_submit(wpc, error);
> +}
> +
> +static const struct iomap_writeback_ops fuse_iomap_writeback_ops = {
> +	.writeback_range	= fuse_iomap_writeback_range,
> +	.writeback_submit	= fuse_iomap_writeback_submit,
> +};
> +
> +static int fuse_iomap_writepages(struct address_space *mapping,
> +				 struct writeback_control *wbc)
> +{
> +	struct fuse_writepage_ctx wpc = {
> +		.ctx = {
> +			.inode = mapping->host,
> +			.wbc = wbc,
> +			.ops = &fuse_iomap_writeback_ops,
> +		},
> +	};
> +
> +	ASSERT(fuse_inode_has_iomap(mapping->host));
> +
> +	return iomap_writepages(&wpc.ctx);
> +}
> +
> +static int fuse_iomap_read_folio(struct file *file, struct folio *folio)
> +{
> +	ASSERT(fuse_inode_has_iomap(file_inode(file)));
> +
> +	iomap_bio_read_folio(folio, &fuse_iomap_ops);
> +	return 0;
> +}
> +
> +static void fuse_iomap_readahead(struct readahead_control *rac)
> +{
> +	ASSERT(fuse_inode_has_iomap(file_inode(rac->file)));
> +
> +	iomap_bio_readahead(rac, &fuse_iomap_ops);
> +}
> +
> +static const struct address_space_operations fuse_iomap_aops = {
> +	.read_folio		= fuse_iomap_read_folio,
> +	.readahead		= fuse_iomap_readahead,
> +	.writepages		= fuse_iomap_writepages,
> +	.dirty_folio		= iomap_dirty_folio,
> +	.release_folio		= iomap_release_folio,
> +	.invalidate_folio	= iomap_invalidate_folio,
> +	.migrate_folio		= filemap_migrate_folio,
> +	.is_partially_uptodate  = iomap_is_partially_uptodate,
> +	.error_remove_folio	= generic_error_remove_folio,
> +
> +	/* These aren't pagecache operations per se */
> +	.bmap			= fuse_bmap,
> +};
> +
> +static inline void fuse_inode_set_iomap(struct inode *inode)
> +{
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +
> +	inode->i_data.a_ops = &fuse_iomap_aops;
> +
> +	INIT_WORK(&fi->ioend_work, fuse_iomap_end_io);
> +	INIT_LIST_HEAD(&fi->ioend_list);
> +	spin_lock_init(&fi->ioend_lock);
> +	set_bit(FUSE_I_IOMAP, &fi->state);
> +}
> +
> +/*
> + * Locking for serialisation of IO during page faults. This results in a lock
> + * ordering of:
> + *
> + * mmap_lock (MM)
> + *   sb_start_pagefault(vfs, freeze)
> + *     invalidate_lock (vfs - truncate serialisation)
> + *       page_lock (MM)
> + *         i_lock (FUSE - extent map serialisation)
> + */
> +static vm_fault_t fuse_iomap_page_mkwrite(struct vm_fault *vmf)
> +{
> +	struct inode *inode = file_inode(vmf->vma->vm_file);
> +	struct address_space *mapping = vmf->vma->vm_file->f_mapping;
> +	vm_fault_t ret;
> +
> +	ASSERT(fuse_inode_has_iomap(inode));
> +
> +	sb_start_pagefault(inode->i_sb);
> +	file_update_time(vmf->vma->vm_file);
> +
> +	filemap_invalidate_lock_shared(mapping);
> +	ret = iomap_page_mkwrite(vmf, &fuse_iomap_ops, NULL);
> +	filemap_invalidate_unlock_shared(mapping);
> +
> +	sb_end_pagefault(inode->i_sb);
> +	return ret;
> +}
> +
> +static const struct vm_operations_struct fuse_iomap_vm_ops = {
> +	.fault		= filemap_fault,
> +	.map_pages	= filemap_map_pages,
> +	.page_mkwrite	= fuse_iomap_page_mkwrite,
> +};
> +
> +int fuse_iomap_mmap(struct file *file, struct vm_area_struct *vma)
> +{
> +	ASSERT(fuse_inode_has_iomap(file_inode(file)));
> +
> +	file_accessed(file);
> +	vma->vm_ops = &fuse_iomap_vm_ops;
> +	return 0;
> +}
> +
> +static ssize_t fuse_iomap_buffered_read(struct kiocb *iocb, struct iov_iter *to)
> +{
> +	struct inode *inode = file_inode(iocb->ki_filp);
> +	ssize_t ret;
> +
> +	ASSERT(fuse_inode_has_iomap(inode));
> +
> +	if (!iov_iter_count(to))
> +		return 0; /* skip atime */
> +
> +	ret = fuse_iomap_ilock_iocb(iocb, SHARED);
> +	if (ret)
> +		return ret;
> +	ret = generic_file_read_iter(iocb, to);
> +	if (ret > 0)
> +		file_accessed(iocb->ki_filp);
> +	inode_unlock_shared(inode);
> +
> +	return ret;
> +}
> +
> +static ssize_t fuse_iomap_buffered_write(struct kiocb *iocb,
> +					 struct iov_iter *from)
> +{
> +	struct inode *inode = file_inode(iocb->ki_filp);
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	loff_t pos = iocb->ki_pos;
> +	ssize_t ret;
> +
> +	ASSERT(fuse_inode_has_iomap(inode));
> +
> +	if (!iov_iter_count(from))
> +		return 0;
> +
> +	ret = fuse_iomap_ilock_iocb(iocb, EXCL);
> +	if (ret)
> +		return ret;
> +
> +	ret = fuse_iomap_write_checks(iocb, from);
> +	if (ret)
> +		goto out_unlock;
> +
> +	if (inode->i_size < pos + iov_iter_count(from))
> +		set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
> +
> +	ret = iomap_file_buffered_write(iocb, from, &fuse_iomap_ops,
> +					&fuse_iomap_write_ops, NULL);
> +
> +	if (ret > 0)
> +		fuse_write_update_attr(inode, pos + ret, ret);
> +	clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
> +
> +out_unlock:
> +	inode_unlock(inode);
> +
> +	if (ret > 0) {
> +		/* Handle various SYNC-type writes */
> +		ret = generic_write_sync(iocb, ret);
> +	}
> +	return ret;
> +}
> +
>  static inline bool fuse_iomap_force_directio(const struct kiocb *iocb)
>  {
>  	struct fuse_file *ff = iocb->ki_filp->private_data;
> @@ -1072,9 +1520,30 @@ ssize_t fuse_iomap_read_iter(struct kiocb *iocb, struct iov_iter *to)
>  
>  	ASSERT(fuse_inode_has_iomap(file_inode(iocb->ki_filp)));
>  
> -	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio)
> -		return fuse_iomap_direct_read(iocb, to);
> -	return -EIO;
> +	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio) {
> +		ssize_t ret = fuse_iomap_direct_read(iocb, to);
> +
> +		switch (ret) {
> +		case -ENOTBLK:
> +		case -ENOSYS:
> +			/*
> +			 * We fall back to a buffered read if:
> +			 *
> +			 *  - ENOTBLK means iomap told us to do it
> +			 *  - ENOSYS means the fuse server wants it
> +			 *
> +			 * Don't fall back if we were forced to do it.
> +			 */
> +			if (force_directio)
> +				return -EIO;
> +			break;
> +		default:
> +			/* errors, no progress, or partial progress */
> +			return ret;
> +		}

When falling back from directio read to buffered IO, we need to clear
IOCB_DIRECT so that generic_file_read_iter won't fall into ->direct_IO.

Note that the directio write fallback doesn't need to clear this because
it calls the iomap buffered write code directly.

--D

> +	}
> +
> +	return fuse_iomap_buffered_read(iocb, to);
>  }
>  
>  ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from)
> @@ -1083,7 +1552,206 @@ ssize_t fuse_iomap_write_iter(struct kiocb *iocb, struct iov_iter *from)
>  
>  	ASSERT(fuse_inode_has_iomap(file_inode(iocb->ki_filp)));
>  
> -	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio)
> -		return fuse_iomap_direct_write(iocb, from);
> -	return -EIO;
> +	if ((iocb->ki_flags & IOCB_DIRECT) || force_directio) {
> +		ssize_t ret = fuse_iomap_direct_write(iocb, from);
> +
> +		switch (ret) {
> +		case -ENOTBLK:
> +		case -ENOSYS:
> +			/*
> +			 * We fall back to a buffered write if:
> +			 *
> +			 *  - ENOTBLK means iomap told us to do it
> +			 *  - ENOSYS means the fuse server wants it
> +			 *
> +			 * Either way, try the write again as a synchronous
> +			 * buffered write unless we were forced to do directio.
> +			 */
> +			if (force_directio)
> +				return -EIO;
> +			iocb->ki_flags |= IOCB_SYNC;
> +			break;
> +		default:
> +			/* errors, no progress, or partial progress */
> +			return ret;
> +		}
> +	}
> +
> +	return fuse_iomap_buffered_write(iocb, from);
> +}
> +
> +static int
> +fuse_iomap_truncate_page(
> +	struct inode *inode,
> +	loff_t			pos,
> +	bool			*did_zero)
> +{
> +	return iomap_truncate_page(inode, pos, did_zero, &fuse_iomap_ops,
> +				   &fuse_iomap_write_ops, NULL);
> +}
> +/*
> + * Truncate pagecache for a file before sending the truncate request to
> + * userspace.  Must have write permission and not be a directory.
> + *
> + * Caution: The caller of this function is responsible for calling
> + * setattr_prepare() or otherwise verifying the change is fine.
> + */
> +int
> +fuse_iomap_setsize_start(
> +	struct inode		*inode,
> +	loff_t			newsize)
> +{
> +	loff_t			oldsize = i_size_read(inode);
> +	int			error;
> +	bool			did_zeroing = false;
> +
> +	rwsem_assert_held_write(&inode->i_rwsem);
> +	rwsem_assert_held_write(&inode->i_mapping->invalidate_lock);
> +	ASSERT(S_ISREG(inode->i_mode));
> +
> +	/*
> +	 * Wait for all direct I/O to complete.
> +	 */
> +	inode_dio_wait(inode);
> +
> +	/*
> +	 * File data changes must be complete and flushed to disk before we
> +	 * call userspace to modify the inode.
> +	 *
> +	 * Start with zeroing any data beyond EOF that we may expose on file
> +	 * extension, or zeroing out the rest of the block on a downward
> +	 * truncate.
> +	 */
> +	if (newsize > oldsize)
> +		error = fuse_iomap_zero_range(inode, oldsize, newsize - oldsize,
> +					      &did_zeroing);
> +	else
> +		error = fuse_iomap_truncate_page(inode, newsize, &did_zeroing);
> +	if (error)
> +		return error;
> +
> +	/*
> +	 * We've already locked out new page faults, so now we can safely
> +	 * remove pages from the page cache knowing they won't get refaulted
> +	 * until we drop the mapping invalidation lock after the extent
> +	 * manipulations are complete. The truncate_setsize() call also cleans
> +	 * folios spanning EOF on extending truncates and hence ensures
> +	 * sub-page block size filesystems are correctly handled, too.
> +	 *
> +	 * And we update in-core i_size and truncate page cache beyond newsize
> +	 * before writing back the whole file, so we're guaranteed not to write
> +	 * stale data past the new EOF on truncate down.
> +	 */
> +	truncate_setsize(inode, newsize);
> +
> +	/*
> +	 * Flush the entire pagecache to ensure the fuse server logs the inode
> +	 * size change and all dirty data that might be associated with it.
> +	 * We don't know the ondisk inode size, so we only have this clumsy
> +	 * hammer.
> +	 */
> +	return filemap_write_and_wait(inode->i_mapping);
> +}
> +
> +/*
> + * Prepare for a file data block remapping operation by flushing and unmapping
> + * all pagecache for the entire range.
> + */
> +int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
> +				 loff_t endpos)
> +{
> +	loff_t			start, end;
> +	unsigned int		rounding;
> +	int			error;
> +
> +	/*
> +	 * Make sure we extend the flush out to extent alignment boundaries so
> +	 * any extent range overlapping the start/end of the modification we
> +	 * are about to do is clean and idle.
> +	 */
> +	rounding = max_t(unsigned int, i_blocksize(inode), PAGE_SIZE);
> +	start = round_down(pos, rounding);
> +	end = round_up(endpos + 1, rounding) - 1;
> +
> +	error = filemap_write_and_wait_range(inode->i_mapping, start, end);
> +	if (error)
> +		return error;
> +	truncate_pagecache_range(inode, start, end);
> +	return 0;
> +}
> +
> +static int fuse_iomap_punch_range(struct inode *inode, loff_t offset,
> +				  loff_t length)
> +{
> +	loff_t isize = i_size_read(inode);
> +	int error;
> +
> +	/*
> +	 * Now that we've unmap all full blocks we'll have to zero out any
> +	 * partial block at the beginning and/or end.  iomap_zero_range is
> +	 * smart enough to skip holes and unwritten extents, including those we
> +	 * just created, but we must take care not to zero beyond EOF, which
> +	 * would enlarge i_size.
> +	 */
> +	if (offset >= isize)
> +		return 0;
> +	if (offset + length > isize)
> +		length = isize - offset;
> +	error = fuse_iomap_zero_range(inode, offset, length, NULL);
> +	if (error)
> +		return error;
> +
> +	/*
> +	 * If we zeroed right up to EOF and EOF straddles a page boundary we
> +	 * must make sure that the post-EOF area is also zeroed because the
> +	 * page could be mmap'd and iomap_zero_range doesn't do that for us.
> +	 * Writeback of the eof page will do this, albeit clumsily.
> +	 */
> +	if (offset + length >= isize && offset_in_page(offset + length) > 0) {
> +		error = filemap_write_and_wait_range(inode->i_mapping,
> +					round_down(offset + length, PAGE_SIZE),
> +					LLONG_MAX);
> +	}
> +
> +	return error;
> +}
> +
> +int
> +fuse_iomap_fallocate(
> +	struct file		*file,
> +	int			mode,
> +	loff_t			offset,
> +	loff_t			length,
> +	loff_t			new_size)
> +{
> +	struct inode *inode = file_inode(file);
> +	int error;
> +
> +	ASSERT(fuse_inode_has_iomap(inode));
> +
> +	/*
> +	 * If we unmapped blocks from the file range, then we zero the
> +	 * pagecache for those regions and push them to disk rather than make
> +	 * the fuse server manually zero the disk blocks.
> +	 */
> +	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)) {
> +		error = fuse_iomap_punch_range(inode, offset, length);
> +		if (error)
> +			return error;
> +	}
> +
> +	/*
> +	 * If this is an extending write, we need to zero the bytes beyond the
> +	 * new EOF and bounce the new size out to userspace.
> +	 */
> +	if (new_size) {
> +		error = fuse_iomap_setsize_start(inode, new_size);
> +		if (error)
> +			return error;
> +
> +		fuse_write_update_attr(inode, new_size, length);
> +	}
> +
> +	file_update_time(file);
> +	return 0;
>  }
> 
> 

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 01/12] fuse: cache iomaps
  2026-02-23 23:20   ` [PATCH 01/12] fuse: cache iomaps Darrick J. Wong
@ 2026-02-27 18:07     ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-02-27 18:07 UTC (permalink / raw)
  To: miklos; +Cc: joannelkoong, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Mon, Feb 23, 2026 at 03:20:40PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Cache iomaps to a file so that we don't have to upcall the server.
> 
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> ---
>  fs/fuse/fuse_i.h           |    3 
>  fs/fuse/fuse_iomap_cache.h |   99 +++
>  include/uapi/linux/fuse.h  |    5 
>  fs/fuse/Makefile           |    2 
>  fs/fuse/fuse_iomap.c       |    5 
>  fs/fuse/fuse_iomap_cache.c | 1701 ++++++++++++++++++++++++++++++++++++++++++++
>  fs/fuse/trace.c            |    1 
>  7 files changed, 1815 insertions(+), 1 deletion(-)
>  create mode 100644 fs/fuse/fuse_iomap_cache.h
>  create mode 100644 fs/fuse/fuse_iomap_cache.c
> 
> 
> diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> index b4da866187ba2c..1ba95d1f430c3e 100644
> --- a/fs/fuse/fuse_i.h
> +++ b/fs/fuse/fuse_i.h
> @@ -197,6 +197,9 @@ struct fuse_inode {
>  			spinlock_t ioend_lock;
>  			struct work_struct ioend_work;
>  			struct list_head ioend_list;
> +
> +			/* cached iomap mappings */
> +			struct fuse_iomap_cache *cache;
>  #endif
>  		};
>  
> diff --git a/fs/fuse/fuse_iomap_cache.h b/fs/fuse/fuse_iomap_cache.h
> new file mode 100644
> index 00000000000000..922ca182357aa7
> --- /dev/null
> +++ b/fs/fuse/fuse_iomap_cache.h
> @@ -0,0 +1,99 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * The fuse_iext code comes from xfs_iext_tree.[ch] and is:
> + * Copyright (c) 2017 Christoph Hellwig.
> + *
> + * Everything else is:
> + * Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
> + * Author: Darrick J. Wong <djwong@kernel.org>
> + */
> +#ifndef _FS_FUSE_IOMAP_CACHE_H
> +#define _FS_FUSE_IOMAP_CACHE_H
> +
> +#if IS_ENABLED(CONFIG_FUSE_IOMAP)
> +/*
> + * File incore extent information, present for read and write mappings.
> + */
> +struct fuse_iext_root {
> +	/* bytes in ir_data, or -1 if it has never been used */
> +	int64_t			ir_bytes;
> +	void			*ir_data;	/* extent tree root */
> +	unsigned int		ir_height;	/* height of the extent tree */
> +};
> +
> +struct fuse_iomap_cache {
> +	struct fuse_iext_root	ic_read;
> +	struct fuse_iext_root	ic_write;
> +	uint64_t		ic_seq;		/* validity counter */
> +	struct rw_semaphore	ic_lock;	/* mapping lock */
> +	struct inode		*ic_inode;
> +};
> +
> +void fuse_iomap_cache_lock(struct inode *inode);
> +void fuse_iomap_cache_unlock(struct inode *inode);
> +void fuse_iomap_cache_lock_shared(struct inode *inode);
> +void fuse_iomap_cache_unlock_shared(struct inode *inode);
> +
> +struct fuse_iext_leaf;
> +
> +struct fuse_iext_cursor {
> +	struct fuse_iext_leaf	*leaf;
> +	int			pos;
> +};
> +
> +#define FUSE_IEXT_LEFT_CONTIG	(1u << 0)
> +#define FUSE_IEXT_RIGHT_CONTIG	(1u << 1)
> +#define FUSE_IEXT_LEFT_FILLING	(1u << 2)
> +#define FUSE_IEXT_RIGHT_FILLING	(1u << 3)
> +#define FUSE_IEXT_LEFT_VALID	(1u << 4)
> +#define FUSE_IEXT_RIGHT_VALID	(1u << 5)
> +#define FUSE_IEXT_WRITE_MAPPING	(1u << 6)
> +
> +bool fuse_iext_get_extent(const struct fuse_iext_root *ir,
> +			  const struct fuse_iext_cursor *cur,
> +			  struct fuse_iomap_io *gotp);
> +
> +static inline uint64_t fuse_iext_read_seq(struct fuse_iomap_cache *ic)
> +{
> +	return (uint64_t)READ_ONCE(ic->ic_seq);
> +}
> +
> +static inline void fuse_iomap_cache_init(struct fuse_inode *fi)
> +{
> +	fi->cache = NULL;
> +}
> +
> +static inline bool fuse_inode_caches_iomaps(const struct inode *inode)
> +{
> +	const struct fuse_inode *fi = get_fuse_inode(inode);
> +
> +	return fi->cache != NULL;
> +}
> +
> +int fuse_iomap_cache_alloc(struct inode *inode);
> +void fuse_iomap_cache_free(struct inode *inode);
> +
> +int fuse_iomap_cache_remove(struct inode *inode, enum fuse_iomap_iodir iodir,
> +			    loff_t off, uint64_t len);
> +
> +int fuse_iomap_cache_upsert(struct inode *inode, enum fuse_iomap_iodir iodir,
> +			    const struct fuse_iomap_io *map);
> +
> +enum fuse_iomap_lookup_result {
> +	LOOKUP_HIT,
> +	LOOKUP_MISS,
> +	LOOKUP_NOFORK,
> +};
> +
> +struct fuse_iomap_lookup {
> +	struct fuse_iomap_io	map;		 /* cached mapping */
> +	uint64_t		validity_cookie; /* used with .iomap_valid() */
> +};
> +
> +enum fuse_iomap_lookup_result
> +fuse_iomap_cache_lookup(struct inode *inode, enum fuse_iomap_iodir iodir,
> +			loff_t off, uint64_t len,
> +			struct fuse_iomap_lookup *mval);
> +#endif /* CONFIG_FUSE_IOMAP */
> +
> +#endif /* _FS_FUSE_IOMAP_CACHE_H */
> diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
> index bf8514a5ee27af..a273838bc20f2f 100644
> --- a/include/uapi/linux/fuse.h
> +++ b/include/uapi/linux/fuse.h
> @@ -1394,6 +1394,8 @@ struct fuse_uring_cmd_req {
>  
>  /* fuse-specific mapping type indicating that writes use the read mapping */
>  #define FUSE_IOMAP_TYPE_PURE_OVERWRITE	(255)
> +/* fuse-specific mapping type saying the server has populated the cache */
> +#define FUSE_IOMAP_TYPE_RETRY_CACHE	(254)
>  
>  #define FUSE_IOMAP_DEV_NULL		(0U)	/* null device cookie */
>  
> @@ -1551,4 +1553,7 @@ struct fuse_iomap_dev_inval_out {
>  	struct fuse_range range;
>  };
>  
> +/* invalidate all cached iomap mappings up to EOF */
> +#define FUSE_IOMAP_INVAL_TO_EOF		(~0ULL)
> +
>  #endif /* _LINUX_FUSE_H */
> diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile
> index 2536bc6a71b898..c672503da7bcbd 100644
> --- a/fs/fuse/Makefile
> +++ b/fs/fuse/Makefile
> @@ -18,6 +18,6 @@ fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o
>  fuse-$(CONFIG_FUSE_BACKING) += backing.o
>  fuse-$(CONFIG_SYSCTL) += sysctl.o
>  fuse-$(CONFIG_FUSE_IO_URING) += dev_uring.o
> -fuse-$(CONFIG_FUSE_IOMAP) += fuse_iomap.o
> +fuse-$(CONFIG_FUSE_IOMAP) += fuse_iomap.o fuse_iomap_cache.o
>  
>  virtiofs-y := virtio_fs.o
> diff --git a/fs/fuse/fuse_iomap.c b/fs/fuse/fuse_iomap.c
> index 9599efcf1c2593..849ce1626c35fd 100644
> --- a/fs/fuse/fuse_iomap.c
> +++ b/fs/fuse/fuse_iomap.c
> @@ -14,6 +14,7 @@
>  #include "fuse_iomap.h"
>  #include "fuse_iomap_i.h"
>  #include "fuse_dev_i.h"
> +#include "fuse_iomap_cache.h"
>  
>  static bool __read_mostly enable_iomap =
>  #if IS_ENABLED(CONFIG_FUSE_IOMAP_BY_DEFAULT)
> @@ -1179,6 +1180,8 @@ void fuse_iomap_evict_inode(struct inode *inode)
>  
>  	trace_fuse_iomap_evict_inode(inode);
>  
> +	if (fuse_inode_caches_iomaps(inode))
> +		fuse_iomap_cache_free(inode);
>  	fuse_inode_clear_atomic(inode);
>  	fuse_inode_clear_iomap(inode);
>  }
> @@ -1886,6 +1889,8 @@ static inline void fuse_inode_set_iomap(struct inode *inode)
>  		min_order = inode->i_blkbits - PAGE_SHIFT;
>  
>  	mapping_set_folio_min_order(inode->i_mapping, min_order);
> +
> +	fuse_iomap_cache_init(fi);
>  	set_bit(FUSE_I_IOMAP, &fi->state);
>  }
>  
> diff --git a/fs/fuse/fuse_iomap_cache.c b/fs/fuse/fuse_iomap_cache.c
> new file mode 100644
> index 00000000000000..e32de8a5e3c325
> --- /dev/null
> +++ b/fs/fuse/fuse_iomap_cache.c
> @@ -0,0 +1,1701 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * fuse_iext* code adapted from xfs_iext_tree.c:
> + * Copyright (c) 2017 Christoph Hellwig.
> + *
> + * fuse_iomap_cache*lock* code adapted from xfs_inode.c:
> + * Copyright (c) 2000-2006 Silicon Graphics, Inc.
> + * All Rights Reserved.
> + *
> + * Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
> + * Author: Darrick J. Wong <djwong@kernel.org>
> + */
> +#include "fuse_i.h"
> +#include "fuse_trace.h"
> +#include "fuse_iomap_i.h"
> +#include "fuse_iomap.h"
> +#include "fuse_iomap_cache.h"
> +#include <linux/iomap.h>
> +
> +void fuse_iomap_cache_lock_shared(struct inode *inode)
> +{
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache *ic = fi->cache;
> +
> +	down_read(&ic->ic_lock);
> +}
> +
> +void fuse_iomap_cache_unlock_shared(struct inode *inode)
> +{
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache *ic = fi->cache;
> +
> +	up_read(&ic->ic_lock);
> +}
> +
> +void fuse_iomap_cache_lock(struct inode *inode)
> +{
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache *ic = fi->cache;
> +
> +	down_write(&ic->ic_lock);
> +}
> +
> +void fuse_iomap_cache_unlock(struct inode *inode)
> +{
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache *ic = fi->cache;
> +
> +	up_write(&ic->ic_lock);
> +}
> +
> +static inline void assert_cache_locked_shared(struct fuse_iomap_cache *ic)
> +{
> +	rwsem_assert_held(&ic->ic_lock);
> +}
> +
> +static inline void assert_cache_locked(struct fuse_iomap_cache *ic)
> +{
> +	rwsem_assert_held_write_nolockdep(&ic->ic_lock);
> +}
> +
> +/*
> + * In-core extent btree block layout:
> + *
> + * There are two types of blocks in the btree: leaf and inner (non-leaf) blocks.
> + *
> + * The leaf blocks are made up by %KEYS_PER_NODE extent records, which each
> + * contain the startoffset, blockcount, startblock and unwritten extent flag.
> + * See above for the exact format, followed by pointers to the previous and next
> + * leaf blocks (if there are any).
> + *
> + * The inner (non-leaf) blocks first contain KEYS_PER_NODE lookup keys, followed
> + * by an equal number of pointers to the btree blocks at the next lower level.
> + *
> + *		+-------+-------+-------+-------+-------+----------+----------+
> + * Leaf:	| rec 1 | rec 2 | rec 3 | rec 4 | rec N | prev-ptr | next-ptr |
> + *		+-------+-------+-------+-------+-------+----------+----------+
> + *
> + *		+-------+-------+-------+-------+-------+-------+------+-------+
> + * Inner:	| key 1 | key 2 | key 3 | key N | ptr 1 | ptr 2 | ptr3 | ptr N |
> + *		+-------+-------+-------+-------+-------+-------+------+-------+
> + */
> +typedef uint64_t fuse_iext_key_t;
> +#define FUSE_IEXT_KEY_INVALID	(1ULL << 63)
> +
> +enum {
> +	NODE_SIZE	= 256,
> +	KEYS_PER_NODE	= NODE_SIZE / (sizeof(fuse_iext_key_t) + sizeof(void *)),
> +	RECS_PER_LEAF	= (NODE_SIZE - (2 * sizeof(struct fuse_iext_leaf *))) /
> +				sizeof(struct fuse_iomap_io),
> +};
> +
> +/* maximum length of a mapping that we're willing to cache */
> +#define FUSE_IOMAP_MAX_LEN	((loff_t)(1ULL << 63))
> +
> +struct fuse_iext_node {
> +	fuse_iext_key_t		keys[KEYS_PER_NODE];
> +	void			*ptrs[KEYS_PER_NODE];
> +};
> +
> +struct fuse_iext_leaf {
> +	struct fuse_iomap_io	recs[RECS_PER_LEAF];
> +	struct fuse_iext_leaf	*prev;
> +	struct fuse_iext_leaf	*next;
> +};
> +
> +static uint32_t
> +fuse_iomap_fork_to_state(const struct fuse_iomap_cache *ic,
> +			 const struct fuse_iext_root *ir)
> +{
> +	ASSERT(ir == &ic->ic_write || ir == &ic->ic_read);
> +
> +	if (ir == &ic->ic_write)
> +		return FUSE_IEXT_WRITE_MAPPING;
> +	return 0;
> +}
> +
> +/* Convert bmap state flags to an inode fork. */
> +static struct fuse_iext_root *
> +fuse_iext_state_to_fork(
> +	struct fuse_iomap_cache	*ic,
> +	uint32_t		state)
> +{
> +	if (state & FUSE_IEXT_WRITE_MAPPING)
> +		return &ic->ic_write;
> +	return &ic->ic_read;
> +}
> +
> +/* The internal iext tree record is a struct fuse_iomap_io */
> +
> +static inline bool fuse_iext_rec_is_empty(const struct fuse_iomap_io *rec)
> +{
> +	return rec->length == 0;
> +}
> +
> +static inline void fuse_iext_rec_clear(struct fuse_iomap_io *rec)
> +{
> +	memset(rec, 0, sizeof(*rec));
> +}
> +
> +static inline void
> +fuse_iext_set(
> +	struct fuse_iomap_io		*rec,
> +	const struct fuse_iomap_io	*irec)
> +{
> +	ASSERT(irec->length > 0);
> +
> +	*rec = *irec;
> +}
> +
> +static inline void
> +fuse_iext_get(
> +	struct fuse_iomap_io		*irec,
> +	const struct fuse_iomap_io	*rec)
> +{
> +	*irec = *rec;
> +}
> +
> +static inline uint64_t fuse_iext_count(const struct fuse_iext_root *ir)
> +{
> +	return ir->ir_bytes / sizeof(struct fuse_iomap_io);
> +}
> +
> +static inline int fuse_iext_max_recs(const struct fuse_iext_root *ir)
> +{
> +	if (ir->ir_height == 1)
> +		return fuse_iext_count(ir);
> +	return RECS_PER_LEAF;
> +}
> +
> +static inline struct fuse_iomap_io *cur_rec(const struct fuse_iext_cursor *cur)
> +{
> +	return &cur->leaf->recs[cur->pos];
> +}
> +
> +static bool fuse_iext_valid(const struct fuse_iext_root *ir,
> +				   const struct fuse_iext_cursor *cur)
> +{
> +	if (!cur->leaf)
> +		return false;
> +	if (cur->pos < 0 || cur->pos >= fuse_iext_max_recs(ir))
> +		return false;
> +	if (fuse_iext_rec_is_empty(cur_rec(cur)))
> +		return false;
> +	return true;
> +}
> +
> +static void *
> +fuse_iext_find_first_leaf(
> +	struct fuse_iext_root	*ir)
> +{
> +	struct fuse_iext_node	*node = ir->ir_data;
> +	int			height;
> +
> +	if (!ir->ir_height)
> +		return NULL;
> +
> +	for (height = ir->ir_height; height > 1; height--) {
> +		node = node->ptrs[0];
> +		ASSERT(node);
> +	}
> +
> +	return node;
> +}
> +
> +static void *
> +fuse_iext_find_last_leaf(
> +	struct fuse_iext_root	*ir)
> +{
> +	struct fuse_iext_node	*node = ir->ir_data;
> +	int			height, i;
> +
> +	if (!ir->ir_height)
> +		return NULL;
> +
> +	for (height = ir->ir_height; height > 1; height--) {
> +		for (i = 1; i < KEYS_PER_NODE; i++)
> +			if (!node->ptrs[i])
> +				break;
> +		node = node->ptrs[i - 1];
> +		ASSERT(node);
> +	}
> +
> +	return node;
> +}
> +
> +static void
> +fuse_iext_first(
> +	struct fuse_iext_root	*ir,
> +	struct fuse_iext_cursor	*cur)
> +{
> +	cur->pos = 0;
> +	cur->leaf = fuse_iext_find_first_leaf(ir);
> +}
> +
> +static void
> +fuse_iext_last(
> +	struct fuse_iext_root	*ir,
> +	struct fuse_iext_cursor	*cur)
> +{
> +	int			i;
> +
> +	cur->leaf = fuse_iext_find_last_leaf(ir);
> +	if (!cur->leaf) {
> +		cur->pos = 0;
> +		return;
> +	}
> +
> +	for (i = 1; i < fuse_iext_max_recs(ir); i++) {
> +		if (fuse_iext_rec_is_empty(&cur->leaf->recs[i]))
> +			break;
> +	}
> +	cur->pos = i - 1;
> +}
> +
> +static void
> +fuse_iext_next(
> +	struct fuse_iext_root	*ir,
> +	struct fuse_iext_cursor	*cur)
> +{
> +	if (!cur->leaf) {
> +		ASSERT(cur->pos <= 0 || cur->pos >= RECS_PER_LEAF);
> +		fuse_iext_first(ir, cur);
> +		return;
> +	}
> +
> +	ASSERT(cur->pos >= 0);
> +	ASSERT(cur->pos < fuse_iext_max_recs(ir));
> +
> +	cur->pos++;
> +	if (ir->ir_height > 1 && !fuse_iext_valid(ir, cur) &&
> +	    cur->leaf->next) {
> +		cur->leaf = cur->leaf->next;
> +		cur->pos = 0;
> +	}
> +}
> +
> +static void
> +fuse_iext_prev(
> +	struct fuse_iext_root	*ir,
> +	struct fuse_iext_cursor	*cur)
> +{
> +	if (!cur->leaf) {
> +		ASSERT(cur->pos <= 0 || cur->pos >= RECS_PER_LEAF);
> +		fuse_iext_last(ir, cur);
> +		return;
> +	}
> +
> +	ASSERT(cur->pos >= 0);
> +	ASSERT(cur->pos <= RECS_PER_LEAF);
> +
> +recurse:
> +	do {
> +		cur->pos--;
> +		if (fuse_iext_valid(ir, cur))
> +			return;
> +	} while (cur->pos > 0);
> +
> +	if (ir->ir_height > 1 && cur->leaf->prev) {
> +		cur->leaf = cur->leaf->prev;
> +		cur->pos = RECS_PER_LEAF;
> +		goto recurse;
> +	}
> +}
> +
> +/*
> + * Return true if the cursor points at an extent and return the extent structure
> + * in gotp.  Else return false.
> + */
> +bool
> +fuse_iext_get_extent(
> +	const struct fuse_iext_root	*ir,
> +	const struct fuse_iext_cursor	*cur,
> +	struct fuse_iomap_io		*gotp)
> +{
> +	if (!fuse_iext_valid(ir, cur))
> +		return false;
> +	fuse_iext_get(gotp, cur_rec(cur));
> +	return true;
> +}
> +
> +static inline bool fuse_iext_next_extent(struct fuse_iext_root *ir,
> +		struct fuse_iext_cursor *cur, struct fuse_iomap_io *gotp)
> +{
> +	fuse_iext_next(ir, cur);
> +	return fuse_iext_get_extent(ir, cur, gotp);
> +}
> +
> +static inline bool fuse_iext_prev_extent(struct fuse_iext_root *ir,
> +		struct fuse_iext_cursor *cur, struct fuse_iomap_io *gotp)
> +{
> +	fuse_iext_prev(ir, cur);
> +	return fuse_iext_get_extent(ir, cur, gotp);
> +}
> +
> +/*
> + * Return the extent after cur in gotp without updating the cursor.
> + */
> +static inline bool fuse_iext_peek_next_extent(struct fuse_iext_root *ir,
> +		struct fuse_iext_cursor *cur, struct fuse_iomap_io *gotp)
> +{
> +	struct fuse_iext_cursor ncur = *cur;
> +
> +	fuse_iext_next(ir, &ncur);
> +	return fuse_iext_get_extent(ir, &ncur, gotp);
> +}
> +
> +/*
> + * Return the extent before cur in gotp without updating the cursor.
> + */
> +static inline bool fuse_iext_peek_prev_extent(struct fuse_iext_root *ir,
> +		struct fuse_iext_cursor *cur, struct fuse_iomap_io *gotp)
> +{
> +	struct fuse_iext_cursor ncur = *cur;
> +
> +	fuse_iext_prev(ir, &ncur);
> +	return fuse_iext_get_extent(ir, &ncur, gotp);
> +}
> +
> +static inline int
> +fuse_iext_key_cmp(
> +	struct fuse_iext_node	*node,
> +	int			n,
> +	loff_t			offset)
> +{
> +	if (node->keys[n] > offset)
> +		return 1;
> +	if (node->keys[n] < offset)
> +		return -1;
> +	return 0;
> +}
> +
> +static inline int
> +fuse_iext_rec_cmp(
> +	struct fuse_iomap_io	*rec,
> +	loff_t			offset)
> +{
> +	if (rec->offset > offset)
> +		return 1;
> +	if (rec->offset + rec->length <= offset)
> +		return -1;
> +	return 0;
> +}
> +
> +static void *
> +fuse_iext_find_level(
> +	struct fuse_iext_root	*ir,
> +	loff_t			offset,
> +	int			level)
> +{
> +	struct fuse_iext_node	*node = ir->ir_data;
> +	int			height, i;
> +
> +	if (!ir->ir_height)
> +		return NULL;
> +
> +	for (height = ir->ir_height; height > level; height--) {
> +		for (i = 1; i < KEYS_PER_NODE; i++)
> +			if (fuse_iext_key_cmp(node, i, offset) > 0)
> +				break;
> +
> +		node = node->ptrs[i - 1];
> +		if (!node)
> +			break;
> +	}
> +
> +	return node;
> +}
> +
> +static int
> +fuse_iext_node_pos(
> +	struct fuse_iext_node	*node,
> +	loff_t			offset)
> +{
> +	int			i;
> +
> +	for (i = 1; i < KEYS_PER_NODE; i++) {
> +		if (fuse_iext_key_cmp(node, i, offset) > 0)
> +			break;
> +	}
> +
> +	return i - 1;
> +}
> +
> +static int
> +fuse_iext_node_insert_pos(
> +	struct fuse_iext_node	*node,
> +	loff_t			offset)
> +{
> +	int			i;
> +
> +	for (i = 0; i < KEYS_PER_NODE; i++) {
> +		if (fuse_iext_key_cmp(node, i, offset) > 0)
> +			return i;
> +	}
> +
> +	return KEYS_PER_NODE;
> +}
> +
> +static int
> +fuse_iext_node_nr_entries(
> +	struct fuse_iext_node	*node,
> +	int			start)
> +{
> +	int			i;
> +
> +	for (i = start; i < KEYS_PER_NODE; i++) {
> +		if (node->keys[i] == FUSE_IEXT_KEY_INVALID)
> +			break;
> +	}
> +
> +	return i;
> +}
> +
> +static int
> +fuse_iext_leaf_nr_entries(
> +	struct fuse_iext_root	*ir,
> +	struct fuse_iext_leaf	*leaf,
> +	int			start)
> +{
> +	int			i;
> +
> +	for (i = start; i < fuse_iext_max_recs(ir); i++) {
> +		if (fuse_iext_rec_is_empty(&leaf->recs[i]))
> +			break;
> +	}
> +
> +	return i;
> +}
> +
> +static inline fuse_iext_key_t
> +fuse_iext_leaf_key(
> +	struct fuse_iext_leaf	*leaf,
> +	int			n)
> +{
> +	return leaf->recs[n].offset;
> +}
> +
> +static inline void *
> +fuse_iext_alloc_node(
> +	int	size)
> +{
> +	return kzalloc(size, GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
> +}
> +
> +static void
> +fuse_iext_grow(
> +	struct fuse_iext_root	*ir)
> +{
> +	struct fuse_iext_node	*node = fuse_iext_alloc_node(NODE_SIZE);
> +	int			i;
> +
> +	if (ir->ir_height == 1) {
> +		struct fuse_iext_leaf *prev = ir->ir_data;
> +
> +		node->keys[0] = fuse_iext_leaf_key(prev, 0);
> +		node->ptrs[0] = prev;
> +	} else  {
> +		struct fuse_iext_node *prev = ir->ir_data;
> +
> +		ASSERT(ir->ir_height > 1);
> +
> +		node->keys[0] = prev->keys[0];
> +		node->ptrs[0] = prev;
> +	}
> +
> +	for (i = 1; i < KEYS_PER_NODE; i++)
> +		node->keys[i] = FUSE_IEXT_KEY_INVALID;
> +
> +	ir->ir_data = node;
> +	ir->ir_height++;
> +}
> +
> +static void
> +fuse_iext_update_node(
> +	struct fuse_iext_root	*ir,
> +	loff_t			old_offset,
> +	loff_t			new_offset,
> +	int			level,
> +	void			*ptr)
> +{
> +	struct fuse_iext_node	*node = ir->ir_data;
> +	int			height, i;
> +
> +	for (height = ir->ir_height; height > level; height--) {
> +		for (i = 0; i < KEYS_PER_NODE; i++) {
> +			if (i > 0 && fuse_iext_key_cmp(node, i, old_offset) > 0)
> +				break;
> +			if (node->keys[i] == old_offset)
> +				node->keys[i] = new_offset;
> +		}
> +		node = node->ptrs[i - 1];
> +		ASSERT(node);
> +	}
> +
> +	ASSERT(node == ptr);
> +}
> +
> +static struct fuse_iext_node *
> +fuse_iext_split_node(
> +	struct fuse_iext_node	**nodep,
> +	int			*pos,
> +	int			*nr_entries)
> +{
> +	struct fuse_iext_node	*node = *nodep;
> +	struct fuse_iext_node	*new = fuse_iext_alloc_node(NODE_SIZE);
> +	const int		nr_move = KEYS_PER_NODE / 2;
> +	int			nr_keep = nr_move + (KEYS_PER_NODE & 1);
> +	int			i = 0;
> +
> +	/* for sequential append operations just spill over into the new node */
> +	if (*pos == KEYS_PER_NODE) {
> +		*nodep = new;
> +		*pos = 0;
> +		*nr_entries = 0;
> +		goto done;
> +	}
> +
> +
> +	for (i = 0; i < nr_move; i++) {
> +		new->keys[i] = node->keys[nr_keep + i];
> +		new->ptrs[i] = node->ptrs[nr_keep + i];
> +
> +		node->keys[nr_keep + i] = FUSE_IEXT_KEY_INVALID;
> +		node->ptrs[nr_keep + i] = NULL;
> +	}
> +
> +	if (*pos >= nr_keep) {
> +		*nodep = new;
> +		*pos -= nr_keep;
> +		*nr_entries = nr_move;
> +	} else {
> +		*nr_entries = nr_keep;
> +	}
> +done:
> +	for (; i < KEYS_PER_NODE; i++)
> +		new->keys[i] = FUSE_IEXT_KEY_INVALID;
> +	return new;
> +}
> +
> +static void
> +fuse_iext_insert_node(
> +	struct fuse_iext_root	*ir,
> +	fuse_iext_key_t		offset,
> +	void			*ptr,
> +	int			level)
> +{
> +	struct fuse_iext_node	*node, *new;
> +	int			i, pos, nr_entries;
> +
> +again:
> +	if (ir->ir_height < level)
> +		fuse_iext_grow(ir);
> +
> +	new = NULL;
> +	node = fuse_iext_find_level(ir, offset, level);
> +	pos = fuse_iext_node_insert_pos(node, offset);
> +	nr_entries = fuse_iext_node_nr_entries(node, pos);
> +
> +	ASSERT(pos >= nr_entries || fuse_iext_key_cmp(node, pos, offset) != 0);
> +	ASSERT(nr_entries <= KEYS_PER_NODE);
> +
> +	if (nr_entries == KEYS_PER_NODE)
> +		new = fuse_iext_split_node(&node, &pos, &nr_entries);
> +
> +	/*
> +	 * Update the pointers in higher levels if the first entry changes
> +	 * in an existing node.
> +	 */
> +	if (node != new && pos == 0 && nr_entries > 0)
> +		fuse_iext_update_node(ir, node->keys[0], offset, level, node);
> +
> +	for (i = nr_entries; i > pos; i--) {
> +		node->keys[i] = node->keys[i - 1];
> +		node->ptrs[i] = node->ptrs[i - 1];
> +	}
> +	node->keys[pos] = offset;
> +	node->ptrs[pos] = ptr;
> +
> +	if (new) {
> +		offset = new->keys[0];
> +		ptr = new;
> +		level++;
> +		goto again;
> +	}
> +}
> +
> +static struct fuse_iext_leaf *
> +fuse_iext_split_leaf(
> +	struct fuse_iext_cursor	*cur,
> +	int			*nr_entries)
> +{
> +	struct fuse_iext_leaf	*leaf = cur->leaf;
> +	struct fuse_iext_leaf	*new = fuse_iext_alloc_node(NODE_SIZE);
> +	const int		nr_move = RECS_PER_LEAF / 2;
> +	int			nr_keep = nr_move + (RECS_PER_LEAF & 1);
> +	int			i;
> +
> +	/* for sequential append operations just spill over into the new node */
> +	if (cur->pos == RECS_PER_LEAF) {
> +		cur->leaf = new;
> +		cur->pos = 0;
> +		*nr_entries = 0;
> +		goto done;
> +	}
> +
> +	for (i = 0; i < nr_move; i++) {
> +		new->recs[i] = leaf->recs[nr_keep + i];
> +		fuse_iext_rec_clear(&leaf->recs[nr_keep + i]);
> +	}
> +
> +	if (cur->pos >= nr_keep) {
> +		cur->leaf = new;
> +		cur->pos -= nr_keep;
> +		*nr_entries = nr_move;
> +	} else {
> +		*nr_entries = nr_keep;
> +	}
> +done:
> +	if (leaf->next)
> +		leaf->next->prev = new;
> +	new->next = leaf->next;
> +	new->prev = leaf;
> +	leaf->next = new;
> +	return new;
> +}
> +
> +static void
> +fuse_iext_alloc_root(
> +	struct fuse_iext_root	*ir,
> +	struct fuse_iext_cursor	*cur)
> +{
> +	ASSERT(ir->ir_bytes == 0);
> +
> +	ir->ir_data = fuse_iext_alloc_node(sizeof(struct fuse_iomap_io));
> +	ir->ir_height = 1;
> +
> +	/* now that we have a node step into it */
> +	cur->leaf = ir->ir_data;
> +	cur->pos = 0;
> +}
> +
> +static void
> +fuse_iext_realloc_root(
> +	struct fuse_iext_root	*ir,
> +	struct fuse_iext_cursor	*cur)
> +{
> +	int64_t new_size = ir->ir_bytes + sizeof(struct fuse_iomap_io);
> +	void *new;
> +
> +	/* account for the prev/next pointers */
> +	if (new_size / sizeof(struct fuse_iomap_io) == RECS_PER_LEAF)
> +		new_size = NODE_SIZE;
> +
> +	new = krealloc(ir->ir_data, new_size,
> +			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
> +	memset(new + ir->ir_bytes, 0, new_size - ir->ir_bytes);
> +	ir->ir_data = new;
> +	cur->leaf = new;
> +}
> +
> +/*
> + * Increment the sequence counter on extent tree changes. We use WRITE_ONCE
> + * here to ensure the update to the sequence counter is seen before the
> + * modifications to the extent tree itself take effect.
> + */
> +static inline void fuse_iext_inc_seq(struct fuse_iomap_cache *ic)
> +{
> +	WRITE_ONCE(ic->ic_seq, READ_ONCE(ic->ic_seq) + 1);
> +}
> +
> +static void
> +fuse_iext_insert_raw(
> +	struct fuse_iomap_cache		*ic,
> +	struct fuse_iext_root		*ir,
> +	struct fuse_iext_cursor		*cur,
> +	const struct fuse_iomap_io	*irec)
> +{
> +	loff_t				offset = irec->offset;
> +	struct fuse_iext_leaf		*new = NULL;
> +	int				nr_entries, i;
> +
> +	fuse_iext_inc_seq(ic);
> +
> +	if (ir->ir_height == 0)
> +		fuse_iext_alloc_root(ir, cur);
> +	else if (ir->ir_height == 1)
> +		fuse_iext_realloc_root(ir, cur);
> +
> +	nr_entries = fuse_iext_leaf_nr_entries(ir, cur->leaf, cur->pos);
> +	ASSERT(nr_entries <= RECS_PER_LEAF);
> +	ASSERT(cur->pos >= nr_entries ||
> +	       fuse_iext_rec_cmp(cur_rec(cur), irec->offset) != 0);
> +
> +	if (nr_entries == RECS_PER_LEAF)
> +		new = fuse_iext_split_leaf(cur, &nr_entries);
> +
> +	/*
> +	 * Update the pointers in higher levels if the first entry changes
> +	 * in an existing node.
> +	 */
> +	if (cur->leaf != new && cur->pos == 0 && nr_entries > 0) {
> +		fuse_iext_update_node(ir, fuse_iext_leaf_key(cur->leaf, 0),
> +				offset, 1, cur->leaf);
> +	}
> +
> +	for (i = nr_entries; i > cur->pos; i--)
> +		cur->leaf->recs[i] = cur->leaf->recs[i - 1];
> +	fuse_iext_set(cur_rec(cur), irec);
> +	ir->ir_bytes += sizeof(struct fuse_iomap_io);
> +
> +	if (new)
> +		fuse_iext_insert_node(ir, fuse_iext_leaf_key(new, 0), new, 2);
> +}
> +
> +static void
> +fuse_iext_insert(
> +	struct fuse_iomap_cache		*ic,
> +	struct fuse_iext_cursor		*cur,
> +	const struct fuse_iomap_io	*irec,
> +	uint32_t			state)
> +{
> +	struct fuse_iext_root		*ir = fuse_iext_state_to_fork(ic, state);
> +
> +	fuse_iext_insert_raw(ic, ir, cur, irec);
> +}
> +
> +static struct fuse_iext_node *
> +fuse_iext_rebalance_node(
> +	struct fuse_iext_node	*parent,
> +	int			*pos,
> +	struct fuse_iext_node	*node,
> +	int			nr_entries)
> +{
> +	/*
> +	 * If the neighbouring nodes are completely full, or have different
> +	 * parents, we might never be able to merge our node, and will only
> +	 * delete it once the number of entries hits zero.
> +	 */
> +	if (nr_entries == 0)
> +		return node;
> +
> +	if (*pos > 0) {
> +		struct fuse_iext_node *prev = parent->ptrs[*pos - 1];
> +		int nr_prev = fuse_iext_node_nr_entries(prev, 0), i;
> +
> +		if (nr_prev + nr_entries <= KEYS_PER_NODE) {
> +			for (i = 0; i < nr_entries; i++) {
> +				prev->keys[nr_prev + i] = node->keys[i];
> +				prev->ptrs[nr_prev + i] = node->ptrs[i];
> +			}
> +			return node;
> +		}
> +	}
> +
> +	if (*pos + 1 < fuse_iext_node_nr_entries(parent, *pos)) {
> +		struct fuse_iext_node *next = parent->ptrs[*pos + 1];
> +		int nr_next = fuse_iext_node_nr_entries(next, 0), i;
> +
> +		if (nr_entries + nr_next <= KEYS_PER_NODE) {
> +			/*
> +			 * Merge the next node into this node so that we don't
> +			 * have to do an additional update of the keys in the
> +			 * higher levels.
> +			 */
> +			for (i = 0; i < nr_next; i++) {
> +				node->keys[nr_entries + i] = next->keys[i];
> +				node->ptrs[nr_entries + i] = next->ptrs[i];
> +			}
> +
> +			++*pos;
> +			return next;
> +		}
> +	}
> +
> +	return NULL;
> +}
> +
> +static void
> +fuse_iext_remove_node(
> +	struct fuse_iext_root	*ir,
> +	loff_t			offset,
> +	void			*victim)
> +{
> +	struct fuse_iext_node	*node, *parent;
> +	int			level = 2, pos, nr_entries, i;
> +
> +	ASSERT(level <= ir->ir_height);
> +	node = fuse_iext_find_level(ir, offset, level);
> +	pos = fuse_iext_node_pos(node, offset);
> +again:
> +	ASSERT(node->ptrs[pos]);
> +	ASSERT(node->ptrs[pos] == victim);
> +	kfree(victim);
> +
> +	nr_entries = fuse_iext_node_nr_entries(node, pos) - 1;
> +	offset = node->keys[0];
> +	for (i = pos; i < nr_entries; i++) {
> +		node->keys[i] = node->keys[i + 1];
> +		node->ptrs[i] = node->ptrs[i + 1];
> +	}
> +	node->keys[nr_entries] = FUSE_IEXT_KEY_INVALID;
> +	node->ptrs[nr_entries] = NULL;
> +
> +	if (pos == 0 && nr_entries > 0) {
> +		fuse_iext_update_node(ir, offset, node->keys[0], level, node);
> +		offset = node->keys[0];
> +	}
> +
> +	if (nr_entries >= KEYS_PER_NODE / 2)
> +		return;
> +
> +	if (level < ir->ir_height) {
> +		/*
> +		 * If we aren't at the root yet try to find a neighbour node to
> +		 * merge with (or delete the node if it is empty), and then
> +		 * recurse up to the next level.
> +		 */
> +		level++;
> +		parent = fuse_iext_find_level(ir, offset, level);
> +		pos = fuse_iext_node_pos(parent, offset);
> +
> +		ASSERT(pos != KEYS_PER_NODE);
> +		ASSERT(parent->ptrs[pos] == node);
> +
> +		node = fuse_iext_rebalance_node(parent, &pos, node, nr_entries);
> +		if (node) {
> +			victim = node;
> +			node = parent;
> +			goto again;
> +		}
> +	} else if (nr_entries == 1) {
> +		/*
> +		 * If we are at the root and only one entry is left we can just
> +		 * free this node and update the root pointer.
> +		 */
> +		ASSERT(node == ir->ir_data);
> +		ir->ir_data = node->ptrs[0];
> +		ir->ir_height--;
> +		kfree(node);
> +	}
> +}
> +
> +static void
> +fuse_iext_rebalance_leaf(
> +	struct fuse_iext_root	*ir,
> +	struct fuse_iext_cursor	*cur,
> +	struct fuse_iext_leaf	*leaf,
> +	loff_t			offset,
> +	int			nr_entries)
> +{
> +	/*
> +	 * If the neighbouring nodes are completely full we might never be able
> +	 * to merge our node, and will only delete it once the number of
> +	 * entries hits zero.
> +	 */
> +	if (nr_entries == 0)
> +		goto remove_node;
> +
> +	if (leaf->prev) {
> +		int nr_prev = fuse_iext_leaf_nr_entries(ir, leaf->prev, 0), i;
> +
> +		if (nr_prev + nr_entries <= RECS_PER_LEAF) {
> +			for (i = 0; i < nr_entries; i++)
> +				leaf->prev->recs[nr_prev + i] = leaf->recs[i];
> +
> +			if (cur->leaf == leaf) {
> +				cur->leaf = leaf->prev;
> +				cur->pos += nr_prev;
> +			}
> +			goto remove_node;
> +		}
> +	}
> +
> +	if (leaf->next) {
> +		int nr_next = fuse_iext_leaf_nr_entries(ir, leaf->next, 0), i;
> +
> +		if (nr_entries + nr_next <= RECS_PER_LEAF) {
> +			/*
> +			 * Merge the next node into this node so that we don't
> +			 * have to do an additional update of the keys in the
> +			 * higher levels.
> +			 */
> +			for (i = 0; i < nr_next; i++) {
> +				leaf->recs[nr_entries + i] =
> +					leaf->next->recs[i];
> +			}
> +
> +			if (cur->leaf == leaf->next) {
> +				cur->leaf = leaf;
> +				cur->pos += nr_entries;
> +			}
> +
> +			offset = fuse_iext_leaf_key(leaf->next, 0);
> +			leaf = leaf->next;
> +			goto remove_node;
> +		}
> +	}
> +
> +	return;
> +remove_node:
> +	if (leaf->prev)
> +		leaf->prev->next = leaf->next;
> +	if (leaf->next)
> +		leaf->next->prev = leaf->prev;
> +	fuse_iext_remove_node(ir, offset, leaf);
> +}
> +
> +static void
> +fuse_iext_free_last_leaf(
> +	struct fuse_iext_root	*ir)
> +{
> +	ir->ir_height--;
> +	kfree(ir->ir_data);
> +	ir->ir_data = NULL;
> +}
> +
> +static void
> +fuse_iext_remove(
> +	struct fuse_iomap_cache	*ic,
> +	struct fuse_iext_cursor	*cur,
> +	uint32_t		state)
> +{
> +	struct fuse_iext_root	*ir = fuse_iext_state_to_fork(ic, state);
> +	struct fuse_iext_leaf	*leaf = cur->leaf;
> +	loff_t			offset = fuse_iext_leaf_key(leaf, 0);
> +	int			i, nr_entries;
> +
> +	ASSERT(ir->ir_height > 0);
> +	ASSERT(ir->ir_data != NULL);
> +	ASSERT(fuse_iext_valid(ir, cur));
> +
> +	fuse_iext_inc_seq(ic);
> +
> +	nr_entries = fuse_iext_leaf_nr_entries(ir, leaf, cur->pos) - 1;
> +	for (i = cur->pos; i < nr_entries; i++)
> +		leaf->recs[i] = leaf->recs[i + 1];
> +	fuse_iext_rec_clear(&leaf->recs[nr_entries]);
> +	ir->ir_bytes -= sizeof(struct fuse_iomap_io);
> +
> +	if (cur->pos == 0 && nr_entries > 0) {
> +		fuse_iext_update_node(ir, offset, fuse_iext_leaf_key(leaf, 0), 1,
> +				leaf);
> +		offset = fuse_iext_leaf_key(leaf, 0);
> +	} else if (cur->pos == nr_entries) {
> +		if (ir->ir_height > 1 && leaf->next)
> +			cur->leaf = leaf->next;
> +		else
> +			cur->leaf = NULL;
> +		cur->pos = 0;
> +	}
> +
> +	if (nr_entries >= RECS_PER_LEAF / 2)
> +		return;
> +
> +	if (ir->ir_height > 1)
> +		fuse_iext_rebalance_leaf(ir, cur, leaf, offset, nr_entries);
> +	else if (nr_entries == 0)
> +		fuse_iext_free_last_leaf(ir);
> +}
> +
> +/*
> + * Lookup the extent covering offset.
> + *
> + * If there is an extent covering offset return the extent index, and store the
> + * expanded extent structure in *gotp, and the extent cursor in *cur.
> + * If there is no extent covering offset, but there is an extent after it (e.g.
> + * it lies in a hole) return that extent in *gotp and its cursor in *cur
> + * instead.
> + * If offset is beyond the last extent return false, and return an invalid
> + * cursor value.
> + */
> +static bool
> +fuse_iext_lookup_extent(
> +	struct fuse_iomap_cache	*ic,
> +	struct fuse_iext_root	*ir,
> +	loff_t			offset,
> +	struct fuse_iext_cursor	*cur,
> +	struct fuse_iomap_io	*gotp)
> +{
> +	cur->leaf = fuse_iext_find_level(ir, offset, 1);
> +	if (!cur->leaf) {
> +		cur->pos = 0;
> +		return false;
> +	}
> +
> +	for (cur->pos = 0; cur->pos < fuse_iext_max_recs(ir); cur->pos++) {
> +		struct fuse_iomap_io *rec = cur_rec(cur);
> +
> +		if (fuse_iext_rec_is_empty(rec))
> +			break;
> +		if (fuse_iext_rec_cmp(rec, offset) >= 0)
> +			goto found;
> +	}
> +
> +	/* Try looking in the next node for an entry > offset */
> +	if (ir->ir_height == 1 || !cur->leaf->next)
> +		return false;
> +	cur->leaf = cur->leaf->next;
> +	cur->pos = 0;
> +	if (!fuse_iext_valid(ir, cur))
> +		return false;
> +found:
> +	fuse_iext_get(gotp, cur_rec(cur));
> +	return true;
> +}
> +
> +/*
> + * Returns the last extent before end, and if this extent doesn't cover
> + * end, update end to the end of the extent.
> + */
> +static bool
> +fuse_iext_lookup_extent_before(
> +	struct fuse_iomap_cache	*ic,
> +	struct fuse_iext_root	*ir,
> +	loff_t			*end,
> +	struct fuse_iext_cursor	*cur,
> +	struct fuse_iomap_io	*gotp)
> +{
> +	/* could be optimized to not even look up the next on a match.. */
> +	if (fuse_iext_lookup_extent(ic, ir, *end - 1, cur, gotp) &&
> +	    gotp->offset <= *end - 1)
> +		return true;
> +	if (!fuse_iext_prev_extent(ir, cur, gotp))
> +		return false;
> +	*end = gotp->offset + gotp->length;
> +	return true;
> +}
> +
> +static void
> +fuse_iext_update_extent(
> +	struct fuse_iomap_cache	*ic,
> +	uint32_t		state,
> +	struct fuse_iext_cursor	*cur,
> +	struct fuse_iomap_io	*new)
> +{
> +	struct fuse_iext_root	*ir = fuse_iext_state_to_fork(ic, state);
> +
> +	fuse_iext_inc_seq(ic);
> +
> +	if (cur->pos == 0) {
> +		struct fuse_iomap_io	old;
> +
> +		fuse_iext_get(&old, cur_rec(cur));
> +		if (new->offset != old.offset) {
> +			fuse_iext_update_node(ir, old.offset,
> +					new->offset, 1, cur->leaf);
> +		}
> +	}
> +
> +	fuse_iext_set(cur_rec(cur), new);
> +}
> +
> +/*
> + * This is a recursive function, because of that we need to be extremely
> + * careful with stack usage.
> + */
> +static void
> +fuse_iext_destroy_node(
> +	struct fuse_iext_node	*node,
> +	int			level)
> +{
> +	int			i;
> +
> +	if (level > 1) {
> +		for (i = 0; i < KEYS_PER_NODE; i++) {
> +			if (node->keys[i] == FUSE_IEXT_KEY_INVALID)
> +				break;
> +			fuse_iext_destroy_node(node->ptrs[i], level - 1);
> +		}
> +	}
> +
> +	kfree(node);
> +}
> +
> +static void
> +fuse_iext_destroy(
> +	struct fuse_iext_root	*ir)
> +{
> +	fuse_iext_destroy_node(ir->ir_data, ir->ir_height);
> +
> +	ir->ir_bytes = 0;
> +	ir->ir_height = 0;
> +	ir->ir_data = NULL;
> +}
> +
> +static inline struct fuse_iext_root *
> +fuse_iext_root_ptr(
> +	struct fuse_iomap_cache	*ic,
> +	enum fuse_iomap_iodir	iodir)
> +{
> +	switch (iodir) {
> +	case READ_MAPPING:
> +		return &ic->ic_read;
> +	case WRITE_MAPPING:
> +		return &ic->ic_write;
> +	default:
> +		ASSERT(0);
> +		return NULL;
> +	}
> +}
> +
> +static inline bool fuse_iomap_addrs_adjacent(const struct fuse_iomap_io *left,
> +					     const struct fuse_iomap_io *right)
> +{
> +	switch (left->type) {
> +	case FUSE_IOMAP_TYPE_MAPPED:
> +	case FUSE_IOMAP_TYPE_UNWRITTEN:
> +		return left->addr + left->length == right->addr;
> +	default:
> +		return left->addr  == FUSE_IOMAP_NULL_ADDR &&
> +		       right->addr == FUSE_IOMAP_NULL_ADDR;
> +	}
> +}
> +
> +static inline bool fuse_iomap_can_merge(const struct fuse_iomap_io *left,
> +					const struct fuse_iomap_io *right)
> +{
> +	return (left->dev == right->dev &&
> +		left->offset + left->length == right->offset &&
> +		left->type  == right->type &&
> +		fuse_iomap_addrs_adjacent(left, right) &&
> +		left->flags == right->flags &&
> +		left->length + right->length <= FUSE_IOMAP_MAX_LEN);
> +}
> +
> +static inline bool fuse_iomap_can_merge3(const struct fuse_iomap_io *left,
> +					 const struct fuse_iomap_io *new,
> +					 const struct fuse_iomap_io *right)
> +{
> +	return left->length + new->length + right->length <= FUSE_IOMAP_MAX_LEN;
> +}
> +
> +#if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG)
> +static void fuse_iext_check_mappings(struct fuse_iomap_cache *ic,
> +				     struct fuse_iext_root *ir)
> +{
> +	struct fuse_iext_cursor	icur;
> +	struct fuse_iomap_io	prev, got;
> +	struct inode		*inode = ic->ic_inode;
> +	struct fuse_inode	*fi = get_fuse_inode(inode);
> +	unsigned long long	nr = 0;
> +
> +	if (ir->ir_bytes < 0 || !static_branch_unlikely(&fuse_iomap_debug))
> +		return;
> +
> +	fuse_iext_first(ir, &icur);
> +	if (!fuse_iext_get_extent(ir, &icur, &prev))
> +		return;
> +	nr++;
> +
> +	fuse_iext_next(ir, &icur);
> +	while (fuse_iext_get_extent(ir, &icur, &got)) {
> +		if (got.length == 0 ||
> +		    got.offset < prev.offset + prev.length ||
> +		    fuse_iomap_can_merge(&prev, &got)) {
> +			printk(KERN_ERR "FUSE IOMAP CORRUPTION ino=%llu nr=%llu",
> +			       fi->orig_ino, nr);
> +			printk(KERN_ERR "prev: offset=%llu length=%llu type=%u flags=0x%x dev=%u addr=%llu\n",
> +			       prev.offset, prev.length, prev.type, prev.flags,
> +			       prev.dev, prev.addr);
> +			printk(KERN_ERR "curr: offset=%llu length=%llu type=%u flags=0x%x dev=%u addr=%llu\n",
> +			       got.offset, got.length, got.type, got.flags,
> +			       got.dev, got.addr);
> +		}
> +
> +		prev = got;
> +		nr++;
> +		fuse_iext_next(ir, &icur);
> +	}
> +}
> +#else
> +# define fuse_iext_check_mappings(...)	((void)0)
> +#endif
> +
> +static void
> +fuse_iext_del_mapping(
> +	struct fuse_iomap_cache	*ic,
> +	struct fuse_iext_root	*ir,
> +	struct fuse_iext_cursor	*icur,
> +	struct fuse_iomap_io	*got,	/* current extent entry */
> +	struct fuse_iomap_io	*del)	/* data to remove from extents */
> +{
> +	struct fuse_iomap_io	new;	/* new record to be inserted */
> +	/* first addr (fsblock aligned) past del */
> +	fuse_iext_key_t		del_endaddr;
> +	/* first offset (fsblock aligned) past del */
> +	fuse_iext_key_t		del_endoff = del->offset + del->length;
> +	/* first offset (fsblock aligned) past got */
> +	fuse_iext_key_t		got_endoff = got->offset + got->length;
> +	uint32_t		state = fuse_iomap_fork_to_state(ic, ir);
> +
> +	ASSERT(del->length > 0);
> +	ASSERT(got->offset <= del->offset);
> +	ASSERT(got_endoff >= del_endoff);
> +
> +	switch (del->type) {
> +	case FUSE_IOMAP_TYPE_MAPPED:
> +	case FUSE_IOMAP_TYPE_UNWRITTEN:
> +		del_endaddr = del->addr + del->length;
> +		break;
> +	default:
> +		del_endaddr = FUSE_IOMAP_NULL_ADDR;
> +		break;
> +	}
> +
> +	if (got->offset == del->offset)
> +		state |= FUSE_IEXT_LEFT_FILLING;
> +	if (got_endoff == del_endoff)
> +		state |= FUSE_IEXT_RIGHT_FILLING;
> +
> +	switch (state & (FUSE_IEXT_LEFT_FILLING | FUSE_IEXT_RIGHT_FILLING)) {
> +	case FUSE_IEXT_LEFT_FILLING | FUSE_IEXT_RIGHT_FILLING:
> +		/*
> +		 * Matches the whole extent.  Delete the entry.
> +		 */
> +		fuse_iext_remove(ic, icur, state);
> +		fuse_iext_prev(ir, icur);
> +		break;
> +	case FUSE_IEXT_LEFT_FILLING:
> +		/*
> +		 * Deleting the first part of the extent.
> +		 */
> +		got->offset = del_endoff;
> +		got->addr = del_endaddr;
> +		got->length -= del->length;
> +		fuse_iext_update_extent(ic, state, icur, got);
> +		break;
> +	case FUSE_IEXT_RIGHT_FILLING:
> +		/*
> +		 * Deleting the last part of the extent.
> +		 */
> +		got->length -= del->length;
> +		fuse_iext_update_extent(ic, state, icur, got);
> +		break;
> +	case 0:
> +		/*
> +		 * Deleting the middle of the extent.
> +		 */
> +		got->length = del->offset - got->offset;
> +		fuse_iext_update_extent(ic, state, icur, got);
> +
> +		new.offset = del_endoff;
> +		new.length = got_endoff - del_endoff;
> +		new.type = got->type;
> +		new.flags = got->flags;
> +		new.addr = del_endaddr;
> +		new.dev = got->dev;
> +
> +		fuse_iext_next(ir, icur);
> +		fuse_iext_insert(ic, icur, &new, state);
> +		break;
> +	}
> +}
> +
> +int
> +fuse_iomap_cache_remove(
> +	struct inode		*inode,
> +	enum fuse_iomap_iodir	iodir,
> +	loff_t			start,		/* first file offset deleted */
> +	uint64_t		len)		/* length to unmap */
> +{
> +	struct fuse_iext_cursor	icur;
> +	struct fuse_iomap_io	got;		/* current extent record */
> +	struct fuse_iomap_io	del;		/* extent being deleted */
> +	loff_t			end;
> +	struct fuse_inode	*fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache	*ic = fi->cache;
> +	struct fuse_iext_root	*ir = fuse_iext_root_ptr(ic, iodir);
> +	bool			wasreal;
> +	bool			done = false;
> +	int			ret = 0;
> +
> +	assert_cache_locked(ic);
> +
> +	/* Fork is not active or has zero mappings */
> +	if (ir->ir_bytes < 0 || fuse_iext_count(ir) == 0)
> +		return 0;
> +
> +	/* Fast shortcut if the caller wants to erase everything */
> +	if (start == 0 && len >= inode->i_sb->s_maxbytes) {
> +		fuse_iext_destroy(ir);
> +		return 0;
> +	}
> +
> +	if (!len)
> +		goto out;
> +
> +	/*
> +	 * If the caller wants us to remove everything to EOF, we set the end
> +	 * of the removal range to the maximum file offset.  We don't support
> +	 * unsigned file offsets.
> +	 */
> +	if (len == FUSE_IOMAP_INVAL_TO_EOF) {
> +		const unsigned int blocksize = i_blocksize(&fi->inode);
> +
> +		len = round_up(inode->i_sb->s_maxbytes, blocksize) - start;
> +	}
> +
> +	/*
> +	 * Now that we've settled len, look up the extent before the end of the
> +	 * range.
> +	 */
> +	end = start + len;
> +	if (!fuse_iext_lookup_extent_before(ic, ir, &end, &icur, &got))
> +		goto out;
> +	end--;
> +
> +	while (end != -1 && end >= start) {
> +		/*
> +		 * Is the found extent after a hole in which end lives?
> +		 * Just back up to the previous extent, if so.
> +		 */
> +		if (got.offset > end &&
> +		    !fuse_iext_prev_extent(ir, &icur, &got)) {
> +			done = true;
> +			break;
> +		}
> +		/*
> +		 * Is the last block of this extent before the range
> +		 * we're supposed to delete?  If so, we're done.
> +		 */
> +		end = min_t(loff_t, end, got.offset + got.length - 1);
> +		if (end < start)
> +			break;
> +		/*
> +		 * Then deal with the (possibly delayed) allocated space
> +		 * we found.
> +		 */
> +		del = got;
> +		switch (del.type) {
> +		case FUSE_IOMAP_TYPE_DELALLOC:
> +		case FUSE_IOMAP_TYPE_HOLE:
> +		case FUSE_IOMAP_TYPE_INLINE:
> +		case FUSE_IOMAP_TYPE_PURE_OVERWRITE:
> +			wasreal = false;
> +			break;
> +		case FUSE_IOMAP_TYPE_MAPPED:
> +		case FUSE_IOMAP_TYPE_UNWRITTEN:
> +			wasreal = true;
> +			break;
> +		default:
> +			ASSERT(0);
> +			ret = -EFSCORRUPTED;
> +			goto out;
> +		}
> +
> +		if (got.offset < start) {
> +			del.offset = start;
> +			del.length -= start - got.offset;
> +			if (wasreal)
> +				del.addr += start - got.offset;
> +		}
> +		if (del.offset + del.length > end + 1)
> +			del.length = end + 1 - del.offset;
> +
> +		fuse_iext_del_mapping(ic, ir, &icur, &got, &del);
> +		end = del.offset - 1;
> +
> +		/*
> +		 * If not done go on to the next (previous) record.
> +		 */
> +		if (end != -1 && end >= start) {
> +			if (!fuse_iext_get_extent(ir, &icur, &got) ||
> +			    (got.offset > end &&
> +			     !fuse_iext_prev_extent(ir, &icur, &got))) {
> +				done = true;
> +				break;
> +			}
> +		}
> +	}
> +
> +	/* Should have removed everything */
> +	if (len == 0 || done || end == (loff_t)-1 || end < start)
> +		ret = 0;
> +	else
> +		ret = -EFSCORRUPTED;
> +
> +out:
> +	fuse_iext_check_mappings(ic, ir);
> +	return ret;
> +}
> +
> +static void
> +fuse_iext_add_mapping(
> +	struct fuse_iomap_cache		*ic,
> +	struct fuse_iext_root		*ir,
> +	struct fuse_iext_cursor		*icur,
> +	const struct fuse_iomap_io	*new)	/* new extent entry */
> +{
> +	struct fuse_iomap_io		left;	/* left neighbor extent entry */
> +	struct fuse_iomap_io		right;	/* right neighbor extent entry */
> +	uint32_t			state = fuse_iomap_fork_to_state(ic, ir);
> +
> +	/*
> +	 * Check and set flags if this segment has a left neighbor.
> +	 */
> +	if (fuse_iext_peek_prev_extent(ir, icur, &left))
> +		state |= FUSE_IEXT_LEFT_VALID;
> +
> +	/*
> +	 * Check and set flags if this segment has a current value.
> +	 * Not true if we're inserting into the "hole" at eof.
> +	 */
> +	if (fuse_iext_get_extent(ir, icur, &right))
> +		state |= FUSE_IEXT_RIGHT_VALID;
> +
> +	/*
> +	 * We're inserting a real allocation between "left" and "right".
> +	 * Set the contiguity flags.  Don't let extents get too large.
> +	 */
> +	if ((state & FUSE_IEXT_LEFT_VALID) && fuse_iomap_can_merge(&left, new))
> +		state |= FUSE_IEXT_LEFT_CONTIG;
> +
> +	if ((state & FUSE_IEXT_RIGHT_VALID) &&
> +	    fuse_iomap_can_merge(new, &right) &&
> +	    (!(state & FUSE_IEXT_LEFT_CONTIG) ||
> +	     fuse_iomap_can_merge3(&left, new, &right)))
> +		state |= FUSE_IEXT_RIGHT_CONTIG;
> +
> +	/*
> +	 * Select which case we're in here, and implement it.
> +	 */
> +	switch (state & (FUSE_IEXT_LEFT_CONTIG | FUSE_IEXT_RIGHT_CONTIG)) {
> +	case FUSE_IEXT_LEFT_CONTIG | FUSE_IEXT_RIGHT_CONTIG:
> +		/*
> +		 * New allocation is contiguous with real allocations on the
> +		 * left and on the right.
> +		 * Merge all three into a single extent record.
> +		 */
> +		left.length += new->length + right.length;
> +
> +		fuse_iext_remove(ic, icur, state);
> +		fuse_iext_prev(ir, icur);
> +		fuse_iext_update_extent(ic, state, icur, &left);
> +		break;
> +
> +	case FUSE_IEXT_LEFT_CONTIG:
> +		/*
> +		 * New allocation is contiguous with a real allocation
> +		 * on the left.
> +		 * Merge the new allocation with the left neighbor.
> +		 */
> +		left.length += new->length;
> +
> +		fuse_iext_prev(ir, icur);
> +		fuse_iext_update_extent(ic, state, icur, &left);
> +		break;
> +
> +	case FUSE_IEXT_RIGHT_CONTIG:
> +		/*
> +		 * New allocation is contiguous with a real allocation
> +		 * on the right.
> +		 * Merge the new allocation with the right neighbor.
> +		 */
> +		right.offset = new->offset;
> +		right.addr = new->addr;
> +		right.length += new->length;
> +		fuse_iext_update_extent(ic, state, icur, &right);
> +		break;
> +
> +	case 0:
> +		/*
> +		 * New allocation is not contiguous with another
> +		 * real allocation.
> +		 * Insert a new entry.
> +		 */
> +		fuse_iext_insert(ic, icur, new, state);
> +		break;
> +	}
> +}
> +
> +static int
> +fuse_iomap_cache_add(
> +	struct inode			*inode,
> +	enum fuse_iomap_iodir		iodir,
> +	const struct fuse_iomap_io	*new)
> +{
> +	struct fuse_iext_cursor		icur;
> +	struct fuse_iomap_io		got;
> +	struct fuse_inode		*fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache		*ic = fi->cache;
> +	struct fuse_iext_root		*ir = fuse_iext_root_ptr(ic, iodir);
> +
> +	assert_cache_locked(ic);
> +	ASSERT(new->length > 0);
> +	ASSERT(new->offset < inode->i_sb->s_maxbytes);
> +
> +	/* Mark this fork as being in use */
> +	if (ir->ir_bytes < 0)
> +		ir->ir_bytes = 0;
> +
> +	if (fuse_iext_lookup_extent(ic, ir, new->offset, &icur, &got)) {
> +		/* make sure we only add into a hole. */
> +		ASSERT(got.offset > new->offset);
> +		ASSERT(got.offset - new->offset >= new->length);
> +
> +		if (got.offset <= new->offset ||
> +		    got.offset - new->offset < new->length)
> +			return -EFSCORRUPTED;
> +	}
> +
> +	fuse_iext_add_mapping(ic, ir, &icur, new);
> +	fuse_iext_check_mappings(ic, ir);
> +	return 0;
> +}
> +
> +int fuse_iomap_cache_alloc(struct inode *inode)
> +{
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache *old = NULL;
> +	struct fuse_iomap_cache *ic;
> +
> +	ic = kzalloc_obj(struct fuse_iomap_cache);
> +	if (!ic)
> +		return -ENOMEM;
> +
> +	/* Only the write mapping cache can return NOFORK */
> +	ic->ic_write.ir_bytes = -1;
> +	ic->ic_inode = inode;
> +	init_rwsem(&ic->ic_lock);
> +
> +	if (!try_cmpxchg(&fi->cache, &old, ic)) {
> +		/* Someone created mapping cache before us? Free ours... */
> +		kfree(ic);
> +	}
> +
> +	return 0;
> +}
> +
> +static void fuse_iomap_cache_purge(struct fuse_iomap_cache *ic)
> +{
> +	fuse_iext_destroy(&ic->ic_read);
> +	fuse_iext_destroy(&ic->ic_write);
> +}
> +
> +void fuse_iomap_cache_free(struct inode *inode)
> +{
> +	struct fuse_inode *fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache *ic = fi->cache;
> +
> +	/*
> +	 * This is only called from eviction, so we cannot be racing to set or
> +	 * clear the pointer.
> +	 */
> +	fi->cache = NULL;
> +
> +	fuse_iomap_cache_purge(ic);
> +	kfree(ic);
> +}
> +
> +int
> +fuse_iomap_cache_upsert(
> +	struct inode			*inode,
> +	enum fuse_iomap_iodir		iodir,
> +	const struct fuse_iomap_io	*map)
> +{
> +	struct fuse_inode		*fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache		*ic = fi->cache;
> +	int				err;
> +
> +	ASSERT(fuse_inode_caches_iomaps(inode));
> +
> +	/*
> +	 * We interpret no write fork to mean that all writes are pure
> +	 * overwrites.  Avoid wasting memory if we're trying to upsert a
> +	 * pure overwrite.
> +	 */
> +	if (iodir == WRITE_MAPPING &&
> +	    map->type == FUSE_IOMAP_TYPE_PURE_OVERWRITE &&
> +	    ic->ic_write.ir_bytes < 0)
> +		return 0;
> +
> +	err = fuse_iomap_cache_remove(inode, iodir, map->offset, map->length);
> +	if (err)
> +		return err;
> +
> +	return fuse_iomap_cache_add(inode, iodir, map);
> +}
> +
> +/*
> + * Trim the returned map to the required bounds
> + */
> +static void
> +fuse_iomap_trim(
> +	struct fuse_inode		*fi,
> +	struct fuse_iomap_lookup	*mval,
> +	const struct fuse_iomap_io	*got,
> +	loff_t				off,
> +	loff_t				len)
> +{
> +	struct fuse_iomap_cache		*ic = fi->cache;
> +	const unsigned int blocksize = i_blocksize(&fi->inode);
> +	const loff_t aligned_off = round_down(off, blocksize);
> +	const loff_t aligned_end = round_up(off + len, blocksize);
> +	const loff_t aligned_len = aligned_end - aligned_off;

This realignment logic is no longer necessary because now we require
that all cached mappings are aligned to the blocksize...

> +
> +	ASSERT(aligned_off >= got->offset);
> +
> +	switch (got->type) {
> +	case FUSE_IOMAP_TYPE_MAPPED:
> +	case FUSE_IOMAP_TYPE_UNWRITTEN:
> +		mval->map.addr = got->addr + (aligned_off - got->offset);
> +		break;
> +	default:
> +		mval->map.addr = FUSE_IOMAP_NULL_ADDR;
> +		break;
> +	}
> +	mval->map.offset = aligned_off;
> +	mval->map.length = min_t(loff_t, aligned_len,
> +				 got->length - (aligned_off - got->offset));

...and this logic here has a bug where we can accidentally extend
mappings if off+len is far beyond the end of @got.  In the end we can
more or less copy got to mval->map, set addr appropriately for the iomap
type, and sample the validity cookie.

--D

> +	mval->map.type = got->type;
> +	mval->map.flags = got->flags;
> +	mval->map.dev = got->dev;
> +	mval->validity_cookie = fuse_iext_read_seq(ic);
> +}
> +
> +enum fuse_iomap_lookup_result
> +fuse_iomap_cache_lookup(
> +	struct inode			*inode,
> +	enum fuse_iomap_iodir		iodir,
> +	loff_t				off,
> +	uint64_t			len,
> +	struct fuse_iomap_lookup	*mval)
> +{
> +	struct fuse_iomap_io		got;
> +	struct fuse_iext_cursor		icur;
> +	struct fuse_inode		*fi = get_fuse_inode(inode);
> +	struct fuse_iomap_cache		*ic = fi->cache;
> +	struct fuse_iext_root		*ir = fuse_iext_root_ptr(ic, iodir);
> +
> +	assert_cache_locked_shared(ic);
> +
> +	if (ir->ir_bytes < 0) {
> +		/*
> +		 * No write fork at all means this filesystem doesn't do out of
> +		 * place writes.
> +		 */
> +		return LOOKUP_NOFORK;
> +	}
> +
> +	if (!fuse_iext_lookup_extent(ic, ir, off, &icur, &got)) {
> +		/*
> +		 * Does not contain a mapping at or beyond off, which is a
> +		 * cache miss.
> +		 */
> +		return LOOKUP_MISS;
> +	}
> +
> +	if (got.offset > off) {
> +		/*
> +		 * Found a mapping, but it doesn't cover the start of the
> +		 * range, which is effectively a miss.
> +		 */
> +		return LOOKUP_MISS;
> +	}
> +
> +	/* Found a mapping in the cache, return it */
> +	fuse_iomap_trim(fi, mval, &got, off, len);
> +	return LOOKUP_HIT;
> +}
> diff --git a/fs/fuse/trace.c b/fs/fuse/trace.c
> index 71d444ac1e5021..69310d6f773ffa 100644
> --- a/fs/fuse/trace.c
> +++ b/fs/fuse/trace.c
> @@ -8,6 +8,7 @@
>  #include "fuse_dev_i.h"
>  #include "fuse_iomap.h"
>  #include "fuse_iomap_i.h"
> +#include "fuse_iomap_cache.h"
>  
>  #include <linux/pagemap.h>
>  #include <linux/iomap.h>
> 
> 

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
                   ` (22 preceding siblings ...)
  2026-02-23 23:06 ` [PATCHSET RFC 8/8] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
@ 2026-03-16 17:56 ` Joanne Koong
  2026-03-16 18:04   ` Darrick J. Wong
  23 siblings, 1 reply; 234+ messages in thread
From: Joanne Koong @ 2026-03-16 17:56 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: linux-fsdevel, bpf, linux-ext4, Miklos Szeredi, Bernd Schubert,
	Theodore Ts'o, Neal Gompa, Amir Goldstein, Christian Brauner,
	Jeff Layton, John, demiobenour

On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
>
> There are some warts remaining:
>
> a. I would like to continue the discussion about how the design review
>    of this code should be structured, and how might I go about creating
>    new userspace filesystem servers -- lightweight new ones based off
>    the existing userspace tools?  Or by merging lklfuse?

What do you mean by "merging lklfuse"?

Could you explain what the limitations of lklfuse are compared to the
fuse iomap approach in this patchset?

Thanks,
Joanne

>
> b. ext4 doesn't support out of place writes so I don't know if that
>    actually works correctly.
>
> c. fuse2fs doesn't support the ext4 journal.  Urk.
>
> d. There's a VERY large quantity of fuse2fs improvements that need to be
>    applied before we get to the fuse-iomap parts.  I'm not sending these
>    (or the fstests changes) to keep the size of the patchbomb at
>    "unreasonably large". :P  As a result, the fstests and e2fsprogs
>    postings are very targeted.
>
> e. I've dropped the fstests part of the patchbomb because v6 was just
>    way too long.
>
> I would like to get the main parts of this submission reviewed for 7.1
> now that this has been collecting comments and tweaks in non-rfc status
> for 3.5 months.
>
> Kernel:
> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf
>
> libfuse:
> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git/log/?h=fuse-iomap-bpf
>
> e2fsprogs:
> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse-iomap-bpf
>
> fstests:
> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfstests-dev.git/log/?h=fuse2fs
>
> --Darrick

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-16 17:56 ` [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Joanne Koong
@ 2026-03-16 18:04   ` Darrick J. Wong
  2026-03-16 23:08     ` Joanne Koong
  0 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-03-16 18:04 UTC (permalink / raw)
  To: Joanne Koong
  Cc: linux-fsdevel, bpf, linux-ext4, Miklos Szeredi, Bernd Schubert,
	Theodore Ts'o, Neal Gompa, Amir Goldstein, Christian Brauner,
	Jeff Layton, John, demiobenour

On Mon, Mar 16, 2026 at 10:56:21AM -0700, Joanne Koong wrote:
> On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
> >
> > There are some warts remaining:
> >
> > a. I would like to continue the discussion about how the design review
> >    of this code should be structured, and how might I go about creating
> >    new userspace filesystem servers -- lightweight new ones based off
> >    the existing userspace tools?  Or by merging lklfuse?
> 
> What do you mean by "merging lklfuse"?

Merging the lklfuse project into upstream Linux, which involves running
the whole kit and caboodle through our review process, and then fixing
user-mode-linux to work anywhere other than x86.

> Could you explain what the limitations of lklfuse are compared to the
> fuse iomap approach in this patchset?

The ones I know about are:

1> There's no support for vmapped kernel memory in UML mode, so anyone
who requires a large contiguous memory buffer cannot assemble them out
of "physical" pages.  This has been a stumbling block for XFS in the
past.

2> LKLFUSE still uses the classic fuse IO paths, which means that at
best you can directio the IO through the lklfuse kernel.  At worst you
have to use the pagecache inside the lklfuse kernel, which is very
wasteful.

3> lklfuse hasn't been updated since 6.6.

--D

> Thanks,
> Joanne
> 
> >
> > b. ext4 doesn't support out of place writes so I don't know if that
> >    actually works correctly.
> >
> > c. fuse2fs doesn't support the ext4 journal.  Urk.
> >
> > d. There's a VERY large quantity of fuse2fs improvements that need to be
> >    applied before we get to the fuse-iomap parts.  I'm not sending these
> >    (or the fstests changes) to keep the size of the patchbomb at
> >    "unreasonably large". :P  As a result, the fstests and e2fsprogs
> >    postings are very targeted.
> >
> > e. I've dropped the fstests part of the patchbomb because v6 was just
> >    way too long.
> >
> > I would like to get the main parts of this submission reviewed for 7.1
> > now that this has been collecting comments and tweaks in non-rfc status
> > for 3.5 months.
> >
> > Kernel:
> > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf
> >
> > libfuse:
> > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git/log/?h=fuse-iomap-bpf
> >
> > e2fsprogs:
> > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse-iomap-bpf
> >
> > fstests:
> > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfstests-dev.git/log/?h=fuse2fs
> >
> > --Darrick

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-16 18:04   ` Darrick J. Wong
@ 2026-03-16 23:08     ` Joanne Koong
  2026-03-16 23:41       ` Darrick J. Wong
  2026-03-17  0:10       ` Demi Marie Obenour
  0 siblings, 2 replies; 234+ messages in thread
From: Joanne Koong @ 2026-03-16 23:08 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: linux-fsdevel, bpf, linux-ext4, Miklos Szeredi, Bernd Schubert,
	Theodore Ts'o, Neal Gompa, Amir Goldstein, Christian Brauner,
	Jeff Layton, John, demiobenour

On Mon, Mar 16, 2026 at 11:04 AM Darrick J. Wong <djwong@kernel.org> wrote:
>
> On Mon, Mar 16, 2026 at 10:56:21AM -0700, Joanne Koong wrote:
> > On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
> > >
> > > There are some warts remaining:
> > >
> > > a. I would like to continue the discussion about how the design review
> > >    of this code should be structured, and how might I go about creating
> > >    new userspace filesystem servers -- lightweight new ones based off
> > >    the existing userspace tools?  Or by merging lklfuse?
> >
> > What do you mean by "merging lklfuse"?
>
> Merging the lklfuse project into upstream Linux, which involves running
> the whole kit and caboodle through our review process, and then fixing

Gotcha, so it would basically be having to port this arch/lkl
directory [1] into the linux tree

> user-mode-linux to work anywhere other than x86.

Are lklfuse and user-mode-linux (UML) two separate things or is
lklfuse dependent on user-mode-linux?

>
> > Could you explain what the limitations of lklfuse are compared to the
> > fuse iomap approach in this patchset?
>
> The ones I know about are:
>
> 1> There's no support for vmapped kernel memory in UML mode, so anyone
> who requires a large contiguous memory buffer cannot assemble them out
> of "physical" pages.  This has been a stumbling block for XFS in the
> past.
>
> 2> LKLFUSE still uses the classic fuse IO paths, which means that at
> best you can directio the IO through the lklfuse kernel.  At worst you
> have to use the pagecache inside the lklfuse kernel, which is very
> wasteful.

For the security / isolation use cases you've described, is
near-native performance a hard requirement? As I understand it, the
main use cases of this will be for mounting untrusted disk images and
CI/filesystem testing, or are there broader use cases beyond this?

>
> 3> lklfuse hasn't been updated since 6.6.

Gotcha. So if I'm understanding it correctly, the pros/cons come down to:
lklfuse pros:
- (arguably) easier setup cost. once it's setup (assuming it's
possible to add support for the vmapped kernel memory thing you
mentioned above), it'll automatically work for every filesystem vs.
having to implement a fuse-iomap server for every filesystem
- easier to maintain vs. having to maintain each filesystem's
userspace server implementation

lklfuse cons:
- worse (not sure by how much) performance
- once it's merged into the kernel, we can't choose to not
maintain/support it in the future

Am I understanding this correctly?

In my opinion, if near-native performance is not a hard requirement,
it seems like less pain overall to go with lklfuse. lklfuse seems a
lot easier to maintain and I'm not sure if some complexities like
btrfs's copy-on-write could be handled properly with fuse-iomap.

What are your thoughts on this?

Thanks,
Joanne

[1] https://github.com/lkl/linux/tree/master/arch/lkl

>
> --D
>
> > Thanks,
> > Joanne
> >
> > >
> > > b. ext4 doesn't support out of place writes so I don't know if that
> > >    actually works correctly.
> > >
> > > c. fuse2fs doesn't support the ext4 journal.  Urk.
> > >
> > > d. There's a VERY large quantity of fuse2fs improvements that need to be
> > >    applied before we get to the fuse-iomap parts.  I'm not sending these
> > >    (or the fstests changes) to keep the size of the patchbomb at
> > >    "unreasonably large". :P  As a result, the fstests and e2fsprogs
> > >    postings are very targeted.
> > >
> > > e. I've dropped the fstests part of the patchbomb because v6 was just
> > >    way too long.
> > >
> > > I would like to get the main parts of this submission reviewed for 7.1
> > > now that this has been collecting comments and tweaks in non-rfc status
> > > for 3.5 months.
> > >
> > > Kernel:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf
> > >
> > > libfuse:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git/log/?h=fuse-iomap-bpf
> > >
> > > e2fsprogs:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse-iomap-bpf
> > >
> > > fstests:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfstests-dev.git/log/?h=fuse2fs
> > >
> > > --Darrick

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-16 23:08     ` Joanne Koong
@ 2026-03-16 23:41       ` Darrick J. Wong
  2026-03-17  0:20         ` Demi Marie Obenour
  2026-03-17  0:10       ` Demi Marie Obenour
  1 sibling, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-03-16 23:41 UTC (permalink / raw)
  To: Joanne Koong
  Cc: linux-fsdevel, bpf, linux-ext4, Miklos Szeredi, Bernd Schubert,
	Theodore Ts'o, Neal Gompa, Amir Goldstein, Christian Brauner,
	Jeff Layton, John, demiobenour

On Mon, Mar 16, 2026 at 04:08:55PM -0700, Joanne Koong wrote:
> On Mon, Mar 16, 2026 at 11:04 AM Darrick J. Wong <djwong@kernel.org> wrote:
> >
> > On Mon, Mar 16, 2026 at 10:56:21AM -0700, Joanne Koong wrote:
> > > On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
> > > >
> > > > There are some warts remaining:
> > > >
> > > > a. I would like to continue the discussion about how the design review
> > > >    of this code should be structured, and how might I go about creating
> > > >    new userspace filesystem servers -- lightweight new ones based off
> > > >    the existing userspace tools?  Or by merging lklfuse?
> > >
> > > What do you mean by "merging lklfuse"?
> >
> > Merging the lklfuse project into upstream Linux, which involves running
> > the whole kit and caboodle through our review process, and then fixing
> 
> Gotcha, so it would basically be having to port this arch/lkl
> directory [1] into the linux tree

Right.

> > user-mode-linux to work anywhere other than x86.
> 
> Are lklfuse and user-mode-linux (UML) two separate things or is
> lklfuse dependent on user-mode-linux?

I was under the impression that lklfuse uses UML.  Given the weird
things in arch/lkl/Kconfig:

config 64BIT
	bool "64bit kernel"
	default y if OUTPUT_FORMAT = "pe-x86-64"
	default $(success,$(srctree)/arch/lkl/scripts/cc-objdump-file-format.sh|grep -q '^elf64-') if OUTPUT_FORMAT != "pe-x86-64"

I was kinda guessing x86_64 was the primary target of the developers?

/me notes that he's now looked into libguestfs per Demi Marie's comments
and some curiosity on the part of ngompa and i>

Whatever it is that libguestfs does to stand up unprivileged fs mounts
also could fit this bill.  It's *really* slow to start because it takes
the booted kernel, creates a largeish initramfs, boots that combo via
libvirt, and then fires up a fuse server to talk to the vm kernel.

I think all you'd have to do is change libguestfs to start the VM and
run the fuse server inside a systemd container instead of directly from
the CLI.

> > > Could you explain what the limitations of lklfuse are compared to the
> > > fuse iomap approach in this patchset?
> >
> > The ones I know about are:
> >
> > 1> There's no support for vmapped kernel memory in UML mode, so anyone
> > who requires a large contiguous memory buffer cannot assemble them out
> > of "physical" pages.  This has been a stumbling block for XFS in the
> > past.
> >
> > 2> LKLFUSE still uses the classic fuse IO paths, which means that at
> > best you can directio the IO through the lklfuse kernel.  At worst you
> > have to use the pagecache inside the lklfuse kernel, which is very
> > wasteful.
> 
> For the security / isolation use cases you've described, is
> near-native performance a hard requirement?

Not a hard requirement, just a means to convince people that they can
choose containment without completely collapsing performance.

> As I understand it, the main use cases of this will be for mounting
> untrusted disk images and CI/filesystem testing, or are there broader
> use cases beyond this?

That covers nearly all of it.

> >
> > 3> lklfuse hasn't been updated since 6.6.
> 
> Gotcha. So if I'm understanding it correctly, the pros/cons come down to:
> lklfuse pros:
> - (arguably) easier setup cost. once it's setup (assuming it's
> possible to add support for the vmapped kernel memory thing you
> mentioned above), it'll automatically work for every filesystem vs.
> having to implement a fuse-iomap server for every filesystem

Or even a good non-iomap fuse server for every filesystem.  Admittedly
the weak part of fuse4fs is that libext2fs is not as robust as the
kernel is.

> - easier to maintain vs. having to maintain each filesystem's
> userspace server implementation

Yeah.

> lklfuse cons:
> - worse (not sure by how much) performance

Probably a lot, because now you have to run a full IO stack all the way
through lklfuse.

> - once it's merged into the kernel, we can't choose to not
> maintain/support it in the future

Correct.

> Am I understanding this correctly?
> 
> In my opinion, if near-native performance is not a hard requirement,
> it seems like less pain overall to go with lklfuse. lklfuse seems a
> lot easier to maintain and I'm not sure if some complexities like
> btrfs's copy-on-write could be handled properly with fuse-iomap.

btrfs cow can be done with iomap, at least on the directio end.  It's
the other features like fsverity/fscrypt/data checksumming that aren't
currently supported by iomap.

> What are your thoughts on this?

"Gee, what if I could simplify most of my own work out of existence?"

--D

> Thanks,
> Joanne
> 
> [1] https://github.com/lkl/linux/tree/master/arch/lkl
> 
> >
> > --D
> >
> > > Thanks,
> > > Joanne
> > >
> > > >
> > > > b. ext4 doesn't support out of place writes so I don't know if that
> > > >    actually works correctly.
> > > >
> > > > c. fuse2fs doesn't support the ext4 journal.  Urk.
> > > >
> > > > d. There's a VERY large quantity of fuse2fs improvements that need to be
> > > >    applied before we get to the fuse-iomap parts.  I'm not sending these
> > > >    (or the fstests changes) to keep the size of the patchbomb at
> > > >    "unreasonably large". :P  As a result, the fstests and e2fsprogs
> > > >    postings are very targeted.
> > > >
> > > > e. I've dropped the fstests part of the patchbomb because v6 was just
> > > >    way too long.
> > > >
> > > > I would like to get the main parts of this submission reviewed for 7.1
> > > > now that this has been collecting comments and tweaks in non-rfc status
> > > > for 3.5 months.
> > > >
> > > > Kernel:
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf
> > > >
> > > > libfuse:
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git/log/?h=fuse-iomap-bpf
> > > >
> > > > e2fsprogs:
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse-iomap-bpf
> > > >
> > > > fstests:
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfstests-dev.git/log/?h=fuse2fs
> > > >
> > > > --Darrick
> 

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-16 23:08     ` Joanne Koong
  2026-03-16 23:41       ` Darrick J. Wong
@ 2026-03-17  0:10       ` Demi Marie Obenour
  1 sibling, 0 replies; 234+ messages in thread
From: Demi Marie Obenour @ 2026-03-17  0:10 UTC (permalink / raw)
  To: Joanne Koong, Darrick J. Wong
  Cc: linux-fsdevel, bpf, linux-ext4, Miklos Szeredi, Bernd Schubert,
	Theodore Ts'o, Neal Gompa, Amir Goldstein, Christian Brauner,
	Jeff Layton, John


[-- Attachment #1.1.1: Type: text/plain, Size: 3067 bytes --]

On 3/16/26 19:08, Joanne Koong wrote:
> On Mon, Mar 16, 2026 at 11:04 AM Darrick J. Wong <djwong@kernel.org> wrote:
>>
>> On Mon, Mar 16, 2026 at 10:56:21AM -0700, Joanne Koong wrote:
>>> On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
>>>>
>>>> There are some warts remaining:
>>>>
>>>> a. I would like to continue the discussion about how the design review
>>>>    of this code should be structured, and how might I go about creating
>>>>    new userspace filesystem servers -- lightweight new ones based off
>>>>    the existing userspace tools?  Or by merging lklfuse?
>>>
>>> What do you mean by "merging lklfuse"?
>>
>> Merging the lklfuse project into upstream Linux, which involves running
>> the whole kit and caboodle through our review process, and then fixing
> 
> Gotcha, so it would basically be having to port this arch/lkl
> directory [1] into the linux tree
> 
>> user-mode-linux to work anywhere other than x86.
> 
> Are lklfuse and user-mode-linux (UML) two separate things or is
> lklfuse dependent on user-mode-linux?
> 
>>
>>> Could you explain what the limitations of lklfuse are compared to the
>>> fuse iomap approach in this patchset?
>>
>> The ones I know about are:
>>
>> 1> There's no support for vmapped kernel memory in UML mode, so anyone
>> who requires a large contiguous memory buffer cannot assemble them out
>> of "physical" pages.  This has been a stumbling block for XFS in the
>> past.
>>
>> 2> LKLFUSE still uses the classic fuse IO paths, which means that at
>> best you can directio the IO through the lklfuse kernel.  At worst you
>> have to use the pagecache inside the lklfuse kernel, which is very
>> wasteful.
> 
> For the security / isolation use cases you've described, is
> near-native performance a hard requirement?

It should be good enough that distros are willing to use it by default.
Otherwise, there is no way to break out of the loop where kernel devs
say to not mount untrusted filesystems, yet the distros keep doing
that because people have stuff they need to get done.

I know from talking to Neal Gompa that libguestfs is too slow for this.

> As I understand it, the
> main use cases of this will be for mounting untrusted disk images and
> CI/filesystem testing, or are there broader use cases beyond this?

Anyone with strong verified boot requirements is going to want this.
The threat model used by Android and Chromium OS is that all on-disk
state is *never* trusted.  The root filesystem is on a dm-verity
protected partition, so mounting it in the kernel is fine.  However,
the writable partition should be mounted in userspace.

I checked with the ChromeOS security team, and they do consider being
able to write corrupted metadata to disk that compromises the system
on the next reboot to be a vulnerability.

This is also a case where performance actually matters, including
for F2FS on zoned UFS which is always copy-on-write for user data.
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-16 23:41       ` Darrick J. Wong
@ 2026-03-17  0:20         ` Demi Marie Obenour
  2026-03-17 13:59           ` Theodore Tso
  2026-03-18 21:31           ` Darrick J. Wong
  0 siblings, 2 replies; 234+ messages in thread
From: Demi Marie Obenour @ 2026-03-17  0:20 UTC (permalink / raw)
  To: Darrick J. Wong, Joanne Koong
  Cc: linux-fsdevel, bpf, linux-ext4, Miklos Szeredi, Bernd Schubert,
	Theodore Ts'o, Neal Gompa, Amir Goldstein, Christian Brauner,
	Jeff Layton, John


[-- Attachment #1.1.1: Type: text/plain, Size: 7274 bytes --]

On 3/16/26 19:41, Darrick J. Wong wrote:
> On Mon, Mar 16, 2026 at 04:08:55PM -0700, Joanne Koong wrote:
>> On Mon, Mar 16, 2026 at 11:04 AM Darrick J. Wong <djwong@kernel.org> wrote:
>>>
>>> On Mon, Mar 16, 2026 at 10:56:21AM -0700, Joanne Koong wrote:
>>>> On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
>>>>>
>>>>> There are some warts remaining:
>>>>>
>>>>> a. I would like to continue the discussion about how the design review
>>>>>    of this code should be structured, and how might I go about creating
>>>>>    new userspace filesystem servers -- lightweight new ones based off
>>>>>    the existing userspace tools?  Or by merging lklfuse?
>>>>
>>>> What do you mean by "merging lklfuse"?
>>>
>>> Merging the lklfuse project into upstream Linux, which involves running
>>> the whole kit and caboodle through our review process, and then fixing
>>
>> Gotcha, so it would basically be having to port this arch/lkl
>> directory [1] into the linux tree
> 
> Right.
> 
>>> user-mode-linux to work anywhere other than x86.
>>
>> Are lklfuse and user-mode-linux (UML) two separate things or is
>> lklfuse dependent on user-mode-linux?
> 
> I was under the impression that lklfuse uses UML.  Given the weird
> things in arch/lkl/Kconfig:
> 
> config 64BIT
> 	bool "64bit kernel"
> 	default y if OUTPUT_FORMAT = "pe-x86-64"
> 	default $(success,$(srctree)/arch/lkl/scripts/cc-objdump-file-format.sh|grep -q '^elf64-') if OUTPUT_FORMAT != "pe-x86-64"
> 
> I was kinda guessing x86_64 was the primary target of the developers?
> 
> /me notes that he's now looked into libguestfs per Demi Marie's comments
> and some curiosity on the part of ngompa and i>
> 
> Whatever it is that libguestfs does to stand up unprivileged fs mounts
> also could fit this bill.  It's *really* slow to start because it takes
> the booted kernel, creates a largeish initramfs, boots that combo via
> libvirt, and then fires up a fuse server to talk to the vm kernel.
> 
> I think all you'd have to do is change libguestfs to start the VM and
> run the fuse server inside a systemd container instead of directly from
> the CLI.

The feedback I have gotten from ngompa is that libguestfs is just
too slow for distros to use it to mount stuff.

>>>> Could you explain what the limitations of lklfuse are compared to the
>>>> fuse iomap approach in this patchset?
>>>
>>> The ones I know about are:
>>>
>>> 1> There's no support for vmapped kernel memory in UML mode, so anyone
>>> who requires a large contiguous memory buffer cannot assemble them out
>>> of "physical" pages.  This has been a stumbling block for XFS in the
>>> past.
>>>
>>> 2> LKLFUSE still uses the classic fuse IO paths, which means that at
>>> best you can directio the IO through the lklfuse kernel.  At worst you
>>> have to use the pagecache inside the lklfuse kernel, which is very
>>> wasteful.
>>
>> For the security / isolation use cases you've described, is
>> near-native performance a hard requirement?
> 
> Not a hard requirement, just a means to convince people that they can
> choose containment without completely collapsing performance.
> 
>> As I understand it, the main use cases of this will be for mounting
>> untrusted disk images and CI/filesystem testing, or are there broader
>> use cases beyond this?
> 
> That covers nearly all of it.

It's worth noting that on ChromeOS and Android, the only trusted
disk images are those that are read-only and protected by dm-verity.
*Every* writable image is considered untrusted.

I don't know if doing a full fsck at each boot is considered
acceptable, but I suspect it would slow boot far too much.

Yes, Google ought to be paying for the kernel changes to fix this mess.

>>> 3> lklfuse hasn't been updated since 6.6.
>>
>> Gotcha. So if I'm understanding it correctly, the pros/cons come down to:
>> lklfuse pros:
>> - (arguably) easier setup cost. once it's setup (assuming it's
>> possible to add support for the vmapped kernel memory thing you
>> mentioned above), it'll automatically work for every filesystem vs.
>> having to implement a fuse-iomap server for every filesystem
> 
> Or even a good non-iomap fuse server for every filesystem.  Admittedly
> the weak part of fuse4fs is that libext2fs is not as robust as the
> kernel is.
> 
>> - easier to maintain vs. having to maintain each filesystem's
>> userspace server implementation
> 
> Yeah.
> 
>> lklfuse cons:
>> - worse (not sure by how much) performance
> 
> Probably a lot, because now you have to run a full IO stack all the way
> through lklfuse.

How much is "a lot"?  Is it "this is only useful for non-interactive
overnight backups", "you will notice this in benchmarks but it's okay
for normal use", or somewhere in between?

Could lklfuse and iomap be combined?

>> - once it's merged into the kernel, we can't choose to not
>> maintain/support it in the future
> 
> Correct.
> 
>> Am I understanding this correctly?
>>
>> In my opinion, if near-native performance is not a hard requirement,
>> it seems like less pain overall to go with lklfuse. lklfuse seems a
>> lot easier to maintain and I'm not sure if some complexities like
>> btrfs's copy-on-write could be handled properly with fuse-iomap.
> 
> btrfs cow can be done with iomap, at least on the directio end.  It's
> the other features like fsverity/fscrypt/data checksumming that aren't
> currently supported by iomap.

Pretty much everyone on btrfs uses data checksumming.

>> What are your thoughts on this?
> 
> "Gee, what if I could simplify most of my own work out of existence?"

What is that work?

> --D
> 
>> Thanks,
>> Joanne
>>
>> [1] https://github.com/lkl/linux/tree/master/arch/lkl
>>
>>>
>>> --D
>>>
>>>> Thanks,
>>>> Joanne
>>>>
>>>>>
>>>>> b. ext4 doesn't support out of place writes so I don't know if that
>>>>>    actually works correctly.
>>>>>
>>>>> c. fuse2fs doesn't support the ext4 journal.  Urk.
>>>>>
>>>>> d. There's a VERY large quantity of fuse2fs improvements that need to be
>>>>>    applied before we get to the fuse-iomap parts.  I'm not sending these
>>>>>    (or the fstests changes) to keep the size of the patchbomb at
>>>>>    "unreasonably large". :P  As a result, the fstests and e2fsprogs
>>>>>    postings are very targeted.
>>>>>
>>>>> e. I've dropped the fstests part of the patchbomb because v6 was just
>>>>>    way too long.
>>>>>
>>>>> I would like to get the main parts of this submission reviewed for 7.1
>>>>> now that this has been collecting comments and tweaks in non-rfc status
>>>>> for 3.5 months.
>>>>>
>>>>> Kernel:
>>>>> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf
>>>>>
>>>>> libfuse:
>>>>> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git/log/?h=fuse-iomap-bpf
>>>>>
>>>>> e2fsprogs:
>>>>> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse-iomap-bpf
>>>>>
>>>>> fstests:
>>>>> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfstests-dev.git/log/?h=fuse2fs
>>>>>
>>>>> --Darrick
>>


-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-17  0:20         ` Demi Marie Obenour
@ 2026-03-17 13:59           ` Theodore Tso
  2026-03-17 14:05             ` Demi Marie Obenour
  2026-03-18 21:31           ` Darrick J. Wong
  1 sibling, 1 reply; 234+ messages in thread
From: Theodore Tso @ 2026-03-17 13:59 UTC (permalink / raw)
  To: Demi Marie Obenour
  Cc: Darrick J. Wong, Joanne Koong, linux-fsdevel, bpf, linux-ext4,
	Miklos Szeredi, Bernd Schubert, Neal Gompa, Amir Goldstein,
	Christian Brauner, Jeff Layton, John

On Mon, Mar 16, 2026 at 08:20:29PM -0400, Demi Marie Obenour wrote:
> 
> It's worth noting that on ChromeOS and Android, the only trusted
> disk images are those that are read-only and protected by dm-verity.
> *Every* writable image is considered untrusted.

So I can't speak for ChromeOS or Android, but given discussions that
I've had with folks in those teams when we were developing fscrypt and
fsverity, the writeable images which are soldered onto the mainboard,
where user data is stored, is protected by fscrypt, which provide
confidentiality but not integrity for user data.

However, from a trust perspective, if there is an "evil maid attack"
(where someone leaves their device unattended in a hotel room, and the
housecleaning staff removes the device, and the flash is removed from
the mainboard and modified) is something which is considered an attack
which is realistically only going to be carried out by a nation state,
and the primary priority was protecting the privileged APK's (the
moral equivalent of setuid binaries), and that's where fsverity is
used to protect against that threat.

Yes, the nation state attacker could potentially corrupt the metadata
of the writeable file system image, and but there are enough zero day
attacks that involve sending corrupted image files that trigger buffer
overflows, etc., that while it would be nice to protect against this
sort of thing, given that it requires a physical attack (and that
point, the nation state attacker could also enhance the device with
remotely denotated explosives, something which spies on the
touchscreen or microphone and ships the output over the network,
etc.), I don't believe this is considered a high priority threat that
is worth spending $$$ to mitigate.

The only other extrenal image, which is where something like using
fuse would be interesting, is a USB thumb drive being connected to the
ChromeOS or Android device.  In that case, performance is really not
an issue, so running fsck before mounting would probably be considered
acceptable.  The main issue here is that fsck for NTFS, FAT, etc.,
probably isn't as good as the fsck for a file systems such as xfs or
ext4.  So the primary protection that we have is that enterprise
managed devices can simply prohibit mounting external USB thumb drives
if the enterprise administrators elects to do so.  This doesn't help
personal devices, but users have to take affirmative action to mount a
device (simply inserting a device isn't enough, at least on Android),
so people who are paranoid can simply not pick up a USB thumb drive
they find in a parking lot and insert it into their phone.

Cheers,

						- Ted
					

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-17 13:59           ` Theodore Tso
@ 2026-03-17 14:05             ` Demi Marie Obenour
  2026-03-17 15:20               ` Theodore Tso
  0 siblings, 1 reply; 234+ messages in thread
From: Demi Marie Obenour @ 2026-03-17 14:05 UTC (permalink / raw)
  To: Theodore Tso
  Cc: Darrick J. Wong, Joanne Koong, linux-fsdevel, bpf, linux-ext4,
	Miklos Szeredi, Bernd Schubert, Neal Gompa, Amir Goldstein,
	Christian Brauner, Jeff Layton, John


[-- Attachment #1.1.1: Type: text/plain, Size: 2098 bytes --]

On 3/17/26 09:59, Theodore Tso wrote:
> On Mon, Mar 16, 2026 at 08:20:29PM -0400, Demi Marie Obenour wrote:
>>
>> It's worth noting that on ChromeOS and Android, the only trusted
>> disk images are those that are read-only and protected by dm-verity.
>> *Every* writable image is considered untrusted.
> 
> So I can't speak for ChromeOS or Android, but given discussions that
> I've had with folks in those teams when we were developing fscrypt and
> fsverity, the writeable images which are soldered onto the mainboard,
> where user data is stored, is protected by fscrypt, which provide
> confidentiality but not integrity for user data.
> 
> However, from a trust perspective, if there is an "evil maid attack"
> (where someone leaves their device unattended in a hotel room, and the
> housecleaning staff removes the device, and the flash is removed from
> the mainboard and modified) is something which is considered an attack
> which is realistically only going to be carried out by a nation state,
> and the primary priority was protecting the privileged APK's (the
> moral equivalent of setuid binaries), and that's where fsverity is
> used to protect against that threat.
> 
> Yes, the nation state attacker could potentially corrupt the metadata
> of the writeable file system image, and but there are enough zero day
> attacks that involve sending corrupted image files that trigger buffer
> overflows, etc., that while it would be nice to protect against this
> sort of thing, given that it requires a physical attack (and that
> point, the nation state attacker could also enhance the device with
> remotely denotated explosives, something which spies on the
> touchscreen or microphone and ships the output over the network,
> etc.), I don't believe this is considered a high priority threat that
> is worth spending $$$ to mitigate.

This doesn't require a physical attack.  An attacker who has previously
gained root access could use a metadata parsing attack to keep that
access across reboots.
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-17 14:05             ` Demi Marie Obenour
@ 2026-03-17 15:20               ` Theodore Tso
  0 siblings, 0 replies; 234+ messages in thread
From: Theodore Tso @ 2026-03-17 15:20 UTC (permalink / raw)
  To: Demi Marie Obenour
  Cc: Darrick J. Wong, Joanne Koong, linux-fsdevel, bpf, linux-ext4,
	Miklos Szeredi, Bernd Schubert, Neal Gompa, Amir Goldstein,
	Christian Brauner, Jeff Layton, John

On Tue, Mar 17, 2026 at 10:05:59AM -0400, Demi Marie Obenour wrote:
> 
> This doesn't require a physical attack.  An attacker who has previously
> gained root access could use a metadata parsing attack to keep that
> access across reboots.

So the concern that you are raising is that an attacker might be able
to corrupt the metadata in such a way that it triggers some kind of
buffer overrun or other zero-day attack, but that it will *not*
trigger an EXT4-fs error indication (since if it does, then on the
next reboot, an fsck will be forced since the file system will be
marked corrupt).  Is that correct?

That's... possible, but in my experience, the vast majority of syzbot
reported bugs involving fuzzed file systems do actually trigger the
file system being detected as corrupted.  It's just that the file
system is mounted in errors=continue mode, as opposed to
errors=remount-ro or errirs=panic.  And more often than not, it
triggers a warning or an OOPS, which is considered CVE fodder.  Not
all syzbot issues can be translated into a privilege escalation
attack.

But if the attacker could pull it off, and reliably find a way to
force the system to trip against the hidden file system corruption, I
agree that this would represent a violation of the security model for
Android, which is that a reboot should always get the system back to a
secure state.  I will note, though, that you can also carry out
zero-day attacks by putting malicious data into an image file that
triggers a buffer overrun, and in some ways, that might be an easier
way to persist some kind of security vulnerability across reboots
compared to trying to find a more complex file system metadata parsing
attack.

Ultimately, it's really a cost/benefit tradeoff.  We need to take a
big picture view when considering which attacks we should be expending
resources to protect against, since security mitigation budget is not
infinite.  That being said, patches are welcome.  :-)

Cheers,

						- Ted

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-17  0:20         ` Demi Marie Obenour
  2026-03-17 13:59           ` Theodore Tso
@ 2026-03-18 21:31           ` Darrick J. Wong
  2026-03-19  7:28             ` Demi Marie Obenour
  1 sibling, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-03-18 21:31 UTC (permalink / raw)
  To: Demi Marie Obenour
  Cc: Joanne Koong, linux-fsdevel, bpf, linux-ext4, Miklos Szeredi,
	Bernd Schubert, Theodore Ts'o, Neal Gompa, Amir Goldstein,
	Christian Brauner, Jeff Layton, John

On Mon, Mar 16, 2026 at 08:20:29PM -0400, Demi Marie Obenour wrote:
> On 3/16/26 19:41, Darrick J. Wong wrote:
> > On Mon, Mar 16, 2026 at 04:08:55PM -0700, Joanne Koong wrote:
> >> On Mon, Mar 16, 2026 at 11:04 AM Darrick J. Wong <djwong@kernel.org> wrote:
> >>>
> >>> On Mon, Mar 16, 2026 at 10:56:21AM -0700, Joanne Koong wrote:
> >>>> On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
> >>>>>
> >>>>> There are some warts remaining:
> >>>>>
> >>>>> a. I would like to continue the discussion about how the design review
> >>>>>    of this code should be structured, and how might I go about creating
> >>>>>    new userspace filesystem servers -- lightweight new ones based off
> >>>>>    the existing userspace tools?  Or by merging lklfuse?
> >>>>
> >>>> What do you mean by "merging lklfuse"?
> >>>
> >>> Merging the lklfuse project into upstream Linux, which involves running
> >>> the whole kit and caboodle through our review process, and then fixing
> >>
> >> Gotcha, so it would basically be having to port this arch/lkl
> >> directory [1] into the linux tree
> > 
> > Right.
> > 
> >>> user-mode-linux to work anywhere other than x86.
> >>
> >> Are lklfuse and user-mode-linux (UML) two separate things or is
> >> lklfuse dependent on user-mode-linux?
> > 
> > I was under the impression that lklfuse uses UML.  Given the weird
> > things in arch/lkl/Kconfig:
> > 
> > config 64BIT
> > 	bool "64bit kernel"
> > 	default y if OUTPUT_FORMAT = "pe-x86-64"
> > 	default $(success,$(srctree)/arch/lkl/scripts/cc-objdump-file-format.sh|grep -q '^elf64-') if OUTPUT_FORMAT != "pe-x86-64"
> > 
> > I was kinda guessing x86_64 was the primary target of the developers?
> > 
> > /me notes that he's now looked into libguestfs per Demi Marie's comments
> > and some curiosity on the part of ngompa and i>
> > 
> > Whatever it is that libguestfs does to stand up unprivileged fs mounts
> > also could fit this bill.  It's *really* slow to start because it takes
> > the booted kernel, creates a largeish initramfs, boots that combo via
> > libvirt, and then fires up a fuse server to talk to the vm kernel.
> > 
> > I think all you'd have to do is change libguestfs to start the VM and
> > run the fuse server inside a systemd container instead of directly from
> > the CLI.
> 
> The feedback I have gotten from ngompa is that libguestfs is just
> too slow for distros to use it to mount stuff.

Yes, libguestfs is /verrrry/ slow to start up.

> >>>> Could you explain what the limitations of lklfuse are compared to the
> >>>> fuse iomap approach in this patchset?
> >>>
> >>> The ones I know about are:
> >>>
> >>> 1> There's no support for vmapped kernel memory in UML mode, so anyone
> >>> who requires a large contiguous memory buffer cannot assemble them out
> >>> of "physical" pages.  This has been a stumbling block for XFS in the
> >>> past.
> >>>
> >>> 2> LKLFUSE still uses the classic fuse IO paths, which means that at
> >>> best you can directio the IO through the lklfuse kernel.  At worst you
> >>> have to use the pagecache inside the lklfuse kernel, which is very
> >>> wasteful.
> >>
> >> For the security / isolation use cases you've described, is
> >> near-native performance a hard requirement?
> > 
> > Not a hard requirement, just a means to convince people that they can
> > choose containment without completely collapsing performance.
> > 
> >> As I understand it, the main use cases of this will be for mounting
> >> untrusted disk images and CI/filesystem testing, or are there broader
> >> use cases beyond this?
> > 
> > That covers nearly all of it.
> 
> It's worth noting that on ChromeOS and Android, the only trusted
> disk images are those that are read-only and protected by dm-verity.
> *Every* writable image is considered untrusted.
> 
> I don't know if doing a full fsck at each boot is considered
> acceptable, but I suspect it would slow boot far too much.

Not to mention that an attacker who gained control of the boot process
could inject malicious filesystem metadata after fsck completes
successfully but before the kernel mount occurs.

> Yes, Google ought to be paying for the kernel changes to fix this mess.
> 
> >>> 3> lklfuse hasn't been updated since 6.6.
> >>
> >> Gotcha. So if I'm understanding it correctly, the pros/cons come down to:
> >> lklfuse pros:
> >> - (arguably) easier setup cost. once it's setup (assuming it's
> >> possible to add support for the vmapped kernel memory thing you
> >> mentioned above), it'll automatically work for every filesystem vs.
> >> having to implement a fuse-iomap server for every filesystem
> > 
> > Or even a good non-iomap fuse server for every filesystem.  Admittedly
> > the weak part of fuse4fs is that libext2fs is not as robust as the
> > kernel is.
> > 
> >> - easier to maintain vs. having to maintain each filesystem's
> >> userspace server implementation
> > 
> > Yeah.
> > 
> >> lklfuse cons:
> >> - worse (not sure by how much) performance
> > 
> > Probably a lot, because now you have to run a full IO stack all the way
> > through lklfuse.
> 
> How much is "a lot"?  Is it "this is only useful for non-interactive
> overnight backups", "you will notice this in benchmarks but it's okay
> for normal use", or somewhere in between?

Startup is painfully slow.  Normal operation isn't noticeably bad, but I
didn't bother doing any performance comparisons.

> Could lklfuse and iomap be combined?

Probably, though you'd have to find a way to route the FUSE_IOMAP_*
requests to a filesystem driver.  That's upside-down of the current
iomap model where filesystems have to opt into using iomap on a
per-IO-path basis, and then iomap calls the filesystem to find mappings.

> >> - once it's merged into the kernel, we can't choose to not
> >> maintain/support it in the future
> > 
> > Correct.
> > 
> >> Am I understanding this correctly?
> >>
> >> In my opinion, if near-native performance is not a hard requirement,
> >> it seems like less pain overall to go with lklfuse. lklfuse seems a
> >> lot easier to maintain and I'm not sure if some complexities like
> >> btrfs's copy-on-write could be handled properly with fuse-iomap.
> > 
> > btrfs cow can be done with iomap, at least on the directio end.  It's
> > the other features like fsverity/fscrypt/data checksumming that aren't
> > currently supported by iomap.
> 
> Pretty much everyone on btrfs uses data checksumming.
> 
> >> What are your thoughts on this?
> > 
> > "Gee, what if I could simplify most of my own work out of existence?"
> 
> What is that work?

Everything I've put out since the end of online fsck for xfs.

--D

> 
> > --D
> > 
> >> Thanks,
> >> Joanne
> >>
> >> [1] https://github.com/lkl/linux/tree/master/arch/lkl
> >>
> >>>
> >>> --D
> >>>
> >>>> Thanks,
> >>>> Joanne
> >>>>
> >>>>>
> >>>>> b. ext4 doesn't support out of place writes so I don't know if that
> >>>>>    actually works correctly.
> >>>>>
> >>>>> c. fuse2fs doesn't support the ext4 journal.  Urk.
> >>>>>
> >>>>> d. There's a VERY large quantity of fuse2fs improvements that need to be
> >>>>>    applied before we get to the fuse-iomap parts.  I'm not sending these
> >>>>>    (or the fstests changes) to keep the size of the patchbomb at
> >>>>>    "unreasonably large". :P  As a result, the fstests and e2fsprogs
> >>>>>    postings are very targeted.
> >>>>>
> >>>>> e. I've dropped the fstests part of the patchbomb because v6 was just
> >>>>>    way too long.
> >>>>>
> >>>>> I would like to get the main parts of this submission reviewed for 7.1
> >>>>> now that this has been collecting comments and tweaks in non-rfc status
> >>>>> for 3.5 months.
> >>>>>
> >>>>> Kernel:
> >>>>> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-bpf
> >>>>>
> >>>>> libfuse:
> >>>>> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git/log/?h=fuse-iomap-bpf
> >>>>>
> >>>>> e2fsprogs:
> >>>>> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse-iomap-bpf
> >>>>>
> >>>>> fstests:
> >>>>> https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfstests-dev.git/log/?h=fuse2fs
> >>>>>
> >>>>> --Darrick
> >>
> 
> 
> -- 
> Sincerely,
> Demi Marie Obenour (she/her/hers)






^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-18 21:31           ` Darrick J. Wong
@ 2026-03-19  7:28             ` Demi Marie Obenour
  2026-03-19 16:08               ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Demi Marie Obenour @ 2026-03-19  7:28 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Joanne Koong, linux-fsdevel, bpf, linux-ext4, Miklos Szeredi,
	Bernd Schubert, Theodore Ts'o, Neal Gompa, Amir Goldstein,
	Christian Brauner, Jeff Layton, John


[-- Attachment #1.1.1: Type: text/plain, Size: 7118 bytes --]

On 3/18/26 17:31, Darrick J. Wong wrote:
> On Mon, Mar 16, 2026 at 08:20:29PM -0400, Demi Marie Obenour wrote:
>> On 3/16/26 19:41, Darrick J. Wong wrote:
>>> On Mon, Mar 16, 2026 at 04:08:55PM -0700, Joanne Koong wrote:
>>>> On Mon, Mar 16, 2026 at 11:04 AM Darrick J. Wong <djwong@kernel.org> wrote:
>>>>>
>>>>> On Mon, Mar 16, 2026 at 10:56:21AM -0700, Joanne Koong wrote:
>>>>>> On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
>>>>>>>
>>>>>>> There are some warts remaining:
>>>>>>>
>>>>>>> a. I would like to continue the discussion about how the design review
>>>>>>>    of this code should be structured, and how might I go about creating
>>>>>>>    new userspace filesystem servers -- lightweight new ones based off
>>>>>>>    the existing userspace tools?  Or by merging lklfuse?
>>>>>>
>>>>>> What do you mean by "merging lklfuse"?
>>>>>
>>>>> Merging the lklfuse project into upstream Linux, which involves running
>>>>> the whole kit and caboodle through our review process, and then fixing
>>>>
>>>> Gotcha, so it would basically be having to port this arch/lkl
>>>> directory [1] into the linux tree
>>>
>>> Right.
>>>
>>>>> user-mode-linux to work anywhere other than x86.
>>>>
>>>> Are lklfuse and user-mode-linux (UML) two separate things or is
>>>> lklfuse dependent on user-mode-linux?
>>>
>>> I was under the impression that lklfuse uses UML.  Given the weird
>>> things in arch/lkl/Kconfig:
>>>
>>> config 64BIT
>>> 	bool "64bit kernel"
>>> 	default y if OUTPUT_FORMAT = "pe-x86-64"
>>> 	default $(success,$(srctree)/arch/lkl/scripts/cc-objdump-file-format.sh|grep -q '^elf64-') if OUTPUT_FORMAT != "pe-x86-64"
>>>
>>> I was kinda guessing x86_64 was the primary target of the developers?
>>>
>>> /me notes that he's now looked into libguestfs per Demi Marie's comments
>>> and some curiosity on the part of ngompa and i>
>>>
>>> Whatever it is that libguestfs does to stand up unprivileged fs mounts
>>> also could fit this bill.  It's *really* slow to start because it takes
>>> the booted kernel, creates a largeish initramfs, boots that combo via
>>> libvirt, and then fires up a fuse server to talk to the vm kernel.
>>>
>>> I think all you'd have to do is change libguestfs to start the VM and
>>> run the fuse server inside a systemd container instead of directly from
>>> the CLI.
>>
>> The feedback I have gotten from ngompa is that libguestfs is just
>> too slow for distros to use it to mount stuff.
> 
> Yes, libguestfs is /verrrry/ slow to start up.
> 
>>>>>> Could you explain what the limitations of lklfuse are compared to the
>>>>>> fuse iomap approach in this patchset?
>>>>>
>>>>> The ones I know about are:
>>>>>
>>>>> 1> There's no support for vmapped kernel memory in UML mode, so anyone
>>>>> who requires a large contiguous memory buffer cannot assemble them out
>>>>> of "physical" pages.  This has been a stumbling block for XFS in the
>>>>> past.
>>>>>
>>>>> 2> LKLFUSE still uses the classic fuse IO paths, which means that at
>>>>> best you can directio the IO through the lklfuse kernel.  At worst you
>>>>> have to use the pagecache inside the lklfuse kernel, which is very
>>>>> wasteful.
>>>>
>>>> For the security / isolation use cases you've described, is
>>>> near-native performance a hard requirement?
>>>
>>> Not a hard requirement, just a means to convince people that they can
>>> choose containment without completely collapsing performance.
>>>
>>>> As I understand it, the main use cases of this will be for mounting
>>>> untrusted disk images and CI/filesystem testing, or are there broader
>>>> use cases beyond this?
>>>
>>> That covers nearly all of it.
>>
>> It's worth noting that on ChromeOS and Android, the only trusted
>> disk images are those that are read-only and protected by dm-verity.
>> *Every* writable image is considered untrusted.
>>
>> I don't know if doing a full fsck at each boot is considered
>> acceptable, but I suspect it would slow boot far too much.
> 
> Not to mention that an attacker who gained control of the boot process
> could inject malicious filesystem metadata after fsck completes
> successfully but before the kernel mount occurs.
> 
>> Yes, Google ought to be paying for the kernel changes to fix this mess.
>>
>>>>> 3> lklfuse hasn't been updated since 6.6.
>>>>
>>>> Gotcha. So if I'm understanding it correctly, the pros/cons come down to:
>>>> lklfuse pros:
>>>> - (arguably) easier setup cost. once it's setup (assuming it's
>>>> possible to add support for the vmapped kernel memory thing you
>>>> mentioned above), it'll automatically work for every filesystem vs.
>>>> having to implement a fuse-iomap server for every filesystem
>>>
>>> Or even a good non-iomap fuse server for every filesystem.  Admittedly
>>> the weak part of fuse4fs is that libext2fs is not as robust as the
>>> kernel is.
>>>
>>>> - easier to maintain vs. having to maintain each filesystem's
>>>> userspace server implementation
>>>
>>> Yeah.
>>>
>>>> lklfuse cons:
>>>> - worse (not sure by how much) performance
>>>
>>> Probably a lot, because now you have to run a full IO stack all the way
>>> through lklfuse.
>>
>> How much is "a lot"?  Is it "this is only useful for non-interactive
>> overnight backups", "you will notice this in benchmarks but it's okay
>> for normal use", or somewhere in between?
> 
> Startup is painfully slow.  Normal operation isn't noticeably bad, but I
> didn't bother doing any performance comparisons.
> 
>> Could lklfuse and iomap be combined?
> 
> Probably, though you'd have to find a way to route the FUSE_IOMAP_*
> requests to a filesystem driver.  That's upside-down of the current
> iomap model where filesystems have to opt into using iomap on a
> per-IO-path basis, and then iomap calls the filesystem to find mappings.

If it does get done it would be awesome.  I don't think I'll be able to
contribute, though.

>>>> - once it's merged into the kernel, we can't choose to not
>>>> maintain/support it in the future
>>>
>>> Correct.
>>>
>>>> Am I understanding this correctly?
>>>>
>>>> In my opinion, if near-native performance is not a hard requirement,
>>>> it seems like less pain overall to go with lklfuse. lklfuse seems a
>>>> lot easier to maintain and I'm not sure if some complexities like
>>>> btrfs's copy-on-write could be handled properly with fuse-iomap.
>>>
>>> btrfs cow can be done with iomap, at least on the directio end.  It's
>>> the other features like fsverity/fscrypt/data checksumming that aren't
>>> currently supported by iomap.
>>
>> Pretty much everyone on btrfs uses data checksumming.
>>
>>>> What are your thoughts on this?
>>>
>>> "Gee, what if I could simplify most of my own work out of existence?"
>>
>> What is that work?
> 
> Everything I've put out since the end of online fsck for xfs.

Is pretty much all of that work either on better FUSE performance or
fixes for problems found by fuzzers?
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-19  7:28             ` Demi Marie Obenour
@ 2026-03-19 16:08               ` Darrick J. Wong
  2026-03-20 17:04                 ` Joanne Koong
  0 siblings, 1 reply; 234+ messages in thread
From: Darrick J. Wong @ 2026-03-19 16:08 UTC (permalink / raw)
  To: Demi Marie Obenour
  Cc: Joanne Koong, linux-fsdevel, bpf, linux-ext4, Miklos Szeredi,
	Bernd Schubert, Theodore Ts'o, Neal Gompa, Amir Goldstein,
	Christian Brauner, Jeff Layton, John

On Thu, Mar 19, 2026 at 03:28:21AM -0400, Demi Marie Obenour wrote:
> On 3/18/26 17:31, Darrick J. Wong wrote:
> > On Mon, Mar 16, 2026 at 08:20:29PM -0400, Demi Marie Obenour wrote:
> >> On 3/16/26 19:41, Darrick J. Wong wrote:
> >>> On Mon, Mar 16, 2026 at 04:08:55PM -0700, Joanne Koong wrote:
> >>>> On Mon, Mar 16, 2026 at 11:04 AM Darrick J. Wong <djwong@kernel.org> wrote:
> >>>>>
> >>>>> On Mon, Mar 16, 2026 at 10:56:21AM -0700, Joanne Koong wrote:
> >>>>>> On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
> >>>>>>>
> >>>>>>> There are some warts remaining:
> >>>>>>>
> >>>>>>> a. I would like to continue the discussion about how the design review
> >>>>>>>    of this code should be structured, and how might I go about creating
> >>>>>>>    new userspace filesystem servers -- lightweight new ones based off
> >>>>>>>    the existing userspace tools?  Or by merging lklfuse?
> >>>>>>
> >>>>>> What do you mean by "merging lklfuse"?
> >>>>>
> >>>>> Merging the lklfuse project into upstream Linux, which involves running
> >>>>> the whole kit and caboodle through our review process, and then fixing
> >>>>
> >>>> Gotcha, so it would basically be having to port this arch/lkl
> >>>> directory [1] into the linux tree
> >>>
> >>> Right.
> >>>
> >>>>> user-mode-linux to work anywhere other than x86.
> >>>>
> >>>> Are lklfuse and user-mode-linux (UML) two separate things or is
> >>>> lklfuse dependent on user-mode-linux?
> >>>
> >>> I was under the impression that lklfuse uses UML.  Given the weird
> >>> things in arch/lkl/Kconfig:
> >>>
> >>> config 64BIT
> >>> 	bool "64bit kernel"
> >>> 	default y if OUTPUT_FORMAT = "pe-x86-64"
> >>> 	default $(success,$(srctree)/arch/lkl/scripts/cc-objdump-file-format.sh|grep -q '^elf64-') if OUTPUT_FORMAT != "pe-x86-64"
> >>>
> >>> I was kinda guessing x86_64 was the primary target of the developers?
> >>>
> >>> /me notes that he's now looked into libguestfs per Demi Marie's comments
> >>> and some curiosity on the part of ngompa and i>
> >>>
> >>> Whatever it is that libguestfs does to stand up unprivileged fs mounts
> >>> also could fit this bill.  It's *really* slow to start because it takes
> >>> the booted kernel, creates a largeish initramfs, boots that combo via
> >>> libvirt, and then fires up a fuse server to talk to the vm kernel.
> >>>
> >>> I think all you'd have to do is change libguestfs to start the VM and
> >>> run the fuse server inside a systemd container instead of directly from
> >>> the CLI.
> >>
> >> The feedback I have gotten from ngompa is that libguestfs is just
> >> too slow for distros to use it to mount stuff.
> > 
> > Yes, libguestfs is /verrrry/ slow to start up.
> > 
> >>>>>> Could you explain what the limitations of lklfuse are compared to the
> >>>>>> fuse iomap approach in this patchset?
> >>>>>
> >>>>> The ones I know about are:
> >>>>>
> >>>>> 1> There's no support for vmapped kernel memory in UML mode, so anyone
> >>>>> who requires a large contiguous memory buffer cannot assemble them out
> >>>>> of "physical" pages.  This has been a stumbling block for XFS in the
> >>>>> past.
> >>>>>
> >>>>> 2> LKLFUSE still uses the classic fuse IO paths, which means that at
> >>>>> best you can directio the IO through the lklfuse kernel.  At worst you
> >>>>> have to use the pagecache inside the lklfuse kernel, which is very
> >>>>> wasteful.
> >>>>
> >>>> For the security / isolation use cases you've described, is
> >>>> near-native performance a hard requirement?
> >>>
> >>> Not a hard requirement, just a means to convince people that they can
> >>> choose containment without completely collapsing performance.
> >>>
> >>>> As I understand it, the main use cases of this will be for mounting
> >>>> untrusted disk images and CI/filesystem testing, or are there broader
> >>>> use cases beyond this?
> >>>
> >>> That covers nearly all of it.
> >>
> >> It's worth noting that on ChromeOS and Android, the only trusted
> >> disk images are those that are read-only and protected by dm-verity.
> >> *Every* writable image is considered untrusted.
> >>
> >> I don't know if doing a full fsck at each boot is considered
> >> acceptable, but I suspect it would slow boot far too much.
> > 
> > Not to mention that an attacker who gained control of the boot process
> > could inject malicious filesystem metadata after fsck completes
> > successfully but before the kernel mount occurs.
> > 
> >> Yes, Google ought to be paying for the kernel changes to fix this mess.
> >>
> >>>>> 3> lklfuse hasn't been updated since 6.6.
> >>>>
> >>>> Gotcha. So if I'm understanding it correctly, the pros/cons come down to:
> >>>> lklfuse pros:
> >>>> - (arguably) easier setup cost. once it's setup (assuming it's
> >>>> possible to add support for the vmapped kernel memory thing you
> >>>> mentioned above), it'll automatically work for every filesystem vs.
> >>>> having to implement a fuse-iomap server for every filesystem
> >>>
> >>> Or even a good non-iomap fuse server for every filesystem.  Admittedly
> >>> the weak part of fuse4fs is that libext2fs is not as robust as the
> >>> kernel is.
> >>>
> >>>> - easier to maintain vs. having to maintain each filesystem's
> >>>> userspace server implementation
> >>>
> >>> Yeah.
> >>>
> >>>> lklfuse cons:
> >>>> - worse (not sure by how much) performance
> >>>
> >>> Probably a lot, because now you have to run a full IO stack all the way
> >>> through lklfuse.
> >>
> >> How much is "a lot"?  Is it "this is only useful for non-interactive
> >> overnight backups", "you will notice this in benchmarks but it's okay
> >> for normal use", or somewhere in between?
> > 
> > Startup is painfully slow.  Normal operation isn't noticeably bad, but I
> > didn't bother doing any performance comparisons.
> > 
> >> Could lklfuse and iomap be combined?
> > 
> > Probably, though you'd have to find a way to route the FUSE_IOMAP_*
> > requests to a filesystem driver.  That's upside-down of the current
> > iomap model where filesystems have to opt into using iomap on a
> > per-IO-path basis, and then iomap calls the filesystem to find mappings.
> 
> If it does get done it would be awesome.  I don't think I'll be able to
> contribute, though.

I wonder if one could export a (pnfs) layout from the lklfuse kernel to
the real one, that's <cough> where struct iomap came from.  A huge
downside to that solution is that layouts don't support out of place
writes because pnfs doesn't support out of place writes.

> >>>> - once it's merged into the kernel, we can't choose to not
> >>>> maintain/support it in the future
> >>>
> >>> Correct.
> >>>
> >>>> Am I understanding this correctly?
> >>>>
> >>>> In my opinion, if near-native performance is not a hard requirement,
> >>>> it seems like less pain overall to go with lklfuse. lklfuse seems a
> >>>> lot easier to maintain and I'm not sure if some complexities like
> >>>> btrfs's copy-on-write could be handled properly with fuse-iomap.
> >>>
> >>> btrfs cow can be done with iomap, at least on the directio end.  It's
> >>> the other features like fsverity/fscrypt/data checksumming that aren't
> >>> currently supported by iomap.
> >>
> >> Pretty much everyone on btrfs uses data checksumming.
> >>
> >>>> What are your thoughts on this?
> >>>
> >>> "Gee, what if I could simplify most of my own work out of existence?"
> >>
> >> What is that work?
> > 
> > Everything I've put out since the end of online fsck for xfs.
> 
> Is pretty much all of that work either on better FUSE performance or
> fixes for problems found by fuzzers?

Mostly the iomap parts of fuse-iomap.  It's a huge complication to add
to the already confusing fuse codebase.

--D

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-19 16:08               ` Darrick J. Wong
@ 2026-03-20 17:04                 ` Joanne Koong
  2026-03-20 20:31                   ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Joanne Koong @ 2026-03-20 17:04 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Demi Marie Obenour, linux-fsdevel, bpf, linux-ext4,
	Miklos Szeredi, Bernd Schubert, Theodore Ts'o, Neal Gompa,
	Amir Goldstein, Christian Brauner, Jeff Layton, John

On Thu, Mar 19, 2026 at 9:08 AM Darrick J. Wong <djwong@kernel.org> wrote:
>
> On Thu, Mar 19, 2026 at 03:28:21AM -0400, Demi Marie Obenour wrote:
> > On 3/18/26 17:31, Darrick J. Wong wrote:
> > > On Mon, Mar 16, 2026 at 08:20:29PM -0400, Demi Marie Obenour wrote:
> > >> On 3/16/26 19:41, Darrick J. Wong wrote:
> > >>> On Mon, Mar 16, 2026 at 04:08:55PM -0700, Joanne Koong wrote:
> > >>>> On Mon, Mar 16, 2026 at 11:04 AM Darrick J. Wong <djwong@kernel.org> wrote:
> > >>>>>
> > >>>>> On Mon, Mar 16, 2026 at 10:56:21AM -0700, Joanne Koong wrote:
> > >>>>>> On Mon, Feb 23, 2026 at 2:46 PM Darrick J. Wong <djwong@kernel.org> wrote:
> > >>>>>>>
> > >>>>>>> There are some warts remaining:
> > >>>>>>>
> > >>>>>>> a. I would like to continue the discussion about how the design review
> > >>>>>>>    of this code should be structured, and how might I go about creating
> > >>>>>>>    new userspace filesystem servers -- lightweight new ones based off
> > >>>>>>>    the existing userspace tools?  Or by merging lklfuse?
> > >>>>>>
> > >>>>>> What do you mean by "merging lklfuse"?
> > >>>>>
> > >>>>> Merging the lklfuse project into upstream Linux, which involves running
> > >>>>> the whole kit and caboodle through our review process, and then fixing
> > >>>>
> > >>>> Gotcha, so it would basically be having to port this arch/lkl
> > >>>> directory [1] into the linux tree
> > >>>
> > >>> Right.
> > >>>
> > >>>>> user-mode-linux to work anywhere other than x86.
> > >>>>
> > >>>> Are lklfuse and user-mode-linux (UML) two separate things or is
> > >>>> lklfuse dependent on user-mode-linux?
> > >>>
> > >>> I was under the impression that lklfuse uses UML.  Given the weird
> > >>> things in arch/lkl/Kconfig:
> > >>>
> > >>> config 64BIT
> > >>>   bool "64bit kernel"
> > >>>   default y if OUTPUT_FORMAT = "pe-x86-64"
> > >>>   default $(success,$(srctree)/arch/lkl/scripts/cc-objdump-file-format.sh|grep -q '^elf64-') if OUTPUT_FORMAT != "pe-x86-64"
> > >>>
> > >>> I was kinda guessing x86_64 was the primary target of the developers?
> > >>>
> > >>> /me notes that he's now looked into libguestfs per Demi Marie's comments
> > >>> and some curiosity on the part of ngompa and i>
> > >>>
> > >>> Whatever it is that libguestfs does to stand up unprivileged fs mounts
> > >>> also could fit this bill.  It's *really* slow to start because it takes
> > >>> the booted kernel, creates a largeish initramfs, boots that combo via
> > >>> libvirt, and then fires up a fuse server to talk to the vm kernel.
> > >>>
> > >>> I think all you'd have to do is change libguestfs to start the VM and
> > >>> run the fuse server inside a systemd container instead of directly from
> > >>> the CLI.
> > >>
> > >> The feedback I have gotten from ngompa is that libguestfs is just
> > >> too slow for distros to use it to mount stuff.
> > >
> > > Yes, libguestfs is /verrrry/ slow to start up.
> > >
> > >>>>>> Could you explain what the limitations of lklfuse are compared to the
> > >>>>>> fuse iomap approach in this patchset?
> > >>>>>
> > >>>>> The ones I know about are:
> > >>>>>
> > >>>>> 1> There's no support for vmapped kernel memory in UML mode, so anyone
> > >>>>> who requires a large contiguous memory buffer cannot assemble them out
> > >>>>> of "physical" pages.  This has been a stumbling block for XFS in the
> > >>>>> past.
> > >>>>>
> > >>>>> 2> LKLFUSE still uses the classic fuse IO paths, which means that at
> > >>>>> best you can directio the IO through the lklfuse kernel.  At worst you
> > >>>>> have to use the pagecache inside the lklfuse kernel, which is very
> > >>>>> wasteful.
> > >>>>
> > >>>> For the security / isolation use cases you've described, is
> > >>>> near-native performance a hard requirement?
> > >>>
> > >>> Not a hard requirement, just a means to convince people that they can
> > >>> choose containment without completely collapsing performance.
> > >>>
> > >>>> As I understand it, the main use cases of this will be for mounting
> > >>>> untrusted disk images and CI/filesystem testing, or are there broader
> > >>>> use cases beyond this?
> > >>>
> > >>> That covers nearly all of it.
> > >>
> > >> It's worth noting that on ChromeOS and Android, the only trusted
> > >> disk images are those that are read-only and protected by dm-verity.
> > >> *Every* writable image is considered untrusted.
> > >>
> > >> I don't know if doing a full fsck at each boot is considered
> > >> acceptable, but I suspect it would slow boot far too much.
> > >
> > > Not to mention that an attacker who gained control of the boot process
> > > could inject malicious filesystem metadata after fsck completes
> > > successfully but before the kernel mount occurs.
> > >
> > >> Yes, Google ought to be paying for the kernel changes to fix this mess.
> > >>
> > >>>>> 3> lklfuse hasn't been updated since 6.6.
> > >>>>
> > >>>> Gotcha. So if I'm understanding it correctly, the pros/cons come down to:
> > >>>> lklfuse pros:
> > >>>> - (arguably) easier setup cost. once it's setup (assuming it's
> > >>>> possible to add support for the vmapped kernel memory thing you
> > >>>> mentioned above), it'll automatically work for every filesystem vs.
> > >>>> having to implement a fuse-iomap server for every filesystem
> > >>>
> > >>> Or even a good non-iomap fuse server for every filesystem.  Admittedly
> > >>> the weak part of fuse4fs is that libext2fs is not as robust as the
> > >>> kernel is.
> > >>>
> > >>>> - easier to maintain vs. having to maintain each filesystem's
> > >>>> userspace server implementation
> > >>>
> > >>> Yeah.
> > >>>
> > >>>> lklfuse cons:
> > >>>> - worse (not sure by how much) performance
> > >>>
> > >>> Probably a lot, because now you have to run a full IO stack all the way
> > >>> through lklfuse.
> > >>
> > >> How much is "a lot"?  Is it "this is only useful for non-interactive
> > >> overnight backups", "you will notice this in benchmarks but it's okay
> > >> for normal use", or somewhere in between?
> > >
> > > Startup is painfully slow.  Normal operation isn't noticeably bad, but I
> > > didn't bother doing any performance comparisons.

For the CI/filesystem testing use case, could fork() help amortize
lklfuse's slow startup time? eg start lklfuse + pay LKL initialization
cost once, fork for each test, and each child mounts its own test
image?

> > >
> > >> Could lklfuse and iomap be combined?
> > >
> > > Probably, though you'd have to find a way to route the FUSE_IOMAP_*
> > > requests to a filesystem driver.  That's upside-down of the current
> > > iomap model where filesystems have to opt into using iomap on a
> > > per-IO-path basis, and then iomap calls the filesystem to find mappings.
> >
> > If it does get done it would be awesome.  I don't think I'll be able to
> > contribute, though.
>
> I wonder if one could export a (pnfs) layout from the lklfuse kernel to
> the real one, that's <cough> where struct iomap came from.  A huge
> downside to that solution is that layouts don't support out of place
> writes because pnfs doesn't support out of place writes.
>
> > >>>> - once it's merged into the kernel, we can't choose to not
> > >>>> maintain/support it in the future
> > >>>
> > >>> Correct.
> > >>>
> > >>>> Am I understanding this correctly?
> > >>>>
> > >>>> In my opinion, if near-native performance is not a hard requirement,
> > >>>> it seems like less pain overall to go with lklfuse. lklfuse seems a
> > >>>> lot easier to maintain and I'm not sure if some complexities like
> > >>>> btrfs's copy-on-write could be handled properly with fuse-iomap.
> > >>>
> > >>> btrfs cow can be done with iomap, at least on the directio end.  It's
> > >>> the other features like fsverity/fscrypt/data checksumming that aren't
> > >>> currently supported by iomap.
> > >>
> > >> Pretty much everyone on btrfs uses data checksumming.
> > >>
> > >>>> What are your thoughts on this?
> > >>>
> > >>> "Gee, what if I could simplify most of my own work out of existence?"
> > >>
> > >> What is that work?
> > >
> > > Everything I've put out since the end of online fsck for xfs.
> >
> > Is pretty much all of that work either on better FUSE performance or
> > fixes for problems found by fuzzers?
>
> Mostly the iomap parts of fuse-iomap.  It's a huge complication to add
> to the already confusing fuse codebase.

imo if you did end up going the lklfuse route, I think it'd still be
useful to have the generic iomap infrastructure pieces of your
fuse-iomap patchblizzard added, for future new filesystem
implementations that can provide extent mappings to get near-native IO
performance.

Thanks,
Joanne

>
> --D

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation
  2026-03-20 17:04                 ` Joanne Koong
@ 2026-03-20 20:31                   ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-03-20 20:31 UTC (permalink / raw)
  To: Joanne Koong
  Cc: Demi Marie Obenour, linux-fsdevel, bpf, linux-ext4,
	Miklos Szeredi, Bernd Schubert, Theodore Ts'o, Neal Gompa,
	Amir Goldstein, Christian Brauner, Jeff Layton, John

On Fri, Mar 20, 2026 at 10:04:29AM -0700, Joanne Koong wrote:

<snip>

> > > >>>> - easier to maintain vs. having to maintain each filesystem's
> > > >>>> userspace server implementation
> > > >>>
> > > >>> Yeah.
> > > >>>
> > > >>>> lklfuse cons:
> > > >>>> - worse (not sure by how much) performance
> > > >>>
> > > >>> Probably a lot, because now you have to run a full IO stack all the way
> > > >>> through lklfuse.
> > > >>
> > > >> How much is "a lot"?  Is it "this is only useful for non-interactive
> > > >> overnight backups", "you will notice this in benchmarks but it's okay
> > > >> for normal use", or somewhere in between?
> > > >
> > > > Startup is painfully slow.  Normal operation isn't noticeably bad, but I
> > > > didn't bother doing any performance comparisons.
> 
> For the CI/filesystem testing use case, could fork() help amortize
> lklfuse's slow startup time? eg start lklfuse + pay LKL initialization
> cost once, fork for each test, and each child mounts its own test
> image?

I suppose you could prefork like that (with some difficulty) if you had
a means to convey the device, fstype, and mount options to each new
child as a mount request comes in.

Though if you had a way to do that, then you might be better off
shipping a canned kernel + hibernate image which would "unhibernate"
quickly, discover the fs parameters, and immediately engage the fuse
server.

> > > >
> > > >> Could lklfuse and iomap be combined?
> > > >
> > > > Probably, though you'd have to find a way to route the FUSE_IOMAP_*
> > > > requests to a filesystem driver.  That's upside-down of the current
> > > > iomap model where filesystems have to opt into using iomap on a
> > > > per-IO-path basis, and then iomap calls the filesystem to find mappings.
> > >
> > > If it does get done it would be awesome.  I don't think I'll be able to
> > > contribute, though.
> >
> > I wonder if one could export a (pnfs) layout from the lklfuse kernel to
> > the real one, that's <cough> where struct iomap came from.  A huge
> > downside to that solution is that layouts don't support out of place
> > writes because pnfs doesn't support out of place writes.
> >
> > > >>>> - once it's merged into the kernel, we can't choose to not
> > > >>>> maintain/support it in the future
> > > >>>
> > > >>> Correct.
> > > >>>
> > > >>>> Am I understanding this correctly?
> > > >>>>
> > > >>>> In my opinion, if near-native performance is not a hard requirement,
> > > >>>> it seems like less pain overall to go with lklfuse. lklfuse seems a
> > > >>>> lot easier to maintain and I'm not sure if some complexities like
> > > >>>> btrfs's copy-on-write could be handled properly with fuse-iomap.
> > > >>>
> > > >>> btrfs cow can be done with iomap, at least on the directio end.  It's
> > > >>> the other features like fsverity/fscrypt/data checksumming that aren't
> > > >>> currently supported by iomap.
> > > >>
> > > >> Pretty much everyone on btrfs uses data checksumming.
> > > >>
> > > >>>> What are your thoughts on this?
> > > >>>
> > > >>> "Gee, what if I could simplify most of my own work out of existence?"
> > > >>
> > > >> What is that work?
> > > >
> > > > Everything I've put out since the end of online fsck for xfs.
> > >
> > > Is pretty much all of that work either on better FUSE performance or
> > > fixes for problems found by fuzzers?
> >
> > Mostly the iomap parts of fuse-iomap.  It's a huge complication to add
> > to the already confusing fuse codebase.
> 
> imo if you did end up going the lklfuse route, I think it'd still be
> useful to have the generic iomap infrastructure pieces of your
> fuse-iomap patchblizzard added, for future new filesystem
> implementations that can provide extent mappings to get near-native IO
> performance.

<nod> But, uh, are those patches going to be reviewed?

--D

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 3/5] fuse: implement file attributes mask for statx
  2026-02-23 23:07   ` [PATCH 3/5] fuse: implement file attributes mask for statx Darrick J. Wong
@ 2026-03-25 18:35     ` Joanne Koong
  2026-03-25 22:12       ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Joanne Koong @ 2026-03-25 18:35 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: miklos, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Mon, Feb 23, 2026 at 3:07 PM Darrick J. Wong <djwong@kernel.org> wrote:
>
> From: Darrick J. Wong <djwong@kernel.org>
>
> Actually copy the attributes/attributes_mask from userspace.  Ignore
> file attributes bits that the VFS sets (or doesn't set) on its own.
>
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
> ---
>  fs/fuse/fuse_i.h |   37 +++++++++++++++++++++++++++++++++++++
>  fs/fuse/dir.c    |    4 ++++
>  fs/fuse/inode.c  |    4 ++++
>  3 files changed, 45 insertions(+)
>
>
> diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> index 1d4beca5c7018d..79793db3e9a743 100644
> --- a/fs/fuse/fuse_i.h
> +++ b/fs/fuse/fuse_i.h
> @@ -147,6 +147,10 @@ struct fuse_inode {
>         /** Version of last attribute change */
>         u64 attr_version;
>
> +       /** statx file attributes */
> +       u64 statx_attributes;
> +       u64 statx_attributes_mask;
> +
>         union {
>                 /* read/write io cache (regular file only) */
>                 struct {
> @@ -1236,6 +1240,39 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
>                                    u64 attr_valid, u32 cache_mask,
>                                    u64 evict_ctr);
>
> +/*
> + * These statx attribute flags are set by the VFS so mask them out of replies
> + * from the fuse server for local filesystems.  Nonlocal filesystems are
> + * responsible for enforcing and advertising these flags themselves.
> + */
> +#define FUSE_STATX_LOCAL_VFS_ATTRIBUTES (STATX_ATTR_IMMUTABLE | \
> +                                        STATX_ATTR_APPEND)
> +
> +/*
> + * These statx attribute flags are set by the VFS so mask them out of replies
> + * from the fuse server.
> + */
> +#define FUSE_STATX_VFS_ATTRIBUTES (STATX_ATTR_AUTOMOUNT | STATX_ATTR_DAX | \
> +                                  STATX_ATTR_MOUNT_ROOT)
> +
> +static inline u64 fuse_statx_attributes_mask(const struct inode *inode,
> +                                            const struct fuse_statx *sx)
> +{
> +       if (fuse_inode_is_exclusive(inode))
> +               return sx->attributes_mask & ~(FUSE_STATX_VFS_ATTRIBUTES |
> +                                              FUSE_STATX_LOCAL_VFS_ATTRIBUTES);
> +       return sx->attributes_mask & ~FUSE_STATX_VFS_ATTRIBUTES;
> +}
> +
> +static inline u64 fuse_statx_attributes(const struct inode *inode,
> +                                       const struct fuse_statx *sx)
> +{
> +       if (fuse_inode_is_exclusive(inode))
> +               return sx->attributes & ~(FUSE_STATX_VFS_ATTRIBUTES |
> +                                         FUSE_STATX_LOCAL_VFS_ATTRIBUTES);
> +       return sx->attributes & ~FUSE_STATX_VFS_ATTRIBUTES;
> +}
> +
>  u32 fuse_get_cache_mask(struct inode *inode);
>
>  /**
> diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
> index 7ac6b232ef1232..10fa47e969292f 100644
> --- a/fs/fuse/dir.c
> +++ b/fs/fuse/dir.c
> @@ -1464,6 +1464,8 @@ static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
>                 stat->result_mask = sx->mask & (STATX_BASIC_STATS | STATX_BTIME);
>                 stat->btime.tv_sec = sx->btime.tv_sec;
>                 stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec, NSEC_PER_SEC - 1);
> +               stat->attributes |= fuse_statx_attributes(inode, sx);
> +               stat->attributes_mask |= fuse_statx_attributes_mask(inode, sx);
>                 fuse_fillattr(idmap, inode, &attr, stat);
>                 stat->result_mask |= STATX_TYPE;
>         }
> @@ -1568,6 +1570,8 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,
>                         stat->btime = fi->i_btime;
>                         stat->result_mask |= STATX_BTIME;
>                 }
> +               stat->attributes = fi->statx_attributes;
> +               stat->attributes_mask = fi->statx_attributes_mask;

Do these need to be |= so we don't overwrite any vfs attributes stored
in stat already?

Thanks,
Joanne

>         }
>
>         return err;
> diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
> index 58c3351b467221..ff8b94cb02e63c 100644
> --- a/fs/fuse/inode.c
> +++ b/fs/fuse/inode.c
> @@ -286,6 +286,10 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
>                         fi->i_btime.tv_sec = sx->btime.tv_sec;
>                         fi->i_btime.tv_nsec = sx->btime.tv_nsec;
>                 }
> +
> +               fi->statx_attributes = fuse_statx_attributes(inode, sx);
> +               fi->statx_attributes_mask = fuse_statx_attributes_mask(inode,
> +                                                                      sx);
>         }
>
>         if (attr->blksize)
>

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 4/5] fuse: update file mode when updating acls
  2026-02-23 23:07   ` [PATCH 4/5] fuse: update file mode when updating acls Darrick J. Wong
@ 2026-03-25 19:39     ` Joanne Koong
  2026-03-25 22:23       ` Darrick J. Wong
  0 siblings, 1 reply; 234+ messages in thread
From: Joanne Koong @ 2026-03-25 19:39 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: miklos, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Mon, Feb 23, 2026 at 3:07 PM Darrick J. Wong <djwong@kernel.org> wrote:
>
> From: Darrick J. Wong <djwong@kernel.org>
>
> If someone sets ACLs on a file that can be expressed fully as Unix DAC
> mode bits, most local filesystems will then update the mode bits and
> drop the ACL xattr to reduce inefficiency in the file access paths.
> Let's do that too.  Note that means that we can setacl and end up with
> no ACL xattrs, so we also need to tolerate ENODATA returns from
> fuse_removexattr.
>
> Note that here we define a "local" fuse filesystem as one that uses
> fuseblk mode; we'll shortly add fuse servers that use iomap for the file
> IO path to that list.
>
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> ---
>  fs/fuse/fuse_i.h |    2 +-
>  fs/fuse/acl.c    |   43 ++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 43 insertions(+), 2 deletions(-)
>
> diff --git a/fs/fuse/acl.c b/fs/fuse/acl.c
> index cbde6ac1add35a..f2b959efd67490 100644
> --- a/fs/fuse/acl.c
> +++ b/fs/fuse/acl.c
> @@ -11,6 +11,18 @@
>  #include <linux/posix_acl.h>
>  #include <linux/posix_acl_xattr.h>
>
> +/*
> + * If this fuse server behaves like a local filesystem, we can implement the
> + * kernel's optimizations for ACLs for local filesystems instead of passing
> + * the ACL requests straight through to another server.
> + */
> +static inline bool fuse_inode_has_local_acls(const struct inode *inode)
> +{
> +       const struct fuse_conn *fc = get_fuse_conn(inode);
> +
> +       return fc->posix_acl && fuse_inode_is_exclusive(inode);
> +}
> +
>  static struct posix_acl *__fuse_get_acl(struct fuse_conn *fc,
>                                         struct inode *inode, int type, bool rcu)
>  {
> @@ -98,6 +110,7 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
>         struct inode *inode = d_inode(dentry);
>         struct fuse_conn *fc = get_fuse_conn(inode);
>         const char *name;
> +       umode_t mode = inode->i_mode;
>         int ret;
>
>         if (fuse_is_bad(inode))
> @@ -113,6 +126,18 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
>         else
>                 return -EINVAL;
>
> +       /*
> +        * If the ACL can be represented entirely with changes to the mode
> +        * bits, then most filesystems will update the mode bits and delete
> +        * the ACL xattr.
> +        */
> +       if (acl && type == ACL_TYPE_ACCESS &&
> +           fuse_inode_has_local_acls(inode)) {
> +               ret = posix_acl_update_mode(idmap, inode, &mode, &acl);
> +               if (ret)
> +                       return ret;
> +       }
> +
>         if (acl) {
>                 unsigned int extra_flags = 0;
>                 /*

I think this sentence in this comment block "Fuse userspace is
responsible for updating access permissions in the inode, if needed"
needs some updating now, since this is only now true for non-local
fuse servers

> @@ -139,7 +164,7 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
>                  * through POSIX ACLs. Such daemons don't expect setgid bits to
>                  * be stripped.
>                  */
> -               if (fc->posix_acl &&
> +               if (fc->posix_acl && mode == inode->i_mode &&

Maybe a bit verbose but imo it'd be clearer if we had a separate
boolean tracking the case where the kernel updated the mode bits,
instead of using "mode == inode->i_mode" here and below for the
fuse_do_setattr() logic block. That makes it more clear here to reason
about (eg it'd at least make it more obvious here that we don't need
to strip sgid since the kernel already did that when it updated the
mode bits earlier)

>                     !in_group_or_capable(idmap, inode,
>                                          i_gid_into_vfsgid(idmap, inode)))
>                         extra_flags |= FUSE_SETXATTR_ACL_KILL_SGID;
> @@ -148,6 +173,22 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
>                 kfree(value);
>         } else {
>                 ret = fuse_removexattr(inode, name);
> +               /* If the acl didn't exist to start with that's fine. */
> +               if (ret == -ENODATA)
> +                       ret = 0;
> +       }
> +
> +       /* If we scheduled a mode update above, push that to userspace now. */
> +       if (!ret) {
> +               struct iattr attr = { };
> +
> +               if (mode != inode->i_mode) {
> +                       attr.ia_valid |= ATTR_MODE;
> +                       attr.ia_mode = mode;
> +               }
> +
> +               if (attr.ia_valid)
> +                       ret = fuse_do_setattr(idmap, dentry, &attr, NULL);
>         }

I think this logic reads clearer if it's restructured to

if (!ret && mode != inode->i_mode) {
    struct iattr attr = {
            .ia_valid = ATTR_MODE,
            .ia_mode = mode,
     };

    ret = fuse_do_setattr(idmap, dentry, &attr, NULL);
}

>
>         if (fc->posix_acl) {
>

For local / exclusive servers, the kernel already has / sets the
refreshed attributes, so we could probably skip the invalidation logic
here for that case since the cache is already uptodate?

Thanks,
Joanne

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 3/5] fuse: implement file attributes mask for statx
  2026-03-25 18:35     ` Joanne Koong
@ 2026-03-25 22:12       ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-03-25 22:12 UTC (permalink / raw)
  To: Joanne Koong; +Cc: miklos, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Wed, Mar 25, 2026 at 11:35:47AM -0700, Joanne Koong wrote:
> On Mon, Feb 23, 2026 at 3:07 PM Darrick J. Wong <djwong@kernel.org> wrote:
> >
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > Actually copy the attributes/attributes_mask from userspace.  Ignore
> > file attributes bits that the VFS sets (or doesn't set) on its own.
> >
> > Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> > Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
> > ---
> >  fs/fuse/fuse_i.h |   37 +++++++++++++++++++++++++++++++++++++
> >  fs/fuse/dir.c    |    4 ++++
> >  fs/fuse/inode.c  |    4 ++++
> >  3 files changed, 45 insertions(+)
> >
> >
> > diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> > index 1d4beca5c7018d..79793db3e9a743 100644
> > --- a/fs/fuse/fuse_i.h
> > +++ b/fs/fuse/fuse_i.h
> > @@ -147,6 +147,10 @@ struct fuse_inode {
> >         /** Version of last attribute change */
> >         u64 attr_version;
> >
> > +       /** statx file attributes */
> > +       u64 statx_attributes;
> > +       u64 statx_attributes_mask;
> > +
> >         union {
> >                 /* read/write io cache (regular file only) */
> >                 struct {
> > @@ -1236,6 +1240,39 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
> >                                    u64 attr_valid, u32 cache_mask,
> >                                    u64 evict_ctr);
> >
> > +/*
> > + * These statx attribute flags are set by the VFS so mask them out of replies
> > + * from the fuse server for local filesystems.  Nonlocal filesystems are
> > + * responsible for enforcing and advertising these flags themselves.
> > + */
> > +#define FUSE_STATX_LOCAL_VFS_ATTRIBUTES (STATX_ATTR_IMMUTABLE | \
> > +                                        STATX_ATTR_APPEND)
> > +
> > +/*
> > + * These statx attribute flags are set by the VFS so mask them out of replies
> > + * from the fuse server.
> > + */
> > +#define FUSE_STATX_VFS_ATTRIBUTES (STATX_ATTR_AUTOMOUNT | STATX_ATTR_DAX | \
> > +                                  STATX_ATTR_MOUNT_ROOT)
> > +
> > +static inline u64 fuse_statx_attributes_mask(const struct inode *inode,
> > +                                            const struct fuse_statx *sx)
> > +{
> > +       if (fuse_inode_is_exclusive(inode))
> > +               return sx->attributes_mask & ~(FUSE_STATX_VFS_ATTRIBUTES |
> > +                                              FUSE_STATX_LOCAL_VFS_ATTRIBUTES);
> > +       return sx->attributes_mask & ~FUSE_STATX_VFS_ATTRIBUTES;
> > +}
> > +
> > +static inline u64 fuse_statx_attributes(const struct inode *inode,
> > +                                       const struct fuse_statx *sx)
> > +{
> > +       if (fuse_inode_is_exclusive(inode))
> > +               return sx->attributes & ~(FUSE_STATX_VFS_ATTRIBUTES |
> > +                                         FUSE_STATX_LOCAL_VFS_ATTRIBUTES);
> > +       return sx->attributes & ~FUSE_STATX_VFS_ATTRIBUTES;
> > +}
> > +
> >  u32 fuse_get_cache_mask(struct inode *inode);
> >
> >  /**
> > diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
> > index 7ac6b232ef1232..10fa47e969292f 100644
> > --- a/fs/fuse/dir.c
> > +++ b/fs/fuse/dir.c
> > @@ -1464,6 +1464,8 @@ static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
> >                 stat->result_mask = sx->mask & (STATX_BASIC_STATS | STATX_BTIME);
> >                 stat->btime.tv_sec = sx->btime.tv_sec;
> >                 stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec, NSEC_PER_SEC - 1);
> > +               stat->attributes |= fuse_statx_attributes(inode, sx);
> > +               stat->attributes_mask |= fuse_statx_attributes_mask(inode, sx);
> >                 fuse_fillattr(idmap, inode, &attr, stat);
> >                 stat->result_mask |= STATX_TYPE;
> >         }
> > @@ -1568,6 +1570,8 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,
> >                         stat->btime = fi->i_btime;
> >                         stat->result_mask |= STATX_BTIME;
> >                 }
> > +               stat->attributes = fi->statx_attributes;
> > +               stat->attributes_mask = fi->statx_attributes_mask;
> 
> Do these need to be |= so we don't overwrite any vfs attributes stored
> in stat already?

Ackpth yes.  Good catch!

--D

> Thanks,
> Joanne
> 
> >         }
> >
> >         return err;
> > diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
> > index 58c3351b467221..ff8b94cb02e63c 100644
> > --- a/fs/fuse/inode.c
> > +++ b/fs/fuse/inode.c
> > @@ -286,6 +286,10 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
> >                         fi->i_btime.tv_sec = sx->btime.tv_sec;
> >                         fi->i_btime.tv_nsec = sx->btime.tv_nsec;
> >                 }
> > +
> > +               fi->statx_attributes = fuse_statx_attributes(inode, sx);
> > +               fi->statx_attributes_mask = fuse_statx_attributes_mask(inode,
> > +                                                                      sx);
> >         }
> >
> >         if (attr->blksize)
> >
> 

^ permalink raw reply	[flat|nested] 234+ messages in thread

* Re: [PATCH 4/5] fuse: update file mode when updating acls
  2026-03-25 19:39     ` Joanne Koong
@ 2026-03-25 22:23       ` Darrick J. Wong
  0 siblings, 0 replies; 234+ messages in thread
From: Darrick J. Wong @ 2026-03-25 22:23 UTC (permalink / raw)
  To: Joanne Koong; +Cc: miklos, bpf, bernd, neal, linux-fsdevel, linux-ext4

On Wed, Mar 25, 2026 at 12:39:57PM -0700, Joanne Koong wrote:
> On Mon, Feb 23, 2026 at 3:07 PM Darrick J. Wong <djwong@kernel.org> wrote:
> >
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > If someone sets ACLs on a file that can be expressed fully as Unix DAC
> > mode bits, most local filesystems will then update the mode bits and
> > drop the ACL xattr to reduce inefficiency in the file access paths.
> > Let's do that too.  Note that means that we can setacl and end up with
> > no ACL xattrs, so we also need to tolerate ENODATA returns from
> > fuse_removexattr.
> >
> > Note that here we define a "local" fuse filesystem as one that uses
> > fuseblk mode; we'll shortly add fuse servers that use iomap for the file
> > IO path to that list.
> >
> > Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> > ---
> >  fs/fuse/fuse_i.h |    2 +-
> >  fs/fuse/acl.c    |   43 ++++++++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 43 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/fuse/acl.c b/fs/fuse/acl.c
> > index cbde6ac1add35a..f2b959efd67490 100644
> > --- a/fs/fuse/acl.c
> > +++ b/fs/fuse/acl.c
> > @@ -11,6 +11,18 @@
> >  #include <linux/posix_acl.h>
> >  #include <linux/posix_acl_xattr.h>
> >
> > +/*
> > + * If this fuse server behaves like a local filesystem, we can implement the
> > + * kernel's optimizations for ACLs for local filesystems instead of passing
> > + * the ACL requests straight through to another server.
> > + */
> > +static inline bool fuse_inode_has_local_acls(const struct inode *inode)
> > +{
> > +       const struct fuse_conn *fc = get_fuse_conn(inode);
> > +
> > +       return fc->posix_acl && fuse_inode_is_exclusive(inode);
> > +}
> > +
> >  static struct posix_acl *__fuse_get_acl(struct fuse_conn *fc,
> >                                         struct inode *inode, int type, bool rcu)
> >  {
> > @@ -98,6 +110,7 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
> >         struct inode *inode = d_inode(dentry);
> >         struct fuse_conn *fc = get_fuse_conn(inode);
> >         const char *name;
> > +       umode_t mode = inode->i_mode;
> >         int ret;
> >
> >         if (fuse_is_bad(inode))
> > @@ -113,6 +126,18 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
> >         else
> >                 return -EINVAL;
> >
> > +       /*
> > +        * If the ACL can be represented entirely with changes to the mode
> > +        * bits, then most filesystems will update the mode bits and delete
> > +        * the ACL xattr.
> > +        */
> > +       if (acl && type == ACL_TYPE_ACCESS &&
> > +           fuse_inode_has_local_acls(inode)) {
> > +               ret = posix_acl_update_mode(idmap, inode, &mode, &acl);
> > +               if (ret)
> > +                       return ret;
> > +       }
> > +
> >         if (acl) {
> >                 unsigned int extra_flags = 0;
> >                 /*
> 
> I think this sentence in this comment block "Fuse userspace is
> responsible for updating access permissions in the inode, if needed"
> needs some updating now, since this is only now true for non-local
> fuse servers

Done.

	/*
	 * For non-local filesystems, fuse userspace is responsible for
	 * updating access permissions in the inode, if needed.
	 * fuse_setxattr invalidates the inode attributes, which will
	 * force them to be refreshed the next time they are used, and
	 * it also updates i_ctime.
	 */

> 
> > @@ -139,7 +164,7 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
> >                  * through POSIX ACLs. Such daemons don't expect setgid bits to
> >                  * be stripped.
> >                  */
> > -               if (fc->posix_acl &&
> > +               if (fc->posix_acl && mode == inode->i_mode &&
> 
> Maybe a bit verbose but imo it'd be clearer if we had a separate
> boolean tracking the case where the kernel updated the mode bits,
> instead of using "mode == inode->i_mode" here and below for the
> fuse_do_setattr() logic block. That makes it more clear here to reason
> about (eg it'd at least make it more obvious here that we don't need
> to strip sgid since the kernel already did that when it updated the
> mode bits earlier)

Yeah, this could be keyed off fuse_inode_has_local_acls().

> 
> >                     !in_group_or_capable(idmap, inode,
> >                                          i_gid_into_vfsgid(idmap, inode)))
> >                         extra_flags |= FUSE_SETXATTR_ACL_KILL_SGID;
> > @@ -148,6 +173,22 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
> >                 kfree(value);
> >         } else {
> >                 ret = fuse_removexattr(inode, name);
> > +               /* If the acl didn't exist to start with that's fine. */
> > +               if (ret == -ENODATA)
> > +                       ret = 0;
> > +       }
> > +
> > +       /* If we scheduled a mode update above, push that to userspace now. */
> > +       if (!ret) {
> > +               struct iattr attr = { };
> > +
> > +               if (mode != inode->i_mode) {
> > +                       attr.ia_valid |= ATTR_MODE;
> > +                       attr.ia_mode = mode;
> > +               }
> > +
> > +               if (attr.ia_valid)
> > +                       ret = fuse_do_setattr(idmap, dentry, &attr, NULL);
> >         }
> 
> I think this logic reads clearer if it's restructured to
> 
> if (!ret && mode != inode->i_mode) {
>     struct iattr attr = {
>             .ia_valid = ATTR_MODE,
>             .ia_mode = mode,
>      };
> 
>     ret = fuse_do_setattr(idmap, dentry, &attr, NULL);
> }
> 
> >
> >         if (fc->posix_acl) {
> >
> 
> For local / exclusive servers, the kernel already has / sets the
> refreshed attributes, so we could probably skip the invalidation logic
> here for that case since the cache is already uptodate?

I could, but down in the iomap patchset I add more logic to update the
ctime:

	struct iattr attr = { };

	/*
	 * When we're running in iomap mode, we need to update mode and
	 * ctime ourselves instead of letting the fuse server figure
	 * that out.
	 */
	if (is_iomap) {
		attr.ia_valid |= ATTR_CTIME;
		inode_set_ctime_current(inode);
		attr.ia_ctime = inode_get_ctime(inode);
	}

	/*
	 * If we scheduled a mode update above, push that to userspace
	 * now.
	 */
	if (mode != inode->i_mode) {
		attr.ia_valid |= ATTR_MODE;
		attr.ia_mode = mode;
	}

	if (attr.ia_valid)
		ret = fuse_do_setattr(idmap, dentry, &attr, NULL);

In non-iomap "local acls" mode the server's still expected to update
ctime in set/removexattr.  OTOH I guess that is ... 65-16=49 patches
from now so maybe it's worth the churn?

Either way thanks for getting back to this. :)

--D

> Thanks,
> Joanne
> 

^ permalink raw reply	[flat|nested] 234+ messages in thread

end of thread, other threads:[~2026-03-25 22:23 UTC | newest]

Thread overview: 234+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 22:46 [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Darrick J. Wong
2026-02-23 23:00 ` [PATCHSET v7 1/9] fuse: general bug fixes Darrick J. Wong
2026-02-23 23:06   ` [PATCH 1/5] fuse: flush pending FUSE_RELEASE requests before sending FUSE_DESTROY Darrick J. Wong
2026-02-24 19:33     ` Joanne Koong
2026-02-24 19:57       ` Darrick J. Wong
2026-02-24 20:03         ` Joanne Koong
2026-02-23 23:06   ` [PATCH 2/5] fuse: quiet down complaints in fuse_conn_limit_write Darrick J. Wong
2026-02-24  8:36     ` Horst Birthelmer
2026-02-24 19:17       ` Darrick J. Wong
2026-02-24 20:09     ` Joanne Koong
2026-02-27 16:05     ` Miklos Szeredi
2026-02-23 23:07   ` [PATCH 3/5] fuse: implement file attributes mask for statx Darrick J. Wong
2026-03-25 18:35     ` Joanne Koong
2026-03-25 22:12       ` Darrick J. Wong
2026-02-23 23:07   ` [PATCH 4/5] fuse: update file mode when updating acls Darrick J. Wong
2026-03-25 19:39     ` Joanne Koong
2026-03-25 22:23       ` Darrick J. Wong
2026-02-23 23:07   ` [PATCH 5/5] fuse: propagate default and file acls on creation Darrick J. Wong
2026-02-23 23:00 ` [PATCHSET v7 2/9] iomap: cleanups ahead of adding fuse support Darrick J. Wong
2026-02-23 23:07   ` [PATCH 1/2] iomap: allow directio callers to supply _COMP_WORK Darrick J. Wong
2026-02-24 14:00     ` Christoph Hellwig
2026-02-24 19:17       ` Darrick J. Wong
2026-02-23 23:08   ` [PATCH 2/2] iomap: allow NULL swap info bdev when activating swapfile Darrick J. Wong
2026-02-24 14:01     ` Christoph Hellwig
2026-02-24 19:26       ` Darrick J. Wong
2026-02-25 14:16         ` Christoph Hellwig
2026-02-25 17:03           ` Darrick J. Wong
2026-02-25 17:49             ` Christoph Hellwig
2026-02-23 23:01 ` [PATCHSET v7 3/9] fuse: cleanups ahead of adding fuse support Darrick J. Wong
2026-02-23 23:08   ` [PATCH 1/2] fuse: move the passthrough-specific code back to passthrough.c Darrick J. Wong
2026-02-23 23:08   ` [PATCH 2/2] fuse_trace: " Darrick J. Wong
2026-02-23 23:01 ` [PATCHSET v7 4/9] fuse: allow servers to use iomap for better file IO performance Darrick J. Wong
2026-02-23 23:08   ` [PATCH 01/33] fuse: implement the basic iomap mechanisms Darrick J. Wong
2026-02-23 23:09   ` [PATCH 02/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:09   ` [PATCH 03/33] fuse: make debugging configurable at runtime Darrick J. Wong
2026-02-23 23:09   ` [PATCH 04/33] fuse: adapt FUSE_DEV_IOC_BACKING_{OPEN,CLOSE} to add new iomap devices Darrick J. Wong
2026-02-23 23:09   ` [PATCH 05/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:10   ` [PATCH 06/33] fuse: enable SYNCFS and ensure we flush everything before sending DESTROY Darrick J. Wong
2026-02-23 23:10   ` [PATCH 07/33] fuse: clean up per-file type inode initialization Darrick J. Wong
2026-02-23 23:10   ` [PATCH 08/33] fuse: create a per-inode flag for setting exclusive mode Darrick J. Wong
2026-02-23 23:11   ` [PATCH 09/33] fuse: create a per-inode flag for toggling iomap Darrick J. Wong
2026-02-23 23:11   ` [PATCH 10/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:11   ` [PATCH 11/33] fuse: isolate the other regular file IO paths from iomap Darrick J. Wong
2026-02-23 23:11   ` [PATCH 12/33] fuse: implement basic iomap reporting such as FIEMAP and SEEK_{DATA,HOLE} Darrick J. Wong
2026-02-23 23:12   ` [PATCH 13/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:12   ` [PATCH 14/33] fuse: implement direct IO with iomap Darrick J. Wong
2026-02-23 23:12   ` [PATCH 15/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:12   ` [PATCH 16/33] fuse: implement buffered " Darrick J. Wong
2026-02-27 18:04     ` Darrick J. Wong
2026-02-23 23:13   ` [PATCH 17/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:13   ` [PATCH 18/33] fuse: use an unrestricted backing device with iomap pagecache io Darrick J. Wong
2026-02-23 23:13   ` [PATCH 19/33] fuse: implement large folios for iomap pagecache files Darrick J. Wong
2026-02-23 23:13   ` [PATCH 20/33] fuse: advertise support for iomap Darrick J. Wong
2026-02-23 23:14   ` [PATCH 21/33] fuse: query filesystem geometry when using iomap Darrick J. Wong
2026-02-23 23:14   ` [PATCH 22/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:14   ` [PATCH 23/33] fuse: implement fadvise for iomap files Darrick J. Wong
2026-02-23 23:14   ` [PATCH 24/33] fuse: invalidate ranges of block devices being used for iomap Darrick J. Wong
2026-02-23 23:15   ` [PATCH 25/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:15   ` [PATCH 26/33] fuse: implement inline data file IO via iomap Darrick J. Wong
2026-02-27 18:02     ` Darrick J. Wong
2026-02-23 23:15   ` [PATCH 27/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:15   ` [PATCH 28/33] fuse: allow more statx fields Darrick J. Wong
2026-02-23 23:16   ` [PATCH 29/33] fuse: support atomic writes with iomap Darrick J. Wong
2026-02-24 12:58     ` Pankaj Raghav (Samsung)
2026-02-24 19:30       ` Darrick J. Wong
2026-02-24 21:18         ` Pankaj Raghav (Samsung)
2026-02-23 23:16   ` [PATCH 30/33] fuse_trace: " Darrick J. Wong
2026-02-23 23:16   ` [PATCH 31/33] fuse: disable direct fs reclaim for any fuse server that uses iomap Darrick J. Wong
2026-02-23 23:17   ` [PATCH 32/33] fuse: enable swapfile activation on iomap Darrick J. Wong
2026-02-23 23:17   ` [PATCH 33/33] fuse: implement freeze and shutdowns for iomap filesystems Darrick J. Wong
2026-02-23 23:01 ` [PATCHSET v7 5/9] fuse: allow servers to specify root node id Darrick J. Wong
2026-02-23 23:17   ` [PATCH 1/3] fuse: make the root nodeid dynamic Darrick J. Wong
2026-02-23 23:17   ` [PATCH 2/3] fuse_trace: " Darrick J. Wong
2026-02-23 23:18   ` [PATCH 3/3] fuse: allow setting of root nodeid Darrick J. Wong
2026-02-23 23:01 ` [PATCHSET v7 6/9] fuse: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
2026-02-23 23:18   ` [PATCH 1/9] fuse: enable caching of timestamps Darrick J. Wong
2026-02-23 23:18   ` [PATCH 2/9] fuse: force a ctime update after a fileattr_set call when in iomap mode Darrick J. Wong
2026-02-23 23:18   ` [PATCH 3/9] fuse: allow local filesystems to set some VFS iflags Darrick J. Wong
2026-02-23 23:19   ` [PATCH 4/9] fuse_trace: " Darrick J. Wong
2026-02-23 23:19   ` [PATCH 5/9] fuse: cache atime when in iomap mode Darrick J. Wong
2026-02-23 23:19   ` [PATCH 6/9] fuse: let the kernel handle KILL_SUID/KILL_SGID for iomap filesystems Darrick J. Wong
2026-02-23 23:19   ` [PATCH 7/9] fuse_trace: " Darrick J. Wong
2026-02-23 23:20   ` [PATCH 8/9] fuse: update ctime when updating acls on an iomap inode Darrick J. Wong
2026-02-23 23:20   ` [PATCH 9/9] fuse: always cache ACLs when using iomap Darrick J. Wong
2026-02-23 23:02 ` [PATCHSET v7 7/9] fuse: cache iomap mappings for even better file IO performance Darrick J. Wong
2026-02-23 23:20   ` [PATCH 01/12] fuse: cache iomaps Darrick J. Wong
2026-02-27 18:07     ` Darrick J. Wong
2026-02-23 23:20   ` [PATCH 02/12] fuse_trace: " Darrick J. Wong
2026-02-23 23:21   ` [PATCH 03/12] fuse: use the iomap cache for iomap_begin Darrick J. Wong
2026-02-23 23:21   ` [PATCH 04/12] fuse_trace: " Darrick J. Wong
2026-02-23 23:21   ` [PATCH 05/12] fuse: invalidate iomap cache after file updates Darrick J. Wong
2026-02-23 23:21   ` [PATCH 06/12] fuse_trace: " Darrick J. Wong
2026-02-23 23:22   ` [PATCH 07/12] fuse: enable iomap cache management Darrick J. Wong
2026-02-23 23:22   ` [PATCH 08/12] fuse_trace: " Darrick J. Wong
2026-02-23 23:22   ` [PATCH 09/12] fuse: overlay iomap inode info in struct fuse_inode Darrick J. Wong
2026-02-23 23:23   ` [PATCH 10/12] fuse: constrain iomap mapping cache size Darrick J. Wong
2026-02-23 23:23   ` [PATCH 11/12] fuse_trace: " Darrick J. Wong
2026-02-23 23:23   ` [PATCH 12/12] fuse: enable iomap Darrick J. Wong
2026-02-23 23:02 ` [PATCHSET v7 8/9] fuse: run fuse servers as a contained service Darrick J. Wong
2026-02-23 23:23   ` [PATCH 1/2] fuse: allow privileged mount helpers to pre-approve iomap usage Darrick J. Wong
2026-02-23 23:24   ` [PATCH 2/2] fuse: set iomap backing device block size Darrick J. Wong
2026-02-23 23:02 ` [PATCHSET RFC 9/9] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
2026-02-23 23:24   ` [PATCH 1/5] fuse: enable fuse servers to upload BPF programs to handle iomap requests Darrick J. Wong
2026-02-23 23:24   ` [PATCH 2/5] fuse_trace: " Darrick J. Wong
2026-02-23 23:24   ` [PATCH 3/5] fuse: prevent iomap bpf programs from writing to most of the system Darrick J. Wong
2026-02-23 23:25   ` [PATCH 4/5] fuse: add kfuncs for iomap bpf programs to manage the cache Darrick J. Wong
2026-02-23 23:25   ` [PATCH 5/5] fuse: make fuse_inode opaque to iomap bpf programs Darrick J. Wong
2026-02-23 23:02 ` [PATCHSET v7 1/6] libfuse: allow servers to use iomap for better file IO performance Darrick J. Wong
2026-02-23 23:25   ` [PATCH 01/25] libfuse: bump kernel and library ABI versions Darrick J. Wong
2026-02-23 23:25   ` [PATCH 02/25] libfuse: wait in do_destroy until all open files are closed Darrick J. Wong
2026-02-23 23:26   ` [PATCH 03/25] libfuse: add kernel gates for FUSE_IOMAP Darrick J. Wong
2026-02-23 23:26   ` [PATCH 04/25] libfuse: add fuse commands for iomap_begin and end Darrick J. Wong
2026-02-23 23:26   ` [PATCH 05/25] libfuse: add upper level iomap commands Darrick J. Wong
2026-02-23 23:26   ` [PATCH 06/25] libfuse: add a lowlevel notification to add a new device to iomap Darrick J. Wong
2026-02-23 23:27   ` [PATCH 07/25] libfuse: add upper-level iomap add device function Darrick J. Wong
2026-02-23 23:27   ` [PATCH 08/25] libfuse: add iomap ioend low level handler Darrick J. Wong
2026-02-23 23:27   ` [PATCH 09/25] libfuse: add upper level iomap ioend commands Darrick J. Wong
2026-02-23 23:27   ` [PATCH 10/25] libfuse: add a reply function to send FUSE_ATTR_* to the kernel Darrick J. Wong
2026-02-23 23:28   ` [PATCH 11/25] libfuse: connect high level fuse library to fuse_reply_attr_iflags Darrick J. Wong
2026-02-23 23:28   ` [PATCH 12/25] libfuse: support enabling exclusive mode for files Darrick J. Wong
2026-02-23 23:28   ` [PATCH 13/25] libfuse: support direct I/O through iomap Darrick J. Wong
2026-02-23 23:29   ` [PATCH 14/25] libfuse: don't allow hardlinking of iomap files in the upper level fuse library Darrick J. Wong
2026-02-23 23:29   ` [PATCH 15/25] libfuse: allow discovery of the kernel's iomap capabilities Darrick J. Wong
2026-02-23 23:29   ` [PATCH 16/25] libfuse: add lower level iomap_config implementation Darrick J. Wong
2026-02-23 23:29   ` [PATCH 17/25] libfuse: add upper " Darrick J. Wong
2026-02-23 23:30   ` [PATCH 18/25] libfuse: add low level code to invalidate iomap block device ranges Darrick J. Wong
2026-02-23 23:30   ` [PATCH 19/25] libfuse: add upper-level API to invalidate parts of an iomap block device Darrick J. Wong
2026-02-23 23:30   ` [PATCH 20/25] libfuse: add atomic write support Darrick J. Wong
2026-02-23 23:30   ` [PATCH 21/25] libfuse: allow disabling of fs memory reclaim and write throttling Darrick J. Wong
2026-02-23 23:31   ` [PATCH 22/25] libfuse: create a helper to transform an open regular file into an open loopdev Darrick J. Wong
2026-02-23 23:31   ` [PATCH 23/25] libfuse: add swapfile support for iomap files Darrick J. Wong
2026-02-23 23:31   ` [PATCH 24/25] libfuse: add lower-level filesystem freeze, thaw, and shutdown requests Darrick J. Wong
2026-02-23 23:31   ` [PATCH 25/25] libfuse: add upper-level filesystem freeze, thaw, and shutdown events Darrick J. Wong
2026-02-23 23:03 ` [PATCHSET v7 2/6] libfuse: allow servers to specify root node id Darrick J. Wong
2026-02-23 23:32   ` [PATCH 1/1] libfuse: allow root_nodeid mount option Darrick J. Wong
2026-02-23 23:03 ` [PATCHSET v7 3/6] libfuse: implement syncfs Darrick J. Wong
2026-02-23 23:32   ` [PATCH 1/2] libfuse: add strictatime/lazytime mount options Darrick J. Wong
2026-02-23 23:32   ` [PATCH 2/2] libfuse: set sync, immutable, and append when loading files Darrick J. Wong
2026-02-23 23:03 ` [PATCHSET v7 4/6] libfuse: cache iomap mappings for even better file IO performance Darrick J. Wong
2026-02-23 23:32   ` [PATCH 1/5] libfuse: enable iomap cache management for lowlevel fuse Darrick J. Wong
2026-02-23 23:33   ` [PATCH 2/5] libfuse: add upper-level iomap cache management Darrick J. Wong
2026-02-23 23:33   ` [PATCH 3/5] libfuse: allow constraining of iomap mapping cache size Darrick J. Wong
2026-02-23 23:33   ` [PATCH 4/5] libfuse: add upper-level iomap mapping cache constraint code Darrick J. Wong
2026-02-23 23:33   ` [PATCH 5/5] libfuse: enable iomap Darrick J. Wong
2026-02-23 23:03 ` [PATCHSET v7 5/6] libfuse: run fuse servers as a contained service Darrick J. Wong
2026-02-23 23:34   ` [PATCH 1/5] libfuse: add systemd/inetd socket service mounting helper Darrick J. Wong
2026-02-23 23:34   ` [PATCH 2/5] libfuse: integrate fuse services into mount.fuse3 Darrick J. Wong
2026-02-23 23:34   ` [PATCH 3/5] libfuse: delegate iomap privilege from mount.service to fuse services Darrick J. Wong
2026-02-23 23:34   ` [PATCH 4/5] libfuse: enable setting iomap block device block size Darrick J. Wong
2026-02-23 23:35   ` [PATCH 5/5] fuservicemount: create loop devices for regular files Darrick J. Wong
2026-02-23 23:04 ` [PATCHSET RFC 6/6] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
2026-02-23 23:35   ` [PATCH 1/3] libfuse: allow fuse servers to upload bpf code for iomap functions Darrick J. Wong
2026-02-23 23:35   ` [PATCH 2/3] libfuse: add kfuncs for iomap bpf programs to manage the cache Darrick J. Wong
2026-02-23 23:36   ` [PATCH 3/3] libfuse: make fuse_inode opaque to iomap bpf programs Darrick J. Wong
2026-02-23 23:04 ` [PATCHSET v7 1/8] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
2026-02-23 23:36   ` [PATCH 01/19] fuse2fs: implement bare minimum iomap for file mapping reporting Darrick J. Wong
2026-02-23 23:36   ` [PATCH 02/19] fuse2fs: add iomap= mount option Darrick J. Wong
2026-02-23 23:36   ` [PATCH 03/19] fuse2fs: implement iomap configuration Darrick J. Wong
2026-02-23 23:37   ` [PATCH 04/19] fuse2fs: register block devices for use with iomap Darrick J. Wong
2026-02-23 23:37   ` [PATCH 05/19] fuse2fs: implement directio file reads Darrick J. Wong
2026-02-23 23:37   ` [PATCH 06/19] fuse2fs: add extent dump function for debugging Darrick J. Wong
2026-02-23 23:37   ` [PATCH 07/19] fuse2fs: implement direct write support Darrick J. Wong
2026-02-23 23:38   ` [PATCH 08/19] fuse2fs: turn on iomap for pagecache IO Darrick J. Wong
2026-02-23 23:38   ` [PATCH 09/19] fuse2fs: don't zero bytes in punch hole Darrick J. Wong
2026-02-23 23:38   ` [PATCH 10/19] fuse2fs: don't do file data block IO when iomap is enabled Darrick J. Wong
2026-02-23 23:38   ` [PATCH 11/19] fuse2fs: try to create loop device when ext4 device is a regular file Darrick J. Wong
2026-02-23 23:39   ` [PATCH 12/19] fuse2fs: enable file IO to inline data files Darrick J. Wong
2026-02-23 23:39   ` [PATCH 13/19] fuse2fs: set iomap-related inode flags Darrick J. Wong
2026-02-23 23:39   ` [PATCH 14/19] fuse2fs: configure block device block size Darrick J. Wong
2026-02-23 23:39   ` [PATCH 15/19] fuse4fs: separate invalidation Darrick J. Wong
2026-02-23 23:40   ` [PATCH 16/19] fuse2fs: implement statx Darrick J. Wong
2026-02-23 23:40   ` [PATCH 17/19] fuse2fs: enable atomic writes Darrick J. Wong
2026-02-23 23:40   ` [PATCH 18/19] fuse4fs: disable fs reclaim and write throttling Darrick J. Wong
2026-02-23 23:41   ` [PATCH 19/19] fuse2fs: implement freeze and shutdown requests Darrick J. Wong
2026-02-23 23:04 ` [PATCHSET v7 2/8] fuse4fs: specify the root node id Darrick J. Wong
2026-02-23 23:41   ` [PATCH 1/1] fuse4fs: don't use inode number translation when possible Darrick J. Wong
2026-02-23 23:05 ` [PATCHSET v7 3/8] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
2026-02-23 23:41   ` [PATCH 01/10] fuse2fs: add strictatime/lazytime mount options Darrick J. Wong
2026-02-23 23:41   ` [PATCH 02/10] fuse2fs: skip permission checking on utimens when iomap is enabled Darrick J. Wong
2026-02-23 23:42   ` [PATCH 03/10] fuse2fs: let the kernel tell us about acl/mode updates Darrick J. Wong
2026-02-23 23:42   ` [PATCH 04/10] fuse2fs: better debugging for file mode updates Darrick J. Wong
2026-02-23 23:42   ` [PATCH 05/10] fuse2fs: debug timestamp updates Darrick J. Wong
2026-02-23 23:42   ` [PATCH 06/10] fuse2fs: use coarse timestamps for iomap mode Darrick J. Wong
2026-02-23 23:43   ` [PATCH 07/10] fuse2fs: add tracing for retrieving timestamps Darrick J. Wong
2026-02-23 23:43   ` [PATCH 08/10] fuse2fs: enable syncfs Darrick J. Wong
2026-02-23 23:43   ` [PATCH 09/10] fuse2fs: set sync, immutable, and append at file load time Darrick J. Wong
2026-02-23 23:43   ` [PATCH 10/10] fuse4fs: increase attribute timeout in iomap mode Darrick J. Wong
2026-02-23 23:05 ` [PATCHSET v7 4/8] fuse2fs: cache iomap mappings for even better file IO performance Darrick J. Wong
2026-02-23 23:44   ` [PATCH 1/3] fuse2fs: enable caching of iomaps Darrick J. Wong
2026-02-23 23:44   ` [PATCH 2/3] fuse2fs: constrain iomap mapping cache size Darrick J. Wong
2026-02-23 23:44   ` [PATCH 3/3] fuse2fs: enable iomap Darrick J. Wong
2026-02-23 23:05 ` [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
2026-02-23 23:44   ` [PATCH 1/6] libsupport: add caching IO manager Darrick J. Wong
2026-02-23 23:45   ` [PATCH 2/6] iocache: add the actual buffer cache Darrick J. Wong
2026-02-23 23:45   ` [PATCH 3/6] iocache: bump buffer mru priority every 50 accesses Darrick J. Wong
2026-02-23 23:45   ` [PATCH 4/6] fuse2fs: enable caching IO manager Darrick J. Wong
2026-02-23 23:45   ` [PATCH 5/6] fuse2fs: increase inode cache size Darrick J. Wong
2026-02-23 23:46   ` [PATCH 6/6] libext2fs: improve caching for inodes Darrick J. Wong
2026-02-23 23:05 ` [PATCHSET v7 6/8] fuse4fs: run servers as a contained service Darrick J. Wong
2026-02-23 23:46   ` [PATCH 1/8] libext2fs: fix MMP code to work with unixfd IO manager Darrick J. Wong
2026-02-23 23:46   ` [PATCH 2/8] fuse4fs: enable safe service mode Darrick J. Wong
2026-02-23 23:47   ` [PATCH 3/8] fuse4fs: set proc title when in fuse " Darrick J. Wong
2026-02-23 23:47   ` [PATCH 4/8] fuse4fs: upsert first file mapping to kernel on open Darrick J. Wong
2026-02-23 23:47   ` [PATCH 5/8] fuse4fs: set iomap backing device blocksize Darrick J. Wong
2026-02-23 23:47   ` [PATCH 6/8] fuse4fs: ask for loop devices when opening via fuservicemount Darrick J. Wong
2026-02-23 23:48   ` [PATCH 7/8] fuse4fs: make MMP work correctly in safe service mode Darrick J. Wong
2026-02-23 23:48   ` [PATCH 8/8] debian: update packaging for fuse4fs service Darrick J. Wong
2026-02-23 23:06 ` [PATCHSET v7 7/8] fuse4fs: reclaim buffer cache under memory pressure Darrick J. Wong
2026-02-23 23:48   ` [PATCH 1/4] libsupport: add pressure stall monitor Darrick J. Wong
2026-02-23 23:48   ` [PATCH 2/4] fuse2fs: only reclaim buffer cache when there is memory pressure Darrick J. Wong
2026-02-23 23:49   ` [PATCH 3/4] fuse4fs: enable memory pressure monitoring with service containers Darrick J. Wong
2026-02-23 23:49   ` [PATCH 4/4] fuse2fs: flush dirty metadata periodically Darrick J. Wong
2026-02-23 23:06 ` [PATCHSET RFC 8/8] fuse: allow fuse servers to upload iomap BPF programs Darrick J. Wong
2026-02-23 23:49   ` [PATCH 1/3] fuse4fs: add dynamic iomap bpf prototype which will break FIEMAP Darrick J. Wong
2026-02-23 23:49   ` [PATCH 2/3] fuse4fs: wire up caching examples to fuse iomap bpf program Darrick J. Wong
2026-02-23 23:50   ` [PATCH 3/3] fuse4fs: adjust test bpf program to deal with opaque inodes Darrick J. Wong
2026-03-16 17:56 ` [PATCHBLIZZARD v7] fuse/libfuse/e2fsprogs: containerize ext4 for safer operation Joanne Koong
2026-03-16 18:04   ` Darrick J. Wong
2026-03-16 23:08     ` Joanne Koong
2026-03-16 23:41       ` Darrick J. Wong
2026-03-17  0:20         ` Demi Marie Obenour
2026-03-17 13:59           ` Theodore Tso
2026-03-17 14:05             ` Demi Marie Obenour
2026-03-17 15:20               ` Theodore Tso
2026-03-18 21:31           ` Darrick J. Wong
2026-03-19  7:28             ` Demi Marie Obenour
2026-03-19 16:08               ` Darrick J. Wong
2026-03-20 17:04                 ` Joanne Koong
2026-03-20 20:31                   ` Darrick J. Wong
2026-03-17  0:10       ` Demi Marie Obenour
  -- strict thread matches above, loose matches on Subject: below --
2025-10-29  0:37 [PATCHSET v6 1/8] fuse: general bug fixes Darrick J. Wong
2025-10-29  0:43 ` [PATCH 3/5] fuse: implement file attributes mask for statx Darrick J. Wong
2025-11-03 18:30   ` Joanne Koong
2025-11-03 18:43     ` Joanne Koong
2025-11-03 19:28       ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox