Skip to contentSkip to conversation

fuse/libfuse/e2fsprogs: faster file IO for containerized ext4 servers

PATCH New Darrick J. Wong 4 participants 59 messages May 19 – Jun 10

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH v9 1/1 fuse/libfuse/e2fsprogs: faster file IO for containerized ext4 servers

Hi everyone,

This is the ninth 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.

This effort is now separate from the one to run fuse servers in a constrained environment via systemd. Putting fuse servers in a container gets you all the blast radii reduction advantages and provides a pathway to removing less popular filesystem drivers to reduce maintenance work in the kernel; now we want trade relaxation of that isolation for better performance.

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!

This series has been rebased to 7.1-rc4 since the eighth RFC, with the following kernel changes:

1. The BPF stuff has been replaced with a filesystem striping mechanism. This is my first attempt ever to implement raid0.

2. Much tightening of the validation code based on Codex reviews so that we don't expose more "ABI" than we feel like getting yelled at for in 2031.

3. Refactored iomap writeback mapping so that you can use the standard iomap_begin functions for that.

4. Better userspace helpers so that fuse server authors don't have to know quite so much detail of the innards.

5. The libfuse changes are based off the WIP fuse-service-container branch.

There are some questions remaining:

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

b. I've dropped everything but the kernel patches for basic plumbing and
file IO paths because frankly they weren't getting looked at.

c. How on earth am I going to separate out the file_operations?
Will it actually work to say that fuse-iomap only supports local filesystems initially? How many of the "is_iomap?" predicates are actually for local filesystems and not the IO path???

I would like to any part of this submission reviewed for 7.2 now that this has been collecting comments and tweaks in non-rfc status for 6 months.

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

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

e2fsprogs:
https://git.kernel.org/pub/scm/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse4fs-memory-reclaim

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

--Darrick

#1 lore raw

PATCH v9 1/4 fuse: cleanups ahead of adding fuse support

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: store backing id in fuse_backing objects
* fuse_trace: move the passthrough-specific code back to passthrough.c
* fuse: clean up per-file type inode initialization

---
 fs/fuse/fuse_i.h          |   30 +++++++++--
 fs/fuse/fuse_trace.h      |   33 ++++++++++++
 include/uapi/linux/fuse.h |    8 +++
 fs/fuse/Kconfig           |    4 +
 fs/fuse/Makefile          |    3 +
 fs/fuse/backing.c         |  126 +++++++++++++++++++++++++++++++++++----------
 fs/fuse/dev.c             |    4 +
 fs/fuse/file.c            |    5 +-
 fs/fuse/inode.c           |   40 ++++++++++----
 fs/fuse/passthrough.c     |   38 +++++++++++++-
 10 files changed, 240 insertions(+), 51 deletions(-)
#14 lore raw

PATCH v9 2/4 fuse: basic plumbing to upload file mappings from servers

In reply to Darrick J. Wong

Hi all,

It is desirable to connect fuse (the userspace filesystem layer) to fs-iomap to get fuse servers out of the business of handling file I/O themselves. The easiest way to do this is to reuse the (newish) vfs iomap library that manages pagecache and direct IO. The first part of this work adds the piping necessary to get a mapping from the fuse server and release it when work has completed.

Note that although this series creates the basic plumbing for moving file mappings around the system, there's still a lot more that needs to be configured.

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-plumbing
---
Commits in this patchset:
* fuse: implement the basic iomap mechanisms
* fuse_trace: implement the basic iomap mechanisms
* fuse: make iomap 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: 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}

---
 fs/fuse/fuse_i.h          |   47 +++
 fs/fuse/fuse_iomap.h      |   49 +++
 fs/fuse/fuse_iomap_i.h    |   45 +++
 fs/fuse/fuse_trace.h      |  402 +++++++++++++++++++++++-
 include/uapi/linux/fuse.h |  120 +++++++
 fs/fuse/Kconfig           |   48 +++
 fs/fuse/Makefile          |    1 
 fs/fuse/backing.c         |   52 +++
 fs/fuse/dir.c             |   29 +-
 fs/fuse/file.c            |   40 ++
 fs/fuse/fuse_iomap.c      |  766 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |   41 ++
 fs/fuse/iomode.c          |    3 
 fs/fuse/trace.c           |    2 
 14 files changed, 1620 insertions(+), 25 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
#29 lore raw

PATCH v9 3/4 fuse: allow servers to use iomap for better file IO performance

In reply to Darrick J. Wong

Hi all,

Now that we've gotten the basic mapping plumbing installed, it's time to actually 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 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: implement inline data file IO via iomap
* fuse_trace: implement inline data file IO via iomap

---
 fs/fuse/fuse_i.h          |   18 +
 fs/fuse/fuse_iomap.h      |   37 +
 fs/fuse/fuse_trace.h      |  526 ++++++++++++++++++
 include/uapi/linux/fuse.h |   29 +
 fs/fuse/dev.c             |   10 
 fs/fuse/dir.c             |   36 +
 fs/fuse/file.c            |   83 ++-
 fs/fuse/fuse_iomap.c      | 1320 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |    2 
 fs/fuse/iomode.c          |    2 
 fs/fuse/trace.c           |    2 
 11 files changed, 2033 insertions(+), 32 deletions(-)
#36 lore raw

PATCH v9 4/4 fuse: discovery and configuration of iomap

In reply to Darrick J. Wong

Hi all,

Now that we have established the key file IO codepaths with iomap, we need a mechanism for fuse servers to detect if the running kernel driver supports iomap. If the fuse server indicates that it wants iomap, the kernel driver can then ask the server about what sort of behaviors it wants.

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-config
---
Commits in this patchset:
* fuse: advertise support for iomap
* fuse: query filesystem geometry when using iomap
* fuse_trace: query filesystem geometry when using iomap
* fuse: use an unrestricted backing device with iomap pagecache io
* fuse: disable direct fs reclaim for any fuse server that uses iomap
* fuse: allow privileged mount helpers to pre-approve iomap usage
* fuse: invalidate ranges of backing devices being used for iomap
* fuse_trace: invalidate ranges of block devices being used for iomap
* fuse: set iomap backing device block size

---
 fs/fuse/fuse_i.h                                   |   17 +
 fs/fuse/fuse_iomap.h                               |   19 +
 fs/fuse/fuse_trace.h                               |   74 ++++
 include/uapi/linux/fuse.h                          |   78 ++++
 Documentation/userspace-api/ioctl/ioctl-number.rst |    2 
 fs/fuse/dev.c                                      |   37 ++
 fs/fuse/fuse_iomap.c                               |  417 ++++++++++++++++++++
 fs/fuse/inode.c                                    |   46 ++
 mm/page-writeback.c                                |    1 
 9 files changed, 680 insertions(+), 11 deletions(-)
#2 lore raw

PATCH 1/4 fuse: move the passthrough-specific code back to passthrough.c

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_i.h          |   26 +++++++++-
 include/uapi/linux/fuse.h |    8 +++
 fs/fuse/Kconfig           |    4 ++
 fs/fuse/Makefile          |    3 +
 fs/fuse/backing.c         |  113 ++++++++++++++++++++++++++++++++++-----------
 fs/fuse/dev.c             |    4 +-
 fs/fuse/inode.c           |    4 +-
 fs/fuse/passthrough.c     |   38 +++++++++++++++
 8 files changed, 162 insertions(+), 38 deletions(-)
fs/fuse/fuse_i.h +23 -3
index 0b9c617ee3e5be..7f9939df81e3f9 100644
@@ -103,10 +103,24 @@ struct fuse_submount_lookup {
 	struct fuse_forget_link *forget;
 };
 
+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, const struct fuse_backing *fb);
+	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;
@@ -980,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
@@ -1591,10 +1605,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)
@@ -1649,6 +1665,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,
include/uapi/linux/fuse.h +7 -1
index c13e1f9a2f12bd..18713cfaf09171 100644
@@ -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;
 };
 
fs/fuse/Kconfig +4 -0
index 3a4ae632c94aa8..290d1c09e0b924 100644
@@ -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
fs/fuse/Makefile +2 -1
index 22ad9538dfc4b8..46041228e5be2c 100644
@@ -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
 
fs/fuse/backing.c +85 -28

212 lines not on this page · raw message

fs/fuse/dev.c +2 -2
index 2ff09d9f101d00..2708e17bc46949 100644
@@ -2644,7 +2644,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)))
@@ -2661,7 +2661,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))
fs/fuse/inode.c +2 -2
index b43e4bf4a1c117..c04d9ae42bb008 100644
@@ -1034,7 +1034,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);
@@ -1074,7 +1074,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);
 }
fs/fuse/passthrough.c +37 -1
index f2d08ac2459b7e..a3ea9b9eb903d5 100644
@@ -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,
+};
#8 lore raw

PATCH 2/4 fuse: store backing id in fuse_backing objects

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Make fuse_backing objects know their own id, it'll make tracing and recovery of backing ids easier later on.

---
 fs/fuse/fuse_i.h  |    2 ++
 fs/fuse/backing.c |   12 ++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
fs/fuse/fuse_i.h +2 -0
index 7f9939df81e3f9..b0a11a31bb5955 100644
@@ -122,6 +122,8 @@ struct fuse_backing {
 	struct cred *cred;
 	const struct fuse_backing_ops *ops;
 
+	int id;
+
 	/** refcount */
 	refcount_t count;
 	struct rcu_head rcu;
fs/fuse/backing.c +10 -2
index 4f86f3ca13fd40..217facf3f408a4 100644
@@ -40,15 +40,22 @@ void fuse_backing_files_init(struct fuse_conn *fc)
 
 static int fuse_backing_id_alloc(struct fuse_conn *fc, struct fuse_backing *fb)
 {
+	const unsigned long max =
+		fb->ops->id_end > 0 ? fb->ops->id_end - 1 : INT_MAX;
 	int id;
 
 	WARN_ON_ONCE(fb->ops->id_start < 1);
+	fb->id = fb->ops->id_start;
 
 	idr_preload(GFP_KERNEL);
 	spin_lock(&fc->lock);
 	/* FIXME: xarray might be space inefficient */
-	id = idr_alloc_cyclic(&fc->backing_files_map, fb, fb->ops->id_start,
-			      fb->ops->id_end, GFP_ATOMIC);
+	id = idr_alloc_u32(&fc->backing_files_map, fb, &fb->id, max,
+			   GFP_ATOMIC);
+	if (id < 0)
+		fb->id = -1;
+	else
+		id = fb->id;
 	spin_unlock(&fc->lock);
 	idr_preload_end();
 
@@ -147,6 +154,7 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 	fb->file = file;
 	fb->cred = prepare_creds();
 	fb->ops = ops;
+	fb->id = -1;
 	refcount_set(&fb->count, 1);
 
 	res = fuse_backing_id_alloc(fc, fb);
#12 lore raw

PATCH 3/4 fuse_trace: move the passthrough-specific code back to passthrough.c

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_trace.h |   33 +++++++++++++++++++++++++++++++++
 fs/fuse/backing.c    |    7 +++++++
 2 files changed, 40 insertions(+)
fs/fuse/fuse_trace.h +33 -0
index bbe9ddd8c71696..3b28ec736d4d60 100644
@@ -124,6 +124,39 @@ TRACE_EVENT(fuse_request_end,
 		  __entry->unique, __entry->len, __entry->error)
 );
 
+#ifdef CONFIG_FUSE_BACKING
+DECLARE_EVENT_CLASS(fuse_backing_class,
+	TP_PROTO(const struct fuse_conn *fc, const struct fuse_backing *fb),
+
+	TP_ARGS(fc, fb),
+
+	TP_STRUCT__entry(
+		__field(dev_t,			connection)
+		__field(int,			id)
+		__field(unsigned long,		ino)
+	),
+
+	TP_fast_assign(
+		struct inode *inode = file_inode(fb->file);
+
+		__entry->connection	=	fc->dev;
+		__entry->id		=	fb->id;
+		__entry->ino		=	inode->i_ino;
+	),
+
+	TP_printk("connection %u id %d ino 0x%lx",
+		  __entry->connection,
+		  __entry->id,
+		  __entry->ino)
+);
+#define DEFINE_FUSE_BACKING_EVENT(name)		\
+DEFINE_EVENT(fuse_backing_class, name,		\
+	TP_PROTO(const struct fuse_conn *fc, const struct fuse_backing *fb), \
+	TP_ARGS(fc, 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
fs/fuse/backing.c +7 -0
index 217facf3f408a4..8bfc85a45642c0 100644
@@ -89,6 +89,9 @@ 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);
+
+	trace_fuse_backing_close((struct fuse_conn *)data, fb);
+
 	fuse_backing_free(fb);
 	return 0;
 }
@@ -163,6 +166,8 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 		fb = NULL;
 		goto out;
 	}
+
+	trace_fuse_backing_open(fc, fb);
 out:
 	pr_debug("%s: fb=0x%p, ret=%i\n", __func__, fb, res);
 
@@ -216,6 +221,8 @@ int fuse_backing_close(struct fuse_conn *fc, int backing_id)
 	if (err)
 		goto out_fb;
 
+	trace_fuse_backing_close(fc, fb);
+
 	/* drop the backing id cache's refcount */
 	fuse_backing_put(fb);
 out_fb:
#13 lore raw

PATCH 4/4 fuse: clean up per-file type inode initialization

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_i.h |    2 +-
 fs/fuse/file.c   |    5 +++--
 fs/fuse/inode.c  |   36 +++++++++++++++++++++++++-----------
 3 files changed, 29 insertions(+), 14 deletions(-)
fs/fuse/fuse_i.h +1 -1
index b0a11a31bb5955..de27949d31a72a 100644
@@ -1226,7 +1226,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
fs/fuse/file.c +3 -2
index c59452d60b8da0..5e7fe7ef87d2e4 100644
@@ -3199,11 +3199,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)
@@ -3217,5 +3218,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);
 }
fs/fuse/inode.c +25 -11
index c04d9ae42bb008..afaabc1734d8cf 100644
@@ -421,6 +421,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)
 {
@@ -428,20 +434,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.
#15 lore raw

PATCH 1/11 fuse: implement the basic iomap mechanisms

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

---
 fs/fuse/fuse_i.h          |    5 -
 fs/fuse/fuse_iomap.h      |   26 +++
 fs/fuse/fuse_iomap_i.h    |   28 +++
 include/uapi/linux/fuse.h |  105 +++++++++++
 fs/fuse/Kconfig           |   32 +++
 fs/fuse/Makefile          |    1 
 fs/fuse/fuse_iomap.c      |  445 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |   15 ++
 8 files changed, 655 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
fs/fuse/fuse_i.h +4 -1
index de27949d31a72a..82603e8969a9db 100644
@@ -940,6 +940,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;
 
@@ -1061,7 +1064,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);
 }
fs/fuse/fuse_iomap.h new file +26 -0
new file mode 100644
index 00000000000000..6c71318365ca82
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <[email protected]>
+ */
+#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 */
fs/fuse/fuse_iomap_i.h new file +28 -0
new file mode 100644
index 00000000000000..2897049637fad2
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025-2026 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <[email protected]>
+ */
+#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 */
include/uapi/linux/fuse.h +104 -1

139 lines not on this page · raw message

fs/fuse/Kconfig +32 -0
index 290d1c09e0b924..934d48076a010c 100644
@@ -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
fs/fuse/Makefile +1 -0
index 46041228e5be2c..2536bc6a71b898 100644
@@ -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
fs/fuse/fuse_iomap.c new file +445 -0

445 lines not on this page · raw message

fs/fuse/inode.c +15 -0
index afaabc1734d8cf..fdf5414c24160b 100644
@@ -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>
@@ -1503,6 +1504,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;
@@ -1572,6 +1579,14 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)
 	if (fuse_uring_enabled())
 		flags |= FUSE_OVER_IO_URING;
 
+	/*
+	 * iomap requires that all nodeids share the same struct inode so that
+	 * locking works correctly.  This is not compatible with creating
+	 * shadow inode objects for a submount.
+	 */
+	if (fuse_iomap_enabled() && !(flags & FUSE_SUBMOUNTS))
+		flags |= FUSE_IOMAP;
+
 	ia->in.flags = flags;
 	ia->in.flags2 = flags >> 32;
 
#19 lore raw

PATCH 2/11 fuse_trace: implement the basic iomap mechanisms

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 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(-)
fs/fuse/fuse_iomap_i.h +6 -0
index 2897049637fad2..b9ab8ce140e8e1 100644
@@ -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 */
fs/fuse/fuse_trace.h +295 -0

313 lines not on this page · raw message

fs/fuse/fuse_iomap.c +13 -2
index 9650c6452126ea..201577812d007f 100644
@@ -338,6 +338,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);
+
 	/* Not very useful until we can cache mappings in the kernel */
 	if (opflags & IOMAP_NOWAIT)
 		return -EAGAIN;
@@ -351,8 +353,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)
@@ -419,6 +426,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;
@@ -432,8 +441,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;
#20 lore raw

PATCH 3/11 fuse: make iomap debugging configurable at runtime

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_iomap_i.h |   17 ++++++++++++++---
 fs/fuse/Kconfig        |   15 +++++++++++++++
 fs/fuse/fuse_iomap.c   |   42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 3 deletions(-)
fs/fuse/fuse_iomap_i.h +14 -3
index b9ab8ce140e8e1..c37a7c5cfc862f 100644
@@ -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)
fs/fuse/Kconfig +15 -0
index 934d48076a010c..1b8990f1c2a8f9 100644
@@ -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
fs/fuse/fuse_iomap.c +42 -0

48 lines not on this page · raw message

#21 lore raw

PATCH 4/11 fuse: adapt FUSE_DEV_IOC_BACKING_{OPEN,CLOSE} to add new iomap devices

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

---
 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         |   52 ++++++++++++++
 fs/fuse/fuse_iomap.c      |  165 +++++++++++++++++++++++++++++++++++++++++----
 fs/fuse/trace.c           |    2 +
 7 files changed, 216 insertions(+), 16 deletions(-)
fs/fuse/fuse_i.h +7 -0
index 82603e8969a9db..969d546ecbaaec 100644
@@ -111,6 +111,7 @@ 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, const struct fuse_backing *fb);
+	int (*post_open)(struct fuse_conn *fc, struct fuse_backing *fb);
 	unsigned int type;
 	int id_start;
 	int id_end;
@@ -120,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;
 
 	int id;
@@ -1616,6 +1618,11 @@ 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,
+			   const struct fuse_backing_ops *ops,
+			   fuse_match_backing_fn match_fn, const void *data);
 #else
 
 static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
fs/fuse/fuse_iomap.h +2 -0
index 6c71318365ca82..43562ef23fb325 100644
@@ -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)
include/uapi/linux/fuse.h +2 -1
index 093b4ba6a602ac..6ce5de5b74f256 100644
@@ -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)
 
fs/fuse/Kconfig +1 -0
index 1b8990f1c2a8f9..3e35611c3aac07 100644
@@ -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
fs/fuse/backing.c +51 -1

79 lines not on this page · raw message

fs/fuse/fuse_iomap.c +151 -14

231 lines not on this page · raw message

fs/fuse/trace.c +2 -0
index 93bd72efc98cd0..65badac814b591 100644
@@ -9,5 +9,7 @@
 
 #include <linux/pagemap.h>
 
+#include "fuse_iomap_i.h"
+
 #define CREATE_TRACE_POINTS
 #include "fuse_trace.h"
#22 lore raw

PATCH 5/11 fuse_trace: adapt FUSE_DEV_IOC_BACKING_{OPEN,CLOSE} to add new iomap devices

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

---
 fs/fuse/fuse_trace.h |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
