Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36175240rwd; Mon, 10 Jul 2023 19:35:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlFzp9nZtE14KzW9fZQPJ0s8uZNAMcMLkP0M0WUlmrDNfLFILHvBpnQTGz18ihFXrcKzjrNT X-Received: by 2002:ac2:5bde:0:b0:4f8:651f:9bbe with SMTP id u30-20020ac25bde000000b004f8651f9bbemr11481448lfn.54.1689042933373; Mon, 10 Jul 2023 19:35:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1689042933; cv=pass; d=google.com; s=arc-20160816; b=kO3N1W+P0DZHPJLtMlv/GPIBUkt7cXYXZSSLy7NiDGXnDM1gwTbVD/se9MZdLpTtkh NcxGcbrsEzzcRXK4u4+MqLuVr23CcJcyetUVsSG/7rxEfWJLQrHGu4GRw5OAc/8mQXIg vdzHYmmXA6qXtaR8zvRfRNgAUDRgOeKmQwpNgfufgUdEAZz/2SJ39mBgquF+Om0Hjv/X b73pYjKPlKsqQIBDe5mUuJwc8I2jyxcGJQ7YLxdhmnC91cED2y8fuezwKAY91zaa+rz+ 9saGHyxg8gevXg+pIA1LDhHQtoh37j6hgDFqGPeeO8Gx6k9xzcMgIjjgbmW8dZNyh88w EVHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=nM5r4kLoXtTj1OB8dGhlf8+7pkGcDvR2giSHwak5XTQ=; fh=XvGtmF0+VVaT6J0bRzCQFzpBtmTZgkYtVchCcm/o2t8=; b=f23+jU11OIcDSFHY7ThOAZdNcR8yUxdT9n2jX+PnqK4QBgLlGgXBAM/0hHI9qLCBk8 jVmbLn9XgohX/zI/VLX3PZQj+1WVkVi+PiuRNxAkljVhRusmY7j6ijDSrjR4lTlEKItQ e2dd3BEbBZNnD4TVksCfT5y7p3PyiAUeL/YbZZm/WpwQ+tYdvuUaUQ73z6i8mU8wg0Nc DiHOaUv+YB3KBEeDYxjKjzMtq+914XdY1693HmNVfuqTwbTEkTlfJARyFh5WuNzek4yI VMr9J6CccWyCowWxER33HZavuRL88SrXQjqVWHMdt0paQBurCRNFOocKpp+IyU7A11Td zVvA== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@templeofstupid.com header.s=dreamhost header.b=cl1sWhlg; arc=pass (i=1); 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t22-20020aa7d4d6000000b0051a4adabcb5si934660edr.618.2023.07.10.19.35.09; Mon, 10 Jul 2023 19:35:33 -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=fail header.i=@templeofstupid.com header.s=dreamhost header.b=cl1sWhlg; arc=pass (i=1); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229892AbjGKBp5 (ORCPT + 99 others); Mon, 10 Jul 2023 21:45:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229938AbjGKBpz (ORCPT ); Mon, 10 Jul 2023 21:45:55 -0400 Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FB04DB for ; Mon, 10 Jul 2023 18:45:53 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id DB1B726126F for ; Tue, 11 Jul 2023 01:37:51 +0000 (UTC) Received: from pdx1-sub0-mail-a234.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 61F602610FE for ; Tue, 11 Jul 2023 01:37:51 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1689039471; a=rsa-sha256; cv=none; b=uSZlxF6+pYd8OM/WZZuBv9c6cKlKvpTSY1kSrwZtYFEI2M9rqys1/tjO8T7lGTRpH4N2G8 fsYCb9eJyVDMTHJz8rWAcGoMgGpwteTraS2UQcEs0gDKHmpGKlAQucV5oKOxc0Np4z4Fzi MSZY0qdrMhHdUkl4MpmOc4U4B/h8CDDPnEV7O3UKfZjNSKJlZ3JHpkb7txkk9HPpjckFmL 2ow5/Ovbpa2Bu3VilAfWmubZL/anP/moh6dp6ZlE/xkPBGoZqOMf5NWwmVXhE63D42ZvH9 pkJNHkVYpXTUg1i5Jt4ApQA5P8OVab5b53ktIJf298/CxS9eDrOLaX60RoRPsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1689039471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nM5r4kLoXtTj1OB8dGhlf8+7pkGcDvR2giSHwak5XTQ=; b=0DTWRP7pGwRBilyMz6AeJ5uFDe9ay9OD3Go5OnoRehdUeDxgS3OJSZWS+xMfr4uIKsEDES XshA/evfn3llrk0AYh7Z5xsV7MwfRT/dHnZ6d7mUlJKLZlu7GovgvQsCRt/Lpm5tye2dzY lmP7YNIF+gdp4i/vCgW7lXwnZK7dV/peScnP2m6lNe3yVGpR5ZyPb8iSr8Zp0ez1Y9zK4M WAMCLinNZahzVmx2TTYDWG4oE99pIkq5Q4kG2zd9b7JenUppUEmwit++P0bN6tgrjq7jCd 7hhE7l/OPja9TaTzEpf8cg7BYBH4asMVI//ad2B334DLdS5vZxdHpsHgPxopMg== ARC-Authentication-Results: i=1; rspamd-7d9c4d5c9b-d2xk7; auth=pass smtp.auth=dreamhost smtp.mailfrom=kjlx@templeofstupid.com X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|kjlx@templeofstupid.com X-MailChannels-Auth-Id: dreamhost X-Spill-Trouble: 5559d8162ae76da4_1689039471646_3482250127 X-MC-Loop-Signature: 1689039471646:3958711742 X-MC-Ingress-Time: 1689039471646 Received: from pdx1-sub0-mail-a234.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.119.120.47 (trex/6.9.1); Tue, 11 Jul 2023 01:37:51 +0000 Received: from kmjvbox (unknown [71.198.86.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kjlx@templeofstupid.com) by pdx1-sub0-mail-a234.dreamhost.com (Postfix) with ESMTPSA id 4R0NmH187jzy7 for ; Mon, 10 Jul 2023 18:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=templeofstupid.com; s=dreamhost; t=1689039471; bh=nM5r4kLoXtTj1OB8dGhlf8+7pkGcDvR2giSHwak5XTQ=; h=Date:From:To:Cc:Subject:Content-Type; b=cl1sWhlgJDAUx+Fp8BqpjD0TB1F9tdkiF6lbGUQuKmzOVx4SI/cKyW3bVMURgeSOT LjqaTol9KsPyJ4xRMRRE5dceMeTxEiXoE3pKABgPp6SaWS++gvAPdIyFBSmM9btvd3 l+ZDKsLXd4WMlXg4x/oJhV9wEVeoo6Yew1/jgloU= Received: from johansen (uid 1000) (envelope-from kjlx@templeofstupid.com) id e0085 by kmjvbox (DragonFly Mail Agent v0.12); Mon, 10 Jul 2023 18:37:14 -0700 Date: Mon, 10 Jul 2023 18:37:14 -0700 From: Krister Johansen To: Miklos Szeredi , linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, German Maglione , Greg Kurz , Max Reitz Subject: [RFC PATCH 1/2] fuse: revalidate: move lookup into a separate function Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=no 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 If this refactoring seems cumbersome, it's because the goal is to move the lookup parts of fuse_dentry_revalidate into a common function. This function will be used elsewhere in a separate commit. In the meantime, the new function fuse_dentry_revalidate_lookup is responsible for just the lookup and validation portions of the revalidate dance. The fuse_dentry_revalidate function retains the responsibility for invalidating and mutating any state associated with the origial fuse_inode and dentry. Signed-off-by: Krister Johansen --- fs/fuse/dir.c | 87 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index f67bef9d83c4..bdf5526a0733 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -193,6 +193,59 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args, args->out_args[0].value = outarg; } +static int fuse_dentry_revalidate_lookup(struct fuse_mount *fm, + struct dentry *entry, + struct inode *inode, + struct fuse_entry_out *outarg, + bool *lookedup) +{ + struct dentry *parent; + struct fuse_forget_link *forget; + struct fuse_inode *fi; + FUSE_ARGS(args); + int ret; + + forget = fuse_alloc_forget(); + ret = -ENOMEM; + if (!forget) + goto out; + + parent = dget_parent(entry); + fuse_lookup_init(fm->fc, &args, get_node_id(d_inode(parent)), + &entry->d_name, outarg); + ret = fuse_simple_request(fm, &args); + dput(parent); + + /* Zero nodeid is same as -ENOENT */ + if (!ret && !outarg->nodeid) + ret = -ENOENT; + if (!ret) { + fi = get_fuse_inode(inode); + if (outarg->nodeid != get_node_id(inode) || + (bool) IS_AUTOMOUNT(inode) != (bool) (outarg->attr.flags & FUSE_ATTR_SUBMOUNT)) { + fuse_queue_forget(fm->fc, forget, + outarg->nodeid, 1); + goto invalid; + } + *lookedup = true; + } + kfree(forget); + if (ret == -ENOMEM || ret == -EINTR) + goto out; + if (ret || fuse_invalid_attr(&outarg->attr) || + fuse_stale_inode(inode, outarg->generation, &outarg->attr)) { + goto invalid; + } + + ret = 1; +out: + return ret; + +invalid: + ret = 0; + goto out; +} + /* * Check whether the dentry is still valid * @@ -216,9 +269,8 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) || (flags & (LOOKUP_EXCL | LOOKUP_REVAL | LOOKUP_RENAME_TARGET))) { struct fuse_entry_out outarg; - FUSE_ARGS(args); - struct fuse_forget_link *forget; u64 attr_version; + bool lookedup = false; /* For negative dentries, always do a fresh lookup */ if (!inode) @@ -230,38 +282,19 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) fm = get_fuse_mount(inode); - forget = fuse_alloc_forget(); - ret = -ENOMEM; - if (!forget) - goto out; - attr_version = fuse_get_attr_version(fm->fc); - parent = dget_parent(entry); - fuse_lookup_init(fm->fc, &args, get_node_id(d_inode(parent)), - &entry->d_name, &outarg); - ret = fuse_simple_request(fm, &args); - dput(parent); - /* Zero nodeid is same as -ENOENT */ - if (!ret && !outarg.nodeid) - ret = -ENOENT; - if (!ret) { + ret = fuse_dentry_revalidate_lookup(fm, entry, inode, &outarg, + &lookedup); + if (ret == -ENOMEM || ret == -EINTR) + goto out; + if (lookedup) { fi = get_fuse_inode(inode); - if (outarg.nodeid != get_node_id(inode) || - (bool) IS_AUTOMOUNT(inode) != (bool) (outarg.attr.flags & FUSE_ATTR_SUBMOUNT)) { - fuse_queue_forget(fm->fc, forget, - outarg.nodeid, 1); - goto invalid; - } spin_lock(&fi->lock); fi->nlookup++; spin_unlock(&fi->lock); } - kfree(forget); - if (ret == -ENOMEM || ret == -EINTR) - goto out; - if (ret || fuse_invalid_attr(&outarg.attr) || - fuse_stale_inode(inode, outarg.generation, &outarg.attr)) + if (ret <= 0) goto invalid; forget_all_cached_acls(inode); -- 2.25.1