[PATCH 02/17] fuse2fs: add iomap= mount option

Darrick J. Wong
2025-09-16T00:59:15Z

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 bf9c2081702132..2d7b40911ce0f7 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -223,6 +223,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 logfd;
int blocklog;
#ifdef HAVE_FUSE_IOMAP
+ enum fuse4fs_feature_toggle iomap_want;
enum fuse4fs_iomap_state iomap_state;
#endif
unsigned int blockmask;
@@ -1539,6 +1546,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)
@@ -5981,6 +5994,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 }
@@ -6012,6 +6028,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),
@@ -6063,6 +6083,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:
@@ -6090,6 +6127,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) {
@@ -6282,6 +6322,7 @@ int main(int argc, char *argv[])
.opstate = F4OP_WRITABLE,
.logfd = -1,
#ifdef HAVE_FUSE_IOMAP
+ .iomap_want = FT_DEFAULT,
.iomap_state = IOMAP_UNKNOWN,
#endif
};
@@ -6299,6 +6340,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 ca61fbc89f5fda..95d3dedbdb8b80 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -216,6 +216,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 logfd;
int blocklog;
#ifdef HAVE_FUSE_IOMAP
+ enum fuse2fs_feature_toggle iomap_want;
enum fuse2fs_iomap_state iomap_state;
#endif
unsigned int blockmask;
@@ -1345,6 +1352,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)
@@ -5419,6 +5432,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 }
@@ -5450,6 +5466,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),
@@ -5501,6 +5521,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:
@@ -5528,6 +5565,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) {
@@ -5620,6 +5660,7 @@ int main(int argc, char *argv[])
.opstate = F2OP_WRITABLE,
.logfd = -1,
#ifdef HAVE_FUSE_IOMAP
+ .iomap_want = FT_DEFAULT,
.iomap_state = IOMAP_UNKNOWN,
#endif
};
@@ -5637,6 +5678,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)