fs/fuse/fuse_trace.h +15 -2
index 2fcff2c46a9733..e942480b9d5841 100644
@@ -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" }
+
 DECLARE_EVENT_CLASS(fuse_backing_class,
 	TP_PROTO(const struct fuse_conn *fc, const struct fuse_backing *fb),
 
@@ -183,7 +187,9 @@ DECLARE_EVENT_CLASS(fuse_backing_class,
 	TP_STRUCT__entry(
 		__field(dev_t,			connection)
 		__field(int,			id)
+		__field(unsigned int,		type)
 		__field(unsigned long,		ino)
+		__field(dev_t,			rdev)
 	),
 
 	TP_fast_assign(
@@ -192,12 +198,19 @@ DECLARE_EVENT_CLASS(fuse_backing_class,
 		__entry->connection	=	fc->dev;
 		__entry->id		=	fb->id;
 		__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 id %d ino 0x%lx",
+	TP_printk("connection %u id %d type %s ino 0x%lx rdev %u:%u",
 		  __entry->connection,
 		  __entry->id,
-		  __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,		\
#23 lore raw

PATCH 6/11 fuse: create a per-inode flag for setting exclusive mode

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_i.h          |   17 +++++++++++++++++
 include/uapi/linux/fuse.h |    6 ++++++
 fs/fuse/inode.c           |   17 +++++++++++++++++
 3 files changed, 40 insertions(+)
fs/fuse/fuse_i.h +17 -0
index 969d546ecbaaec..822b77da7a144c 100644
@@ -1118,6 +1118,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);
include/uapi/linux/fuse.h +6 -0
index 6ce5de5b74f256..7f4a7b7ba1e613 100644
@@ -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,14 @@ 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).  Must be set in the initial LOOKUP/GETATTR response.
+ *     Cannot be cleared.
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 #define FUSE_ATTR_DAX		(1 << 1)
+#define FUSE_ATTR_EXCLUSIVE	(1 << 2)
 
 /**
  * Open flags
fs/fuse/inode.c +17 -0
index fdf5414c24160b..3ba80514bd59eb 100644
@@ -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)
@@ -318,6 +320,15 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
 	 * anyway. Its less efficient but should be safe.
 	 */
 	inode->i_flags &= ~S_NOSEC;
+
+	/*
+	 * The root inode is created with attr->flags == 0 at mount time prior
+	 * to FUSE_INIT, so this is the only way that the fuse server can set
+	 * the attribute on the root directory after the fact.
+	 */
+	if (get_node_id(inode) == FUSE_ROOT_ID &&
+	    (attr->flags & FUSE_ATTR_EXCLUSIVE))
+		fuse_inode_set_exclusive(fc, inode);
 }
 
 u32 fuse_get_cache_mask(struct inode *inode)
@@ -436,6 +447,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);
@@ -1783,6 +1797,9 @@ static void fuse_fill_attr_from_inode(struct fuse_attr *attr,
 		.rdev		= fi->inode.i_rdev,
 		.blksize	= 1u << fi->inode.i_blkbits,
 	};
+
+	if (fuse_inode_is_exclusive(&fi->inode))
+		attr->flags |= FUSE_ATTR_EXCLUSIVE;
 }
 
 static void fuse_sb_defaults(struct super_block *sb)
#24 lore raw

PATCH 7/11 fuse: create a per-inode flag for toggling iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_i.h          |   18 +++++++++++-
 fs/fuse/fuse_iomap.h      |   13 +++++++++
 include/uapi/linux/fuse.h |    6 ++++
 fs/fuse/dir.c             |   14 ++++++++--
 fs/fuse/file.c            |    3 ++
 fs/fuse/fuse_iomap.c      |   66 +++++++++++++++++++++++++++++++++++++++++----
 fs/fuse/inode.c           |    6 +++-
 7 files changed, 114 insertions(+), 12 deletions(-)
fs/fuse/fuse_i.h +16 -2
index 822b77da7a144c..4ffdb2b9c39129 100644
@@ -266,6 +266,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;
@@ -658,6 +660,13 @@ struct fuse_sync_bucket {
 	struct rcu_head rcu;
 };
 
+#ifdef CONFIG_FUSE_IOMAP
+struct fuse_iomap_conn {
+	/**  number of inodes that have iomap enabled */
+	atomic64_t inodes;
+};
+#endif
+
 /**
  * A Fuse connection.
  *
@@ -1019,6 +1028,11 @@ struct fuse_conn {
 		/* Request timeout (in jiffies). 0 = no timeout */
 		unsigned int req_timeout;
 	} timeout;
+
+#ifdef CONFIG_FUSE_IOMAP
+	/** iomap information */
+	struct fuse_iomap_conn iomap_conn;
+#endif
 };
 
 /*
@@ -1258,12 +1272,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
fs/fuse/fuse_iomap.h +13 -0
index 43562ef23fb325..66a95e8635339a 100644
@@ -20,9 +20,22 @@ static inline bool fuse_has_iomap(const struct inode *inode)
 }
 
 extern const struct fuse_backing_ops fuse_iomap_backing_ops;
+
+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_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 */
include/uapi/linux/fuse.h +6 -0
index 7f4a7b7ba1e613..9cf63b4c4a3e9d 100644
@@ -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
@@ -589,10 +590,15 @@ struct fuse_file_lock {
  *     kernel can use cached attributes more aggressively (e.g. ACL
  *     inheritance).  Must be set in the initial LOOKUP/GETATTR response.
  *     Cannot be cleared.
+ * FUSE_ATTR_IOMAP: Use iomap for this inode.  Must be set in the initial
+ *     LOOKUP/GETATTR response, and only for regular files.  Cannot be cleared.
+ *     This flag supplies FUSE_ATTR_EXCLUSIVE.
  */
 #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_IOMAP		(FUSE_ATTR_EXCLUSIVE | __FUSE_ATTR_IOMAP)
 
 /**
  * Open flags
fs/fuse/dir.c +12 -2
index 572a764a5eb803..ca201ce3499040 100644
@@ -7,6 +7,7 @@
 */
 
 #include "fuse_i.h"
+#include "fuse_iomap.h"
 
 #include <linux/pagemap.h>
 #include <linux/file.h>
@@ -2517,9 +2518,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;
@@ -2529,6 +2531,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)
@@ -2547,9 +2552,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);
 }
fs/fuse/file.c +3 -0
index 5e7fe7ef87d2e4..8d55d2f4dd4cc9 100644
@@ -7,6 +7,7 @@
 */
 
 #include "fuse_i.h"
+#include "fuse_iomap.h"
 
 #include <linux/pagemap.h>
 #include <linux/slab.h>
@@ -3217,6 +3218,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);
 }
fs/fuse/fuse_iomap.c +60 -6

81 lines not on this page · raw message

fs/fuse/inode.c +4 -2
index 3ba80514bd59eb..59113da7d31f5e 100644
@@ -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);
 }
 
@@ -455,10 +457,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:
#25 lore raw

PATCH 8/11 fuse_trace: create a per-inode flag for toggling iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_trace.h |   44 ++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    8 +++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)
fs/fuse/fuse_trace.h +44 -0
index e942480b9d5841..21316c5fa890d6 100644
@@ -299,6 +299,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),
 
@@ -463,6 +482,31 @@ TRACE_EVENT(fuse_iomap_end_error,
 		  __entry->written,
 		  __entry->error)
 );
+
+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 */
fs/fuse/fuse_iomap.c +7 -1
index 3e8eb9642f1adb..b6d2fe11c0e17b 100644
@@ -675,15 +675,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);
 }
#26 lore raw

PATCH 9/11 fuse: isolate the other regular file IO paths from iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/dir.c    |   14 +++++++++-----
 fs/fuse/file.c   |   22 +++++++++++++++++-----
 fs/fuse/inode.c  |    3 ++-
 fs/fuse/iomode.c |    3 ++-
 4 files changed, 30 insertions(+), 12 deletions(-)
fs/fuse/dir.c +9 -5
index ca201ce3499040..1641223f76d8c6 100644
@@ -2203,6 +2203,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;
@@ -2260,12 +2261,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;
@@ -2337,7 +2341,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);
 	}
@@ -2361,7 +2365,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);
fs/fuse/file.c +17 -5
index 8d55d2f4dd4cc9..8edb2f089277a1 100644
@@ -206,6 +206,10 @@ static void fuse_link_write_file(struct file *file)
 	struct inode *inode = file_inode(file);
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	struct fuse_file *ff = file->private_data;
+
+	if (fuse_inode_has_iomap(&fi->inode))
+		return;
+
 	/*
 	 * file may be written through mmap, so chain it onto the
 	 * inodes's write_file list
@@ -257,6 +261,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);
@@ -278,7 +283,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);
@@ -291,7 +296,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)
@@ -539,12 +544,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
@@ -555,7 +562,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
@@ -579,7 +587,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;
 }
@@ -2015,6 +2024,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);
fs/fuse/inode.c +2 -1
index 59113da7d31f5e..98f2464389d026 100644
@@ -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));
fs/fuse/iomode.c +2 -1
index 3728933188f307..9be9ae3520003e 100644
@@ -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;
 
 	/*
#27 lore raw

PATCH 10/11 fuse: implement basic iomap reporting such as FIEMAP and SEEK_{DATA,HOLE}

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

---
 fs/fuse/fuse_iomap.h |    8 ++++++
 fs/fuse/dir.c        |    1 +
 fs/fuse/file.c       |   15 ++++++++++-
 fs/fuse/fuse_iomap.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 91 insertions(+), 2 deletions(-)
fs/fuse/fuse_iomap.h +8 -0
index 66a95e8635339a..4196c6ed5466bc 100644
@@ -30,12 +30,20 @@ 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)
 # 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 */
fs/fuse/dir.c +1 -0
index 1641223f76d8c6..18b9a43a69f6e8 100644
@@ -2508,6 +2508,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 = {
fs/fuse/file.c +14 -1
index 8edb2f089277a1..a6b8d6bf62d6d2 100644
@@ -2597,7 +2597,13 @@ static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
 	struct fuse_bmap_out outarg;
 	int err;
 
-	if (!inode->i_sb->s_bdev || fm->fc->no_bmap)
+	if (!inode->i_sb->s_bdev)
+		return 0;
+
+	if (fuse_inode_has_iomap(inode))
+		return fuse_iomap_bmap(mapping, block);
+
+	if (fm->fc->no_bmap)
 		return 0;
 
 	memset(&inarg, 0, sizeof(inarg));
@@ -2632,6 +2638,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;
 
fs/fuse/fuse_iomap.c +68 -1

84 lines not on this page · raw message

#28 lore raw

PATCH 11/11 fuse_trace: implement basic iomap reporting such as FIEMAP and SEEK_{DATA,HOLE}

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_trace.h |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    4 ++++
 2 files changed, 50 insertions(+)
fs/fuse/fuse_trace.h +46 -0
index 21316c5fa890d6..10e263732305c0 100644
@@ -507,6 +507,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 */
fs/fuse/fuse_iomap.c +4 -0
index 9ac3fc86ceb623..3c6bf865ff4d43 100644
@@ -717,6 +717,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);
@@ -745,6 +747,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);
#30 lore raw

PATCH 1/6 fuse: implement direct IO with iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_i.h          |   11 +
 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      |  337 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |    2 
 fs/fuse/iomode.c          |    2 
 8 files changed, 433 insertions(+), 6 deletions(-)
fs/fuse/fuse_i.h +11 -0
index 4ffdb2b9c39129..5b219ce8a6c918 100644
@@ -190,6 +190,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) */
@@ -664,6 +669,12 @@ struct fuse_sync_bucket {
 struct fuse_iomap_conn {
 	/**  number of inodes that have iomap enabled */
 	atomic64_t inodes;
+
+	/* 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
 
fs/fuse/fuse_iomap.h +18 -0
index 4196c6ed5466bc..4ea34082e01a15 100644
@@ -35,6 +35,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)
@@ -44,6 +55,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 */
include/uapi/linux/fuse.h +27 -0
index 9cf63b4c4a3e9d..ad977782eef231 100644
@@ -682,6 +682,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,
 
@@ -1430,4 +1431,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 */
fs/fuse/dir.c +13 -0
index 18b9a43a69f6e8..9daac6af7d3a22 100644
@@ -908,6 +908,10 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
 	entry->d_time = epoch;
 	fuse_change_entry_timeout(entry, &outentry);
 	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;
@@ -1955,6 +1959,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;
@@ -2315,6 +2322,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) {
fs/fuse/file.c +26 -3
index a6b8d6bf62d6d2..279a5229a51a9e 100644
@@ -226,7 +226,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;
 
@@ -269,6 +272,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;
@@ -299,9 +305,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)
@@ -1831,6 +1839,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);
 
@@ -1852,6 +1863,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);
 
@@ -2964,7 +2978,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)));
@@ -2997,6 +3013,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);
@@ -3021,6 +3038,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);
 	}
fs/fuse/fuse_iomap.c +335 -2

367 lines not on this page · raw message

fs/fuse/inode.c +2 -0
index 98f2464389d026..c94f47779f9966 100644
@@ -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
fs/fuse/iomode.c +1 -1
index 9be9ae3520003e..ed666b39cf8af4 100644
@@ -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;
 
 	/*
#31 lore raw

PATCH 2/6 fuse_trace: implement direct IO with iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_iomap.h |    6 +
 fs/fuse/fuse_trace.h |  222 +++++++++++++++++++++++++++++++++++++++++++++++++-
 fs/fuse/fuse_iomap.c |   18 ++++
 fs/fuse/trace.c      |    2 
 4 files changed, 244 insertions(+), 4 deletions(-)
fs/fuse/fuse_iomap.h +6 -0
index 4ea34082e01a15..a7c30ebd46dda7 100644
@@ -42,6 +42,11 @@ 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)
+{
+	/* unlocked access, for tracing only */
+	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);
@@ -59,6 +64,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)
fs/fuse/fuse_trace.h +218 -4

265 lines not on this page · raw message

fs/fuse/fuse_iomap.c +18 -0
index 5e23c662b972fa..ed6d9ba32c47b2 100644
@@ -622,6 +622,8 @@ fuse_iomap_setsize_finish(
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_setsize_finish(inode, newsize, 0);
+
 	spin_lock(&fi->lock);
 	fi->i_disk_size = newsize;
 	spin_unlock(&fi->lock);
@@ -652,6 +654,8 @@ static int fuse_iomap_ioend(struct inode *inode, loff_t pos, size_t written,
 	outarg.newsize = max_t(loff_t, fi->i_disk_size, pos + written),
 	spin_unlock(&fi->lock);
 
+	trace_fuse_iomap_ioend(inode, &inarg);
+
 	if (fuse_should_send_iomap_ioend(fm, &inarg)) {
 		FUSE_ARGS(args);
 		int iomap_error;
@@ -677,6 +681,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.
@@ -950,6 +957,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 = 0;
 
+	trace_fuse_iomap_direct_read(iocb, to);
+
 	if (!iov_iter_count(to))
 		goto out; /* skip atime */
 
@@ -963,6 +972,7 @@ static ssize_t fuse_iomap_direct_read(struct kiocb *iocb, struct iov_iter *to)
 	inode_unlock_shared(inode);
 
 out:
+	trace_fuse_iomap_direct_read_end(iocb, to, ret);
 	return ret;
 }
 
@@ -977,6 +987,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)
@@ -1013,6 +1026,8 @@ static ssize_t fuse_iomap_direct_write(struct kiocb *iocb,
 	unsigned int flags = IOMAP_DIO_COMP_WORK;
 	ssize_t ret = 0;
 
+	trace_fuse_iomap_direct_write(iocb, from);
+
 	if (!count)
 		goto out;
 
@@ -1047,6 +1062,7 @@ static ssize_t fuse_iomap_direct_write(struct kiocb *iocb,
 out_unlock:
 	inode_unlock(inode);
 out:
+	trace_fuse_iomap_direct_write_end(iocb, from, ret);
 	return ret;
 }
 
@@ -1064,6 +1080,8 @@ void fuse_iomap_open_truncate(struct inode *inode)
 
 	ASSERT(fuse_inode_has_iomap(inode));
 
+	trace_fuse_iomap_open_truncate(inode);
+
 	spin_lock(&fi->lock);
 	fi->i_disk_size = 0;
 	spin_unlock(&fi->lock);
fs/fuse/trace.c +2 -0
index 65badac814b591..ac17cc79bfbc7c 100644
@@ -8,7 +8,9 @@
 #include "fuse_dev_i.h"
 
 #include <linux/pagemap.h>
+#include <linux/iomap.h>
 
+#include "fuse_iomap.h"
 #include "fuse_iomap_i.h"
 
 #define CREATE_TRACE_POINTS
#32 lore raw

PATCH 3/6 fuse: implement buffered IO with iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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. As a result, the kernel only needs to upcall the fuse server to find out where to direct its file IO.

---
 fs/fuse/fuse_i.h          |    7 
 fs/fuse/fuse_iomap.h      |   13 +
 include/uapi/linux/fuse.h |    2 
 fs/fuse/dev.c             |   10 +
 fs/fuse/dir.c             |   23 +
 fs/fuse/file.c            |   62 +++-
 fs/fuse/fuse_iomap.c      |  704 ++++++++++++++++++++++++++++++++++++++++++++-
 7 files changed, 790 insertions(+), 31 deletions(-)
fs/fuse/fuse_i.h +7 -0
index 5b219ce8a6c918..31193345f709b5 100644
@@ -194,6 +194,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 */
fs/fuse/fuse_iomap.h +13 -0
index a7c30ebd46dda7..714ab728066631 100644
@@ -51,6 +51,14 @@ 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);
+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)
@@ -68,6 +76,11 @@ 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)
+# define fuse_iomap_fadvise			NULL
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
include/uapi/linux/fuse.h +2 -0
index ad977782eef231..1f1f9392a441f5 100644
@@ -1441,6 +1441,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_* */
fs/fuse/dev.c +10 -0
index 2708e17bc46949..d21eebbe12d4c9 100644
@@ -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>
@@ -1794,6 +1795,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;
 	file_size = i_size_read(inode);
 	end = pos + num;
@@ -1873,6 +1880,9 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 	struct fuse_args *args;
 	loff_t pos = outarg->offset;
 
+	if (fuse_inode_has_iomap(inode))
+		return -EOPNOTSUPP;
+
 	offset = offset_in_page(pos);
 	file_size = i_size_read(inode);
 
fs/fuse/dir.c +22 -1
index 9daac6af7d3a22..30fcb1492dda18 100644
@@ -2232,7 +2232,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);
@@ -2247,6 +2250,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
@@ -2280,6 +2295,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));
fs/fuse/file.c +46 -16

133 lines not on this page · raw message

fs/fuse/fuse_iomap.c +690 -14

749 lines not on this page · raw message

#33 lore raw

PATCH 4/6 fuse_trace: implement buffered IO with iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_trace.h |  263 ++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |   43 ++++++++
 2 files changed, 302 insertions(+), 4 deletions(-)
fs/fuse/fuse_trace.h +261 -2
index 46a6b7527c3bb3..f1dab22d41636f 100644
@@ -225,6 +225,8 @@ 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 \
@@ -293,7 +295,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" }, \
@@ -308,7 +311,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" }, \
@@ -333,6 +337,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),
 
