Fuse-BPF and plans on merging with Fuse Passthrough
v4 cover Fuse-BPF and plans on merging with Fuse Passthrough
I've recently gotten some time to re-focus on fuse-bpf efforts, and had some questions on how to best integrate with recent changes that have landed in the last year. I've included a rebased version (ontop of bpf-next e63985ecd226 ("bpf, riscv64/cfi: Support kCFI + BPF on riscv64") of the old patchset for reference here.
On the bpf end, I'm struggling a little bit with the interface for selecting programs. I'd like to be able to pass the map id to fuse, since that's a value userspace already knows the program by. Would it be reasonable to either pass that ID down to the registration function, or otherwise provide a path for a separate module to translate from a map id to a struct_op program?
On the fuse end, I'm wondering how the interface will extend to directories. At LSFMMBPF last year, some people brought up concerns with the interface we had, specifically that it required opens to get fds, which we'd then use to respond to lookup requests, adding a lot of extra overhead. I had been planning to switch to a path that the response would supply instead, likely limited by RESOLVE_BENEATH. That seems pretty different from Fuse Passthrough's approach. Are there any current plans on how that interface will extend for a directory passthrough?
Could someone clarify why passthrough has an extra layer to register for use as a backing file? Does the ioctl provide some additional tracking purpose? I recall there being some security issue around directly responding with the fd. In fuse-bpf, we were handling this by responding to the fuse request via an ioctl in those cases.
Passthrough also maintains a separate cred instance for each backing file. I had been planning to have a single one for the userspace daemon, likely grabbed during the init response. I'm unsure how the current Passthrough method there should scale to directories.
Now on to my plans. Struct ops programs have more dynamic support now [1]. I'm hoping to be able to move most of the Fuse BPF related code to live closer to Fuse, and to have it more neatly encapsulated when building as a module. I'm not sure if everything that's needed for that exists, but I need to play with it a bit more to understand what I'm missing. I'll probably show up at bpf office hours at some point.
Struct ops have proper multi page support now [2], which removes another patch. I'm still slightly over the struct ops limit, but that may change with other changes I'm considering.
I'm very excited to see the new generic stacking filesystem support with backing-file [3]. I imagine in time we'll extend that to have a backing-inode as well, for the various inode_operations. That will definitely involve a lot of refactoring of the way fuse-bpf is currently structured, but it's clearly the right way forward.
I'm glad to see fuse passthrough, which provides a subset of the fuse-bpf functionality, has landed[4]. I'm planning to rework the patch set to integrate better with that. First off, I've been considering splitting up the bpf progam into a dentry, inode, and file set. That has the added bonus of pushing us back down below the current struct_op function list limits. I would want to establish some linkage between the sets, so that you could still just set the bpf program at a folder level, and have all objects underneath inherit the correct program. That's not an issue for a version with just file support, but I'll want to ensure the interface extends naturally. With the increased module support, I plan to redo all of the bpf program linking anyways. The existing code was a temporary placeholder while the method of registering struct ops programs was still in flux.
My plan for the next patch set is to prune down to just the file operations. That removes a lot of the tricky questions for the moment, and should shrink down the patch set massively. Along with that, I'll clean up the struct_op implementation to take more advantage of the recent bpf additions.
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/20240105-vfs-rw-9b5809292b57@brauner/
[4] https://lore.kernel.org/all/CAJfpegsZoLMfcpBXBPr7wdAnuXfAYUZYyinru3jrOWWEz7DJPQ@mail.gmail.com/
Daniel Rosenberg (36):
fuse-bpf: Update fuse side uapi
fuse-bpf: Add data structures for fuse-bpf
fuse-bpf: Prepare for fuse-bpf patch
fuse: Add fuse-bpf, a stacked fs extension for FUSE
fuse-bpf: Add ioctl interface for /dev/fuse
fuse-bpf: Don't support export_operations
fuse-bpf: Add support for access
fuse-bpf: Partially add mapping support
fuse-bpf: Add lseek support
fuse-bpf: Add support for fallocate
fuse-bpf: Support file/dir open/close
fuse-bpf: Support mknod/unlink/mkdir/rmdir
fuse-bpf: Add support for read/write iter
fuse-bpf: support readdir
fuse-bpf: Add support for sync operations
fuse-bpf: Add Rename support
fuse-bpf: Add attr support
fuse-bpf: Add support for FUSE_COPY_FILE_RANGE
fuse-bpf: Add xattr support
fuse-bpf: Add symlink/link support
fuse-bpf: Add partial flock support
fuse-bpf: Add partial ioctl support
fuse-bpf: allow mounting with no userspace daemon
fuse-bpf: Add fuse-bpf constants
bpf: Increase struct_op max members
WIP: bpf: Add fuse_ops struct_op programs
fuse-bpf: Export Functions
fuse: Provide registration functions for fuse-bpf
fuse-bpf: Set fuse_ops at mount or lookup time
fuse-bpf: Call bpf for pre/post filters
fuse-bpf: Add userspace pre/post filters
WIP: fuse-bpf: add error_out
fuse-bpf: Add default filter op
tools: Add FUSE, update bpf includes
fuse-bpf: Add selftests
fuse: Provide easy way to test fuse struct_op call
fs/fuse/Kconfig | 8 + fs/fuse/Makefile | 1 + fs/fuse/backing.c | 4287 +++++++++++++++++ fs/fuse/bpf_register.c | 207 + fs/fuse/control.c | 2 +- fs/fuse/dev.c | 85 +- fs/fuse/dir.c | 318 +- fs/fuse/file.c | 126 +- fs/fuse/fuse_i.h | 472 +- fs/fuse/inode.c | 377 +- fs/fuse/ioctl.c | 11 +- fs/fuse/readdir.c | 5 + fs/fuse/xattr.c | 18 + include/linux/bpf.h | 2 +- include/linux/bpf_fuse.h | 285 ++ include/uapi/linux/bpf.h | 13 + include/uapi/linux/fuse.h | 41 + kernel/bpf/Makefile | 4 + kernel/bpf/bpf_fuse.c | 716 +++ kernel/bpf/bpf_struct_ops.c | 2 + kernel/bpf/btf.c | 1 + kernel/bpf/verifier.c | 10 +- tools/include/uapi/linux/bpf.h | 13 + tools/include/uapi/linux/fuse.h | 1197 +++++ .../selftests/filesystems/fuse/.gitignore | 2 + .../selftests/filesystems/fuse/Makefile | 189 + .../testing/selftests/filesystems/fuse/OWNERS | 2 + .../selftests/filesystems/fuse/bpf_common.h | 51 + .../selftests/filesystems/fuse/bpf_loader.c | 597 +++ .../testing/selftests/filesystems/fuse/fd.txt | 21 + .../selftests/filesystems/fuse/fd_bpf.bpf.c | 397 ++ .../selftests/filesystems/fuse/fuse_daemon.c | 300 ++ .../selftests/filesystems/fuse/fuse_test.c | 2476 ++++++++++ .../filesystems/fuse/struct_op_test.bpf.c | 642 +++ .../selftests/filesystems/fuse/test.bpf.c | 1045 ++++ .../filesystems/fuse/test_framework.h | 172 + .../selftests/filesystems/fuse/test_fuse.h | 494 ++ 37 files changed, 14385 insertions(+), 204 deletions(-) create mode 100644 fs/fuse/backing.c create mode 100644 fs/fuse/bpf_register.c create mode 100644 include/linux/bpf_fuse.h create mode 100644 kernel/bpf/bpf_fuse.c create mode 100644 tools/include/uapi/linux/fuse.h create mode 100644 tools/testing/selftests/filesystems/fuse/.gitignore create mode 100644 tools/testing/selftests/filesystems/fuse/Makefile create mode 100644 tools/testing/selftests/filesystems/fuse/OWNERS create mode 100644 tools/testing/selftests/filesystems/fuse/bpf_common.h create mode 100644 tools/testing/selftests/filesystems/fuse/bpf_loader.c create mode 100644 tools/testing/selftests/filesystems/fuse/fd.txt create mode 100644 tools/testing/selftests/filesystems/fuse/fd_bpf.bpf.c create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_daemon.c create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_test.c create mode 100644 tools/testing/selftests/filesystems/fuse/struct_op_test.bpf.c create mode 100644 tools/testing/selftests/filesystems/fuse/test.bpf.c create mode 100644 tools/testing/selftests/filesystems/fuse/test_framework.h create mode 100644 tools/testing/selftests/filesystems/fuse/test_fuse.h
base-commit: e63985ecd22681c7f5975f2e8637187a326b6791
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 1/36 fuse-bpf: Update fuse side uapi
Adds structures which will be used to inform fuse about what it is being stacked on top of. Once filters are in place, error_in will inform the post filter if the backing call returned an error.
--- include/uapi/linux/fuse.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
include/uapi/linux/fuse.h +23 -0
@@ -654,6 +654,29 @@ struct fuse_entry_out {struct fuse_attr attr; }; +#define FUSE_BPF_MAX_ENTRIES 2 + +enum fuse_bpf_type { +FUSE_ENTRY_BACKING =1 , +FUSE_ENTRY_BPF =2 , +FUSE_ENTRY_REMOVE_BACKING =3 , +FUSE_ENTRY_REMOVE_BPF =4 , +}; + +#define BPF_FUSE_NAME_MAX 15 + +struct fuse_bpf_entry_out { +uint32_t entry_type; +uint32_t unused; +union { +struct { +uint64_t unused2; +uint64_t fd; + }; +char name[BPF_FUSE_NAME_MAX +1 ]; + }; +}; +struct fuse_forget_in {uint64_t nlookup; };
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 2/36 fuse-bpf: Add data structures for fuse-bpf
In reply to Daniel RosenbergThese structures will be used to interact between the fuse bpf calls and normal userspace calls
--- include/linux/bpf_fuse.h | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 include/linux/bpf_fuse.h
include/linux/bpf_fuse.h new file +84 -0
@@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright 2022 Google LLC. +*/ + +#ifndef _BPF_FUSE_H +#define _BPF_FUSE_H + +#include <linux/types.h> +#include <linux/fuse.h> + +struct fuse_buffer { +void *data; +unsigned size; +unsigned alloc_size; +unsigned max_size; +int flags; +}; + +/* These flags are used internally to track information about the fuse buffers. +* Fuse sets some of the flags in init. The helper functions sets others, depending on what +* was requested by the bpf program. +*/ +// Flags set by FUSE +#define BPF_FUSE_IMMUTABLE (1 << 0) // Buffer may not be written to +#define BPF_FUSE_VARIABLE_SIZE (1 << 1) // Buffer length may be changed (growth requires alloc) +#define BPF_FUSE_MUST_ALLOCATE (1 << 2) // Buffer must be re allocated before allowing writes + +// Flags set by helper function +#define BPF_FUSE_MODIFIED (1 << 3) // The helper function allowed writes to the buffer +#define BPF_FUSE_ALLOCATED (1 << 4) // The helper function allocated the buffer + +/* +* BPF Fuse Args +* +* Used to translate between bpf program parameters and their userspace equivalent calls. +* Variable sized arguments are held in fuse_buffers. To access these, bpf programs must +* use kfuncs to access them as dynptrs. +* +*/ + +#define FUSE_MAX_ARGS_IN 3 +#define FUSE_MAX_ARGS_OUT 2 + +struct bpf_fuse_arg { +union { +void *value; +struct fuse_buffer *buffer; + }; +unsigned size; +bool is_buffer; +}; + +struct bpf_fuse_meta_info { +uint64_t nodeid; +uint32_t opcode; +uint32_t error_in; +}; + +struct bpf_fuse_args { +struct bpf_fuse_meta_info info; +uint32_t in_numargs; +uint32_t out_numargs; +uint32_t flags; +struct bpf_fuse_arg in_args[FUSE_MAX_ARGS_IN ]; +struct bpf_fuse_arg out_args[FUSE_MAX_ARGS_OUT ]; +}; + +// Mirrors for struct fuse_args flags +#define FUSE_BPF_FORCE (1 << 0) +#define FUSE_BPF_OUT_ARGVAR (1 << 6) +#define FUSE_BPF_IS_LOOKUP (1 << 11) + +static inline void *bpf_fuse_arg_value (const struct bpf_fuse_arg *arg) +{ +return arg->is_buffer ? arg->buffer : arg->value; +} + +static inline unsigned bpf_fuse_arg_size (const struct bpf_fuse_arg *arg) +{ +return arg->is_buffer ? arg->buffer->size : arg->size; +} + +#endif /* _BPF_FUSE_H */
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 3/36 fuse-bpf: Prepare for fuse-bpf patch
In reply to Daniel RosenbergThis moves some functions and structs around to make the following patch easier to read.
--- fs/fuse/dir.c | 4 ---- fs/fuse/fuse_i.h | 8 ++++++++ fs/fuse/inode.c | 52 ++++++++++++++++++++++++------------------------ 3 files changed, 34 insertions(+), 30 deletions(-)
fs/fuse/dir.c +0 -4
@@ -46,10 +46,6 @@ static inline u64 fuse_dentry_time(const struct dentry *entry) }#else -union fuse_dentry { -u64 time; -struct rcu_head rcu; -};static inline void __fuse_dentry_settime (struct dentry *dentry,u64 time) {
fs/fuse/fuse_i.h +8 -0
@@ -76,6 +76,14 @@ struct fuse_submount_lookup {struct fuse_forget_link *forget; }; +/** FUSE specific dentry data */ +#if BITS_PER_LONG <64 +union fuse_dentry { +u64 time; +struct rcu_head rcu; +}; +#endif +/** FUSE inode */ struct fuse_inode {/** Inode data */
fs/fuse/inode.c +26 -26
64 lines not on this page · raw message
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 4/36 fuse: Add fuse-bpf, a stacked fs extension for FUSE
In reply to Daniel RosenbergFuse-bpf provides a short circuit path for Fuse implementations that act as a stacked filesystem. For cases that are directly unchanged, operations are passed directly to the backing filesystem. Small adjustments can be handled by bpf prefilters or postfilters, with the option to fall back to userspace as needed.
Fuse implementations may supply backing node information, as well as bpf programs via an optional add on to the lookup structure.
This has been split over the next set of patches for readability. Clusters of fuse ops have been split into their own patches, as well as the actual bpf calls and userspace calls for filters.
--- fs/fuse/Kconfig | 8 + fs/fuse/Makefile | 1 + fs/fuse/backing.c | 422 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dev.c | 41 ++++- fs/fuse/dir.c | 184 ++++++++++++++++---- fs/fuse/file.c | 25 ++- fs/fuse/fuse_i.h | 100 ++++++++++- fs/fuse/inode.c | 183 ++++++++++++++++---- fs/fuse/ioctl.c | 2 +- 9 files changed, 887 insertions(+), 79 deletions(-) create mode 100644 fs/fuse/backing.c
fs/fuse/Kconfig +8 -0
@@ -52,3 +52,11 @@ config FUSE_DAX If you want to allow mounting a Virtio Filesystem with the "dax" option, answer Y. + +config FUSE_BPF + bool "Adds BPF to fuse" + depends on FUSE_FS + depends on BPF + help + Extends FUSE by adding BPF to prefilter calls and potentially pass to a + backing file system
fs/fuse/Makefile +1 -0
@@ -9,5 +9,6 @@ obj-$(CONFIG_VIRTIO_FS) += virtiofs.o fuse-y := dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o ioctl.o fuse-$(CONFIG_FUSE_DAX) += dax.o +fuse-$(CONFIG_FUSE_BPF) += backing.o virtiofs-y := virtio_fs.o
fs/fuse/backing.c new file +422 -0
422 lines not on this page · raw message
fs/fuse/dev.c +38 -3
74 lines not on this page · raw message
fs/fuse/dir.c +150 -34
327 lines not on this page · raw message
fs/fuse/file.c +22 -3
@@ -8,6 +8,7 @@#include "fuse_i.h" +#include <linux/filter.h> #include <linux/pagemap.h> #include <linux/slab.h> #include <linux/kernel.h>
@@ -127,13 +128,18 @@ static void fuse_file_put(struct fuse_file *ff, bool sync, bool isdir) }struct fuse_file *fuse_file_open (struct fuse_mount *fm,u64 nodeid, -unsigned int open_flags,bool isdir) +unsigned int open_flags,bool isdir,struct file *file) {struct fuse_conn *fc = fm->fc;struct fuse_file *ff;int opcode = isdir ?FUSE_OPENDIR :FUSE_OPEN ; - ff =fuse_file_alloc (fm); +if (file && file->private_data) { + ff = file->private_data; + file->private_data =NULL ; + }else { + ff =fuse_file_alloc (fm); + }if (!ff)return ERR_PTR (-ENOMEM );
@@ -171,7 +177,7 @@ struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid,int fuse_do_open (struct fuse_mount *fm,u64 nodeid,struct file *file,bool isdir) { -struct fuse_file *ff =fuse_file_open (fm, nodeid, file->f_flags, isdir); +struct fuse_file *ff =fuse_file_open (fm, nodeid, file->f_flags, isdir, file);if (!IS_ERR (ff)) file->private_data = ff;
@@ -1906,6 +1912,19 @@ int fuse_write_inode(struct inode *inode, struct writeback_control *wbc)*/ WARN_ON (wbc->for_reclaim); +/** +* TODO - fully understand why this is necessary +* +* With fuse-bpf, fsstress fails if rename is enabled without this +* +* We are getting writes here on directory inodes, which do not have an +* initialized file list so crash. +* +* The question is why we are getting those writes +*/ +if (!S_ISREG (inode->i_mode)) +return 0 ; + ff =__fuse_write_file_get (fi); err =fuse_flush_times (inode, ff);if (ff)
fs/fuse/fuse_i.h +94 -6
173 lines not on this page · raw message
fs/fuse/inode.c +151 -32
335 lines not on this page · raw message
fs/fuse/ioctl.c +1 -1
@@ -433,7 +433,7 @@ static struct fuse_file *fuse_priv_ioctl_prepare(struct inode *inode)if (!S_ISREG (inode->i_mode) && !isdir)return ERR_PTR (-ENOTTY ); -return fuse_file_open (fm,get_node_id (inode),O_RDONLY , isdir); +return fuse_file_open (fm,get_node_id (inode),O_RDONLY , isdir,NULL ); }static void fuse_priv_ioctl_cleanup (struct inode *inode,struct fuse_file *ff)
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 5/36 fuse-bpf: Add ioctl interface for /dev/fuse
In reply to Daniel RosenbergThis introduces an alternative method of responding to fuse requests. Lookups supplying a backing fd or bpf will need to call through the ioctl to ensure there can be no attempts to fool priveledged processes into inadvertantly performing other actions.
--- fs/fuse/dev.c | 56 ++++++++++++++++++++++++++++++++------- fs/fuse/fuse_i.h | 1 + include/uapi/linux/fuse.h | 1 + 3 files changed, 48 insertions(+), 10 deletions(-)
fs/fuse/dev.c +46 -10
@@ -1016,18 +1016,19 @@ static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size)/* Copy the fuse-bpf lookup args and verify them */ #ifdef CONFIG_FUSE_BPF -static int fuse_copy_lookup (struct fuse_copy_state *cs,void *val,unsigned size) +static int fuse_copy_lookup (struct fuse_copy_state *cs,unsigned via_ioctl,void *val,unsigned size) {struct fuse_bpf_entry_out *fbeo = (struct fuse_bpf_entry_out *)val; struct fuse_bpf_entry *feb = container_of(fbeo, struct fuse_bpf_entry, out[0]);int num_entries = size /sizeof (*fbeo);int err; -if (size && size %sizeof (*fbeo) !=0 ) +if (size && (size %sizeof (*fbeo) !=0 || !via_ioctl))return -EINVAL ;if (num_entries >FUSE_BPF_MAX_ENTRIES )return -EINVAL ; + err =fuse_copy_one (cs, val, size);if (err)return err;
@@ -1036,7 +1037,7 @@ static int fuse_copy_lookup(struct fuse_copy_state *cs, void *val, unsigned size return err; }#else -static int fuse_copy_lookup (struct fuse_copy_state *cs,void *val,unsigned size) +static int fuse_copy_lookup (struct fuse_copy_state *cs,unsigned via_ioctl,void *val,unsigned size) {return fuse_copy_one (cs, val, size); }
@@ -1045,7 +1046,7 @@ static int fuse_copy_lookup(struct fuse_copy_state *cs, void *val, unsigned size/* Copy request arguments to/from userspace buffer */ static int fuse_copy_args (struct fuse_copy_state *cs,unsigned numargs,unsigned argpages,struct fuse_arg *args, -int zeroing,unsigned is_lookup) +int zeroing,unsigned is_lookup,unsigned via_ioct) {int err =0 ;unsigned i;
@@ -1055,7 +1056,7 @@ static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs,if (i == numargs -1 && argpages) err =fuse_copy_pages (cs, arg->size, zeroing);else if (i == numargs -1 && is_lookup) - err =fuse_copy_lookup (cs, arg->value, arg->size); + err =fuse_copy_lookup (cs, via_ioct, arg->value, arg->size);else err =fuse_copy_one (cs, arg->value, arg->size); }
@@ -1333,7 +1334,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, err =fuse_copy_one (cs, &req->in.h,sizeof (req->in.h));if (!err) err =fuse_copy_args (cs, args->in_numargs, args->in_pages, - (struct fuse_arg *) args->in_args,0 ,0 ); + (struct fuse_arg *) args->in_args,0 ,0 ,0 );fuse_copy_finish (cs);spin_lock (&fpq->lock);clear_bit (FR_LOCKED , &req->flags);
@@ -1872,7 +1873,8 @@ static int copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args, lastarg->size -= diffsize; }return fuse_copy_args (cs, args->out_numargs, args->out_pages, - args->out_args, args->page_zeroing, args->is_lookup); + args->out_args, args->page_zeroing, args->is_lookup, + args->via_ioctl); }/*
@@ -1882,7 +1884,7 @@ static int copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args,* it from the list and copy the rest of the buffer to the request. * The request is finished by calling fuse_request_end(). */ -static ssize_t fuse_dev_do_write (struct fuse_dev *fud, +static ssize_t fuse_dev_do_write (struct fuse_dev *fud,bool from_ioctl,struct fuse_copy_state *cs,size_t nbytes) {int err;
@@ -1954,6 +1956,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,if (!req->args->page_replace) cs->move_pages =0 ; + req->args->via_ioctl = from_ioctl;if (oh.error) err = nbytes !=sizeof (oh) ? -EINVAL :0 ;else
@@ -1992,7 +1995,7 @@ static ssize_t fuse_dev_write(struct kiocb *iocb, struct iov_iter *from)fuse_copy_init (&cs,0 , from); -return fuse_dev_do_write (fud, &cs,iov_iter_count (from)); +return fuse_dev_do_write (fud, false, &cs,iov_iter_count (from)); } static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
@@ -2073,7 +2076,7 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,if (flags &SPLICE_F_MOVE ) cs.move_pages =1 ; - ret =fuse_dev_do_write (fud, &cs, len); + ret =fuse_dev_do_write (fud, false, &cs, len);pipe_lock (pipe); out_free:
@@ -2286,6 +2289,33 @@ static int fuse_device_clone(struct fuse_conn *fc, struct file *new)return 0 ; } +// Provides an alternate means to respond to a fuse request +static int fuse_handle_ioc_response (struct fuse_dev *dev,void *buff,uint32_t size) +{ +struct fuse_copy_state cs; +struct iovec *iov =NULL ; +struct iov_iter iter; +int res; + +if (size >PAGE_SIZE ) +return -EINVAL ; + iov = (struct iovec *)__get_free_page (GFP_KERNEL ); +if (!iov) +return -ENOMEM ; + + iov->iov_base = buff; + iov->iov_len = size; + +iov_iter_init (&iter,READ , iov,1 , size); +fuse_copy_init (&cs,0 , &iter); + + + res =fuse_dev_do_write (dev, true, &cs, size); +free_page ((unsigned long ) iov); + +return res; +} +static long fuse_dev_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {
@@ -2319,6 +2349,12 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,fdput (f);break ;default : +if (_IOC_TYPE (cmd) ==FUSE_DEV_IOC_MAGIC + &&_IOC_NR (cmd) ==_IOC_NR (FUSE_DEV_IOC_BPF_RESPONSE (0 )) + &&_IOC_DIR (cmd) == _IOC_WRITE) { + res =fuse_handle_ioc_response (fuse_get_dev (file), (void *) arg,_IOC_SIZE (cmd)); +break ; + } res = -ENOTTY ;break ; }
fs/fuse/fuse_i.h +1 -0
@@ -336,6 +336,7 @@ struct fuse_args { bool may_block:1; bool is_ext:1; bool is_lookup:1; + bool via_ioctl:1;struct fuse_in_arg in_args[3 ];struct fuse_arg out_args[2 ];void (*end)(struct fuse_mount *fm,struct fuse_args *args,int error);
include/uapi/linux/fuse.h +1 -0
@@ -1075,6 +1075,7 @@ struct fuse_notify_retrieve_in {/* Device ioctls: */ #define FUSE_DEV_IOC_MAGIC 229#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t) +#define FUSE_DEV_IOC_BPF_RESPONSE (N ) _IOW(FUSE_DEV_IOC_MAGIC, 125, char[N])struct fuse_lseek_in {uint64_t fh;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 6/36 fuse-bpf: Don't support export_operations
In reply to Daniel RosenbergIn the future, we may choose to support these, but it poses some challenges. In order to create a disconnected dentry/inode, we'll need to encode the mountpoint and bpf into the file_handle, which means we'd need a stable representation of them. This also won't hold up to cases where the bpf is not stateless. One possibility is registering bpf programs and mounts in a specific order, so they can be assigned consistent ids we can use in the file_handle. We can defer to the lower filesystem for the lower inode's representation in the file_handle.
--- fs/fuse/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/fuse/inode.c +8 -0
@@ -1187,6 +1187,14 @@ static int fuse_encode_fh(struct inode *inode, u32 *fh, int *max_len, nodeid =get_fuse_inode (inode)->nodeid; generation = inode->i_generation; +#ifdef CONFIG_FUSE_BPF +/* TODO: Does it make sense to support this in some cases? */ +if (!nodeid &&get_fuse_inode (inode)->backing_inode) { + *max_len =0 ; +return FILEID_INVALID ; + } +#endif + fh[0 ] = (u32)(nodeid >>32 ); fh[1 ] = (u32)(nodeid &0xffffffff ); fh[2 ] = generation;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 7/36 fuse-bpf: Add support for access
In reply to Daniel RosenbergThis adds backing support for FUSE_ACCESS
--- fs/fuse/backing.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 6 ++++++ fs/fuse/fuse_i.h | 6 ++++++ 3 files changed, 59 insertions(+)
fs/fuse/backing.c +47 -0
@@ -420,3 +420,50 @@ int fuse_revalidate_backing(struct dentry *entry, unsigned int flags)return backing_entry->d_op->d_revalidate (backing_entry, flags);return 1 ; } + +static int fuse_access_initialize_in (struct bpf_fuse_args *fa,struct fuse_access_in *in, +struct inode *inode,int mask) +{ + *in = (struct fuse_access_in ) { + .mask = mask, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .opcode =FUSE_ACCESS , + .nodeid =get_node_id (inode), + }, + .in_numargs =1 , + .in_args[0 ].size =sizeof (*in), + .in_args[0 ].value = in, + }; + +return 0 ; +} + +static int fuse_access_initialize_out (struct bpf_fuse_args *fa,struct fuse_access_in *in, +struct inode *inode,int mask) +{ +return 0 ; +} + +static int fuse_access_backing (struct bpf_fuse_args *fa,int *out,struct inode *inode,int mask) +{ +struct fuse_inode *fi =get_fuse_inode (inode); +const struct fuse_access_in *fai = fa->in_args[0 ].value; + + *out =inode_permission (&nop_mnt_idmap, fi->backing_inode, fai->mask); +return 0 ; +} + +static int fuse_access_finalize (struct bpf_fuse_args *fa,int *out,struct inode *inode,int mask) +{ +return 0 ; +} + +int fuse_bpf_access (int *out,struct inode *inode,int mask) +{ + return bpf_fuse_backing(inode, struct fuse_access_in, out, + fuse_access_initialize_in, fuse_access_initialize_out, + fuse_access_backing, fuse_access_finalize, inode, mask); +}
fs/fuse/dir.c +6 -0
@@ -1563,6 +1563,9 @@ static int fuse_access(struct inode *inode, int mask)struct fuse_access_in inarg;int err; +if (fuse_bpf_access (&err, inode, mask)) +return err; +BUG_ON (mask &MAY_NOT_BLOCK );if (fm->fc->no_access)
@@ -1619,6 +1622,9 @@ static int fuse_permission(struct mnt_idmap *idmap,if (!fuse_allow_current_process (fc))return -EACCES ; +if (fuse_bpf_access (&err, inode, mask)) +return err; +/* * If attributes are needed, refresh them before proceeding */
fs/fuse/fuse_i.h +6 -0
@@ -1439,6 +1439,7 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num_entries);#ifdef CONFIG_FUSE_BPF int fuse_bpf_lookup (struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags); +int fuse_bpf_access (int *out,struct inode *inode,int mask);#else
@@ -1447,6 +1448,11 @@ static inline int fuse_bpf_lookup(struct dentry **out, struct inode *dir, struct return 0; } +static inline int fuse_bpf_access (int *out,struct inode *inode,int mask) +{ +return 0 ; +} +#endif // CONFIG_FUSE_BPF int fuse_handle_backing (struct fuse_bpf_entry *feb,struct path *backing_path);
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 8/36 fuse-bpf: Partially add mapping support
In reply to Daniel RosenbergThis adds a backing implementation for mapping, but is not currently hooked into the infrastructure that will call the bpf programs.
--- fs/fuse/backing.c | 41 +++++++++++++++++++++++++++++++++++++++++ fs/fuse/file.c | 6 ++++++ fs/fuse/fuse_i.h | 4 +++- 3 files changed, 50 insertions(+), 1 deletion(-)
fs/fuse/backing.c +41 -0
@@ -210,6 +210,47 @@ static void fuse_stat_to_attr(struct fuse_conn *fc, struct inode *inode, attr->blksize =1 << blkbits; } +ssize_t fuse_backing_mmap (struct file *file,struct vm_area_struct *vma) +{ +int ret; +struct fuse_file *ff = file->private_data; +struct inode *fuse_inode =file_inode (file); +struct file *backing_file = ff->backing_file; +struct inode *backing_inode =file_inode (backing_file); +struct timespec64 mtime, bmtime, ctime, bctime; + +if (!backing_file->f_op->mmap) +return -ENODEV ; + +if (WARN_ON (file != vma->vm_file)) +return -EIO ; + + vma->vm_file =get_file (backing_file); + + ret =call_mmap (vma->vm_file, vma); + +if (ret) +fput (backing_file); +else +fput (file); + +if (file->f_flags &O_NOATIME ) +return ret; + + mtime =inode_get_mtime (fuse_inode); + bmtime =inode_get_mtime (backing_inode); + ctime =inode_get_ctime (fuse_inode); + bctime =inode_get_ctime (backing_inode); +if ((!timespec64_equal (&mtime, &bmtime) || + !timespec64_equal (&ctime, &bctime))) { +inode_set_mtime_to_ts (fuse_inode, bmtime); +inode_set_ctime_to_ts (fuse_inode, bctime); + } +touch_atime (&file->f_path); + +return ret; +} +/******************************************************************************* * Directory operations after here * ******************************************************************************/
fs/fuse/file.c +6 -0
@@ -2486,6 +2486,12 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)if (FUSE_IS_DAX (file_inode (file)))return fuse_dax_mmap (file, vma); +#ifdef CONFIG_FUSE_BPF +/* TODO - this is simply passthrough, not a proper BPF filter */ +if (ff->backing_file) +return fuse_backing_mmap (file, vma); +#endif +if (ff->open_flags &FOPEN_DIRECT_IO ) {/* Can't provide the coherency needed for MAP_SHARED * if FUSE_DIRECT_IO_ALLOW_MMAP isn't set.
fs/fuse/fuse_i.h +3 -1
@@ -1455,7 +1455,9 @@ static inline int fuse_bpf_access(int *out, struct inode *inode, int mask)#endif // CONFIG_FUSE_BPF -int fuse_handle_backing (struct fuse_bpf_entry *feb,struct path *backing_path); +ssize_t fuse_backing_mmap (struct file *file,struct vm_area_struct *vma); + +int fuse_handle_backing (struct fuse_bpf_entry *fbe,struct path *backing_path);int fuse_revalidate_backing (struct dentry *entry,unsigned int flags);
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 9/36 fuse-bpf: Add lseek support
In reply to Daniel RosenbergThis adds backing support for FUSE_LSEEK
--- fs/fuse/backing.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/file.c | 3 ++ fs/fuse/fuse_i.h | 6 ++++ 3 files changed, 98 insertions(+)
fs/fuse/backing.c +89 -0
@@ -210,6 +210,95 @@ static void fuse_stat_to_attr(struct fuse_conn *fc, struct inode *inode, attr->blksize =1 << blkbits; } +struct fuse_lseek_args { +struct fuse_lseek_in in; +struct fuse_lseek_out out; +}; + +static int fuse_lseek_initialize_in (struct bpf_fuse_args *fa,struct fuse_lseek_args *args, +struct file *file,loff_t offset,int whence) +{ +struct fuse_file *fuse_file = file->private_data; + + args->in = (struct fuse_lseek_in ) { + .fh = fuse_file->fh, + .offset = offset, + .whence = whence, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (file->f_inode), + .opcode =FUSE_LSEEK , + }, + .in_numargs =1 , + .in_args[0 ].size =sizeof (args->in), + .in_args[0 ].value = &args->in, + }; + +return 0 ; +} + +static int fuse_lseek_initialize_out (struct bpf_fuse_args *fa,struct fuse_lseek_args *args, +struct file *file,loff_t offset,int whence) +{ + fa->out_numargs =1 ; + fa->out_args[0 ].size =sizeof (args->out); + fa->out_args[0 ].value = &args->out; + +return 0 ; +} + +static int fuse_lseek_backing (struct bpf_fuse_args *fa,loff_t *out, +struct file *file,loff_t offset,int whence) +{ +const struct fuse_lseek_in *fli = fa->in_args[0 ].value; +struct fuse_lseek_out *flo = fa->out_args[0 ].value; +struct fuse_file *fuse_file = file->private_data; +struct file *backing_file = fuse_file->backing_file; + +/* TODO: Handle changing of the file handle */ +if (offset ==0 ) { +if (whence ==SEEK_CUR ) { + flo->offset = file->f_pos; + *out = flo->offset; +return 0 ; + } + +if (whence ==SEEK_SET ) { + flo->offset =vfs_setpos (file,0 ,0 ); + *out = flo->offset; +return 0 ; + } + } + +inode_lock (file->f_inode); + backing_file->f_pos = file->f_pos; + *out =vfs_llseek (backing_file, fli->offset, fli->whence); + flo->offset = *out; +inode_unlock (file->f_inode); +return 0 ; +} + +static int fuse_lseek_finalize (struct bpf_fuse_args *fa,loff_t *out, +struct file *file,loff_t offset,int whence) +{ +struct fuse_lseek_out *flo = fa->out_args[0 ].value; + +if (!fa->info.error_in) + file->f_pos = flo->offset; + *out = flo->offset; +return 0 ; +} + +int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence) +{ + return bpf_fuse_backing(inode, struct fuse_lseek_args, out, + fuse_lseek_initialize_in, fuse_lseek_initialize_out, + fuse_lseek_backing, fuse_lseek_finalize, + file, offset, whence); +} +ssize_t fuse_backing_mmap (struct file *file,struct vm_area_struct *vma) {int ret;
fs/fuse/file.c +3 -0
@@ -2740,6 +2740,9 @@ static loff_t fuse_file_llseek(struct file *file, loff_t offset, int whence)loff_t retval;struct inode *inode =file_inode (file); +if (fuse_bpf_lseek (&retval, inode, file, offset, whence)) +return retval; +switch (whence) {case SEEK_SET :case SEEK_CUR :
fs/fuse/fuse_i.h +6 -0
@@ -1438,11 +1438,17 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num_entries);#ifdef CONFIG_FUSE_BPF +int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence);int fuse_bpf_lookup (struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags);int fuse_bpf_access (int *out,struct inode *inode,int mask);#else +static inline int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence) +{ +return 0 ; +} +static inline int fuse_bpf_lookup (struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags) {return 0 ;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 10/36 fuse-bpf: Add support for fallocate
In reply to Daniel RosenbergThis adds backing support for FUSE_FALLOCATE
--- fs/fuse/backing.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/file.c | 3 +++ fs/fuse/fuse_i.h | 6 +++++ 3 files changed, 69 insertions(+)
fs/fuse/backing.c +60 -0
@@ -340,6 +340,66 @@ ssize_t fuse_backing_mmap(struct file *file, struct vm_area_struct *vma)return ret; } +static int fuse_file_fallocate_initialize_in (struct bpf_fuse_args *fa, +struct fuse_fallocate_in *in, +struct file *file,int mode,loff_t offset,loff_t length) +{ +struct fuse_file *ff = file->private_data; + + *in = (struct fuse_fallocate_in ) { + .fh = ff->fh, + .offset = offset, + .length = length, + .mode = mode, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .opcode =FUSE_FALLOCATE , + .nodeid = ff->nodeid, + }, + .in_numargs =1 , + .in_args[0 ].size =sizeof (*in), + .in_args[0 ].value = in, + }; + +return 0 ; +} + +static int fuse_file_fallocate_initialize_out (struct bpf_fuse_args *fa, +struct fuse_fallocate_in *in, +struct file *file,int mode,loff_t offset,loff_t length) +{ +return 0 ; +} + +static int fuse_file_fallocate_backing (struct bpf_fuse_args *fa,int *out, +struct file *file,int mode,loff_t offset,loff_t length) +{ +const struct fuse_fallocate_in *ffi = fa->in_args[0 ].value; +struct fuse_file *ff = file->private_data; + + *out =vfs_fallocate (ff->backing_file, ffi->mode, ffi->offset, + ffi->length); +return 0 ; +} + +static int fuse_file_fallocate_finalize (struct bpf_fuse_args *fa,int *out, +struct file *file,int mode,loff_t offset,loff_t length) +{ +return 0 ; +} + +int fuse_bpf_file_fallocate (int *out,struct inode *inode,struct file *file,int mode,loff_t offset,loff_t length) +{ + return bpf_fuse_backing(inode, struct fuse_fallocate_in, out, + fuse_file_fallocate_initialize_in, + fuse_file_fallocate_initialize_out, + fuse_file_fallocate_backing, + fuse_file_fallocate_finalize, + file, mode, offset, length); +} +/******************************************************************************* * Directory operations after here * ******************************************************************************/
fs/fuse/file.c +3 -0
@@ -3032,6 +3032,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset, (!(mode &FALLOC_FL_KEEP_SIZE ) || (mode & (FALLOC_FL_PUNCH_HOLE |FALLOC_FL_ZERO_RANGE ))); +if (fuse_bpf_file_fallocate (&err, inode, file, mode, offset, length)) +return err; +if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE |FALLOC_FL_ZERO_RANGE ))return -EOPNOTSUPP ;
fs/fuse/fuse_i.h +6 -0
@@ -1439,6 +1439,7 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num_entries);#ifdef CONFIG_FUSE_BPF int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence); +int fuse_bpf_file_fallocate (int *out,struct inode *inode,struct file *file,int mode,loff_t offset,loff_t length);int fuse_bpf_lookup (struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags);int fuse_bpf_access (int *out,struct inode *inode,int mask);
@@ -1449,6 +1450,11 @@ static inline int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *return 0 ; } +static inline int fuse_bpf_file_fallocate (int *out,struct inode *inode,struct file *file,int mode,loff_t offset,loff_t length) +{ +return 0 ; +} +static inline int fuse_bpf_lookup (struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags) {return 0 ;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 11/36 fuse-bpf: Support file/dir open/close
In reply to Daniel RosenbergThis adds backing support for FUSE_OPEN, FUSE_OPENDIR, FUSE_CREATE, FUSE_RELEASE, and FUSE_RELEASEDIR
--- fs/fuse/backing.c | 336 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 3 + fs/fuse/file.c | 62 +++++---- fs/fuse/fuse_i.h | 26 ++++ 4 files changed, 404 insertions(+), 23 deletions(-)
fs/fuse/backing.c +336 -0
@@ -210,6 +210,342 @@ static void fuse_stat_to_attr(struct fuse_conn *fc, struct inode *inode, attr->blksize =1 << blkbits; } +struct fuse_open_args { +struct fuse_open_in in; +struct fuse_open_out out; +}; + +static int fuse_open_initialize_in (struct bpf_fuse_args *fa,struct fuse_open_args *args, +struct inode *inode,struct file *file,bool isdir) +{ + args->in = (struct fuse_open_in ) { + .flags = file->f_flags & ~(O_CREAT |O_EXCL |O_NOCTTY ), + }; + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_fuse_inode (inode)->nodeid, + .opcode = isdir ?FUSE_OPENDIR :FUSE_OPEN , + }, + .in_numargs =1 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + }; + +return 0 ; +} + +static int fuse_open_initialize_out (struct bpf_fuse_args *fa,struct fuse_open_args *args, +struct inode *inode,struct file *file,bool isdir) +{ + args->out = (struct fuse_open_out ) {0 }; + + fa->out_numargs =1 ; + fa->out_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->out), + .value = &args->out, + }; + +return 0 ; +} + +static int fuse_open_backing (struct bpf_fuse_args *fa,int *out, +struct inode *inode,struct file *file,bool isdir) +{ +struct fuse_mount *fm =get_fuse_mount (inode); +const struct fuse_open_in *foi = fa->in_args[0 ].value; +struct fuse_file *ff; +int mask; +struct fuse_dentry *fd =get_fuse_dentry (file->f_path.dentry); +struct file *backing_file; + + ff =fuse_file_alloc (fm); +if (!ff) +return -ENOMEM ; + file->private_data = ff; + +switch (foi->flags &O_ACCMODE ) { +case O_RDONLY : + mask =MAY_READ ; +break ; + +case O_WRONLY : + mask =MAY_WRITE ; +break ; + +case O_RDWR : + mask =MAY_READ |MAY_WRITE ; +break ; + +default : +return -EINVAL ; + } + + *out =inode_permission (&nop_mnt_idmap, +get_fuse_inode (inode)->backing_inode, mask); +if (*out) +return *out; + + backing_file = +dentry_open (&fd->backing_path, foi->flags,current_cred ()); + +if (IS_ERR (backing_file)) { +fuse_file_free (ff); + file->private_data =NULL ; +return PTR_ERR (backing_file); + } + ff->backing_file = backing_file; + + *out =0 ; +return 0 ; +} + +static int fuse_open_finalize (struct bpf_fuse_args *fa,int *out, +struct inode *inode,struct file *file,bool isdir) +{ +struct fuse_file *ff = file->private_data; +struct fuse_open_out *foo = fa->out_args[0 ].value; + +if (ff) { + ff->fh = foo->fh; + ff->nodeid =get_fuse_inode (inode)->nodeid; + } +return 0 ; +} + +int fuse_bpf_open (int *out,struct inode *inode,struct file *file,bool isdir) +{ + return bpf_fuse_backing(inode, struct fuse_open_args, out, + fuse_open_initialize_in, fuse_open_initialize_out, + fuse_open_backing, fuse_open_finalize, + inode, file, isdir); +} + +struct fuse_create_open_args { +struct fuse_create_in in; +struct fuse_buffer name; +struct fuse_entry_out entry_out; +struct fuse_open_out open_out; +}; + +static int fuse_create_open_initialize_in (struct bpf_fuse_args *fa,struct fuse_create_open_args *args, +struct inode *dir,struct dentry *entry, +struct file *file,unsigned int flags,umode_t mode) +{ + args->in = (struct fuse_create_in ) { + .flags = file->f_flags & ~(O_CREAT |O_EXCL |O_NOCTTY ), + .mode = mode, + }; + + args->name = (struct fuse_buffer ) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (dir), + .opcode =FUSE_CREATE , + }, + .in_numargs =2 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + .in_args[1 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->name, + }, + }; + +return 0 ; +} + +static int fuse_create_open_initialize_out (struct bpf_fuse_args *fa,struct fuse_create_open_args *args, +struct inode *dir,struct dentry *entry, +struct file *file,unsigned int flags,umode_t mode) +{ + args->entry_out = (struct fuse_entry_out ) {0 }; + args->open_out = (struct fuse_open_out ) {0 }; + + fa->out_numargs =2 ; + fa->out_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->entry_out), + .value = &args->entry_out, + }; + fa->out_args[1 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->open_out), + .value = &args->open_out, + }; + +return 0 ; +} + +static int fuse_open_file_backing (struct inode *inode,struct file *file) +{ +struct fuse_mount *fm =get_fuse_mount (inode); +struct dentry *entry = file->f_path.dentry; +struct fuse_dentry *fuse_dentry =get_fuse_dentry (entry); +struct fuse_file *fuse_file; +struct file *backing_file; + + fuse_file =fuse_file_alloc (fm); +if (!fuse_file) +return -ENOMEM ; + file->private_data = fuse_file; + + backing_file =dentry_open (&fuse_dentry->backing_path, file->f_flags, +current_cred ()); +if (IS_ERR (backing_file)) { +fuse_file_free (fuse_file); + file->private_data =NULL ; +return PTR_ERR (backing_file); + } + fuse_file->backing_file = backing_file; + +return 0 ; +} + +static int fuse_create_open_backing (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry, +struct file *file,unsigned int flags,umode_t mode) +{ +struct fuse_inode *dir_fuse_inode =get_fuse_inode (dir); +struct path backing_path; +struct inode *inode =NULL ; +struct dentry *backing_parent; +struct dentry *newent; +const struct fuse_create_in *fci = fa->in_args[0 ].value; + +get_fuse_backing_path (entry, &backing_path); +if (!backing_path.dentry) +return -EBADF ; + +if (IS_ERR (backing_path.dentry)) +return PTR_ERR (backing_path.dentry); + +if (d_really_is_positive (backing_path.dentry)) { + *out = -EIO ; + goto out; + } + + backing_parent =dget_parent (backing_path.dentry); +inode_lock_nested (dir_fuse_inode->backing_inode,I_MUTEX_PARENT ); + *out =vfs_create (&nop_mnt_idmap,d_inode (backing_parent), + backing_path.dentry, fci->mode, true); +inode_unlock (d_inode (backing_parent)); +dput (backing_parent); +if (*out) + goto out; + + inode =fuse_iget_backing (dir->i_sb,0 , backing_path.dentry->d_inode); +if (!inode) { + *out = -EIO ; + goto out; + } + + newent =d_splice_alias (inode, entry); +if (IS_ERR (newent)) { + *out =PTR_ERR (newent); + goto out; + } + + inode =NULL ; + entry = newent ? newent : entry; + *out =finish_open (file, entry, fuse_open_file_backing); + +out: +iput (inode); +path_put (&backing_path); +return *out; +} + +static int fuse_create_open_finalize (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry, +struct file *file,unsigned int flags,umode_t mode) +{ +struct fuse_file *ff = file->private_data; +struct fuse_inode *fi =get_fuse_inode (file->f_inode); +struct fuse_entry_out *feo = fa->out_args[0 ].value; +struct fuse_open_out *foo = fa->out_args[1 ].value; + +if (fi) + fi->nodeid = feo->nodeid; +if (ff) + ff->fh = foo->fh; +return 0 ; +} + +int fuse_bpf_create_open (int *out,struct inode *dir,struct dentry *entry, +struct file *file,unsigned int flags,umode_t mode) +{ + return bpf_fuse_backing(dir, struct fuse_create_open_args, out, + fuse_create_open_initialize_in, + fuse_create_open_initialize_out, + fuse_create_open_backing, + fuse_create_open_finalize, + dir, entry, file, flags, mode); +} + +static int fuse_release_initialize_in (struct bpf_fuse_args *fa,struct fuse_release_in *fri, +struct inode *inode,struct fuse_file *ff) +{ +/* Always put backing file whatever bpf/userspace says */ +fput (ff->backing_file); + + *fri = (struct fuse_release_in ) { + .fh = ff->fh, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_fuse_inode (inode)->nodeid, + .opcode =S_ISDIR (inode->i_mode) ?FUSE_RELEASEDIR + :FUSE_RELEASE , + }, .in_numargs =1 , + .in_args[0 ].size =sizeof (*fri), + .in_args[0 ].value = fri, + }; + +return 0 ; +} + +static int fuse_release_initialize_out (struct bpf_fuse_args *fa,struct fuse_release_in *fri, +struct inode *inode,struct fuse_file *ff) +{ +return 0 ; +} + +static int fuse_release_backing (struct bpf_fuse_args *fa,int *out, +struct inode *inode,struct fuse_file *ff) +{ +return 0 ; +} + +static int fuse_release_finalize (struct bpf_fuse_args *fa,int *out, +struct inode *inode,struct fuse_file *ff) +{ + *out =0 ; +return 0 ; +} + +int fuse_bpf_release (int *out,struct inode *inode,struct fuse_file *ff) +{ + return bpf_fuse_backing(inode, struct fuse_release_in, out, + fuse_release_initialize_in, fuse_release_initialize_out, + fuse_release_backing, fuse_release_finalize, + inode, ff); +} + +int fuse_bpf_releasedir (int *out,struct inode *inode,struct fuse_file *ff) +{ + return bpf_fuse_backing(inode, struct fuse_release_in, out, + fuse_release_initialize_in, fuse_release_initialize_out, + fuse_release_backing, fuse_release_finalize, inode, ff); +} +struct fuse_lseek_args {struct fuse_lseek_in in;struct fuse_lseek_out out;
fs/fuse/dir.c +3 -0
@@ -736,6 +736,9 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,/* Userspace expects S_IFREG in create mode */ BUG_ON ((mode &S_IFMT ) !=S_IFREG ); +if (fuse_bpf_create_open (&err, dir, entry, file, flags, mode)) +return err; + forget =fuse_alloc_forget (); err = -ENOMEM ;if (!forget)
fs/fuse/file.c +39 -23
113 lines not on this page · raw message
fs/fuse/fuse_i.h +26 -0
@@ -1438,6 +1438,11 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num_entries);#ifdef CONFIG_FUSE_BPF +int fuse_bpf_open (int *err,struct inode *inode,struct file *file,bool isdir); +int fuse_bpf_create_open (int *out,struct inode *dir,struct dentry *entry, +struct file *file,unsigned int flags,umode_t mode); +int fuse_bpf_release (int *out,struct inode *inode,struct fuse_file *ff); +int fuse_bpf_releasedir (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence);int fuse_bpf_file_fallocate (int *out,struct inode *inode,struct file *file,int mode,loff_t offset,loff_t length);int fuse_bpf_lookup (struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags);
@@ -1445,6 +1450,27 @@ int fuse_bpf_access(int *out, struct inode *inode, int mask);#else +static inline int fuse_bpf_open (int *err,struct inode *inode,struct file *file,bool isdir) +{ +return 0 ; +} + +static inline int fuse_bpf_create_open (int *out,struct inode *dir,struct dentry *entry, +struct file *file,unsigned int flags,umode_t mode) +{ +return 0 ; +} + +static inline int fuse_bpf_release (int *out,struct inode *inode,struct file *file) +{ +return 0 ; +} + +static inline int fuse_bpf_releasedir (int *out,struct inode *inode,struct file *file) +{ +return 0 ; +} +static inline int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence) {return 0 ;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 12/36 fuse-bpf: Support mknod/unlink/mkdir/rmdir
In reply to Daniel RosenbergThis adds backing support for FUSE_MKNOD, FUSE_MKDIR, FUSE_RMDIR, and FUSE_UNLINK
--- fs/fuse/backing.c | 342 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 14 ++ fs/fuse/fuse_i.h | 24 ++++ 3 files changed, 380 insertions(+)
fs/fuse/backing.c +342 -0
@@ -947,6 +947,348 @@ int fuse_revalidate_backing(struct dentry *entry, unsigned int flags)return 1 ; } +struct fuse_mknod_args { +struct fuse_mknod_in in; +struct fuse_buffer name; +}; + +static int fuse_mknod_initialize_in (struct bpf_fuse_args *fa,struct fuse_mknod_args *args, +struct inode *dir,struct dentry *entry,umode_t mode,dev_t rdev) +{ + *args = (struct fuse_mknod_args ) { + .in = (struct fuse_mknod_in ) { + .mode = mode, + .rdev =new_encode_dev (rdev), + .umask =current_umask (), + }, + .name = (struct fuse_buffer ) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }, + }; + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (dir), + .opcode =FUSE_MKNOD , + }, + .in_numargs =2 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + .in_args[1 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->name, + }, + }; + +return 0 ; +} + +static int fuse_mknod_initialize_out (struct bpf_fuse_args *fa,struct fuse_mknod_args *args, +struct inode *dir,struct dentry *entry,umode_t mode,dev_t rdev) +{ +return 0 ; +} + +static int fuse_mknod_backing (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry,umode_t mode,dev_t rdev) +{ +const struct fuse_mknod_in *fmi = fa->in_args[0 ].value; +struct fuse_inode *fuse_inode =get_fuse_inode (dir); +struct inode *backing_inode = fuse_inode->backing_inode; +struct path backing_path; +struct inode *inode =NULL ; + +get_fuse_backing_path (entry, &backing_path); +if (!backing_path.dentry) +return -EBADF ; + +inode_lock_nested (backing_inode,I_MUTEX_PARENT ); + mode = fmi->mode; +if (!IS_POSIXACL (backing_inode)) + mode &= ~fmi->umask; + *out =vfs_mknod (&nop_mnt_idmap, backing_inode, backing_path.dentry, mode, +new_decode_dev (fmi->rdev)); +inode_unlock (backing_inode); +if (*out) + goto out; +if (d_really_is_negative (backing_path.dentry) || +unlikely (d_unhashed (backing_path.dentry))) { + *out = -EINVAL ; +/** +* TODO: overlayfs responds to this situation with a +* lookupOneLen. Should we do that too? +*/ + goto out; + } + inode =fuse_iget_backing (dir->i_sb, fuse_inode->nodeid, backing_inode); +if (IS_ERR (inode)) { + *out =PTR_ERR (inode); + goto out; + } +d_instantiate (entry, inode); +out: +path_put (&backing_path); +return *out; +} + +static int fuse_mknod_finalize (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry,umode_t mode,dev_t rdev) +{ +return 0 ; +} + +int fuse_bpf_mknod (int *out,struct inode *dir,struct dentry *entry,umode_t mode,dev_t rdev) +{ + return bpf_fuse_backing(dir, struct fuse_mknod_args, out, + fuse_mknod_initialize_in, fuse_mknod_initialize_out, + fuse_mknod_backing, fuse_mknod_finalize, + dir, entry, mode, rdev); +} + +struct fuse_mkdir_args { +struct fuse_mkdir_in in; +struct fuse_buffer name; +}; + +static int fuse_mkdir_initialize_in (struct bpf_fuse_args *fa,struct fuse_mkdir_args *args, +struct inode *dir,struct dentry *entry,umode_t mode) +{ + *args = (struct fuse_mkdir_args ) { + .in = (struct fuse_mkdir_in ) { + .mode = mode, + .umask =current_umask (), + }, + .name = (struct fuse_buffer ) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (dir), + .opcode =FUSE_MKDIR , + }, + .in_numargs =2 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + .in_args[1 ] = (struct bpf_fuse_arg ) { + .value = &args->name, + .is_buffer = true, + }, + }; + +return 0 ; +} + +static int fuse_mkdir_initialize_out (struct bpf_fuse_args *fa,struct fuse_mkdir_args *args, +struct inode *dir,struct dentry *entry,umode_t mode) +{ +return 0 ; +} + +static int fuse_mkdir_backing (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry,umode_t mode) +{ +const struct fuse_mkdir_in *fmi = fa->in_args[0 ].value; +struct fuse_inode *fuse_inode =get_fuse_inode (dir); +struct inode *backing_inode = fuse_inode->backing_inode; +struct path backing_path; +struct inode *inode =NULL ; +struct dentry *d; + +get_fuse_backing_path (entry, &backing_path); +if (!backing_path.dentry) +return -EBADF ; + +inode_lock_nested (backing_inode,I_MUTEX_PARENT ); + mode = fmi->mode; +if (!IS_POSIXACL (backing_inode)) + mode &= ~fmi->umask; + *out =vfs_mkdir (&nop_mnt_idmap, backing_inode, backing_path.dentry, + mode); +if (*out) + goto out; +if (d_really_is_negative (backing_path.dentry) || +unlikely (d_unhashed (backing_path.dentry))) { + d =lookup_one_len (entry->d_name.name, + backing_path.dentry->d_parent, + entry->d_name.len); +if (IS_ERR (d)) { + *out =PTR_ERR (d); + goto out; + } +dput (backing_path.dentry); + backing_path.dentry = d; + } + inode =fuse_iget_backing (dir->i_sb, fuse_inode->nodeid, backing_inode); +if (IS_ERR (inode)) { + *out =PTR_ERR (inode); + goto out; + } +d_instantiate (entry, inode); +out: +inode_unlock (backing_inode); +path_put (&backing_path); +return *out; +} + +static int fuse_mkdir_finalize (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry,umode_t mode) +{ +return 0 ; +} + +int fuse_bpf_mkdir (int *out,struct inode *dir,struct dentry *entry,umode_t mode) +{ + return bpf_fuse_backing(dir, struct fuse_mkdir_args, out, + fuse_mkdir_initialize_in, fuse_mkdir_initialize_out, + fuse_mkdir_backing, fuse_mkdir_finalize, + dir, entry, mode); +} + +static int fuse_rmdir_initialize_in (struct bpf_fuse_args *fa,struct fuse_buffer *name, +struct inode *dir,struct dentry *entry) +{ + *name = (struct fuse_buffer ) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }; + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (dir), + .opcode =FUSE_RMDIR , + }, + .in_numargs =1 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = name, + }, + }; + +return 0 ; +} + +static int fuse_rmdir_initialize_out (struct bpf_fuse_args *fa,struct fuse_buffer *name, +struct inode *dir,struct dentry *entry) +{ +return 0 ; +} + +static int fuse_rmdir_backing (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry) +{ +struct path backing_path; +struct dentry *backing_parent_dentry; +struct inode *backing_inode; + +get_fuse_backing_path (entry, &backing_path); +if (!backing_path.dentry) +return -EBADF ; + + backing_parent_dentry =dget_parent (backing_path.dentry); + backing_inode =d_inode (backing_parent_dentry); + +inode_lock_nested (backing_inode,I_MUTEX_PARENT ); + *out =vfs_rmdir (&nop_mnt_idmap, backing_inode, backing_path.dentry); +inode_unlock (backing_inode); + +dput (backing_parent_dentry); +if (!*out) +d_drop (entry); +path_put (&backing_path); +return *out; +} + +static int fuse_rmdir_finalize (struct bpf_fuse_args *fa,int *out,struct inode *dir,struct dentry *entry) +{ +return 0 ; +} + +int fuse_bpf_rmdir (int *out,struct inode *dir,struct dentry *entry) +{ + return bpf_fuse_backing(dir, struct fuse_buffer, out, + fuse_rmdir_initialize_in, fuse_rmdir_initialize_out, + fuse_rmdir_backing, fuse_rmdir_finalize, + dir, entry); +} + +static int fuse_unlink_initialize_in (struct bpf_fuse_args *fa,struct fuse_buffer *name, +struct inode *dir,struct dentry *entry) +{ + *name = (struct fuse_buffer ) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }; + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (dir), + .opcode =FUSE_UNLINK , + }, + .in_numargs =1 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = name, + }, + }; + +return 0 ; +} + +static int fuse_unlink_initialize_out (struct bpf_fuse_args *fa,struct fuse_buffer *name, +struct inode *dir,struct dentry *entry) +{ +return 0 ; +} + +static int fuse_unlink_backing (struct bpf_fuse_args *fa,int *out,struct inode *dir,struct dentry *entry) +{ +struct path backing_path; +struct dentry *backing_parent_dentry; +struct inode *backing_inode; + +get_fuse_backing_path (entry, &backing_path); +if (!backing_path.dentry) +return -EBADF ; + +/* TODO Not sure if we should reverify like overlayfs, or get inode from d_parent */ + backing_parent_dentry =dget_parent (backing_path.dentry); + backing_inode =d_inode (backing_parent_dentry); + +inode_lock_nested (backing_inode,I_MUTEX_PARENT ); + *out =vfs_unlink (&nop_mnt_idmap, backing_inode, backing_path.dentry, +NULL ); +inode_unlock (backing_inode); + +dput (backing_parent_dentry); +if (!*out) +d_drop (entry); +path_put (&backing_path); +return *out; +} + +static int fuse_unlink_finalize (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry) +{ +return 0 ; +} + +int fuse_bpf_unlink (int *out,struct inode *dir,struct dentry *entry) +{ + return bpf_fuse_backing(dir, struct fuse_buffer, out, + fuse_unlink_initialize_in, fuse_unlink_initialize_out, + fuse_unlink_backing, fuse_unlink_finalize, + dir, entry); +} +static int fuse_access_initialize_in (struct bpf_fuse_args *fa,struct fuse_access_in *in,struct inode *inode,int mask) {
fs/fuse/dir.c +14 -0
@@ -957,6 +957,10 @@ static int fuse_mknod(struct mnt_idmap *idmap, struct inode *dir,struct fuse_mknod_in inarg;struct fuse_mount *fm =get_fuse_mount (dir);FUSE_ARGS (args); +int err; + +if (fuse_bpf_mknod (&err, dir, entry, mode, rdev)) +return err;if (!fm->fc->dont_mask) mode &= ~current_umask ();
@@ -1003,6 +1007,10 @@ static int fuse_mkdir(struct mnt_idmap *idmap, struct inode *dir,struct fuse_mkdir_in inarg;struct fuse_mount *fm =get_fuse_mount (dir);FUSE_ARGS (args); +int err; + +if (fuse_bpf_mkdir (&err, dir, entry, mode)) +return err;if (!fm->fc->dont_mask) mode &= ~current_umask ();
@@ -1089,6 +1097,9 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry)if (fuse_is_bad (dir))return -EIO ; +if (fuse_bpf_unlink (&err, dir, entry)) +return err; + args.opcode =FUSE_UNLINK ; args.nodeid =get_node_id (dir); args.in_numargs =1 ;
@@ -1112,6 +1123,9 @@ static int fuse_rmdir(struct inode *dir, struct dentry *entry)if (fuse_is_bad (dir))return -EIO ; +if (fuse_bpf_rmdir (&err, dir, entry)) +return err; + args.opcode =FUSE_RMDIR ; args.nodeid =get_node_id (dir); args.in_numargs =1 ;
fs/fuse/fuse_i.h +24 -0
@@ -1441,6 +1441,10 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num_entries);int fuse_bpf_open (int *err,struct inode *inode,struct file *file,bool isdir);int fuse_bpf_create_open (int *out,struct inode *dir,struct dentry *entry,struct file *file,unsigned int flags,umode_t mode); +int fuse_bpf_mknod (int *out,struct inode *dir,struct dentry *entry,umode_t mode,dev_t rdev); +int fuse_bpf_mkdir (int *out,struct inode *dir,struct dentry *entry,umode_t mode); +int fuse_bpf_rmdir (int *out,struct inode *dir,struct dentry *entry); +int fuse_bpf_unlink (int *out,struct inode *dir,struct dentry *entry);int fuse_bpf_release (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_releasedir (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence);
@@ -1461,6 +1465,26 @@ static inline int fuse_bpf_create_open(int *out, struct inode *dir, struct dentrreturn 0 ; } +static inline int fuse_bpf_mknod (int *out,struct inode *dir,struct dentry *entry,umode_t mode,dev_t rdev) +{ +return 0 ; +} + +static inline int fuse_bpf_mkdir (int *out,struct inode *dir,struct dentry *entry,umode_t mode) +{ +return 0 ; +} + +static inline int fuse_bpf_rmdir (int *out,struct inode *dir,struct dentry *entry) +{ +return 0 ; +} + +static inline int fuse_bpf_unlink (int *out,struct inode *dir,struct dentry *entry) +{ +return 0 ; +} +static inline int fuse_bpf_release (int *out,struct inode *inode,struct file *file) {return 0 ;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 13/36 fuse-bpf: Add support for read/write iter
In reply to Daniel RosenbergAdds backing support for FUSE_READ and FUSE_WRITE
This includes adjustments from Amir Goldstein's patch to FUSE Passthrough
--- fs/fuse/backing.c | 384 ++++++++++++++++++++++++++++++++++++++ fs/fuse/control.c | 2 +- fs/fuse/file.c | 8 + fs/fuse/fuse_i.h | 19 +- fs/fuse/inode.c | 13 ++ include/uapi/linux/fuse.h | 10 + 6 files changed, 434 insertions(+), 2 deletions(-)
fs/fuse/backing.c +384 -0
@@ -11,6 +11,7 @@#include <linux/file.h> #include <linux/fs_stack.h> #include <linux/namei.h> +#include <linux/uio.h> /* * expression statement to wrap the backing filter logic
@@ -76,6 +77,95 @@ handled; \ }) +#define FUSE_BPF_IOCB_MASK (IOCB_APPEND | IOCB_DSYNC | IOCB_HIPRI | IOCB_NOWAIT | IOCB_SYNC) + +struct fuse_bpf_aio_req { +struct kiocb iocb; +refcount_t ref; +struct kiocb *iocb_orig; +struct timespec64 pre_atime; +}; + +static struct kmem_cache *fuse_bpf_aio_request_cachep; + +static void fuse_file_accessed (struct file *dst_file,struct file *src_file) +{ +struct inode *dst_inode; +struct inode *src_inode; +struct timespec64 dest_mtime, src_mtime, dst_ctime, src_ctime; + +if (dst_file->f_flags &O_NOATIME ) +return ; + + dst_inode =file_inode (dst_file); + src_inode =file_inode (src_file); + + dest_mtime =inode_get_mtime (dst_inode); + src_mtime =inode_get_mtime (src_inode); + dst_ctime =inode_get_ctime (dst_inode); + src_ctime =inode_get_ctime (src_inode); +if ((!timespec64_equal (&dest_mtime, &src_mtime) || + !timespec64_equal (&dst_ctime, &src_ctime))) { +inode_set_mtime_to_ts (dst_inode, src_mtime); +inode_set_ctime_to_ts (dst_inode, src_ctime); + } + +touch_atime (&dst_file->f_path); +} + +static void fuse_copyattr (struct file *dst_file,struct file *src_file) +{ +struct inode *dst =file_inode (dst_file); +struct inode *src =file_inode (src_file); + +inode_set_atime_to_ts (dst,inode_get_atime (src)); +inode_set_mtime_to_ts (dst,inode_get_mtime (src)); +inode_set_ctime_to_ts (dst,inode_get_ctime (src)); +i_size_write (dst,i_size_read (src)); +fuse_invalidate_attr (dst); +} + +static void fuse_file_start_write (struct file *fuse_file,struct file *backing_file, +loff_t pos,size_t count) +{ +struct inode *inode =file_inode (fuse_file); +struct fuse_inode *fi =get_fuse_inode (inode); + +if (inode->i_size < pos + count) +set_bit (FUSE_I_SIZE_UNSTABLE , &fi->state); + +file_start_write (backing_file); +} + +static void fuse_file_end_write (struct file *fuse_file,struct file *backing_file, +loff_t pos,size_t res) +{ +struct inode *inode =file_inode (fuse_file); +struct fuse_inode *fi =get_fuse_inode (inode); + +file_end_write (backing_file); + +if (res >0 ) +fuse_write_update_attr (inode, pos, res); + +clear_bit (FUSE_I_SIZE_UNSTABLE , &fi->state); +fuse_invalidate_attr (inode); +} + +static void fuse_file_start_read (struct file *backing_file,struct timespec64 *pre_atime) +{ + *pre_atime =inode_get_atime (file_inode (backing_file)); +} + +static void fuse_file_end_read (struct file *fuse_file,struct file *backing_file, +struct timespec64 *pre_atime) +{ +struct timespec64 atime =inode_get_atime (file_inode (backing_file)); +/* Mimic atime update policy of passthrough inode, not the value */ +if (!timespec64_equal (&atime, pre_atime)) +fuse_invalidate_atime (file_inode (fuse_file)); +} +static void fuse_get_backing_path (struct file *file,struct path *path) {path_get (&file->f_path);
@@ -635,6 +725,284 @@ int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *file, loff_t o file, offset, whence); } +static inline void fuse_bpf_aio_put (struct fuse_bpf_aio_req *aio_req) +{ +if (refcount_dec_and_test (&aio_req->ref)) +kmem_cache_free (fuse_bpf_aio_request_cachep, aio_req); +} + +static void fuse_bpf_aio_cleanup_handler (struct fuse_bpf_aio_req *aio_req,long res) +{ +struct kiocb *iocb = &aio_req->iocb; +struct kiocb *iocb_orig = aio_req->iocb_orig; +struct file *filp = iocb->ki_filp; +struct file *fuse_filp = iocb_orig->ki_filp; + +if (iocb->ki_flags &IOCB_WRITE ) { +__sb_writers_acquired (file_inode (iocb->ki_filp)->i_sb, +SB_FREEZE_WRITE ); +fuse_file_end_write (iocb_orig->ki_filp, iocb->ki_filp, iocb->ki_pos, res); + }else { +fuse_file_end_read (fuse_filp, filp, &aio_req->pre_atime); + } + iocb_orig->ki_pos = iocb->ki_pos; +fuse_bpf_aio_put (aio_req); +} + +static void fuse_bpf_aio_rw_complete (struct kiocb *iocb,long res) +{ +struct fuse_bpf_aio_req *aio_req = + container_of(iocb, struct fuse_bpf_aio_req, iocb); +struct kiocb *iocb_orig = aio_req->iocb_orig; + +fuse_bpf_aio_cleanup_handler (aio_req, res); + iocb_orig->ki_complete (iocb_orig, res); +} + +struct fuse_file_read_iter_args { +struct fuse_read_in in; +struct fuse_read_iter_out out; +}; + +static int fuse_file_read_iter_initialize_in (struct bpf_fuse_args *fa,struct fuse_file_read_iter_args *args, +struct kiocb *iocb,struct iov_iter *to) +{ +struct file *file = iocb->ki_filp; +struct fuse_file *ff = file->private_data; + + args->in = (struct fuse_read_in ) { + .fh = ff->fh, + .offset = iocb->ki_pos, + .size = to->count, + }; + +/* TODO we can't assume 'to' is a kvec */ +/* TODO we also can't assume the vector has only one component */ + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .opcode =FUSE_READ , + .nodeid = ff->nodeid, + }, .in_numargs =1 , + .in_args[0 ].size =sizeof (args->in), + .in_args[0 ].value = &args->in, +/* +* TODO Design this properly. +* Possible approach: do not pass buf to bpf +* If going to userland, do a deep copy +* For extra credit, do that to/from the vector, rather than +* making an extra copy in the kernel +*/ + }; + +return 0 ; +} + +static int fuse_file_read_iter_initialize_out (struct bpf_fuse_args *fa,struct fuse_file_read_iter_args *args, +struct kiocb *iocb,struct iov_iter *to) +{ + args->out = (struct fuse_read_iter_out ) { + .ret = args->in.size, + }; + + fa->out_numargs =1 ; + fa->out_args[0 ].size =sizeof (args->out); + fa->out_args[0 ].value = &args->out; + +return 0 ; +} + + +// TODO: use backing-file.c +static inline rwf_t fuse_iocb_to_rw_flags (int ifl,int iocb_mask) +{ +return ifl & iocb_mask; +} + +static int fuse_file_read_iter_backing (struct bpf_fuse_args *fa,ssize_t *out, +struct kiocb *iocb,struct iov_iter *to) +{ +struct fuse_read_iter_out *frio = fa->out_args[0 ].value; +struct file *file = iocb->ki_filp; +struct fuse_file *ff = file->private_data; + +if (!iov_iter_count (to)) +return 0 ; + +if ((iocb->ki_flags &IOCB_DIRECT ) && + (!ff->backing_file->f_mapping->a_ops || + !ff->backing_file->f_mapping->a_ops->direct_IO)) +return -EINVAL ; + +/* TODO This just plain ignores any change to fuse_read_in */ +if (is_sync_kiocb (iocb)) { +struct timespec64 pre_atime; + +fuse_file_start_read (ff->backing_file, &pre_atime); + *out =vfs_iter_read (ff->backing_file, to, &iocb->ki_pos, +fuse_iocb_to_rw_flags (iocb->ki_flags,FUSE_BPF_IOCB_MASK )); +fuse_file_end_read (file, ff->backing_file, &pre_atime); + }else { +struct fuse_bpf_aio_req *aio_req; + + *out = -ENOMEM ; + aio_req =kmem_cache_zalloc (fuse_bpf_aio_request_cachep,GFP_KERNEL ); +if (!aio_req) + goto out; + + aio_req->iocb_orig = iocb; +fuse_file_start_read (ff->backing_file, &aio_req->pre_atime); +kiocb_clone (&aio_req->iocb, iocb, ff->backing_file); + aio_req->iocb.ki_complete = fuse_bpf_aio_rw_complete; +refcount_set (&aio_req->ref,2 ); + *out =vfs_iocb_iter_read (ff->backing_file, &aio_req->iocb, to); +fuse_bpf_aio_put (aio_req); +if (*out != -EIOCBQUEUED ) +fuse_bpf_aio_cleanup_handler (aio_req, *out); + } + + frio->ret = *out; + +/* TODO Need to point value at the buffer for post-modification */ + +out: +fuse_file_accessed (file, ff->backing_file); + +return *out; +} + +static int fuse_file_read_iter_finalize (struct bpf_fuse_args *fa,ssize_t *out, +struct kiocb *iocb,struct iov_iter *to) +{ +struct fuse_read_iter_out *frio = fa->out_args[0 ].value; + + *out = frio->ret; + +return 0 ; +} + +int fuse_bpf_file_read_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *to) +{ + return bpf_fuse_backing(inode, struct fuse_file_read_iter_args, out, + fuse_file_read_iter_initialize_in, + fuse_file_read_iter_initialize_out, + fuse_file_read_iter_backing, + fuse_file_read_iter_finalize, + iocb, to); +} + +struct fuse_file_write_iter_args { +struct fuse_write_in in; +struct fuse_write_iter_out out; +}; + +static int fuse_file_write_iter_initialize_in (struct bpf_fuse_args *fa, +struct fuse_file_write_iter_args *args, +struct kiocb *iocb,struct iov_iter *from) +{ +struct file *file = iocb->ki_filp; +struct fuse_file *ff = file->private_data; + + *args = (struct fuse_file_write_iter_args ) { + .in.fh = ff->fh, + .in.offset = iocb->ki_pos, + .in.size = from->count, + }; + +/* TODO we can't assume 'from' is a kvec */ + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .opcode =FUSE_WRITE , + .nodeid = ff->nodeid, + }, + .in_numargs =1 , + .in_args[0 ].size =sizeof (args->in), + .in_args[0 ].value = &args->in, + }; + +return 0 ; +} + +static int fuse_file_write_iter_initialize_out (struct bpf_fuse_args *fa, +struct fuse_file_write_iter_args *args, +struct kiocb *iocb,struct iov_iter *from) +{ +/* TODO we can't assume 'from' is a kvec */ + fa->out_numargs =1 ; + fa->out_args[0 ].size =sizeof (args->out); + fa->out_args[0 ].value = &args->out; + +return 0 ; +} + +static int fuse_file_write_iter_backing (struct bpf_fuse_args *fa,ssize_t *out, +struct kiocb *iocb,struct iov_iter *from) +{ +struct file *file = iocb->ki_filp; +struct fuse_file *ff = file->private_data; +struct fuse_write_iter_out *fwio = fa->out_args[0 ].value; +ssize_t count =iov_iter_count (from); + +if (!count) +return 0 ; + +/* TODO This just plain ignores any change to fuse_write_in */ +/* TODO uint32_t seems smaller than ssize_t.... right? */ +inode_lock (file_inode (file)); + +fuse_copyattr (file, ff->backing_file); + +if (is_sync_kiocb (iocb)) { +fuse_file_start_write (file, ff->backing_file, iocb->ki_pos, count); + *out =vfs_iter_write (ff->backing_file, from, &iocb->ki_pos, +fuse_iocb_to_rw_flags (iocb->ki_flags,FUSE_BPF_IOCB_MASK )); +fuse_file_end_write (file, ff->backing_file, iocb->ki_pos, *out); + }else { +struct fuse_bpf_aio_req *aio_req; + + *out = -ENOMEM ; + aio_req =kmem_cache_zalloc (fuse_bpf_aio_request_cachep,GFP_KERNEL ); +if (!aio_req) + goto out; + +fuse_file_start_write (file, ff->backing_file, iocb->ki_pos, count); +__sb_writers_release (file_inode (ff->backing_file)->i_sb,SB_FREEZE_WRITE ); + aio_req->iocb_orig = iocb; +kiocb_clone (&aio_req->iocb, iocb, ff->backing_file); + aio_req->iocb.ki_complete = fuse_bpf_aio_rw_complete; +refcount_set (&aio_req->ref,2 ); + *out =vfs_iocb_iter_write (ff->backing_file, &aio_req->iocb, from); +fuse_bpf_aio_put (aio_req); +if (*out != -EIOCBQUEUED ) +fuse_bpf_aio_cleanup_handler (aio_req, *out); + } + +out: +inode_unlock (file_inode (file)); + fwio->ret = *out; +if (*out <0 ) +return *out; +return 0 ; +} + +static int fuse_file_write_iter_finalize (struct bpf_fuse_args *fa,ssize_t *out, +struct kiocb *iocb,struct iov_iter *from) +{ +struct fuse_write_iter_out *fwio = fa->out_args[0 ].value; + + *out = fwio->ret; +return 0 ; +} + +int fuse_bpf_file_write_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *from) +{ + return bpf_fuse_backing(inode, struct fuse_file_write_iter_args, out, + fuse_file_write_iter_initialize_in, + fuse_file_write_iter_initialize_out, + fuse_file_write_iter_backing, + fuse_file_write_iter_finalize, + iocb, from); +} +ssize_t fuse_backing_mmap (struct file *file,struct vm_area_struct *vma) {int ret;
@@ -1335,3 +1703,19 @@ int fuse_bpf_access(int *out, struct inode *inode, int mask) fuse_access_initialize_in, fuse_access_initialize_out, fuse_access_backing, fuse_access_finalize, inode, mask); } + +int __init fuse_bpf_init (void ) +{ + fuse_bpf_aio_request_cachep =kmem_cache_create ("fuse_bpf_aio_req" , +sizeof (struct fuse_bpf_aio_req ), +0 ,SLAB_HWCACHE_ALIGN ,NULL ); +if (!fuse_bpf_aio_request_cachep) +return -ENOMEM ; + +return 0 ; +} + +void __exit fuse_bpf_cleanup(void) +{ +kmem_cache_destroy (fuse_bpf_aio_request_cachep); +}
fs/fuse/control.c +1 -1
@@ -378,7 +378,7 @@ int __init fuse_ctl_init(void)return register_filesystem (&fuse_ctl_fs_type); } -void __exit fuse_ctl_cleanup(void) +void fuse_ctl_cleanup (void ) {unregister_filesystem (&fuse_ctl_fs_type); }
fs/fuse/file.c +8 -0
@@ -1646,6 +1646,7 @@ static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to)struct file *file = iocb->ki_filp;struct fuse_file *ff = file->private_data;struct inode *inode =file_inode (file); +ssize_t ret;if (fuse_is_bad (inode))return -EIO ;
@@ -1653,6 +1654,9 @@ static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to)if (FUSE_IS_DAX (inode))return fuse_dax_read_iter (iocb, to); +if (fuse_bpf_file_read_iter (&ret, inode, iocb, to)) +return ret; +if (!(ff->open_flags &FOPEN_DIRECT_IO ))return fuse_cache_read_iter (iocb, to);else
@@ -1664,6 +1668,7 @@ static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)struct file *file = iocb->ki_filp;struct fuse_file *ff = file->private_data;struct inode *inode =file_inode (file); +ssize_t ret =0 ;if (fuse_is_bad (inode))return -EIO ;
@@ -1671,6 +1676,9 @@ static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)if (FUSE_IS_DAX (inode))return fuse_dax_write_iter (iocb, from); +if (fuse_bpf_file_write_iter (&ret, inode, iocb, from)) +return ret; +if (!(ff->open_flags &FOPEN_DIRECT_IO ))return fuse_cache_write_iter (iocb, from);else
fs/fuse/fuse_i.h +18 -1
@@ -1164,7 +1164,7 @@ int fuse_dev_init(void);void fuse_dev_cleanup (void );int fuse_ctl_init (void ); -void __exit fuse_ctl_cleanup(void); +void fuse_ctl_cleanup (void );/** * Simple request sending that does request allocation and freeing
@@ -1448,6 +1448,8 @@ int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry);int fuse_bpf_release (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_releasedir (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence); +int fuse_bpf_file_read_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *to); +int fuse_bpf_file_write_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *from);int fuse_bpf_file_fallocate (int *out,struct inode *inode,struct file *file,int mode,loff_t offset,loff_t length);int fuse_bpf_lookup (struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags);int fuse_bpf_access (int *out,struct inode *inode,int mask);
@@ -1500,6 +1502,16 @@ static inline int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *return 0 ; } +static inline int fuse_bpf_file_read_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *to) +{ +return 0 ; +} + +static inline int fuse_bpf_file_write_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *from) +{ +return 0 ; +} +static inline int fuse_bpf_file_fallocate (int *out,struct inode *inode,struct file *file,int mode,loff_t offset,loff_t length) {return 0 ;
@@ -1523,4 +1535,9 @@ int fuse_handle_backing(struct fuse_bpf_entry *fbe, struct path *backing_path);int fuse_revalidate_backing (struct dentry *entry,unsigned int flags); +#ifdef CONFIG_FUSE_BPF +int __init fuse_bpf_init (void ); +void __exit fuse_bpf_cleanup(void); +#endif /* CONFIG_FUSE_BPF */ +#endif /* _FS_FUSE_I_H */
fs/fuse/inode.c +13 -0
@@ -2199,11 +2199,21 @@ static int __init fuse_init(void)if (res) goto err_sysfs_cleanup; +#ifdef CONFIG_FUSE_BPF + res =fuse_bpf_init (); +if (res) + goto err_ctl_cleanup; +#endif +sanitize_global_limit (&max_user_bgreq);sanitize_global_limit (&max_user_congthresh);return 0 ; +#ifdef CONFIG_FUSE_BPF + err_ctl_cleanup: +fuse_ctl_cleanup (); +#endif err_sysfs_cleanup:fuse_sysfs_cleanup (); err_dev_cleanup:
@@ -2221,6 +2231,9 @@ static void __exit fuse_exit(void)fuse_ctl_cleanup ();fuse_sysfs_cleanup ();fuse_fs_cleanup (); +#ifdef CONFIG_FUSE_BPF +fuse_bpf_cleanup (); +#endif fuse_dev_cleanup (); }
include/uapi/linux/fuse.h +10 -0
@@ -811,6 +811,11 @@ struct fuse_read_in {uint32_t padding; }; +// This is likely not what we want +struct fuse_read_iter_out { +uint64_t ret; +}; +#define FUSE_COMPAT_WRITE_IN_SIZE 24struct fuse_write_in {
@@ -828,6 +833,11 @@ struct fuse_write_out {uint32_t padding; }; +// This is likely not what we want +struct fuse_write_iter_out { +uint64_t ret; +}; +#define FUSE_COMPAT_STATFS_SIZE 48struct fuse_statfs_out {
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 14/36 fuse-bpf: support readdir
In reply to Daniel RosenbergThis adds backing support for FUSE_READDIR
--- fs/fuse/backing.c | 202 ++++++++++++++++++++++++++++++++++++++ fs/fuse/fuse_i.h | 6 ++ fs/fuse/readdir.c | 5 + include/uapi/linux/fuse.h | 6 ++ 4 files changed, 219 insertions(+)
fs/fuse/backing.c +202 -0
@@ -1657,6 +1657,208 @@ int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry) dir, entry); } +struct fuse_read_args { +struct fuse_read_in in; +struct fuse_read_out out; +struct fuse_buffer buffer; +}; + +static int fuse_readdir_initialize_in (struct bpf_fuse_args *fa,struct fuse_read_args *args, +struct file *file,struct dir_context *ctx, +bool *force_again,bool *allow_force,bool is_continued) +{ +struct fuse_file *ff = file->private_data; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid = ff->nodeid, + .opcode =FUSE_READDIR , + }, + .in_numargs =1 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + }; + + args->in = (struct fuse_read_in ) { + .fh = ff->fh, + .offset = ctx->pos, + .size =PAGE_SIZE , + }; + + *force_again = false; + *allow_force = true; +return 0 ; +} + +static int fuse_readdir_initialize_out (struct bpf_fuse_args *fa,struct fuse_read_args *args, +struct file *file,struct dir_context *ctx, +bool *force_again,bool *allow_force,bool is_continued) +{ +u8 *page = (u8 *)__get_free_page (GFP_KERNEL ); + +if (!page) +return -ENOMEM ; + + fa->flags =FUSE_BPF_OUT_ARGVAR ; + fa->out_numargs =2 ; + fa->out_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->out), + .value = &args->out, + }; + fa->out_args[1 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->buffer, + }; + args->out = (struct fuse_read_out ) { + .again =0 , + .offset =0 , + }; + args->buffer = (struct fuse_buffer ) { + .data = page, + .size =PAGE_SIZE , + .alloc_size =PAGE_SIZE , + .max_size =PAGE_SIZE , + .flags =BPF_FUSE_VARIABLE_SIZE , + }; + +return 0 ; +} + +struct fusebpf_ctx { +struct dir_context ctx; +u8 *addr; +size_t offset; +}; + +static bool filldir (struct dir_context *ctx,const char *name,int namelen, +loff_t offset,u64 ino,unsigned int d_type) +{ + struct fusebpf_ctx *ec = container_of(ctx, struct fusebpf_ctx, ctx); +struct fuse_dirent *fd = (struct fuse_dirent *)(ec->addr + ec->offset); + +if (ec->offset +sizeof (struct fuse_dirent ) + namelen >PAGE_SIZE ) +return false; + + *fd = (struct fuse_dirent ) { + .ino = ino, + .off = offset, + .namelen = namelen, + .type = d_type, + }; + +memcpy (fd->name, name, namelen); + ec->offset +=FUSE_DIRENT_SIZE (fd); + +return true; +} + +static int parse_dirfile (char *buf,size_t nbytes,struct dir_context *ctx, +loff_t next_offset) +{ +char *buf_start = buf; + +while (nbytes >=FUSE_NAME_OFFSET ) { +struct fuse_dirent *dirent = (struct fuse_dirent *) buf; +size_t reclen =FUSE_DIRENT_SIZE (dirent); + +if (!dirent->namelen || dirent->namelen >FUSE_NAME_MAX ) +return -EIO ; +if (reclen > nbytes) +break ; +if (memchr (dirent->name,'/' , dirent->namelen) !=NULL ) +return -EIO ; + + ctx->pos = dirent->off; +if (!dir_emit (ctx, dirent->name, dirent->namelen, dirent->ino, + dirent->type)) { +// If we can't make any progress, user buffer is too small +if (buf == buf_start) +return -EINVAL ; +else +return 0 ; + } + + buf += reclen; + nbytes -= reclen; + } + ctx->pos = next_offset; + +return 0 ; +} + +static int fuse_readdir_backing (struct bpf_fuse_args *fa,int *out, +struct file *file,struct dir_context *ctx, +bool *force_again,bool *allow_force,bool is_continued) +{ +struct fuse_file *ff = file->private_data; +struct file *backing_dir = ff->backing_file; +struct fuse_read_out *fro = fa->out_args[0 ].value; +struct fusebpf_ctx ec; + + ec = (struct fusebpf_ctx ) { + .ctx.actor = filldir, + .ctx.pos = ctx->pos, + .addr = fa->out_args[1 ].buffer->data, + }; + +if (!ec.addr) +return -ENOMEM ; + +if (!is_continued) + backing_dir->f_pos = file->f_pos; + + *out =iterate_dir (backing_dir, &ec.ctx); +if (ec.offset ==0 ) + *allow_force = false; + fa->out_args[1 ].buffer->size = ec.offset; + + fro->offset = ec.ctx.pos; + fro->again = false; + +return *out; +} + +static int fuse_readdir_finalize (struct bpf_fuse_args *fa,int *out, +struct file *file,struct dir_context *ctx, +bool *force_again,bool *allow_force,bool is_continued) +{ +struct fuse_read_out *fro = fa->out_args[0 ].value; +struct fuse_file *ff = file->private_data; +struct file *backing_dir = ff->backing_file; + + *out =parse_dirfile (fa->out_args[1 ].buffer->data, fa->out_args[1 ].buffer->size, ctx, fro->offset); + *force_again = !!fro->again; +if (*force_again && !*allow_force) + *out = -EINVAL ; + + backing_dir->f_pos = ctx->pos; + +free_page ((unsigned long )fa->out_args[1 ].buffer->data); +return *out; +} + +int fuse_bpf_readdir (int *out,struct inode *inode,struct file *file,struct dir_context *ctx) +{ +int ret; +bool allow_force; +bool force_again = false; +bool is_continued = false; + +again: + ret = bpf_fuse_backing(inode, struct fuse_read_args, out, + fuse_readdir_initialize_in, fuse_readdir_initialize_out, + fuse_readdir_backing, fuse_readdir_finalize, + file, ctx, &force_again, &allow_force, is_continued); +if (force_again && *out >=0 ) { + is_continued = true; + goto again; + } + +return ret; +} +static int fuse_access_initialize_in (struct bpf_fuse_args *fa,struct fuse_access_in *in,struct inode *inode,int mask) {
fs/fuse/fuse_i.h +6 -0
@@ -1452,6 +1452,7 @@ int fuse_bpf_file_read_iter(ssize_t *out, struct inode *inode, struct kiocb *iocint fuse_bpf_file_write_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *from);int fuse_bpf_file_fallocate (int *out,struct inode *inode,struct file *file,int mode,loff_t offset,loff_t length);int fuse_bpf_lookup (struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags); +int fuse_bpf_readdir (int *out,struct inode *inode,struct file *file,struct dir_context *ctx);int fuse_bpf_access (int *out,struct inode *inode,int mask);#else
@@ -1522,6 +1523,11 @@ static inline int fuse_bpf_lookup(struct dentry **out, struct inode *dir, structreturn 0 ; } +static inline int fuse_bpf_readdir (int *out,struct inode *inode,struct file *file,struct dir_context *ctx) +{ +return 0 ; +} +static inline int fuse_bpf_access (int *out,struct inode *inode,int mask) {return 0 ;
fs/fuse/readdir.c +5 -0
@@ -20,6 +20,8 @@ static bool fuse_use_readdirplus(struct inode *dir, struct dir_context *ctx)if (!fc->do_readdirplus)return false; +if (fi->nodeid ==0 ) +return false;if (!fc->readdirplus_auto)return true;if (test_and_clear_bit (FUSE_I_ADVISE_RDPLUS , &fi->state))
@@ -592,6 +594,9 @@ int fuse_readdir(struct file *file, struct dir_context *ctx)if (fuse_is_bad (inode))return -EIO ; +if (fuse_bpf_readdir (&err, inode, file, ctx)) +return err; +mutex_lock (&ff->readdir.lock); err =UNCACHED ;
include/uapi/linux/fuse.h +6 -0
@@ -811,6 +811,12 @@ struct fuse_read_in {uint32_t padding; }; +struct fuse_read_out { +uint64_t offset; +uint32_t again; +uint32_t padding; +}; +// This is likely not what we want struct fuse_read_iter_out {uint64_t ret;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 15/36 fuse-bpf: Add support for sync operations
In reply to Daniel RosenbergThis adds backing support for FUSE_FLUSH, FUSE_FSYNC, and FUSE_FSYNCDIR.
--- fs/fuse/backing.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 3 + fs/fuse/file.c | 6 ++ fs/fuse/fuse_i.h | 18 ++++++ 4 files changed, 174 insertions(+)
fs/fuse/backing.c +147 -0
@@ -636,6 +636,59 @@ int fuse_bpf_releasedir(int *out, struct inode *inode, struct fuse_file *ff) fuse_release_backing, fuse_release_finalize, inode, ff); } +static int fuse_flush_initialize_in (struct bpf_fuse_args *fa,struct fuse_flush_in *ffi, +struct file *file,fl_owner_t id) +{ +struct fuse_file *fuse_file = file->private_data; + + *ffi = (struct fuse_flush_in ) { + .fh = fuse_file->fh, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (file->f_inode), + .opcode =FUSE_FLUSH , + }, + .in_numargs =1 , + .in_args[0 ].size =sizeof (*ffi), + .in_args[0 ].value = ffi, + .flags =FUSE_BPF_FORCE , + }; + +return 0 ; +} + +static int fuse_flush_initialize_out (struct bpf_fuse_args *fa,struct fuse_flush_in *ffi, +struct file *file,fl_owner_t id) +{ +return 0 ; +} + +static int fuse_flush_backing (struct bpf_fuse_args *fa,int *out,struct file *file,fl_owner_t id) +{ +struct fuse_file *fuse_file = file->private_data; +struct file *backing_file = fuse_file->backing_file; + + *out =0 ; +if (backing_file->f_op->flush) + *out = backing_file->f_op->flush (backing_file, id); +return *out; +} + +static int fuse_flush_finalize (struct bpf_fuse_args *fa,int *out,struct file *file,fl_owner_t id) +{ +return 0 ; +} + +int fuse_bpf_flush (int *out,struct inode *inode,struct file *file,fl_owner_t id) +{ + return bpf_fuse_backing(inode, struct fuse_flush_in, out, + fuse_flush_initialize_in, fuse_flush_initialize_out, + fuse_flush_backing, fuse_flush_finalize, + file, id); +} +struct fuse_lseek_args {struct fuse_lseek_in in;struct fuse_lseek_out out;
@@ -725,6 +778,100 @@ int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *file, loff_t o file, offset, whence); } +static int fuse_fsync_initialize_in (struct bpf_fuse_args *fa,struct fuse_fsync_in *in, +struct file *file,loff_t start,loff_t end,int datasync) +{ +struct fuse_file *fuse_file = file->private_data; + + *in = (struct fuse_fsync_in ) { + .fh = fuse_file->fh, + .fsync_flags = datasync ?FUSE_FSYNC_FDATASYNC :0 , + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_fuse_inode (file->f_inode)->nodeid, + .opcode =FUSE_FSYNC , + }, + .in_numargs =1 , + .in_args[0 ].size =sizeof (*in), + .in_args[0 ].value = in, + .flags =FUSE_BPF_FORCE , + }; + +return 0 ; +} + +static int fuse_fsync_initialize_out (struct bpf_fuse_args *fa,struct fuse_fsync_in *ffi, +struct file *file,loff_t start,loff_t end,int datasync) +{ +return 0 ; +} + +static int fuse_fsync_backing (struct bpf_fuse_args *fa,int *out, +struct file *file,loff_t start,loff_t end,int datasync) +{ +struct fuse_file *fuse_file = file->private_data; +struct file *backing_file = fuse_file->backing_file; +const struct fuse_fsync_in *ffi = fa->in_args[0 ].value; +int new_datasync = (ffi->fsync_flags &FUSE_FSYNC_FDATASYNC ) ?1 :0 ; + + *out =vfs_fsync (backing_file, new_datasync); +return 0 ; +} + +static int fuse_fsync_finalize (struct bpf_fuse_args *fa,int *out, +struct file *file,loff_t start,loff_t end,int datasync) +{ +return 0 ; +} + +int fuse_bpf_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync) +{ + return bpf_fuse_backing(inode, struct fuse_fsync_in, out, + fuse_fsync_initialize_in, fuse_fsync_initialize_out, + fuse_fsync_backing, fuse_fsync_finalize, + file, start, end, datasync); +} + +static int fuse_dir_fsync_initialize_in (struct bpf_fuse_args *fa,struct fuse_fsync_in *in, +struct file *file,loff_t start,loff_t end,int datasync) +{ +struct fuse_file *fuse_file = file->private_data; + + *in = (struct fuse_fsync_in ) { + .fh = fuse_file->fh, + .fsync_flags = datasync ?FUSE_FSYNC_FDATASYNC :0 , + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_fuse_inode (file->f_inode)->nodeid, + .opcode =FUSE_FSYNCDIR , + }, + .in_numargs =1 , + .in_args[0 ].size =sizeof (*in), + .in_args[0 ].value = in, + .flags =FUSE_BPF_FORCE , + }; + +return 0 ; +} + +static int fuse_dir_fsync_initialize_out (struct bpf_fuse_args *fa,struct fuse_fsync_in *ffi, +struct file *file,loff_t start,loff_t end,int datasync) +{ +return 0 ; +} + +int fuse_bpf_dir_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync) +{ + return bpf_fuse_backing(inode, struct fuse_fsync_in, out, + fuse_dir_fsync_initialize_in, fuse_dir_fsync_initialize_out, + fuse_fsync_backing, fuse_fsync_finalize, + file, start, end, datasync); +} +static inline void fuse_bpf_aio_put (struct fuse_bpf_aio_req *aio_req) {if (refcount_dec_and_test (&aio_req->ref))
fs/fuse/dir.c +3 -0
@@ -1785,6 +1785,9 @@ static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,if (fuse_is_bad (inode))return -EIO ; +if (fuse_bpf_dir_fsync (&err, inode, file, start, end, datasync)) +return err; +if (fc->no_fsyncdir)return 0 ;
fs/fuse/file.c +6 -0
@@ -510,6 +510,9 @@ static int fuse_flush(struct file *file, fl_owner_t id)if (fuse_is_bad (inode))return -EIO ; +if (fuse_bpf_flush (&err,file_inode (file), file, id)) +return err; +if (ff->open_flags &FOPEN_NOFLUSH && !fm->fc->writeback_cache)return 0 ;
@@ -585,6 +588,9 @@ static int fuse_fsync(struct file *file, loff_t start, loff_t end,if (fuse_is_bad (inode))return -EIO ; +if (fuse_bpf_fsync (&err, inode, file, start, end, datasync)) +return err; +inode_lock (inode);/*
fs/fuse/fuse_i.h +18 -0
@@ -1447,7 +1447,10 @@ int fuse_bpf_rmdir(int *out, struct inode *dir, struct dentry *entry);int fuse_bpf_unlink (int *out,struct inode *dir,struct dentry *entry);int fuse_bpf_release (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_releasedir (int *out,struct inode *inode,struct fuse_file *ff); +int fuse_bpf_flush (int *out,struct inode *inode,struct file *file,fl_owner_t id);int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence); +int fuse_bpf_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync); +int fuse_bpf_dir_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync);int fuse_bpf_file_read_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *to);int fuse_bpf_file_write_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *from);int fuse_bpf_file_fallocate (int *out,struct inode *inode,struct file *file,int mode,loff_t offset,loff_t length);
@@ -1498,11 +1501,26 @@ static inline int fuse_bpf_releasedir(int *out, struct inode *inode, struct filereturn 0 ; } +static inline int fuse_bpf_flush (int *out,struct inode *inode,struct file *file,fl_owner_t id) +{ +return 0 ; +} +static inline int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence) {return 0 ; } +static inline int fuse_bpf_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync) +{ +return 0 ; +} + +static inline int fuse_bpf_dir_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync) +{ +return 0 ; +} +static inline int fuse_bpf_file_read_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *to) {return 0 ;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 16/36 fuse-bpf: Add Rename support
In reply to Daniel RosenbergThis adds backing support for FUSE_RENAME and FUSE_RENAME2
--- fs/fuse/backing.c | 250 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 7 ++ fs/fuse/fuse_i.h | 18 ++++ 3 files changed, 275 insertions(+)
fs/fuse/backing.c +250 -0
@@ -1735,6 +1735,256 @@ int fuse_bpf_rmdir(int *out, struct inode *dir, struct dentry *entry) dir, entry); } +static int fuse_rename_backing_common (struct inode *olddir, +struct dentry *oldent, +struct inode *newdir, +struct dentry *newent,unsigned int flags) +{ +int err =0 ; +struct path old_backing_path; +struct path new_backing_path; +struct dentry *old_backing_dir_dentry; +struct dentry *old_backing_dentry; +struct dentry *new_backing_dir_dentry; +struct dentry *new_backing_dentry; +struct dentry *trap =NULL ; +struct inode *target_inode; +struct renamedata rd; + +//TODO Actually deal with changing anything that isn't a flag +get_fuse_backing_path (oldent, &old_backing_path); +if (!old_backing_path.dentry) +return -EBADF ; +get_fuse_backing_path (newent, &new_backing_path); +if (!new_backing_path.dentry) { +/* +* TODO A file being moved from a backing path to another +* backing path which is not yet instrumented with FUSE-BPF. +* This may be slow and should be substituted with something +* more clever. +*/ + err = -EXDEV ; + goto put_old_path; + } +if (new_backing_path.mnt != old_backing_path.mnt) { + err = -EXDEV ; + goto put_new_path; + } + old_backing_dentry = old_backing_path.dentry; + new_backing_dentry = new_backing_path.dentry; + old_backing_dir_dentry =dget_parent (old_backing_dentry); + new_backing_dir_dentry =dget_parent (new_backing_dentry); + target_inode =d_inode (newent); + + trap =lock_rename (old_backing_dir_dentry, new_backing_dir_dentry); +if (trap == old_backing_dentry) { + err = -EINVAL ; + goto put_parents; + } +if (trap == new_backing_dentry) { + err = -ENOTEMPTY ; + goto put_parents; + } + + rd = (struct renamedata ) { + .old_mnt_idmap = &nop_mnt_idmap, + .old_dir =d_inode (old_backing_dir_dentry), + .old_dentry = old_backing_dentry, + .new_mnt_idmap = &nop_mnt_idmap, + .new_dir =d_inode (new_backing_dir_dentry), + .new_dentry = new_backing_dentry, + .flags = flags, + }; + err =vfs_rename (&rd); +if (err) + goto unlock; +if (target_inode) +fsstack_copy_attr_all (target_inode, +get_fuse_inode (target_inode)->backing_inode); +fsstack_copy_attr_all (d_inode (oldent),d_inode (old_backing_dentry)); +unlock: +unlock_rename (old_backing_dir_dentry, new_backing_dir_dentry); +put_parents: +dput (new_backing_dir_dentry); +dput (old_backing_dir_dentry); +put_new_path: +path_put (&new_backing_path); +put_old_path: +path_put (&old_backing_path); +return err; +} + +struct fuse_rename2_args { +struct fuse_rename2_in in; +struct fuse_buffer old_name; +struct fuse_buffer new_name; +}; + +static int fuse_rename2_initialize_in (struct bpf_fuse_args *fa,struct fuse_rename2_args *args, +struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent, +unsigned int flags) +{ + *args = (struct fuse_rename2_args ) { + .in = (struct fuse_rename2_in ) { + .newdir =get_node_id (newdir), + .flags = flags, + }, + .old_name = (struct fuse_buffer ) { + .data = (void *) oldent->d_name.name, + .size = oldent->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }, + .new_name = (struct fuse_buffer ) { + .data = (void *) newent->d_name.name, + .size = newent->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }, + + }; + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (olddir), + .opcode =FUSE_RENAME2 , + }, + .in_numargs =3 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + .in_args[1 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->old_name, + }, + .in_args[2 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->new_name, + }, + }; + +return 0 ; +} + +static int fuse_rename2_initialize_out (struct bpf_fuse_args *fa,struct fuse_rename2_args *args, +struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent, +unsigned int flags) +{ +return 0 ; +} + +static int fuse_rename2_backing (struct bpf_fuse_args *fa,int *out, +struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent, +unsigned int flags) +{ +const struct fuse_rename2_args *fri = fa->in_args[0 ].value; + +/* TODO: deal with changing dirs/ents */ + *out =fuse_rename_backing_common (olddir, oldent, newdir, newent, + fri->in.flags); +return *out; +} + +static int fuse_rename2_finalize (struct bpf_fuse_args *fa,int *out, +struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent, +unsigned int flags) +{ +return 0 ; +} + +int fuse_bpf_rename2 (int *out,struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent, +unsigned int flags) +{ + return bpf_fuse_backing(olddir, struct fuse_rename2_args, out, + fuse_rename2_initialize_in, fuse_rename2_initialize_out, + fuse_rename2_backing, fuse_rename2_finalize, + olddir, oldent, newdir, newent, flags); +} + +struct fuse_rename_args { +struct fuse_rename_in in; +struct fuse_buffer old_name; +struct fuse_buffer new_name; +}; + +static int fuse_rename_initialize_in (struct bpf_fuse_args *fa,struct fuse_rename_args *args, +struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent) +{ + *args = (struct fuse_rename_args ) { + .in = (struct fuse_rename_in ) { + .newdir =get_node_id (newdir), + }, + .old_name = (struct fuse_buffer ) { + .data = (void *) oldent->d_name.name, + .size = oldent->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }, + .new_name = (struct fuse_buffer ) { + .data = (void *) newent->d_name.name, + .size = newent->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }, + + }; + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (olddir), + .opcode =FUSE_RENAME , + }, + .in_numargs =3 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + .in_args[1 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->old_name, + }, + .in_args[2 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->new_name, + }, + }; + +return 0 ; +} + +static int fuse_rename_initialize_out (struct bpf_fuse_args *fa,struct fuse_rename_args *args, +struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent) +{ +return 0 ; +} + +static int fuse_rename_backing (struct bpf_fuse_args *fa,int *out, +struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent) +{ +/* TODO: deal with changing dirs/ents */ + *out =fuse_rename_backing_common (olddir, oldent, newdir, newent,0 ); +return *out; +} + +static int fuse_rename_finalize (struct bpf_fuse_args *fa,int *out, +struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent) +{ +return 0 ; +} + +int fuse_bpf_rename (int *out,struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent) +{ + return bpf_fuse_backing(olddir, struct fuse_rename_args, out, + fuse_rename_initialize_in, fuse_rename_initialize_out, + fuse_rename_backing, fuse_rename_finalize, + olddir, oldent, newdir, newent); +} +static int fuse_unlink_initialize_in (struct bpf_fuse_args *fa,struct fuse_buffer *name,struct inode *dir,struct dentry *entry) {
fs/fuse/dir.c +7 -0
@@ -1204,6 +1204,10 @@ static int fuse_rename2(struct mnt_idmap *idmap, struct inode *olddir,return -EINVAL ;if (flags) { +if (fuse_bpf_rename2 (&err, olddir, oldent, newdir, newent, flags)) +return err; + +/* TODO: how should this go with bpfs involved? */ if (fc->no_rename2 || fc->minor <23 )return -EINVAL ;
@@ -1215,6 +1219,9 @@ static int fuse_rename2(struct mnt_idmap *idmap, struct inode *olddir, err = -EINVAL ; } }else { +if (fuse_bpf_rename (&err, olddir, oldent, newdir, newent)) +return err; + err =fuse_rename_common (olddir, oldent, newdir, newent,0 ,FUSE_RENAME ,sizeof (struct fuse_rename_in ));
fs/fuse/fuse_i.h +18 -0
@@ -1444,6 +1444,11 @@ int fuse_bpf_create_open(int *out, struct inode *dir, struct dentry *entry,int fuse_bpf_mknod (int *out,struct inode *dir,struct dentry *entry,umode_t mode,dev_t rdev);int fuse_bpf_mkdir (int *out,struct inode *dir,struct dentry *entry,umode_t mode);int fuse_bpf_rmdir (int *out,struct inode *dir,struct dentry *entry); +int fuse_bpf_rename2 (int *out,struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent, +unsigned int flags); +int fuse_bpf_rename (int *out,struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent);int fuse_bpf_unlink (int *out,struct inode *dir,struct dentry *entry);int fuse_bpf_release (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_releasedir (int *out,struct inode *inode,struct fuse_file *ff);
@@ -1486,6 +1491,19 @@ static inline int fuse_bpf_rmdir(int *out, struct inode *dir, struct dentry *entreturn 0 ; } +static inline int fuse_bpf_rename2 (int *out,struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent, +unsigned int flags) +{ +return 0 ; +} + +static inline int fuse_bpf_rename (int *out,struct inode *olddir,struct dentry *oldent, +struct inode *newdir,struct dentry *newent) +{ +return 0 ; +} +static inline int fuse_bpf_unlink (int *out,struct inode *dir,struct dentry *entry) {return 0 ;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 17/36 fuse-bpf: Add attr support
In reply to Daniel RosenbergThis adds backing support for FUSE_GETATTR, FUSE_SETATTR, and FUSE_STATFS
--- fs/fuse/backing.c | 296 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 67 ++--------- fs/fuse/fuse_i.h | 102 ++++++++++++++++ fs/fuse/inode.c | 17 +-- 4 files changed, 412 insertions(+), 70 deletions(-)
fs/fuse/backing.c +296 -0
@@ -2054,6 +2054,302 @@ int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry) dir, entry); } +struct fuse_getattr_args { +struct fuse_getattr_in in; +struct fuse_attr_out out; +}; + +static int fuse_getattr_initialize_in (struct bpf_fuse_args *fa,struct fuse_getattr_args *args, +const struct dentry *entry,struct kstat *stat, +u32 request_mask,unsigned int flags) +{ + args->in = (struct fuse_getattr_in ) { + .getattr_flags = flags, + .fh =-1 ,/* TODO is this OK? */ + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (entry->d_inode), + .opcode =FUSE_GETATTR , + }, + .in_numargs =1 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + }; + +return 0 ; +} + +static int fuse_getattr_initialize_out (struct bpf_fuse_args *fa,struct fuse_getattr_args *args, +const struct dentry *entry,struct kstat *stat, +u32 request_mask,unsigned int flags) +{ + args->out = (struct fuse_attr_out ) {0 }; + + fa->out_numargs =1 ; + fa->out_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->out), + .value = &args->out, + }; + +return 0 ; +} + +/* TODO: unify with overlayfs */ +static inline int fuse_do_getattr (const struct path *path,struct kstat *stat, +u32 request_mask,unsigned int flags) +{ +if (flags &AT_GETATTR_NOSEC ) +return vfs_getattr_nosec (path, stat, request_mask, flags); +return vfs_getattr (path, stat, request_mask, flags); +} + +static int fuse_getattr_backing (struct bpf_fuse_args *fa,int *out, +const struct dentry *entry,struct kstat *stat, +u32 request_mask,unsigned int flags) +{ +struct path *backing_path = &get_fuse_dentry (entry)->backing_path; +struct inode *backing_inode = backing_path->dentry->d_inode; +struct fuse_attr_out *fao = fa->out_args[0 ].value; +struct kstat tmp; + +if (!stat) + stat = &tmp; + + *out =fuse_do_getattr (backing_path, stat, request_mask, flags); + +if (!*out) +fuse_stat_to_attr (get_fuse_conn (entry->d_inode), backing_inode, + stat, &fao->attr); + +return 0 ; +} + +static int finalize_attr (struct inode *inode,struct fuse_attr_out *outarg, +u64 attr_version,struct kstat *stat) +{ +int err =0 ; + +if (fuse_invalid_attr (&outarg->attr) || + ((inode->i_mode ^ outarg->attr.mode) &S_IFMT )) { +fuse_make_bad (inode); + err = -EIO ; + }else { +fuse_change_attributes (inode, &outarg->attr,NULL , +ATTR_TIMEOUT (outarg), attr_version); +if (stat) +fuse_fillattr (inode, &outarg->attr, stat); + } +return err; +} + +static int fuse_getattr_finalize (struct bpf_fuse_args *fa,int *out, +const struct dentry *entry,struct kstat *stat, +u32 request_mask,unsigned int flags) +{ +struct fuse_attr_out *outarg = fa->out_args[0 ].value; +struct inode *inode = entry->d_inode; +u64 attr_version =fuse_get_attr_version (get_fuse_mount (inode)->fc); + +/* TODO: Ensure this doesn't happen if we had an error getting attrs in +* backing. +*/ + *out =finalize_attr (inode, outarg, attr_version, stat); +return 0 ; +} + +int fuse_bpf_getattr (int *out,struct inode *inode,const struct dentry *entry,struct kstat *stat, +u32 request_mask,unsigned int flags) +{ + return bpf_fuse_backing(inode, struct fuse_getattr_args, out, + fuse_getattr_initialize_in, fuse_getattr_initialize_out, + fuse_getattr_backing, fuse_getattr_finalize, + entry, stat, request_mask, flags); +} + +static void fattr_to_iattr (struct fuse_conn *fc, +const struct fuse_setattr_in *arg, +struct iattr *iattr) +{ +unsigned int fvalid = arg->valid; + +if (fvalid &FATTR_MODE ) + iattr->ia_valid |=ATTR_MODE , iattr->ia_mode = arg->mode; +if (fvalid &FATTR_UID ) { + iattr->ia_valid |=ATTR_UID ; + iattr->ia_uid =make_kuid (fc->user_ns, arg->uid); + } +if (fvalid &FATTR_GID ) { + iattr->ia_valid |=ATTR_GID ; + iattr->ia_gid =make_kgid (fc->user_ns, arg->gid); + } +if (fvalid &FATTR_SIZE ) + iattr->ia_valid |=ATTR_SIZE , iattr->ia_size = arg->size; +if (fvalid &FATTR_ATIME ) { + iattr->ia_valid |=ATTR_ATIME ; + iattr->ia_atime.tv_sec = arg->atime; + iattr->ia_atime.tv_nsec = arg->atimensec; +if (!(fvalid &FATTR_ATIME_NOW )) + iattr->ia_valid |=ATTR_ATIME_SET ; + } +if (fvalid &FATTR_MTIME ) { + iattr->ia_valid |=ATTR_MTIME ; + iattr->ia_mtime.tv_sec = arg->mtime; + iattr->ia_mtime.tv_nsec = arg->mtimensec; +if (!(fvalid &FATTR_MTIME_NOW )) + iattr->ia_valid |=ATTR_MTIME_SET ; + } +if (fvalid &FATTR_CTIME ) { + iattr->ia_valid |=ATTR_CTIME ; + iattr->ia_ctime.tv_sec = arg->ctime; + iattr->ia_ctime.tv_nsec = arg->ctimensec; + } +} + +struct fuse_setattr_args { +struct fuse_setattr_in in; +struct fuse_attr_out out; +}; + +static int fuse_setattr_initialize_in (struct bpf_fuse_args *fa,struct fuse_setattr_args *args, +struct dentry *dentry,struct iattr *attr,struct file *file) +{ +struct fuse_conn *fc =get_fuse_conn (dentry->d_inode); + + *args = (struct fuse_setattr_args ) {0 }; +iattr_to_fattr (fc, attr, &args->in, true); + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .opcode =FUSE_SETATTR , + .nodeid =get_node_id (dentry->d_inode), + }, + .in_numargs =1 , + .in_args[0 ].size =sizeof (args->in), + .in_args[0 ].value = &args->in, + }; + +return 0 ; +} + +static int fuse_setattr_initialize_out (struct bpf_fuse_args *fa,struct fuse_setattr_args *args, +struct dentry *dentry,struct iattr *attr,struct file *file) +{ + fa->out_numargs =1 ; + fa->out_args[0 ].size =sizeof (args->out); + fa->out_args[0 ].value = &args->out; + +return 0 ; +} + +static int fuse_setattr_backing (struct bpf_fuse_args *fa,int *out, +struct dentry *dentry,struct iattr *attr,struct file *file) +{ +struct fuse_conn *fc =get_fuse_conn (dentry->d_inode); +const struct fuse_setattr_in *fsi = fa->in_args[0 ].value; +struct iattr new_attr = {0 }; +struct path *backing_path = &get_fuse_dentry (dentry)->backing_path; + +fattr_to_iattr (fc, fsi, &new_attr); +/* TODO: Some info doesn't get saved by the attr->fattr->attr transition +* When we actually allow the bpf to change these, we may have to consider +* the extra flags more, or pass more info into the bpf. Until then we can +* keep everything except for ATTR_FILE, since we'd need a file on the +* lower fs. For what it's worth, neither f2fs nor ext4 make use of that +* even if it is present. +*/ + new_attr.ia_valid = attr->ia_valid & ~ATTR_FILE ; +inode_lock (d_inode (backing_path->dentry)); + *out =notify_change (&nop_mnt_idmap, backing_path->dentry, &new_attr, +NULL ); +inode_unlock (d_inode (backing_path->dentry)); + +if (*out ==0 && (new_attr.ia_valid &ATTR_SIZE )) +i_size_write (dentry->d_inode, new_attr.ia_size); +return 0 ; +} + +static int fuse_setattr_finalize (struct bpf_fuse_args *fa,int *out, +struct dentry *dentry,struct iattr *attr,struct file *file) +{ +return 0 ; +} + +int fuse_bpf_setattr (int *out,struct inode *inode,struct dentry *dentry,struct iattr *attr,struct file *file) +{ + return bpf_fuse_backing(inode, struct fuse_setattr_args, out, + fuse_setattr_initialize_in, fuse_setattr_initialize_out, + fuse_setattr_backing, fuse_setattr_finalize, + dentry, attr, file); +} + +static int fuse_statfs_initialize_in (struct bpf_fuse_args *fa,struct fuse_statfs_out *out, +struct dentry *dentry,struct kstatfs *buf) +{ + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (d_inode (dentry)), + .opcode =FUSE_STATFS , + }, + }; + +return 0 ; +} + +static int fuse_statfs_initialize_out (struct bpf_fuse_args *fa,struct fuse_statfs_out *out, +struct dentry *dentry,struct kstatfs *buf) +{ + *out = (struct fuse_statfs_out ) {0 }; + + fa->out_numargs =1 ; + fa->out_args[0 ].size =sizeof (*out); + fa->out_args[0 ].value = out; + +return 0 ; +} + +static int fuse_statfs_backing (struct bpf_fuse_args *fa,int *out, +struct dentry *dentry,struct kstatfs *buf) +{ +struct path backing_path; +struct fuse_statfs_out *fso = fa->out_args[0 ].value; + + *out =0 ; +get_fuse_backing_path (dentry, &backing_path); +if (!backing_path.dentry) +return -EBADF ; + *out =vfs_statfs (&backing_path, buf); +path_put (&backing_path); + buf->f_type =FUSE_SUPER_MAGIC ; + +//TODO Provide postfilter opportunity to modify +if (!*out) +convert_statfs_to_fuse (&fso->st, buf); + +return 0 ; +} + +static int fuse_statfs_finalize (struct bpf_fuse_args *fa,int *out, +struct dentry *dentry,struct kstatfs *buf) +{ +struct fuse_statfs_out *fso = fa->out_args[0 ].value; + +if (!fa->info.error_in) +convert_fuse_statfs (buf, &fso->st); +return 0 ; +} + +int fuse_bpf_statfs (int *out,struct inode *inode,struct dentry *dentry,struct kstatfs *buf) +{ + return bpf_fuse_backing(dentry->d_inode, struct fuse_statfs_out, out, + fuse_statfs_initialize_in, fuse_statfs_initialize_out, + fuse_statfs_backing, fuse_statfs_finalize, + dentry, buf); +} +struct fuse_read_args {struct fuse_read_in in;struct fuse_read_out out;
fs/fuse/dir.c +11 -56
115 lines not on this page · raw message
fs/fuse/fuse_i.h +102 -0
120 lines not on this page · raw message
fs/fuse/inode.c +3 -14
@@ -696,20 +696,6 @@ static void fuse_send_destroy(struct fuse_mount *fm) } } -static void convert_fuse_statfs (struct kstatfs *stbuf,struct fuse_kstatfs *attr) -{ - stbuf->f_type =FUSE_SUPER_MAGIC ; - stbuf->f_bsize = attr->bsize; - stbuf->f_frsize = attr->frsize; - stbuf->f_blocks = attr->blocks; - stbuf->f_bfree = attr->bfree; - stbuf->f_bavail = attr->bavail; - stbuf->f_files = attr->files; - stbuf->f_ffree = attr->ffree; - stbuf->f_namelen = attr->namelen; -/* fsid is left zero */ -} -static int fuse_statfs (struct dentry *dentry,struct kstatfs *buf) {struct super_block *sb = dentry->d_sb;
@@ -723,6 +709,9 @@ static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf)return 0 ; } +if (fuse_bpf_statfs (&err, dentry->d_inode, dentry, buf)) +return err; +memset (&outarg,0 ,sizeof (outarg)); args.in_numargs =0 ; args.opcode =FUSE_STATFS ;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 18/36 fuse-bpf: Add support for FUSE_COPY_FILE_RANGE
In reply to Daniel RosenbergThis adds backing support for FUSE_COPY_FILE_RANGE
--- fs/fuse/backing.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/file.c | 4 +++ fs/fuse/fuse_i.h | 10 ++++++ 3 files changed, 101 insertions(+)
fs/fuse/backing.c +87 -0
@@ -11,6 +11,7 @@#include <linux/file.h> #include <linux/fs_stack.h> #include <linux/namei.h> +#include <linux/splice.h> #include <linux/uio.h> /*
@@ -778,6 +779,92 @@ int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *file, loff_t o file, offset, whence); } +struct fuse_copy_file_range_args { +struct fuse_copy_file_range_in in; +struct fuse_write_out out; +}; + +static int fuse_copy_file_range_initialize_in (struct bpf_fuse_args *fa, +struct fuse_copy_file_range_args *args, +struct file *file_in,loff_t pos_in,struct file *file_out, +loff_t pos_out,size_t len,unsigned int flags) +{ +struct fuse_file *fuse_file_in = file_in->private_data; +struct fuse_file *fuse_file_out = file_out->private_data; + + args->in = (struct fuse_copy_file_range_in ) { + .fh_in = fuse_file_in->fh, + .off_in = pos_in, + .nodeid_out = fuse_file_out->nodeid, + .fh_out = fuse_file_out->fh, + .off_out = pos_out, + .len = len, + .flags = flags, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (file_in->f_inode), + .opcode =FUSE_COPY_FILE_RANGE , + }, + .in_numargs =1 , + .in_args[0 ].size =sizeof (args->in), + .in_args[0 ].value = &args->in, + }; + +return 0 ; +} + +static int fuse_copy_file_range_initialize_out (struct bpf_fuse_args *fa, +struct fuse_copy_file_range_args *args, +struct file *file_in,loff_t pos_in,struct file *file_out, +loff_t pos_out,size_t len,unsigned int flags) +{ + fa->out_numargs =1 ; + fa->out_args[0 ].size =sizeof (args->out); + fa->out_args[0 ].value = &args->out; + +return 0 ; +} + +static int fuse_copy_file_range_backing (struct bpf_fuse_args *fa,ssize_t *out,struct file *file_in, +loff_t pos_in,struct file *file_out,loff_t pos_out,size_t len, +unsigned int flags) +{ +const struct fuse_copy_file_range_in *fci = fa->in_args[0 ].value; +struct fuse_file *fuse_file_in = file_in->private_data; +struct file *backing_file_in = fuse_file_in->backing_file; +struct fuse_file *fuse_file_out = file_out->private_data; +struct file *backing_file_out = fuse_file_out->backing_file; + +/* TODO: Handle changing of in/out files */ +if (backing_file_out) + *out =vfs_copy_file_range (backing_file_in, fci->off_in, backing_file_out, + fci->off_out, fci->len, fci->flags); +else + *out =splice_copy_file_range (file_in, pos_in, file_out, pos_out, len); +return 0 ; +} + +static int fuse_copy_file_range_finalize (struct bpf_fuse_args *fa,ssize_t *out,struct file *file_in, +loff_t pos_in,struct file *file_out,loff_t pos_out,size_t len, +unsigned int flags) +{ +return 0 ; +} + +int fuse_bpf_copy_file_range (ssize_t *out,struct inode *inode,struct file *file_in, +loff_t pos_in,struct file *file_out,loff_t pos_out,size_t len, +unsigned int flags) +{ + return bpf_fuse_backing(inode, struct fuse_copy_file_range_args, out, + fuse_copy_file_range_initialize_in, + fuse_copy_file_range_initialize_out, + fuse_copy_file_range_backing, + fuse_copy_file_range_finalize, + file_in, pos_in, file_out, pos_out, len, flags); +} +static int fuse_fsync_initialize_in (struct bpf_fuse_args *fa,struct fuse_fsync_in *in,struct file *file,loff_t start,loff_t end,int datasync) {
fs/fuse/file.c +4 -0
@@ -3168,6 +3168,10 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,bool is_unstable = (!fc->writeback_cache) && ((pos_out + len) > inode_out->i_size); +if (fuse_bpf_copy_file_range (&err,file_inode (file_in), file_in, pos_in, + file_out, pos_out, len, flags)) +return err; +if (fc->no_copy_file_range)return -EOPNOTSUPP ;
fs/fuse/fuse_i.h +10 -0
@@ -1454,6 +1454,9 @@ int fuse_bpf_release(int *out, struct inode *inode, struct fuse_file *ff);int fuse_bpf_releasedir (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_flush (int *out,struct inode *inode,struct file *file,fl_owner_t id);int fuse_bpf_lseek (loff_t *out,struct inode *inode,struct file *file,loff_t offset,int whence); +int fuse_bpf_copy_file_range (ssize_t *out,struct inode *inode,struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +size_t len,unsigned int flags);int fuse_bpf_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync);int fuse_bpf_dir_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync);int fuse_bpf_file_read_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *to);
@@ -1533,6 +1536,13 @@ static inline int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *return 0 ; } +static inline int fuse_bpf_copy_file_range (ssize_t *out,struct inode *inode,struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +size_t len,unsigned int flags) +{ +return 0 ; +} +static inline int fuse_bpf_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync) {return 0 ;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 19/36 fuse-bpf: Add xattr support
In reply to Daniel RosenbergThis adds support for FUSE_GETXATTR, FUSE_LISTXATTR, FUSE_SETXATTR, and FUSE_REMOVEXATTR
--- fs/fuse/backing.c | 349 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/fuse_i.h | 30 ++++ fs/fuse/xattr.c | 18 +++ 3 files changed, 397 insertions(+)
fs/fuse/backing.c +349 -0
@@ -959,6 +959,355 @@ int fuse_bpf_dir_fsync(int *out, struct inode *inode, struct file *file, loff_t file, start, end, datasync); } +struct fuse_getxattr_args { +struct fuse_getxattr_in in; +struct fuse_buffer name; +struct fuse_buffer value; +struct fuse_getxattr_out out; +}; + +static int fuse_getxattr_initialize_in (struct bpf_fuse_args *fa, +struct fuse_getxattr_args *args, +struct dentry *dentry,const char *name,void *value, +size_t size) +{ + *args = (struct fuse_getxattr_args ) { + .in.size = size, + .name = (struct fuse_buffer ) { + .data = (void *) name, + .size =strlen (name) +1 , + .max_size =XATTR_NAME_MAX +1 , + .flags =BPF_FUSE_MUST_ALLOCATE |BPF_FUSE_VARIABLE_SIZE , + }, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_fuse_inode (dentry->d_inode)->nodeid, + .opcode =FUSE_GETXATTR , + }, + .in_numargs =2 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + .in_args[1 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->name, + }, + }; + +return 0 ; +} + +static int fuse_getxattr_initialize_out (struct bpf_fuse_args *fa, +struct fuse_getxattr_args *args, +struct dentry *dentry,const char *name,void *value, +size_t size) +{ + fa->flags = size ?FUSE_BPF_OUT_ARGVAR :0 ; + fa->out_numargs =1 ; +if (size) { + args->value = (struct fuse_buffer ) { + .data = (void *) value, + .size = size, + .alloc_size = size, + .max_size = size, + .flags =BPF_FUSE_VARIABLE_SIZE , + }; + fa->out_args[0 ].is_buffer = true; + fa->out_args[0 ].buffer = &args->value; + }else { + fa->out_args[0 ].size =sizeof (args->out); + fa->out_args[0 ].value = &args->out; + } +return 0 ; +} + +static int fuse_getxattr_backing (struct bpf_fuse_args *fa,int *out, +struct dentry *dentry,const char *name,void *value, +size_t size) +{ +ssize_t ret; + +if (fa->in_args[1 ].buffer->flags &BPF_FUSE_MODIFIED ) { +// Ensure bpf provided string is null terminated +char *new_name = fa->in_args[1 ].buffer->data; + new_name[fa->in_args[1 ].buffer->size -1 ] =0 ; + } + ret =vfs_getxattr (&nop_mnt_idmap, +get_fuse_dentry (dentry)->backing_path.dentry, + fa->in_args[1 ].buffer->data, value, size); + +if (fa->flags &FUSE_BPF_OUT_ARGVAR ) + fa->out_args[0 ].buffer->size = ret; +else + ((struct fuse_getxattr_out *)fa->out_args[0 ].value)->size = ret; + +return 0 ; +} + +static int fuse_getxattr_finalize (struct bpf_fuse_args *fa,int *out, +struct dentry *dentry,const char *name,void *value, +size_t size) +{ +struct fuse_getxattr_out *fgo; + +if (fa->flags &FUSE_BPF_OUT_ARGVAR ) { + *out = fa->out_args[0 ].buffer->size; +return 0 ; + } + + fgo = fa->out_args[0 ].value; + + *out = fgo->size; +return 0 ; +} + +int fuse_bpf_getxattr (int *out,struct inode *inode,struct dentry *dentry,const char *name, +void *value,size_t size) +{ + return bpf_fuse_backing(inode, struct fuse_getxattr_args, out, + fuse_getxattr_initialize_in, fuse_getxattr_initialize_out, + fuse_getxattr_backing, fuse_getxattr_finalize, + dentry, name, value, size); +} + +static int fuse_listxattr_initialize_in (struct bpf_fuse_args *fa, +struct fuse_getxattr_args *args, +struct dentry *dentry,char *list,size_t size) +{ + *args = (struct fuse_getxattr_args ) { + .in.size = size, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_fuse_inode (dentry->d_inode)->nodeid, + .opcode =FUSE_LISTXATTR , + }, + .in_numargs =1 , + .in_args[0 ] = + (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + }; + +return 0 ; +} + +static int fuse_listxattr_initialize_out (struct bpf_fuse_args *fa, +struct fuse_getxattr_args *args, +struct dentry *dentry,char *list,size_t size) +{ + fa->out_numargs =1 ; + +if (size) { + args->value = (struct fuse_buffer ) { + .data = list, + .size = size, + .alloc_size = size, + .max_size = size, + .flags =BPF_FUSE_VARIABLE_SIZE , + }; + fa->flags =FUSE_BPF_OUT_ARGVAR ; + fa->out_args[0 ].is_buffer = true; + fa->out_args[0 ].buffer = &args->value; + }else { + fa->out_args[0 ].size =sizeof (args->out); + fa->out_args[0 ].value = &args->out; + } +return 0 ; +} + +static int fuse_listxattr_backing (struct bpf_fuse_args *fa,ssize_t *out,struct dentry *dentry, +char *list,size_t size) +{ + *out =vfs_listxattr (get_fuse_dentry (dentry)->backing_path.dentry, list, size); + +if (*out <0 ) +return *out; + +if (fa->flags &FUSE_BPF_OUT_ARGVAR ) + fa->out_args[0 ].buffer->size = *out; +else + ((struct fuse_getxattr_out *)fa->out_args[0 ].value)->size = *out; + +return 0 ; +} + +static int fuse_listxattr_finalize (struct bpf_fuse_args *fa,ssize_t *out,struct dentry *dentry, +char *list,size_t size) +{ +struct fuse_getxattr_out *fgo; + +if (fa->info.error_in) +return 0 ; + +if (fa->flags &FUSE_BPF_OUT_ARGVAR ) { + *out = fa->out_args[0 ].buffer->size; +return 0 ; + } + + fgo = fa->out_args[0 ].value; + *out = fgo->size; +return 0 ; +} + +int fuse_bpf_listxattr (ssize_t *out,struct inode *inode,struct dentry *dentry, +char *list,size_t size) +{ + return bpf_fuse_backing(inode, struct fuse_getxattr_args, out, + fuse_listxattr_initialize_in, fuse_listxattr_initialize_out, + fuse_listxattr_backing, fuse_listxattr_finalize, + dentry, list, size); +} + +struct fuse_setxattr_args { +struct fuse_setxattr_in in; +struct fuse_buffer name; +struct fuse_buffer value; +}; + +static int fuse_setxattr_initialize_in (struct bpf_fuse_args *fa, +struct fuse_setxattr_args *args, +struct dentry *dentry,const char *name, +const void *value,size_t size,int flags) +{ + *args = (struct fuse_setxattr_args ) { + .in = (struct fuse_setxattr_in ) { + .size = size, + .flags = flags, + }, + .name = (struct fuse_buffer ) { + .data = (void *) name, + .size =strlen (name) +1 , + .max_size =XATTR_NAME_MAX +1 , + .flags =BPF_FUSE_VARIABLE_SIZE |BPF_FUSE_MUST_ALLOCATE , + }, + .value =(struct fuse_buffer ) { + .data = (void *) value, + .size = size, + .max_size =XATTR_SIZE_MAX , + .flags =BPF_FUSE_VARIABLE_SIZE |BPF_FUSE_MUST_ALLOCATE , + }, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_fuse_inode (dentry->d_inode)->nodeid, + .opcode =FUSE_SETXATTR , + }, + .in_numargs =3 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + .in_args[1 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->name, + }, + .in_args[2 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->value, + }, + }; + +return 0 ; +} + +static int fuse_setxattr_initialize_out (struct bpf_fuse_args *fa, +struct fuse_setxattr_args *args, +struct dentry *dentry,const char *name, +const void *value,size_t size,int flags) +{ +return 0 ; +} + +static int fuse_setxattr_backing (struct bpf_fuse_args *fa,int *out,struct dentry *dentry, +const char *name,const void *value,size_t size, +int flags) +{ +// TODO Ensure we actually use filter values + *out =vfs_setxattr (&nop_mnt_idmap, +get_fuse_dentry (dentry)->backing_path.dentry, name, + value, size, flags); +return 0 ; +} + +static int fuse_setxattr_finalize (struct bpf_fuse_args *fa,int *out,struct dentry *dentry, +const char *name,const void *value,size_t size, +int flags) +{ +return 0 ; +} + +int fuse_bpf_setxattr (int *out,struct inode *inode,struct dentry *dentry, +const char *name,const void *value,size_t size,int flags) +{ + return bpf_fuse_backing(inode, struct fuse_setxattr_args, out, + fuse_setxattr_initialize_in, fuse_setxattr_initialize_out, + fuse_setxattr_backing, fuse_setxattr_finalize, + dentry, name, value, size, flags); +} + +static int fuse_removexattr_initialize_in (struct bpf_fuse_args *fa, +struct fuse_buffer *in, +struct dentry *dentry,const char *name) +{ + *in = (struct fuse_buffer ) { + .data = (void *) name, + .size =strlen (name) +1 , + .max_size =XATTR_NAME_MAX +1 , + .flags =BPF_FUSE_VARIABLE_SIZE |BPF_FUSE_MUST_ALLOCATE , + }; + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_fuse_inode (dentry->d_inode)->nodeid, + .opcode =FUSE_REMOVEXATTR , + }, + .in_numargs =1 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = in, + }, + }; + +return 0 ; +} + +static int fuse_removexattr_initialize_out (struct bpf_fuse_args *fa, +struct fuse_buffer *in, +struct dentry *dentry,const char *name) +{ +return 0 ; +} + +static int fuse_removexattr_backing (struct bpf_fuse_args *fa,int *out, +struct dentry *dentry,const char *name) +{ +struct path *backing_path = &get_fuse_dentry (dentry)->backing_path; + +/* TODO account for changes of the name by prefilter */ + *out =vfs_removexattr (&nop_mnt_idmap, backing_path->dentry, name); +return 0 ; +} + +static int fuse_removexattr_finalize (struct bpf_fuse_args *fa,int *out, +struct dentry *dentry,const char *name) +{ +return 0 ; +} + +int fuse_bpf_removexattr (int *out,struct inode *inode,struct dentry *dentry,const char *name) +{ + return bpf_fuse_backing(inode, struct fuse_buffer, out, + fuse_removexattr_initialize_in, fuse_removexattr_initialize_out, + fuse_removexattr_backing, fuse_removexattr_finalize, + dentry, name); +} +static inline void fuse_bpf_aio_put (struct fuse_bpf_aio_req *aio_req) {if (refcount_dec_and_test (&aio_req->ref))
fs/fuse/fuse_i.h +30 -0
@@ -1459,6 +1459,13 @@ int fuse_bpf_copy_file_range(ssize_t *out, struct inode *inode, struct file *fil size_t len, unsigned int flags);int fuse_bpf_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync);int fuse_bpf_dir_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync); +int fuse_bpf_getxattr (int *out,struct inode *inode,struct dentry *dentry, +const char *name,void *value,size_t size); +int fuse_bpf_listxattr (ssize_t *out,struct inode *inode,struct dentry *dentry,char *list,size_t size); +int fuse_bpf_setxattr (int *out,struct inode *inode,struct dentry *dentry, +const char *name,const void *value,size_t size, +int flags); +int fuse_bpf_removexattr (int *out,struct inode *inode,struct dentry *dentry,const char *name);int fuse_bpf_file_read_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *to);int fuse_bpf_file_write_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *from);int fuse_bpf_file_fallocate (int *out,struct inode *inode,struct file *file,int mode,loff_t offset,loff_t length);
@@ -1553,6 +1560,29 @@ static inline int fuse_bpf_dir_fsync(int *out, struct inode *inode, struct filereturn 0 ; } +static inline int fuse_bpf_getxattr (int *out,struct inode *inode,struct dentry *dentry, +const char *name,void *value,size_t size) +{ +return 0 ; +} + +static inline int fuse_bpf_listxattr (ssize_t *out,struct inode *inode,struct dentry *dentry,char *list,size_t size) +{ +return 0 ; +} + +static inline int fuse_bpf_setxattr (int *out,struct inode *inode,struct dentry *dentry, +const char *name,const void *value,size_t size, +int flags) +{ +return 0 ; +} + +static inline int fuse_bpf_removexattr (int *out,struct inode *inode,struct dentry *dentry,const char *name) +{ +return 0 ; +} +static inline int fuse_bpf_file_read_iter (ssize_t *out,struct inode *inode,struct kiocb *iocb,struct iov_iter *to) {return 0 ;
fs/fuse/xattr.c +18 -0
@@ -118,6 +118,9 @@ ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)if (fuse_is_bad (inode))return -EIO ; +if (fuse_bpf_listxattr (&ret, inode, entry, list, size)) +return ret; +if (!fuse_allow_current_process (fm->fc))return -EACCES ;
@@ -182,9 +185,14 @@ static int fuse_xattr_get(const struct xattr_handler *handler, struct dentry *dentry, struct inode *inode, const char *name, void *value, size_t size) { + int err; +if (fuse_is_bad (inode))return -EIO ; +if (fuse_bpf_getxattr (&err, inode, dentry, name, value, size)) +return err; +return fuse_getxattr (inode, name, value, size); }
@@ -194,9 +202,19 @@ static int fuse_xattr_set(const struct xattr_handler *handler, const char *name, const void *value, size_t size, int flags) { + int err; +bool handled; +if (fuse_is_bad (inode))return -EIO ; +if (value) + handled =fuse_bpf_setxattr (&err, inode, dentry, name, value, size, flags); +else + handled =fuse_bpf_removexattr (&err, inode, dentry, name); +if (handled) +return err; +if (!value)return fuse_removexattr (inode, name);
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 20/36 fuse-bpf: Add symlink/link support
In reply to Daniel RosenbergThis adds backing support for FUSE_LINK, FUSE_READLINK, and FUSE_SYMLINK
--- fs/fuse/backing.c | 327 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 11 ++ fs/fuse/fuse_i.h | 20 +++ 3 files changed, 358 insertions(+)
fs/fuse/backing.c +327 -0
@@ -2490,6 +2490,125 @@ int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry) dir, entry); } +struct fuse_link_args { +struct fuse_link_in in; +struct fuse_buffer name; +}; + +static int fuse_link_initialize_in (struct bpf_fuse_args *fa,struct fuse_link_args *args, +struct dentry *entry,struct inode *dir, +struct dentry *newent) +{ +struct inode *src_inode = entry->d_inode; + + *args = (struct fuse_link_args ) { + .in = (struct fuse_link_in ) { + .oldnodeid =get_node_id (src_inode), + }, + .name = (struct fuse_buffer ) { + .data = (void *) newent->d_name.name, + .size = newent->d_name.len +1 , + .max_size =NAME_MAX +1 , + .flags =BPF_FUSE_VARIABLE_SIZE |BPF_FUSE_MUST_ALLOCATE , + }, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .opcode =FUSE_LINK , + }, + .in_numargs =2 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .size =sizeof (args->in), + .value = &args->in, + }, + .in_args[1 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->name, + }, + }; + +return 0 ; +} + +static int fuse_link_initialize_out (struct bpf_fuse_args *fa,struct fuse_link_args *args, +struct dentry *entry,struct inode *dir, +struct dentry *newent) +{ +return 0 ; +} + +static int fuse_link_backing (struct bpf_fuse_args *fa,int *out,struct dentry *entry, +struct inode *dir,struct dentry *newent) +{ +struct path backing_old_path; +struct path backing_new_path; +struct dentry *backing_dir_dentry; +struct inode *fuse_new_inode =NULL ; +struct fuse_inode *fuse_dir_inode =get_fuse_inode (dir); +struct inode *backing_dir_inode = fuse_dir_inode->backing_inode; + + *out =0 ; +get_fuse_backing_path (entry, &backing_old_path); +if (!backing_old_path.dentry) +return -EBADF ; + +get_fuse_backing_path (newent, &backing_new_path); +if (!backing_new_path.dentry) { + *out = -EBADF ; + goto err_dst_path; + } + + backing_dir_dentry =dget_parent (backing_new_path.dentry); + backing_dir_inode =d_inode (backing_dir_dentry); + +inode_lock_nested (backing_dir_inode,I_MUTEX_PARENT ); + *out =vfs_link (backing_old_path.dentry, &nop_mnt_idmap, + backing_dir_inode, backing_new_path.dentry,NULL ); +inode_unlock (backing_dir_inode); +if (*out) + goto out; + +if (d_really_is_negative (backing_new_path.dentry) || +unlikely (d_unhashed (backing_new_path.dentry))) { + *out = -EINVAL ; +/** +* TODO: overlayfs responds to this situation with a +* lookupOneLen. Should we do that too? +*/ + goto out; + } + + fuse_new_inode =fuse_iget_backing (dir->i_sb, fuse_dir_inode->nodeid, backing_dir_inode); +if (IS_ERR (fuse_new_inode)) { + *out =PTR_ERR (fuse_new_inode); + goto out; + } +d_instantiate (newent, fuse_new_inode); + +out: +dput (backing_dir_dentry); +path_put (&backing_new_path); +err_dst_path: +path_put (&backing_old_path); +return *out; +} + +static int fuse_link_finalize (struct bpf_fuse_args *fa,int *out,struct dentry *entry, +struct inode *dir,struct dentry *newent) +{ +return 0 ; +} + +int fuse_bpf_link (int *out,struct inode *inode,struct dentry *entry, +struct inode *newdir,struct dentry *newent) +{ + return bpf_fuse_backing(inode, struct fuse_link_args, out, + fuse_link_initialize_in, fuse_link_initialize_out, + fuse_link_backing, fuse_link_finalize, + entry, newdir, newent); +} +struct fuse_getattr_args {struct fuse_getattr_in in;struct fuse_attr_out out;
@@ -2786,6 +2905,214 @@ int fuse_bpf_statfs(int *out, struct inode *inode, struct dentry *dentry, struct dentry, buf); } +struct fuse_get_link_args { +struct fuse_buffer name; +struct fuse_buffer path; +}; + +static int fuse_get_link_initialize_in (struct bpf_fuse_args *fa,struct fuse_get_link_args *args, +struct inode *inode,struct dentry *dentry, +struct delayed_call *callback) +{ +/* +* TODO +* If we want to handle changing these things, we'll need to copy +* the lower fs's data into our own buffer, and provide our own callback +* to free that buffer. +* +* Pre could change the name we're looking at +* postfilter can change the name we return +* +* We ought to only make that buffer if it's been requested, so leaving +* this unimplemented for the moment +*/ + *args = (struct fuse_get_link_args ) { + .name = (struct fuse_buffer ) { + .data = (void *) dentry->d_name.name, + .size = dentry->d_name.len +1 , + .max_size =NAME_MAX +1 , + .flags =BPF_FUSE_VARIABLE_SIZE |BPF_FUSE_MUST_ALLOCATE , + }, + }; + + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .opcode =FUSE_READLINK , + .nodeid =get_node_id (inode), + }, + .in_numargs =1 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->name, + }, + }; + +return 0 ; +} + +static int fuse_get_link_initialize_out (struct bpf_fuse_args *fa,struct fuse_get_link_args *args, +struct inode *inode,struct dentry *dentry, +struct delayed_call *callback) +{ +// TODO +#if 0 + args->path = (struct fuse_buffer ) { + .data =NULL , + .size =0 , + .max_size =PATH_MAX , + .flags =BPF_FUSE_VARIABLE_SIZE |BPF_FUSE_MUST_ALLOCATE , + }; + fa->out_numargs =1 ; + fa->out_args[0 ].is_buffer = true; + fa->out_args[0 ].buffer = &args->path; +#endif + +return 0 ; +} + +static int fuse_get_link_backing (struct bpf_fuse_args *fa,const char **out, +struct inode *inode,struct dentry *dentry, +struct delayed_call *callback) +{ +struct path backing_path; + +if (!dentry) { + *out =ERR_PTR (-ECHILD ); +return PTR_ERR (*out); + } + +get_fuse_backing_path (dentry, &backing_path); +if (!backing_path.dentry) { + *out =ERR_PTR (-ECHILD ); +return PTR_ERR (*out); + } + +/* +* TODO: If we want to do our own thing, copy the data and then call the +* callback +*/ + *out =vfs_get_link (backing_path.dentry, callback); + +path_put (&backing_path); +return 0 ; +} + +static int fuse_get_link_finalize (struct bpf_fuse_args *fa,const char **out, +struct inode *inode,struct dentry *dentry, +struct delayed_call *callback) +{ +return 0 ; +} + +int fuse_bpf_get_link (const char **out,struct inode *inode,struct dentry *dentry, +struct delayed_call *callback) +{ + return bpf_fuse_backing(inode, struct fuse_get_link_args, out, + fuse_get_link_initialize_in, fuse_get_link_initialize_out, + fuse_get_link_backing, fuse_get_link_finalize, + inode, dentry, callback); +} + +struct fuse_symlink_args { +struct fuse_buffer name; +struct fuse_buffer path; +}; + +static int fuse_symlink_initialize_in (struct bpf_fuse_args *fa,struct fuse_symlink_args *args, +struct inode *dir,struct dentry *entry,const char *link,int len) +{ + *args = (struct fuse_symlink_args ) { + .name = (struct fuse_buffer ) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len +1 , + .flags =BPF_FUSE_IMMUTABLE , + }, + .path = (struct fuse_buffer ) { + .data = (void *) link, + .size = len, + .max_size =PATH_MAX , + .flags =BPF_FUSE_VARIABLE_SIZE |BPF_FUSE_MUST_ALLOCATE , + }, + }; + *fa = (struct bpf_fuse_args ) { + .info = (struct bpf_fuse_meta_info ) { + .nodeid =get_node_id (dir), + .opcode =FUSE_SYMLINK , + }, + .in_numargs =2 , + .in_args[0 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->name, + }, + .in_args[1 ] = (struct bpf_fuse_arg ) { + .is_buffer = true, + .buffer = &args->path, + }, + }; + +return 0 ; +} + +static int fuse_symlink_initialize_out (struct bpf_fuse_args *fa,struct fuse_symlink_args *args, +struct inode *dir,struct dentry *entry,const char *link,int len) +{ +return 0 ; +} + +static int fuse_symlink_backing (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry,const char *link,int len) +{ +struct fuse_inode *fuse_inode =get_fuse_inode (dir); +struct inode *backing_inode = fuse_inode->backing_inode; +struct path backing_path; +struct inode *inode =NULL ; + + *out =0 ; +//TODO Actually deal with changing the backing entry in symlink +get_fuse_backing_path (entry, &backing_path); +if (!backing_path.dentry) +return -EBADF ; + +inode_lock_nested (backing_inode,I_MUTEX_PARENT ); + *out =vfs_symlink (&nop_mnt_idmap, backing_inode, backing_path.dentry, + link); +inode_unlock (backing_inode); +if (*out) + goto out; +if (d_really_is_negative (backing_path.dentry) || +unlikely (d_unhashed (backing_path.dentry))) { + *out = -EINVAL ; +/** +* TODO: overlayfs responds to this situation with a +* lookupOneLen. Should we do that too? +*/ + goto out; + } + inode =fuse_iget_backing (dir->i_sb, fuse_inode->nodeid, backing_inode); +if (IS_ERR (inode)) { + *out =PTR_ERR (inode); + goto out; + } +d_instantiate (entry, inode); +out: +path_put (&backing_path); +return *out; +} + +static int fuse_symlink_finalize (struct bpf_fuse_args *fa,int *out, +struct inode *dir,struct dentry *entry,const char *link,int len) +{ +return 0 ; +} + +int fuse_bpf_symlink (int *out,struct inode *dir,struct dentry *entry,const char *link,int len) +{ + return bpf_fuse_backing(dir, struct fuse_symlink_args, out, + fuse_symlink_initialize_in, fuse_symlink_initialize_out, + fuse_symlink_backing, fuse_symlink_finalize, + dir, entry, link, len); +} +struct fuse_read_args {struct fuse_read_in in;struct fuse_read_out out;
fs/fuse/dir.c +11 -0
@@ -1033,6 +1033,10 @@ static int fuse_symlink(struct mnt_idmap *idmap, struct inode *dir,struct fuse_mount *fm =get_fuse_mount (dir);unsigned len =strlen (link) +1 ;FUSE_ARGS (args); +int err; + +if (fuse_bpf_symlink (&err, dir, entry, link, len)) +return err; args.opcode =FUSE_SYMLINK ; args.in_numargs =2 ;
@@ -1239,6 +1243,9 @@ static int fuse_link(struct dentry *entry, struct inode *newdir,struct fuse_mount *fm =get_fuse_mount (inode);FUSE_ARGS (args); +if (fuse_bpf_link (&err, inode, entry, newdir, newent)) +return err; +memset (&inarg,0 ,sizeof (inarg)); inarg.oldnodeid =get_node_id (inode); args.opcode =FUSE_LINK ;
@@ -1741,12 +1748,16 @@ static const char *fuse_get_link(struct dentry *dentry, struct inode *inode, {struct fuse_conn *fc =get_fuse_conn (inode);struct page *page; +const char *out =NULL ;int err; err = -EIO ;if (fuse_is_bad (inode)) goto out_err; +if (fuse_bpf_get_link (&out, inode, dentry, callback)) +return out; +if (fc->cache_symlinks)return page_get_link (dentry, inode, callback);
fs/fuse/fuse_i.h +20 -0
@@ -1450,6 +1450,7 @@ int fuse_bpf_rename2(int *out, struct inode *olddir, struct dentry *oldent,int fuse_bpf_rename (int *out,struct inode *olddir,struct dentry *oldent,struct inode *newdir,struct dentry *newent);int fuse_bpf_unlink (int *out,struct inode *dir,struct dentry *entry); +int fuse_bpf_link (int *out,struct inode *inode,struct dentry *entry,struct inode *dir,struct dentry *newent);int fuse_bpf_release (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_releasedir (int *out,struct inode *inode,struct fuse_file *ff);int fuse_bpf_flush (int *out,struct inode *inode,struct file *file,fl_owner_t id);
@@ -1474,6 +1475,9 @@ int fuse_bpf_getattr(int *out, struct inode *inode, const struct dentry *entry, u32 request_mask, unsigned int flags);int fuse_bpf_setattr (int *out,struct inode *inode,struct dentry *dentry,struct iattr *attr,struct file *file);int fuse_bpf_statfs (int *out,struct inode *inode,struct dentry *dentry,struct kstatfs *buf); +int fuse_bpf_get_link (const char **out,struct inode *inode,struct dentry *dentry, +struct delayed_call *callback); +int fuse_bpf_symlink (int *out,struct inode *dir,struct dentry *entry,const char *link,int len);int fuse_bpf_readdir (int *out,struct inode *inode,struct file *file,struct dir_context *ctx);int fuse_bpf_access (int *out,struct inode *inode,int mask);
@@ -1523,6 +1527,11 @@ static inline int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *enreturn 0 ; } +static inline int fuse_bpf_link (int *out,struct inode *inode,struct dentry *entry,struct inode *dir,struct dentry *newent) +{ +return 0 ; +} +static inline int fuse_bpf_release (int *out,struct inode *inode,struct file *file) {return 0 ;
@@ -1619,6 +1628,17 @@ static inline int fuse_bpf_statfs(int *out, struct inode *inode, struct dentry *return 0 ; } +static inline int fuse_bpf_get_link (const char **out,struct inode *inode,struct dentry *dentry, +struct delayed_call *callback) +{ +return 0 ; +} + +static inline int fuse_bpf_symlink (int *out,struct inode *dir,struct dentry *entry,const char *link,int len) +{ +return 0 ; +} +static inline int fuse_bpf_readdir (int *out,struct inode *inode,struct file *file,struct dir_context *ctx) {return 0 ;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 21/36 fuse-bpf: Add partial flock support
In reply to Daniel RosenbergThis adds passthrough support for flock on fuse-bpf files. It does not give any control via a bpf filter. The flock will act as though it was taken on the lower file.
see fuse_test -t32 (flock_test)
--- fs/fuse/backing.c | 15 +++++++++++++++ fs/fuse/file.c | 9 +++++++-- fs/fuse/fuse_i.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-)
fs/fuse/backing.c +15 -0
@@ -9,6 +9,7 @@#include <linux/bpf_fuse.h> #include <linux/fdtable.h> #include <linux/file.h> +#include <linux/filelock.h> #include <linux/fs_stack.h> #include <linux/namei.h> #include <linux/splice.h>
@@ -1586,6 +1587,20 @@ int fuse_bpf_file_write_iter(ssize_t *out, struct inode *inode, struct kiocb *io iocb, from); } +int fuse_file_flock_backing (struct file *file,int cmd,struct file_lock *fl) +{ +struct fuse_file *ff = file->private_data; +struct file *backing_file = ff->backing_file; +int error; + + fl->fl_file = backing_file; +if (backing_file->f_op->flock) + error = backing_file->f_op->flock (backing_file, cmd, fl); +else + error =locks_lock_file_wait (backing_file, fl); +return error; +} +ssize_t fuse_backing_mmap (struct file *file,struct vm_area_struct *vma) {int ret;
fs/fuse/file.c +7 -2
@@ -2676,13 +2676,18 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl) {struct inode *inode =file_inode (file);struct fuse_conn *fc =get_fuse_conn (inode); +struct fuse_file *ff = file->private_data;int err; +#ifdef CONFIG_FUSE_BPF +/* TODO - this is simply passthrough, not a proper BPF filter */ +if (ff->backing_file) +return fuse_file_flock_backing (file, cmd, fl); +#endif +if (fc->no_flock) { err =locks_lock_file_wait (file, fl); }else { -struct fuse_file *ff = file->private_data; -/* emulate flock with POSIX locks */ ff->flock = true; err =fuse_setlk (file, fl,1 );
fs/fuse/fuse_i.h +1 -0
@@ -1651,6 +1651,7 @@ static inline int fuse_bpf_access(int *out, struct inode *inode, int mask)#endif // CONFIG_FUSE_BPF +int fuse_file_flock_backing (struct file *file,int cmd,struct file_lock *fl);ssize_t fuse_backing_mmap (struct file *file,struct vm_area_struct *vma);int fuse_handle_backing (struct fuse_bpf_entry *fbe,struct path *backing_path);
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 22/36 fuse-bpf: Add partial ioctl support
In reply to Daniel RosenbergThis adds passthrough only support for ioctls with fuse-bpf. compat_ioctls will return -ENOTTY.
--- fs/fuse/backing.c | 13 +++++++++++++ fs/fuse/fuse_i.h | 2 ++ fs/fuse/ioctl.c | 9 +++++++++ 3 files changed, 24 insertions(+)
fs/fuse/backing.c +13 -0
@@ -1587,6 +1587,19 @@ int fuse_bpf_file_write_iter(ssize_t *out, struct inode *inode, struct kiocb *io iocb, from); } +long fuse_backing_ioctl (struct file *file,unsigned int command,unsigned long arg,int flags) +{ +struct fuse_file *ff = file->private_data; +long ret; + +if (flags &FUSE_IOCTL_COMPAT ) + ret = -ENOTTY ; +else + ret =vfs_ioctl (ff->backing_file, command, arg); + +return ret; +} +int fuse_file_flock_backing (struct file *file,int cmd,struct file_lock *fl) {struct fuse_file *ff = file->private_data;
fs/fuse/fuse_i.h +2 -0
@@ -1651,6 +1651,8 @@ static inline int fuse_bpf_access(int *out, struct inode *inode, int mask)#endif // CONFIG_FUSE_BPF +long fuse_backing_ioctl (struct file *file,unsigned int command,unsigned long arg,int flags); +int fuse_file_flock_backing (struct file *file,int cmd,struct file_lock *fl);ssize_t fuse_backing_mmap (struct file *file,struct vm_area_struct *vma);
fs/fuse/ioctl.c +9 -0
@@ -360,6 +360,15 @@ long fuse_ioctl_common(struct file *file, unsigned int cmd,if (fuse_is_bad (inode))return -EIO ; +#ifdef CONFIG_FUSE_BPF + { +struct fuse_file *ff = file->private_data; + +/* TODO - this is simply passthrough, not a proper BPF filter */ +if (ff->backing_file) +return fuse_backing_ioctl (file, cmd, arg, flags); + } +#endif return fuse_do_ioctl (file, cmd, arg, flags); }
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 23/36 fuse-bpf: allow mounting with no userspace daemon
In reply to Daniel RosenbergWhen using fuse-bpf in pure passthrough mode, we don't explicitly need a userspace daemon. This allows simple testing of the backing operations.
--- fs/fuse/fuse_i.h | 4 ++++ fs/fuse/inode.c | 25 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-)
fs/fuse/fuse_i.h +4 -0
@@ -586,6 +586,7 @@ struct fuse_fs_context { bool no_control:1; bool no_force_umount:1; bool legacy_opts_show:1; + bool no_daemon:1;enum fuse_dax_mode dax_mode;unsigned int max_read;unsigned int blksize;
@@ -873,6 +874,9 @@ struct fuse_conn {/* Is statx not implemented by fs? */ unsigned int no_statx:1; +/** BPF Only, no Daemon running */ + unsigned int no_daemon:1; +/** The number of requests waiting for completion */ atomic_t num_waiting;
fs/fuse/inode.c +19 -6
@@ -829,6 +829,7 @@ enum {OPT_MAX_READ ,OPT_BLKSIZE ,OPT_ROOT_DIR , +OPT_NO_DAEMON , OPT_ERR };
@@ -844,6 +845,7 @@ static const struct fs_parameter_spec fuse_fs_parameters[] = {fsparam_u32 ("blksize" ,OPT_BLKSIZE ),fsparam_string ("subtype" ,OPT_SUBTYPE ),fsparam_u32 ("root_dir" ,OPT_ROOT_DIR ), + fsparam_flag ("no_daemon", OPT_NO_DAEMON), {} };
@@ -933,6 +935,11 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)return invalfc (fsc,"Unable to open root directory" );break ; +case OPT_NO_DAEMON : + ctx->no_daemon = true; + ctx->fd_present = true; +break ; +default :return -EINVAL ; }
@@ -1506,7 +1513,7 @@ void fuse_send_init(struct fuse_mount *fm) ia->args.nocreds = true; ia->args.end = process_init_reply; -if (fuse_simple_background (fm, &ia->args,GFP_KERNEL ) !=0 ) +if (unlikely (fm->fc->no_daemon) ||fuse_simple_background (fm, &ia->args,GFP_KERNEL ) !=0 )process_init_reply (fm, &ia->args, -ENOTCONN ); }EXPORT_SYMBOL_GPL (fuse_send_init);
@@ -1798,6 +1805,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) fc->destroy = ctx->destroy; fc->no_control = ctx->no_control; fc->no_force_umount = ctx->no_force_umount; + fc->no_daemon = ctx->no_daemon; err = -ENOMEM ; root =fuse_get_root_inode (sb, ctx->rootmode, ctx->root_dir);
@@ -1844,7 +1852,7 @@ static int fuse_fill_super(struct super_block *sb, struct fs_context *fsc)struct fuse_fs_context *ctx = fsc->fs_private;int err; -if (!ctx->file || !ctx->rootmode_present || +if (!!ctx->file == ctx->no_daemon || !ctx->rootmode_present || !ctx->user_id_present || !ctx->group_id_present)return -EINVAL ;
@@ -1852,10 +1860,12 @@ static int fuse_fill_super(struct super_block *sb, struct fs_context *fsc)* Require mount to happen from the same user namespace which * opened /dev/fuse to prevent potential attacks. */ -if ((ctx->file->f_op != &fuse_dev_operations) || - (ctx->file->f_cred->user_ns != sb->s_user_ns)) -return -EINVAL ; - ctx->fudptr = &ctx->file->private_data; +if (ctx->file) { +if ((ctx->file->f_op != &fuse_dev_operations) || + (ctx->file->f_cred->user_ns != sb->s_user_ns)) +return -EINVAL ; + ctx->fudptr = &ctx->file->private_data; + } err =fuse_fill_super_common (sb, ctx);if (err)
@@ -1905,6 +1915,9 @@ static int fuse_get_tree(struct fs_context *fsc) fsc->s_fs_info = fm; +if (ctx->no_daemon) +return get_tree_nodev (fsc, fuse_fill_super);; +if (ctx->fd_present) ctx->file =fget (ctx->fd);
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 24/36 fuse-bpf: Add fuse-bpf constants
In reply to Daniel RosenbergThis adds constants that fuse_op programs will rely on for communicating what action fuse should take next.
--- include/uapi/linux/bpf.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/uapi/linux/bpf.h +12 -0
@@ -7461,4 +7461,16 @@ struct bpf_iter_num {__u64 __opaque[1 ]; } __attribute__((aligned(8))); +/* Return Codes for Fuse BPF struct_op programs */ +#define BPF_FUSE_CONTINUE 0 +#define BPF_FUSE_USER 1 +#define BPF_FUSE_USER_PREFILTER 2 +#define BPF_FUSE_POSTFILTER 3 +#define BPF_FUSE_USER_POSTFILTER 4 + +/* Op Code Filter values for BPF Programs */ +#define FUSE_OPCODE_FILTER 0x0ffff +#define FUSE_PREFILTER 0x10000 +#define FUSE_POSTFILTER 0x20000 +#endif /* _UAPI__LINUX_BPF_H__ */
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 25/36 bpf: Increase struct_op max members
In reply to Daniel RosenbergFuse bpf goes a bit past the '64' limit here.
This doubles the limit, although fuse-bpf currently uses 66.
--- include/linux/bpf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/bpf.h +1 -1
@@ -1636,7 +1636,7 @@ struct bpf_token {struct bpf_struct_ops_value ;struct btf_member ; -#define BPF_STRUCT_OPS_MAX_NR_MEMBERS 64 +#define BPF_STRUCT_OPS_MAX_NR_MEMBERS 128/** * struct bpf_struct_ops - A structure of callbacks allowing a subsystem to * define a BPF_MAP_TYPE_STRUCT_OPS map type composed
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 26/36 WIP: bpf: Add fuse_ops struct_op programs
In reply to Daniel RosenbergThis introduces a new struct_op type: fuse_ops. This program set provides pre and post filters to run around fuse-bpf calls that act directly on the lower filesystem.
The inputs are either fixed structures, or struct fuse_buffer's.
These programs are not permitted to make any changes to these fuse_buffers unless they create a dynptr wrapper using the supplied kfunc helpers.
Fuse_buffers maintain additional state information that FUSE uses to manage memory and determine if additional set up or checks are needed.
--- include/linux/bpf_fuse.h | 189 +++++++++++ kernel/bpf/Makefile | 4 + kernel/bpf/bpf_fuse.c | 716 +++++++++++++++++++++++++++++++++++++++ kernel/bpf/btf.c | 1 + kernel/bpf/verifier.c | 10 +- 5 files changed, 919 insertions(+), 1 deletion(-) create mode 100644 kernel/bpf/bpf_fuse.c
include/linux/bpf_fuse.h +189 -0
@@ -30,6 +30,8 @@ struct fuse_buffer {#define BPF_FUSE_MODIFIED (1 << 3) // The helper function allowed writes to the buffer#define BPF_FUSE_ALLOCATED (1 << 4) // The helper function allocated the buffer +extern void *bpf_fuse_get_writeable (struct fuse_buffer *arg,u64 size,bool copy); +/* * BPF Fuse Args *
@@ -81,4 +83,191 @@ static inline unsigned bpf_fuse_arg_size(const struct bpf_fuse_arg *arg)return arg->is_buffer ? arg->buffer->size : arg->size; } +struct fuse_ops { +uint32_t (*open_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_open_in *in); +uint32_t (*open_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_open_in *in, +struct fuse_open_out *out); + +uint32_t (*opendir_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_open_in *in); +uint32_t (*opendir_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_open_in *in, +struct fuse_open_out *out); + +uint32_t (*create_open_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_create_in *in,struct fuse_buffer *name); +uint32_t (*create_open_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_create_in *in,const struct fuse_buffer *name, +struct fuse_entry_out *entry_out,struct fuse_open_out *out); + +uint32_t (*release_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_release_in *in); +uint32_t (*release_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_release_in *in); + +uint32_t (*releasedir_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_release_in *in); +uint32_t (*releasedir_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_release_in *in); + +uint32_t (*flush_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_flush_in *in); +uint32_t (*flush_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_flush_in *in); + +uint32_t (*lseek_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_lseek_in *in); +uint32_t (*lseek_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_lseek_in *in, +struct fuse_lseek_out *out); + +uint32_t (*copy_file_range_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_copy_file_range_in *in); +uint32_t (*copy_file_range_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_copy_file_range_in *in, +struct fuse_write_out *out); + +uint32_t (*fsync_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_fsync_in *in); +uint32_t (*fsync_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_fsync_in *in); + +uint32_t (*dir_fsync_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_fsync_in *in); +uint32_t (*dir_fsync_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_fsync_in *in); + +uint32_t (*getxattr_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_getxattr_in *in,struct fuse_buffer *name); +// if in->size > 0, use value. If in->size == 0, use out. +uint32_t (*getxattr_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_getxattr_in *in,const struct fuse_buffer *name, +struct fuse_buffer *value,struct fuse_getxattr_out *out); + +uint32_t (*listxattr_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_getxattr_in *in); +// if in->size > 0, use value. If in->size == 0, use out. +uint32_t (*listxattr_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_getxattr_in *in, +struct fuse_buffer *value,struct fuse_getxattr_out *out); + +uint32_t (*setxattr_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_setxattr_in *in,struct fuse_buffer *name, +struct fuse_buffer *value); +uint32_t (*setxattr_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_setxattr_in *in,const struct fuse_buffer *name, +const struct fuse_buffer *value); + +uint32_t (*removexattr_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name); +uint32_t (*removexattr_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_buffer *name); + +/* Read and Write iter will likely undergo some sort of change/addition to handle changing +* the data buffer passed in/out. */ +uint32_t (*read_iter_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_read_in *in); +uint32_t (*read_iter_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_read_in *in, +struct fuse_read_iter_out *out); + +uint32_t (*write_iter_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_write_in *in); +uint32_t (*write_iter_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_write_in *in, +struct fuse_write_iter_out *out); + +uint32_t (*file_fallocate_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_fallocate_in *in); +uint32_t (*file_fallocate_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_fallocate_in *in); + +uint32_t (*lookup_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name); +uint32_t (*lookup_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_buffer *name, +struct fuse_entry_out *out,struct fuse_buffer *entries); + +uint32_t (*mknod_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_mknod_in *in,struct fuse_buffer *name); +uint32_t (*mknod_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_mknod_in *in,const struct fuse_buffer *name); + +uint32_t (*mkdir_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_mkdir_in *in,struct fuse_buffer *name); +uint32_t (*mkdir_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_mkdir_in *in,const struct fuse_buffer *name); + +uint32_t (*rmdir_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name); +uint32_t (*rmdir_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_buffer *name); + +uint32_t (*rename2_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_rename2_in *in,struct fuse_buffer *old_name, +struct fuse_buffer *new_name); +uint32_t (*rename2_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_rename2_in *in,const struct fuse_buffer *old_name, +const struct fuse_buffer *new_name); + +uint32_t (*rename_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_rename_in *in,struct fuse_buffer *old_name, +struct fuse_buffer *new_name); +uint32_t (*rename_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_rename_in *in,const struct fuse_buffer *old_name, +const struct fuse_buffer *new_name); + +uint32_t (*unlink_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name); +uint32_t (*unlink_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_buffer *name); + +uint32_t (*link_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_link_in *in,struct fuse_buffer *name); +uint32_t (*link_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_link_in *in,const struct fuse_buffer *name); + +uint32_t (*getattr_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_getattr_in *in); +uint32_t (*getattr_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_getattr_in *in, +struct fuse_attr_out *out); + +uint32_t (*setattr_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_setattr_in *in); +uint32_t (*setattr_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_setattr_in *in, +struct fuse_attr_out *out); + +uint32_t (*statfs_prefilter)(const struct bpf_fuse_meta_info *meta); +uint32_t (*statfs_postfilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_statfs_out *out); + +//TODO: This does not allow doing anything with path +uint32_t (*get_link_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name); +uint32_t (*get_link_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_buffer *name); + +uint32_t (*symlink_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name,struct fuse_buffer *path); +uint32_t (*symlink_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_buffer *name,const struct fuse_buffer *path); + +uint32_t (*readdir_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_read_in *in); +uint32_t (*readdir_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_read_in *in, +struct fuse_read_out *out,struct fuse_buffer *buffer); + +uint32_t (*access_prefilter)(const struct bpf_fuse_meta_info *meta, +struct fuse_access_in *in); +uint32_t (*access_postfilter)(const struct bpf_fuse_meta_info *meta, +const struct fuse_access_in *in); + +char name[BPF_FUSE_NAME_MAX ]; +}; +#endif /* _BPF_FUSE_H */
kernel/bpf/Makefile +4 -0
@@ -46,3 +46,7 @@ obj-$(CONFIG_BPF_PRELOAD) += preload/ obj-$(CONFIG_BPF_SYSCALL) += relo_core.o $(obj)/relo_core.o: $(srctree)/tools/lib/bpf/relo_core.c FORCE $(call if_changed_rule,cc_o_c) + +ifeq ($(CONFIG_FUSE_BPF),y) +obj-$(CONFIG_BPF_SYSCALL) += bpf_fuse.o +endif
kernel/bpf/bpf_fuse.c new file +716 -0
716 lines not on this page · raw message
kernel/bpf/btf.c +1 -0
@@ -26,6 +26,7 @@#include <linux/bsearch.h> #include <linux/kobject.h> #include <linux/sysfs.h> +#include <linux/bpf_fuse.h> #include <net/netfilter/nf_bpf_link.h>
kernel/bpf/verifier.c +9 -1
@@ -10947,6 +10947,8 @@ enum special_kfunc_type { KF_bpf_percpu_obj_drop_impl, KF_bpf_throw, KF_bpf_iter_css_task_new, + KF_bpf_fuse_get_rw_dynptr, + KF_bpf_fuse_get_ro_dynptr, };BTF_SET_START (special_kfunc_set)
@@ -10973,6 +10975,8 @@ BTF_ID(func, bpf_throw)#ifdef CONFIG_CGROUPS BTF_ID(func, bpf_iter_css_task_new)#endif +BTF_ID(func, bpf_fuse_get_rw_dynptr) +BTF_ID(func, bpf_fuse_get_ro_dynptr)BTF_SET_END (special_kfunc_set)BTF_ID_LIST (special_kfunc_list)
@@ -11003,6 +11007,8 @@ BTF_ID(func, bpf_iter_css_task_new)#else BTF_ID_UNUSED #endif +BTF_ID (func ,bpf_fuse_get_rw_dynptr ) +BTF_ID (func, bpf_fuse_get_ro_dynptr) static bool is_kfunc_ret_null(struct bpf_kfunc_call_arg_meta *meta) {
@@ -11793,7 +11799,9 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_verbose (env,"verifier internal error: missing ref obj id for parent of clone\n" );return -EFAULT ; } - } + }else if (meta->func_id == special_kfunc_list[KF_bpf_fuse_get_rw_dynptr] || + meta->func_id == special_kfunc_list[KF_bpf_fuse_get_ro_dynptr]) + dynptr_arg_type |=DYNPTR_TYPE_LOCAL ; ret =process_dynptr_func (env, regno, insn_idx, dynptr_arg_type, clone_ref_obj_id);if (ret <0 )
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 27/36 fuse-bpf: Export Functions
In reply to Daniel RosenbergThese functions needed to be exported to build fuse as a module
--- kernel/bpf/bpf_struct_ops.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/bpf/bpf_struct_ops.c +2 -0
@@ -1024,6 +1024,7 @@ bool bpf_struct_ops_get(const void *kdata) map =__bpf_map_inc_not_zero (&st_map->map, false);return !IS_ERR (map); } +EXPORT_SYMBOL_GPL (bpf_struct_ops_get);void bpf_struct_ops_put (const void *kdata) {
@@ -1035,6 +1036,7 @@ void bpf_struct_ops_put(const void *kdata)bpf_map_put (&st_map->map); } +EXPORT_SYMBOL_GPL (bpf_struct_ops_put);static bool bpf_struct_ops_valid_to_reg (struct bpf_map *map) {
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 28/36 fuse: Provide registration functions for fuse-bpf
In reply to Daniel RosenbergFuse may be built as a module, but verifier components are not. This provides a means for fuse-bpf to handle struct op programs once the module is loaded.
--- fs/fuse/Makefile | 2 +- fs/fuse/backing.c | 2 + fs/fuse/bpf_register.c | 207 +++++++++++++++++++++++++++++++++++++++ fs/fuse/fuse_i.h | 26 +++++ include/linux/bpf_fuse.h | 8 ++ 5 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 fs/fuse/bpf_register.c
fs/fuse/Makefile +1 -1
@@ -9,6 +9,6 @@ obj-$(CONFIG_VIRTIO_FS) += virtiofs.o fuse-y := dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o ioctl.o fuse-$(CONFIG_FUSE_DAX) += dax.o -fuse-$(CONFIG_FUSE_BPF) += backing.o +fuse-$(CONFIG_FUSE_BPF) += backing.o bpf_register.o virtiofs-y := virtio_fs.o
fs/fuse/backing.c +2 -0
@@ -3392,6 +3392,7 @@ int fuse_bpf_access(int *out, struct inode *inode, int mask)int __init fuse_bpf_init (void ) { +init_fuse_bpf (); fuse_bpf_aio_request_cachep =kmem_cache_create ("fuse_bpf_aio_req" ,sizeof (struct fuse_bpf_aio_req ),0 ,SLAB_HWCACHE_ALIGN ,NULL );
@@ -3403,5 +3404,6 @@ int __init fuse_bpf_init(void) void __exit fuse_bpf_cleanup(void) { +uninit_fuse_bpf ();kmem_cache_destroy (fuse_bpf_aio_request_cachep); }
fs/fuse/bpf_register.c new file +207 -0
207 lines not on this page · raw message
fs/fuse/fuse_i.h +26 -0
@@ -1423,6 +1423,32 @@ 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_BPF +struct fuse_ops *find_fuse_ops (const char *key); +struct fuse_ops *get_fuse_ops (struct fuse_ops *ops); +void put_fuse_ops (struct fuse_ops *ops); +int init_fuse_bpf (void ); +void uninit_fuse_bpf (void ); +#else +int init_fuse_bpf (void ) +{ +return -EOPNOTSUPP ; +} +void uninit_fuse_bpf (void ) +{ +} +struct fuse_ops *find_fuse_ops (const char *key) +{ +return NULL ; +} +struct fuse_ops *get_fuse_ops (struct fuse_ops *ops) +{ +return NULL ; +} +void put_fuse_ops (struct fuse_ops *ops) +{ +} +#endif enum fuse_bpf_set {FUSE_BPF_UNCHANGED =0 ,
include/linux/bpf_fuse.h +8 -0
@@ -270,4 +270,12 @@ struct fuse_ops { char name[BPF_FUSE_NAME_MAX]; }; +struct bpf_fuse_ops_attach { +int (*fuse_register_bpf)(struct fuse_ops *f_ops); +void (*fuse_unregister_bpf)(struct fuse_ops *f_ops); +}; + +int register_fuse_bpf (struct bpf_fuse_ops_attach *reg_ops); +void unregister_fuse_bpf (struct bpf_fuse_ops_attach *reg_ops); +#endif /* _BPF_FUSE_H */
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 29/36 fuse-bpf: Set fuse_ops at mount or lookup time
In reply to Daniel RosenbergThis adds the ability to associate a fuse_op struct_op program with inodes in fuse. This can be done at mount time at the root level, or by inode at lookup time.
--- fs/fuse/backing.c | 100 +++++++++++++++++++++++++++++++++++++++++----- fs/fuse/dir.c | 19 ++++++++- fs/fuse/fuse_i.h | 12 ++++++ fs/fuse/inode.c | 45 ++++++++++++++++++--- 4 files changed, 160 insertions(+), 16 deletions(-)
fs/fuse/backing.c +91 -9
@@ -6,6 +6,7 @@#include "fuse_i.h" +#include <linux/bpf.h> #include <linux/bpf_fuse.h> #include <linux/fdtable.h> #include <linux/file.h>
@@ -176,12 +177,13 @@ static void fuse_get_backing_path(struct file *file, struct path *path)static bool has_file (int type) { -return type ==FUSE_ENTRY_BACKING ; +return (type ==FUSE_ENTRY_BACKING ); }/* -* The optional fuse bpf entry lists the backing file for a particular -* lookup. These are inherited by default. +* The optional fuse bpf entry lists the bpf and backing files for a particular +* lookup. These are inherited by default. A Bpf requires a backing file to be +* meaningful. * * In the future, we may support multiple bpfs, and multiple backing files for * the bpf to choose between.
@@ -190,14 +192,14 @@ static bool has_file(int type)* file. Changing only the bpf is valid, though meaningless if there isn't an * inherited backing file. * -* Support for the bpf program will be added in a later patch -* */ int parse_fuse_bpf_entry (struct fuse_bpf_entry *fbe,int num) {struct fuse_bpf_entry_out *fbeo; +struct fuse_ops *ops;struct file *file;bool has_backing = false; +bool has_bpf_ops = false;int num_entries;int err = -EINVAL ;int i;
@@ -235,6 +237,11 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num) goto out_err; fbe->backing_action =FUSE_BPF_REMOVE ;break ; +case FUSE_ENTRY_REMOVE_BPF : +if (fbe->bpf_action || i ==2 ) + goto out_err; + fbe->bpf_action =FUSE_BPF_REMOVE ; +break ;case FUSE_ENTRY_BACKING :if (fbe->backing_action) goto out_err;
@@ -242,8 +249,17 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num) fbe->backing_action =FUSE_BPF_SET ; has_backing = true;break ; +case FUSE_ENTRY_BPF : +if (fbe->bpf_action || i ==2 ) + goto out_err; + ops =find_fuse_ops (fbeo->name); +if (!ops) + goto out_err; + has_bpf_ops = true; + fbe->bpf_action =FUSE_BPF_SET ; + fbe->ops = ops; +break ;default : - err = -EINVAL ; goto out_err; }if (has_file (fbeo->entry_type)) {
@@ -260,6 +276,10 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num)fput (file);if (has_backing)path_put_init (&fbe->backing_path); +if (has_bpf_ops) { +put_fuse_ops (fbe->ops); + fbe->ops =NULL ; + }return err; }
@@ -538,6 +558,15 @@ static int fuse_create_open_backing(struct bpf_fuse_args *fa, int *out, goto out; } +if (get_fuse_inode (inode)->bpf_ops) +put_fuse_ops (get_fuse_inode (inode)->bpf_ops); +get_fuse_inode (inode)->bpf_ops = dir_fuse_inode->bpf_ops; +if (get_fuse_inode (inode)->bpf_ops) +if (!get_fuse_ops (get_fuse_inode (inode)->bpf_ops)) { + *out = -EINVAL ; + goto out; + } + newent =d_splice_alias (inode, entry);if (IS_ERR (newent)) { *out =PTR_ERR (newent);
@@ -1858,12 +1887,56 @@ int fuse_handle_backing(struct fuse_bpf_entry *fbe, struct path *backing_path)return 0 ; } +int fuse_handle_bpf_ops (struct fuse_bpf_entry *fbe,struct inode *parent, +struct fuse_ops **ops) +{ +struct fuse_ops *new_ops =NULL ; + +switch (fbe->bpf_action) { +case FUSE_BPF_UNCHANGED : { +/* Parent isn't presented, but we want to keep +* Don't touch bpf program at all in this case +*/ +if (!parent) +return 0 ; + + new_ops =get_fuse_inode (parent)->bpf_ops; +if (new_ops && !get_fuse_ops (new_ops)) +return -EINVAL ; +break ; + } + +case FUSE_BPF_REMOVE : +break ; + +case FUSE_BPF_SET : + new_ops = fbe->ops; + +if (!new_ops) +return -EINVAL ; +break ; + +default : +return -EINVAL ; + } + +/* Cannot change existing program */ +if (*ops) { +if (new_ops) +put_fuse_ops (new_ops); +return new_ops == *ops ?0 : -EINVAL ; + } + + *ops = new_ops; +return 0 ; +} +static int fuse_lookup_finalize (struct bpf_fuse_args *fa,struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags) {struct fuse_dentry *fd;struct dentry *backing_dentry; -struct inode *inode, *backing_inode; +struct inode *inode =NULL , *backing_inode;struct inode *d_inode = entry->d_inode;struct fuse_entry_out *feo = fa->out_args[0 ].value;struct fuse_bpf_entry_out *febo = fa->out_args[1 ].buffer->data;
@@ -1891,13 +1964,22 @@ static int fuse_lookup_finalize(struct bpf_fuse_args *fa, struct dentry **out, target_nodeid =get_fuse_inode (d_inode)->nodeid; inode =fuse_iget_backing (dir->i_sb, target_nodeid, backing_inode); +if (!inode) +return -EIO ; -if (IS_ERR (inode)) -return PTR_ERR (inode); + error =fuse_handle_bpf_ops (fbe, dir, &get_fuse_inode (inode)->bpf_ops); +if (error) { +return error; + goto out; + }get_fuse_inode (inode)->nodeid = feo->nodeid; *out =d_splice_alias (inode, entry); +if (!IS_ERR (*out)) + inode =NULL ; +out: +iput (inode);return 0 ; }
fs/fuse/dir.c +17 -2
@@ -10,6 +10,7 @@#include <linux/pagemap.h> #include <linux/file.h> +#include <linux/filter.h> #include <linux/fs_context.h> #include <linux/moduleparam.h> #include <linux/sched.h>
@@ -202,6 +203,7 @@ static bool backing_data_changed(struct fuse_inode *fi, struct dentry *entry, {struct path new_backing_path;struct inode *new_backing_inode; +struct fuse_ops *ops =NULL ;int err;bool ret = true;
@@ -216,9 +218,15 @@ static bool backing_data_changed(struct fuse_inode *fi, struct dentry *entry,if (err) goto put_inode; - ret = (fi->backing_inode != new_backing_inode || - !path_equal (&get_fuse_dentry (entry)->backing_path, &new_backing_path)); + err =fuse_handle_bpf_ops (bpf_arg, entry->d_parent->d_inode, &ops); +if (err) + goto put_bpf; + ret = (ops != fi->bpf_ops || fi->backing_inode != new_backing_inode || + !path_equal (&get_fuse_dentry (entry)->backing_path, &new_backing_path)); +put_bpf: +if (ops) +put_fuse_ops (ops); put_inode:path_put (&new_backing_path);return ret;
@@ -486,6 +494,13 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, *inode =fuse_iget_backing (sb, outarg->nodeid, backing_inode);if (!*inode) goto out_queue_forget; + + err =fuse_handle_bpf_ops (&bpf_arg,NULL , &get_fuse_inode (*inode)->bpf_ops); +if (err) { +iput (*inode); + *inode =NULL ; + goto out_put_forget; + } } else#endif {
fs/fuse/fuse_i.h +12 -0
@@ -33,6 +33,7 @@#include <linux/pid_namespace.h> #include <linux/refcount.h> #include <linux/user_namespace.h> +#include <linux/bpf_fuse.h> #include <linux/magic.h> /** Default max number of pages that can be used in a single read request */
@@ -122,6 +123,12 @@ struct fuse_inode {* If this is set, nodeid is 0. */ struct inode *backing_inode; + +/** +* fuse_ops, provides handlers to run on all operations to determine +* whether to pass through or handle in place +*/ +struct fuse_ops *bpf_ops;#endif /** Unique ID, which identifies the inode between userspace
@@ -591,6 +598,7 @@ struct fuse_fs_context {unsigned int max_read;unsigned int blksize;const char *subtype; +struct fuse_ops *root_ops;struct file *root_dir;/* DAX device, may be NULL */
@@ -1461,6 +1469,8 @@ struct fuse_bpf_entry {enum fuse_bpf_set backing_action;struct path backing_path; +enum fuse_bpf_set bpf_action; +struct fuse_ops *ops;bool is_used; };
@@ -1687,6 +1697,8 @@ int fuse_file_flock_backing(struct file *file, int cmd, struct file_lock *fl);ssize_t fuse_backing_mmap (struct file *file,struct vm_area_struct *vma);int fuse_handle_backing (struct fuse_bpf_entry *fbe,struct path *backing_path); +int fuse_handle_bpf_ops (struct fuse_bpf_entry *fbe,struct inode *parent, +struct fuse_ops **ops);int fuse_revalidate_backing (struct dentry *entry,unsigned int flags);
fs/fuse/inode.c +40 -5
117 lines not on this page · raw message
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 30/36 fuse-bpf: Call bpf for pre/post filters
In reply to Daniel RosenbergThis allows altering input or output parameters to fuse calls that will be handled directly by the backing filesystems. BPF programs can signal whether the entire operation should instead go through regular fuse, or if a postfilter call is needed.
--- fs/fuse/backing.c | 605 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 605 insertions(+)
fs/fuse/backing.c +605 -0
@@ -16,6 +16,27 @@#include <linux/splice.h> #include <linux/uio.h> +static inline void bpf_fuse_set_in_immutable (struct bpf_fuse_args *fa) +{ +int i; + +for (i =0 ; i <FUSE_MAX_ARGS_IN ; i++) +if (fa->in_args[i].is_buffer) + fa->in_args[i].buffer->flags |=BPF_FUSE_IMMUTABLE ; +} + +static inline void bpf_fuse_free_alloced (struct bpf_fuse_args *fa) +{ +int i; + +for (i =0 ; i <FUSE_MAX_ARGS_IN ; i++) +if (fa->in_args[i].is_buffer && (fa->in_args[i].buffer->flags &BPF_FUSE_ALLOCATED )) +kfree (fa->in_args[i].buffer->data); +for (i =0 ; i <FUSE_MAX_ARGS_OUT ; i++) +if (fa->out_args[i].is_buffer && (fa->out_args[i].buffer->flags &BPF_FUSE_ALLOCATED )) +kfree (fa->out_args[i].buffer->data); +} +/* * expression statement to wrap the backing filter logic * struct inode *inode: inode with bpf and backing inode
@@ -25,6 +46,10 @@* up fa and io based on args * void initialize_out(struct bpf_fuse_args *fa, io *in_out, args...): function that sets * up fa and io based on args +* int call_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta, io *in_out): Calls +* the struct_op prefilter function for the given fuse op +* int call_prostfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta, io *in_out): Calls +* the struct_op postfilter function for the given fuse op * int backing(struct fuse_bpf_args_internal *fa, args...): function that actually performs * the backing io operation * void *finalize(struct fuse_bpf_args *, args...): function that performs any final
@@ -32,13 +57,16 @@*/ #define bpf_fuse_backing (inode, io, out, \ initialize_in, initialize_out, \ + call_prefilter, call_postfilter, \ backing, finalize, args...) \ ({ \ struct fuse_inode *fuse_inode = get_fuse_inode(inode); \ + struct fuse_ops *fuse_ops = fuse_inode->bpf_ops; \ struct bpf_fuse_args fa = { 0 }; \ bool initialized = false; \ bool handled = false; \ ssize_t res; \ + int bpf_next; \ io feo = { 0 }; \ int error = 0; \ \
@@ -51,16 +79,46 @@if (error) \break ; \ \ + fa.info.opcode |=FUSE_PREFILTER ; \ +if (fuse_ops) \ + bpf_next =call_prefilter (fuse_ops, \ + &fa.info, &feo); \ +else \ + bpf_next =BPF_FUSE_CONTINUE ; \ +if (bpf_next <0 ) { \ + error = bpf_next; \ +break ; \ + } \ + \ +bpf_fuse_set_in_immutable (&fa); \ + \ error =initialize_out (&fa, &feo, args); \if (error) \break ; \ \ initialized = true; \ +if (bpf_next ==BPF_FUSE_USER ) { \ + handled = false; \ +break ; \ + } \ + \ + fa.info.opcode &= ~FUSE_PREFILTER ; \ \ error =backing (&fa, out, args); \if (error <0 ) \ fa.info.error_in = error; \ \ +if (bpf_next ==BPF_FUSE_CONTINUE ) \ +break ; \ + \ + fa.info.opcode |=FUSE_POSTFILTER ; \ +if (bpf_next ==BPF_FUSE_POSTFILTER ) \ + bpf_next =call_postfilter (fuse_ops, &fa.info, &feo);\ +if (bpf_next <0 ) { \ + error = bpf_next; \ +break ; \ + } \ + \ }while (false); \ \if (initialized && handled) { \
@@ -68,6 +126,7 @@if (res) \ error = res; \ } \ +bpf_fuse_free_alloced (&fa); \ \ *out = error ? _Generic((*out), \ default : \
@@ -362,6 +421,34 @@ static int fuse_open_initialize_out(struct bpf_fuse_args *fa, struct fuse_open_areturn 0 ; } +static int fuse_open_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_open_args *open) +{ +if (meta->opcode == (FUSE_OPEN |FUSE_PREFILTER )) { +if (ops->open_prefilter) +return ops->open_prefilter (meta, &open->in); + } +if (meta->opcode == (FUSE_OPENDIR |FUSE_PREFILTER )) { +if (ops->opendir_prefilter) +return ops->opendir_prefilter (meta, &open->in); + } +return BPF_FUSE_CONTINUE ; +} + +static int fuse_open_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_open_args *open) +{ +if (meta->opcode == (FUSE_OPEN |FUSE_POSTFILTER )) { +if (ops->open_postfilter) +return ops->open_postfilter (meta, &open->in, &open->out); + } +if (meta->opcode == (FUSE_OPENDIR |FUSE_POSTFILTER )) { +if (ops->opendir_postfilter) +return ops->opendir_postfilter (meta, &open->in, &open->out); + } +return BPF_FUSE_CONTINUE ; +} +static int fuse_open_backing (struct bpf_fuse_args *fa,int *out,struct inode *inode,struct file *file,bool isdir) {
@@ -430,6 +517,7 @@ int fuse_bpf_open(int *out, struct inode *inode, struct file *file, bool isdir) { return bpf_fuse_backing(inode, struct fuse_open_args, out, fuse_open_initialize_in, fuse_open_initialize_out, + fuse_open_prefilter, fuse_open_postfilter, fuse_open_backing, fuse_open_finalize, inode, file, isdir); }
@@ -495,6 +583,22 @@ static int fuse_create_open_initialize_out(struct bpf_fuse_args *fa, struct fusereturn 0 ; } +static int fuse_create_open_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_create_open_args *args) +{ +if (ops->create_open_prefilter) +return ops->create_open_prefilter (meta, &args->in, &args->name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_create_open_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_create_open_args *args) +{ +if (ops->create_open_postfilter) +return ops->create_open_postfilter (meta, &args->in, &args->name, &args->entry_out, &args->open_out); +return BPF_FUSE_CONTINUE ; +} +static int fuse_open_file_backing (struct inode *inode,struct file *file) {struct fuse_mount *fm =get_fuse_mount (inode);
@@ -599,12 +703,16 @@ static int fuse_create_open_finalize(struct bpf_fuse_args *fa, int *out,return 0 ; } + +int fuse_bpf_create_open (int *out,struct inode *dir,struct dentry *entry,struct file *file,unsigned int flags,umode_t mode) { return bpf_fuse_backing(dir, struct fuse_create_open_args, out, fuse_create_open_initialize_in, fuse_create_open_initialize_out, + fuse_create_open_prefilter, + fuse_create_open_postfilter, fuse_create_open_backing, fuse_create_open_finalize, dir, entry, file, flags, mode);
@@ -639,6 +747,38 @@ static int fuse_release_initialize_out(struct bpf_fuse_args *fa, struct fuse_relreturn 0 ; } +static int fuse_release_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_release_in *args) +{ +if (ops->release_prefilter) +return ops->release_prefilter (meta, args); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_release_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_release_in *args) +{ +if (ops->release_postfilter) +return ops->release_postfilter (meta, args); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_releasedir_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_release_in *args) +{ +if (ops->releasedir_prefilter) +return ops->releasedir_prefilter (meta, args); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_releasedir_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_release_in *args) +{ +if (ops->releasedir_postfilter) +return ops->releasedir_postfilter (meta, args); +return BPF_FUSE_CONTINUE ; +} +static int fuse_release_backing (struct bpf_fuse_args *fa,int *out,struct inode *inode,struct fuse_file *ff) {
@@ -656,6 +796,7 @@ int fuse_bpf_release(int *out, struct inode *inode, struct fuse_file *ff) { return bpf_fuse_backing(inode, struct fuse_release_in, out, fuse_release_initialize_in, fuse_release_initialize_out, + fuse_release_prefilter, fuse_release_postfilter, fuse_release_backing, fuse_release_finalize, inode, ff); }
@@ -664,6 +805,7 @@ int fuse_bpf_releasedir(int *out, struct inode *inode, struct fuse_file *ff) { return bpf_fuse_backing(inode, struct fuse_release_in, out, fuse_release_initialize_in, fuse_release_initialize_out, + fuse_releasedir_prefilter, fuse_releasedir_postfilter, fuse_release_backing, fuse_release_finalize, inode, ff); }
@@ -696,6 +838,22 @@ static int fuse_flush_initialize_out(struct bpf_fuse_args *fa, struct fuse_flushreturn 0 ; } +static int fuse_flush_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_flush_in *args) +{ +if (ops->flush_prefilter) +return ops->flush_prefilter (meta, args); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_flush_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_flush_in *args) +{ +if (ops->flush_postfilter) +return ops->flush_postfilter (meta, args); +return BPF_FUSE_CONTINUE ; +} +static int fuse_flush_backing (struct bpf_fuse_args *fa,int *out,struct file *file,fl_owner_t id) {struct fuse_file *fuse_file = file->private_data;
@@ -716,6 +874,7 @@ int fuse_bpf_flush(int *out, struct inode *inode, struct file *file, fl_owner_t { return bpf_fuse_backing(inode, struct fuse_flush_in, out, fuse_flush_initialize_in, fuse_flush_initialize_out, + fuse_flush_prefilter, fuse_flush_postfilter, fuse_flush_backing, fuse_flush_finalize, file, id); }
@@ -759,6 +918,22 @@ static int fuse_lseek_initialize_out(struct bpf_fuse_args *fa, struct fuse_lseekreturn 0 ; } +static int fuse_lseek_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_lseek_args *args) +{ +if (ops->lseek_prefilter) +return ops->lseek_prefilter (meta, &args->in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_lseek_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_lseek_args *args) +{ +if (ops->lseek_postfilter) +return ops->lseek_postfilter (meta, &args->in, &args->out); +return BPF_FUSE_CONTINUE ; +} +static int fuse_lseek_backing (struct bpf_fuse_args *fa,loff_t *out,struct file *file,loff_t offset,int whence) {
@@ -805,6 +980,7 @@ int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *file, loff_t o { return bpf_fuse_backing(inode, struct fuse_lseek_args, out, fuse_lseek_initialize_in, fuse_lseek_initialize_out, + fuse_lseek_prefilter, fuse_lseek_postfilter, fuse_lseek_backing, fuse_lseek_finalize, file, offset, whence); }
@@ -857,6 +1033,22 @@ static int fuse_copy_file_range_initialize_out(struct bpf_fuse_args *fa,return 0 ; } +static int fuse_copy_file_range_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_copy_file_range_args *args) +{ +if (ops->copy_file_range_prefilter) +return ops->copy_file_range_prefilter (meta, &args->in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_copy_file_range_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_copy_file_range_args *args) +{ +if (ops->copy_file_range_postfilter) +return ops->copy_file_range_postfilter (meta, &args->in, &args->out); +return BPF_FUSE_CONTINUE ; +} +static int fuse_copy_file_range_backing (struct bpf_fuse_args *fa,ssize_t *out,struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,size_t len,unsigned int flags)
@@ -890,6 +1082,8 @@ int fuse_bpf_copy_file_range(ssize_t *out, struct inode *inode, struct file *fil return bpf_fuse_backing(inode, struct fuse_copy_file_range_args, out, fuse_copy_file_range_initialize_in, fuse_copy_file_range_initialize_out, + fuse_copy_file_range_prefilter, + fuse_copy_file_range_postfilter, fuse_copy_file_range_backing, fuse_copy_file_range_finalize, file_in, pos_in, file_out, pos_out, len, flags);
@@ -925,6 +1119,22 @@ static int fuse_fsync_initialize_out(struct bpf_fuse_args *fa, struct fuse_fsyncreturn 0 ; } +static int fuse_fsync_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_fsync_in *in) +{ +if (ops->fsync_prefilter) +return ops->fsync_prefilter (meta, in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_fsync_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_fsync_in *in) +{ +if (ops->fsync_postfilter) +return ops->fsync_postfilter (meta, in); +return BPF_FUSE_CONTINUE ; +} +static int fuse_fsync_backing (struct bpf_fuse_args *fa,int *out,struct file *file,loff_t start,loff_t end,int datasync) {
@@ -947,6 +1157,7 @@ int fuse_bpf_fsync(int *out, struct inode *inode, struct file *file, loff_t star { return bpf_fuse_backing(inode, struct fuse_fsync_in, out, fuse_fsync_initialize_in, fuse_fsync_initialize_out, + fuse_fsync_prefilter, fuse_fsync_postfilter, fuse_fsync_backing, fuse_fsync_finalize, file, start, end, datasync); }
@@ -981,10 +1192,27 @@ static int fuse_dir_fsync_initialize_out(struct bpf_fuse_args *fa, struct fuse_freturn 0 ; } +static int fuse_dir_fsync_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_fsync_in *in) +{ +if (ops->dir_fsync_prefilter) +return ops->fsync_prefilter (meta, in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_dir_fsync_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_fsync_in *in) +{ +if (ops->dir_fsync_postfilter) +return ops->dir_fsync_postfilter (meta, in); +return BPF_FUSE_CONTINUE ; +} +int fuse_bpf_dir_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync) { return bpf_fuse_backing(inode, struct fuse_fsync_in, out, fuse_dir_fsync_initialize_in, fuse_dir_fsync_initialize_out, + fuse_dir_fsync_prefilter, fuse_dir_fsync_postfilter, fuse_fsync_backing, fuse_fsync_finalize, file, start, end, datasync); }
@@ -1054,6 +1282,22 @@ static int fuse_getxattr_initialize_out(struct bpf_fuse_args *fa,return 0 ; } +static int fuse_getxattr_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_getxattr_args *args) +{ +if (ops->getxattr_prefilter) +return ops->getxattr_prefilter (meta, &args->in, &args->name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_getxattr_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_getxattr_args *args) +{ +if (ops->getxattr_postfilter) +return ops->getxattr_postfilter (meta, &args->in, &args->name, &args->value, &args->out); +return BPF_FUSE_CONTINUE ; +} +static int fuse_getxattr_backing (struct bpf_fuse_args *fa,int *out,struct dentry *dentry,const char *name,void *value,size_t size)
@@ -1099,6 +1343,7 @@ int fuse_bpf_getxattr(int *out, struct inode *inode, struct dentry *dentry, cons { return bpf_fuse_backing(inode, struct fuse_getxattr_args, out, fuse_getxattr_initialize_in, fuse_getxattr_initialize_out, + fuse_getxattr_prefilter, fuse_getxattr_postfilter, fuse_getxattr_backing, fuse_getxattr_finalize, dentry, name, value, size); }
@@ -1151,6 +1396,22 @@ static int fuse_listxattr_initialize_out(struct bpf_fuse_args *fa,return 0 ; } +static int fuse_listxattr_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_getxattr_args *args) +{ +if (ops->listxattr_prefilter) +return ops->listxattr_prefilter (meta, &args->in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_listxattr_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_getxattr_args *args) +{ +if (ops->listxattr_postfilter) +return ops->listxattr_postfilter (meta, &args->in, &args->value, &args->out); +return BPF_FUSE_CONTINUE ; +} +static int fuse_listxattr_backing (struct bpf_fuse_args *fa,ssize_t *out,struct dentry *dentry,char *list,size_t size) {
@@ -1190,6 +1451,7 @@ int fuse_bpf_listxattr(ssize_t *out, struct inode *inode, struct dentry *dentry, { return bpf_fuse_backing(inode, struct fuse_getxattr_args, out, fuse_listxattr_initialize_in, fuse_listxattr_initialize_out, + fuse_listxattr_prefilter, fuse_listxattr_postfilter, fuse_listxattr_backing, fuse_listxattr_finalize, dentry, list, size); }
@@ -1255,6 +1517,22 @@ static int fuse_setxattr_initialize_out(struct bpf_fuse_args *fa,return 0 ; } +static int fuse_setxattr_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_setxattr_args *args) +{ +if (ops->setxattr_prefilter) +return ops->setxattr_prefilter (meta, &args->in, &args->name, &args->value); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_setxattr_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_setxattr_args *args) +{ +if (ops->setxattr_postfilter) +return ops->setxattr_postfilter (meta, &args->in, &args->name, &args->value); +return BPF_FUSE_CONTINUE ; +} +static int fuse_setxattr_backing (struct bpf_fuse_args *fa,int *out,struct dentry *dentry,const char *name,const void *value,size_t size,int flags)
@@ -1278,6 +1556,7 @@ int fuse_bpf_setxattr(int *out, struct inode *inode, struct dentry *dentry, { return bpf_fuse_backing(inode, struct fuse_setxattr_args, out, fuse_setxattr_initialize_in, fuse_setxattr_initialize_out, + fuse_setxattr_prefilter, fuse_setxattr_postfilter, fuse_setxattr_backing, fuse_setxattr_finalize, dentry, name, value, size, flags); }
@@ -1314,6 +1593,22 @@ static int fuse_removexattr_initialize_out(struct bpf_fuse_args *fa,return 0 ; } +static int fuse_removexattr_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_buffer *in) +{ +if (ops->removexattr_prefilter) +return ops->removexattr_prefilter (meta, in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_removexattr_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_buffer *in) +{ +if (ops->removexattr_postfilter) +return ops->removexattr_postfilter (meta, in); +return BPF_FUSE_CONTINUE ; +} +static int fuse_removexattr_backing (struct bpf_fuse_args *fa,int *out,struct dentry *dentry,const char *name) {
@@ -1334,6 +1629,7 @@ int fuse_bpf_removexattr(int *out, struct inode *inode, struct dentry *dentry, c { return bpf_fuse_backing(inode, struct fuse_buffer, out, fuse_removexattr_initialize_in, fuse_removexattr_initialize_out, + fuse_removexattr_prefilter, fuse_removexattr_postfilter, fuse_removexattr_backing, fuse_removexattr_finalize, dentry, name); }
@@ -1424,6 +1720,21 @@ static int fuse_file_read_iter_initialize_out(struct bpf_fuse_args *fa, struct freturn 0 ; } +static int fuse_file_read_iter_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_file_read_iter_args *args) +{ +if (ops->read_iter_prefilter) +return ops->read_iter_prefilter (meta, &args->in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_file_read_iter_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_file_read_iter_args *args) +{ +if (ops->read_iter_postfilter) +return ops->read_iter_postfilter (meta, &args->in, &args->out); +return BPF_FUSE_CONTINUE ; +}// TODO: use backing-file.c static inline rwf_t fuse_iocb_to_rw_flags (int ifl,int iocb_mask)
@@ -1498,6 +1809,8 @@ int fuse_bpf_file_read_iter(ssize_t *out, struct inode *inode, struct kiocb *ioc return bpf_fuse_backing(inode, struct fuse_file_read_iter_args, out, fuse_file_read_iter_initialize_in, fuse_file_read_iter_initialize_out, + fuse_file_read_iter_prefilter, + fuse_file_read_iter_postfilter, fuse_file_read_iter_backing, fuse_file_read_iter_finalize, iocb, to);
@@ -1547,6 +1860,22 @@ static int fuse_file_write_iter_initialize_out(struct bpf_fuse_args *fa,return 0 ; } +static int fuse_write_iter_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_file_write_iter_args *args) +{ +if (ops->write_iter_prefilter) +return ops->write_iter_prefilter (meta, &args->in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_write_iter_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_file_write_iter_args *args) +{ +if (ops->write_iter_postfilter) +return ops->write_iter_postfilter (meta, &args->in, &args->out); +return BPF_FUSE_CONTINUE ; +} +static int fuse_file_write_iter_backing (struct bpf_fuse_args *fa,ssize_t *out,struct kiocb *iocb,struct iov_iter *from) {
@@ -1611,6 +1940,8 @@ int fuse_bpf_file_write_iter(ssize_t *out, struct inode *inode, struct kiocb *io return bpf_fuse_backing(inode, struct fuse_file_write_iter_args, out, fuse_file_write_iter_initialize_in, fuse_file_write_iter_initialize_out, + fuse_write_iter_prefilter, + fuse_write_iter_postfilter, fuse_file_write_iter_backing, fuse_file_write_iter_finalize, iocb, from);
@@ -1717,6 +2048,22 @@ static int fuse_file_fallocate_initialize_out(struct bpf_fuse_args *fa,return 0 ; } +static int fuse_file_fallocate_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_fallocate_in *in) +{ +if (ops->file_fallocate_prefilter) +return ops->file_fallocate_prefilter (meta, in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_file_fallocate_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_fallocate_in *in) +{ +if (ops->file_fallocate_postfilter) +return ops->file_fallocate_postfilter (meta, in); +return BPF_FUSE_CONTINUE ; +} +static int fuse_file_fallocate_backing (struct bpf_fuse_args *fa,int *out,struct file *file,int mode,loff_t offset,loff_t length) {
@@ -1739,6 +2086,8 @@ int fuse_bpf_file_fallocate(int *out, struct inode *inode, struct file *file, in return bpf_fuse_backing(inode, struct fuse_fallocate_in, out, fuse_file_fallocate_initialize_in, fuse_file_fallocate_initialize_out, + fuse_file_fallocate_prefilter, + fuse_file_fallocate_postfilter, fuse_file_fallocate_backing, fuse_file_fallocate_finalize, file, mode, offset, length);
@@ -1806,6 +2155,22 @@ static int fuse_lookup_initialize_out(struct bpf_fuse_args *fa, struct fuse_lookreturn 0 ; } +static int fuse_lookup_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_lookup_args *args) +{ +if (ops->lookup_prefilter) +return ops->lookup_prefilter (meta, &args->name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_lookup_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_lookup_args *args) +{ +if (ops->lookup_postfilter) +return ops->lookup_postfilter (meta, &args->name, &args->out, &args->bpf_entries); +return BPF_FUSE_CONTINUE ; +} +static int fuse_lookup_backing (struct bpf_fuse_args *fa,struct dentry **out,struct inode *dir,struct dentry *entry,unsigned int flags) {
@@ -1987,6 +2352,7 @@ int fuse_bpf_lookup(struct dentry **out, struct inode *dir, struct dentry *entry { return bpf_fuse_backing(dir, struct fuse_lookup_args, out, fuse_lookup_initialize_in, fuse_lookup_initialize_out, + fuse_lookup_prefilter, fuse_lookup_postfilter, fuse_lookup_backing, fuse_lookup_finalize, dir, entry, flags); }
@@ -2053,6 +2419,22 @@ static int fuse_mknod_initialize_out(struct bpf_fuse_args *fa, struct fuse_mknodreturn 0 ; } +static int fuse_mknod_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_mknod_args *args) +{ +if (ops->mknod_prefilter) +return ops->mknod_prefilter (meta, &args->in, &args->name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_mknod_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_mknod_args *args) +{ +if (ops->mknod_postfilter) +return ops->mknod_postfilter (meta, &args->in, &args->name); +return BPF_FUSE_CONTINUE ; +} +static int fuse_mknod_backing (struct bpf_fuse_args *fa,int *out,struct inode *dir,struct dentry *entry,umode_t mode,dev_t rdev) {
@@ -2105,6 +2487,7 @@ int fuse_bpf_mknod(int *out, struct inode *dir, struct dentry *entry, umode_t mo { return bpf_fuse_backing(dir, struct fuse_mknod_args, out, fuse_mknod_initialize_in, fuse_mknod_initialize_out, + fuse_mknod_prefilter, fuse_mknod_postfilter, fuse_mknod_backing, fuse_mknod_finalize, dir, entry, mode, rdev); }
@@ -2206,10 +2589,27 @@ static int fuse_mkdir_finalize(struct bpf_fuse_args *fa, int *out,return 0 ; } +static int fuse_mkdir_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_mkdir_args *args) +{ +if (ops->mkdir_prefilter) +return ops->mkdir_prefilter (meta, &args->in, &args->name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_mkdir_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_mkdir_args *args) +{ +if (ops->mkdir_prefilter) +return ops->mkdir_postfilter (meta, &args->in, &args->name); +return BPF_FUSE_CONTINUE ; +} +int fuse_bpf_mkdir (int *out,struct inode *dir,struct dentry *entry,umode_t mode) { return bpf_fuse_backing(dir, struct fuse_mkdir_args, out, fuse_mkdir_initialize_in, fuse_mkdir_initialize_out, + fuse_mkdir_prefilter, fuse_mkdir_postfilter, fuse_mkdir_backing, fuse_mkdir_finalize, dir, entry, mode); }
@@ -2243,6 +2643,22 @@ static int fuse_rmdir_initialize_out(struct bpf_fuse_args *fa, struct fuse_buffereturn 0 ; } +static int fuse_rmdir_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name) +{ +if (ops->rmdir_prefilter) +return ops->rmdir_prefilter (meta, name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_rmdir_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name) +{ +if (ops->rmdir_postfilter) +return ops->rmdir_postfilter (meta, name); +return BPF_FUSE_CONTINUE ; +} +static int fuse_rmdir_backing (struct bpf_fuse_args *fa,int *out,struct inode *dir,struct dentry *entry) {
@@ -2277,6 +2693,7 @@ int fuse_bpf_rmdir(int *out, struct inode *dir, struct dentry *entry) { return bpf_fuse_backing(dir, struct fuse_buffer, out, fuse_rmdir_initialize_in, fuse_rmdir_initialize_out, + fuse_rmdir_prefilter, fuse_rmdir_postfilter, fuse_rmdir_backing, fuse_rmdir_finalize, dir, entry); }
@@ -2419,6 +2836,22 @@ static int fuse_rename2_initialize_out(struct bpf_fuse_args *fa, struct fuse_renreturn 0 ; } +static int fuse_rename2_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_rename2_args *args) +{ +if (ops->rename2_prefilter) +return ops->rename2_prefilter (meta, &args->in, &args->old_name, &args->new_name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_rename2_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_rename2_args *args) +{ +if (ops->rename2_postfilter) +return ops->rename2_postfilter (meta, &args->in, &args->old_name, &args->new_name); +return BPF_FUSE_CONTINUE ; +} + static int fuse_rename2_backing(struct bpf_fuse_args *fa, int *out, struct inode *olddir, struct dentry *oldent, struct inode *newdir, struct dentry *newent,
@@ -2446,6 +2879,7 @@ int fuse_bpf_rename2(int *out, struct inode *olddir, struct dentry *oldent, { return bpf_fuse_backing(olddir, struct fuse_rename2_args, out, fuse_rename2_initialize_in, fuse_rename2_initialize_out, + fuse_rename2_prefilter, fuse_rename2_postfilter, fuse_rename2_backing, fuse_rename2_finalize, olddir, oldent, newdir, newent, flags); }
@@ -2506,6 +2940,22 @@ static int fuse_rename_initialize_out(struct bpf_fuse_args *fa, struct fuse_renareturn 0 ; } +static int fuse_rename_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_rename_args *args) +{ +if (ops->rename_prefilter) +return ops->rename_prefilter (meta, &args->in, &args->old_name, &args->new_name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_rename_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_rename_args *args) +{ +if (ops->rename_postfilter) +return ops->rename_postfilter (meta, &args->in, &args->old_name, &args->new_name); +return BPF_FUSE_CONTINUE ; +} +static int fuse_rename_backing (struct bpf_fuse_args *fa,int *out,struct inode *olddir,struct dentry *oldent,struct inode *newdir,struct dentry *newent)
@@ -2527,6 +2977,7 @@ int fuse_bpf_rename(int *out, struct inode *olddir, struct dentry *oldent, { return bpf_fuse_backing(olddir, struct fuse_rename_args, out, fuse_rename_initialize_in, fuse_rename_initialize_out, + fuse_rename_prefilter, fuse_rename_postfilter, fuse_rename_backing, fuse_rename_finalize, olddir, oldent, newdir, newent); }
@@ -2560,6 +3011,22 @@ static int fuse_unlink_initialize_out(struct bpf_fuse_args *fa, struct fuse_buffreturn 0 ; } +static int fuse_unlink_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name) +{ +if (ops->unlink_prefilter) +return ops->unlink_prefilter (meta, name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_unlink_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_buffer *name) +{ +if (ops->unlink_postfilter) +return ops->unlink_postfilter (meta, name); +return BPF_FUSE_CONTINUE ; +} +static int fuse_unlink_backing (struct bpf_fuse_args *fa,int *out,struct inode *dir,struct dentry *entry) {struct path backing_path;
@@ -2596,6 +3063,7 @@ int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry) { return bpf_fuse_backing(dir, struct fuse_buffer, out, fuse_unlink_initialize_in, fuse_unlink_initialize_out, + fuse_unlink_prefilter, fuse_unlink_postfilter, fuse_unlink_backing, fuse_unlink_finalize, dir, entry); }
@@ -2648,6 +3116,23 @@ static int fuse_link_initialize_out(struct bpf_fuse_args *fa, struct fuse_link_areturn 0 ; } +static int fuse_link_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_link_args *args) +{ +if (ops->link_prefilter) +return ops->link_prefilter (meta, &args->in, &args->name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_link_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_link_args *args) +{ +if (ops->link_postfilter) +return ops->link_postfilter (meta, &args->in, &args->name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_link_backing (struct bpf_fuse_args *fa,int *out,struct dentry *entry,struct inode *dir,struct dentry *newent) {
@@ -2715,6 +3200,7 @@ int fuse_bpf_link(int *out, struct inode *inode, struct dentry *entry, { return bpf_fuse_backing(inode, struct fuse_link_args, out, fuse_link_initialize_in, fuse_link_initialize_out, + fuse_link_prefilter, fuse_link_postfilter, fuse_link_backing, fuse_link_finalize, entry, newdir, newent); }
@@ -2763,6 +3249,22 @@ static int fuse_getattr_initialize_out(struct bpf_fuse_args *fa, struct fuse_getreturn 0 ; } +static int fuse_getattr_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_getattr_args *args) +{ +if (ops->getattr_prefilter) +return ops->getattr_prefilter (meta, &args->in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_getattr_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_getattr_args *args) +{ +if (ops->getattr_postfilter) +return ops->getattr_postfilter (meta, &args->in, &args->out); +return BPF_FUSE_CONTINUE ; +} +/* TODO: unify with overlayfs */ static inline int fuse_do_getattr (const struct path *path,struct kstat *stat,u32 request_mask,unsigned int flags)
@@ -2831,6 +3333,7 @@ int fuse_bpf_getattr(int *out, struct inode *inode, const struct dentry *entry, { return bpf_fuse_backing(inode, struct fuse_getattr_args, out, fuse_getattr_initialize_in, fuse_getattr_initialize_out, + fuse_getattr_prefilter, fuse_getattr_postfilter, fuse_getattr_backing, fuse_getattr_finalize, entry, stat, request_mask, flags); }
@@ -2910,6 +3413,22 @@ static int fuse_setattr_initialize_out(struct bpf_fuse_args *fa, struct fuse_setreturn 0 ; } +static int fuse_setattr_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_setattr_args *args) +{ +if (ops->setattr_prefilter) +return ops->setattr_prefilter (meta, &args->in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_setattr_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_setattr_args *args) +{ +if (ops->setattr_postfilter) +return ops->setattr_postfilter (meta, &args->in, &args->out); +return BPF_FUSE_CONTINUE ; +} +static int fuse_setattr_backing (struct bpf_fuse_args *fa,int *out,struct dentry *dentry,struct iattr *attr,struct file *file) {
@@ -2947,6 +3466,7 @@ int fuse_bpf_setattr(int *out, struct inode *inode, struct dentry *dentry, struc { return bpf_fuse_backing(inode, struct fuse_setattr_args, out, fuse_setattr_initialize_in, fuse_setattr_initialize_out, + fuse_setattr_prefilter, fuse_setattr_postfilter, fuse_setattr_backing, fuse_setattr_finalize, dentry, attr, file); }
@@ -2976,6 +3496,22 @@ static int fuse_statfs_initialize_out(struct bpf_fuse_args *fa, struct fuse_statreturn 0 ; } +static int fuse_statfs_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_statfs_out *out) +{ +if (ops->statfs_prefilter) +return ops->statfs_prefilter (meta); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_statfs_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_statfs_out *out) +{ +if (ops->statfs_postfilter) +return ops->statfs_postfilter (meta, out); +return BPF_FUSE_CONTINUE ; +} +static int fuse_statfs_backing (struct bpf_fuse_args *fa,int *out,struct dentry *dentry,struct kstatfs *buf) {
@@ -3011,6 +3547,7 @@ int fuse_bpf_statfs(int *out, struct inode *inode, struct dentry *dentry, struct { return bpf_fuse_backing(dentry->d_inode, struct fuse_statfs_out, out, fuse_statfs_initialize_in, fuse_statfs_initialize_out, + fuse_statfs_prefilter, fuse_statfs_postfilter, fuse_statfs_backing, fuse_statfs_finalize, dentry, buf); }
@@ -3080,6 +3617,22 @@ static int fuse_get_link_initialize_out(struct bpf_fuse_args *fa, struct fuse_gereturn 0 ; } +static int fuse_get_link_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_get_link_args *args) +{ +if (ops->get_link_prefilter) +return ops->get_link_prefilter (meta, &args->name); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_get_link_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_get_link_args *args) +{ +if (ops->get_link_postfilter) +return ops->get_link_postfilter (meta, &args->name); +return BPF_FUSE_CONTINUE ; +} +static int fuse_get_link_backing (struct bpf_fuse_args *fa,const char **out,struct inode *inode,struct dentry *dentry,struct delayed_call *callback)
@@ -3119,6 +3672,7 @@ int fuse_bpf_get_link(const char **out, struct inode *inode, struct dentry *dent { return bpf_fuse_backing(inode, struct fuse_get_link_args, out, fuse_get_link_initialize_in, fuse_get_link_initialize_out, + fuse_get_link_prefilter, fuse_get_link_postfilter, fuse_get_link_backing, fuse_get_link_finalize, inode, dentry, callback); }
@@ -3169,6 +3723,22 @@ static int fuse_symlink_initialize_out(struct bpf_fuse_args *fa, struct fuse_symreturn 0 ; } +static int fuse_symlink_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_symlink_args *args) +{ +if (ops->symlink_prefilter) +return ops->symlink_prefilter (meta, &args->name, &args->path); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_symlink_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_symlink_args *args) +{ +if (ops->symlink_postfilter) +return ops->symlink_postfilter (meta, &args->name, &args->path); +return BPF_FUSE_CONTINUE ; +} +static int fuse_symlink_backing (struct bpf_fuse_args *fa,int *out,struct inode *dir,struct dentry *entry,const char *link,int len) {
@@ -3219,6 +3789,7 @@ int fuse_bpf_symlink(int *out, struct inode *dir, struct dentry *entry, const c { return bpf_fuse_backing(dir, struct fuse_symlink_args, out, fuse_symlink_initialize_in, fuse_symlink_initialize_out, + fuse_symlink_prefilter, fuse_symlink_postfilter, fuse_symlink_backing, fuse_symlink_finalize, dir, entry, link, len); }
@@ -3292,6 +3863,22 @@ static int fuse_readdir_initialize_out(struct bpf_fuse_args *fa, struct fuse_reareturn 0 ; } +static int fuse_readdir_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_read_args *args) +{ +if (ops->readdir_prefilter) +return ops->readdir_prefilter (meta, &args->in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_readdir_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_read_args *args) +{ +if (ops->readdir_postfilter) +return ops->readdir_postfilter (meta, &args->in, &args->out, &args->buffer); +return BPF_FUSE_CONTINUE ; +} +struct fusebpf_ctx {struct dir_context ctx;u8 *addr;
@@ -3415,6 +4002,7 @@ int fuse_bpf_readdir(int *out, struct inode *inode, struct file *file, struct di again: ret = bpf_fuse_backing(inode, struct fuse_read_args, out, fuse_readdir_initialize_in, fuse_readdir_initialize_out, + fuse_readdir_prefilter, fuse_readdir_postfilter, fuse_readdir_backing, fuse_readdir_finalize, file, ctx, &force_again, &allow_force, is_continued);if (force_again && *out >=0 ) {
@@ -3451,6 +4039,22 @@ static int fuse_access_initialize_out(struct bpf_fuse_args *fa, struct fuse_accereturn 0 ; } +static int fuse_access_prefilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_access_in *in) +{ +if (ops->access_prefilter) +return ops->access_prefilter (meta, in); +return BPF_FUSE_CONTINUE ; +} + +static int fuse_access_postfilter (struct fuse_ops *ops,struct bpf_fuse_meta_info *meta, +struct fuse_access_in *in) +{ +if (ops->access_postfilter) +return ops->access_postfilter (meta, in); +return BPF_FUSE_CONTINUE ; +} +static int fuse_access_backing (struct bpf_fuse_args *fa,int *out,struct inode *inode,int mask) {struct fuse_inode *fi =get_fuse_inode (inode);
@@ -3469,6 +4073,7 @@ int fuse_bpf_access(int *out, struct inode *inode, int mask) { return bpf_fuse_backing(inode, struct fuse_access_in, out, fuse_access_initialize_in, fuse_access_initialize_out, + fuse_access_prefilter, fuse_access_postfilter, fuse_access_backing, fuse_access_finalize, inode, mask); }
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 31/36 fuse-bpf: Add userspace pre/post filters
In reply to Daniel RosenbergThis allows fuse-bpf to call out to userspace to handle pre and post filters. Any of the inputs may be changed by the prefilter, so we must handle up to 3 outputs. For the postfilter, our inputs include the output arguments, so we must handle up to 5 inputs.
Additionally, we add an extension for passing the return code of the backing call to the postfilter, adding one additional possible output bringing the total to 4.
As long as you don't request both pre-filter and post-filter in userspace, we will end up doing fewer round trips to userspace.
--- fs/fuse/backing.c | 179 ++++++++++++++++++++++++++++++++++++++ fs/fuse/dev.c | 2 + fs/fuse/dir.c | 6 +- fs/fuse/fuse_i.h | 33 ++++++- include/linux/bpf_fuse.h | 1 + include/uapi/linux/fuse.h | 1 + 6 files changed, 217 insertions(+), 5 deletions(-)
fs/fuse/backing.c +179 -0
@@ -16,6 +16,163 @@#include <linux/splice.h> #include <linux/uio.h> +static void set_in_args (struct fuse_in_arg *dst,struct bpf_fuse_arg *src) +{ +if (src->is_buffer) { +struct fuse_buffer *buffer = src->buffer; + + *dst = (struct fuse_in_arg ) { + .size = buffer->size, + .value = buffer->data, + }; + }else { + *dst = (struct fuse_in_arg ) { + .size = src->size, + .value = src->value, + }; + } +} + +static void set_out_args (struct fuse_arg *dst,struct bpf_fuse_arg *src) +{ +if (src->is_buffer) { +struct fuse_buffer *buffer = src->buffer; + +// Userspace out args presents as much space as needed + *dst = (struct fuse_arg ) { + .size = buffer->max_size, + .value = buffer->data, + }; + }else { + *dst = (struct fuse_arg ) { + .size = src->size, + .value = src->value, + }; + } +} + +static int get_err_in (uint32_t error,struct fuse_in_arg *ext) +{ +struct fuse_ext_header *xh; +uint32_t *err_in; +uint32_t err_in_size =fuse_ext_size (sizeof (*err_in)); + + xh =extend_arg (ext, err_in_size); +if (!xh) +return -ENOMEM ; + xh->size = err_in_size; + xh->type =FUSE_ERROR_IN ; + + err_in = (uint32_t *)&xh[1 ]; + *err_in = error; +return 0 ; +} + +static int get_filter_ext (struct fuse_args *args) +{ +struct fuse_in_arg ext = { .size =0 , .value =NULL }; +int err =0 ; + +if (args->is_filter) + err =get_err_in (args->error_in, &ext); +if (!err && ext.size) { +WARN_ON (args->in_numargs >=ARRAY_SIZE (args->in_args)); + args->is_ext = true; + args->ext_idx = args->in_numargs++; + args->in_args[args->ext_idx] = ext; + }else { +kfree (ext.value); + } +return err; +} + +static ssize_t fuse_bpf_simple_request (struct fuse_mount *fm,struct bpf_fuse_args *fa, +unsigned short in_numargs,unsigned short out_numargs, +struct bpf_fuse_arg *out_arg_array,bool add_out_to_in) +{ +int i; +ssize_t res; + +struct fuse_args args = { + .nodeid = fa->info.nodeid, + .opcode = fa->info.opcode, + .error_in = fa->info.error_in, + .in_numargs = in_numargs, + .out_numargs = out_numargs, + .force = !!(fa->flags &FUSE_BPF_FORCE ), + .out_argvar = !!(fa->flags &FUSE_BPF_OUT_ARGVAR ), + .is_lookup = !!(fa->flags &FUSE_BPF_IS_LOOKUP ), + .is_filter = true, + }; + +/* All out args must be writeable */ +for (i =0 ; i < out_numargs; ++i) { +struct fuse_buffer *buffer; + +if (!out_arg_array[i].is_buffer) +continue ; + buffer = out_arg_array[i].buffer; +if (!bpf_fuse_get_writeable (buffer, buffer->max_size, true)) +return -ENOMEM ; + } + +/* Set in args */ +for (i =0 ; i < fa->in_numargs; ++i) +set_in_args (&args.in_args[i], &fa->in_args[i]); +if (add_out_to_in) { +for (i =0 ; i < fa->out_numargs; ++i) { +set_in_args (&args.in_args[fa->in_numargs + i], &fa->out_args[i]); + } + } + +/* Set out args */ +for (i =0 ; i < out_numargs; ++i) +set_out_args (&args.out_args[i], &out_arg_array[i]); + +if (out_arg_array[out_numargs -1 ].is_buffer) { +struct fuse_buffer *buff = out_arg_array[out_numargs -1 ].buffer; + +if (buff->flags &BPF_FUSE_VARIABLE_SIZE ) + args.out_argvar = true; + } +if (add_out_to_in) { + res =get_filter_ext (&args); +if (res) +return res; + } + res =fuse_simple_request (fm, &args); + +/* update used areas of buffers */ +for (i =0 ; i < out_numargs; ++i) +if (out_arg_array[i].is_buffer && + (out_arg_array[i].buffer->flags &BPF_FUSE_VARIABLE_SIZE )) + out_arg_array[i].buffer->size = args.out_args[i].size; + fa->ret = args.ret; + +free_ext_value (&args); + +return res; +} + +static ssize_t fuse_prefilter_simple_request (struct fuse_mount *fm,struct bpf_fuse_args *fa) +{ +uint32_t out_args = fa->in_numargs; + +// mkdir and company are not permitted to change the name. This should be done at lookup +// Thus, these can't be set by the userspace prefilter +if (fa->in_args[fa->in_numargs -1 ].is_buffer && + (fa->in_args[fa->in_numargs -1 ].buffer->flags &BPF_FUSE_IMMUTABLE )) + out_args--; +return fuse_bpf_simple_request (fm, fa, fa->in_numargs, out_args, + fa->in_args, false); +} + +static ssize_t fuse_postfilter_simple_request (struct fuse_mount *fm,struct bpf_fuse_args *fa) +{ +return fuse_bpf_simple_request (fm, fa, fa->in_numargs + fa->out_numargs, fa->out_numargs, + fa->out_args, true); +} +static inline void bpf_fuse_set_in_immutable (struct bpf_fuse_args *fa) {int i;
@@ -62,9 +219,11 @@ static inline void bpf_fuse_free_alloced(struct bpf_fuse_args *fa) ({ \ struct fuse_inode *fuse_inode = get_fuse_inode(inode); \ struct fuse_ops *fuse_ops = fuse_inode->bpf_ops; \ + struct fuse_mount *fm = get_fuse_mount(inode); \ struct bpf_fuse_args fa = { 0 }; \ bool initialized = false; \ bool handled = false; \ + bool locked; \ ssize_t res; \ int bpf_next; \ io feo = { 0 }; \
@@ -90,6 +249,16 @@ static inline void bpf_fuse_free_alloced(struct bpf_fuse_args *fa)break ; \ } \ \ +if (bpf_next ==BPF_FUSE_USER_PREFILTER ) { \ + locked =fuse_lock_inode (inode); \ + res =fuse_prefilter_simple_request (fm, &fa); \ +fuse_unlock_inode (inode, locked); \ +if (res <0 ) { \ + error = res; \ +break ; \ + } \ + bpf_next = fa.ret; \ + } \bpf_fuse_set_in_immutable (&fa); \ \ error =initialize_out (&fa, &feo, args); \
@@ -119,6 +288,16 @@ static inline void bpf_fuse_free_alloced(struct bpf_fuse_args *fa)break ; \ } \ \ +if (!(bpf_next ==BPF_FUSE_USER_POSTFILTER )) \ +break ; \ + \ + locked =fuse_lock_inode (inode); \ + res =fuse_postfilter_simple_request (fm, &fa); \ +fuse_unlock_inode (inode, locked); \ +if (res <0 ) { \ + error = res; \ +break ; \ + } \ }while (false); \ \if (initialized && handled) { \
fs/fuse/dev.c +2 -0
@@ -521,6 +521,8 @@ ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args)BUG_ON (args->out_numargs ==0 ); ret = args->out_args[args->out_numargs -1 ].size; } +if (args->is_filter && args->is_ext) + args->ret = req->out.h.error;fuse_put_request (req);return ret;
fs/fuse/dir.c +3 -3
@@ -640,7 +640,7 @@ static int get_security_context(struct dentry *entry, umode_t mode,return err; } -static void *extend_arg (struct fuse_in_arg *buf,u32 bytes) +void *extend_arg (struct fuse_in_arg *buf,u32 bytes) {void *p;u32 newlen = buf->size + bytes;
@@ -660,7 +660,7 @@ static void *extend_arg(struct fuse_in_arg *buf, u32 bytes)return p + newlen - bytes; } -static u32 fuse_ext_size (size_t size) +u32 fuse_ext_size (size_t size) {return FUSE_REC_ALIGN (sizeof (struct fuse_ext_header ) + size); }
@@ -720,7 +720,7 @@ static int get_create_ext(struct fuse_args *args,return err; } -static void free_ext_value (struct fuse_args *args) +void free_ext_value (struct fuse_args *args) {if (args->is_ext)kfree (args->in_args[args->ext_idx].value);
fs/fuse/fuse_i.h +31 -2
@@ -324,6 +324,17 @@ struct fuse_page_desc {unsigned int offset; }; +/* To deal with bpf pre and post filters in userspace calls, we must support +* passing the inputs and outputs as inputs, and we must have enough space in +* outputs to handle all of the inputs. Plus one more for extensions. +*/ +#define FUSE_EXTENDED_MAX_ARGS_IN (FUSE_MAX_ARGS_IN + FUSE_MAX_ARGS_OUT + 1) +#if FUSE_MAX_ARGS_IN >FUSE_MAX_ARGS_OUT +#define FUSE_EXTENDED_MAX_ARGS_OUT FUSE_MAX_ARGS_IN +#else +#define FUSE_EXTENDED_MAX_ARGS_OUT FUSE_MAX_ARGS_OUT +#endif +struct fuse_args {uint64_t nodeid;uint32_t opcode;
@@ -342,10 +353,12 @@ struct fuse_args { bool page_replace:1; bool may_block:1; bool is_ext:1; + bool is_filter:1; bool is_lookup:1; bool via_ioctl:1; -struct fuse_in_arg in_args[3 ]; -struct fuse_arg out_args[2 ]; +uint32_t ret; +struct fuse_in_arg in_args[FUSE_EXTENDED_MAX_ARGS_IN ]; +struct fuse_arg out_args[FUSE_EXTENDED_MAX_ARGS_OUT ];void (*end)(struct fuse_mount *fm,struct fuse_args *args,int error); };
@@ -1194,6 +1207,22 @@ void fuse_request_end(struct fuse_req *req);void fuse_abort_conn (struct fuse_conn *fc);void fuse_wait_aborted (struct fuse_conn *fc); +/** +* Allocated/Reallocate extended header information +* Returns pointer to start of most recent allocation +*/ +void *extend_arg (struct fuse_in_arg *buf,u32 bytes); + +/** +* Returns adjusted size field for extensions +*/ +u32 fuse_ext_size (size_t size); + +/** +* Free allocated extended header information +*/ +void free_ext_value (struct fuse_args *args); +/** * Invalidate inode attributes */
include/linux/bpf_fuse.h +1 -0
@@ -64,6 +64,7 @@ struct bpf_fuse_args {uint32_t in_numargs;uint32_t out_numargs;uint32_t flags; +uint32_t ret;struct bpf_fuse_arg in_args[FUSE_MAX_ARGS_IN ];struct bpf_fuse_arg out_args[FUSE_MAX_ARGS_OUT ]; };
include/uapi/linux/fuse.h +1 -0
@@ -566,6 +566,7 @@ enum fuse_ext_type {/* Types 0..31 are reserved for fuse_secctx_header */ FUSE_MAX_NR_SECCTX =31 ,FUSE_EXT_GROUPS =32 , + FUSE_ERROR_IN = 33, }; enum fuse_opcode {
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 32/36 WIP: fuse-bpf: add error_out
In reply to Daniel Rosenbergerror_out field will allow differentiating between altering error code from bpf programs, and the bpf program returning an error. TODO
--- include/linux/bpf_fuse.h | 1 + 1 file changed, 1 insertion(+)
include/linux/bpf_fuse.h +1 -0
@@ -57,6 +57,7 @@ struct bpf_fuse_meta_info {uint64_t nodeid;uint32_t opcode;uint32_t error_in; +uint32_t error_out;// TODO: struct_op programs may set this to alter reported error code };struct bpf_fuse_args {
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 33/36 fuse-bpf: Add default filter op
In reply to Daniel RosenbergAdd a default bpf func to call if the specific one is not present. Useful if you wish to track when different ops are handled.
--- fs/fuse/backing.c | 136 +++++++++++++++++++++------------------ include/linux/bpf_fuse.h | 2 + include/uapi/linux/bpf.h | 1 + 3 files changed, 77 insertions(+), 62 deletions(-)
fs/fuse/backing.c +74 -62
@@ -244,6 +244,12 @@ static inline void bpf_fuse_free_alloced(struct bpf_fuse_args *fa) &fa.info, &feo); \ else \ bpf_next =BPF_FUSE_CONTINUE ; \ +if (bpf_next ==BPF_FUSE_CALL_DEFAULT ) { \ +if (fuse_ops->default_filter) \ + bpf_next = fuse_ops->default_filter (&fa.info); \ +else \ + bpf_next =BPF_FUSE_CONTINUE ; \ + } \if (bpf_next <0 ) { \ error = bpf_next; \break ; \
@@ -283,6 +289,12 @@ static inline void bpf_fuse_free_alloced(struct bpf_fuse_args *fa) fa.info.opcode |=FUSE_POSTFILTER ; \if (bpf_next ==BPF_FUSE_POSTFILTER ) \ bpf_next =call_postfilter (fuse_ops, &fa.info, &feo);\ +if (bpf_next ==BPF_FUSE_CALL_DEFAULT ) { \ +if (fuse_ops->default_filter) \ + bpf_next = fuse_ops->default_filter (&fa.info); \ +else \ + bpf_next =BPF_FUSE_CONTINUE ; \ + } \if (bpf_next <0 ) { \ error = bpf_next; \break ; \
@@ -611,7 +623,7 @@ static int fuse_open_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *if (ops->opendir_prefilter)return ops->opendir_prefilter (meta, &open->in); } -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_open_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -625,7 +637,7 @@ static int fuse_open_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_infoif (ops->opendir_postfilter)return ops->opendir_postfilter (meta, &open->in, &open->out); } -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_open_backing(struct bpf_fuse_args *fa, int *out,
@@ -767,7 +779,7 @@ static int fuse_create_open_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta {if (ops->create_open_prefilter)return ops->create_open_prefilter (meta, &args->in, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_create_open_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -775,7 +787,7 @@ static int fuse_create_open_postfilter(struct fuse_ops *ops, struct bpf_fuse_met {if (ops->create_open_postfilter)return ops->create_open_postfilter (meta, &args->in, &args->name, &args->entry_out, &args->open_out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }static int fuse_open_file_backing (struct inode *inode,struct file *file)
@@ -931,7 +943,7 @@ static int fuse_release_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->release_prefilter)return ops->release_prefilter (meta, args); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_release_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -939,7 +951,7 @@ static int fuse_release_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_in {if (ops->release_postfilter)return ops->release_postfilter (meta, args); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_releasedir_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -947,7 +959,7 @@ static int fuse_releasedir_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_ {if (ops->releasedir_prefilter)return ops->releasedir_prefilter (meta, args); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_releasedir_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -955,7 +967,7 @@ static int fuse_releasedir_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta {if (ops->releasedir_postfilter)return ops->releasedir_postfilter (meta, args); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_release_backing(struct bpf_fuse_args *fa, int *out,
@@ -1022,7 +1034,7 @@ static int fuse_flush_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->flush_prefilter)return ops->flush_prefilter (meta, args); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_flush_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1030,7 +1042,7 @@ static int fuse_flush_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->flush_postfilter)return ops->flush_postfilter (meta, args); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }static int fuse_flush_backing (struct bpf_fuse_args *fa,int *out,struct file *file,fl_owner_t id)
@@ -1102,7 +1114,7 @@ static int fuse_lseek_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->lseek_prefilter)return ops->lseek_prefilter (meta, &args->in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_lseek_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1110,7 +1122,7 @@ static int fuse_lseek_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->lseek_postfilter)return ops->lseek_postfilter (meta, &args->in, &args->out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_lseek_backing(struct bpf_fuse_args *fa, loff_t *out,
@@ -1217,7 +1229,7 @@ static int fuse_copy_file_range_prefilter(struct fuse_ops *ops, struct bpf_fuse_ {if (ops->copy_file_range_prefilter)return ops->copy_file_range_prefilter (meta, &args->in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_copy_file_range_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1225,7 +1237,7 @@ static int fuse_copy_file_range_postfilter(struct fuse_ops *ops, struct bpf_fuse {if (ops->copy_file_range_postfilter)return ops->copy_file_range_postfilter (meta, &args->in, &args->out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_copy_file_range_backing(struct bpf_fuse_args *fa, ssize_t *out, struct file *file_in,
@@ -1303,7 +1315,7 @@ static int fuse_fsync_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->fsync_prefilter)return ops->fsync_prefilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_fsync_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1311,7 +1323,7 @@ static int fuse_fsync_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->fsync_postfilter)return ops->fsync_postfilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_fsync_backing(struct bpf_fuse_args *fa, int *out,
@@ -1376,7 +1388,7 @@ static int fuse_dir_fsync_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_i {if (ops->dir_fsync_prefilter)return ops->fsync_prefilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_dir_fsync_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1384,7 +1396,7 @@ static int fuse_dir_fsync_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_ {if (ops->dir_fsync_postfilter)return ops->dir_fsync_postfilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }int fuse_bpf_dir_fsync (int *out,struct inode *inode,struct file *file,loff_t start,loff_t end,int datasync)
@@ -1466,7 +1478,7 @@ static int fuse_getxattr_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_in {if (ops->getxattr_prefilter)return ops->getxattr_prefilter (meta, &args->in, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_getxattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1474,7 +1486,7 @@ static int fuse_getxattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_i {if (ops->getxattr_postfilter)return ops->getxattr_postfilter (meta, &args->in, &args->name, &args->value, &args->out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_getxattr_backing(struct bpf_fuse_args *fa, int *out,
@@ -1580,7 +1592,7 @@ static int fuse_listxattr_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_i {if (ops->listxattr_prefilter)return ops->listxattr_prefilter (meta, &args->in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_listxattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1588,7 +1600,7 @@ static int fuse_listxattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_ {if (ops->listxattr_postfilter)return ops->listxattr_postfilter (meta, &args->in, &args->value, &args->out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_listxattr_backing(struct bpf_fuse_args *fa, ssize_t *out, struct dentry *dentry,
@@ -1701,7 +1713,7 @@ static int fuse_setxattr_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_in {if (ops->setxattr_prefilter)return ops->setxattr_prefilter (meta, &args->in, &args->name, &args->value); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_setxattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1709,7 +1721,7 @@ static int fuse_setxattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_i {if (ops->setxattr_postfilter)return ops->setxattr_postfilter (meta, &args->in, &args->name, &args->value); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_setxattr_backing(struct bpf_fuse_args *fa, int *out, struct dentry *dentry,
@@ -1777,7 +1789,7 @@ static int fuse_removexattr_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta {if (ops->removexattr_prefilter)return ops->removexattr_prefilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_removexattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1785,7 +1797,7 @@ static int fuse_removexattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_met {if (ops->removexattr_postfilter)return ops->removexattr_postfilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_removexattr_backing(struct bpf_fuse_args *fa, int *out,
@@ -1904,7 +1916,7 @@ static int fuse_file_read_iter_prefilter(struct fuse_ops *ops, struct bpf_fuse_m {if (ops->read_iter_prefilter)return ops->read_iter_prefilter (meta, &args->in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_file_read_iter_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -1912,7 +1924,7 @@ static int fuse_file_read_iter_postfilter(struct fuse_ops *ops, struct bpf_fuse_ {if (ops->read_iter_postfilter)return ops->read_iter_postfilter (meta, &args->in, &args->out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }// TODO: use backing-file.c
@@ -2044,7 +2056,7 @@ static int fuse_write_iter_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_ {if (ops->write_iter_prefilter)return ops->write_iter_prefilter (meta, &args->in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_write_iter_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -2052,7 +2064,7 @@ static int fuse_write_iter_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta {if (ops->write_iter_postfilter)return ops->write_iter_postfilter (meta, &args->in, &args->out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_file_write_iter_backing(struct bpf_fuse_args *fa, ssize_t *out,
@@ -2232,7 +2244,7 @@ static int fuse_file_fallocate_prefilter(struct fuse_ops *ops, struct bpf_fuse_m {if (ops->file_fallocate_prefilter)return ops->file_fallocate_prefilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_file_fallocate_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -2240,7 +2252,7 @@ static int fuse_file_fallocate_postfilter(struct fuse_ops *ops, struct bpf_fuse_ {if (ops->file_fallocate_postfilter)return ops->file_fallocate_postfilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_file_fallocate_backing(struct bpf_fuse_args *fa, int *out,
@@ -2339,7 +2351,7 @@ static int fuse_lookup_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->lookup_prefilter)return ops->lookup_prefilter (meta, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_lookup_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -2347,7 +2359,7 @@ static int fuse_lookup_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->lookup_postfilter)return ops->lookup_postfilter (meta, &args->name, &args->out, &args->bpf_entries); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_lookup_backing(struct bpf_fuse_args *fa, struct dentry **out, struct inode *dir,
@@ -2603,7 +2615,7 @@ static int fuse_mknod_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->mknod_prefilter)return ops->mknod_prefilter (meta, &args->in, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_mknod_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -2611,7 +2623,7 @@ static int fuse_mknod_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->mknod_postfilter)return ops->mknod_postfilter (meta, &args->in, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_mknod_backing(struct bpf_fuse_args *fa, int *out,
@@ -2773,7 +2785,7 @@ static int fuse_mkdir_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->mkdir_prefilter)return ops->mkdir_prefilter (meta, &args->in, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_mkdir_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -2781,7 +2793,7 @@ static int fuse_mkdir_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->mkdir_prefilter)return ops->mkdir_postfilter (meta, &args->in, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }int fuse_bpf_mkdir (int *out,struct inode *dir,struct dentry *entry,umode_t mode)
@@ -2827,7 +2839,7 @@ static int fuse_rmdir_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->rmdir_prefilter)return ops->rmdir_prefilter (meta, name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_rmdir_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -2835,7 +2847,7 @@ static int fuse_rmdir_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->rmdir_postfilter)return ops->rmdir_postfilter (meta, name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_rmdir_backing(struct bpf_fuse_args *fa, int *out,
@@ -3020,7 +3032,7 @@ static int fuse_rename2_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->rename2_prefilter)return ops->rename2_prefilter (meta, &args->in, &args->old_name, &args->new_name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_rename2_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -3028,7 +3040,7 @@ static int fuse_rename2_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_in {if (ops->rename2_postfilter)return ops->rename2_postfilter (meta, &args->in, &args->old_name, &args->new_name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_rename2_backing(struct bpf_fuse_args *fa, int *out,
@@ -3124,7 +3136,7 @@ static int fuse_rename_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->rename_prefilter)return ops->rename_prefilter (meta, &args->in, &args->old_name, &args->new_name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_rename_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -3132,7 +3144,7 @@ static int fuse_rename_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->rename_postfilter)return ops->rename_postfilter (meta, &args->in, &args->old_name, &args->new_name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_rename_backing(struct bpf_fuse_args *fa, int *out,
@@ -3195,7 +3207,7 @@ static int fuse_unlink_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->unlink_prefilter)return ops->unlink_prefilter (meta, name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_unlink_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -3203,7 +3215,7 @@ static int fuse_unlink_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->unlink_postfilter)return ops->unlink_postfilter (meta, name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }static int fuse_unlink_backing (struct bpf_fuse_args *fa,int *out,struct inode *dir,struct dentry *entry)
@@ -3300,7 +3312,7 @@ static int fuse_link_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info * {if (ops->link_prefilter)return ops->link_prefilter (meta, &args->in, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_link_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -3308,7 +3320,7 @@ static int fuse_link_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->link_postfilter)return ops->link_postfilter (meta, &args->in, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }
@@ -3433,7 +3445,7 @@ static int fuse_getattr_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->getattr_prefilter)return ops->getattr_prefilter (meta, &args->in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_getattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -3441,7 +3453,7 @@ static int fuse_getattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_in {if (ops->getattr_postfilter)return ops->getattr_postfilter (meta, &args->in, &args->out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }/* TODO: unify with overlayfs */
@@ -3597,7 +3609,7 @@ static int fuse_setattr_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->setattr_prefilter)return ops->setattr_prefilter (meta, &args->in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_setattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -3605,7 +3617,7 @@ static int fuse_setattr_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_in {if (ops->setattr_postfilter)return ops->setattr_postfilter (meta, &args->in, &args->out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_setattr_backing(struct bpf_fuse_args *fa, int *out,
@@ -3680,7 +3692,7 @@ static int fuse_statfs_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->statfs_prefilter)return ops->statfs_prefilter (meta); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_statfs_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -3688,7 +3700,7 @@ static int fuse_statfs_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->statfs_postfilter)return ops->statfs_postfilter (meta, out); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_statfs_backing(struct bpf_fuse_args *fa, int *out,
@@ -3801,7 +3813,7 @@ static int fuse_get_link_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_in {if (ops->get_link_prefilter)return ops->get_link_prefilter (meta, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_get_link_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -3809,7 +3821,7 @@ static int fuse_get_link_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_i {if (ops->get_link_postfilter)return ops->get_link_postfilter (meta, &args->name); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_get_link_backing(struct bpf_fuse_args *fa, const char **out,
@@ -3907,7 +3919,7 @@ static int fuse_symlink_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->symlink_prefilter)return ops->symlink_prefilter (meta, &args->name, &args->path); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_symlink_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -3915,7 +3927,7 @@ static int fuse_symlink_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_in {if (ops->symlink_postfilter)return ops->symlink_postfilter (meta, &args->name, &args->path); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_symlink_backing(struct bpf_fuse_args *fa, int *out,
@@ -4047,7 +4059,7 @@ static int fuse_readdir_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->readdir_prefilter)return ops->readdir_prefilter (meta, &args->in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_readdir_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -4055,7 +4067,7 @@ static int fuse_readdir_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_in {if (ops->readdir_postfilter)return ops->readdir_postfilter (meta, &args->in, &args->out, &args->buffer); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }struct fusebpf_ctx {
@@ -4223,7 +4235,7 @@ static int fuse_access_prefilter(struct fuse_ops *ops, struct bpf_fuse_meta_info {if (ops->access_prefilter)return ops->access_prefilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; } static int fuse_access_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_info *meta,
@@ -4231,7 +4243,7 @@ static int fuse_access_postfilter(struct fuse_ops *ops, struct bpf_fuse_meta_inf {if (ops->access_postfilter)return ops->access_postfilter (meta, in); -return BPF_FUSE_CONTINUE ; +return BPF_FUSE_CALL_DEFAULT ; }static int fuse_access_backing (struct bpf_fuse_args *fa,int *out,struct inode *inode,int mask)
include/linux/bpf_fuse.h +2 -0
@@ -86,6 +86,8 @@ static inline unsigned bpf_fuse_arg_size(const struct bpf_fuse_arg *arg) }struct fuse_ops { +uint32_t (*default_filter)(const struct bpf_fuse_meta_info *meta); +uint32_t (*open_prefilter)(const struct bpf_fuse_meta_info *meta,struct fuse_open_in *in); uint32_t (*open_postfilter)(const struct bpf_fuse_meta_info *meta,
include/uapi/linux/bpf.h +1 -0
@@ -7467,6 +7467,7 @@ struct bpf_iter_num {#define BPF_FUSE_USER_PREFILTER 2#define BPF_FUSE_POSTFILTER 3#define BPF_FUSE_USER_POSTFILTER 4 +#define BPF_FUSE_CALL_DEFAULT 5/* Op Code Filter values for BPF Programs */ #define FUSE_OPCODE_FILTER 0x0ffff
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 34/36 tools: Add FUSE, update bpf includes
In reply to Daniel RosenbergUpdates the bpf includes under tools, and adds fuse
--- tools/include/uapi/linux/bpf.h | 13 + tools/include/uapi/linux/fuse.h | 1197 +++++++++++++++++++++++++++++++ 2 files changed, 1210 insertions(+) create mode 100644 tools/include/uapi/linux/fuse.h
tools/include/uapi/linux/bpf.h +13 -0
@@ -7461,4 +7461,17 @@ struct bpf_iter_num {__u64 __opaque[1 ]; } __attribute__((aligned(8))); +/* Return Codes for Fuse BPF struct_op programs */ +#define BPF_FUSE_CONTINUE 0 +#define BPF_FUSE_USER 1 +#define BPF_FUSE_USER_PREFILTER 2 +#define BPF_FUSE_POSTFILTER 3 +#define BPF_FUSE_USER_POSTFILTER 4 +#define BPF_FUSE_CALL_DEFAULT 5 + +/* Op Code Filter values for BPF Programs */ +#define FUSE_OPCODE_FILTER 0x0ffff +#define FUSE_PREFILTER 0x10000 +#define FUSE_POSTFILTER 0x20000 +#endif /* _UAPI__LINUX_BPF_H__ */
tools/include/uapi/linux/fuse.h new file +1197 -0
1,197 lines not on this page · raw message
Signature · 1 line
2.44.0.478.gd926399ef9-goog
RFC PATCH v4 35/36 fuse-bpf: Add selftests
In reply to Daniel RosenbergAdds basic selftests for fuse. These check that you can add fuse_op programs, and perform basic operations
--- .../selftests/filesystems/fuse/.gitignore | 2 + .../selftests/filesystems/fuse/Makefile | 188 ++ .../testing/selftests/filesystems/fuse/OWNERS | 2 + .../selftests/filesystems/fuse/bpf_common.h | 51 + .../selftests/filesystems/fuse/bpf_loader.c | 597 ++++ .../testing/selftests/filesystems/fuse/fd.txt | 21 + .../selftests/filesystems/fuse/fd_bpf.bpf.c | 397 +++ .../selftests/filesystems/fuse/fuse_daemon.c | 300 ++ .../selftests/filesystems/fuse/fuse_test.c | 2476 +++++++++++++++++ .../selftests/filesystems/fuse/test.bpf.c | 1045 +++++++ .../filesystems/fuse/test_framework.h | 172 ++ .../selftests/filesystems/fuse/test_fuse.h | 494 ++++ 12 files changed, 5745 insertions(+) create mode 100644 tools/testing/selftests/filesystems/fuse/.gitignore create mode 100644 tools/testing/selftests/filesystems/fuse/Makefile create mode 100644 tools/testing/selftests/filesystems/fuse/OWNERS create mode 100644 tools/testing/selftests/filesystems/fuse/bpf_common.h create mode 100644 tools/testing/selftests/filesystems/fuse/bpf_loader.c create mode 100644 tools/testing/selftests/filesystems/fuse/fd.txt create mode 100644 tools/testing/selftests/filesystems/fuse/fd_bpf.bpf.c create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_daemon.c create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_test.c create mode 100644 tools/testing/selftests/filesystems/fuse/test.bpf.c create mode 100644 tools/testing/selftests/filesystems/fuse/test_framework.h create mode 100644 tools/testing/selftests/filesystems/fuse/test_fuse.h
tools/testing/selftests/filesystems/fuse/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +fuse_test +*.raw
tools/testing/selftests/filesystems/fuse/Makefile new file +188 -0
188 lines not on this page · raw message
tools/testing/selftests/filesystems/fuse/OWNERS new file +2 -0
@@ -0,0 +1,2 @@ +# include OWNERS from the authoritative android-mainline branch +include kernel/common:android-mainline:/tools/testing/selftests/filesystems/incfs/OWNERS
tools/testing/selftests/filesystems/fuse/bpf_common.h new file +51 -0
51 lines not on this page · raw message
tools/testing/selftests/filesystems/fuse/bpf_loader.c new file +597 -0
597 lines not on this page · raw message
tools/testing/selftests/filesystems/fuse/fd.txt new file +21 -0
@@ -0,0 +1,21 @@ +fuse_daemon $* +cd fd-dst +ls +cd show +ls +fsstress -s 123 -d . -p 4 -n 100 -l5 +echo test > wibble +ls +cat wibble +fallocate -l 1000 wobble +mkdir testdir +mkdir tmpdir +rmdir tmpdir +touch tmp +mv tmp tmp2 +rm tmp2 + +# FUSE_LINK +echo "ln_src contents" > ln_src +ln ln_src ln_link +cat ln_link
tools/testing/selftests/filesystems/fuse/fd_bpf.bpf.c new file +397 -0
397 lines not on this page · raw message
tools/testing/selftests/filesystems/fuse/fuse_daemon.c new file +300 -0
300 lines not on this page · raw message
tools/testing/selftests/filesystems/fuse/fuse_test.c new file +2476 -0
1,442 lines not on this page · raw message
tools/testing/selftests/filesystems/fuse/test.bpf.c new file +1045 -0
1,045 lines not on this page · raw message
tools/testing/selftests/filesystems/fuse/test_framework.h new file +172 -0
172 lines not on this page · raw message
tools/testing/selftests/filesystems/fuse/test_fuse.h new file +494 -0
494 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Part of the diff is not shown here. View the raw message.
RFC PATCH v4 36/36 fuse: Provide easy way to test fuse struct_op call
In reply to Daniel RosenbergThis is useful for quickly testing a struct_op program. I've been using this set up to test verifier changes.
I'll eventually move those sorts of tests to bpf selftests
--- fs/fuse/inode.c | 70 ++ .../selftests/filesystems/fuse/Makefile | 1 + .../filesystems/fuse/struct_op_test.bpf.c | 642 ++++++++++++++++++ 3 files changed, 713 insertions(+) create mode 100644 tools/testing/selftests/filesystems/fuse/struct_op_test.bpf.c
fs/fuse/inode.c +70 -0
@@ -2184,16 +2184,83 @@ static void fuse_fs_cleanup(void)static struct kobject *fuse_kobj; +static char struct_op_name[BPF_FUSE_NAME_MAX ]; +static struct fuse_ops *fop =NULL ; + +static ssize_t struct_op_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +size_t max = count; + +if (max >BPF_FUSE_NAME_MAX ) max =BPF_FUSE_NAME_MAX ; +strncpy (struct_op_name, buf, max); +if (struct_op_name[max-1 ] =='\n' ) + struct_op_name[max-1 ] =0 ; +put_fuse_ops (fop); + fop =find_fuse_ops (struct_op_name); +if (!fop) +printk ("No struct op named %s found" , struct_op_name); + +return count; +} + +static ssize_t struct_op_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct fuse_ops *op; +uint32_t result =0 ; +struct bpf_fuse_meta_info meta; +struct fuse_mkdir_in in; +struct fuse_buffer name; +char name_buff[10 ] ="test" ; + + name.data = &name_buff[0 ]; + name.flags =BPF_FUSE_VARIABLE_SIZE ; + name.max_size =10 ; + name.size =5 ; + + op = fop; +if (!op) { +printk ("Could not find fuse_op for %s" , struct_op_name); +return 0 ; + } + +if (op->mkdir_prefilter) + result = op->mkdir_prefilter (&meta, &in, &name); +else +printk ("No func!!" ); + +printk ("in->mode:%d, name:%s result:%d" , in.mode, (char *)name.data, result); +return sprintf (buf,"%d dyn:%s\n" , result, (char *)name.data); +} + +static struct kobj_attribute test_attr =__ATTR_RW (struct_op); + +static struct attribute *test_attrs[] = { + &test_attr.attr, +NULL , +}; + +static const struct attribute_group test_attr_group = { + .attrs = test_attrs, +}; +static int fuse_sysfs_init (void ) {int err; +memset (struct_op_name,0 ,BPF_FUSE_NAME_MAX ); fuse_kobj =kobject_create_and_add ("fuse" , fs_kobj);if (!fuse_kobj) { err = -ENOMEM ; goto out_err; } + err =sysfs_create_group (fuse_kobj, &test_attr_group); +if (err) + goto tmp; + err =sysfs_create_mount_point (fuse_kobj,"connections" );if (err) goto out_fuse_unregister;
@@ -2202,6 +2269,8 @@ static int fuse_sysfs_init(void) out_fuse_unregister:kobject_put (fuse_kobj); +tmp: +sysfs_remove_group (fuse_kobj, &test_attr_group); out_err:return err; }
@@ -2209,6 +2278,7 @@ static int fuse_sysfs_init(void)static void fuse_sysfs_cleanup (void ) {sysfs_remove_mount_point (fuse_kobj,"connections" ); +sysfs_remove_group (fuse_kobj, &test_attr_group);kobject_put (fuse_kobj); }
tools/testing/selftests/filesystems/fuse/Makefile +1 -0
@@ -52,6 +52,7 @@ SELFTESTS:=$(TOOLSDIR)/testing/selftests/ LDLIBS := -lpthread -lelf -lz TEST_GEN_PROGS := fuse_test fuse_daemon TEST_GEN_FILES := \ + struct_op_test.bpf.o \ test.skel.h \ fd.sh \
tools/testing/selftests/filesystems/fuse/struct_op_test.bpf.c new file +642 -0
642 lines not on this page · raw message
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Amir Goldstein
maintainerHi Daniel,
Quoted 2 lines · Daniel Rosenberg
I've recently gotten some time to re-focus on fuse-bpf efforts, and
Glad to hear that this effort is still on track!
Quoted 12 lines
had some questions on how to best integrate with recent changes that have landed in the last year. I've included a rebased version (ontop of bpf-next
e63985ecd226("bpf, riscv64/cfi: Support kCFI + BPF on riscv64") of the old patchset for reference here.On the bpf end, I'm struggling a little bit with the interface for selecting programs. I'd like to be able to pass the map id to fuse, since that's a value userspace already knows the program by. Would it be reasonable to either pass that ID down to the registration function, or otherwise provide a path for a separate module to translate from a map id to a
struct_opprogram?
Quoted 10 lines
On the fuse end, I'm wondering how the interface will extend to directories. At LSFMMBPF last year, some people brought up concerns with the interface we had, specifically that it required opens to get fds, which we'd then use to respond to lookup requests, adding a lot of extra overhead. I had been planning to switch to a path that the response would supply instead, likely limited by
RESOLVE_BENEATH. That seems pretty different from Fuse Passthrough's approach. Are there any current plans on how that interface will extend for a directory passthrough?
My plan was to start from passthrough ioctl with O_PATH fd on lookup and deal with performance improvements later when there are actual workloads that report a problem and that depends where the overhead is.
Is it with the opening of O_PATH fds?
Is it with the passthtough ioctls?
If latter, then when fuse uring is merged, I think we could get loose the ioctls anyway.
Quoted 6 lines
Could someone clarify why passthrough has an extra layer to register for use as a backing file? Does the ioctl provide some additional tracking purpose? I recall there being some security issue around directly responding with the fd. In fuse-bpf, we were handling this by responding to the fuse request via an ioctl in those cases.
The original reason was to mitigate an attack vector of fooling a privileged process into writing the fd (number) to /dev/fuse to gain access to a backing file this way.
The fuse-bpf way of doing all responds with ioctls seems fine for this purpose, but note that the explicit setup also provides feedback to the server in case the passthrough cannot be accomplished for a specific inode (e.g. because of stacking depths overflow) and that is a big benefit IMO.
Quoted 5 lines
Passthrough also maintains a separate cred instance for each backing file. I had been planning to have a single one for the userspace daemon, likely grabbed during the init response. I'm unsure how the current Passthrough method there should scale to directories.
Using a global cred should be fine, just as overlayfs does. The specific inode passthrough setup could mention if the global cred should be used.
However, note that overlayfs needs to handle some special cases when using mounter creds (e.g.: ovl_create_or_link() and dropping of CAP_SYS_RESOURCE).
If you are going to mimic all this, better have that in the stacking fs common code.
Quoted 7 lines
Now on to my plans. Struct ops programs have more dynamic support now [1]. I'm hoping to be able to move most of the Fuse BPF related code to live closer to Fuse, and to have it more neatly encapsulated when building as a module. I'm not sure if everything that's needed for that exists, but I need to play with it a bit more to understand what I'm missing. I'll probably show up at bpf office hours at some point.
Quoted 7 lines
Struct ops have proper multi page support now [2], which removes another patch. I'm still slightly over the struct ops limit, but that may change with other changes I'm considering.
I'm very excited to see the new generic stacking filesystem support with backing-file [3]. I imagine in time we'll extend that to have a backing-inode as well, for the various
inode_operations. That will
Yes, that was the plan.
I had initially planned to start an fsstack library, but I found out that this "library" already exists (fs/stack.c), but it has code that is not a good abstraction for ovl/fuse and ecryptfs will not be changed to improve the abstraction, so we first need to burn this lib and start over:
https://github.com/amir73il/linux/commits/fsstack
Then, we can move backing_file.c into fs/stack/.
Quoted 7 lines
definitely involve a lot of refactoring of the way fuse-bpf is currently structured, but it's clearly the right way forward.
I'm glad to see fuse passthrough, which provides a subset of the fuse-bpf functionality, has landed[4]. I'm planning to rework the patch set to integrate better with that. First off, I've been considering splitting up the bpf progam into a dentry, inode, and file
That sounds like a good plan, but also, please remember Miklos' request - please split the patch sets for review to:
1. FUSE-passthrough-all-mode
2. Attach BPF program
We FUSE developers must be able to review the FUSE/passthough changes without any BPF code at all (which we have little understanding thereof)
As a merge strategy, I think we need to aim for merging all the FUSE passthrough infrastructure needed for passthrough of inode operations strictly before merging any FUSE-BPF specific code.
In parallel you may get BPF infrastructure merged, but integrating FUSE+BPF, should be done only after all infrastructure is already merged IMO.
Quoted 10 lines
set. That has the added bonus of pushing us back down below the current
struct_opfunction list limits. I would want to establish some linkage between the sets, so that you could still just set the bpf program at a folder level, and have all objects underneath inherit the correct program. That's not an issue for a version with just file support, but I'll want to ensure the interface extends naturally. With the increased module support, I plan to redo all of the bpf program linking anyways. The existing code was a temporary placeholder while the method of registering struct ops programs was still in flux.
So I don't think there is any point in anyone actually reviewing the v4 patch set that you just posted?
Quoted 1 line
My plan for the next patch set is to prune down to just the file
Please explain what you mean by that.
How are fuse-bpf file operations expected to be used and specifically, How are they expected to extend the current FUSE passthrough functionality?
Do you mean that an passthrough setup will include a reference to a bpf program that will be used to decide per read/write/splice operation whether it should be passed through to backing file or sent to server direct_io style?
I just wanted to make sure that you are aware of the fact that direct io to server is the only mode of io that is allowed on an inode with an attached backing file.
Thanks,
Amir.
Quoted 111 lines
operations. That removes a lot of the tricky questions for the moment, and should shrink down the patch set massively. Along with that, I'll clean up the
struct_opimplementation to take more advantage of the recent bpf additions.[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/20240105-vfs-rw-9b5809292b57@brauner/
[4] https://lore.kernel.org/all/CAJfpegsZoLMfcpBXBPr7wdAnuXfAYUZYyinru3jrOWWEz7DJPQ@mail.gmail.com/Daniel Rosenberg (36):
fuse-bpf: Update fuse side uapi
fuse-bpf: Add data structures for fuse-bpf
fuse-bpf: Prepare for fuse-bpf patch
fuse: Add fuse-bpf, a stacked fs extension for FUSE
fuse-bpf: Add ioctl interface for/dev/fuse
fuse-bpf: Don't supportexport_operations
fuse-bpf: Add support for access
fuse-bpf: Partially add mapping support
fuse-bpf: Add lseek support
fuse-bpf: Add support for fallocate
fuse-bpf: Support file/dir open/close
fuse-bpf: Support mknod/unlink/mkdir/rmdir
fuse-bpf: Add support for read/write iter
fuse-bpf: support readdir
fuse-bpf: Add support for sync operations
fuse-bpf: Add Rename support
fuse-bpf: Add attr support
fuse-bpf: Add support forFUSE_COPY_FILE_RANGE
fuse-bpf: Add xattr support
fuse-bpf: Add symlink/link support
fuse-bpf: Add partial flock support
fuse-bpf: Add partial ioctl support
fuse-bpf: allow mounting with no userspace daemon
fuse-bpf: Add fuse-bpf constants
bpf: Increasestruct_opmax members
WIP: bpf: Addfuse_opsstruct_opprograms
fuse-bpf: Export Functions
fuse: Provide registration functions for fuse-bpf
fuse-bpf: Setfuse_opsat mount or lookup time
fuse-bpf: Call bpf for pre/post filters
fuse-bpf: Add userspace pre/post filters
WIP: fuse-bpf: adderror_out
fuse-bpf: Add default filter op
tools: Add FUSE, update bpf includes
fuse-bpf: Add selftests
fuse: Provide easy way to test fusestruct_opcallfs/fuse/Kconfig | 8 + fs/fuse/Makefile | 1 + fs/fuse/backing.c | 4287 +++++++++++++++++ fs/fuse/bpf_register.c | 207 + fs/fuse/control.c | 2 +- fs/fuse/dev.c | 85 +- fs/fuse/dir.c | 318 +- fs/fuse/file.c | 126 +- fs/fuse/fuse_i.h | 472 +- fs/fuse/inode.c | 377 +- fs/fuse/ioctl.c | 11 +- fs/fuse/readdir.c | 5 + fs/fuse/xattr.c | 18 + include/linux/bpf.h | 2 +- include/linux/bpf_fuse.h | 285 ++ include/uapi/linux/bpf.h | 13 + include/uapi/linux/fuse.h | 41 + kernel/bpf/Makefile | 4 + kernel/bpf/bpf_fuse.c | 716 +++ kernel/bpf/bpf_struct_ops.c | 2 + kernel/bpf/btf.c | 1 + kernel/bpf/verifier.c | 10 +- tools/include/uapi/linux/bpf.h | 13 + tools/include/uapi/linux/fuse.h | 1197 +++++ .../selftests/filesystems/fuse/.gitignore | 2 + .../selftests/filesystems/fuse/Makefile | 189 + .../testing/selftests/filesystems/fuse/OWNERS | 2 + .../selftests/filesystems/fuse/bpf_common.h | 51 + .../selftests/filesystems/fuse/bpf_loader.c | 597 +++ .../testing/selftests/filesystems/fuse/fd.txt | 21 + .../selftests/filesystems/fuse/fd_bpf.bpf.c | 397 ++ .../selftests/filesystems/fuse/fuse_daemon.c | 300 ++ .../selftests/filesystems/fuse/fuse_test.c | 2476 ++++++++++ .../filesystems/fuse/struct_op_test.bpf.c | 642 +++ .../selftests/filesystems/fuse/test.bpf.c | 1045 ++++ .../filesystems/fuse/test_framework.h | 172 + .../selftests/filesystems/fuse/test_fuse.h | 494 ++ 37 files changed, 14385 insertions(+), 204 deletions(-) create mode 100644 fs/fuse/backing.c create mode 100644 fs/fuse/bpf_register.c create mode 100644 include/linux/bpf_fuse.h create mode 100644 kernel/bpf/bpf_fuse.c create mode 100644 tools/include/uapi/linux/fuse.h create mode 100644 tools/testing/selftests/filesystems/fuse/.gitignore create mode 100644 tools/testing/selftests/filesystems/fuse/Makefile create mode 100644 tools/testing/selftests/filesystems/fuse/OWNERS create mode 100644 tools/testing/selftests/filesystems/fuse/bpf_common.h create mode 100644 tools/testing/selftests/filesystems/fuse/bpf_loader.c create mode 100644 tools/testing/selftests/filesystems/fuse/fd.txt create mode 100644 tools/testing/selftests/filesystems/fuse/fd_bpf.bpf.c create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_daemon.c create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_test.c create mode 100644 tools/testing/selftests/filesystems/fuse/struct_op_test.bpf.c create mode 100644 tools/testing/selftests/filesystems/fuse/test.bpf.c create mode 100644 tools/testing/selftests/filesystems/fuse/test_framework.h create mode 100644 tools/testing/selftests/filesystems/fuse/test_fuse.hbase-commit:
e63985ecd22681c7f5975f2e8637187a326b6791--
2.44.0.478.gd926399ef9-goog
Quoted 10 lines · Amir Goldstein
My plan was to start from passthrough ioctl with
O_PATHfd on lookup and deal with performance improvements later when there are actual workloads that report a problem and that depends where the overhead is.Is it with the opening of
O_PATHfds?
Is it with the passthtough ioctls?
If latter, then when fuse uring is merged, I think we could get loose the ioctls anyway.
I'm not terribly sure. Ideally I would have cc'ed them on this email, but I didn't take down contact info with my notes. I was under the impression that it was triggering all of the opens before an actual open was needed, for example, during ls -l, but I don't know if that was with O_PATH fds. I was a bit concerned that a performance fix there might end up needing a different interface, and managing multiple of those could get pretty cluttered. But I agree that it doesn't make sense to do anything there without a concrete use-case and issue.
Quoted 11 lines
The original reason was to mitigate an attack vector of fooling a privileged process into writing the fd (number) to
/dev/fuseto gain access to a backing file this way.The fuse-bpf way of doing all responds with ioctls seems fine for this purpose, but note that the explicit setup also provides feedback to the server in case the passthrough cannot be accomplished for a specific inode (e.g. because of stacking depths overflow) and that is a big benefit IMO.
That certainly informs the daemon of the error earlier. So long as we can still run the complete passthrough mode serverless that's fine by me. I've found that mode helpful for running filesystem tests on pure backing mode, plus I imagine some simple Fuse filesystems could get away with only the bpf programs.
Quoted 5 lines
Using a global cred should be fine, just as overlayfs does. The specific inode passthrough setup could mention if the global cred should be used.
Quoted 7 lines
However, note that overlayfs needs to handle some special cases when using mounter creds (e.g.:
ovl_create_or_link()and dropping ofCAP_SYS_RESOURCE).If you are going to mimic all this, better have that in the stacking fs common code.
Sure. The less duplicate code the better :)
Quoted 9 lines
That sounds like a good plan, but also, please remember Miklos' request - please split the patch sets for review to:
1. FUSE-passthrough-all-mode
2. Attach BPF programWe FUSE developers must be able to review the FUSE/passthough changes without any BPF code at all (which we have little understanding thereof)
Quoted 7 lines
As a merge strategy, I think we need to aim for merging all the FUSE passthrough infrastructure needed for passthrough of inode operations strictly before merging any FUSE-BPF specific code.
In parallel you may get BPF infrastructure merged, but integrating FUSE+BPF, should be done only after all infrastructure is already merged IMO.
Ok. I'll probably mess around with the module stuff at least, in order to work out if everything I need is present on the bpf side. Do you know if anyone is actively working on extending the file-backing work to something like inode-backing? I don't want to duplicate work there, but I'd be happy to start looking at it. Otherwise I'd focus on the bpf end for now. I expect we'll want to be able to optionally set the bpf program at the same place where we set the backing file/inode. Hence the spit into a file and inode program set. I'm still thinking over what the best way to address the programs is...
Quoted 4 lines
So I don't think there is any point in anyone actually reviewing the v4 patch set that you just posted?
Correct. The only reason I included it was as a reference for the sort of stuff fuse-bpf is currently doing.
Quoted 10 lines
Please explain what you mean by that.
How are fuse-bpf file operations expected to be used and specifically, How are they expected to extend the current FUSE passthrough functionality?Do you mean that an passthrough setup will include a reference to a bpf program that will be used to decide per read/write/splice operation whether it should be passed through to backing file or sent to server
direct_iostyle?
So in the current fuse-bpf setup, the bpf program does two things. It can edit certain parameters, and it can indicate what the next action should be. That action could be queuing up the post filter after the backing operation, deferring to a userspace pre/post filter, or going back to normal fuse operations.
The latter one isn't currently very well fleshed out. Unless you do some specific tracking, under existing fuse-bpf you'd have a node id of 0, and userspace can't make much out of that. With that aside, there's all sorts of caching nightmares to deal with there.
We're only using the parameter changing currently in our use cases. I wouldn't be opposed to leaving the falling back to fuse for specific operations out of v1 of the bpf enhancements, especially if we have the userspace pre/post filters available.
So you'd optionally specify a bpf program to use with the backing file. That would allow you to manipulate some data in the files like you might in Fuse itself. For instance, data redaction. You could null out location metadata in images, provided a map or something with the offsets that should be nulled. You could also prepend some data at the beginning of a file by adjusting offsets and attrs and whatnot. I could imagine having multiple backing files, and the bpf program splitting a read into multiple parts to handle parts of it using different backing files, although that's not in the current design.
Quoted 8 lines
I just wanted to make sure that you are aware of the fact that direct io to server is the only mode of io that is allowed on an inode with an attached backing file.
Thanks,
Amir.
Can you not read/write without interacting with the server? Or do you mean FOPEN_DIRECT_IO sends some file ops to the server even in passthrough mode? At the moment I'm tempted to follow the same mechanics passthrough is using. The only exception would be possibly tossing back to the server, which I mentioned above. That'd only happen for, say, read, if we're not under FOPEN_DIRECT_IO. I've not looked too closely at FOPEN_DIRECT_IO. In Fuse bpf we currently have bpf mode taking priority. Are there any email threads I should look at for more background there?
-Daniel
Amir Goldstein
maintainerQuoted 13 lines
Quoted 13 lines
That sounds like a good plan, but also, please remember Miklos' request - please split the patch sets for review to:
1. FUSE-passthrough-all-mode
2. Attach BPF programWe FUSE developers must be able to review the FUSE/passthough changes without any BPF code at all (which we have little understanding thereof)
As a merge strategy, I think we need to aim for merging all the FUSE passthrough infrastructure needed for passthrough of inode operations strictly before merging any FUSE-BPF specific code.
Quoted 8 lines
Quoted 3 lines
In parallel you may get BPF infrastructure merged, but integrating FUSE+BPF, should be done only after all infrastructure is already merged IMO.
Ok. I'll probably mess around with the module stuff at least, in order to work out if everything I need is present on the bpf side. Do you know if anyone is actively working on extending the file-backing work to something like inode-backing? I don't want to duplicate work there,
I am actively *thinking* about working on passthrough for getattr/getxattr. As soon as I come up with something concrete I will let you know.
Quoted 6 lines
but I'd be happy to start looking at it. Otherwise I'd focus on the bpf end for now. I expect we'll want to be able to optionally set the bpf program at the same place where we set the backing file/inode. Hence the spit into a file and inode program set. I'm still thinking over what the best way to address the programs is...
My thoughts were doing something similar to FOPEN_PASSTHROUGH but in response to LOOKUP request and in that case the fuse inode will enter passthrough mode early and will not leave passthrough mode until inode is evicted.
Quoted 10 lines
Quoted 9 lines
Please explain what you mean by that.
How are fuse-bpf file operations expected to be used and specifically, How are they expected to extend the current FUSE passthrough functionality?Do you mean that an passthrough setup will include a reference to a bpf program that will be used to decide per read/write/splice operation whether it should be passed through to backing file or sent to server
direct_iostyle?
Quoted 8 lines
So in the current fuse-bpf setup, the bpf program does two things. It can edit certain parameters, and it can indicate what the next action should be. That action could be queuing up the post filter after the backing operation, deferring to a userspace pre/post filter, or going back to normal fuse operations.
The latter one isn't currently very well fleshed out. Unless you do some specific tracking, under existing fuse-bpf you'd have a node id of 0, and userspace can't make much out of that. With that aside,
node id 0 sounds weird.
I was wondering if and how a passthrough lookup operation would work. The only thing I can think of is that in this setup, fuse must use the backing file st_ino as the fuse node id, so that the kernel can instantiate a fuse inode before the server knows about it.
Quoted 2 lines
there's all sorts of caching nightmares to deal with there.
Yeh...
Quoted 5 lines
We're only using the parameter changing currently in our use cases. I wouldn't be opposed to leaving the falling back to fuse for specific operations out of v1 of the bpf enhancements, especially if we have the userspace pre/post filters available.
So you'd optionally specify a bpf program to use with the backing
Quoted 9 lines
file. That would allow you to manipulate some data in the files like you might in Fuse itself. For instance, data redaction. You could null out location metadata in images, provided a map or something with the offsets that should be nulled. You could also prepend some data at the beginning of a file by adjusting offsets and attrs and whatnot. I could imagine having multiple backing files, and the bpf program splitting a read into multiple parts to handle parts of it using different backing files, although that's not in the current design.
Lots of plans ;)
Quoted 4 lines
Can you not read/write without interacting with the server? Or do you mean
FOPEN_DIRECT_IOsends some file ops to the server even in passthrough mode?
FOPEN_DIRECT_IO sends write() and read() to the server even in passthrough mode.
Quoted 7 lines
At the moment I'm tempted to follow the same
mechanics passthrough is using. The only exception would be possibly tossing back to the server, which I mentioned above. That'd only happen for, say, read, if we're not underFOPEN_DIRECT_IO. I've not looked too closely atFOPEN_DIRECT_IO. In Fuse bpf we currently have bpf mode taking priority. Are there any email threads I should look at for more background there?
Maybe this patch set:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Bernd and I worked on it together as a prerequisite to fuse passthrough. Benrd has some followup direct_io re-factoring patches.
Thanks,
Amir.
Quoted 17 lines · Amir Goldstein
Quoted 5 lines
Can you not read/write without interacting with the server? Or do you mean
FOPEN_DIRECT_IOsends some file ops to the server even in passthrough mode?
FOPEN_DIRECT_IOsendswrite()andread()to the server even in passthrough mode.Quoted 7 lines
At the moment I'm tempted to follow the same
mechanics passthrough is using. The only exception would be possibly tossing back to the server, which I mentioned above. That'd only happen for, say, read, if we're not underFOPEN_DIRECT_IO. I've not looked too closely atFOPEN_DIRECT_IO. In Fuse bpf we currently have bpf mode taking priority. Are there any email threads I should look at for more background there?
Quoted 5 lines
Maybe this patch set:
https://lore.kernel.org/linux-fsdevel/[email protected]/Bernd and I worked on it together as a prerequisite to fuse passthrough. Benrd has some followup
direct_iore-factoring patches.
They are in this branch
https://github.com/bsbernd/linux/commits/fuse-dio-v5/
Going to rebase it to 6.9 this week and will send it out then. I had been rather occupied with with ddn internal work and didn't have the time since February...
Thanks,
Bernd