From patchwork Tue May 5 05:22:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6335221 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 5FFFEBEEE5 for ; Tue, 5 May 2015 05:41:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85524202C8 for ; Tue, 5 May 2015 05:41:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 86169202BE for ; Tue, 5 May 2015 05:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030544AbbEEFkx (ORCPT ); Tue, 5 May 2015 01:40:53 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:39732 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755584AbbEEFXA (ORCPT ); Tue, 5 May 2015 01:23:00 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1YpVJp-0001Kf-Qo; Tue, 05 May 2015 05:22:57 +0000 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 30/79] namei.c: separate the parts of follow_link() that find the link body Date: Tue, 5 May 2015 06:22:04 +0100 Message-Id: <1430803373-4948-30-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 Split a piece of fs/namei.c:follow_link() that does obtaining the link body into a separate function. follow_link() itself is converted to calling get_link() and then doing the body traversal (if any). The next step will expand follow_link() call in link_path_walk() and this helps to keep the size down... Signed-off-by: Al Viro --- fs/namei.c | 65 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 862e659..5f2c986 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -836,21 +836,22 @@ static int may_linkat(struct path *link) return -EPERM; } -static __always_inline int -follow_link(struct path *link, struct nameidata *nd, void **p) +static __always_inline const char * +get_link(struct path *link, struct nameidata *nd, void **p) { struct dentry *dentry = link->dentry; + struct inode *inode = dentry->d_inode; int error; - const char *s; + const char *res; BUG_ON(nd->flags & LOOKUP_RCU); if (link->mnt == nd->path.mnt) mntget(link->mnt); - error = -ELOOP; + res = ERR_PTR(-ELOOP); if (unlikely(current->total_link_count >= 40)) - goto out_put_nd_path; + goto out; cond_resched(); current->total_link_count++; @@ -858,37 +859,43 @@ follow_link(struct path *link, struct nameidata *nd, void **p) touch_atime(link); error = security_inode_follow_link(dentry); + res = ERR_PTR(error); if (error) - goto out_put_nd_path; + goto out; nd->last_type = LAST_BIND; *p = NULL; - s = dentry->d_inode->i_op->follow_link(dentry, p, nd); - error = PTR_ERR(s); - if (IS_ERR(s)) - goto out_put_nd_path; - - error = 0; - if (s) { - if (*s == '/') { - if (!nd->root.mnt) - set_root(nd); - path_put(&nd->path); - nd->path = nd->root; - path_get(&nd->root); - nd->flags |= LOOKUP_JUMPED; - } - nd->inode = nd->path.dentry->d_inode; - error = link_path_walk(s, nd); - if (unlikely(error)) - put_link(nd, link, *p); + res = inode->i_op->follow_link(dentry, p, nd); + if (IS_ERR(res)) { +out: + path_put(&nd->path); + path_put(link); } + return res; +} - return error; +static __always_inline int +follow_link(struct path *link, struct nameidata *nd, void **p) +{ + const char *s = get_link(link, nd, p); + int error; -out_put_nd_path: - path_put(&nd->path); - path_put(link); + if (unlikely(IS_ERR(s))) + return PTR_ERR(s); + if (unlikely(!s)) + return 0; + if (*s == '/') { + if (!nd->root.mnt) + set_root(nd); + path_put(&nd->path); + nd->path = nd->root; + path_get(&nd->root); + nd->flags |= LOOKUP_JUMPED; + } + nd->inode = nd->path.dentry->d_inode; + error = link_path_walk(s, nd); + if (unlikely(error)) + put_link(nd, link, *p); return error; }