Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3133234pxj; Mon, 7 Jun 2021 03:13:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwKnLaDM6Kl2aqFko22hZ30yLbUTYRwjYJA00+yFdON2Y42BhTDRUvSEcAFcvDM1j/sxCN X-Received: by 2002:a17:906:3042:: with SMTP id d2mr17452748ejd.234.1623060830754; Mon, 07 Jun 2021 03:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623060830; cv=none; d=google.com; s=arc-20160816; b=HxqrRq40V5tKSC4OZU3uiTG5syW02sRz5C7xD2PKntPuU4+PQ5hSNy4l25whDtydYP DV5J/tk9sH6btSuiBsh1Rpdp588ZEYjJbJw8KdYC7zvyf/HC3tAHgGbmaef90jgAMmnK 3EEWjJHzFh7OtL8hJrtfRhMMxlywtBbMm2g+alHC/JuQFVquRa3DtDjH2nwlDZ/c+UiV Q3AO76DTLbeFrhui0FDgdLmXaLEKc+CCAqH1pqUU83/dojSbRuZ/rPoVXGP2C3vdiflz wOPMqRhi49eVOzoO5f0zgsUrQ7AEmUY61YyzyWuLNZLfDMwmWz5Qe1IU0hTCNvfSnJL9 7Hqw== 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=ZSb3eTtWg/4ffHIPWvc5/dcsHVOD0VifakQzZeLoe9XJKSRbAfuy476WVDz7LVQVZu 9ag5MErKufp+E+Oh2cakz8Tto2O6PEnKgtvbhTSVwnD4p+kZXFBLvqF65Zf6cg6cG5Sp /aOLTUNBXdSPxoMl26fyHN6sUZnqNj6sfh7k1WedGHKoHiy6fAV0EQ8AFDiiQCTKCjCs 7EY5Rckgwpyx91m11hKgSVC3UrF5zBnI0z5ZYSpQgCOHzWkhySREG2yq1Kf5GnYWixv3 dDltGRPXsz4qOi7Of5eSoJjgj0talvS3KuAHms3ZMSEUuPeGWhz0VvgYbEGhhXZmn/aJ veLg== 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 m10si5636004eji.316.2021.06.07.03.13.27; Mon, 07 Jun 2021 03:13:50 -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 S230323AbhFGKNj convert rfc822-to-8bit (ORCPT + 99 others); Mon, 7 Jun 2021 06:13:39 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:20343 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbhFGKNj (ORCPT ); Mon, 7 Jun 2021 06:13:39 -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-555-QOdhIilZNB-1xoyKqp7R2w-1; Mon, 07 Jun 2021 06:11:47 -0400 X-MC-Unique: QOdhIilZNB-1xoyKqp7R2w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 489391883522; Mon, 7 Jun 2021 10:11:45 +0000 (UTC) Received: from web.messagingengine.com (ovpn-116-49.sin2.redhat.com [10.67.116.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2683369A; Mon, 7 Jun 2021 10:11:37 +0000 (UTC) Subject: [PATCH v5 1/6] 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: Mon, 07 Jun 2021 18:11:36 +0800 Message-ID: <162306069604.69474.5531850302754566305.stgit@web.messagingengine.com> In-Reply-To: <162306058093.69474.2367505736322611930.stgit@web.messagingengine.com> References: <162306058093.69474.2367505736322611930.stgit@web.messagingengine.com> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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)