From patchwork Mon May 11 18:07:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6381401 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 CA42E9F32B for ; Mon, 11 May 2015 18:25:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD59B20601 for ; Mon, 11 May 2015 18:25:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC12C201CD for ; Mon, 11 May 2015 18:25:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755459AbbEKSY1 (ORCPT ); Mon, 11 May 2015 14:24:27 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:47336 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754991AbbEKSIY (ORCPT ); Mon, 11 May 2015 14:08:24 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1Yrs7q-0001TN-Kz; Mon, 11 May 2015 18:08:22 +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 070/110] namei: new calling conventions for walk_component() Date: Mon, 11 May 2015 19:07:30 +0100 Message-Id: <1431367690-5223-70-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 instead of a single flag (!= 0 => we want to follow symlinks) pass two bits - WALK_GET (want to follow symlinks) and WALK_PUT (put_link() once we are done looking at the name). The latter matters only for success exits - on failure the caller will discard everything anyway. Suggestions for better variant are welcome; what this thing aims for is making sure that pending put_link() is done *before* walk_component() decides to pick a symlink up, rather than between picking it up and acting upon it. See the next commit for payoff. Signed-off-by: Al Viro --- fs/namei.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 19e5c8a..1c9af925 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1577,7 +1577,9 @@ static inline int should_follow_link(struct dentry *dentry, int follow) return unlikely(d_is_symlink(dentry)) ? follow : 0; } -static int walk_component(struct nameidata *nd, int follow) +enum {WALK_GET = 1, WALK_PUT = 2}; + +static int walk_component(struct nameidata *nd, int flags) { struct path path; struct inode *inode; @@ -1587,8 +1589,12 @@ static int walk_component(struct nameidata *nd, int follow) * to be able to know about the current root directory and * parent relationships. */ - if (unlikely(nd->last_type != LAST_NORM)) - return handle_dots(nd, nd->last_type); + if (unlikely(nd->last_type != LAST_NORM)) { + err = handle_dots(nd, nd->last_type); + if (flags & WALK_PUT) + put_link(nd); + return err; + } err = lookup_fast(nd, &path, &inode); if (unlikely(err)) { if (err < 0) @@ -1604,7 +1610,9 @@ static int walk_component(struct nameidata *nd, int follow) goto out_path_put; } - if (should_follow_link(path.dentry, follow)) { + if (flags & WALK_PUT) + put_link(nd); + if (should_follow_link(path.dentry, flags & WALK_GET)) { if (nd->flags & LOOKUP_RCU) { if (unlikely(nd->path.mnt != path.mnt || unlazy_walk(nd, path.dentry))) { @@ -1816,10 +1824,9 @@ OK: if (!name) return 0; /* last component of nested symlink */ - err = walk_component(nd, LOOKUP_FOLLOW); - put_link(nd); + err = walk_component(nd, WALK_GET | WALK_PUT); } else { - err = walk_component(nd, LOOKUP_FOLLOW); + err = walk_component(nd, WALK_GET); } if (err < 0) break; @@ -2017,9 +2024,12 @@ static inline int lookup_last(struct nameidata *nd) nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; nd->flags &= ~LOOKUP_PARENT; - err = walk_component(nd, nd->flags & LOOKUP_FOLLOW); - if (nd->depth) - put_link(nd); + err = walk_component(nd, + nd->flags & LOOKUP_FOLLOW + ? nd->depth + ? WALK_PUT | WALK_GET + : WALK_GET + : 0); if (err < 0) terminate_walk(nd); return err;