@@ -658,6 +668,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,
@@ -694,6 +707,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,
@@ -766,7 +781,251 @@ 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, int error),
+
+	TP_ARGS(ioend, error),
+
+	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		=	error;
+	),
+
+	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_range_end,
+	TP_PROTO(const struct inode *inode, u64 offset, unsigned int count,
+		 u64 end_pos, ssize_t ret),
+
+	TP_ARGS(inode, offset, count, end_pos, ret),
+
+	TP_STRUCT__entry(
+		FUSE_IO_RANGE_FIELDS()
+		__field(uint64_t,		end_pos)
+		__field(size_t,			bytes)
+		__field(int,			error)
+	),
+
+	TP_fast_assign(
+		FUSE_INODE_ASSIGN(inode, fi, fm);
+		__entry->offset		=	offset;
+		__entry->length		=	count;
+		__entry->end_pos	=	end_pos;
+		if (ret >= 0) {
+			__entry->bytes	=	ret;
+			__entry->error	=	0;
+		} else {
+			__entry->bytes	=	0;
+			__entry->error	=	ret;
+		}
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() " end_pos 0x%llx bytes 0x%zx error %d",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __entry->end_pos,
+		  __entry->bytes,
+		  __entry->error)
+);
+
+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;
+		__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;
+		if (wbc->range_end == LLONG_MAX)
+			__entry->length	=	i_size_read(inode) - wbc->range_start;
+		else
+			__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 */
fs/fuse/fuse_iomap.c +41 -2

154 lines not on this page · raw message

#34 lore raw

PATCH 5/6 fuse: implement inline data file IO via iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

---
 fs/fuse/fuse_iomap.c |  227 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 227 insertions(+)
fs/fuse/fuse_iomap.c +227 -0
index 503d399d40d708..8d8a1bc2c4bfe5 100644
@@ -8,6 +8,7 @@
 #include <linux/pagemap.h>
 #include <linux/falloc.h>
 #include <linux/fadvise.h>
+#include <linux/fserror.h>
 #include "fuse_i.h"
 #include "fuse_trace.h"
 #include "fuse_iomap.h"
@@ -424,6 +425,178 @@ fuse_iomap_validate_bdev_access(const struct fuse_backing *fb,
 	return (!fb || (fb->file->f_mode & fmode) == fmode) ? 0 : -EACCES;
 }
 
+static inline int fuse_iomap_inline_alloc(const struct inode *inode,
+					  struct iomap *iomap)
+{
+	ASSERT(iomap->inline_data == NULL);
+	ASSERT(iomap->length > 0);
+
+	if (iomap->length > i_blocksize(inode))
+		return -ENOMEM;
+
+	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.  Read all of the inline data every
+ * time so that iomap->inline_data is always uptodate.  This is safe (though
+ * not maximally efficient) because iomap_write_begin_inline doesn't handle
+ * inline mappings with nonzero offset.
+ */
+static int fuse_iomap_inline_read(struct inode *inode, loff_t pos,
+				  loff_t count, struct iomap *iomap)
+{
+	struct fuse_read_in in = {
+		.offset = iomap->offset,
+		.size = iomap->length,
+	};
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_mount *fm = get_fuse_mount(inode);
+	FUSE_ARGS(args);
+	ssize_t ret;
+
+	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 = in.size;
+	args.out_args[0].value = iomap_inline_data(iomap, in.offset);
+
+	ret = fuse_simple_request(fm, &args);
+	if (ret == -ENOSYS)
+		ret = 0;
+	if (ret < 0)
+		return ret;
+
+	/* no readahead means something bad happened */
+	if (ret == 0)
+		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.  Note that we only send the
+ * written range to the server.
+ */
+static ssize_t fuse_iomap_inline_write(struct inode *inode, loff_t pos,
+				       ssize_t written, struct iomap *iomap)
+{
+	struct fuse_write_in in = {
+		.offset = pos,
+		.size = written,
+	};
+	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 persisted = 0;
+	ssize_t ret = 0;
+
+	if (BAD_DATA(pos + written > iomap->offset + iomap->length))
+		return -EIO;
+
+	while (in.size > 0) {
+		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 = in.size;
+		args.in_args[1].value = iomap_inline_data(iomap, in.offset);
+		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 == -ENOSYS)
+			ret = 0;
+		if (ret < 0)
+			break;
+
+		/* zero or excessive length write means something bad happened */
+		if (out.size == 0 || BAD_DATA(out.size > in.size)) {
+			ret = -EIO;
+			break;
+		}
+
+		in.offset += out.size;
+		in.size -= out.size;
+		persisted += out.size;
+	}
+
+	return persisted ? persisted : ret;
+}
+
+/* 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(inode, iomap);
+			if (err)
+				return err;
+		}
+
+		if (srcmap->type == IOMAP_INLINE) {
+			/* inline data read in preparation for write */
+			err = fuse_iomap_inline_alloc(inode, srcmap);
+			if (err)
+				goto out_iomap;
+
+			err = fuse_iomap_inline_read(inode, pos, count,
+						     srcmap);
+			if (err)
+				goto out_srcmap;
+		} else if (iomap->type == IOMAP_INLINE &&
+			   srcmap->type == IOMAP_HOLE) {
+			/* pure overwrite of inline data */
+			err = fuse_iomap_inline_read(inode, pos, count,
+						     iomap);
+			if (err)
+				goto out_iomap;
+		}
+	} else if (iomap->type == IOMAP_INLINE) {
+		/* inline data read */
+		err = fuse_iomap_inline_alloc(inode, iomap);
+		if (err)
+			return err;
+
+		err = fuse_iomap_inline_read(inode, pos, count, iomap);
+		if (err)
+			goto out_iomap;
+	}
+
+	return 0;
+
+out_srcmap:
+	fuse_iomap_inline_free(srcmap);
+out_iomap:
+	fuse_iomap_inline_free(iomap);
+	return err;
+}
+
 static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 			    unsigned opflags, struct iomap *iomap,
 			    struct iomap *srcmap)
@@ -510,6 +683,13 @@ 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;
+	}
+
 	/*
 	 * It's ok to put the refcount here because you can't remove an iomap
 	 * device unless there are zero iomap inodes.
@@ -547,14 +727,61 @@ static bool fuse_should_send_iomap_end(const struct fuse_mount *fm,
 	return written < count;
 }
 
+static void fuse_iomap_write_error(struct inode *inode, loff_t pos,
+				    loff_t count, unsigned opflags, int error)
+{
+	const enum fserror_type f =
+		(opflags & IOMAP_DIRECT) ? FSERR_DIRECTIO_WRITE :
+					   FSERR_BUFFERED_WRITE;
+
+	mapping_set_error(inode->i_mapping, error);
+	fserror_report_io(inode, f, pos, count, error, GFP_NOFS);
+}
+
 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);
+	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) {
+			ssize_t persisted =
+				fuse_iomap_inline_write(inode, pos, written,
+							iomap);
+
+			fuse_iomap_inline_free(iomap);
+			if (persisted < 0) {
+				fuse_iomap_write_error(inode, pos, written,
+						       opflags, persisted);
+				return persisted;
+			}
+
+			if (persisted < written)
+				fuse_iomap_write_error(inode,
+						       pos + persisted,
+						       written - persisted,
+						       opflags, -EIO);
+
+			spin_lock(&fi->lock);
+			fi->i_disk_size = max(fi->i_disk_size,
+					      pos + persisted);
+			spin_unlock(&fi->lock);
+		} 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),
#35 lore raw

PATCH 6/6 fuse_trace: implement inline data file IO via iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_trace.h |   43 +++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    7 +++++++
 2 files changed, 50 insertions(+)
fs/fuse/fuse_trace.h +43 -0
index f1dab22d41636f..62641046138a10 100644
@@ -227,6 +227,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 \
@@ -1026,6 +1027,48 @@ TRACE_EVENT(fuse_iomap_fallocate,
 		  __entry->mode,
 		  __entry->newsize)
 );
+
+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()
+		__field(uint64_t,		mapoffset)
+		__field(uint64_t,		maplength)
+		__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->mapoffset	=	map->offset;
+		__entry->maplength	=	map->length;
+
+		__entry->has_buf	=	map->inline_data != NULL;
+		__entry->validity_cookie=	map->validity_cookie;
+	),
+
+	TP_printk(FUSE_IO_RANGE_FMT() "offset 0x%llx length 0x%llx has_buf? %d cookie 0x%llx",
+		  FUSE_IO_RANGE_PRINTK_ARGS(),
+		  __entry->mapoffset,
+		  __entry->maplength,
+		  __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 */
fs/fuse/fuse_iomap.c +7 -0
index 8d8a1bc2c4bfe5..01cb3b709ddbd5 100644
@@ -464,6 +464,8 @@ static int fuse_iomap_inline_read(struct inode *inode, loff_t pos,
 	FUSE_ARGS(args);
 	ssize_t ret;
 
+	trace_fuse_iomap_inline_read(inode, pos, count, iomap);
+
 	args.opcode = FUSE_READ;
 	args.nodeid = fi->nodeid;
 	args.in_numargs = 1;
@@ -522,6 +524,8 @@ static ssize_t fuse_iomap_inline_write(struct inode *inode, loff_t pos,
 		args.out_args[0].size = sizeof(out);
 		args.out_args[0].value = &out;
 
+		trace_fuse_iomap_inline_write(inode, pos, written, iomap);
+
 		ret = fuse_simple_request(fm, &args);
 		if (ret == -ENOSYS)
 			ret = 0;
@@ -588,6 +592,9 @@ static int fuse_iomap_set_inline(struct inode *inode, unsigned opflags,
 			goto out_iomap;
 	}
 
+	trace_fuse_iomap_set_inline_iomap(inode, pos, count, iomap);
+	trace_fuse_iomap_set_inline_srcmap(inode, pos, count, srcmap);
+
 	return 0;
 
 out_srcmap:
#37 lore raw

PATCH 1/9 fuse: advertise support for iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

---
 fs/fuse/fuse_iomap.h                               |    4 ++++
 include/uapi/linux/fuse.h                          |    9 +++++++++
 Documentation/userspace-api/ioctl/ioctl-number.rst |    2 +-
 fs/fuse/dev.c                                      |    3 +++
 fs/fuse/fuse_iomap.c                               |   13 +++++++++++++
 5 files changed, 30 insertions(+), 1 deletion(-)
fs/fuse/fuse_iomap.h +4 -0
index 714ab728066631..144ff1a579674d 100644
@@ -59,6 +59,9 @@ int fuse_iomap_fallocate(struct file *file, int mode, loff_t offset,
 int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
 				 loff_t endpos);
 int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
+
+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)
@@ -81,6 +84,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_iomap_fadvise			NULL
+# define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
include/uapi/linux/fuse.h +9 -0
index 1f1f9392a441f5..0344ab22411837 100644
@@ -1161,6 +1161,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)
@@ -1168,6 +1175,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;
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -1
index 331223761ffffd..1175e6795cf439 100644
@@ -399,7 +399,7 @@ Code  Seq#    Include File                                             Comments
 0xCF  02     fs/smb/client/cifs_ioctl.h
 0xDD  00-3F                                                            ZFCP device driver see drivers/s390/scsi/
                                                                        <mailto:[email protected]>
-0xE5  00-3F  linux/fuse.h
+0xE5  00-FF  linux/fuse.h
 0xEC  00-01  drivers/platform/chrome/cros_ec_dev.h                     ChromeOS EC driver
 0xEE  00-09  uapi/linux/pfrut.h                                        Platform Firmware Runtime Update and Telemetry
 0xF3  00-3F  drivers/usb/misc/sisusbvga/sisusb.h                       sisfb (in development)
fs/fuse/dev.c +3 -0
index d21eebbe12d4c9..75e1e3f8a4ddd1 100644
@@ -2712,6 +2712,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;
 	}
fs/fuse/fuse_iomap.c +13 -0
index 01cb3b709ddbd5..14e86791c4d8f9 100644
@@ -2064,3 +2064,16 @@ int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice)
 		inode_unlock_shared(inode);
 	return ret;
 }
+
+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;
+}
#38 lore raw

PATCH 2/9 fuse: query filesystem geometry when using iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

---
 fs/fuse/fuse_i.h          |    4 +
 fs/fuse/fuse_iomap.h      |    5 +
 include/uapi/linux/fuse.h |   39 ++++++++++
 fs/fuse/fuse_iomap.c      |  175 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |   39 +++++++++-
 5 files changed, 257 insertions(+), 5 deletions(-)
fs/fuse/fuse_i.h +4 -0
index 31193345f709b5..ecacfc65e95a99 100644
@@ -1036,6 +1036,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 */
@@ -1452,6 +1455,7 @@ struct fuse_dev *fuse_dev_alloc(void);
 void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
 void fuse_dev_put(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
fs/fuse/fuse_iomap.h +5 -0
index 144ff1a579674d..0635bd8b012e6d 100644
@@ -21,6 +21,9 @@ static inline bool fuse_has_iomap(const struct inode *inode)
 
 extern const struct fuse_backing_ops fuse_iomap_backing_ops;
 
+int fuse_iomap_mount_sync(struct fuse_mount *fm);
+void fuse_iomap_mount_async(struct fuse_mount *fm);
+
 void fuse_iomap_init_inode(struct inode *inode, struct fuse_attr *attr);
 void fuse_iomap_evict_inode(struct inode *inode);
 
@@ -65,6 +68,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_sync(...)		(0)
+# define fuse_iomap_mount_async(...)		((void)0)
 # define fuse_iomap_init_inode(...)		((void)0)
 # define fuse_iomap_evict_inode(...)		((void)0)
 # define fuse_inode_has_iomap(...)		(false)
include/uapi/linux/fuse.h +39 -0
index 0344ab22411837..867a0bc54f5b93 100644
@@ -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
@@ -682,6 +683,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,
@@ -1468,4 +1470,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 */
fs/fuse/fuse_iomap.c +175 -0

181 lines not on this page · raw message

fs/fuse/inode.c +34 -5
index c94f47779f9966..781c9cd4ea014e 100644
@@ -1391,6 +1391,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 {
@@ -1546,13 +1548,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)
@@ -2042,7 +2058,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_sync(fm);
+		if (err)
+			return err;
+	}
+
+	if (fm->fc->conn_error)
+		return -EIO;
+
+	return 0;
 }
 
 /*
#39 lore raw

PATCH 3/9 fuse_trace: query filesystem geometry when using iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_trace.h |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    2 ++
 2 files changed, 50 insertions(+)
fs/fuse/fuse_trace.h +48 -0
index 62641046138a10..38fa54e4af731d 100644
@@ -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")	\
@@ -344,6 +345,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),
 
@@ -1069,6 +1078,45 @@ 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);
+
+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_u64(__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 */
fs/fuse/fuse_iomap.c +2 -0
index 06d8832401de8f..ac45a0912c9065 100644
@@ -1028,6 +1028,8 @@ static int fuse_iomap_process_config(struct fuse_mount *fm, int error,
 		return error;
 	}
 
+	trace_fuse_iomap_config(fm, outarg);
+
 	if (BAD_DATA(outarg->flags & ~FUSE_IOMAP_CONFIG_ALL))
 		return -EINVAL;
 
#40 lore raw

PATCH 4/9 fuse: use an unrestricted backing device with iomap pagecache io

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_i.h     |    3 ++
 fs/fuse/fuse_iomap.c |   64 ++++++++++++++++++++++++++++++++++++++++++++++++--
 mm/page-writeback.c  |    1 +
 3 files changed, 66 insertions(+), 2 deletions(-)
fs/fuse/fuse_i.h +3 -0
index ecacfc65e95a99..9e73522b8ed96e 100644
@@ -675,6 +675,9 @@ struct fuse_iomap_conn {
 	/**  number of inodes that have iomap enabled */
 	atomic64_t inodes;
 
+	/* old ra_pages, in case we have to put things back */
+	unsigned long old_ra_pages;
+
 	/* fuse server doesn't implement iomap_end */
 	unsigned int no_end:1;
 
fs/fuse/fuse_iomap.c +62 -2

92 lines not on this page · raw message

mm/page-writeback.c +1 -0
index 833f743f309f9b..e147811d9376d0 100644
@@ -809,6 +809,7 @@ int bdi_set_strict_limit(struct backing_dev_info *bdi, unsigned int strict_limit
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(bdi_set_strict_limit);
 
 static unsigned long dirty_freerun_ceiling(unsigned long thresh,
 					   unsigned long bg_thresh)
#41 lore raw

PATCH 5/9 fuse: disable direct fs reclaim for any fuse server that uses iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_iomap.h      |    2 ++
 include/uapi/linux/fuse.h |    1 +
 fs/fuse/dev.c             |    2 ++
 fs/fuse/fuse_iomap.c      |   40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 45 insertions(+)
fs/fuse/fuse_iomap.h +2 -0
index 0635bd8b012e6d..921836cb6c9686 100644
@@ -65,6 +65,7 @@ int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
 
 int fuse_dev_ioctl_iomap_support(struct file *file,
 				 struct fuse_iomap_support __user *argp);
+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)
@@ -90,6 +91,7 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
 # define fuse_iomap_flush_unmap_range(...)	(-ENOSYS)
 # define fuse_iomap_fadvise			NULL
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
+# define fuse_dev_ioctl_iomap_set_nofs(...)	(-EOPNOTSUPP)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
include/uapi/linux/fuse.h +1 -0
index 867a0bc54f5b93..43a1bbcce576d5 100644
@@ -1179,6 +1179,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;
fs/fuse/dev.c +2 -0
index 75e1e3f8a4ddd1..3257292387e0a6 100644
@@ -2714,6 +2714,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;
fs/fuse/fuse_iomap.c +40 -0
index df68dec16f98c1..3d9f5ecba43e28 100644
@@ -13,6 +13,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)
@@ -2314,3 +2315,42 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
 		return -EFAULT;
 	return 0;
 }
+
+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)
+{
+	uint32_t flags;
+	struct fuse_dev *fud = fuse_get_dev(file);
+
+	if (IS_ERR(fud))
+		return PTR_ERR(fud);
+
+	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;
+	}
+}
#42 lore raw

PATCH 6/9 fuse: allow privileged mount helpers to pre-approve iomap usage

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_i.h          |   10 ++++++++++
 fs/fuse/fuse_iomap.h      |    2 ++
 include/uapi/linux/fuse.h |    1 +
 fs/fuse/dev.c             |    2 ++
 fs/fuse/fuse_iomap.c      |   44 ++++++++++++++++++++++++++++++++++++++++----
 fs/fuse/inode.c           |    7 +++++--
 6 files changed, 60 insertions(+), 6 deletions(-)
fs/fuse/fuse_i.h +10 -0
index 9e73522b8ed96e..9d6ad5b629ffdc 100644
@@ -617,6 +617,9 @@ struct fuse_dev {
 	/** Issue FUSE_INIT synchronously */
 	bool sync_init;
 
+	/** Allow fuse server to ask for IOMAP */
+	bool may_iomap;
+
 	/** Fuse connection for this device */
 	struct fuse_conn *fc;
 
@@ -973,6 +976,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;
 
fs/fuse/fuse_iomap.h +2 -0
index 921836cb6c9686..c4b98123072a37 100644
@@ -63,6 +63,7 @@ int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
 				 loff_t endpos);
 int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
 
+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_nofs(struct file *file, uint32_t __user *argp);
@@ -90,6 +91,7 @@ int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 # define fuse_iomap_fallocate(...)		(-ENOSYS)
 # define fuse_iomap_flush_unmap_range(...)	(-ENOSYS)
 # define fuse_iomap_fadvise			NULL
+# define fuse_dev_ioctl_add_iomap(...)		(-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_set_nofs(...)	(-EOPNOTSUPP)
 #endif /* CONFIG_FUSE_IOMAP */
include/uapi/linux/fuse.h +1 -0
index 43a1bbcce576d5..0366101be3a321 100644
@@ -1180,6 +1180,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;
fs/fuse/dev.c +2 -0
index 3257292387e0a6..9ccf691451b609 100644
@@ -2716,6 +2716,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;
fs/fuse/fuse_iomap.c +40 -4

78 lines not on this page · raw message

fs/fuse/inode.c +5 -2
index 781c9cd4ea014e..e87e7df2c63bdb 100644
@@ -1067,6 +1067,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->may_iomap = fuse_iomap_enabled();
 
 	if (IS_ENABLED(CONFIG_FUSE_BACKING))
 		fuse_backing_files_init(fc);
