Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4756656rwe; Mon, 17 Apr 2023 18:44:21 -0700 (PDT) X-Google-Smtp-Source: AKy350ZJfoJ1Ac9kOlrLuUA9XroiZGtt7TxhItZHEo+fukKco7jW7p0nBnwLpf57OAwYqSjpQPd9 X-Received: by 2002:a17:903:41c6:b0:1a6:8268:9055 with SMTP id u6-20020a17090341c600b001a682689055mr604019ple.24.1681782261026; Mon, 17 Apr 2023 18:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681782261; cv=none; d=google.com; s=arc-20160816; b=ZEuswzIfd5yrv9EFq+Q00w2HNFNJ7UnYDwWPUGNuV+LfWekOZzfchJ+fDPY9+2jIp2 IiR2OK77WwglavytHN3K68Bz0yNZB3mGrFWUIQB6HcHC+igZYPNx17an274x5lzGMIAw 24RCDBKxhTbNjdSZZGoV+NpkUmxS3ppdqQCemtaVcNVb6Xi6yJFnFumwuKgrNLDI5ieZ b+fitnkGrS5QYXiMVQN083t7pi11LiMMzEhU6HMGJSt9F+ROdwWMhmXiL3y0QJaA/XnA E3iQbBJLM3cw8qHoOtR3OkyS2seeDgGWFdAu7b984ndQYTANVXTH2lxKIkjM1/zAwaPd 1NpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=yHPyQOgLAeTv27Hmk1jV/Qw6lBeg9KsOnD3+nmdgTBc=; b=eDGr4TlX4wUz9cbk+7GEkJLDrPUvH8n18PZCvizolQtgf4/GqqQYOGH1q6IKWtuqu2 6Z6FSGGFjeGk9O4UEsl8lmox6K7TIg3MSAClc0OO5l4oCvIUzLDju2NNIBKQRwMH8lOf fYqKrrmQMVpvjw6JjKP/0mKoQ+G5TaUf2QlGxQV1Cxy2g1sTn08U9kCOiuZdu7llcRXn ClC/1t8mt/dwOwL45wfTUJxcl1lRQn4uMA6DL4S4tOPfBSorSkVahLvJSUowzRLdwvFV iiigokD69rFrv2LOCfTak/Up6u8wFc8Xke9FB4QRmYbR8YpabNAC9ECTVCrN+818LtT5 bmXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=WfhU75Gk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb9-20020a170902bc8900b001a69e1d2e6bsi9900426plb.218.2023.04.17.18.44.07; Mon, 17 Apr 2023 18:44:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=WfhU75Gk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbjDRBno (ORCPT + 99 others); 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-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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } +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; @@ -748,6 +801,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)) 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 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; 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 id) struct inode *inode = file_inode(file); struct fuse_mount *fm = get_fuse_mount(inode); struct fuse_file *ff = file->private_data; + int err; 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; @@ -615,6 +619,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); /* 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, 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 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_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); @@ -1465,11 +1468,26 @@ static inline int fuse_bpf_releasedir(int *out, struct inode *inode, struct file return 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; -- 2.40.0.634.g4ca3ef3211-goog