Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5229765rwb; Mon, 21 Nov 2022 19:07:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Z1EXs06DOoq5RXTII7EI/Q2tgmYpcujqOce1HswEvjzvUy8kYqDoAi/pc0PcseRdKkznv X-Received: by 2002:aa7:c758:0:b0:469:b3fc:8d7c with SMTP id c24-20020aa7c758000000b00469b3fc8d7cmr5125195eds.393.1669086427360; Mon, 21 Nov 2022 19:07:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669086427; cv=none; d=google.com; s=arc-20160816; b=EuoOiDE6rCWcVD/Uz4J4bhnkfplVUSkEO15y26i9fhactBIRW8s1bX64iMC2UfwC0m FFQg3woKYOWu+GnFnh/TrZz3c+ZPrxMH8aa0GHZMyGeHrJa+MwmoOs1XRYodr3ralfLn npiQZcB7Ft+LxXW9UQGQnTIenFvMO0kL/Y5supnzebrH++pnRmRwO4iv7+TuujAT9KBX fficrge56GZaL2Noq0xp5T9kZUFHU0Usbd9nHkk/j7CYQbswbySCHnI6u/vHAAzipP3/ hXZCbysLjj1nWk2B0+eLHf9nIaUIfkTi4yaWOhq4w5IsDGM/0m+4bOWefgZ51LKjszcd JoIA== 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=xynMcMsTuZqMLXL5ELmNHCW5CNZGRvCuOQzJlNlxPiE=; b=U/f1WEBmt5ejHYYP4EJ0Z3QmNpWQDaAfJHswvwn7Mzz8IBzWrAvRA80ThrI5zHVV9R 1T4T+Rv0N6vZTdy9PGG3fXQA9hKrPAxTTt64Xz5cHDyLKElER6N8aEhAR0zQwHROQrKw pTs2dvW2Kgj/jZPsiW0aVXeNPkcKyWLk0DwRo701X9SvIvjUup2nc1vTuCrzQZrUd7dR JPUP2ySD8GLSe2D78tdoMabQ8P9OQSwtmX2GEzeFC74PLFYTLcat6i63XCxxDkOthgb8 anoGwq+u2T0zH+jv0lN9rbWhmurQWFjJgGxx2ADrMO0p6eciyqL4Ihyqhjfq/VfW29je deOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OUOhjEq4; 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 sh39-20020a1709076ea700b007b8b7da6480si71303ejc.659.2022.11.21.19.06.45; Mon, 21 Nov 2022 19:07:07 -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=OUOhjEq4; 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 S232706AbiKVCUp (ORCPT + 92 others); Mon, 21 Nov 2022 21:20:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232591AbiKVCTk (ORCPT ); Mon, 21 Nov 2022 21:19:40 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5926E9148 for ; Mon, 21 Nov 2022 18:16:41 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id a1-20020a056902056100b006e6f103d4c1so12687090ybt.23 for ; Mon, 21 Nov 2022 18:16:41 -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=xynMcMsTuZqMLXL5ELmNHCW5CNZGRvCuOQzJlNlxPiE=; b=OUOhjEq4CnL9PVEr0QtLZtsjmGIU43rGzRaSI9yqkOCe/Tq6OgBYhpEJftwd6UWyQ/ 5eeE3FmCGczyreI5r/W4v9N5jqJoGlmQM2q02oW82bjyNtSfMiVAKuuRlyzzRCpqIjcK JqE5A8cs7Nov5Mp1Pr5ppPvmjSjUDvqdNwrEJcxCVXa1nPeGGAqVPzHzrRRvLfekRmG7 QN92GztkE/9jyU1ktQ0mdS+rYMrfjbUKE1XfIg7zDourWrv+MzvWMpNiFOUi1VzoyY63 oGRcclGwP2xBOMc//CIF4OX7JWonfe7495+rdT4v40NBqMMb/aLuZjA/x9Bb7/9mHKQn NAIQ== 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=xynMcMsTuZqMLXL5ELmNHCW5CNZGRvCuOQzJlNlxPiE=; b=1EC8G9bhIOj6vHl9wkwPzeHcnMOMeFowNFWK9vnX+xQhH+n861EAA5qr3QS4nq3hO/ 1e70COO+ZV9Hpgh0/gUG+ApWlFGhJ6BaatSc3NeqvqQd4MLzUUEEzBZ8FDHJHL1ErGT4 yPT9/S96m9E/L0m+hyfk0JYZi9YgC6iWFGVLg7Iobs2HI7Md6Ov5IQf244mtrlkLgzJk y+cSwdu3SMEihWcMqQrhKXkqzmtJ5g4v18pHgnEGCUWWCn4tE7nsNNhHP/+rVBDZNbeJ tI85g1Kq2meMq281MN274NWYcZ1ZiHFwBu/gnCq/qmY765PwVdRMJFP/u6VMVFejnb3D 36SA== X-Gm-Message-State: ANoB5pmIIYX1IRdVhOTn4kGTz0KhkDJ/hdsYuPrkzMbFjb7w8HdmmlPm 6K3v+DVbGv15ydAY7H9a6Exds5NtEoo= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:200:8539:aadd:13be:6e82]) (user=drosen job=sendgmr) by 2002:a25:ae12:0:b0:6d0:704:f19f with SMTP id a18-20020a25ae12000000b006d00704f19fmr4415884ybj.191.1669083400889; Mon, 21 Nov 2022 18:16:40 -0800 (PST) Date: Mon, 21 Nov 2022 18:15:35 -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-21-drosen@google.com> Subject: [RFC PATCH v2 20/21] fuse-bpf: Add symlink/link support 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 | 271 ++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 11 ++ fs/fuse/fuse_i.h | 20 ++++ 3 files changed, 302 insertions(+) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index 05fb88865289..a77414e8f3df 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -2319,6 +2319,104 @@ int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry) dir, entry); } +static int fuse_link_initialize_in(struct fuse_args *fa, struct fuse_link_in *fli, + struct dentry *entry, struct inode *dir, + struct dentry *newent) +{ + struct inode *src_inode = entry->d_inode; + + *fli = (struct fuse_link_in) { + .oldnodeid = get_node_id(src_inode), + }; + + fa->opcode = FUSE_LINK; + fa->in_numargs = 2; + fa->in_args[0].size = sizeof(*fli); + fa->in_args[0].value = fli; + fa->in_args[1].size = newent->d_name.len + 1; + fa->in_args[1].value = (void *) newent->d_name.name; + + return 0; +} + +static int fuse_link_initialize_out(struct fuse_args *fa, struct fuse_link_in *fli, + struct dentry *entry, struct inode *dir, + struct dentry *newent) +{ + return 0; +} + +static int fuse_link_backing(struct fuse_args *fa, int *out, struct dentry *entry, + struct inode *dir, struct dentry *newent) +{ + struct path backing_old_path; + struct path backing_new_path; + struct dentry *backing_dir_dentry; + struct inode *fuse_new_inode = NULL; + struct fuse_inode *fuse_dir_inode = get_fuse_inode(dir); + struct inode *backing_dir_inode = fuse_dir_inode->backing_inode; + + *out = 0; + get_fuse_backing_path(entry, &backing_old_path); + if (!backing_old_path.dentry) + return -EBADF; + + get_fuse_backing_path(newent, &backing_new_path); + if (!backing_new_path.dentry) { + *out = -EBADF; + goto err_dst_path; + } + + backing_dir_dentry = dget_parent(backing_new_path.dentry); + backing_dir_inode = d_inode(backing_dir_dentry); + + inode_lock_nested(backing_dir_inode, I_MUTEX_PARENT); + *out = vfs_link(backing_old_path.dentry, &init_user_ns, + backing_dir_inode, backing_new_path.dentry, NULL); + inode_unlock(backing_dir_inode); + if (*out) + goto out; + + if (d_really_is_negative(backing_new_path.dentry) || + unlikely(d_unhashed(backing_new_path.dentry))) { + *out = -EINVAL; + /** + * TODO: overlayfs responds to this situation with a + * lookupOneLen. Should we do that too? + */ + goto out; + } + + fuse_new_inode = fuse_iget_backing(dir->i_sb, fuse_dir_inode->nodeid, backing_dir_inode); + if (IS_ERR(fuse_new_inode)) { + *out = PTR_ERR(fuse_new_inode); + goto out; + } + d_instantiate(newent, fuse_new_inode); + +out: + dput(backing_dir_dentry); + path_put(&backing_new_path); +err_dst_path: + path_put(&backing_old_path); + return *out; +} + +static int fuse_link_finalize(struct fuse_args *fa, int *out, struct dentry *entry, + struct inode *dir, struct dentry *newent) +{ + return 0; +} + +int fuse_bpf_link(int *out, struct inode *inode, struct dentry *entry, + struct inode *newdir, struct dentry *newent) +{ + return fuse_bpf_backing(inode, struct fuse_link_in, out, + fuse_link_initialize_in, fuse_link_initialize_out, + fuse_link_backing, fuse_link_finalize, entry, + newdir, newent); +} + struct fuse_getattr_io { struct fuse_getattr_in fgi; struct fuse_attr_out fao; @@ -2600,6 +2698,179 @@ int fuse_bpf_statfs(int *out, struct inode *inode, struct dentry *dentry, struct dentry, buf); } +static int fuse_get_link_initialize_in(struct fuse_args *fa, struct fuse_unused_io *unused, + struct inode *inode, struct dentry *dentry, + struct delayed_call *callback) +{ + /* + * TODO + * If we want to handle changing these things, we'll need to copy + * the lower fs's data into our own buffer, and provide our own callback + * to free that buffer. + * + * Pre could change the name we're looking at + * postfilter can change the name we return + * + * We ought to only make that buffer if it's been requested, so leaving + * this unimplemented for the moment + */ + *fa = (struct fuse_args) { + .opcode = FUSE_READLINK, + .nodeid = get_node_id(inode), + .in_numargs = 1, + .in_args[0] = (struct fuse_in_arg) { + .size = dentry->d_name.len + 1, + .value = (void *) dentry->d_name.name, + }, + /* + * .out_argvar = 1, + * .out_numargs = 1, + * .out_args[0].size = , + * .out_args[0].value = , + */ + }; + + return 0; +} + +static int fuse_get_link_initialize_out(struct fuse_args *fa, struct fuse_unused_io *unused, + struct inode *inode, struct dentry *dentry, + struct delayed_call *callback) +{ + /* + * .out_argvar = 1, + * .out_numargs = 1, + * .out_args[0].size = , + * .out_args[0].value = , + */ + + return 0; +} + +static int fuse_get_link_backing(struct fuse_args *fa, const char **out, + struct inode *inode, struct dentry *dentry, + struct delayed_call *callback) +{ + struct path backing_path; + + if (!dentry) { + *out = ERR_PTR(-ECHILD); + return PTR_ERR(*out); + } + + get_fuse_backing_path(dentry, &backing_path); + if (!backing_path.dentry) { + *out = ERR_PTR(-ECHILD); + return PTR_ERR(*out); + } + + /* + * TODO: If we want to do our own thing, copy the data and then call the + * callback + */ + *out = vfs_get_link(backing_path.dentry, callback); + + path_put(&backing_path); + return 0; +} + +static int fuse_get_link_finalize(struct fuse_args *fa, const char **out, + struct inode *inode, struct dentry *dentry, + struct delayed_call *callback) +{ + return 0; +} + +int fuse_bpf_get_link(const char **out, struct inode *inode, struct dentry *dentry, + struct delayed_call *callback) +{ + return fuse_bpf_backing(inode, struct fuse_unused_io, out, + fuse_get_link_initialize_in, fuse_get_link_initialize_out, + fuse_get_link_backing, + fuse_get_link_finalize, + inode, dentry, callback); +} + +static int fuse_symlink_initialize_in(struct fuse_args *fa, struct fuse_unused_io *unused, + struct inode *dir, struct dentry *entry, const char *link, int len) +{ + *fa = (struct fuse_args) { + .nodeid = get_node_id(dir), + .opcode = FUSE_SYMLINK, + .in_numargs = 2, + .in_args[0] = (struct fuse_in_arg) { + .size = entry->d_name.len + 1, + .value = (void *) entry->d_name.name, + }, + .in_args[1] = (struct fuse_in_arg) { + .size = len, + .value = (void *) link, + }, + }; + + return 0; +} + +static int fuse_symlink_initialize_out(struct fuse_args *fa, struct fuse_unused_io *unused, + struct inode *dir, struct dentry *entry, const char *link, int len) +{ + return 0; +} + +static int fuse_symlink_backing(struct fuse_args *fa, int *out, + struct inode *dir, struct dentry *entry, const char *link, int len) +{ + 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; + + *out = 0; + //TODO Actually deal with changing the backing entry in symlink + get_fuse_backing_path(entry, &backing_path); + if (!backing_path.dentry) + return -EBADF; + + inode_lock_nested(backing_inode, I_MUTEX_PARENT); + *out = vfs_symlink(&init_user_ns, backing_inode, backing_path.dentry, + link); + 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_symlink_finalize(struct fuse_args *fa, int *out, + struct inode *dir, struct dentry *entry, const char *link, int len) +{ + return 0; +} + +int fuse_bpf_symlink(int *out, struct inode *dir, struct dentry *entry, const char *link, int len) +{ + return fuse_bpf_backing(dir, struct fuse_unused_io, out, + fuse_symlink_initialize_in, fuse_symlink_initialize_out, + fuse_symlink_backing, fuse_symlink_finalize, + dir, entry, link, len); +} + struct fuse_read_io { struct fuse_read_in fri; struct fuse_read_out fro; diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 899de6c84c2e..1f9105edc7e2 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -945,6 +945,10 @@ static int fuse_symlink(struct user_namespace *mnt_userns, struct inode *dir, struct fuse_mount *fm = get_fuse_mount(dir); unsigned len = strlen(link) + 1; FUSE_ARGS(args); + int err; + + if (fuse_bpf_symlink(&err, dir, entry, link, len)) + return err; args.opcode = FUSE_SYMLINK; args.in_numargs = 2; @@ -1151,6 +1155,9 @@ static int fuse_link(struct dentry *entry, struct inode *newdir, struct fuse_mount *fm = get_fuse_mount(inode); FUSE_ARGS(args); + if (fuse_bpf_link(&err, inode, entry, newdir, newent)) + return err; + memset(&inarg, 0, sizeof(inarg)); inarg.oldnodeid = get_node_id(inode); args.opcode = FUSE_LINK; @@ -1543,12 +1550,16 @@ static const char *fuse_get_link(struct dentry *dentry, struct inode *inode, { struct fuse_conn *fc = get_fuse_conn(inode); struct page *page; + const char *out = NULL; int err; err = -EIO; if (fuse_is_bad(inode)) goto out_err; + if (fuse_bpf_get_link(&out, inode, dentry, callback)) + return out; + if (fc->cache_symlinks) return page_get_link(dentry, inode, callback); diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 37b29a3ea330..99c9231ec98b 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1412,6 +1412,7 @@ int fuse_bpf_rename2(int *out, struct inode *olddir, struct dentry *oldent, int fuse_bpf_rename(int *out, struct inode *olddir, struct dentry *oldent, struct inode *newdir, struct dentry *newent); int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *entry); +int fuse_bpf_link(int *out, struct inode *inode, struct dentry *entry, struct inode *dir, struct dentry *newent); int fuse_bpf_release(int *out, struct inode *inode, struct file *file); int fuse_bpf_releasedir(int *out, struct inode *inode, struct file *file); int fuse_bpf_flush(int *out, struct inode *inode, struct file *file, fl_owner_t id); @@ -1436,6 +1437,9 @@ int fuse_bpf_getattr(int *out, struct inode *inode, const struct dentry *entry, u32 request_mask, unsigned int flags); int fuse_bpf_setattr(int *out, struct inode *inode, struct dentry *dentry, struct iattr *attr, struct file *file); int fuse_bpf_statfs(int *out, struct inode *inode, struct dentry *dentry, struct kstatfs *buf); +int fuse_bpf_get_link(const char **out, struct inode *inode, struct dentry *dentry, + struct delayed_call *callback); +int fuse_bpf_symlink(int *out, struct inode *dir, struct dentry *entry, const char *link, int len); int fuse_bpf_readdir(int *out, struct inode *inode, struct file *file, struct dir_context *ctx); int fuse_bpf_access(int *out, struct inode *inode, int mask); @@ -1485,6 +1489,11 @@ static inline int fuse_bpf_unlink(int *out, struct inode *dir, struct dentry *en return 0; } +static inline int fuse_bpf_link(int *out, struct inode *inode, struct dentry *entry, struct inode *dir, struct dentry *newent) +{ + return 0; +} + static inline int fuse_bpf_release(int *out, struct inode *inode, struct file *file) { return 0; @@ -1581,6 +1590,17 @@ static inline int fuse_bpf_statfs(int *out, struct inode *inode, struct dentry * return 0; } +static inline int fuse_bpf_get_link(const char **out, struct inode *inode, struct dentry *dentry, + struct delayed_call *callback) +{ + return 0; +} + +static inline int fuse_bpf_symlink(int *out, struct inode *dir, struct dentry *entry, const char *link, int len) +{ + return 0; +} + static inline int fuse_bpf_readdir(int *out, struct inode *inode, struct file *file, struct dir_context *ctx) { return 0; -- 2.38.1.584.g0f3c55d4c2-goog