Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp822441lqh; Thu, 28 Mar 2024 19:02:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/8TH/CTo5l3Uzd9DdEHUts6A/DUgXnuDR8FvJwjbcd/c1/fNshP9apkimtk5LQAHY+S4+kLFDdZvCbVdQAG7k+sufa+s94cZHUh0Dyw== X-Google-Smtp-Source: AGHT+IFWPzUNLedFfUcijFdwAK3a1lJIQZIdBGagGN3sE4Go8t+nrFLkz6HcVTmih7lzqqyjcp0A X-Received: by 2002:ad4:4111:0:b0:696:aeac:4676 with SMTP id i17-20020ad44111000000b00696aeac4676mr992679qvp.40.1711677743247; Thu, 28 Mar 2024 19:02:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711677743; cv=pass; d=google.com; s=arc-20160816; b=aoJ7B6xWsRjn4gHDXd5Dwx7HinBgcRa8IoduFGKhiNggd0606W8aC52HhtQuNMCrmq 8pxnrcqrsxCozDe/sQlSYEdGOw51cJYuZOHtXmjXnueiJE4QjbEzhyxjDF93X39lxNJR mhPLMbcJJjtx+s28xRH5uyv/AFIba0ZdX3p+g8i7W9deTvsQ/N1j6T/1N2wa/jH483B9 py1qA45r9NOONjOrpSpudDCXuafcbTMHuF9pSitsrQS/0J+jCxDP4waiY4EJegGL7kT7 fr+vdeYfjA/ekVUEIGjHSIGCR7KdfWBLKKggRjMzNjbdsIVDez2+EylK47YGbycAnZ6s DQpg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=RHfrMplbbUkEBek0oxfkmQFW+uLxDMPloBNof976q78=; fh=zRvgJf8aks078z/ycfpyeL7yZFs/4Gf3zQDD3Bth1LM=; b=xlS0IhrEjEX2JXVKNOWwLMHzcgbsbtml9RJyouGfBiPuyPI1szUhd5hfBGg77OOfiU bL2c3FmiZoxSoXy/d5ruZbhDekzw3MWHlHNnsN5noR80nq/phdtz3cUDPl8LG+w9y8gx L9adgIKzFVxE78QvYT2a3Ma/KIYH9yu4s6X9vQ6lkoOh29coTJ+R2e5zf0we99CdJUtI m9z2IQj5h0xlfwXk/c7rrQgiyn++Q6RB1MGuZkc2sC1WNsR21COd+Q7gTu6eZ9iA1lh3 01NpkQOM9u/AZ8ZjcEDKh+DSLJ/6WEtamtMIcdRjAJXc31y8cQhOKaKrpQ9P7EDq8peX EAWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wHJkKVjR; arc=pass (i=1 spf=pass spfdomain=flex--drosen.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-124001-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124001-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id pr26-20020a056214141a00b00696b46bba5fsi2790048qvb.583.2024.03.28.19.02.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 19:02:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124001-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wHJkKVjR; arc=pass (i=1 spf=pass spfdomain=flex--drosen.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-124001-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124001-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E4A6C1C25EC0 for ; Fri, 29 Mar 2024 02:02:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7821554FA2; Fri, 29 Mar 2024 01:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wHJkKVjR" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A35C654F96 for ; Fri, 29 Mar 2024 01:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677288; cv=none; b=drDvs+oidX8/jinUfIzVx7Dd+bG+ZQRwNNHQbr4K1j2Md3mmXLYE7WqeQHWgJOmWoRqk3P2F6mqaq8UAHyCXNxjMGahfKhCThVBRu4avx/8HP67DZT47d+5UM1lCmLuOYWzHWBZVUXlF4Q9N3FKz2hmTQObfUw4Ke91//cVJXOw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677288; c=relaxed/simple; bh=bBfAJi/bJf2nD+gd3YqaNeaEuDQ3ztMPp8XYXKoJ52g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=A52V1W4d6KmOs4RzlehVHw3rGoIgAxd7ey+2wOEc32XA+Jqi4EUmnEtkhsnvXq95R0Ks+r9SAfVFqKyAVkYvdxvUELnRPidQkZUB+JjHJAJmujadD++jgN0jU7eoMA8QDBNGe7lyZz4VfPrQfutGQ2YPbkhHH/pV+AV5O34rQ70= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--drosen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wHJkKVjR; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--drosen.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc693399655so2763606276.1 for ; Thu, 28 Mar 2024 18:54:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711677286; x=1712282086; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RHfrMplbbUkEBek0oxfkmQFW+uLxDMPloBNof976q78=; b=wHJkKVjRMmLu3l+quU/T1dkRy2eN9n0/f3raXxrUmdxkEBl+F5MjZr/xg38d4MvCqS Zs9QTc8jOGKXFRO4lO1MZBy7urTGovN9UqoSDGIj4vkCU6yKuKVfKoMFe23nx7gPicwU qTndnx7gWcpxrRQE3Bd68SISe31PeCm+I1cUHij18e1P5B9gpTPn5zi1CCK0q6EzeBqm Tc6Q/fcJVszPKaxFXH52l8WwjB31mbv0hsR5M7dzl9cGBNJFiLE8X9zQbPjt7yi13eTb +hYrgs/m/hkK3FRhKnopDAs5EHcEA4vG5Ef4vtT6QkBqDzMPAh39LsuLInkr63qWHXkW YRvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711677286; x=1712282086; 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=RHfrMplbbUkEBek0oxfkmQFW+uLxDMPloBNof976q78=; b=VcNXbrR+2J2GbaxJ7YxZBbe9I+KpuWR7qnwoODC34zDlG4gGIiudgqykTRYGC5uxbA flVVO0IQA5ph2Wpo3jiZvpcyIOtUttnoCN5kdb+Ib3Hqqv4VQlJNW/n28g8HI4HyVkzx hCge/v45AmYt6D80HnsuCwt/eCDgqlIajCJ3fj/zKtfIqc+OevbBa9D/ARLB5X0TSqIJ wCAobsIPwvvSSRDrBarmsayHH+yCIunTwEgOIX2LbzIQI3HkNVeb8JWykHNfqZ8vpGm7 itsKoBEOm5WyK9dzGprt4jHndLP76gaLp74euenGMtyPynWlD8r5CDJxce4P9J+bhw9+ xQjg== X-Forwarded-Encrypted: i=1; AJvYcCVhg1iWGQxG2OGCJ57o71d3G3ZkXwVMd5PUynFYdFs/9TATlqfO6qcjRwtl8xmLkvnSHIoa+kcdFrLDPkuLpkXr4rXMI2jVCeYo4JUh X-Gm-Message-State: AOJu0YyQ5NeLtHPlLUbBO1DmmB0V/iHAWbuqWVerWQf0I+RI2kUubUHn hC5FOqy50kzYP3yxH/CDAB/d7/5gnbzHdHACZatfRtG+Dey7NvXDSq7htOgR8AYGcS782/UfHtF rWw== X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:fcce:d6ab:804c:b94b]) (user=drosen job=sendgmr) by 2002:a05:6902:120a:b0:dda:c59c:3953 with SMTP id s10-20020a056902120a00b00ddac59c3953mr322226ybu.0.1711677285863; Thu, 28 Mar 2024 18:54:45 -0700 (PDT) Date: Thu, 28 Mar 2024 18:53:36 -0700 In-Reply-To: <20240329015351.624249-1-drosen@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240329015351.624249-1-drosen@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240329015351.624249-22-drosen@google.com> Subject: [RFC PATCH v4 21/36] fuse-bpf: Add partial flock support 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 , Eduard Zingerman , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , Christian Brauner , kernel-team@android.com, Daniel Rosenberg Content-Type: text/plain; charset="UTF-8" This adds passthrough support for flock on fuse-bpf files. It does not give any control via a bpf filter. The flock will act as though it was taken on the lower file. see fuse_test -t32 (flock_test) Signed-off-by: Daniel Rosenberg --- fs/fuse/backing.c | 15 +++++++++++++++ fs/fuse/file.c | 9 +++++++-- fs/fuse/fuse_i.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index f18aee297335..b2df2469c29c 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1586,6 +1587,20 @@ int fuse_bpf_file_write_iter(ssize_t *out, struct inode *inode, struct kiocb *io iocb, from); } +int fuse_file_flock_backing(struct file *file, int cmd, struct file_lock *fl) +{ + struct fuse_file *ff = file->private_data; + struct file *backing_file = ff->backing_file; + int error; + + fl->fl_file = backing_file; + if (backing_file->f_op->flock) + error = backing_file->f_op->flock(backing_file, cmd, fl); + else + error = locks_lock_file_wait(backing_file, fl); + return error; +} + ssize_t fuse_backing_mmap(struct file *file, struct vm_area_struct *vma) { int ret; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 46de67810f03..255eb59d04f8 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2676,13 +2676,18 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl) { struct inode *inode = file_inode(file); struct fuse_conn *fc = get_fuse_conn(inode); + struct fuse_file *ff = file->private_data; int err; +#ifdef CONFIG_FUSE_BPF + /* TODO - this is simply passthrough, not a proper BPF filter */ + if (ff->backing_file) + return fuse_file_flock_backing(file, cmd, fl); +#endif + if (fc->no_flock) { err = locks_lock_file_wait(file, fl); } else { - struct fuse_file *ff = file->private_data; - /* emulate flock with POSIX locks */ ff->flock = true; err = fuse_setlk(file, fl, 1); diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 8ae6ad967f95..e69f83616909 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1651,6 +1651,7 @@ static inline int fuse_bpf_access(int *out, struct inode *inode, int mask) #endif // CONFIG_FUSE_BPF +int fuse_file_flock_backing(struct file *file, int cmd, struct file_lock *fl); ssize_t fuse_backing_mmap(struct file *file, struct vm_area_struct *vma); int fuse_handle_backing(struct fuse_bpf_entry *fbe, struct path *backing_path); -- 2.44.0.478.gd926399ef9-goog