[PATCH 18/18] libfuse: add atomic write support

Darrick J. Wong
2025-09-16T00:46:28Z

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 59b79b44a36e8d..eb08320bc8863f 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
@@ -1232,6 +1234,8 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,
#define FUSE_IFLAG_DAX (1U << 0)
/* use iomap for this inode */
#define FUSE_IFLAG_IOMAP (1U << 1)
+/* enable untorn writes */
+#define FUSE_IFLAG_ATOMIC (1U << 2)

/* 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 861c3d449db788..ed41792f94cf4f 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -241,6 +241,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
@@ -582,10 +583,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_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_IOMAP (1 << 2)
+#define FUSE_ATTR_ATOMIC (1 << 3)

/**
* Open flags
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 166bd82eca463b..6108b1862a7eb8 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -126,6 +126,8 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr,
attr->flags |= FUSE_ATTR_DAX;
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)