From patchwork Tue May 5 05:22:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6335121 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 A27319F32E for ; Tue, 5 May 2015 05:40:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB572201F4 for ; Tue, 5 May 2015 05:40:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B509B2021A for ; Tue, 5 May 2015 05:40:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965571AbbEEFeq (ORCPT ); Tue, 5 May 2015 01:34:46 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:40025 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755624AbbEEFXH (ORCPT ); Tue, 5 May 2015 01:23:07 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1YpVJw-0001O5-GY; Tue, 05 May 2015 05:23:04 +0000 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 67/79] namei: take put_link() into {lookup, mountpoint, do}_last() Date: Tue, 5 May 2015 06:22:41 +0100 Message-Id: <1430803373-4948-67-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 rationale: we'll need to have terminate_walk() do put_link() on everything, which will mean that in some cases ..._last() will do put_link() anyway. Easier to have them do it in all cases. Signed-off-by: Al Viro --- fs/namei.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index f7bce07..0fbc9b7 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2010,6 +2010,8 @@ static inline int lookup_last(struct nameidata *nd) nd->flags &= ~LOOKUP_PARENT; err = walk_component(nd, nd->flags & LOOKUP_FOLLOW); + if (nd->depth) + put_link(nd); if (err < 0) terminate_walk(nd); return err; @@ -2037,13 +2039,10 @@ static int path_lookupat(int dfd, const struct filename *name, */ err = path_init(dfd, name, flags, nd); if (!err && !(flags & LOOKUP_PARENT)) { - err = lookup_last(nd); - while (err > 0) { + while ((err = lookup_last(nd)) > 0) { err = trailing_symlink(nd); if (err) break; - err = lookup_last(nd); - put_link(nd); } } @@ -2354,6 +2353,8 @@ done: dput(dentry); goto out; } + if (nd->depth) + put_link(nd); path->dentry = dentry; path->mnt = nd->path.mnt; if (should_follow_link(dentry, nd->flags & LOOKUP_FOLLOW)) { @@ -2365,6 +2366,8 @@ done: error = 0; out: terminate_walk(nd); + if (nd->depth) + put_link(nd); return error; } @@ -2386,13 +2389,10 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path, if (unlikely(err)) goto out; - err = mountpoint_last(nd, path); - while (err > 0) { + while ((err = mountpoint_last(nd, path)) > 0) { err = trailing_symlink(nd); if (err) break; - err = mountpoint_last(nd, path); - put_link(nd); } out: path_cleanup(nd); @@ -2970,6 +2970,8 @@ static int do_last(struct nameidata *nd, error = handle_dots(nd, nd->last_type); if (unlikely(error)) { terminate_walk(nd); + if (nd->depth) + put_link(nd); return error; } goto finish_open; @@ -2995,8 +2997,11 @@ static int do_last(struct nameidata *nd, * about to look up */ error = complete_walk(nd); - if (error) + if (error) { + if (nd->depth) + put_link(nd); return error; + } audit_inode(name, dir, LOOKUP_PARENT); error = -EISDIR; @@ -3087,6 +3092,8 @@ finish_lookup: } } BUG_ON(inode != path.dentry->d_inode); + if (nd->depth) + put_link(nd); nd->link = path; return 1; } @@ -3110,6 +3117,8 @@ finish_lookup: finish_open: error = complete_walk(nd); if (error) { + if (nd->depth) + put_link(nd); path_put(&save_parent); return error; } @@ -3161,6 +3170,8 @@ out: mnt_drop_write(nd->path.mnt); path_put(&save_parent); terminate_walk(nd); + if (nd->depth) + put_link(nd); return error; exit_dput: @@ -3273,14 +3284,11 @@ static struct file *path_openat(int dfd, struct filename *pathname, if (unlikely(error)) goto out; - error = do_last(nd, file, op, &opened, pathname); - while (unlikely(error > 0)) { /* trailing symlink */ + while ((error = do_last(nd, file, op, &opened, pathname)) > 0) { nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL); error = trailing_symlink(nd); if (unlikely(error)) break; - error = do_last(nd, file, op, &opened, pathname); - put_link(nd); } out: path_cleanup(nd);