From patchwork Tue May 5 05:22:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6334601 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 40CD2BEEE1 for ; Tue, 5 May 2015 05:31:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 788D220268 for ; Tue, 5 May 2015 05:31:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A58020266 for ; Tue, 5 May 2015 05:31:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755223AbbEEF2M (ORCPT ); Tue, 5 May 2015 01:28:12 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:40101 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755707AbbEEFX2 (ORCPT ); Tue, 5 May 2015 01:23:28 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1YpVJt-0001Mg-JW; Tue, 05 May 2015 05:23:01 +0000 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 52/79] link_path_walk: nd->depth massage, part 1 Date: Tue, 5 May 2015 06:22:26 +0100 Message-Id: <1430803373-4948-52-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 nd->stack[0] is unused until the handling of trailing symlinks and we want to get rid of that. Having fucked that transformation up several times, I went for bloody pedantic series of provably equivalent transformations. Sorry. Step 1: keep nd->depth higher by one in link_path_walk() - increment upon entry, decrement on exits, adjust the arithmetics inside and surround the calls of functions that care about nd->depth value (nd_alloc_stack(), get_link(), put_link()) with decrement/increment pairs. Signed-off-by: Al Viro --- fs/namei.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 078db1d..da23835 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1755,6 +1755,7 @@ static int link_path_walk(const char *name, struct nameidata *nd) if (!*name) return 0; + nd->depth++; /* At this point we know we have a real path component. */ for(;;) { u64 hash_len; @@ -1815,15 +1816,18 @@ Walked: if (err) { const char *s; + nd->depth--; err = nd_alloc_stack(nd); + nd->depth++; if (unlikely(err)) { path_to_nameidata(&nd->link, nd); break; } nd->depth++; - + nd->depth--; s = get_link(nd); + nd->depth++; if (unlikely(IS_ERR(s))) { err = PTR_ERR(s); @@ -1833,7 +1837,9 @@ Walked: err = 0; if (unlikely(!s)) { /* jumped */ + nd->depth--; put_link(nd); + nd->depth++; nd->depth--; } else { if (*s == '/') { @@ -1847,7 +1853,7 @@ Walked: ; } nd->inode = nd->path.dentry->d_inode; - nd->stack[nd->depth].name = name; + nd->stack[nd->depth - 1].name = name; if (!*s) goto OK; name = s; @@ -1861,19 +1867,25 @@ Walked: } terminate_walk(nd); Err: - while (unlikely(nd->depth)) { + while (unlikely(nd->depth > 1)) { + nd->depth--; put_link(nd); + nd->depth++; nd->depth--; } + nd->depth--; return err; OK: - if (unlikely(nd->depth)) { - name = nd->stack[nd->depth].name; + if (unlikely(nd->depth > 1)) { + name = nd->stack[nd->depth - 1].name; err = walk_component(nd, LOOKUP_FOLLOW); + nd->depth--; put_link(nd); + nd->depth++; nd->depth--; goto Walked; } + nd->depth--; return 0; }