All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Daniel Rosenberg <drosen@google.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-unionfs@vger.kernel.org, bpf@vger.kernel.org,
	kernel-team@android.com, Paul Lawrence <paullawrence@google.com>,
	Alessio Balsini <balsini@google.com>
Subject: Re: [RFC PATCH v2 04/21] fuse: Add fuse-bpf, a stacked fs extension for FUSE
Date: Tue, 22 Nov 2022 12:19:23 +0200	[thread overview]
Message-ID: <CAOQ4uxiVqR_HxCytweO_uKR=gdRHTjGG9SgHaNTFb1+5b6ucGQ@mail.gmail.com> (raw)
In-Reply-To: <20221122021536.1629178-5-drosen@google.com>

On Tue, Nov 22, 2022 at 4:16 AM Daniel Rosenberg <drosen@google.com> wrote:
>
> Fuse-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.
>
> Signed-off-by: Daniel Rosenberg <drosen@google.com>
> Signed-off-by: Paul Lawrence <paullawrence@google.com>
> Signed-off-by: Alessio Balsini <balsini@google.com>
> ---
>  fs/fuse/Kconfig   |   8 +
>  fs/fuse/Makefile  |   1 +
>  fs/fuse/backing.c | 392 ++++++++++++++++++++++++++++++++++++++++++++++
>  fs/fuse/dev.c     |  41 ++++-
>  fs/fuse/dir.c     | 187 +++++++++++++++++-----
>  fs/fuse/file.c    |  25 ++-
>  fs/fuse/fuse_i.h  |  99 +++++++++++-
>  fs/fuse/inode.c   | 189 +++++++++++++++++-----
>  fs/fuse/ioctl.c   |   2 +-
>  9 files changed, 861 insertions(+), 83 deletions(-)
>  create mode 100644 fs/fuse/backing.c
>
> diff --git a/fs/fuse/Kconfig b/fs/fuse/Kconfig
> index 038ed0b9aaa5..3a64fa73e591 100644
> --- a/fs/fuse/Kconfig
> +++ b/fs/fuse/Kconfig
> @@ -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
> diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile
> index 0c48b35c058d..a0853c439db2 100644
> --- a/fs/fuse/Makefile
> +++ b/fs/fuse/Makefile
> @@ -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
> diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
> new file mode 100644
> index 000000000000..5a59a8963d52
> --- /dev/null
> +++ b/fs/fuse/backing.c
> @@ -0,0 +1,392 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * FUSE-BPF: Filesystem in Userspace with BPF
> + * Copyright (c) 2021 Google LLC
> + */
> +
> +#include "fuse_i.h"
> +
> +#include <linux/fdtable.h>
> +#include <linux/file.h>
> +#include <linux/fs_stack.h>
> +#include <linux/namei.h>
> +
> +/*
> + * expression statement to wrap the backing filter logic
> + * struct inode *inode: inode with bpf and backing inode
> + * typedef io: (typically complex) type whose components fuse_args can point to.
> + *     An instance of this type is created locally and passed to initialize
> + * void initialize_in(struct fuse_args *fa, io *in_out, args...): function that sets
> + *     up fa and io based on args
> + * void initialize_out(struct fuse_args *fa, io *in_out, args...): function that sets
> + *     up fa and io based on args
> + * 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
> + *     work needed to commit the backing io
> + */
> +#define fuse_bpf_backing(inode, io, out, initialize_in, initialize_out,        \
> +                        backing, finalize, args...)                    \
> +({                                                                     \
> +       struct fuse_inode *fuse_inode = get_fuse_inode(inode);          \
> +       struct fuse_args fa = { 0 };                                    \
> +       bool initialized = false;                                       \
> +       bool handled = false;                                           \
> +       ssize_t res;                                                    \
> +       io feo = { 0 };                                                 \
> +       int error = 0;                                                  \
> +                                                                       \
> +       do {                                                            \
> +               if (!fuse_inode || !fuse_inode->backing_inode)          \
> +                       break;                                          \
> +                                                                       \
> +               handled = true;                                         \
> +               error = initialize_in(&fa, &feo, args);                 \
> +               if (error)                                              \
> +                       break;                                          \
> +                                                                       \
> +               error = initialize_out(&fa, &feo, args);                \
> +               if (error)                                              \
> +                       break;                                          \
> +                                                                       \
> +               initialized = true;                                     \
> +                                                                       \
> +               error = backing(&fa, out, args);                        \
> +               if (error < 0)                                          \
> +                       fa.error_in = error;                            \
> +                                                                       \
> +       } while (false);                                                \
> +                                                                       \
> +       if (initialized && handled) {                                   \
> +               res = finalize(&fa, out, args);                         \
> +               if (res)                                                \
> +                       error = res;                                    \
> +       }                                                               \
> +                                                                       \
> +       *out = error ? _Generic((*out),                                 \
> +                       default :                                       \
> +                               error,                                  \
> +                       struct dentry * :                               \
> +                               ERR_PTR(error),                         \
> +                       const char * :                                  \
> +                               ERR_PTR(error)                          \
> +                       ) : (*out);                                     \
> +       handled;                                                        \
> +})
> +

