Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5252504rwb; Mon, 21 Nov 2022 19:32:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf4z2hPp4Ifc6VwB7x+m7udOafuiOn15LN6xSAwkeDo8hZO/u2Muznsajf+5Snh/l/vyldSy X-Received: by 2002:aa7:d0d4:0:b0:461:b1b9:bed0 with SMTP id u20-20020aa7d0d4000000b00461b1b9bed0mr10901347edo.122.1669087955262; Mon, 21 Nov 2022 19:32:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669087955; cv=none; d=google.com; s=arc-20160816; b=Cq/cbcrDAKLCL9J2kB2omd1atYjzggeLsmPTC2qjLavG3eyXBgmTllPwVElYsYoL1L TkOnlffeKNWv8zDezPKs+B3TkczQcdpcTkxwgq79/UkBrJC3bjn9pdObbhNPO35uCVPV EqxycDLL7Hcr1sSvqNB8zQLGpqIezUbM8dkaNuuNOc4lbCkQR4BHhvo0riFp+tIGgAE9 3+FcaFa3tu1X85Ugc7qNGgM0QvktFWt8vltYezxIYmTBENdRnMEF2BHlRKp8Xwfg98wL cO2r+mmB5d8jgXhk7G5ylPn6Mrz6Lv8NsPzJsP6JGs4EzBjvSiCrOUgARiH+Yh8TmLmS IJEw== 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=/H+L2cRtspRUVOzDKfhmH9r0h1z7XV5y5jiKoA2w7Jo=; b=x2eLRkkPINusymTNFVrNz3HlE3cQrF56NvQy+TNr3Btn37dvmdJ0D0IzxdtzjhphFB EEW4qarohQRGBd8oULo5nteA1Wujh0tfY+9pY7TVPQXfZvkdogoYd077DssqD45vk7BY W1ZOF/bPdH9jC8CxX1y1uIkCNG6/TeKONc3XhUfDf6AsxS8j8AGlvdtw9RIYhRkYBIZv 0FbOJUgUSbxseMrEyKXWRDPiMTBofheZaami/Mru2TcLcNMphSof6nH+S6Zc5nZXdSK1 yuGa8T0CiyFh7Bvys2jhDhA2JZ7F3kAj03DtjGurn+9DJZnnKwfTiaOIvas42uVGNmss pPAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GkbYhSRu; 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 h18-20020a05640250d200b004542c9947c1si11380508edb.217.2022.11.21.19.32.11; Mon, 21 Nov 2022 19:32:35 -0800 (PST) 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=20210112 header.b=GkbYhSRu; 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 S230460AbiKVCR7 (ORCPT + 91 others); Mon, 21 Nov 2022 21:17:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232603AbiKVCRC (ORCPT ); Mon, 21 Nov 2022 21:17:02 -0500 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 39340E675D for ; Mon, 21 Nov 2022 18:16:18 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-352e29ff8c2so130290337b3.21 for ; Mon, 21 Nov 2022 18:16:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/H+L2cRtspRUVOzDKfhmH9r0h1z7XV5y5jiKoA2w7Jo=; b=GkbYhSRuG3pnC12YeGswQtbl8Qkm/FgEIiaZy5lmsxd6nnIJGVSGgoCrt6HlEko6Ki C6yr+mtFUhPtVnoaJg/ByALo10sNnWpcBCubg/D8R0ssNLL3XjyN46mJHVC5Um8b16CU orSmyP3WSpCgYDTcMIiZcxb2R80zdMKhHpr45RrSwbcJgu+a3jL9Xhb8MiJaYe2teBth L8HZN6e2FJlFs1cfNF808/GPl/xs2NrIzv6kCLjM5O/xSQgt9ou3kcdxWqlecQ+QDqfO utLWnK4t1OVh8O7dFmQ1g64uSIWNxLOGjQxuWWbknOLE404qWDNW8Qs3bG4NsLYvtmbe jw9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=/H+L2cRtspRUVOzDKfhmH9r0h1z7XV5y5jiKoA2w7Jo=; b=sRl0sCoMnP2lh1Av2MuUjXcRFRqB4ZEKMzXL0MhJaXWVSyiw/jS0HVZHuVt8854K+P uHlY/HybA+zdbZ0PSZClAeBqiFFFgxmJPeNoCH4CyWPCWS4Qy+ll+ohr5Dh4QKGCDY56 RPfy2+LcUhLVUGHEaZNAaW6Jr9KQr0M1H3sqSIhh0VV5sMD99x9eBC2s+5R1YpbKQAfZ WGEQBGgbfyVFLGE/DQirlHXOdhYpEoY13n+9LZcyqHc0GIbGnaBV4jJUhddIrQ0Wst/l qX00U0x3Jab1SxF8oXRYArF3Jjzmn89xikscz1kTTNjuW+Y04ZnhBTjEQCujp6hOD7KR t/pA== X-Gm-Message-State: ANoB5pkN8Le3PPDkF1BQMIRB6eXaY8aBforpUbeZWJglzgf+NdZl3Rku zrOYPm1iAPJlqI9gGZyLXE0jx58FQPA= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:200:8539:aadd:13be:6e82]) (user=drosen job=sendgmr) by 2002:a05:690c:845:b0:3a5:36e5:94eb with SMTP id bz5-20020a05690c084500b003a536e594ebmr5266716ywb.39.1669083377322; Mon, 21 Nov 2022 18:16:17 -0800 (PST) Date: Mon, 21 Nov 2022 18:15:25 -0800 In-Reply-To: <20221122021536.1629178-1-drosen@google.com> Mime-Version: 1.0 References: <20221122021536.1629178-1-drosen@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221122021536.1629178-11-drosen@google.com> Subject: [RFC PATCH v2 10/21] fuse-bpf: Add support for fallocate From: Daniel Rosenberg To: Miklos Szeredi Cc: Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, 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,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 Signed-off-by: Daniel Rosenberg Signed-off-by: Paul Lawrence --- fs/fuse/backing.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/file.c | 3 +++ fs/fuse/fuse_i.h | 6 +++++ 3 files changed, 67 insertions(+) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index 76f48872ed35..51aadeb1b7dc 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -330,6 +330,64 @@ ssize_t fuse_backing_mmap(struct file *file, struct vm_area_struct *vma) return ret; } +static int fuse_file_fallocate_initialize_in(struct fuse_args *fa, + struct fuse_fallocate_in *ffi, + struct file *file, int mode, loff_t offset, loff_t length) +{ + struct fuse_file *ff = file->private_data; + + *ffi = (struct fuse_fallocate_in) { + .fh = ff->fh, + .offset = offset, + .length = length, + .mode = mode, + }; + + *fa = (struct fuse_args) { + .opcode = FUSE_FALLOCATE, + .nodeid = ff->nodeid, + .in_numargs = 1, + .in_args[0].size = sizeof(*ffi), + .in_args[0].value = ffi, + }; + + return 0; +} + +static int fuse_file_fallocate_initialize_out(struct fuse_args *fa, + struct fuse_fallocate_in *ffi, + struct file *file, int mode, loff_t offset, loff_t length) +{ + return 0; +} + +static int fuse_file_fallocate_backing(struct 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 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 fuse_bpf_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 e90b3e2d5452..ab3cd43556e0 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2997,6 +2997,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset, bool block_faults = FUSE_IS_DAX(inode) && lock_inode; + 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 108c2ea15a49..4351dbc7f10d 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1401,6 +1401,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); @@ -1411,6 +1412,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.38.1.584.g0f3c55d4c2-goog