@@ -1526,7 +1527,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!");
@@ -1619,7 +1620,7 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)
 	 * locking works correctly.  This is not compatible with creating
 	 * shadow inode objects for a submount.
 	 */
-	if (fuse_iomap_enabled() && !(flags & FUSE_SUBMOUNTS))
+	if (fm->fc->may_iomap && !(flags & FUSE_SUBMOUNTS))
 		flags |= FUSE_IOMAP;
 
 	ia->in.flags = flags;
@@ -2016,6 +2017,8 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
 			goto err_unlock;
 		if (fud->sync_init)
 			fc->sync_init = 1;
+		if (fud->may_iomap)
+			fc->may_iomap = 1;
 	}
 
 	err = fuse_ctl_add_conn(fc);
#43 lore raw

PATCH 7/9 fuse: invalidate ranges of backing devices being used for iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 fs/fuse/fuse_iomap.h      |    3 ++
 include/uapi/linux/fuse.h |   20 ++++++++++++++++
 fs/fuse/dev.c             |   28 +++++++++++++++++++++++
 fs/fuse/fuse_iomap.c      |   56 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 107 insertions(+)
fs/fuse/fuse_iomap.h +3 -0
index c4b98123072a37..f40d202c64c822 100644
@@ -67,6 +67,8 @@ 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_nofs(struct file *file, uint32_t __user *argp);
+int fuse_iomap_backing_inval(struct fuse_conn *fc,
+			     const struct fuse_iomap_backing_inval_out *arg);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -94,6 +96,7 @@ int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 # define fuse_dev_ioctl_add_iomap(...)		(-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_set_nofs(...)	(-EOPNOTSUPP)
+# define fuse_iomap_backing_inval(...)		(-ENOSYS)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
include/uapi/linux/fuse.h +20 -0
index 0366101be3a321..899964f8d6616a 100644
@@ -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_BACKING_INVAL to invalidate iomap bdev ranges
  */
 
 #ifndef _LINUX_FUSE_H
@@ -706,6 +707,8 @@ enum fuse_notify_code {
 	FUSE_NOTIFY_RESEND = 7,
 	FUSE_NOTIFY_INC_EPOCH = 8,
 	FUSE_NOTIFY_PRUNE = 9,
+	FUSE_NOTIFY_IOMAP_BACKING_INVAL = 99,
+	FUSE_NOTIFY_CODE_MAX,
 };
 
 /* The read buffer is required to be at least 8k, but may be much larger */
@@ -1509,4 +1512,21 @@ struct fuse_iomap_config_out {
 	int64_t s_maxbytes;	/* max file size */
 };
 
+struct fuse_range {
+	uint64_t offset;
+	uint64_t length;
+};
+
+struct fuse_iomap_backing_inval_out {
+	uint32_t dev;		/* device cookie */
+	uint32_t reserved;	/* zero */
+
+	/*
+	 * Range of backing file pagecache to invalidate, in bytes.  After
+	 * the call completes, the range will be non-dirty and hence cannot
+	 * be written to by the bdev pagecache.
+	 */
+	struct fuse_range range;
+};
+
 #endif /* _LINUX_FUSE_H */
fs/fuse/dev.c +28 -0
index 9ccf691451b609..06f52114b9aef2 100644
@@ -1848,6 +1848,31 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 	return err;
 }
 
+static int fuse_notify_iomap_backing_inval(struct fuse_conn *fc,
+					   unsigned int size,
+					   struct fuse_copy_state *cs)
+{
+	struct fuse_iomap_backing_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_backing_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;
@@ -2138,6 +2163,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_BACKING_INVAL:
+		return fuse_notify_iomap_backing_inval(fc, size, cs);
+
 	default:
 		return -EINVAL;
 	}
fs/fuse/fuse_iomap.c +56 -0

59 lines not on this page · raw message

#48 lore raw

PATCH 8/9 fuse_trace: invalidate ranges of block devices being used for iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_trace.h |   26 ++++++++++++++++++++++++++
 fs/fuse/fuse_iomap.c |    2 ++
 2 files changed, 28 insertions(+)
fs/fuse/fuse_trace.h +26 -0
index 38fa54e4af731d..8c0b691dfde703 100644
@@ -1117,6 +1117,32 @@ TRACE_EVENT(fuse_iomap_config,
 		  __entry->time_min, __entry->time_max, __entry->maxbytes,
 		  __entry->uuid_len)
 );
