Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5148851pxj; Wed, 9 Jun 2021 10:13:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrkfBP1YtULSKuH7th/qTeaS73TW/OHKxTt8hue/nFqegP/CxNQhLyPtErH1SofrVZkjc7 X-Received: by 2002:a17:906:c00f:: with SMTP id e15mr916687ejz.458.1623258788585; Wed, 09 Jun 2021 10:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623258788; cv=none; d=google.com; s=arc-20160816; b=SNVQ/frBhQu9aI3VS1cyfr4tz9sTRQLzIMq+WBgzhjqecnjqA+AkxOLXYW1AI7Ochj HNNgPiDETpp2iX6KlCDMLgW1F82dmj82bL1c3jH+H6+Yd1lyrx+BFwQawOylNB5oxG/q l7AlsuaRL/aPdWDpUhdT15At1EjOujW076DhwZNkMzlix4PGDsTccXGgCpx4X4IdUZXE tYypV48P3z5I+ykKTaXQlz6jkzjW1nC86nvNwQMUjM9HXEMjWpK5QLf/Jm1aXIuXB45U 0CgnGzUTyx6LxNW6z9fqPkjzlqqzy3r2rMVVcj0ml/d4AdiIuCWJAE3rMzyKVtCzDHw0 CsjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=qsoUs93RTHYgqMf9g/Hr7vHX2GcTlcgcbM+DJOF+aDs=; b=e/n7LCasLmhjuNyE2hzrzaRLXn8oU/k+KyySPEYuPHA4jTytLbhqxzcbC7gAE8lvWl 24spNdqvc3UktAley42jvc1h9dsYVOuq+ozRzla7/UEbimN7+nknZeCTphuyH5YlwBs/ bMNI4GSb2iKStba3HKGt7YHdkbMFn2EHYiv4jVpyjwWP0pSGgCDwdbiQi0Kk8zj4KB21 KycEXosiwvhL5OBUlPtPmhAyAr/8d5Jg1BfPh+8/H7idhe53OhZnzbR8bmUDpjzXDfxC DkbSKnVbi5eXwanOvxgaHP9BmLh0VMKrQzrLQ1/VKtMdVjZ1rt7Y4VwV54Yosk1bj5Cz soyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si217537edd.98.2021.06.09.10.12.44; Wed, 09 Jun 2021 10:13:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237516AbhFIIvv convert rfc822-to-8bit (ORCPT + 99 others); Wed, 9 Jun 2021 04:51:51 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:20331 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbhFIIvv (ORCPT ); Wed, 9 Jun 2021 04:51:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-NhSfD_6EPAGczitIUQQIhg-1; Wed, 09 Jun 2021 04:49:54 -0400 X-MC-Unique: NhSfD_6EPAGczitIUQQIhg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C478100C670; Wed, 9 Jun 2021 08:49:53 +0000 (UTC) Received: from web.messagingengine.com (ovpn-116-20.sin2.redhat.com [10.67.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFEF710016FB; Wed, 9 Jun 2021 08:49:40 +0000 (UTC) Subject: [PATCH v6 1/7] kernfs: move revalidate to be near lookup From: Ian Kent To: Greg Kroah-Hartman , Tejun Heo Cc: Eric Sandeen , Fox Chen , Brice Goglin , Al Viro , Rick Lindsley , David Howells , Miklos Szeredi , Marcelo Tosatti , "Eric W. Biederman" , Carlos Maiolino , linux-fsdevel , Kernel Mailing List Date: Wed, 09 Jun 2021 16:49:37 +0800 Message-ID: <162322857790.361452.16044356399148573870.stgit@web.messagingengine.com> In-Reply-To: <162322846765.361452.17051755721944717990.stgit@web.messagingengine.com> References: <162322846765.361452.17051755721944717990.stgit@web.messagingengine.com> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=raven@themaw.net X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: themaw.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While the dentry operation kernfs_dop_revalidate() is grouped with dentry type functions it also has a strong affinity to the inode operation ->lookup(). It makes sense to locate this function near to kernfs_iop_lookup() because we will be adding VFS negative dentry caching to reduce path lookup overhead for non-existent paths. There's no functional change from this patch. Signed-off-by: Ian Kent --- fs/kernfs/dir.c | 86 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 7e0e62deab53c..33166ec90a112 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -548,49 +548,6 @@ void kernfs_put(struct kernfs_node *kn) } EXPORT_SYMBOL_GPL(kernfs_put); -static int kernfs_dop_revalidate(struct dentry *dentry, unsigned int flags) -{ - struct kernfs_node *kn; - - if (flags & LOOKUP_RCU) - return -ECHILD; - - /* Always perform fresh lookup for negatives */ - if (d_really_is_negative(dentry)) - goto out_bad_unlocked; - - kn = kernfs_dentry_node(dentry); - mutex_lock(&kernfs_mutex); - - /* The kernfs node has been deactivated */ - if (!kernfs_active(kn)) - goto out_bad; - - /* The kernfs node has been moved? */ - if (kernfs_dentry_node(dentry->d_parent) != kn->parent) - goto out_bad; - - /* The kernfs node has been renamed */ - if (strcmp(dentry->d_name.name, kn->name) != 0) - goto out_bad; - - /* The kernfs node has been moved to a different namespace */ - if (kn->parent && kernfs_ns_enabled(kn->parent) && - kernfs_info(dentry->d_sb)->ns != kn->ns) - goto out_bad; - - mutex_unlock(&kernfs_mutex); - return 1; -out_bad: - mutex_unlock(&kernfs_mutex); -out_bad_unlocked: - return 0; -} - -const struct dentry_operations kernfs_dops = { - .d_revalidate = kernfs_dop_revalidate, -}; - /** * kernfs_node_from_dentry - determine kernfs_node associated with a dentry * @dentry: the dentry in question @@ -1073,6 +1030,49 @@ struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent, return ERR_PTR(rc); } +static int kernfs_dop_revalidate(struct dentry *dentry, unsigned int flags) +{ + struct kernfs_node *kn; + + if (flags & LOOKUP_RCU) + return -ECHILD; + + /* Always perform fresh lookup for negatives */ + if (d_really_is_negative(dentry)) + goto out_bad_unlocked; + + kn = kernfs_dentry_node(dentry); + mutex_lock(&kernfs_mutex); + + /* The kernfs node has been deactivated */ + if (!kernfs_active(kn)) + goto out_bad; + + /* The kernfs node has been moved? */ + if (kernfs_dentry_node(dentry->d_parent) != kn->parent) + goto out_bad; + + /* The kernfs node has been renamed */ + if (strcmp(dentry->d_name.name, kn->name) != 0) + goto out_bad; + + /* The kernfs node has been moved to a different namespace */ + if (kn->parent && kernfs_ns_enabled(kn->parent) && + kernfs_info(dentry->d_sb)->ns != kn->ns) + goto out_bad; + + mutex_unlock(&kernfs_mutex); + return 1; +out_bad: + mutex_unlock(&kernfs_mutex); +out_bad_unlocked: + return 0; +} + +const struct dentry_operations kernfs_dops = { + .d_revalidate = kernfs_dop_revalidate, +}; + static struct dentry *kernfs_iop_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)