From patchwork Mon May 11 18:07:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6381211 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 401189F32B for ; Mon, 11 May 2015 18:22:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 70C4720A4F for ; Mon, 11 May 2015 18:22:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 988B920A4C for ; Mon, 11 May 2015 18:22:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755314AbbEKSVD (ORCPT ); Mon, 11 May 2015 14:21:03 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:47414 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755017AbbEKSI0 (ORCPT ); Mon, 11 May 2015 14:08:26 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1Yrs7s-0001UN-Ek; Mon, 11 May 2015 18:08:24 +0000 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 080/110] namei: fold put_link() into the failure case of complete_walk() Date: Mon, 11 May 2015 19:07:40 +0100 Message-Id: <1431367690-5223-80-git-send-email-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <20150511180650.GA4147@ZenIV.linux.org.uk> References: <20150511180650.GA4147@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 ... and don't open-code unlazy_walk() in there - the only reason for that is to avoid verfication of cached nd->root, which is trivially avoided by discarding said cached nd->root first. Signed-off-by: Al Viro --- fs/namei.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c6ff9da..55283fe 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -567,6 +567,8 @@ static inline int nd_alloc_stack(struct nameidata *nd) * to restart the path walk from the beginning in ref-walk mode. */ +static void terminate_walk(struct nameidata *nd); + /** * unlazy_walk - try to switch to ref-walk mode. * @nd: nameidata pathwalk data @@ -673,26 +675,12 @@ static int complete_walk(struct nameidata *nd) int status; if (nd->flags & LOOKUP_RCU) { - nd->flags &= ~LOOKUP_RCU; if (!(nd->flags & LOOKUP_ROOT)) nd->root.mnt = NULL; - - if (!legitimize_mnt(nd->path.mnt, nd->m_seq)) { - rcu_read_unlock(); - return -ECHILD; - } - if (unlikely(!lockref_get_not_dead(&dentry->d_lockref))) { - rcu_read_unlock(); - mntput(nd->path.mnt); - return -ECHILD; - } - if (read_seqcount_retry(&dentry->d_seq, nd->seq)) { - rcu_read_unlock(); - dput(dentry); - mntput(nd->path.mnt); + if (unlikely(unlazy_walk(nd, NULL))) { + terminate_walk(nd); return -ECHILD; } - rcu_read_unlock(); } if (likely(!(nd->flags & LOOKUP_JUMPED))) @@ -708,7 +696,7 @@ static int complete_walk(struct nameidata *nd) if (!status) status = -ESTALE; - path_put(&nd->path); + terminate_walk(nd); return status; } @@ -3008,11 +2996,8 @@ static int do_last(struct nameidata *nd, * about to look up */ error = complete_walk(nd); - if (error) { - if (nd->depth) - put_link(nd); + if (error) return error; - } audit_inode(name, dir, LOOKUP_PARENT); error = -EISDIR; @@ -3117,8 +3102,6 @@ finish_lookup: finish_open: error = complete_walk(nd); if (error) { - if (nd->depth) - put_link(nd); path_put(&save_parent); return error; }