+
+TRACE_EVENT(fuse_iomap_backing_inval,
+	TP_PROTO(const struct fuse_conn *fc,
+		 const struct fuse_iomap_backing_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 */
fs/fuse/fuse_iomap.c +2 -0
index 8d259c8d239b07..ba54eb694dbbac 100644
@@ -2399,6 +2399,8 @@ int fuse_iomap_backing_inval(struct fuse_conn *fc,
 	loff_t end;
 	int ret = 0;
 
+	trace_fuse_iomap_backing_inval(fc, arg);
+
 	if (!fc->iomap || arg->dev == FUSE_IOMAP_DEV_NULL)
 		return -EINVAL;
 
#49 lore raw

PATCH 9/9 fuse: set iomap backing device block size

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

---
 fs/fuse/fuse_iomap.h      |    3 +++
 include/uapi/linux/fuse.h |    8 ++++++++
 fs/fuse/dev.c             |    2 ++
 fs/fuse/fuse_iomap.c      |   27 +++++++++++++++++++++++++++
 4 files changed, 40 insertions(+)
fs/fuse/fuse_iomap.h +3 -0
index f40d202c64c822..3cfef073cbe5aa 100644
@@ -69,6 +69,8 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
 int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 int fuse_iomap_backing_inval(struct fuse_conn *fc,
 			     const struct fuse_iomap_backing_inval_out *arg);
+int fuse_iomap_backing_set_blocksize(struct file *file,
+				     struct fuse_iomap_backing_info __user *argp);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -97,6 +99,7 @@ int fuse_iomap_backing_inval(struct fuse_conn *fc,
 # define fuse_dev_ioctl_iomap_support(...)	(-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_set_nofs(...)	(-EOPNOTSUPP)
 # define fuse_iomap_backing_inval(...)		(-ENOSYS)
+# define fuse_iomap_backing_set_blocksize(...)	(-EOPNOTSUPP)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
include/uapi/linux/fuse.h +8 -0
index 899964f8d6616a..0b67938bb7baf0 100644
@@ -1173,6 +1173,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)
@@ -1184,6 +1189,9 @@ 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_BACKING_SET_BLOCKSIZE \
+					_IOW(FUSE_DEV_IOC_MAGIC, 102, \
+					     struct fuse_iomap_backing_info)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
fs/fuse/dev.c +2 -0
index 06f52114b9aef2..d6ba8d6b1a8875 100644
@@ -2746,6 +2746,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_BACKING_SET_BLOCKSIZE:
+		return fuse_iomap_backing_set_blocksize(file, argp);
 
 	default:
 		return -ENOTTY;
fs/fuse/fuse_iomap.c +27 -0
index ba54eb694dbbac..2deed4749738cb 100644
@@ -2448,3 +2448,30 @@ int fuse_iomap_backing_inval(struct fuse_conn *fc,
 	up_read(&fc->killsb);
 	return ret;
 }
+
+int fuse_iomap_backing_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;
+}
#54 lore raw

RFC PATCH 1/1 fuse: allow fuse servers to upload iomap stripe information

In reply to Darrick J. Wong

Hi all,

There are certain fuse servers that might benefit from the ability to upload storage device striping information into the kernel to assist in responding to ->iomap_begin requests. In other words, this is filesystem striping for fuse iomap, implemented in fuse.

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 solution that does not involve BPF that can provide this
usecase: uploading device striping information into the kernel.

In this case, the fuse server upload a stripe map into the /dev/fuse device and receives a "backing" file id. That id can be combined with a new mapping type (FUSE_IOMAP_TYPE_STRIPE) that will load the stripe information and adjust the mapping to point to a real block device.

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-striping
---
Commits in this patchset:
* fuse: allow fuse servers to upload stripe maps
* fuse_trace: allow fuse servers to upload stripe maps
* fuse: implement striping for iomap
* fuse_trace: implement striping for iomap

---
 fs/fuse/fuse_i.h           |   30 ++++
 fs/fuse/fuse_iomap.h       |    8 +
 fs/fuse/fuse_trace.h       |   57 +++++++-
 include/uapi/linux/fuse.h  |   24 +++
 fs/fuse/backing.c          |   85 +++++++++++
 fs/fuse/dev.c              |    2 
 fs/fuse/fuse_iomap.c       |  328 +++++++++++++++++++++++++++++++++++++++++++-
 fs/fuse/fuse_iomap_cache.c |    8 +
 fs/fuse/inode.c            |    1 
 9 files changed, 533 insertions(+), 10 deletions(-)
#55 lore raw

PATCH 1/4 fuse: allow fuse servers to upload stripe maps

From: Darrick J. Wong <[email protected]>

Enable userspace to create a virtual backing fd that really just contains a stripe map of other iomap backing fds. This enables us to implement in-filesystem striping.

---
 fs/fuse/fuse_i.h          |   30 +++++++++++
 fs/fuse/fuse_iomap.h      |    7 +++
 fs/fuse/fuse_trace.h      |    6 +-
 include/uapi/linux/fuse.h |   19 +++++++
 fs/fuse/backing.c         |   84 ++++++++++++++++++++++++++++++++
 fs/fuse/dev.c             |    2 +
 fs/fuse/fuse_iomap.c      |  118 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c           |    1 
 8 files changed, 263 insertions(+), 4 deletions(-)
fs/fuse/fuse_i.h +30 -0
index bdf18550c34708..bd45c4dfaccd0d 100644
@@ -106,22 +106,45 @@ struct fuse_submount_lookup {
 struct fuse_conn;
 struct fuse_backing;
 
+/* internal backing device type, larger than userspace can pass in */
+#define FUSE_BACKING_TYPE_IOMAP_STRIPE		(FUSE_BACKING_TYPE_MASK + 1)
+
 /** 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, const struct fuse_backing *fb);
 	int (*post_open)(struct fuse_conn *fc, struct fuse_backing *fb);
+	void (*free_data)(const void *fbdata);
 	unsigned int type;
 	int id_start;
 	int id_end;
 };
 
+struct fuse_backing_strip {
+	struct fuse_backing *fb;
+	uint64_t addr;		/* disk offset of strip, bytes */
+	uint32_t dev;		/* backing id */
+};
+
+struct fuse_backing_stripe {
+	unsigned int nr_strips;
+	uint64_t strip_width;	/* strip width, bytes */
+
+	struct fuse_backing_strip strips[] __counted_by(nr_strips);
+};
+
+static inline size_t sizeof_fuse_backing_stripe(unsigned int nr)
+{
+	return flex_array_size((struct fuse_backing_stripe *)NULL, strips, nr);
+}
+
 /** Container for data related to mapping to backing file */
 struct fuse_backing {
 	struct file *file;
 	struct cred *cred;
 	struct block_device *bdev;
+	void *data;
 	const struct fuse_backing_ops *ops;
 
 	int id;
@@ -1707,6 +1730,11 @@ typedef bool (*fuse_match_backing_fn)(const struct fuse_backing *fb,
 int fuse_backing_lookup_id(struct fuse_conn *fc,
 			   const struct fuse_backing_ops *ops,
 			   fuse_match_backing_fn match_fn, const void *data);
+
+typedef int (*fuse_backing_iter_fn)(struct fuse_backing *fb, void *data);
+int fuse_backing_foreach(struct fuse_conn *fc,
+			 const struct fuse_backing_ops *ops,
+			 fuse_backing_iter_fn iter_fn, void *data);
 #else
 
 static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
@@ -1727,6 +1755,8 @@ static inline struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,
 void fuse_backing_files_init(struct fuse_conn *fc);
 void fuse_backing_files_free(struct fuse_conn *fc);
 int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map);
+int fuse_backing_create(struct fuse_conn *fc,
+			const struct fuse_backing_ops *ops, void *data);
 int fuse_backing_close(struct fuse_conn *fc, int backing_id);
 
 /* passthrough.c */
fs/fuse/fuse_iomap.h +7 -0
index 7e5e073df5c92d..267bc55fb3368c 100644
@@ -20,6 +20,7 @@ static inline bool fuse_has_iomap(const struct inode *inode)
 }
 
 extern const struct fuse_backing_ops fuse_iomap_backing_ops;
+extern const struct fuse_backing_ops fuse_iomap_stripe_backing_ops;
 
 int fuse_iomap_mount_sync(struct fuse_mount *fm);
 void fuse_iomap_mount_async(struct fuse_mount *fm);
@@ -81,11 +82,15 @@ int fuse_iomap_backing_inval(struct fuse_conn *fc,
 			     const struct fuse_iomap_backing_inval_out *arg);
 int fuse_iomap_backing_set_blocksize(struct file *file,
 				     struct fuse_iomap_backing_info __user *argp);
+int fuse_iomap_backing_stripe_config(struct file *file,
+				     struct fuse_iomap_backing_stripe __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);
+
+void fuse_iomap_conn_free(struct fuse_conn *fc);
 #else
 # define fuse_iomap_enabled(...)		(false)
 # define fuse_has_iomap(...)			(false)
@@ -117,8 +122,10 @@ int fuse_iomap_inval_mappings(struct fuse_conn *fc,
 # define fuse_dev_ioctl_iomap_set_nofs(...)	(-EOPNOTSUPP)
 # define fuse_iomap_backing_inval(...)		(-ENOSYS)
 # define fuse_iomap_backing_set_blocksize(...)	(-EOPNOTSUPP)
+# define fuse_iomap_backing_stripe_config(...)	(-EOPNOTSUPP)
 # define fuse_iomap_upsert_mappings(...)	(-ENOSYS)
 # define fuse_iomap_inval_mappings(...)		(-ENOSYS)
+# define fuse_iomap_conn_free(...)		((void)0)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
fs/fuse/fuse_trace.h +3 -3
index 4a0b1900c85f6b..c36bd62bc450fd 100644
@@ -291,14 +291,14 @@ DECLARE_EVENT_CLASS(fuse_backing_class,
 	),
 
 	TP_fast_assign(
-		struct inode *inode = file_inode(fb->file);
+		struct inode *inode = fb->file ? file_inode(fb->file) : NULL;
 
 		__entry->connection	=	fc->dev;
 		__entry->id		=	fb->id;
-		__entry->ino		=	inode->i_ino;
+		__entry->ino		=	inode ? inode->i_ino : 0;
 		__entry->type		=	fb->ops->type;
 		if (fb->ops->type == FUSE_BACKING_TYPE_IOMAP)
-			__entry->rdev	=	inode->i_rdev;
+			__entry->rdev	=	inode ? inode->i_rdev : 0;
 		else
 			__entry->rdev	=	0;
 	),
include/uapi/linux/fuse.h +19 -0
index b47c48c0d73ee1..e0332de8383ac5 100644
@@ -1229,6 +1229,9 @@ struct fuse_iomap_backing_info {
 #define FUSE_DEV_IOC_IOMAP_BACKING_SET_BLOCKSIZE \
 					_IOW(FUSE_DEV_IOC_MAGIC, 102, \
 					     struct fuse_iomap_backing_info)
+#define FUSE_DEV_IOC_IOMAP_BACKING_STRIPE_CONFIG \
+					_IOW(FUSE_DEV_IOC_MAGIC, 103, \
+					     struct fuse_iomap_backing_stripe)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
@@ -1631,4 +1634,20 @@ struct fuse_iomap_upsert_mappings_out {
 	struct fuse_iomap_io	write;
 };
 
+struct fuse_iomap_backing_strip {
+	uint32_t dev;		/* device cookie */
+	uint32_t reserved;	/* zero */
+	uint64_t addr;		/* disk offset of strip, bytes */
+};
+
+#define FUSE_IOMAP_BACKING_MAX_STRIPS	(256)
+
+struct fuse_iomap_backing_stripe {
+	uint16_t nr_strips;	/* strip count */
+	uint8_t reserved[6];	/* zero */
+	uint64_t strip_width;	/* stripe width, bytes */
+
+	struct fuse_iomap_backing_strip strips[] __counted_by(nr_strips);
+};
+
 #endif /* _LINUX_FUSE_H */
fs/fuse/backing.c +83 -1

105 lines not on this page · raw message

fs/fuse/dev.c +2 -0
index db361788d7ee37..010fe4041c4da8 100644
@@ -2794,6 +2794,8 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
 		return fuse_dev_ioctl_add_iomap(file);
 	case FUSE_DEV_IOC_IOMAP_BACKING_SET_BLOCKSIZE:
 		return fuse_iomap_backing_set_blocksize(file, argp);
+	case FUSE_DEV_IOC_IOMAP_BACKING_STRIPE_CONFIG:
+		return fuse_iomap_backing_stripe_config(file, argp);
 
 	default:
 		return -ENOTTY;
fs/fuse/fuse_iomap.c +118 -0

127 lines not on this page · raw message

fs/fuse/inode.c +1 -0
index 365501b228ed11..17d35acd03b612 100644
@@ -1135,6 +1135,7 @@ void fuse_conn_put(struct fuse_conn *fc)
 		WARN_ON(atomic_read(&bucket->count) != 1);
 		kfree(bucket);
 	}
+	fuse_iomap_conn_free(fc);
 	if (IS_ENABLED(CONFIG_FUSE_BACKING))
 		fuse_backing_files_free(fc);
 	call_rcu(&fc->rcu, delayed_release);
#56 lore raw

PATCH 2/4 fuse_trace: allow fuse servers to upload stripe maps

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_trace.h |   44 +++++++++++++++++++++++++++++++++++++++++++-
 fs/fuse/backing.c    |    1 +
 fs/fuse/fuse_iomap.c |    2 ++
 3 files changed, 46 insertions(+), 1 deletion(-)
fs/fuse/fuse_trace.h +43 -1
index c36bd62bc450fd..caaa19ac4687bf 100644
@@ -275,7 +275,8 @@ TRACE_EVENT(fuse_setattr,
 #ifdef CONFIG_FUSE_BACKING
 #define FUSE_BACKING_FLAG_STRINGS \
 	{ FUSE_BACKING_TYPE_PASSTHROUGH,	"pass" }, \
-	{ FUSE_BACKING_TYPE_IOMAP,		"iomap" }
+	{ FUSE_BACKING_TYPE_IOMAP,		"iomap" }, \
+	{ FUSE_BACKING_TYPE_IOMAP_STRIPE,	"stripe" }
 
 DECLARE_EVENT_CLASS(fuse_backing_class,
 	TP_PROTO(const struct fuse_conn *fc, const struct fuse_backing *fb),
@@ -316,6 +317,47 @@ DEFINE_EVENT(fuse_backing_class, name,		\
 	TP_ARGS(fc, fb))
 DEFINE_FUSE_BACKING_EVENT(fuse_backing_open);
 DEFINE_FUSE_BACKING_EVENT(fuse_backing_close);
+DEFINE_FUSE_BACKING_EVENT(fuse_backing_create);
+
+DECLARE_EVENT_CLASS(fuse_backing_strip_class,
+	TP_PROTO(const struct fuse_conn *fc,
+		 const struct fuse_backing_stripe *bstripe,
+		 unsigned int strip_nr,
+		 const struct fuse_backing_strip *bstrip),
+
+	TP_ARGS(fc, bstripe, strip_nr, bstrip),
+
+	TP_STRUCT__entry(
+		__field(dev_t,			connection)
+		__field(unsigned int,		strip_nr)
+		__field(int,			strip_id)
+		__field(unsigned long long,	strip_width)
+		__field(unsigned long long,	strip_addr)
+	),
+
+	TP_fast_assign(
+		__entry->connection	=	fc->dev;
+		__entry->strip_nr	=	strip_nr;
+		__entry->strip_id	=	bstrip->dev;
+		__entry->strip_width	=	bstripe->strip_width;
+		__entry->strip_addr	=	bstrip->addr;
+	),
+
+	TP_printk("connection %u strip nr %u id %u width 0x%llx addr 0x%llx",
+		  __entry->connection,
+		  __entry->strip_nr,
+		  __entry->strip_id,
+		  __entry->strip_width,
+		  __entry->strip_addr)
+);
+#define DEFINE_FUSE_BACKING_STRIP_EVENT(name)			\
+DEFINE_EVENT(fuse_backing_strip_class, name, 			\
+	TP_PROTO(const struct fuse_conn *fc,	 		\
+		 const struct fuse_backing_stripe *bstripe,	\
+		 unsigned int strip_nr,				\
+		 const struct fuse_backing_strip *bstrip),	\
+	TP_ARGS(fc, bstripe, strip_nr, bstrip))
+DEFINE_FUSE_BACKING_STRIP_EVENT(fuse_backing_strip_config);
 #endif /* CONFIG_FUSE_BACKING */
 
 #if IS_ENABLED(CONFIG_FUSE_IOMAP)
fs/fuse/backing.c +1 -0
index 815b797b8f52f5..4075db710db591 100644
@@ -230,6 +230,7 @@ int fuse_backing_create(struct fuse_conn *fc,
 	fuse_backing_free(fb);
 	fb = NULL;
 
+	trace_fuse_backing_create(fc, fb);
 out:
 	pr_debug("%s: fb=0x%p, ret=%i\n", __func__, fb, res);
 	return res;
fs/fuse/fuse_iomap.c +2 -0
index 870822d24c0ca8..92fa9cd0d8044a 100644
@@ -3309,6 +3309,8 @@ int fuse_iomap_backing_stripe_config(struct file *file,
 
 		bstrip->dev = strip.dev;
 		bstrip->addr = strip.addr;
+
+		trace_fuse_backing_strip_config(fud->fc, bstripe, i, bstrip);
 	}
 
 	ret = fuse_backing_create(fud->fc, &fuse_iomap_stripe_backing_ops,
#57 lore raw

PATCH 3/4 fuse: implement striping for iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Implement the iomap code to handle the new stripe type by grabbing the virtual backing file and adjusting the mapping to point to a real device. Assuming iomap itself doesn't beat us to this.

---
 fs/fuse/fuse_iomap.h       |    1 
 include/uapi/linux/fuse.h  |    5 +
 fs/fuse/fuse_iomap.c       |  200 +++++++++++++++++++++++++++++++++++++++++++-
 fs/fuse/fuse_iomap_cache.c |    8 ++
 4 files changed, 210 insertions(+), 4 deletions(-)
fs/fuse/fuse_iomap.h +1 -0
index 267bc55fb3368c..faad28219b2793 100644
@@ -19,6 +19,7 @@ static inline bool fuse_has_iomap(const struct inode *inode)
 	return get_fuse_conn(inode)->iomap;
 }
 
+extern const struct fuse_backing_ops fuse_iomap_stripe_backing_ops;
 extern const struct fuse_backing_ops fuse_iomap_backing_ops;
 extern const struct fuse_backing_ops fuse_iomap_stripe_backing_ops;
 
include/uapi/linux/fuse.h +5 -0
index e0332de8383ac5..74e4c31664af0c 100644
@@ -253,6 +253,8 @@
  *    attributes
  *  - add FUSE_NOTIFY_IOMAP_{UPSERT,INVAL}_MAPPINGS so fuse servers can cache
  *    file range mappings in the kernel for iomap
+ *  - add FUSE_IOMAP_TYPE_STRIPE and FUSE_IOC_DEV_IOMAP_BACKING_STRIPE_CONFIG
+ *    so that fuse servers can tell teh kernel about filesystem striping
  */
 
 #ifndef _LINUX_FUSE_H
@@ -1422,6 +1424,9 @@ struct fuse_uring_cmd_req {
 #define FUSE_IOMAP_TYPE_RETRY_CACHE	(65534)
 /* do not upsert this mapping */
 #define FUSE_IOMAP_TYPE_NOCACHE		(65533)
+/* fuse-specific mapping type meaning stripe */
+#define FUSE_IOMAP_TYPE_MAPPED_STRIPE	(65532)
+#define FUSE_IOMAP_TYPE_UNWRITTEN_STRIPE (65531)
 
 #define FUSE_IOMAP_DEV_NULL		(0U)	/* null device cookie */
 
fs/fuse/fuse_iomap.c +196 -4

267 lines not on this page · raw message

fs/fuse/fuse_iomap_cache.c +8 -0
index 056782ba5248e3..bd74d09150e0ec 100644
@@ -1155,6 +1155,8 @@ static inline bool fuse_iomap_addrs_adjacent(const struct fuse_iomap_io *left,
 	switch (left->type) {
 	case FUSE_IOMAP_TYPE_MAPPED:
 	case FUSE_IOMAP_TYPE_UNWRITTEN:
+	case FUSE_IOMAP_TYPE_MAPPED_STRIPE:
+	case FUSE_IOMAP_TYPE_UNWRITTEN_STRIPE:
 		return left->addr + left->length == right->addr;
 	default:
 		return left->addr  == FUSE_IOMAP_NULL_ADDR &&
@@ -1255,6 +1257,8 @@ fuse_iext_del_mapping(
 	switch (del->type) {
 	case FUSE_IOMAP_TYPE_MAPPED:
 	case FUSE_IOMAP_TYPE_UNWRITTEN:
+	case FUSE_IOMAP_TYPE_MAPPED_STRIPE:
+	case FUSE_IOMAP_TYPE_UNWRITTEN_STRIPE:
 		del_endaddr = del->addr + del->length;
 		break;
 	default:
@@ -1400,6 +1404,8 @@ fuse_iomap_cache_remove(
 			break;
 		case FUSE_IOMAP_TYPE_MAPPED:
 		case FUSE_IOMAP_TYPE_UNWRITTEN:
+		case FUSE_IOMAP_TYPE_MAPPED_STRIPE:
+		case FUSE_IOMAP_TYPE_UNWRITTEN_STRIPE:
 			wasreal = true;
 			break;
 		default:
@@ -1727,6 +1733,8 @@ fuse_iomap_trim(
 	switch (got->type) {
 	case FUSE_IOMAP_TYPE_MAPPED:
 	case FUSE_IOMAP_TYPE_UNWRITTEN:
+	case FUSE_IOMAP_TYPE_MAPPED_STRIPE:
+	case FUSE_IOMAP_TYPE_UNWRITTEN_STRIPE:
 		mval->map.addr = got->addr;
 		break;
 	default:
#58 lore raw

PATCH 4/4 fuse_trace: implement striping for iomap

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add tracepoints for the previous patch.

---
 fs/fuse/fuse_trace.h |    7 ++++++-
 fs/fuse/fuse_iomap.c |    8 ++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
fs/fuse/fuse_trace.h +6 -1
index caaa19ac4687bf..7bbcc41cb22197 100644
@@ -457,7 +457,9 @@ struct fuse_iext_root;
 	{ FUSE_IOMAP_TYPE_DELALLOC,		"delalloc" }, \
 	{ FUSE_IOMAP_TYPE_MAPPED,		"mapped" }, \
 	{ FUSE_IOMAP_TYPE_UNWRITTEN,		"unwritten" }, \
-	{ FUSE_IOMAP_TYPE_INLINE,		"inline" }
+	{ FUSE_IOMAP_TYPE_INLINE,		"inline" }, \
+	{ FUSE_IOMAP_TYPE_MAPPED_STRIPE,	"mstripe" }, \
+	{ FUSE_IOMAP_TYPE_UNWRITTEN_STRIPE,	"ustripe" }
 
 #define FUSE_IOMAP_IOEND_STRINGS \
 	{ FUSE_IOMAP_IOEND_SHARED,		"shared" }, \
@@ -626,6 +628,9 @@ DEFINE_EVENT(fuse_iomap_mapping_class, name,	\
 	TP_ARGS(inode, map))
 DEFINE_FUSE_IOMAP_MAPPING_EVENT(fuse_iomap_read_map);
 DEFINE_FUSE_IOMAP_MAPPING_EVENT(fuse_iomap_write_map);
+DEFINE_FUSE_IOMAP_MAPPING_EVENT(fuse_iomap_read_stripe_map);
+DEFINE_FUSE_IOMAP_MAPPING_EVENT(fuse_iomap_write_stripe_map);
+DEFINE_FUSE_IOMAP_MAPPING_EVENT(fuse_iomap_cache_stripe_map);
 
 TRACE_EVENT(fuse_iomap_end,
 	TP_PROTO(const struct inode *inode,
fs/fuse/fuse_iomap.c +8 -0
index 14e411afefaed0..074b5d49be3eca 100644
@@ -847,6 +847,8 @@ static int fuse_iomap_from_cache(struct inode *inode, loff_t pos,
 		err = fuse_iomap_adjust_stripe(inode, pos, &lmap->map, &fb);
 		if (err)
 			goto out_backing;
+
+		trace_fuse_iomap_cache_stripe_map(inode, &lmap->map);
 	}
 
 	err = fuse_iomap_validate_bdev_access(fb, dir);
@@ -1112,6 +1114,8 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 						       &write_dev);
 			if (err)
 				goto out_write_dev;
+
+			trace_fuse_iomap_write_stripe_map(inode, &outarg.write);
 		}
 
 		if (fuse_iomap_is_striped(&outarg.read)) {
@@ -1119,6 +1123,8 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 						       &read_dev);
 			if (err)
 				goto out_write_dev;
+
+			trace_fuse_iomap_read_stripe_map(inode, &outarg.read);
 		}
 
 		err = fuse_iomap_validate_bdev_access(read_dev, READ_MAPPING);
@@ -1141,6 +1147,8 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t count,
 						       &read_dev);
 			if (err)
 				goto out_read_dev;
+
+			trace_fuse_iomap_read_stripe_map(inode, &outarg.read);
 		}
 
 		err = fuse_iomap_validate_bdev_access(read_dev,
maintainer
#9 lore raw

Re: [PATCH 2/4] fuse: store backing id in fuse_backing objects

In reply to Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Make fuse_backing objects know their own id, it'll make tracing and recovery of backing ids easier later on.

The problem is that in the context of fuse passthrough backing_id is just a temporary integer name of a fuse_backing object, but fuse_backing may outlive its backing_id (e.g. in fuse_inode_backing() and in extreme recycle situation a backing_id can be reassigned a new fuse_backing while the old fuse_backing object is still alive.

This only makes sense if backing devs ids are never closed, so maybe only if FUSE_IOMAP and FUSE_PASSTHROUGH are mutually exclusive (did we do that??) and FUSE_IOMAP never closes backing ids.

Thanks,
Amir.

#10 lore raw

Re: [PATCH 2/4] fuse: store backing id in fuse_backing objects

Quoted 13 lines · Amir Goldstein
Quoted 5 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Make fuse_backing objects know their own id, it'll make tracing and recovery of backing ids easier later on.

The problem is that in the context of fuse passthrough backing_id is just a temporary integer name of a fuse_backing object, but fuse_backing may outlive its backing_id (e.g. in fuse_inode_backing() and in extreme recycle situation a backing_id can be reassigned a new fuse_backing while the old fuse_backing object is still alive.

Quoted 3 lines

This only makes sense if backing devs ids are never closed, so maybe only if FUSE_IOMAP and FUSE_PASSTHROUGH are mutually exclusive (did we do that??) and FUSE_IOMAP never closes backing ids.

In iomap they're *nearly* uncloseable because we have no idea how many iomaps might be floating around (either in response to a FUSE_IOMAP_BEGIN; or in the mapping cache) the system.

However, if you can knock the number of iomap inodes down to zero, then you can close them.

<shrug> The self-contained id could be set to 0 on idr_free, so at least you'd see in the trace data that you were using an un-indexed fuse_backing.

--D

maintainer
#11 lore raw

Re: [PATCH 2/4] fuse: store backing id in fuse_backing objects

Quoted 23 lines · Darrick J. Wong
Quoted 13 lines · Amir Goldstein
Quoted 5 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Make fuse_backing objects know their own id, it'll make tracing and recovery of backing ids easier later on.

The problem is that in the context of fuse passthrough backing_id is just a temporary integer name of a fuse_backing object, but fuse_backing may outlive its backing_id (e.g. in fuse_inode_backing() and in extreme recycle situation a backing_id can be reassigned a new fuse_backing while the old fuse_backing object is still alive.

Quoted 3 lines

This only makes sense if backing devs ids are never closed, so maybe only if FUSE_IOMAP and FUSE_PASSTHROUGH are mutually exclusive (did we do that??) and FUSE_IOMAP never closes backing ids.

In iomap they're *nearly* uncloseable because we have no idea how many iomaps might be floating around (either in response to a FUSE_IOMAP_BEGIN; or in the mapping cache) the system.

Quoted 6 lines

However, if you can knock the number of iomap inodes down to zero, then you can close them.

<shrug> The self-contained id could be set to 0 on idr_free, so at least you'd see in the trace data that you were using an un-indexed fuse_backing.

sounds good.

Thanks,
Amir.

maintainer
#16 lore raw

Re: [PATCH 01/11] fuse: implement the basic iomap mechanisms

In reply to Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

iomap_begin - fetch a mapping for an I/O
iomap_end - submitted I/O, done with the mapping

Seems like the latter is more an internal implementation detail, not an interface to be exported to the fs server. Can you explain why filesystem servers would or should care?

Quoted 1 line

+/* mapping types; see corresponding IOMAP_TYPE_ */

I think we should not reference the kernel implementation of iomap. kAPI is not guaranteed to be stable, while this one must be. So this interface has to make sense without relying on the iomap kAPI definition.

[Occurs to me that I made the same mistake for the fuse API, so I should definitely try to properly document the interface now. That should also help with getting something saner for fusex]

I'm adding short definitions, yell if I got something wrong.

Quoted 1 line

+#define FUSE_IOMAP_TYPE_HOLE (0)

"unallocated, zeros returned"

Quoted 1 line

+#define FUSE_IOMAP_TYPE_DELALLOC (1)

"unallocated, zeroes returned, space is reserved"

Quoted 1 line

+#define FUSE_IOMAP_TYPE_MAPPED (2)

"allocated, data is valid"

Quoted 1 line

+#define FUSE_IOMAP_TYPE_UNWRITTEN (3)

"allocated, data is invalid, zeroes returned"

Quoted 1 line

+#define FUSE_IOMAP_TYPE_INLINE (4)

"cannot be mapped"

I'm not clearly seeing the difference between HOLE and DELALLOC in terms of how the iomap code deals with them. We really want description of semantic details, and I'm not finding those except in the code.

I also have a slightly bad feeling about IOMAP_BEGIN being used twice in the buffered write case for different purposes:

1) write to cache - AFAICS this is two functions rolled into one:

- space reservation: doesn't need the mapping, just returns
ACK/NACK, may need undoing on partial or failed I/O. May not be needed
- read-modify-write: mapping to initialize cache. Should be rare,
most writes are not this type

2) write to device - maybe allocate space, needs destination mapping

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1334

Quoted 2 lines
include/uapi/linux/fuse.h +2 -0
+/* fuse-specific mapping type indicating that writes use the read mapping */
+#define FUSE_IOMAP_TYPE_PURE_OVERWRITE (65535)

Does this need to be special cased? Based on the above, read and write mappings are never both used. The write mapping is only used when data is written to the device (DIO write or writeback) and in that case the read mapping is ignored.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+#define FUSE_IOMAP_DEV_NULL            (0U)    /* null device cookie */

This is for unallocated mappings? Not sure that it needs an explicit constant. Unused fields are always assumed to be zeroed.

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1339

Quoted 3 lines
include/uapi/linux/fuse.h +3 -0
+
+/* mapping flags passed back from iomap_begin; see corresponding IOMAP_F_ */
+#define FUSE_IOMAP_F_NEW               (1U << 0)

Definition in iomap.h implies this is about the need to zero blocks, but isn't that exactly the same as UNWRITTEN vs MAPPED?

Looking at iomap code: IOMAP_UNWRITTEN does imply zeroing, so FUSE_IOMAP_F_NEW is only useful for IOMAP_MAPPED. Confused.

Quoted 1 line

+#define FUSE_IOMAP_F_DIRTY (1U << 1)

The only affect this seems to have is to prevent FUA write in DIO
write path. FUA writes are an optimization? Or lack of FUA write is
an optimization?

Quoted 1 line

+#define FUSE_IOMAP_F_SHARED (1U << 2)

This is passed onto fiemap, it's useful to userspace but does not change iomap semantics. I note that while BTRFS obviously does use shared extents, it does not set this (or any other) iomap flag.

Quoted 1 line

+#define FUSE_IOMAP_F_MERGED (1U << 3)

Same as above. Only applies to fs which have block mappings instead of extent mappings.

Quoted 1 line

+#define FUSE_IOMAP_F_BOUNDARY (1U << 4)

Prevent merging of ioend calls. Fringe functionality, used by xfs for request trace group separation.

Quoted 1 line

+#define FUSE_IOMAP_F_ANON_WRITE (1U << 5)

Write mapping has a target device but no address. Only used by XFS. Don't really see if/how this applies to fuse-iomap.

Quoted 1 line

+#define FUSE_IOMAP_F_ATOMIC_BIO (1U << 6)

Filesystems (ext4, xfs) just turn IOMAP_ATOMIC request into
IOMAP_F_ATOMIC_BIO. Not quite sure why a trip through the filesystem
is needed.

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1348

Quoted 3 lines
include/uapi/linux/fuse.h +3 -0
+
+/* fuse-specific mapping flag asking for ->iomap_end call */
+#define FUSE_IOMAP_F_WANT_IOMAP_END    (1U << 7)

AFAICS, nothing actually uses this at this point. Can be dropped?

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1351

Quoted 3 lines
include/uapi/linux/fuse.h +3 -0
+
+/* mapping flags passed to iomap_end */
+#define FUSE_IOMAP_F_SIZE_CHANGED      (1U << 8)

This is used in fuse[24]fs, but with an XXX. It'd be really nice to be able to just drop FUSE_IOMAP_END, especially since it's easily confused with FUSE_IOMAP_IOEND, which does something very similar (and which I'd rename FUSE_IOEND, but let's save bikeshedding for later...)

Quoted 1 line

+#define FUSE_IOMAP_F_STALE (1U << 9)

Unused.

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1355

Quoted 3 lines
include/uapi/linux/fuse.h +3 -0
+
+/* operation flags from iomap; see corresponding IOMAP_* */
+#define FUSE_IOMAP_OP_WRITE            (1U << 0)

This is where it becomes really confusing. IOMAP_WRITE is used by buffered write and DIO write, but not for writeback. While DIO write and writeback has much more in common: actual write to device, needs write mapping.

Quoted 1 line

+#define FUSE_IOMAP_OP_ZERO (1U << 1)

Unused. FUSE_FALLOCATE already did this, no?

Quoted 1 line

+#define FUSE_IOMAP_OP_REPORT (1U << 2)

In all examples the code for READ and REPORT are identical. This seems to just add confusion and complexity at this point.

Quoted 1 line

+#define FUSE_IOMAP_OP_FAULT (1U << 3)

Unused.

Quoted 1 line

+#define FUSE_IOMAP_OP_DIRECT (1U << 4)

Is this just part of the IOMAP_WRITE / IOMAP_WRITEBACK confusion, or is it useful for something else as well?

Quoted 1 line

+#define FUSE_IOMAP_OP_NOWAIT (1U << 5)

Unused. If it's NOWAIT, it probably has no business in userspace.

Quoted 1 line

+#define FUSE_IOMAP_OP_OVERWRITE_ONLY (1U << 6)

Unused. Used by XFS for optimization purposes.

Quoted 1 line

+#define FUSE_IOMAP_OP_UNSHARE (1U << 7)

Fuse doesn't yet support reflinks.

Quoted 1 line

+#define FUSE_IOMAP_OP_DAX (1U << 8)

Unused.

Quoted 1 line

+#define FUSE_IOMAP_OP_ATOMIC (1U << 9)

Examples just do the FUSE_IOMAP_OP_ATOMIC -> FUSE_IOMAP_F_ATOMIC_BIO, exactly like in the kernel. A feature flag would allow getting rid of both flags.

Quoted 1 line

+#define FUSE_IOMAP_OP_DONTCACHE (1U << 10)

Unused.

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1372

Quoted 7 lines
include/uapi/linux/fuse.h +7 -0
+#define FUSE_IOMAP_OP_WRITEBACK                (1U << 11)
+
+/* file write operations */
+#define FUSE_IOMAP_OP_WRITE_MASK       (FUSE_IOMAP_OP_WRITE | \
+                                        FUSE_IOMAP_OP_ZERO | \
+                                        FUSE_IOMAP_OP_UNSHARE | \
+                                        FUSE_IOMAP_OP_WRITEBACK)

So this should instead be just FUSE_IOMAP_OP_WRITE: a single flag indicating that this is a request for a write mapping.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+#define FUSE_IOMAP_NULL_ADDR           (-1ULL) /* addr is not valid */

Hmm.

Quoted 4 lines
include/uapi/linux/fuse.h +4 -0
+
+struct fuse_iomap_io {
+       uint64_t offset;        /* file offset of mapping, bytes */
+       uint64_t length;        /* length of mapping, bytes */

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1388

Quoted 10 lines
include/uapi/linux/fuse.h +10 -0
+       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 */

Ugh, what is this for?

Quoted 8 lines
include/uapi/linux/fuse.h +8 -0
+       uint64_t pos;           /* file position, in bytes */
+       uint64_t count;         /* operation length, in bytes */
+};
+
+struct fuse_iomap_begin_out {
+       /*
+        * Read file data from here.  This must be set even for a write
+        * operation due to the possibility of a read-modify-write.

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1406

Quoted 10 lines
include/uapi/linux/fuse.h +10 -0
+        */
+       struct fuse_iomap_io    read;
+
+       /*
+        * Write file data to here.  This must be set even for a read
+        * operation.  If writes are not allowed, reply to the IOMAP_BEGIN
+        * command with EIO or EROFS.
+        */
+       struct fuse_iomap_io    write;
+};

So this is definitely an improvement over the kABI iomap/srcmap, but I do wonder if we could get away with a single map, OP_WRITE indicating which direction it should referring to.

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1417

Quoted 11 lines
include/uapi/linux/fuse.h +11 -0
+
+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, or a negative errno */
+
+       /* mapping that the kernel acted upon */
+       struct fuse_iomap_io    map;

If we do end up with this being needed, I wonder if we just need to save the needed state in the server and reference it with a cookie?

Thanks,
Miklos

#17 lore raw

Re: [PATCH 01/11] fuse: implement the basic iomap mechanisms

Quoted 9 lines · Miklos Szeredi
Quoted 5 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

iomap_begin - fetch a mapping for an I/O
iomap_end - submitted I/O, done with the mapping

It would be more accurate to say that we're done with the mapping. If the fuse server acquired a resource to provide a mapping (say a cluster lock since technically speaking iomap could be used for them) then it ought to release the lock when we're done with it.

Quoted 3 lines

Seems like the latter is more an internal implementation detail, not an interface to be exported to the fs server. Can you explain why filesystem servers would or should care?

A second example is, if your fuse server implements speculative preallocation (aka delayed allocation) and a pagecache write fails due to ENOMEM or something, you want to notify the fuse server so that it can release the preallocation.

Quoted 6 lines
Quoted 1 line

+/* mapping types; see corresponding IOMAP_TYPE_ */

I think we should not reference the kernel implementation of iomap. kAPI is not guaranteed to be stable, while this one must be. So this interface has to make sense without relying on the iomap kAPI definition.

Yeah, Christoph had the same reaction.

Quoted 9 lines

[Occurs to me that I made the same mistake for the fuse API, so I should definitely try to properly document the interface now. That should also help with getting something saner for fusex]

I'm adding short definitions, yell if I got something wrong.

Quoted 1 line

+#define FUSE_IOMAP_TYPE_HOLE (0)

"unallocated, zeros returned"

I would say "mapped" instead of "allocated", but yes.

Quoted 3 lines
Quoted 1 line

+#define FUSE_IOMAP_TYPE_DELALLOC (1)

"unallocated, zeroes returned, space is reserved"

"Unmapped, zeroes returned on read, space is reserved for a write"

Quoted 11 lines
Quoted 1 line

+#define FUSE_IOMAP_TYPE_MAPPED (2)

"allocated, data is valid"

Quoted 1 line

+#define FUSE_IOMAP_TYPE_UNWRITTEN (3)

"allocated, data is invalid, zeroes returned"

Quoted 1 line

+#define FUSE_IOMAP_TYPE_INLINE (4)

"cannot be mapped"

Inline is a weird one, it means that we have to call the server to do actual IO.

Quoted 4 lines

I'm not clearly seeing the difference between HOLE and DELALLOC in terms of how the iomap code deals with them. We really want description of semantic details, and I'm not finding those except in the code.

You can't buffered write into a hole because that means there's no space available to land the write, but you can write if there's a reservation. Writeback isn't supposed to fail with ENOSPC.

(You can't direct write into a hole or a reservation either, but that's not illustrative for my argument.)

It's critical that the kernel knows the mapping state is correct even if iomap itself doesn't care about the difference.

Quoted 5 lines

I also have a slightly bad feeling about IOMAP_BEGIN being used twice in the buffered write case for different purposes:

1) write to cache - AFAICS this is two functions rolled into one:

Quoted 7 lines

- space reservation: doesn't need the mapping, just returns
ACK/NACK, may need undoing on partial or failed I/O. May not be needed
- read-modify-write: mapping to initialize cache. Should be rare,
most writes are not this type

2) write to device - maybe allocate space, needs destination mapping

Yes it is. I actually had half a mind *not* to duplicate the IOMAP op flags and instead provide an enumeration:

IOMAP_OP_READ read{ahead}ing the pagecache from disk
IOMAP_OP_WRITE writing to the pagecache
IOMAP_OP_ZERO zeroing folios around an unaligned write
IOMAP_OP_WRITEBACK writing to disk

IOMAP_OP_UNSHARE trigger cow for shared extents

IOMAP_OP_DIRECTIO_READ directio
IOMAP_OP_DIRECTIO_WRITE

IOMAP_OP_FIEMAP fiemap/bmap

IOMAP_OP_LEASE_LAYOUT swapon, effectively
IOMAP_OP_REVOKE_LAYOUT swapoff

IOMAP_OP_DAX_READ fsdax "io"
IOMAP_OP_DAX_WRITE

The tricky part is that some of these op flags are mutually exclusive and some are really just flags. Well, maybe we can have a u8 op type and a u24 flags field.

Quoted 7 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1334

Quoted 2 lines
include/uapi/linux/fuse.h +2 -0
+/* fuse-specific mapping type indicating that writes use the read mapping */
+#define FUSE_IOMAP_TYPE_PURE_OVERWRITE (65535)

Does this need to be special cased? Based on the above, read and write mappings are never both used. The write mapping is only used when data is written to the device (DIO write or writeback) and in that case the read mapping is ignored.

I'll get to read vs. write mapping at the bottom, but let's just say yes provisionally for now. :)

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+#define FUSE_IOMAP_DEV_NULL            (0U)    /* null device cookie */

This is for unallocated mappings? Not sure that it needs an explicit constant. Unused fields are always assumed to be zeroed.

Correct, this is for any mapping type that isn't MAPPED or UNWRITTEN. Yes, we can assume it's zero, but in light of the recent rseq input validation mess I decided to crank up the level of validation.

Quoted 9 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1339

Quoted 3 lines
include/uapi/linux/fuse.h +3 -0
+
+/* mapping flags passed back from iomap_begin; see corresponding IOMAP_F_ */
+#define FUSE_IOMAP_F_NEW               (1U << 0)

Definition in iomap.h implies this is about the need to zero blocks, but isn't that exactly the same as UNWRITTEN vs MAPPED?

Looking at iomap code: IOMAP_UNWRITTEN does imply zeroing, so FUSE_IOMAP_F_NEW is only useful for IOMAP_MAPPED. Confused.

Old unix filesystems don't have unwritten mappings, so any newly allocated blocks get MAPPED status and have to be zeroed.

Quoted 5 lines
Quoted 1 line

+#define FUSE_IOMAP_F_DIRTY (1U << 1)

The only affect this seems to have is to prevent FUA write in DIO
write path. FUA writes are an optimization? Or lack of FUA write is
an optimization?

Correct -- if the inode is dirty, directio writes can't just issue an FUA with the write and call it a day; it also needs the ioend callback to know when to flush the dirty inode. This flag just turns off the FUA since we can write the data + metadata and then issue CACHE FLUSH.

Quoted 5 lines
Quoted 1 line

+#define FUSE_IOMAP_F_SHARED (1U << 2)

This is passed onto fiemap, it's useful to userspace but does not change iomap semantics. I note that while BTRFS obviously does use shared extents, it does not set this (or any other) iomap flag.

btrfs doesn't use iomap for pagecache operations

Quoted 4 lines
Quoted 1 line

+#define FUSE_IOMAP_F_MERGED (1U << 3)

Same as above. Only applies to fs which have block mappings instead of extent mappings.

Right, this one's for FIEMAP.

Quoted 4 lines
Quoted 1 line

+#define FUSE_IOMAP_F_BOUNDARY (1U << 4)

Prevent merging of ioend calls. Fringe functionality, used by xfs for request trace group separation.

It prevents merging of writes to a zoned block device.

Quoted 4 lines
Quoted 1 line

+#define FUSE_IOMAP_F_ANON_WRITE (1U << 5)

Write mapping has a target device but no address. Only used by XFS. Don't really see if/how this applies to fuse-iomap.

This triggers the "WRITE APPEND" command for zbd devices, so the FUSE_IOMAP_IOEND handler can use the returned disk address to update its own file mapping.

Quoted 5 lines
Quoted 1 line

+#define FUSE_IOMAP_F_ATOMIC_BIO (1U << 6)

Filesystems (ext4, xfs) just turn IOMAP_ATOMIC request into
IOMAP_F_ATOMIC_BIO. Not quite sure why a trip through the filesystem
is needed.

For any atomic write that crosses an allocation unit boundary, you have to ask the filesystem so that it has the opportunity to reject the write if it can't atomically persist a multi-fsblock mapping update.

It might be the case that we can relax that if the awu min/max would allow it.

Quoted 4 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1348

Quoted 2 lines
include/uapi/linux/fuse.h +2 -0
+/* fuse-specific mapping flag asking for ->iomap_end call */
+#define FUSE_IOMAP_F_WANT_IOMAP_END    (1U << 7)

AFAICS, nothing actually uses this at this point. Can be dropped?

I don't know. There are filesystems like gfs2 that hold a transaction open between ->iomap_begin and ->iomap_end, so the ->iomap_end call is definitely required. This may or may not be necessary for userspace filesystems, but I wouldn't wager against giving userspace a flag to force the FUSE_IOMAP_END command.

Quoted 8 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1351

Quoted 3 lines
include/uapi/linux/fuse.h +3 -0
+
+/* mapping flags passed to iomap_end */
+#define FUSE_IOMAP_F_SIZE_CHANGED      (1U << 8)

This is used in fuse[24]fs, but with an XXX. It'd be really nice to be able to just drop FUSE_IOMAP_END, especially since it's easily confused with FUSE_IOMAP_IOEND, which does something very similar (and which I'd rename FUSE_IOEND, but let's save bikeshedding for later...)

That's a good point, FUSE_IOMAP_IOEND should just be FUSE_IOEND.

Quoted 3 lines
Quoted 1 line

+#define FUSE_IOMAP_F_STALE (1U << 9)

Unused.

This can be set by iomap internally. I don't think there's a need to expose ths one to userspace.

Quoted 9 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1355

Quoted 3 lines
include/uapi/linux/fuse.h +3 -0
+
+/* operation flags from iomap; see corresponding IOMAP_* */
+#define FUSE_IOMAP_OP_WRITE            (1U << 0)

This is where it becomes really confusing. IOMAP_WRITE is used by buffered write and DIO write, but not for writeback. While DIO write and writeback has much more in common: actual write to device, needs write mapping.

Quoted 3 lines
Quoted 1 line

+#define FUSE_IOMAP_OP_ZERO (1U << 1)

Unused. FUSE_FALLOCATE already did this, no?

This is for pagecache zeroing when doing an unaligned write to the pagecache.

Quoted 10 lines
Quoted 1 line

+#define FUSE_IOMAP_OP_REPORT (1U << 2)

In all examples the code for READ and REPORT are identical. This seems to just add confusion and complexity at this point.

Quoted 1 line

+#define FUSE_IOMAP_OP_FAULT (1U << 3)

Unused.

page_mkwrite (aka mmap write faults)

Quoted 4 lines
Quoted 1 line

+#define FUSE_IOMAP_OP_DIRECT (1U << 4)

Is this just part of the IOMAP_WRITE / IOMAP_WRITEBACK confusion, or is it useful for something else as well?

FUSE_IOMAP_OP_WRITE writes to the pagecache
FUSE_IOMAP_OP_WRITEBACK writes pagecache to disk

FUSE_IOMAP_OP_WRITE | FUSE_IOMAP_OP_DIRECT is a directio write

Quoted 3 lines
Quoted 1 line

+#define FUSE_IOMAP_OP_NOWAIT (1U << 5)

Unused. If it's NOWAIT, it probably has no business in userspace.

Later on it means that we can query the cache but not call the server.

Quoted 7 lines
Quoted 1 line

+#define FUSE_IOMAP_OP_OVERWRITE_ONLY (1U << 6)

Unused. Used by XFS for optimization purposes.

Quoted 1 line

+#define FUSE_IOMAP_OP_UNSHARE (1U << 7)

Fuse doesn't yet support reflinks.

Actually it can already, if a fuse server only does directio and catches FICLONERANGE/FICLONE directly in its FUSE_IOCTL handler.

Quoted 3 lines
Quoted 1 line

+#define FUSE_IOMAP_OP_DAX (1U << 8)

Unused.

BUt probably needed for famfs.

Quoted 11 lines
Quoted 1 line

+#define FUSE_IOMAP_OP_ATOMIC (1U << 9)

Examples just do the FUSE_IOMAP_OP_ATOMIC -> FUSE_IOMAP_F_ATOMIC_BIO, exactly like in the kernel. A feature flag would allow getting rid of both flags.

Quoted 1 line

+#define FUSE_IOMAP_OP_DONTCACHE (1U << 10)

Unused.

Quoted 1 line

+#define FUSE_IOMAP_OP_WRITEBACK (1U << 11)

overwrite_only, atomic, and dontcache are actually flags. And yeah, they're not needed right now but I don't want to have to burn FUSE_CAP_ flags to add them later when I could just -EOPNOTSUPP them now. ;)

Quoted 9 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1372

Quoted 6 lines
include/uapi/linux/fuse.h +6 -0
+
+/* file write operations */
+#define FUSE_IOMAP_OP_WRITE_MASK       (FUSE_IOMAP_OP_WRITE | \
+                                        FUSE_IOMAP_OP_ZERO | \
+                                        FUSE_IOMAP_OP_UNSHARE | \
+                                        FUSE_IOMAP_OP_WRITEBACK)

So this should instead be just FUSE_IOMAP_OP_WRITE: a single flag indicating that this is a request for a write mapping.

That's how iomap started, and now we have zero and unshare too.

Quoted 3 lines
Quoted 1 line

+#define FUSE_IOMAP_NULL_ADDR (-1ULL) /* addr is not valid */

Hmm.

LBA 0 is valid.

Quoted 8 lines
Quoted 8 lines
include/uapi/linux/fuse.h +8 -0
+
+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 */
Quoted 8 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1388

Quoted 6 lines
include/uapi/linux/fuse.h +6 -0
+};
+
+struct fuse_iomap_begin_in {
+       uint32_t opflags;       /* FUSE_IOMAP_OP_* */
+       uint32_t reserved;      /* zero */
+       uint64_t attr_ino;      /* matches fuse_attr:ino */

Ugh, what is this for?

This is an ugly hack for high level fuse servers, because libfuse assigns internal nodeids which may have nothing to do with what the fuse server thinks are its own inode numbers.

The reason why this is necessary at all is that iomap operations can target files that are no longer open (e.g. writeback after the last file closes) so there might not be a fuse_file available to imprint a fh value.

Another strike against high level fuse servers using iomap is that you can't support hardlinks because if you hardlink /mount/a to /mount/b, the high level fuse library will assign different nodeids (and create separate kernel inodes) for a and b.

That might be a bug in libfuse?

Quoted 14 lines
Quoted 14 lines
include/uapi/linux/fuse.h +14 -0
+       uint64_t pos;           /* file position, in bytes */
+       uint64_t count;         /* operation length, in bytes */
+};
+
+struct fuse_iomap_begin_out {
+       /*
+        * Read file data from here.  This must be set even for a write
+        * operation due to the possibility of a read-modify-write.
+        */
+       struct fuse_iomap_io    read;
+
+       /*
+        * Write file data to here.  This must be set even for a read
+        * operation.  If writes are not allowed, reply to the IOMAP_BEGIN
Quoted 8 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1406

Quoted 4 lines
include/uapi/linux/fuse.h +4 -0
+        * command with EIO or EROFS.
+        */
+       struct fuse_iomap_io    write;
+};

So this is definitely an improvement over the kABI iomap/srcmap, but I do wonder if we could get away with a single map, OP_WRITE indicating which direction it should referring to.

Not really. Pagecache write operations can require both a read source and a(n alleged) write destination if someone tries an unaligned write to an uncached region of the file.

XFS/iomap started with a single iomap, and the direction was implied by the opflags. This didn't work so well when I added out of place writes to XFS; for that, the "srcmap" was stapled on the side. I don't like that, and various porters get confused by it, so I decided I'd instead have explicit read and write mappings for fuse-iomap.

Note that a log structured filesystem (aka what iomap_ow_ll.c does) also needs the out of place write ability.

Quoted 5 lines
Quoted 5 lines
include/uapi/linux/fuse.h +5 -0
+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 */
Quoted 8 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1417

Quoted 5 lines
include/uapi/linux/fuse.h +5 -0
+       uint64_t count;         /* operation length, in bytes */
+       int64_t written;        /* bytes processed, or a negative errno */
+
+       /* mapping that the kernel acted upon */
+       struct fuse_iomap_io    map;

If we do end up with this being needed, I wonder if we just need to save the needed state in the server and reference it with a cookie?

You'd have to enlarge the iomap_begin response to have a cookie field, and the fuse server would then have to track those cookies. I think it's easier just to echo back whatever mapping got used, particularly since the server won't know to make a cookie if the mapping came from the cache.

(Or it has to create the cookie at upsert time, and maintain that until whatever unspecified point the cache drops the mapping. Then the cache has to be able to tell the fuse server that XX cookie can go away.)

--D

maintainer
#18 lore raw

Re: [PATCH 01/11] fuse: implement the basic iomap mechanisms

[Cc: Christoph]

Quoted 10 lines · Darrick J. Wong
Quoted 4 lines · Miklos Szeredi

On Wed, 20 May 2026 at 00:26, Darrick J. Wong <[email protected]> wrote:

iomap_begin - fetch a mapping for an I/O
iomap_end - submitted I/O, done with the mapping

It would be more accurate to say that we're done with the mapping. If the fuse server acquired a resource to provide a mapping (say a cluster lock since technically speaking iomap could be used for them) then it ought to release the lock when we're done with it.

You are talking about things that this first version definitely doesn't want to handle. Stick to local fs for now, especially if it just means leaving out parts of the interface that can later be added.

And that's a general comment, if we don't want to get bogged down with reviewing thousands of lines of new code, then try to minimize the functionality. If the first version only supported R/O mounts, I'd be totally fine with that.

Your current patchset is a prototype: it shows what's possible, but
that doesn't mean it has to be merged in one go. Let's try to go in
baby steps towards the goal that your prototype has set. But cluster
locks are even beyond that goal, so just ignore them for now.

Quoted 4 lines

A second example is, if your fuse server implements speculative preallocation (aka delayed allocation) and a pagecache write fails due to ENOMEM or something, you want to notify the fuse server so that it can release the preallocation.

That's a FALLOC_FL_PUNCH_HOLE operation, no? Fuse already supports that.

Quoted 9 lines
Quoted 4 lines

I'm not clearly seeing the difference between HOLE and DELALLOC in terms of how the iomap code deals with them. We really want description of semantic details, and I'm not finding those except in the code.

You can't buffered write into a hole because that means there's no space available to land the write, but you can write if there's a reservation. Writeback isn't supposed to fail with ENOSPC.

Quoted 5 lines

(You can't direct write into a hole or a reservation either, but that's not illustrative for my argument.)

It's critical that the kernel knows the mapping state is correct even if iomap itself doesn't care about the difference.

IDGI. When a write to device (DIO write/writeback) happens, and iomap queries the mapping, the filesystem must return one with IOMAP_UNWRITTEN or IOMAP_MAPPED, no?

So where does the kernel check the state?

Quoted 11 lines
Quoted 11 lines

I also have a slightly bad feeling about IOMAP_BEGIN being used twice in the buffered write case for different purposes:

1) write to cache - AFAICS this is two functions rolled into one:

- space reservation: doesn't need the mapping, just returns
ACK/NACK, may need undoing on partial or failed I/O. May not be needed
- read-modify-write: mapping to initialize cache. Should be rare,
most writes are not this type

Quoted 3 lines
Quoted 1 line

2) write to device - maybe allocate space, needs destination mapping

Yes it is.

-ECANTPARSE

Quoted 4 lines

I actually had half a mind *not* to duplicate the IOMAP op
flags and instead provide an enumeration:

IOMAP_OP_READ read{ahead}ing the pagecache from disk

Okay.

Quoted 1 line

IOMAP_OP_WRITE writing to the pagecache

This is not an IOMAP operation. Writing to the page cache does not
need to know the mapping. It needs to reserve/allocate space, but
that's private to the filesystem, the page cache couldn't care less about where that data will eventually go.

If the pagecache write need to read data, then make that an IOMAP_OP_READ.

If we wan't to combine allocation with read, that's fine, we'll do that with compound requests in due course.

Quoted 1 line

IOMAP_OP_ZERO zeroing folios around an unaligned write

Again, fuse already supports FALLOC_FL_ZERO_RANGE. Having two interfaces for the same thing doesn't make sense.

Quoted 1 line

IOMAP_OP_WRITEBACK writing to disk

Call this IOMAP_OP_WRITE.

Quoted 1 line

IOMAP_OP_UNSHARE trigger cow for shared extents

FALLOC_FL_UNSHARE_RANGE + IOMAP_OP_WRITE

Quoted 2 lines

IOMAP_OP_DIRECTIO_READ directio
IOMAP_OP_DIRECTIO_WRITE

What's the difference from their non-DIO counterparts?

Quoted 1 line

IOMAP_OP_FIEMAP fiemap/bmap

Why is this different from IOMAP_OP_READ?

Quoted 2 lines

IOMAP_OP_LEASE_LAYOUT swapon, effectively
IOMAP_OP_REVOKE_LAYOUT swapoff

This can also be a new "exclusive lease" op + IOMAP_OP_WRITE

Quoted 2 lines

IOMAP_OP_DAX_READ fsdax "io"
IOMAP_OP_DAX_WRITE

All parties should know about what sort of device they are dealing
with, block or dax or whatever. This info doesn't need to be sent
across the interface again and again.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

+#define FUSE_IOMAP_DEV_NULL (0U) /* null device cookie */

This is for unallocated mappings? Not sure that it needs an explicit constant. Unused fields are always assumed to be zeroed.

Correct, this is for any mapping type that isn't MAPPED or UNWRITTEN. Yes, we can assume it's zero, but in light of the recent rseq input validation mess I decided to crank up the level of validation.

I'm not against validating unused fields, that's fine. But the initialization can be implicit. This simplifies the interface and the code.

Quoted 11 lines
Quoted 8 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1339

Quoted 2 lines
include/uapi/linux/fuse.h +2 -0
+/* mapping flags passed back from iomap_begin; see corresponding IOMAP_F_ */
+#define FUSE_IOMAP_F_NEW               (1U << 0)

Definition in iomap.h implies this is about the need to zero blocks, but isn't that exactly the same as UNWRITTEN vs MAPPED?

Looking at iomap code: IOMAP_UNWRITTEN does imply zeroing, so FUSE_IOMAP_F_NEW is only useful for IOMAP_MAPPED. Confused.

Old unix filesystems don't have unwritten mappings, so any newly allocated blocks get MAPPED status and have to be zeroed.

So why can't old unix filesystems just say this is an IOMAP_UNWRITTEN extent instead of a IOMAP_MAPPED extent with an FUSE_IOMAP_F_NEW flag?
Seems the two are exactly equivalent from an interface PoV.

Quoted 10 lines
Quoted 5 lines
Quoted 1 line

+#define FUSE_IOMAP_F_DIRTY (1U << 1)

The only affect this seems to have is to prevent FUA write in DIO
write path. FUA writes are an optimization? Or lack of FUA write is
an optimization?

Correct -- if the inode is dirty, directio writes can't just issue an FUA with the write and call it a day; it also needs the ioend callback to know when to flush the dirty inode. This flag just turns off the FUA since we can write the data + metadata and then issue CACHE FLUSH.

Okay, so it's just an optimization. I'd say, omit for now.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

+#define FUSE_IOMAP_F_SHARED (1U << 2)

This is passed onto fiemap, it's useful to userspace but does not change iomap semantics. I note that while BTRFS obviously does use shared extents, it does not set this (or any other) iomap flag.

btrfs doesn't use iomap for pagecache operations

What does fiemap has to do with the pagecache?

Quoted 10 lines
Quoted 4 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1348

Quoted 2 lines
include/uapi/linux/fuse.h +2 -0
+/* fuse-specific mapping flag asking for ->iomap_end call */
+#define FUSE_IOMAP_F_WANT_IOMAP_END    (1U << 7)

AFAICS, nothing actually uses this at this point. Can be dropped?

I don't know. There are filesystems like gfs2 that hold a transaction open between ->iomap_begin and ->iomap_end, so the ->iomap_end call is definitely required. This may or may not be necessary for userspace filesystems, but I wouldn't wager against giving userspace a flag to force the FUSE_IOMAP_END command.

Please drop all "I wouldn't wager against" types of features without a thought.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+#define FUSE_IOMAP_OP_FAULT (1U << 3)

Unused.

page_mkwrite (aka mmap write faults)

But filesystems (at least the prototype ones) simply don't care. Just drop.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+#define FUSE_IOMAP_OP_NOWAIT (1U << 5)

Unused. If it's NOWAIT, it probably has no business in userspace.

Later on it means that we can query the cache but not call the server.

So it's internal to the cache and doesn't ever reach the server. Please drop.

Quoted 4 lines

overwrite_only, atomic, and dontcache are actually flags. And yeah, they're not needed right now but I don't want to have to burn FUSE_CAP_ flags to add them later when I could just -EOPNOTSUPP them now. ;)

Don't worry about that. Really. Just drop everything that is not
needed RIGHT NOW to have a working implementation. And I mean working, not optimized. Optimization is the last step.

Dropping code is easy and it makes review faster, and at this point review is the biggest bottleneck. Yeah, <insert favorite AI> can review patches by the truckful, but it cannot evaluate design decisions and high level stuff.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+#define FUSE_IOMAP_NULL_ADDR (-1ULL) /* addr is not valid */

Hmm.

LBA 0 is valid.

So what? It's an unmapped extent, the address is not used. Leave it zero and validate that it's zero.

Quoted 6 lines

Another strike against high level fuse servers using iomap is that you can't support hardlinks because if you hardlink /mount/a to /mount/b, the high level fuse library will assign different nodeids (and create separate kernel inodes) for a and b.

That might be a bug in libfuse?

Right. Just drop highlevel support for iomap and be done with that.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
include/uapi/linux/fuse.h +10 -0
+struct fuse_iomap_begin_out {
+       /*
+        * Read file data from here.  This must be set even for a write
+        * operation due to the possibility of a read-modify-write.
+        */
+       struct fuse_iomap_io    read;
+
+       /*
+        * Write file data to here.  This must be set even for a read
+        * operation.  If writes are not allowed, reply to the IOMAP_BEGIN
Quoted 8 lines

include/uapi/linux/fuse.h struct fuse_uring_cmd_req { · line 1406

Quoted 4 lines
include/uapi/linux/fuse.h +4 -0
+        * command with EIO or EROFS.
+        */
+       struct fuse_iomap_io    write;
+};

So this is definitely an improvement over the kABI iomap/srcmap, but I do wonder if we could get away with a single map, OP_WRITE indicating which direction it should referring to.

Quoted 3 lines

Not really. Pagecache write operations can require both a read source and a(n alleged) write destination if someone tries an unaligned write to an uncached region of the file.

Why does that need a write destination? It needs a promise that the space was reserved for the write. It doesn't need the actual
destination. And DELALLOC is exactly that: a promise. A zero
return value is perfectly fine for that. A failed reservation would return -ENOSPC.

Thanks,
Miklos

maintainer Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] fuse: move the passthrough-specific code back to passthrough.c

In reply to Darrick J. Wong
Quoted 9 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

Please add

and please keep in it future postings even with minor changes. I realize that fuse_backing_id_remove() was changed in this version, so that's fine, but I only know that because recent revision still fits in my ever shrinking context window..

We discussed the fact that no one has lots of spare time for review and re-review is a big production killer (in general).

You must know that very well as a review and also that having a "what has changed since last patch rev" is very useful for reviewers and also very expensive for authors to maintain... ...unless AI agents can help to generate per patch Changes for the post --- notes?

I assume that Agent can do that on a patch set after it was created just by giving it two sets of patches?
For the very least, producing a "No changes since v.." should be easy and useful.
Letting Agent go over mailbox and verifying that all RVBs have been applied is also trivial.
I realize that patchworks and b4 review can help with these tasks but they are more tuned for maintainers and less for authors (I think).

Obviously, I could do that with an agent on my side, but that is not a good use of resources and not a good model to put this burden on all the reviewers.

Worth a try IMO.

Thanks,
Amir.

maintainer
#7 lore raw

Re: [PATCH 1/4] fuse: move the passthrough-specific code back to passthrough.c

In reply to Darrick J. Wong

include/uapi/linux/fuse.h struct fuse_notify_prune_out { · line 1134

Quoted 6 lines · Darrick J. Wong
include/uapi/linux/fuse.h +6 -0
+#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)
+

Please drop the last two defines. The _MAX and _ALL style non-constants are essentially an automatic API breaker. There's no sane use for them, and insane ones WILL get broken when they change.

Thanks,
Miklos

#50 lore raw

Re: [PATCH 9/9] fuse: set iomap backing device block size

In reply to Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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

If I'm understanding it correctly, doesn't the fs/iomap layer align all i/o to the fuse file inode->i_blkbits and submits bios to the underlying iomap->bdev without ever reading the bdev's inode->i_blkbits? Why do we need this fuse ioctl then for setting the block size of a bdev?

It seems like this ioctl is re-implementing the BLKBSZSET ioctl but bypasses the cap sys admin privilege checking that the BLKBSZSET ioctl requires, which seems like a security violation. Am I understanding this correctly?

Thanks,
Joanne

Quoted 106 lines
---
 fs/fuse/fuse_iomap.h      |    3 +++
 include/uapi/linux/fuse.h |    8 ++++++++
 fs/fuse/dev.c             |    2 ++
 fs/fuse/fuse_iomap.c      |   27 +++++++++++++++++++++++++++
 4 files changed, 40 insertions(+)
fs/fuse/fuse_iomap.h +3 -0
index f40d202c64c822..3cfef073cbe5aa 100644
@@ -69,6 +69,8 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
 int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 int fuse_iomap_backing_inval(struct fuse_conn *fc,
                             const struct fuse_iomap_backing_inval_out *arg);
+int fuse_iomap_backing_set_blocksize(struct file *file,
+                                    struct fuse_iomap_backing_info __user *argp);
 #else
 # define fuse_iomap_enabled(...)               (false)
 # define fuse_has_iomap(...)                   (false)
@@ -97,6 +99,7 @@ int fuse_iomap_backing_inval(struct fuse_conn *fc,
 # define fuse_dev_ioctl_iomap_support(...)     (-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_set_nofs(...)    (-EOPNOTSUPP)
 # define fuse_iomap_backing_inval(...)         (-ENOSYS)
+# define fuse_iomap_backing_set_blocksize(...) (-EOPNOTSUPP)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
include/uapi/linux/fuse.h +8 -0
index 899964f8d6616a..0b67938bb7baf0 100644
@@ -1173,6 +1173,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)
@@ -1184,6 +1189,9 @@ 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_BACKING_SET_BLOCKSIZE \
+                                       _IOW(FUSE_DEV_IOC_MAGIC, 102, \
+                                            struct fuse_iomap_backing_info)
 
 struct fuse_lseek_in {
        uint64_t        fh;
fs/fuse/dev.c +2 -0
index 06f52114b9aef2..d6ba8d6b1a8875 100644
@@ -2746,6 +2746,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_BACKING_SET_BLOCKSIZE:
+               return fuse_iomap_backing_set_blocksize(file, argp);
 
        default:
                return -ENOTTY;
fs/fuse/fuse_iomap.c +27 -0
index ba54eb694dbbac..2deed4749738cb 100644
@@ -2448,3 +2448,30 @@ int fuse_iomap_backing_inval(struct fuse_conn *fc,
        up_read(&fc->killsb);
        return ret;
 }
+
+int fuse_iomap_backing_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;
+}
#44 lore raw

Re: [PATCH 7/9] fuse: invalidate ranges of backing devices being used for iomap

In reply to Darrick J. Wong
Quoted 9 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

imo this would be cleaner going through the ioctl backing interface instead of through notifications.

I was thinking of something similar in idea for this for passthrough where you're able to dynamically update or invalidate a mapping corresponding to a backing id. It'd be great if we could both use the same uapi.

Quoted 44 lines
---
 fs/fuse/fuse_iomap.h      |    3 ++
 include/uapi/linux/fuse.h |   20 ++++++++++++++++
 fs/fuse/dev.c             |   28 +++++++++++++++++++++++
 fs/fuse/fuse_iomap.c      |   56 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 107 insertions(+)
fs/fuse/fuse_iomap.h +3 -0
index c4b98123072a37..f40d202c64c822 100644
@@ -67,6 +67,8 @@ 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_nofs(struct file *file, uint32_t __user *argp);
+int fuse_iomap_backing_inval(struct fuse_conn *fc,
+                            const struct fuse_iomap_backing_inval_out *arg);
 #else
 # define fuse_iomap_enabled(...)               (false)
 # define fuse_has_iomap(...)                   (false)
@@ -94,6 +96,7 @@ int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 # define fuse_dev_ioctl_add_iomap(...)         (-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_support(...)     (-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_set_nofs(...)    (-EOPNOTSUPP)
+# define fuse_iomap_backing_inval(...)         (-ENOSYS)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
include/uapi/linux/fuse.h +1 -0
index 0366101be3a321..899964f8d6616a 100644
@@ -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_BACKING_INVAL to invalidate iomap bdev ranges
  */
 
 #ifndef _LINUX_FUSE_H

include/uapi/linux/fuse.h enum fuse_notify_code { · line 711

Quoted 5 lines
include/uapi/linux/fuse.h +2 -0
@@ -706,6 +707,8 @@ enum fuse_notify_code {
        FUSE_NOTIFY_RESEND = 7,
        FUSE_NOTIFY_INC_EPOCH = 8,
        FUSE_NOTIFY_PRUNE = 9,
+       FUSE_NOTIFY_IOMAP_BACKING_INVAL = 99,
+       FUSE_NOTIFY_CODE_MAX,

Could you explain why this is 99 and not just 10? Btw, I don't think we can define the max enum code like this in uapi, as I think that will break backwards compatibilty when upgrading to a new kernel if new opcodes get added in the future. I don't see this getting used anywhere in the series anyways though so maybe best to just delete it?

Thanks,
Joanne

#45 lore raw

Re: [PATCH 7/9] fuse: invalidate ranges of backing devices being used for iomap

Quoted 11 lines · Joanne Koong
Quoted 9 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

Quoted 7 lines

imo this would be cleaner going through the ioctl backing interface instead of through notifications.

I was thinking of something similar in idea for this for passthrough where you're able to dynamically update or invalidate a mapping corresponding to a backing id. It'd be great if we could both use the same uapi.

What do you mean by update a mapping?

FWIW the functionality here is a lot like POSIX_FADV_DONTNEED, except that we actually want to wait for writeback and tear down all the folios in the range because it's mandatory, not advisory.

(TBH it's more like what filesystems do to the pagecache prior to a fallocate punch-hole operation).

Quoted 42 lines
Quoted 42 lines
---
 fs/fuse/fuse_iomap.h      |    3 ++
 include/uapi/linux/fuse.h |   20 ++++++++++++++++
 fs/fuse/dev.c             |   28 +++++++++++++++++++++++
 fs/fuse/fuse_iomap.c      |   56 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 107 insertions(+)
fs/fuse/fuse_iomap.h +3 -0
index c4b98123072a37..f40d202c64c822 100644
@@ -67,6 +67,8 @@ 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_nofs(struct file *file, uint32_t __user *argp);
+int fuse_iomap_backing_inval(struct fuse_conn *fc,
+                            const struct fuse_iomap_backing_inval_out *arg);
 #else
 # define fuse_iomap_enabled(...)               (false)
 # define fuse_has_iomap(...)                   (false)
@@ -94,6 +96,7 @@ int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 # define fuse_dev_ioctl_add_iomap(...)         (-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_support(...)     (-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_set_nofs(...)    (-EOPNOTSUPP)
+# define fuse_iomap_backing_inval(...)         (-ENOSYS)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
include/uapi/linux/fuse.h +1 -0
index 0366101be3a321..899964f8d6616a 100644
@@ -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_BACKING_INVAL to invalidate iomap bdev ranges
  */
 
Quoted 9 lines

include/uapi/linux/fuse.h enum fuse_notify_code { · line 711

Quoted 7 lines
include/uapi/linux/fuse.h +2 -0
 #ifndef _LINUX_FUSE_H
@@ -706,6 +707,8 @@ enum fuse_notify_code {
        FUSE_NOTIFY_RESEND = 7,
        FUSE_NOTIFY_INC_EPOCH = 8,
        FUSE_NOTIFY_PRUNE = 9,
+       FUSE_NOTIFY_IOMAP_BACKING_INVAL = 99,
+       FUSE_NOTIFY_CODE_MAX,

Could you explain why this is 99 and not just 10? Btw, I don't think

More of me just making it obvious where my development tree starts. :)

Quoted 4 lines

we can define the max enum code like this in uapi, as I think that will break backwards compatibilty when upgrading to a new kernel if new opcodes get added in the future. I don't see this getting used anywhere in the series anyways though so maybe best to just delete it?

Yeah, Miklos already said up-thread to remove the _MAX constants from the UABI.

--D

Quoted 3 lines

Thanks,
Joanne

#51 lore raw

Re: [PATCH 9/9] fuse: set iomap backing device block size

In reply to Joanne Koong
Quoted 4 lines · Joanne Koong
Quoted 3 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Quoted 8 lines
Quoted 2 lines

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

If I'm understanding it correctly, doesn't the fs/iomap layer align all i/o to the fuse file inode->i_blkbits and submits bios to the underlying iomap->bdev without ever reading the bdev's inode->i_blkbits? Why do we need this fuse ioctl then for setting the block size of a bdev?

It's not for the regular file IO, it's for the blockdev pagecache that sits in front of filesystem metadata IO. Block devices do writeback of their pagecache in units of buffer heads, which is a problem if the buffer head size is not aligned to the fsblock size.

Basically, imagine a 1k-fsblock filesystem with 4k pages. Let us further assume that block 0 is a superblock, and block 1 is the only file data in the whole filesystem.

If the BLKBSZGET size is also 4k, then dirtying the superblock now means that the bdev pagecache will think that the whole 4k is dirty, because there's only one bh for the whole 4k.

Now let's say iomap writes to the sole file data block. The ondisk data is newer than the bdev pagecache. Next, the fuse server initiates writeout of the dirty bdev pagecache. It writes the whole page out to disk, which means the ondisk super is newest, but the file data block has just been clobbered by stale bdev pagecache!

Ouch.

So if we can set the bh size to 1k, we avoid the clobbering.

Quoted 4 lines

It seems like this ioctl is re-implementing the BLKBSZSET ioctl but bypasses the cap sys admin privilege checking that the BLKBSZSET ioctl requires, which seems like a security violation. Am I understanding this correctly?

It is, but the assumption was that you'd only get fuse-iomap if you already had CAP_SYS_RAWIO, so you have to have some privilege. But I concede that RAWIO != ADMIN. This might be unnecessary now that fuse service containers can ask the mount helper to open a bdev in O_EXCL mode and set a particular blocksize.

Though note the weird thing -- a sysadmin can use chmod to let unprivileged userspace to open a bdev and it can open it O_EXCL, but it can't set the block size unless they have CAP_SYS_ADMIN.

--D

Quoted 110 lines

Thanks,
Joanne

Quoted 106 lines
---
 fs/fuse/fuse_iomap.h      |    3 +++
 include/uapi/linux/fuse.h |    8 ++++++++
 fs/fuse/dev.c             |    2 ++
 fs/fuse/fuse_iomap.c      |   27 +++++++++++++++++++++++++++
 4 files changed, 40 insertions(+)
fs/fuse/fuse_iomap.h +3 -0
index f40d202c64c822..3cfef073cbe5aa 100644
@@ -69,6 +69,8 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
 int fuse_dev_ioctl_iomap_set_nofs(struct file *file, uint32_t __user *argp);
 int fuse_iomap_backing_inval(struct fuse_conn *fc,
                             const struct fuse_iomap_backing_inval_out *arg);
+int fuse_iomap_backing_set_blocksize(struct file *file,
+                                    struct fuse_iomap_backing_info __user *argp);
 #else
 # define fuse_iomap_enabled(...)               (false)
 # define fuse_has_iomap(...)                   (false)
@@ -97,6 +99,7 @@ int fuse_iomap_backing_inval(struct fuse_conn *fc,
 # define fuse_dev_ioctl_iomap_support(...)     (-EOPNOTSUPP)
 # define fuse_dev_ioctl_iomap_set_nofs(...)    (-EOPNOTSUPP)
 # define fuse_iomap_backing_inval(...)         (-ENOSYS)
+# define fuse_iomap_backing_set_blocksize(...) (-EOPNOTSUPP)
 #endif /* CONFIG_FUSE_IOMAP */
 
 #endif /* _FS_FUSE_IOMAP_H */
include/uapi/linux/fuse.h +8 -0
index 899964f8d6616a..0b67938bb7baf0 100644
@@ -1173,6 +1173,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)
@@ -1184,6 +1189,9 @@ 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_BACKING_SET_BLOCKSIZE \
+                                       _IOW(FUSE_DEV_IOC_MAGIC, 102, \
+                                            struct fuse_iomap_backing_info)
 
 struct fuse_lseek_in {
        uint64_t        fh;
fs/fuse/dev.c +2 -0
index 06f52114b9aef2..d6ba8d6b1a8875 100644
@@ -2746,6 +2746,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_BACKING_SET_BLOCKSIZE:
+               return fuse_iomap_backing_set_blocksize(file, argp);
 
        default:
                return -ENOTTY;
fs/fuse/fuse_iomap.c +27 -0
index ba54eb694dbbac..2deed4749738cb 100644
@@ -2448,3 +2448,30 @@ int fuse_iomap_backing_inval(struct fuse_conn *fc,
        up_read(&fc->killsb);
        return ret;
 }
+
+int fuse_iomap_backing_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;
+}
#46 lore raw

Re: [PATCH 7/9] fuse: invalidate ranges of backing devices being used for iomap

In reply to Darrick J. Wong
Quoted 4 lines · Darrick J. Wong
Quoted 2 lines · Joanne Koong
Quoted 1 line · Darrick J. Wong
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Darrick J. Wong <[email protected]>

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.

Rereading this patch... (or maybe just reading it correctly for the first time now :P)

If I'm understanding it correctly, the problem it's trying to solve is that the block device has its own page cache (separate from the fuse inode page cache) and when the fuseblk server or fuse iomap server is unmounted and done interacting with the block device, there's still data in the block device's cache that lingers - is this correct?

Is userspace not able to handle this themselves by flushing + invalidating the block device's cache with the BLKFLSBUF ioctl call?

Quoted 10 lines
Quoted 8 lines

imo this would be cleaner going through the ioctl backing interface instead of through notifications.

I was thinking of something similar in idea for this for passthrough where you're able to dynamically update or invalidate a mapping corresponding to a backing id. It'd be great if we could both use the same uapi.

What do you mean by update a mapping?

I don't think my previous comment applies to your patch - I had misinterpreted "invalidate ranges of backing devices" as meaning invalidating the range of a file that is mapped to a backing file/device.

Thanks,
Joanne

Quoted 7 lines

FWIW the functionality here is a lot like POSIX_FADV_DONTNEED, except that we actually want to wait for writeback and tear down all the folios in the range because it's mandatory, not advisory.

(TBH it's more like what filesystems do to the pagecache prior to a fallocate punch-hole operation).

#52 lore raw

Re: [PATCH 9/9] fuse: set iomap backing device block size

In reply to Darrick J. Wong
Quoted 34 lines · Darrick J. Wong
Quoted 4 lines · Joanne Koong
Quoted 3 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Quoted 8 lines
Quoted 2 lines

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

If I'm understanding it correctly, doesn't the fs/iomap layer align all i/o to the fuse file inode->i_blkbits and submits bios to the underlying iomap->bdev without ever reading the bdev's inode->i_blkbits? Why do we need this fuse ioctl then for setting the block size of a bdev?

It's not for the regular file IO, it's for the blockdev pagecache that sits in front of filesystem metadata IO. Block devices do writeback of their pagecache in units of buffer heads, which is a problem if the buffer head size is not aligned to the fsblock size.

Basically, imagine a 1k-fsblock filesystem with 4k pages. Let us further assume that block 0 is a superblock, and block 1 is the only file data in the whole filesystem.

If the BLKBSZGET size is also 4k, then dirtying the superblock now means that the bdev pagecache will think that the whole 4k is dirty, because there's only one bh for the whole 4k.

Now let's say iomap writes to the sole file data block. The ondisk data is newer than the bdev pagecache. Next, the fuse server initiates writeout of the dirty bdev pagecache. It writes the whole page out to disk, which means the ondisk super is newest, but the file data block has just been clobbered by stale bdev pagecache!

Quoted 3 lines

Ouch.

So if we can set the bh size to 1k, we avoid the clobbering.

Thanks for the explanation.

From what I remember, fuseblk servers can pass in a size at mount time for what the kernel should use for filesystem inode i_blkbits size. imo it seems like the responsibility of the fuse server to make sure to pass in a value that matches the buffer head size of the block device it's using, or does this not suffice for what you need?

Thanks,
Joanne

Quoted 18 lines
Quoted 5 lines

It seems like this ioctl is re-implementing the BLKBSZSET ioctl but bypasses the cap sys admin privilege checking that the BLKBSZSET ioctl requires, which seems like a security violation. Am I understanding this correctly?

It is, but the assumption was that you'd only get fuse-iomap if you already had CAP_SYS_RAWIO, so you have to have some privilege. But I concede that RAWIO != ADMIN. This might be unnecessary now that fuse service containers can ask the mount helper to open a bdev in O_EXCL mode and set a particular blocksize.

Though note the weird thing -- a sysadmin can use chmod to let unprivileged userspace to open a bdev and it can open it O_EXCL, but it can't set the block size unless they have CAP_SYS_ADMIN.

--D

#53 lore raw

Re: [PATCH 9/9] fuse: set iomap backing device block size

Quoted 39 lines · Joanne Koong
Quoted 34 lines · Darrick J. Wong
Quoted 4 lines · Joanne Koong
Quoted 3 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Quoted 8 lines
Quoted 2 lines

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

If I'm understanding it correctly, doesn't the fs/iomap layer align all i/o to the fuse file inode->i_blkbits and submits bios to the underlying iomap->bdev without ever reading the bdev's inode->i_blkbits? Why do we need this fuse ioctl then for setting the block size of a bdev?

It's not for the regular file IO, it's for the blockdev pagecache that sits in front of filesystem metadata IO. Block devices do writeback of their pagecache in units of buffer heads, which is a problem if the buffer head size is not aligned to the fsblock size.

Basically, imagine a 1k-fsblock filesystem with 4k pages. Let us further assume that block 0 is a superblock, and block 1 is the only file data in the whole filesystem.

If the BLKBSZGET size is also 4k, then dirtying the superblock now means that the bdev pagecache will think that the whole 4k is dirty, because there's only one bh for the whole 4k.

Now let's say iomap writes to the sole file data block. The ondisk data is newer than the bdev pagecache. Next, the fuse server initiates writeout of the dirty bdev pagecache. It writes the whole page out to disk, which means the ondisk super is newest, but the file data block has just been clobbered by stale bdev pagecache!

Quoted 3 lines

Ouch.

So if we can set the bh size to 1k, we avoid the clobbering.

Quoted 7 lines

Thanks for the explanation.

From what I remember, fuseblk servers can pass in a size at mount time for what the kernel should use for filesystem inode i_blkbits size. imo it seems like the responsibility of the fuse server to make sure to pass in a value that matches the buffer head size of the block device it's using, or does this not suffice for what you need?

Correct, but fuseblk only works with a single block device, whereas you can open multiple block devices, register them as iomap backing files, and use all of them with files. You might have sufficient privilege to open the bdev O_EXCL, but not necessarily CAP_SYS_ADMIN to change the blocksize.

--D

Quoted 21 lines

Thanks,
Joanne

Quoted 18 lines
Quoted 5 lines

It seems like this ioctl is re-implementing the BLKBSZSET ioctl but bypasses the cap sys admin privilege checking that the BLKBSZSET ioctl requires, which seems like a security violation. Am I understanding this correctly?

It is, but the assumption was that you'd only get fuse-iomap if you already had CAP_SYS_RAWIO, so you have to have some privilege. But I concede that RAWIO != ADMIN. This might be unnecessary now that fuse service containers can ask the mount helper to open a bdev in O_EXCL mode and set a particular blocksize.

Though note the weird thing -- a sysadmin can use chmod to let unprivileged userspace to open a bdev and it can open it O_EXCL, but it can't set the block size unless they have CAP_SYS_ADMIN.

--D

#47 lore raw

Re: [PATCH 7/9] fuse: invalidate ranges of backing devices being used for iomap

In reply to Joanne Koong
Quoted 14 lines · Joanne Koong
Quoted 4 lines · Darrick J. Wong
Quoted 2 lines · Joanne Koong
Quoted 1 line · Darrick J. Wong
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Darrick J. Wong <[email protected]>

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.

Quoted 6 lines

Rereading this patch... (or maybe just reading it correctly for the first time now :P)

If I'm understanding it correctly, the problem it's trying to solve is that the block device has its own page cache (separate from the fuse inode page cache)

Right.

Quoted 3 lines

and when the fuseblk server or fuse iomap server is
unmounted and done interacting with the block device, there's still data in the block device's cache that lingers - is this correct?

Not quite -- the fuse server could allocate a block to a file (well before unmount) that was previously a metadata block, and now it wants to dump the pagecache and ensure the kernel isn't doing any writeback that could race with a subsequent iomap write.

(fuse4fs does it the other way -- every time it frees a block, it wants to flush the pagecache to quiesce any IO, just in case it later wants to reallocate it. Technically you only have to do that with metadata blocks, but libext2fs isn't smart enough to know the difference.)

Quoted 2 lines

Is userspace not able to handle this themselves by flushing + invalidating the block device's cache with the BLKFLSBUF ioctl call?

We don't want to flush the entire bdev page cache, just the block that we're freeing or allocating.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

imo this would be cleaner going through the ioctl backing interface instead of through notifications.

I was thinking of something similar in idea for this for passthrough where you're able to dynamically update or invalidate a mapping corresponding to a backing id. It'd be great if we could both use the same uapi.

Quoted 6 lines
Quoted 1 line

What do you mean by update a mapping?

I don't think my previous comment applies to your patch - I had misinterpreted "invalidate ranges of backing devices" as meaning invalidating the range of a file that is mapped to a backing file/device.

Ah, ok. Glad I could clear up some confusion then. :)

--D

Quoted 10 lines

Thanks,
Joanne

Quoted 7 lines

FWIW the functionality here is a lot like POSIX_FADV_DONTNEED, except that we actually want to wait for writeback and tear down all the folios in the range because it's mandatory, not advisory.

(TBH it's more like what filesystems do to the pagecache prior to a fallocate punch-hole operation).

#4 lore raw

Re: [PATCH 1/4] fuse: move the passthrough-specific code back to passthrough.c

In reply to Amir Goldstein
Quoted 39 lines · Amir Goldstein
Quoted 9 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

Please add

and please keep in it future postings even with minor changes. I realize that fuse_backing_id_remove() was changed in this version, so that's fine, but I only know that because recent revision still fits in my ever shrinking context window..

We discussed the fact that no one has lots of spare time for review and re-review is a big production killer (in general).

You must know that very well as a review and also that having a "what has changed since last patch rev" is very useful for reviewers and also very expensive for authors to maintain... ...unless AI agents can help to generate per patch Changes for the post --- notes?

I assume that Agent can do that on a patch set after it was created just by giving it two sets of patches?
For the very least, producing a "No changes since v.." should be easy and useful.
Letting Agent go over mailbox and verifying that all RVBs have been applied is also trivial.
I realize that patchworks and b4 review can help with these tasks but they are more tuned for maintainers and less for authors (I think).

Quoted 5 lines

Obviously, I could do that with an agent on my side, but that is not a good use of resources and not a good model to put this burden on all the reviewers.

Worth a try IMO.

How about a range diff? e.g.

https://lore.kernel.org/linux-fsdevel/177758364789.1315233.15610945404741826500.stg-ugh@frogsfrogsfrogs/

I think I'd rather spit those out than either (a) try to remember all the changes (esp. minor ones) that I slipped in between two patchbombs, or (b) go all agenthappy.

--D

Quoted 3 lines

Thanks,
Amir.

maintainer
#5 lore raw

Re: [PATCH 1/4] fuse: move the passthrough-specific code back to passthrough.c

Quoted 47 lines · Darrick J. Wong
Quoted 39 lines · Amir Goldstein
Quoted 9 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

Please add

and please keep in it future postings even with minor changes. I realize that fuse_backing_id_remove() was changed in this version, so that's fine, but I only know that because recent revision still fits in my ever shrinking context window..

We discussed the fact that no one has lots of spare time for review and re-review is a big production killer (in general).

You must know that very well as a review and also that having a "what has changed since last patch rev" is very useful for reviewers and also very expensive for authors to maintain... ...unless AI agents can help to generate per patch Changes for the post --- notes?

I assume that Agent can do that on a patch set after it was created just by giving it two sets of patches?
For the very least, producing a "No changes since v.." should be easy and useful.
Letting Agent go over mailbox and verifying that all RVBs have been applied is also trivial.
I realize that patchworks and b4 review can help with these tasks but they are more tuned for maintainers and less for authors (I think).

Quoted 5 lines

Obviously, I could do that with an agent on my side, but that is not a good use of resources and not a good model to put this burden on all the reviewers.

Worth a try IMO.

Quoted 7 lines

How about a range diff? e.g.

https://lore.kernel.org/linux-fsdevel/177758364789.1315233.15610945404741826500.stg-ugh@frogsfrogsfrogs/

I think I'd rather spit those out than either (a) try to remember all the changes (esp. minor ones) that I slipped in between two patchbombs, or (b) go all agenthappy.

Maybe I don't know.
At the very least, range diff would provide the annotation "no change since last version", which I find useful.

My point was that the load of reviews is very high so if something can be done to reduce the load of re-review it is going to be a win.

Anyway, as long as my RVB is preserved across revisions I am good.

Thanks,
Amir.

maintainer
#6 lore raw

Re: [PATCH 1/4] fuse: move the passthrough-specific code back to passthrough.c

In reply to Darrick J. Wong
Quoted 47 lines · Darrick J. Wong
Quoted 39 lines · Amir Goldstein
Quoted 9 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

Please add

and please keep in it future postings even with minor changes. I realize that fuse_backing_id_remove() was changed in this version, so that's fine, but I only know that because recent revision still fits in my ever shrinking context window..

We discussed the fact that no one has lots of spare time for review and re-review is a big production killer (in general).

You must know that very well as a review and also that having a "what has changed since last patch rev" is very useful for reviewers and also very expensive for authors to maintain... ...unless AI agents can help to generate per patch Changes for the post --- notes?

I assume that Agent can do that on a patch set after it was created just by giving it two sets of patches?
For the very least, producing a "No changes since v.." should be easy and useful.
Letting Agent go over mailbox and verifying that all RVBs have been applied is also trivial.
I realize that patchworks and b4 review can help with these tasks but they are more tuned for maintainers and less for authors (I think).

Quoted 5 lines

Obviously, I could do that with an agent on my side, but that is not a good use of resources and not a good model to put this burden on all the reviewers.

Worth a try IMO.

Quoted 7 lines

How about a range diff? e.g.

https://lore.kernel.org/linux-fsdevel/177758364789.1315233.15610945404741826500.stg-ugh@frogsfrogsfrogs/

I think I'd rather spit those out than either (a) try to remember all the changes (esp. minor ones) that I slipped in between two patchbombs, or (b) go all agenthappy.

I'am open to anything, but the patchbomb thing isn't helping, that I can see.

For trying out a prototype posting git url's is perfectly fine. For
review we need to go with single patchsets that are manageable size.

Some general suggestions towards this goal:

- leave out anything that's not strictly needed (e.g. tracing).
- add only minimal functionality to be able make it do something
useful (e.g. read-only, DIO-only, etc)
- add to the uAPI only parts that are actually used, leaving reserved
space in structs is okay

I can understand that the additional work seems unnecessary and overwhelming, but I don't see any other way of sanely integrating something of this magnitude.

Thanks,
Miklos