[PATCH 11/19] fuse2fs: avoid fuseblk mode if fuse-iomap support is likely

Darrick J. Wong
2025-08-21T01:18:35Z

Since fuse in iomap mode guarantees that op_destroy will be called
before umount returns, we don't need to use fuseblk mode to get that
guarantee. Disable fuseblk mode, which saves us the trouble of closing
and reopening the device.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
misc/fuse2fs.c | 20 +++++++++++++++++++-
misc/fuse4fs.c | 20 +++++++++++++++++++-
2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 588b0053f43c95..97b010b8dc1055 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -275,6 +275,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;
@@ -1056,6 +1057,8 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff, int libext2_flags)
if (ff->directio)
flags |= EXT2_FLAG_DIRECT_IO;

+ dbg_printf(ff, "opening with flags=0x%x\n", flags);
+
err = ext2fs_open2(ff->device, options, flags, 0, 0, unix_io_manager,
&ff->fs);
if (err == EPERM) {
@@ -6527,6 +6530,19 @@ static unsigned long long default_cache_size(void)
return ret;
}

+#ifdef HAVE_FUSE_IOMAP
+static inline bool fuse2fs_discover_iomap(struct fuse2fs *ff)
+{
+ if (ff->iomap_want == FT_DISABLE)
+ return false;
+
+ ff->iomap_cap = fuse_lowlevel_discover_iomap();
+ return ff->iomap_cap & FUSE_IOMAP_SUPPORT_FILEIO;
+}
+#else
+# define fuse2fs_discover_iomap(...) (false)
+#endif
+
static inline bool fuse2fs_want_fuseblk(const struct fuse2fs *ff)
{
if (ff->noblkdev)
@@ -6567,6 +6583,7 @@ int main(int argc, char *argv[])
errcode_t err;
FILE *orig_stderr = stderr;
char extra_args[BUFSIZ];
+ bool iomap_detected = false;
int ret;

ret = fuse_opt_parse(&args, &fctx, fuse2fs_opts, fuse2fs_opt_proc);
@@ -6637,7 +6654,8 @@ int main(int argc, char *argv[])
goto out;
}

- if (fuse2fs_want_fuseblk(&fctx)) {
+ iomap_detected = fuse2fs_discover_iomap(&fctx);
+ if (!iomap_detected && fuse2fs_want_fuseblk(&fctx)) {
/*
* If this is a block device, we want to close the fs, reopen
* the block device in non-exclusive mode, and start the fuse
diff --git a/misc/fuse4fs.c b/misc/fuse4fs.c
index e08c5af5abfd27..3bb6140b35570e 100644
--- a/misc/fuse4fs.c
+++ b/misc/fuse4fs.c
@@ -270,6 +270,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;
@@ -1233,6 +1234,8 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff, int libext2_flags)
if (ff->directio)
flags |= EXT2_FLAG_DIRECT_IO;

+ dbg_printf(ff, "opening with flags=0x%x\n", flags);
+
err = ext2fs_open2(ff->device, options, flags, 0, 0, unix_io_manager,
&ff->fs);
if (err == EPERM) {
@@ -6862,6 +6865,19 @@ static unsigned long long default_cache_size(void)
return ret;
}

+#ifdef HAVE_FUSE_IOMAP
+static inline bool fuse4fs_discover_iomap(struct fuse4fs *ff)
+{
+ if (ff->iomap_want == FT_DISABLE)
+ return false;
+
+ ff->iomap_cap = fuse_lowlevel_discover_iomap();
+ return ff->iomap_cap & FUSE_IOMAP_SUPPORT_FILEIO;
+}
+#else
+# define fuse4fs_discover_iomap(...) (false)
+#endif
+
static inline bool fuse4fs_want_fuseblk(const struct fuse4fs *ff)
{
if (ff->noblkdev)
@@ -7002,6 +7018,7 @@ int main(int argc, char *argv[])
errcode_t err;
FILE *orig_stderr = stderr;
char extra_args[BUFSIZ];
+ bool iomap_detected = false;
int ret;

ret = fuse_opt_parse(&args, &fctx, fuse4fs_opts, fuse4fs_opt_proc);
@@ -7072,7 +7089,8 @@ int main(int argc, char *argv[])
goto out;
}

- if (fuse4fs_want_fuseblk(&fctx)) {
+ iomap_detected = fuse4fs_discover_iomap(&fctx);
+ if (!iomap_detected && fuse4fs_want_fuseblk(&fctx)) {
/*
* If this is a block device, we want to close the fs, reopen
* the block device in non-exclusive mode, and start the fuse