Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965391AbbEEFcR (ORCPT ); Tue, 5 May 2015 01:32:17 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:40088 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755560AbbEEFXJ (ORCPT ); Tue, 5 May 2015 01:23:09 -0400 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 78/79] namei: new helper - is_stale() Date: Tue, 5 May 2015 06:22:52 +0100 Message-Id: <1430803373-4948-78-git-send-email-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <20150505052205.GS889@ZenIV.linux.org.uk> References: <20150505052205.GS889@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2436 Lines: 77 From: Al Viro we have a lot of places where we open-code the check that dentry->d_seq matches nameidata... Signed-off-by: Al Viro --- fs/namei.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index eb3f7d9..cf8f2de 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -575,6 +575,11 @@ static inline int nd_alloc_stack(struct nameidata *nd) * to restart the path walk from the beginning in ref-walk mode. */ +static inline bool is_stale(struct nameidata *nd, struct dentry *dentry) +{ + return read_seqcount_retry(&dentry->d_seq, nd->seq); +} + /** * unlazy_walk - try to switch to ref-walk mode. * @nd: nameidata pathwalk data @@ -621,13 +626,13 @@ static int unlazy_walk(struct nameidata *nd, struct dentry *dentry) * be valid if the child sequence number is still valid. */ if (!dentry) { - if (read_seqcount_retry(&parent->d_seq, nd->seq)) + if (is_stale(nd, parent)) goto out; BUG_ON(nd->inode != parent->d_inode); } else { if (!lockref_get_not_dead(&dentry->d_lockref)) goto out; - if (read_seqcount_retry(&dentry->d_seq, nd->seq)) + if (is_stale(nd, dentry)) goto drop_dentry; } @@ -694,7 +699,7 @@ static int complete_walk(struct nameidata *nd) mntput(nd->path.mnt); return -ECHILD; } - if (read_seqcount_retry(&dentry->d_seq, nd->seq)) { + if (is_stale(nd, dentry)) { rcu_read_unlock(); dput(dentry); mntput(nd->path.mnt); @@ -1218,7 +1223,7 @@ static int follow_dotdot_rcu(struct nameidata *nd) inode = parent->d_inode; seq = read_seqcount_begin(&parent->d_seq); - if (read_seqcount_retry(&old->d_seq, nd->seq)) + if (is_stale(nd, old)) goto failed; nd->path.dentry = parent; nd->seq = seq; @@ -1980,7 +1985,7 @@ static int path_init(int dfd, const struct filename *name, unsigned int flags, nd->inode = nd->path.dentry->d_inode; if (!(flags & LOOKUP_RCU)) goto done; - if (likely(!read_seqcount_retry(&nd->path.dentry->d_seq, nd->seq))) + if (likely(!is_stale(nd, nd->path.dentry))) goto done; if (!(nd->flags & LOOKUP_ROOT)) nd->root.mnt = NULL; -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/