I hope there is a better way than this macro...
Haven't studied the patches enough to be able to suggest one.

Thanks,
Amir.

  reply	other threads:[~2022-11-22 10:21 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22  2:15 [RFC PATCH v2 00/21] FUSE BPF: A Stacked Filesystem Extension for FUSE Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 01/21] fs: Generic function to convert iocb to rw flags Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 02/21] fuse-bpf: Update fuse side uapi Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 03/21] fuse-bpf: Prepare for fuse-bpf patch Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 04/21] fuse: Add fuse-bpf, a stacked fs extension for FUSE Daniel Rosenberg
2022-11-22 10:19   ` Amir Goldstein [this message]
2022-11-22 21:23     ` Daniel Rosenberg
2022-11-23 23:31   ` kernel test robot
2022-11-22  2:15 ` [RFC PATCH v2 05/21] fuse-bpf: Add ioctl interface for /dev/fuse Daniel Rosenberg
2022-11-22 14:20   ` kernel test robot
2022-11-22  2:15 ` [RFC PATCH v2 06/21] fuse-bpf: Don't support export_operations Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 07/21] fuse-bpf: Add support for FUSE_ACCESS Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 08/21] fuse-bpf: Partially add mapping support Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 09/21] fuse-bpf: Add lseek support Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 10/21] fuse-bpf: Add support for fallocate Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 11/21] fuse-bpf: Support file/dir open/close Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 12/21] fuse-bpf: Support mknod/unlink/mkdir/rmdir Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 13/21] fuse-bpf: Add support for read/write iter Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 14/21] fuse-bpf: support FUSE_READDIR Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 15/21] fuse-bpf: Add support for sync operations Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 16/21] fuse-bpf: Add Rename support Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 17/21] fuse-bpf: Add attr support Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 18/21] fuse-bpf: Add support for FUSE_COPY_FILE_RANGE Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 19/21] fuse-bpf: Add xattr support Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 20/21] fuse-bpf: Add symlink/link support Daniel Rosenberg
2022-11-22  2:15 ` [RFC PATCH v2 21/21] fuse-bpf: allow mounting with no userspace daemon Daniel Rosenberg
2022-11-22 11:13 ` [RFC PATCH v2 00/21] FUSE BPF: A Stacked Filesystem Extension for FUSE Amir Goldstein
2022-11-22 20:56   ` Daniel Rosenberg
2022-11-22 21:23     ` Bernd Schubert
2023-02-02  8:47       ` Amir Goldstein
2023-02-02 22:01         ` Bernd Schubert
2023-02-03 11:43           ` Amir Goldstein
2023-02-10  9:38             ` Miklos Szeredi
2023-02-10  9:41               ` Nikolaus Rath
2023-02-10 10:53                 ` Miklos Szeredi
2023-02-14 16:53                   ` Attending LFS (was: [RFC PATCH v2 00/21] FUSE BPF: A Stacked Filesystem Extension for FUSE) Nikolaus Rath
2023-02-14 18:04                     ` Amir Goldstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOQ4uxiVqR_HxCytweO_uKR=gdRHTjGG9SgHaNTFb1+5b6ucGQ@mail.gmail.com' \
    --to=amir73il@gmail.com \
    --cc=balsini@google.com \
    --cc=bpf@vger.kernel.org \
    --cc=drosen@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=paullawrence@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.