[PATCH 15/18] libfuse: add upper level iomap_config implementation

Darrick J. Wong
2025-09-16T00:45:42Z

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 4c4fff837437c8..74b86e8d27fb35 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -896,6 +896,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 cbf2c5d3a67895..177c524eff736b 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2937,6 +2937,23 @@ static int fuse_fs_iomap_ioend(struct fuse_fs *fs, const char *path,
ioendflags, error, new_addr);
}

+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%x maxbytes %lld\n",
+ 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)
{
@@ -4791,6 +4808,25 @@ static void fuse_lib_iomap_ioend(fuse_req_t req, fuse_ino_t nodeid,
reply_err(req, err);
}

+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)
{
/*
@@ -4895,6 +4931,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)