linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Valerie Aurora <vaurora@redhat.com>
To: Nick Piggin <npiggin@kernel.dk>
Cc: Al Viro <viro@zeniv.linux.org.uk>, linux-fsdevel@vger.kernel.org
Subject: Re: [patch 02/10] fs: dentry allocation consolidation
Date: Tue, 17 Aug 2010 18:45:29 -0400	[thread overview]
Message-ID: <20100817224526.GL5556@shell> (raw)
In-Reply-To: <20100817184120.374122837@kernel.dk>

On Wed, Aug 18, 2010 at 04:37:31AM +1000, Nick Piggin wrote:
> fs: dentry allocation consolidation
> 
> There are 2 duplicate copies of code in dentry allocation in path lookup.
> Consolidate them into a single function.
> 
> Signed-off-by: Nick Piggin <npiggin@kernel.dk>
> 
> ---
>  fs/namei.c |   70 ++++++++++++++++++++++++++++---------------------------------
>  1 file changed, 33 insertions(+), 37 deletions(-)
> 
> Index: linux-2.6/fs/namei.c
> ===================================================================
> --- linux-2.6.orig/fs/namei.c	2010-08-18 04:04:29.000000000 +1000
> +++ linux-2.6/fs/namei.c	2010-08-18 04:05:12.000000000 +1000
> @@ -686,6 +686,35 @@ static __always_inline void follow_dotdo
>  }
>  
>  /*
> + * Allocate a dentry with name and parent, and perform a parent
> + * directory ->lookup on it. Returns the new dentry, or ERR_PTR
> + * on error. parent->d_inode->i_mutex must be held. d_lookup must
> + * have verified that no child exists while under i_mutex.
> + */
> +static struct dentry *d_alloc_and_lookup(struct dentry *parent,
> +				struct qstr *name, struct nameidata *nd)
> +{
> +	struct inode *inode = parent->d_inode;
> +	struct dentry *dentry;
> +	struct dentry *old;
> +
> +	/* Don't create child dentry for a dead directory. */
> +	if (unlikely(IS_DEADDIR(inode)))
> +		return ERR_PTR(-ENOENT);
> +
> +	dentry = d_alloc(parent, name);
> +	if (unlikely(!dentry))
> +		return ERR_PTR(-ENOMEM);
> +
> +	old = inode->i_op->lookup(inode, dentry, nd);
> +	if (unlikely(old)) {
> +		dput(dentry);
> +		dentry = old;
> +	}
> +	return dentry;
> +}
> +
> +/*
>   *  It's more convoluted than I'd like it to be, but... it's still fairly
>   *  small and for now I'd prefer to have fast path as straight as possible.
>   *  It _is_ time-critical.
> @@ -738,30 +767,13 @@ need_lookup:
>  	 * so doing d_lookup() (with seqlock), instead of lockfree __d_lookup
>  	 */
>  	dentry = d_lookup(parent, name);
> -	if (!dentry) {
> -		struct dentry *new;
> -
> -		/* Don't create child dentry for a dead directory. */
> -		dentry = ERR_PTR(-ENOENT);
> -		if (IS_DEADDIR(dir))
> -			goto out_unlock;
> -
> -		new = d_alloc(parent, name);
> -		dentry = ERR_PTR(-ENOMEM);
> -		if (new) {
> -			dentry = dir->i_op->lookup(dir, new, nd);
> -			if (dentry)
> -				dput(new);
> -			else
> -				dentry = new;
> -		}
> -out_unlock:
> +	if (likely(!dentry)) {
> +		dentry = d_alloc_and_lookup(parent, name, nd);
>  		mutex_unlock(&dir->i_mutex);
>  		if (IS_ERR(dentry))
>  			goto fail;
>  		goto done;
>  	}
> -
>  	/*
>  	 * Uhhuh! Nasty case: the cache was re-populated while
>  	 * we waited on the semaphore. Need to revalidate.
> @@ -1135,24 +1147,8 @@ static struct dentry *__lookup_hash(stru
>  	if (dentry && dentry->d_op && dentry->d_op->d_revalidate)
>  		dentry = do_revalidate(dentry, nd);
>  
> -	if (!dentry) {
> -		struct dentry *new;
> -
> -		/* Don't create child dentry for a dead directory. */
> -		dentry = ERR_PTR(-ENOENT);
> -		if (IS_DEADDIR(inode))
> -			goto out;
> -
> -		new = d_alloc(base, name);
> -		dentry = ERR_PTR(-ENOMEM);
> -		if (!new)
> -			goto out;
> -		dentry = inode->i_op->lookup(inode, new, nd);
> -		if (!dentry)
> -			dentry = new;
> -		else
> -			dput(new);
> -	}
> +	if (!dentry)
> +		dentry = d_alloc_and_lookup(base, name, nd);
>  out:
>  	return dentry;
>  }

Looks good.

Reviewed-by: Valerie Aurora <vaurora@redhat.com>

-VAL

  reply	other threads:[~2010-08-17 22:45 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-17 18:37 [patch 00/10] first set of vfs scale patches Nick Piggin
2010-08-17 18:37 ` [patch 01/10] fs: fix do_lookup false negative Nick Piggin
2010-08-17 22:45   ` Valerie Aurora
2010-08-17 23:04   ` Sage Weil
2010-08-18 13:41   ` Andi Kleen
2010-08-17 18:37 ` [patch 02/10] fs: dentry allocation consolidation Nick Piggin
2010-08-17 22:45   ` Valerie Aurora [this message]
2010-08-17 18:37 ` [patch 03/10] apparmor: use task path helpers Nick Piggin
2010-08-17 22:59   ` Valerie Aurora
2010-08-17 18:37 ` [patch 04/10] fs: fs_struct rwlock to spinlock Nick Piggin
2010-08-17 23:14   ` Valerie Aurora
2010-08-20 10:05     ` Nick Piggin
2010-08-17 18:37 ` [patch 05/10] fs: remove extra lookup in __lookup_hash Nick Piggin
2010-08-18 13:57   ` Andi Kleen
2010-08-18 21:13     ` Andi Kleen
2010-08-18 19:34   ` Valerie Aurora
2010-08-17 18:37 ` [patch 06/10] fs: cleanup files_lock locking Nick Piggin
2010-08-18 19:46   ` Valerie Aurora
2010-08-17 18:37 ` [patch 07/10] tty: fix fu_list abuse Nick Piggin
2010-08-17 18:37 ` [patch 08/10] lglock: introduce special lglock and brlock spin locks Nick Piggin
2010-08-17 18:37 ` [patch 09/10] fs: scale files_lock Nick Piggin
2010-08-17 18:37 ` [patch 10/10] fs: brlock vfsmount_lock Nick Piggin
2010-08-18 14:05   ` Andi Kleen
2010-08-20 10:09     ` Nick Piggin
2010-08-17 21:14 ` [patch 00/10] first set of vfs scale patches Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100817224526.GL5556@shell \
    --to=vaurora@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=npiggin@kernel.dk \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).