From nobody Wed Dec 17 21:15:13 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 0D684C77B75 for ; Tue, 18 Apr 2023 01:43:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231164AbjDRBm7 (ORCPT ); Mon, 17 Apr 2023 21:42:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230493AbjDRBmR (ORCPT ); Mon, 17 Apr 2023 21:42:17 -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 6F5C1658E for ; Mon, 17 Apr 2023 18:41:25 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54f69fb5cafso190546727b3.12 for ; Mon, 17 Apr 2023 18:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681782082; x=1684374082; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XffErqhYI2OU7fEkAttVu8sFpvDYdEUvBhfwhueehVM=; b=W64W7LYmODf/FRuZNRmhqRfU8jwPzAf2EgQjFr/GwQnfixQx1lnFWxTQHQr2157bLk bOZx0B3xbbAKBKptnu3DGWAHW7YUWHUgXmFNH0B57uqjJVKJbfuIf6siNBmXF+8KrPKl rq/fklWlDzNR/LfPz5La++65odFf+sqMFipQNJ9fbMo8fpXLvw0QrXhDgD89PZ+Bh4Cv ClbkWZWwvPPc53kzJNCAMgQof+PQW1mdRELbdWXfLwzm+gUieIJC3zqNnbis5j2Pkdx0 ai+ArKZhDaSGmGokepURyuQtc1NoAeDczoa0Mwj+K+es3hQOC2CkYjntXKPcSV6FWNzd ApiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681782082; x=1684374082; 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=XffErqhYI2OU7fEkAttVu8sFpvDYdEUvBhfwhueehVM=; b=H2q1jvRuoH+JkPogl5mIix2J1NYNcOYyUmdHriyttUfUIztDZy/vMDiC8ozDs3phON 2ukz0aZVoCh8TYrBiWAqkir9zF1BbXZ6QUyj2DjXDcbMykc34XuW6Ripfy7rQgyJJ2BD U40fsSwJRfOXQlNGo/LjRp/7Nz4GatIrPHT4E1EETrY1I8WmYc83u29Z5ZAewKVWQuBz IWFZ3HXzTef9slGziJp0fd/9cfL0LZL4eG0awQSXnII4u4QT1SB5AAPfXd81XYmCwBLn fIZU/BOZPcgXM5CTTQeD7gIwlynRlsvtSn92WcdfZft/tx9L4dPGZYNTcRmIMbSl1UK+ 3wsg== X-Gm-Message-State: AAQBX9dR4HFzKvdX9R6FzpFWZzzocHsDzuTZfroN3voXr88Xh01chC4F DVG50WRRYRmwmnb2/6Y4f6KMasai7UM= X-Google-Smtp-Source: AKy350bK1wIQRL+1GOlGecQQ1VG4drCo01/C/N6m/UsccfrVXFYrTKOINwumV372LVk08vQB5twTN47yWjc= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:e67a:98b0:942d:86aa]) (user=drosen job=sendgmr) by 2002:a81:b303:0:b0:545:1d7f:abfe with SMTP id r3-20020a81b303000000b005451d7fabfemr10434358ywh.7.1681782082574; Mon, 17 Apr 2023 18:41:22 -0700 (PDT) Date: Mon, 17 Apr 2023 18:40:14 -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-15-drosen@google.com> Subject: [RFC PATCH v3 14/37] fuse-bpf: Add support for fallocate 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_FALLOCATE Signed-off-by: Daniel Rosenberg Signed-off-by: Paul Lawrence --- fs/fuse/backing.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/file.c | 3 +++ fs/fuse/fuse_i.h | 6 +++++ 3 files changed, 69 insertions(+) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index c4916dde48c8..ee315598bc3f 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -333,6 +333,66 @@ ssize_t fuse_backing_mmap(struct file *file, struct vm= _area_struct *vma) return ret; } =20 +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 =3D file->private_data; + + *in =3D (struct fuse_fallocate_in) { + .fh =3D ff->fh, + .offset =3D offset, + .length =3D length, + .mode =3D mode, + }; + + *fa =3D (struct bpf_fuse_args) { + .info =3D (struct bpf_fuse_meta_info) { + .opcode =3D FUSE_FALLOCATE, + .nodeid =3D ff->nodeid, + }, + .in_numargs =3D 1, + .in_args[0].size =3D sizeof(*in), + .in_args[0].value =3D 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 =3D fa->in_args[0].value; + struct fuse_file *ff =3D file->private_data; + + *out =3D 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 *fi= le, 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 = * *************************************************************************= *****/ diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 9758bd1665a6..58cff04660db 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3071,6 +3071,9 @@ static long fuse_file_fallocate(struct file *file, in= t mode, loff_t offset, (!(mode & FALLOC_FL_KEEP_SIZE) || (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE))); =20 + 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; diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 624d0cebd287..1dd9cc9720df 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1406,6 +1406,7 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, = int num_entries); #ifdef CONFIG_FUSE_BPF =20 int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *file, lo= ff_t offset, int whence); +int fuse_bpf_file_fallocate(int *out, struct inode *inode, struct file *fi= le, 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); =20 @@ -1416,6 +1417,11 @@ static inline int fuse_bpf_lseek(loff_t *out, struct= inode *inode, struct file * return 0; } =20 +static inline int fuse_bpf_file_fallocate(int *out, struct inode *inode, s= truct 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; --=20 2.40.0.634.g4ca3ef3211-goog