From patchwork Tue May 5 05:22:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6334611 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9030BBEEE1 for ; Tue, 5 May 2015 05:32:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C761D20268 for ; Tue, 5 May 2015 05:32:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC78620266 for ; Tue, 5 May 2015 05:32:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933043AbbEEFcI (ORCPT ); Tue, 5 May 2015 01:32:08 -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 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1YpVJy-0001PA-CX; Tue, 05 May 2015 05:23:06 +0000 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;