Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49317a7f authored by NeilBrown's avatar NeilBrown Committed by Trond Myklebust
Browse files

NFS: nfs4_lookup_revalidate: only evaluate parent if it will be used.



nfs4_lookup_revalidate only uses 'parent' to get 'dir', and only
uses 'dir' if 'inode == NULL'.

So we don't need to find out what 'parent' or 'dir' is until we
know that 'inode' is NULL.

By moving 'dget_parent' inside the 'if', we can reduce the number of
call sites for 'dput(parent)'.

Signed-off-by: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
parent 1f70ef96
Loading
Loading
Loading
Loading
+8 −9
Original line number Original line Diff line number Diff line
@@ -1529,9 +1529,7 @@ EXPORT_SYMBOL_GPL(nfs_atomic_open);


static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags)
static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags)
{
{
	struct dentry *parent = NULL;
	struct inode *inode;
	struct inode *inode;
	struct inode *dir;
	int ret = 0;
	int ret = 0;


	if (flags & LOOKUP_RCU)
	if (flags & LOOKUP_RCU)
@@ -1545,34 +1543,35 @@ static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags)
		goto no_open;
		goto no_open;


	inode = dentry->d_inode;
	inode = dentry->d_inode;
	parent = dget_parent(dentry);
	dir = parent->d_inode;


	/* We can't create new files in nfs_open_revalidate(), so we
	/* We can't create new files in nfs_open_revalidate(), so we
	 * optimize away revalidation of negative dentries.
	 * optimize away revalidation of negative dentries.
	 */
	 */
	if (inode == NULL) {
	if (inode == NULL) {
		struct dentry *parent;
		struct inode *dir;

		parent = dget_parent(dentry);
		dir = parent->d_inode;
		if (!nfs_neg_need_reval(dir, dentry, flags))
		if (!nfs_neg_need_reval(dir, dentry, flags))
			ret = 1;
			ret = 1;
		dput(parent);
		goto out;
		goto out;
	}
	}


	/* NFS only supports OPEN on regular files */
	/* NFS only supports OPEN on regular files */
	if (!S_ISREG(inode->i_mode))
	if (!S_ISREG(inode->i_mode))
		goto no_open_dput;
		goto no_open;
	/* We cannot do exclusive creation on a positive dentry */
	/* We cannot do exclusive creation on a positive dentry */
	if (flags & LOOKUP_EXCL)
	if (flags & LOOKUP_EXCL)
		goto no_open_dput;
		goto no_open;


	/* Let f_op->open() actually open (and revalidate) the file */
	/* Let f_op->open() actually open (and revalidate) the file */
	ret = 1;
	ret = 1;


out:
out:
	dput(parent);
	return ret;
	return ret;


no_open_dput:
	dput(parent);
no_open:
no_open:
	return nfs_lookup_revalidate(dentry, flags);
	return nfs_lookup_revalidate(dentry, flags);
}
}