Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4756152rwe; Mon, 17 Apr 2023 18:43:50 -0700 (PDT) X-Google-Smtp-Source: AKy350YdtVULMfxAltdO5K2cGamTvDhIPzydl2dcuYYjlSyTp32VHnFCOGynB1+DgA7cXFvulu8h X-Received: by 2002:a17:903:48d:b0:1a6:6f42:f5c0 with SMTP id jj13-20020a170903048d00b001a66f42f5c0mr370017plb.61.1681782229975; Mon, 17 Apr 2023 18:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681782229; cv=none; d=google.com; s=arc-20160816; b=gEbYwDUDUuzL0RNYMk1PUlAXp3GQ78q+RyZzWk8nvwOfWrayd1tSafM+Vf5vdeIYBL dciwb4SqotTaIp5dpBkv5X0oMZwS50raRk+1ZhqM8xIsIDCtJf4jyTk6VthmnxK/O7FU fbFtkaPrtdB2HDo/8PJf9zYNH2t8RQFw2cdOLoCaMGzy4NlFYXEaavxigliHX8ArqcnJ 86OPMmBTN7EJCs8txd1PVGCebG/ukv3Gj4DhvS8qcTpmZz7hlw5bbyIkiYspBRxIBX96 v7/ASVMquLw3f8BJWFu0eF/ZTCFYlhfatgazhzQeqwQAx57GYkDkHBeVNJBIyR3Cks/Y N4UA== 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=XffErqhYI2OU7fEkAttVu8sFpvDYdEUvBhfwhueehVM=; b=TFs/R95U0vbyDnecXETNm+U9P1jj1Zh9GcNiE4RR3yqNF/WPUvayxnVHoqGV/o+g+w G88fkTCyArA2zHyz2BJ2oNbUPoDgWWt+nBCGiFsB18dEDgsTSjO/Kj8MEJbLLLdubIhG zfWx6WrCsGfy9H3R8ohG5B7fLOi+Osm9FbaM54j2Qa8KHpYnWS3AHg325YrXLwlRpz0X di9mKo4gL+0wB9Cyv6m4+OU0JYCzyUV8Qp16Df+VoqszEUZsH0RCWHvzf6fngowWlmua 0uvyQBZs1awrFYDDvdJ/ag19BTXKGzmr+NK3qRAHEcYCOl1zuNAsEO2D6xO7Hzx6dgeE iPfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=W64W7LYm; 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 d13-20020a170902728d00b001a64b2f9a37si12465732pll.118.2023.04.17.18.43.36; Mon, 17 Apr 2023 18:43:49 -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=W64W7LYm; 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 S230496AbjDRBm6 (ORCPT + 99 others); Mon, 17 Apr 2023 21:42:58 -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-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 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_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; } +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 * ******************************************************************************/ 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, 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; 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 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); @@ -1416,6 +1417,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; -- 2.40.0.634.g4ca3ef3211-goog