Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp821291lqh; Thu, 28 Mar 2024 18:59:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVWA2LpKqCTIGWTECyxv/XvmYaFCFsv2qzHiD6qGCFsM/xJdmGQswtK91GXoQXGDccXRxm6vd72eT127leC5rIzmf0V2GZidTzp7u3gKg== X-Google-Smtp-Source: AGHT+IE3mNbg6A3rSb7XsD6fSED2gh13dcVfsDL0lLWYtQmNUVes/9sFX/4ZD68TXcEPbs53k/tP X-Received: by 2002:a05:622a:1a26:b0:431:7333:7adb with SMTP id f38-20020a05622a1a2600b0043173337adbmr6002295qtb.12.1711677576251; Thu, 28 Mar 2024 18:59:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711677576; cv=pass; d=google.com; s=arc-20160816; b=guNoXQb0JQh4R+JP6l+tM3ujd+uW3/KJuGXJ41uC2fd4eH7BMfE65PnjuEuFQVGwy7 CxCEt4ZfPv1Aw+J+wq3d9uw/vIUM2WpMX8hO3/g/NhkXXtbqIQ6q3BpIurpnhtH8jdZc Hxho0SfpTNLiBXivbgLt37alGOtpXL86B4MKZ/MAREc2WWK4qox9RnkCuxeDSGNLSkNx qHtInnmxPbHrRFJPW6ZPvWBQ7rbhFinzBP3G6Yaqmjh84/oWDR0/t20knQrbAtFLPQDt xDtnoVkOorfznD2uNzMOBUFdHCgQsN9W7adXqZpypGUTVrX8K0qx1v+Vvy7fkfc9dVkb S7+w== 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=ktsTVmyBdlTiNpg1aGMp+wH2qwaXK1AaKKS16VfXuCw=; fh=r2A7YzhxJ5aCiV62oMryHETFyNhEiEMbAIqVIlwvXlY=; b=TN3ODKqn0ge1a9xFBT+RhmrukvbdIVkJIBFZlROUyBsbmjo2g7UOqj1dGfgqOlSMLx xsz9UHv25lYVqgVU7NnprgjU6Bjd2GcmH0bzeUyFc1fiz33HdUFkRbBH+Vs9MBZlbmp4 qR4h0lhM2RGD+OZjHxumPKS2OilQWuOBqfFySH2nnYe5UDGxsU6+nlM1yxIGcuazPAPY eEEP93yFOSa+phnaCmvBWamwmBmGxDl3ya5NGZOXPdQduBfvtA11enpe2aPYgKyScWoF 80CHa0PWw3mUQp0ECO82l6eK9oqzmxvI0hDPq1Wzyp0ypoNxNzwp09mWOlSnxiuL7SRP LDzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=011HA22H; 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-123992-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123992-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. [147.75.199.223]) by mx.google.com with ESMTPS id o11-20020a05622a044b00b0043175068184si2711605qtx.76.2024.03.28.18.59.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 18:59:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123992-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=011HA22H; 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-123992-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123992-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 E5A8E1C2693F for ; Fri, 29 Mar 2024 01:59:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5EFD4436D; Fri, 29 Mar 2024 01:54:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="011HA22H" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 4FB934085F for ; Fri, 29 Mar 2024 01:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677269; cv=none; b=DhxqvYRE76nuRcL0JcJFVsQ1pYZpeT2gIxrzFbCKCN2VHMKVuRQa4rORFFoGr5+qFMI5rPekRvulQqQ1tLUiNTHAxBKgxWUwMRTLiTZCLuT3S67Xqh4N4+nz4PvNdynaqr+2GyN7fJYz/bjEe2C97wQGXM0a/AlHjtpm3EqNowU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677269; c=relaxed/simple; bh=JLW59NjmZEXXJzbkpxfd4s8AQSfi6of7y8Bzc4kj/Po=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tkKhegQvXgLqdnlFjwjE4r7MMKHsuWNwXJO1EzsHc/Silksx4oSKM15DM6CC3FdVFlNIrreFPXSl1HHBuyOmjE7gvxsPBEASaHOd+hThgUDkHowk2jrUWhopKOpUVSBh+49l+xFJ9pdniyv/kf4T0N0NZr8OnGF/eP6wvfAIlnE= 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=011HA22H; arc=none smtp.client-ip=209.85.219.202 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-f202.google.com with SMTP id 3f1490d57ef6-dc693399655so2763368276.1 for ; Thu, 28 Mar 2024 18:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711677265; x=1712282065; 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=ktsTVmyBdlTiNpg1aGMp+wH2qwaXK1AaKKS16VfXuCw=; b=011HA22Hps4cpxNx2buAPfy87SMOxluGxh315GZYczaGqPRp4j9AoAPv5j9X4RUHkl GnLdAUrxCinE4g7n7FixzGrAEYgVt4KJynpx+F/eB3YdzFr5h6BUB4oKCwfaxGJCaxek 6ZMHrsiKhPtQySHXW5cn1jLxfe/cxdTekgCnhY3t5KoCCrPR6YhHVIa+ujDwZK/XojtI vxTZCIzx8sHMXu52K9r9OXUUUor8zm586LajpDNEE65gWU431Ae9/yGPf6ZzElTCayWM vuvf2aUGrbTbBUl4M3ZjJ1wftcvdD5L7WhT46VMgjoiLHnGw9312mKQAySbOjaAH6M3o en5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711677265; x=1712282065; 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=ktsTVmyBdlTiNpg1aGMp+wH2qwaXK1AaKKS16VfXuCw=; b=w6DnV4sJOk/66fGHVvub8LS/jZlwWl39YIEflksPQ/DZgMZc9WJ+l7vgXNAvyJXWS3 DqKCR8rDhkp52pmgSIJ5eo5HvCWsqoqrTm6cW/Xu/boLFGWiKm8jsm68Vp3eexkAno34 XFb7sLMEyUb0Xd+YPJbbDhgmBHcgCeQlaJwEeVamJd3E4MBoniVMcJbKgWYZ9g4v86q4 jwzdlMJ5shTcQOs+oLpTd/sRV4/9BLXv0irccrd3jjmW7Px92e0oruBS/7a14w7zkd4f 1MPKijmMwCn8yCKWCsw7IUwz7WLKy9yUTAfvB2qLb++3MI1hXc1k7ZXEGJxznB99daVA G0Iw== X-Forwarded-Encrypted: i=1; AJvYcCWzqLSbv4S0Nkjto/GkWcbKQtFjol4qab5YDA4muyfNkGlBs1hF02RDIkDBjoVmU1tbwel4uaUmzkc79g18KbYPLGKFnba+Lk+JI7oS X-Gm-Message-State: AOJu0YzU6jxdbc//61ig93FhmUjZmaIzGG94YDoeudPpfhH0XESPejGK hl+7gnc+UHTpM3B3j3lvybQI4F+j69wXm0JafrRAEUvFmRQ7RTQKXFHwfiJfjcb4MaCde7Jj8Qd ReQ== X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:fcce:d6ab:804c:b94b]) (user=drosen job=sendgmr) by 2002:a05:6902:2503:b0:dc9:c54e:c5eb with SMTP id dt3-20020a056902250300b00dc9c54ec5ebmr307231ybb.7.1711677265603; Thu, 28 Mar 2024 18:54:25 -0700 (PDT) Date: Thu, 28 Mar 2024 18:53:27 -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-13-drosen@google.com> Subject: [RFC PATCH v4 12/36] fuse-bpf: Support mknod/unlink/mkdir/rmdir 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 , Paul Lawrence Content-Type: text/plain; charset="UTF-8" This adds backing support for FUSE_MKNOD, FUSE_MKDIR, FUSE_RMDIR, and FUSE_UNLINK Signed-off-by: Daniel Rosenberg Signed-off-by: Paul Lawrence --- fs/fuse/backing.c | 342 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 14 ++ fs/fuse/fuse_i.h | 24 ++++ 3 files changed, 380 insertions(+) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index 317a3adbbb3e..567f859d300c 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -947,6 +947,348 @@ int fuse_revalidate_backing(struct dentry *entry, unsigned int flags) return 1; } +struct fuse_mknod_args { + struct fuse_mknod_in in; + struct fuse_buffer name; +}; + +static int fuse_mknod_initialize_in(struct bpf_fuse_args *fa, struct fuse_mknod_args *args, + struct inode *dir, struct dentry *entry, umode_t mode, dev_t rdev) +{ + *args = (struct fuse_mknod_args) { + .in = (struct fuse_mknod_in) { + .mode = mode, + .rdev = new_encode_dev(rdev), + .umask = current_umask(), + }, + .name = (struct fuse_buffer) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len + 1, + .flags = BPF_FUSE_IMMUTABLE, + }, + }; + *fa = (struct bpf_fuse_args) { + .info = (struct bpf_fuse_meta_info) { + .nodeid = get_node_id(dir), + .opcode = FUSE_MKNOD, + }, + .in_numargs = 2, + .in_args[0] = (struct bpf_fuse_arg) { + .size = sizeof(args->in), + .value = &args->in, + }, + .in_args[1] = (struct bpf_fuse_arg) { + .is_buffer = true, + .buffer = &args->name, + }, + }; + + return 0; +} + +static int fuse_mknod_initialize_out(struct bpf_fuse_args *fa, struct fuse_mknod_args *args, + struct inode *dir, struct dentry *entry, umode_t mode, dev_t rdev) +{ + return 0; +} + +static int fuse_mknod_backing(struct bpf_fuse_args *fa, int *out, + struct inode *dir, struct dentry *entry, umode_t mode, dev_t rdev) +{ + const struct fuse_mknod_in *fmi = fa->in_args[0].value; + struct fuse_inode *fuse_inode = get_fuse_inode(dir); + struct inode *backing_inode = fuse_inode->backing_inode; + struct path backing_path; + struct inode *inode = NULL; + + get_fuse_backing_path(entry, &backing_path); + if (!backing_path.dentry) + return -EBADF; + + inode_lock_nested(backing_inode, I_MUTEX_PARENT); + mode = fmi->mode; + if (!IS_POSIXACL(backing_inode)) + mode &= ~fmi->umask; + *out = vfs_mknod(&nop_mnt_idmap, backing_inode, backing_path.dentry, mode, + new_decode_dev(fmi->rdev)); + inode_unlock(backing_inode); + if (*out) + goto out; + if (d_really_is_negative(backing_path.dentry) || + unlikely(d_unhashed(backing_path.dentry))) { + *out = -EINVAL; + /** + * TODO: overlayfs responds to this situation with a + * lookupOneLen. Should we do that too? + */ + goto out; + } + inode = fuse_iget_backing(dir->i_sb, fuse_inode->nodeid, backing_inode); + if (IS_ERR(inode)) { + *out = PTR_ERR(inode); + goto out; + } + d_instantiate(entry, inode); +out: + path_put(&backing_path); + return *out; +} + +static int fuse_mknod_finalize(struct bpf_fuse_args *fa, int *out, + struct inode *dir, struct dentry *entry, umode_t mode, dev_t rdev) +{ + return 0; +} + +int fuse_bpf_mknod(int *out, struct inode *dir, struct dentry *entry, umode_t mode, dev_t rdev) +{ + return bpf_fuse_backing(dir, struct fuse_mknod_args, out, + fuse_mknod_initialize_in, fuse_mknod_initialize_out, + fuse_mknod_backing, fuse_mknod_finalize, + dir, entry, mode, rdev); +} + +struct fuse_mkdir_args { + struct fuse_mkdir_in in; + struct fuse_buffer name; +}; + +static int fuse_mkdir_initialize_in(struct bpf_fuse_args *fa, struct fuse_mkdir_args *args, + struct inode *dir, struct dentry *entry, umode_t mode) +{ + *args = (struct fuse_mkdir_args) { + .in = (struct fuse_mkdir_in) { + .mode = mode, + .umask = current_umask(), + }, + .name = (struct fuse_buffer) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len + 1, + .flags = BPF_FUSE_IMMUTABLE, + }, + }; + + *fa = (struct bpf_fuse_args) { + .info = (struct bpf_fuse_meta_info) { + .nodeid = get_node_id(dir), + .opcode = FUSE_MKDIR, + }, + .in_numargs = 2, + .in_args[0] = (struct bpf_fuse_arg) { + .size = sizeof(args->in), + .value = &args->in, + }, + .in_args[1] = (struct bpf_fuse_arg) { + .value = &args->name, + .is_buffer = true, + }, + }; + + return 0; +} + +static int fuse_mkdir_initialize_out(struct bpf_fuse_args *fa, struct fuse_mkdir_args *args, + struct inode *dir, struct dentry *entry, umode_t mode) +{ + return 0; +} + +static int fuse_mkdir_backing(struct bpf_fuse_args *fa, int *out, + struct inode *dir, struct dentry *entry, umode_t mode) +{ + const struct fuse_mkdir_in *fmi = fa->in_args[0].value; + struct fuse_inode *fuse_inode = get_fuse_inode(dir); + struct inode *backing_inode = fuse_inode->backing_inode; + struct path backing_path; + struct inode *inode = NULL; + struct dentry *d; + + get_fuse_backing_path(entry, &backing_path); + if (!backing_path.dentry) + return -EBADF; + + inode_lock_nested(backing_inode, I_MUTEX_PARENT); + mode = fmi->mode; + if (!IS_POSIXACL(backing_inode)) + mode &= ~fmi->umask; + *out = vfs_mkdir(&nop_mnt_idmap, backing_inode, backing_path.dentry, + mode); + if (*out) + goto out; + if (d_really_is_negative(backing_path.dentry) || + unlikely(d_unhashed(backing_path.dentry))) { + d = lookup_one_len(entry->d_name.name, + backing_path.dentry->d_parent, + entry->d_name.len); + if (IS_ERR(d)) { + *out = PTR_ERR(d); + goto out; + } + dput(backing_path.dentry); + backing_path.dentry = d; + } + inode = fuse_iget_backing(dir->i_sb, fuse_inode->nodeid, backing_inode); + if (IS_ERR(inode)) { + *out = PTR_ERR(inode); + goto out; + } + d_instantiate(entry, inode); +out: + inode_unlock(backing_inode); + path_put(&backing_path); + return *out; +} + +static int fuse_mkdir_finalize(struct bpf_fuse_args *fa, int *out, + struct inode *dir, struct dentry *entry, umode_t mode) +{ + return 0; +} + +int fuse_bpf_mkdir(int *out, struct inode *dir, struct dentry *entry, umode_t mode) +{ + return bpf_fuse_backing(dir, struct fuse_mkdir_args, out, + fuse_mkdir_initialize_in, fuse_mkdir_initialize_out, + fuse_mkdir_backing, fuse_mkdir_finalize, + dir, entry, mode); +} + +static int fuse_rmdir_initialize_in(struct bpf_fuse_args *fa, struct fuse_buffer *name, + struct inode *dir, struct dentry *entry) +{ + *name = (struct fuse_buffer) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len + 1, + .flags = BPF_FUSE_IMMUTABLE, + }; + *fa = (struct bpf_fuse_args) { + .info = (struct bpf_fuse_meta_info) { + .nodeid = get_node_id(dir), + .opcode = FUSE_RMDIR, + }, + .in_numargs = 1, + .in_args[0] = (struct bpf_fuse_arg) { + .is_buffer = true, + .buffer = name, + }, + }; + + return 0; +} + +static int fuse_rmdir_initialize_out(struct bpf_fuse_args *fa, struct fuse_buffer *name, + struct inode *dir, struct dentry *entry) +{ + return 0; +} + +static int fuse_rmdir_backing(struct bpf_fuse_args *fa, int *out, + struct inode *dir, struct dentry *entry) +{ + struct path backing_path; + struct dentry *backing_parent_dentry; + struct inode *backing_inode; + + get_fuse_backing_path(entry, &backing_path); + if (!backing_path.dentry) + return -EBADF; + + backing_parent_dentry = dget_parent(backing_path.dentry); + backing_inode = d_inode(backing_parent_dentry); + + inode_lock_nested(backing_inode, I_MUTEX_PARENT); + *out = vfs_rmdir(&nop_mnt_idmap, backing_inode, backing_path.dentry); + inode_unlock(backing_inode); + + dput(backing_parent_dentry); + if (!*out) + d_drop(entry); + path_put(&backing_path); + return *out; +} + +static int fuse_rmdir_finalize(struct bpf_fuse_args *fa, int *out, struct inode *dir, struct dentry *entry) +{ + return 0; +} + +int fuse_bpf_rmdir(int *out, struct inode *dir, struct dentry *entry) +{ + return bpf_fuse_backing(dir, struct fuse_buffer, out, + fuse_rmdir_initialize_in, fuse_rmdir_initialize_out, + fuse_rmdir_backing, fuse_rmdir_finalize, + dir, entry); +} + +static int fuse_unlink_initialize_in(struct bpf_fuse_args *fa, struct fuse_buffer *name, + struct inode *dir, struct dentry *entry) +{ + *name = (struct fuse_buffer) { + .data = (void *) entry->d_name.name, + .size = entry->d_name.len + 1, + .flags = BPF_FUSE_IMMUTABLE, + }; + *fa = (struct bpf_fuse_args) { + .info = (struct bpf_fuse_meta_info) { + .nodeid = get_node_id(dir), + .opcode = FUSE_UNLINK, + }, + .in_numargs = 1, + .in_args[0] = (struct bpf_fuse_arg) { + .is_buffer = true, + .buffer = name, + }, + }; + + return 0; +} + +static int fuse_unlink_initialize_out(struct bpf_fuse_args *fa, struct fuse_buffer *name, + struct inode *dir, struct dentry *entry) +{ + return 0; +} + +static int fuse_unlink_backing(struct bpf_fuse_args *fa, int *out, struct inode *dir, struct dentry *entry) +{ + struct path backing_path; + struct dentry *backing_parent_dentry; + struct inode *backing_inode; + + get_fuse_backing_path(entry, &backing_path); + if (!backing_path.dentry) + return -EBADF; + + /* TODO Not sure if we should reverify like overlayfs, or get inode from d_parent */ + backing_parent_dentry = dget_parent(backing_path.dentry); + backing_inode = d_inode(backing_parent_dentry); + + inode_lock_nested(backing_inode, I_MUTEX_PARENT); + *out = vfs_unlink(&nop_mnt_idmap, backing_inode, backing_path.dentry, + NULL); + inode_unlock(backing_inode); + + dput(backing_parent_dentry); + if (!*out) + d_drop(entry); + path_put(&backing_path); + return *out; +} + +static int fuse_unlink_finalize(struct bpf_fuse_args *fa, int *out, + struct inode *dir, struct dentry *entry) +{ + return 0; +} + +int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry) +{ + return bpf_fuse_backing(dir, struct fuse_buffer, out, + fuse_unlink_initialize_in, fuse_unlink_initialize_out, + fuse_unlink_backing, fuse_unlink_finalize, + dir, entry); +} + static int fuse_access_initialize_in(struct bpf_fuse_args *fa, struct fuse_access_in *in, struct inode *inode, int mask) { diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 09bb4c63fd71..a5b6aef788b2 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -957,6 +957,10 @@ static int fuse_mknod(struct mnt_idmap *idmap, struct inode *dir, struct fuse_mknod_in inarg; struct fuse_mount *fm = get_fuse_mount(dir); FUSE_ARGS(args); + int err; + + if (fuse_bpf_mknod(&err, dir, entry, mode, rdev)) + return err; if (!fm->fc->dont_mask) mode &= ~current_umask(); @@ -1003,6 +1007,10 @@ static int fuse_mkdir(struct mnt_idmap *idmap, struct inode *dir, struct fuse_mkdir_in inarg; struct fuse_mount *fm = get_fuse_mount(dir); FUSE_ARGS(args); + int err; + + if (fuse_bpf_mkdir(&err, dir, entry, mode)) + return err; if (!fm->fc->dont_mask) mode &= ~current_umask(); @@ -1089,6 +1097,9 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry) if (fuse_is_bad(dir)) return -EIO; + if (fuse_bpf_unlink(&err, dir, entry)) + return err; + args.opcode = FUSE_UNLINK; args.nodeid = get_node_id(dir); args.in_numargs = 1; @@ -1112,6 +1123,9 @@ static int fuse_rmdir(struct inode *dir, struct dentry *entry) if (fuse_is_bad(dir)) return -EIO; + if (fuse_bpf_rmdir(&err, dir, entry)) + return err; + args.opcode = FUSE_RMDIR; args.nodeid = get_node_id(dir); args.in_numargs = 1; diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index a133010fde1c..9b176f78999f 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1441,6 +1441,10 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num_entries); int fuse_bpf_open(int *err, struct inode *inode, struct file *file, bool isdir); int fuse_bpf_create_open(int *out, struct inode *dir, struct dentry *entry, struct file *file, unsigned int flags, umode_t mode); +int fuse_bpf_mknod(int *out, struct inode *dir, struct dentry *entry, umode_t mode, dev_t rdev); +int fuse_bpf_mkdir(int *out, struct inode *dir, struct dentry *entry, umode_t mode); +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 fuse_file *ff); int fuse_bpf_releasedir(int *out, struct inode *inode, struct fuse_file *ff); int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *file, loff_t offset, int whence); @@ -1461,6 +1465,26 @@ static inline int fuse_bpf_create_open(int *out, struct inode *dir, struct dentr return 0; } +static inline int fuse_bpf_mknod(int *out, struct inode *dir, struct dentry *entry, umode_t mode, dev_t rdev) +{ + return 0; +} + +static inline int fuse_bpf_mkdir(int *out, struct inode *dir, struct dentry *entry, umode_t mode) +{ + return 0; +} + +static inline int fuse_bpf_rmdir(int *out, struct inode *dir, struct dentry *entry) +{ + return 0; +} + +static inline int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry) +{ + return 0; +} + static inline int fuse_bpf_release(int *out, struct inode *inode, struct file *file) { return 0; -- 2.44.0.478.gd926399ef9-goog