From nobody Wed Dec 17 21:15:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAB7CC77B76 for ; Tue, 18 Apr 2023 01:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231239AbjDRBno (ORCPT ); Mon, 17 Apr 2023 21:43:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231147AbjDRBmo (ORCPT ); Mon, 17 Apr 2023 21:42:44 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9B33659E for ; Mon, 17 Apr 2023 18:41:45 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54faf2e22afso139560307b3.7 for ; Mon, 17 Apr 2023 18:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681782094; x=1684374094; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yHPyQOgLAeTv27Hmk1jV/Qw6lBeg9KsOnD3+nmdgTBc=; b=WfhU75GkbNBBGPNdlQQqWpIVlOAmIt1xhsdC8ETWkv8e89D2kVJXdfo2nDvpBH4oXa nqAcJ0rkvNDwDtDwu+BjaH1Q8oFoMz/kg0Or59UBboMN/KJfqzGCb2RqOb/U/0RSQ32t dDjHoFKhRwU61k68E2xItY5TqBQZUfdSkdlDFCBzv5zViEbPhG4YAFlvC6a4+lykVyz3 PN4aTi6QZSAJo3dKZSZtek7fRmsqdmoYf8DNy1EJQUBpOuz65vrZutPzrVi47/+A8syB akZ3w8TvKAFp/kH3G4HD2NJLL5M0F242/508++FqsS0CRy19r4HQJW7deZinJ5f6k7Yh LtIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681782094; x=1684374094; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yHPyQOgLAeTv27Hmk1jV/Qw6lBeg9KsOnD3+nmdgTBc=; b=RhfkT4LfBj3nbeS2AA2iSd59TOIarNWblWILdZju3gjpG75xyhLJjC+PtV1ly9Ktn0 FCqwj8TEPYour2UaRxDtUDNn0X42iPodisXL03h8IcAwCshqfweRXc0qFxN0KYLSPgKS 9hL7Yg9sn+X5x8OY3SMK4XJCoUqg/eJozlM4zE3pnWAPyy8qVh6csJ3gA3NOtWOsUhPo XbcKV9adweBj9zmhAQ4B/9Jf3LNnlYyY1hs3J/ARxhwHeYB+V7mxXAz3uqZ5PfCGizfv TOK154hAKGDMJ0aN+y74Od+PcOCnlFtbok6QWlBwDTtorGMm98UnfdjaZZj8J6qsSuQq Pqkw== X-Gm-Message-State: AAQBX9dp/twb0FveMRi7/h6RivlOtk1gQMdr89jgYua7hn0kbgvCRjA3 hrPBVTbubtO/lSmsK/241lZU0gs49VI= X-Google-Smtp-Source: AKy350ZGdfGHneASHc+2qR8hpHc/w9BF7/xnpO/COHxv9rPK2B1jF3L8CR7fh6IuzYQx0u6d+K6DOtAYt2s= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:e67a:98b0:942d:86aa]) (user=drosen job=sendgmr) by 2002:a25:8051:0:b0:b92:40f8:a46f with SMTP id a17-20020a258051000000b00b9240f8a46fmr4359628ybn.2.1681782094311; Mon, 17 Apr 2023 18:41:34 -0700 (PDT) Date: Mon, 17 Apr 2023 18:40:19 -0700 In-Reply-To: <20230418014037.2412394-1-drosen@google.com> Mime-Version: 1.0 References: <20230418014037.2412394-1-drosen@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418014037.2412394-20-drosen@google.com> Subject: [RFC PATCH v3 19/37] fuse-bpf: Add support for sync operations From: Daniel Rosenberg To: Miklos Szeredi , bpf@vger.kernel.org, Alexei Starovoitov Cc: Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , kernel-team@android.com, Daniel Rosenberg , Paul Lawrence Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This adds backing support for FUSE_FLUSH, FUSE_FSYNC, and FUSE_FSYNCDIR. Signed-off-by: Daniel Rosenberg Signed-off-by: Paul Lawrence --- fs/fuse/backing.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 3 + fs/fuse/file.c | 7 +++ fs/fuse/fuse_i.h | 18 ++++++ 4 files changed, 175 insertions(+) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index 2908c231a695..30492f7b2a05 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -659,6 +659,59 @@ int fuse_bpf_releasedir(int *out, struct inode *inode,= struct file *file) fuse_release_backing, fuse_release_finalize, inode, file); } =20 +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 =3D file->private_data; + + *ffi =3D (struct fuse_flush_in) { + .fh =3D fuse_file->fh, + }; + + *fa =3D (struct bpf_fuse_args) { + .info =3D (struct bpf_fuse_meta_info) { + .nodeid =3D get_node_id(file->f_inode), + .opcode =3D FUSE_FLUSH, + }, + .in_numargs =3D 1, + .in_args[0].size =3D sizeof(*ffi), + .in_args[0].value =3D ffi, + .flags =3D 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 f= ile *file, fl_owner_t id) +{ + struct fuse_file *fuse_file =3D file->private_data; + struct file *backing_file =3D fuse_file->backing_file; + + *out =3D 0; + if (backing_file->f_op->flush) + *out =3D 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_ow= ner_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; @@ -748,6 +801,100 @@ int fuse_bpf_lseek(loff_t *out, struct inode *inode, = struct file *file, loff_t o file, offset, whence); } =20 +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 =3D file->private_data; + + *in =3D (struct fuse_fsync_in) { + .fh =3D fuse_file->fh, + .fsync_flags =3D datasync ? FUSE_FSYNC_FDATASYNC : 0, + }; + + *fa =3D (struct bpf_fuse_args) { + .info =3D (struct bpf_fuse_meta_info) { + .nodeid =3D get_fuse_inode(file->f_inode)->nodeid, + .opcode =3D FUSE_FSYNC, + }, + .in_numargs =3D 1, + .in_args[0].size =3D sizeof(*in), + .in_args[0].value =3D in, + .flags =3D 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 =3D file->private_data; + struct file *backing_file =3D fuse_file->backing_file; + const struct fuse_fsync_in *ffi =3D fa->in_args[0].value; + int new_datasync =3D (ffi->fsync_flags & FUSE_FSYNC_FDATASYNC) ? 1 : 0; + + *out =3D 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 f= use_fsync_in *in, + struct file *file, loff_t start, loff_t end, int datasync) +{ + struct fuse_file *fuse_file =3D file->private_data; + + *in =3D (struct fuse_fsync_in) { + .fh =3D fuse_file->fh, + .fsync_flags =3D datasync ? FUSE_FSYNC_FDATASYNC : 0, + }; + + *fa =3D (struct bpf_fuse_args) { + .info =3D (struct bpf_fuse_meta_info) { + .nodeid =3D get_fuse_inode(file->f_inode)->nodeid, + .opcode =3D FUSE_FSYNCDIR, + }, + .in_numargs =3D 1, + .in_args[0].size =3D sizeof(*in), + .in_args[0].value =3D in, + .flags =3D 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, l= off_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)) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index a763a45fa973..5ce65f696980 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1666,6 +1666,9 @@ static int fuse_dir_fsync(struct file *file, loff_t s= tart, loff_t end, if (fuse_is_bad(inode)) return -EIO; =20 + if (fuse_bpf_dir_fsync(&err, inode, file, start, end, datasync)) + return err; + if (fc->no_fsyncdir) return 0; =20 diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 5f19ef5bf124..a4a0aeb28e4a 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -554,10 +554,14 @@ static int fuse_flush(struct file *file, fl_owner_t i= d) struct inode *inode =3D file_inode(file); struct fuse_mount *fm =3D get_fuse_mount(inode); struct fuse_file *ff =3D file->private_data; + int err; =20 if (fuse_is_bad(inode)) return -EIO; =20 + if (fuse_bpf_flush(&err, file_inode(file), file, id)) + return err; + if (ff->open_flags & FOPEN_NOFLUSH && !fm->fc->writeback_cache) return 0; =20 @@ -615,6 +619,9 @@ static int fuse_fsync(struct file *file, loff_t start, = loff_t end, if (fuse_is_bad(inode)) return -EIO; =20 + if (fuse_bpf_fsync(&err, inode, file, start, end, datasync)) + return err; + inode_lock(inode); =20 /* diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index fb3a77b79b0f..e60207bf66de 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1414,7 +1414,10 @@ int fuse_bpf_rmdir(int *out, struct inode *dir, stru= ct dentry *entry); int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry); int fuse_bpf_release(int *out, struct inode *inode, struct file *file); int fuse_bpf_releasedir(int *out, struct inode *inode, struct file *file); +int fuse_bpf_flush(int *out, struct inode *inode, struct file *file, fl_ow= ner_t id); int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *file, lo= ff_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, l= off_t start, loff_t end, int datasync); int fuse_bpf_file_read_iter(ssize_t *out, struct inode *inode, struct kioc= b *iocb, struct iov_iter *to); int fuse_bpf_file_write_iter(ssize_t *out, struct inode *inode, struct kio= cb *iocb, struct iov_iter *from); int fuse_bpf_file_fallocate(int *out, struct inode *inode, struct file *fi= le, int mode, loff_t offset, loff_t length); @@ -1465,11 +1468,26 @@ static inline int fuse_bpf_releasedir(int *out, str= uct inode *inode, struct file return 0; } =20 +static inline int fuse_bpf_flush(int *out, struct inode *inode, struct fil= e *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; } =20 +static inline int fuse_bpf_fsync(int *out, struct inode *inode, struct fil= e *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 *inod= e, struct kiocb *iocb, struct iov_iter *to) { return 0; --=20 2.40.0.634.g4ca3ef3211-goog