Message ID | 20140714012820.12562.14018.stgit@notabene.brown (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Mon, Jul 14, 2014 at 11:28:20AM +1000, NeilBrown wrote: > 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: NeilBrown <neilb@suse.de> Looks good, Reviewed-by: Christoph Hellwig <hch@lst.de> > > /* We can't create new files in nfs_open_revalidate(), so we > * optimize away revalidation of negative dentries. > */ > 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)) > ret = 1; > + dput(parent); > goto out; Seems like this could be further condensed to: struct dentry *parent = dget_parent(dentry); if (!nfs_neg_need_reval(parent->d_inode, dentry, flags)) ret = 1; dput(parent); goto out; or maybe even kill the goto out now that it's just a simple return without additional work. -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 4a3d4ef76127..c5a4a89637fb 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1529,9 +1529,7 @@ EXPORT_SYMBOL_GPL(nfs_atomic_open); static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags) { - struct dentry *parent = NULL; struct inode *inode; - struct inode *dir; int ret = 0; if (flags & LOOKUP_RCU) @@ -1545,34 +1543,35 @@ static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags) goto no_open; inode = dentry->d_inode; - parent = dget_parent(dentry); - dir = parent->d_inode; /* We can't create new files in nfs_open_revalidate(), so we * optimize away revalidation of negative dentries. */ 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)) ret = 1; + dput(parent); goto out; } /* NFS only supports OPEN on regular files */ if (!S_ISREG(inode->i_mode)) - goto no_open_dput; + goto no_open; /* We cannot do exclusive creation on a positive dentry */ if (flags & LOOKUP_EXCL) - goto no_open_dput; + goto no_open; /* Let f_op->open() actually open (and revalidate) the file */ ret = 1; out: - dput(parent); return ret; -no_open_dput: - dput(parent); no_open: return nfs_lookup_revalidate(dentry, flags); }
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: NeilBrown <neilb@suse.de> --- fs/nfs/dir.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html