From patchwork Tue May 5 05:22:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6335211 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 A89D8BEEE1 for ; Tue, 5 May 2015 05:41:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C1522027D for ; Tue, 5 May 2015 05:41:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CB158201F4 for ; Tue, 5 May 2015 05:40:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030536AbbEEFkt (ORCPT ); Tue, 5 May 2015 01:40:49 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:39753 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755586AbbEEFXA (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 1YpVJq-0001Ks-68; Tue, 05 May 2015 05:22:58 +0000 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 32/79] namei: introduce nameidata->link Date: Tue, 5 May 2015 06:22:06 +0100 Message-Id: <1430803373-4948-32-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 shares space with nameidata->next, walk_component() et.al. store the struct path of symlink instead of returning it into a variable passed by caller. Signed-off-by: Al Viro --- fs/namei.c | 62 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index dbcbe42..72a6130 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -494,7 +494,10 @@ EXPORT_SYMBOL(path_put); struct nameidata { struct path path; - struct qstr last; + union { + struct qstr last; + struct path link; + }; struct path root; struct inode *inode; /* path.dentry.d_inode */ unsigned int flags; @@ -1551,8 +1554,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, struct path *path, int follow) +static int walk_component(struct nameidata *nd, int follow) { + struct path path; struct inode *inode; int err; /* @@ -1562,38 +1566,39 @@ static int walk_component(struct nameidata *nd, struct path *path, int follow) */ if (unlikely(nd->last_type != LAST_NORM)) return handle_dots(nd, nd->last_type); - err = lookup_fast(nd, path, &inode); + err = lookup_fast(nd, &path, &inode); if (unlikely(err)) { if (err < 0) goto out_err; - err = lookup_slow(nd, path); + err = lookup_slow(nd, &path); if (err < 0) goto out_err; - inode = path->dentry->d_inode; + inode = path.dentry->d_inode; } err = -ENOENT; - if (d_is_negative(path->dentry)) + if (d_is_negative(path.dentry)) goto out_path_put; - if (should_follow_link(path->dentry, follow)) { + if (should_follow_link(path.dentry, follow)) { if (nd->flags & LOOKUP_RCU) { - if (unlikely(nd->path.mnt != path->mnt || - unlazy_walk(nd, path->dentry))) { + if (unlikely(nd->path.mnt != path.mnt || + unlazy_walk(nd, path.dentry))) { err = -ECHILD; goto out_err; } } - BUG_ON(inode != path->dentry->d_inode); + BUG_ON(inode != path.dentry->d_inode); + nd->link = path; return 1; } - path_to_nameidata(path, nd); + path_to_nameidata(&path, nd); nd->inode = inode; return 0; out_path_put: - path_to_nameidata(path, nd); + path_to_nameidata(&path, nd); out_err: terminate_walk(nd); return err; @@ -1606,12 +1611,12 @@ out_err: * Without that kind of total limit, nasty chains of consecutive * symlinks can cause almost arbitrarily long lookups. */ -static inline int nested_symlink(struct path *path, struct nameidata *nd) +static inline int nested_symlink(struct nameidata *nd) { int res; if (unlikely(current->link_count >= MAX_NESTED_LINKS)) { - path_put_conditional(path, nd); + path_put_conditional(&nd->link, nd); path_put(&nd->path); return -ELOOP; } @@ -1621,13 +1626,13 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd) current->link_count++; do { - struct path link = *path; + struct path link = nd->link; void *cookie; res = follow_link(&link, nd, &cookie); if (res) break; - res = walk_component(nd, path, LOOKUP_FOLLOW); + res = walk_component(nd, LOOKUP_FOLLOW); put_link(nd, &link, cookie); } while (res > 0); @@ -1762,7 +1767,6 @@ static inline u64 hash_name(const char *name) */ static int link_path_walk(const char *name, struct nameidata *nd) { - struct path next; int err; while (*name=='/') @@ -1822,17 +1826,17 @@ static int link_path_walk(const char *name, struct nameidata *nd) if (!*name) return 0; - err = walk_component(nd, &next, LOOKUP_FOLLOW); + err = walk_component(nd, LOOKUP_FOLLOW); if (err < 0) return err; if (err) { - err = nested_symlink(&next, nd); + err = nested_symlink(nd); if (err) return err; } if (!d_can_lookup(nd->path.dentry)) { - err = -ENOTDIR; + err = -ENOTDIR; break; } } @@ -1952,20 +1956,19 @@ static void path_cleanup(struct nameidata *nd) fput(nd->base); } -static inline int lookup_last(struct nameidata *nd, struct path *path) +static inline int lookup_last(struct nameidata *nd) { if (nd->last_type == LAST_NORM && nd->last.name[nd->last.len]) nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; nd->flags &= ~LOOKUP_PARENT; - return walk_component(nd, path, nd->flags & LOOKUP_FOLLOW); + return walk_component(nd, nd->flags & LOOKUP_FOLLOW); } /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */ static int path_lookupat(int dfd, const struct filename *name, unsigned int flags, struct nameidata *nd) { - struct path path; int err; /* @@ -1984,10 +1987,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, &path); + err = lookup_last(nd); while (err > 0) { void *cookie; - struct path link = path; + struct path link = nd->link; err = may_follow_link(&link, nd); if (unlikely(err)) break; @@ -1995,7 +1998,7 @@ static int path_lookupat(int dfd, const struct filename *name, err = follow_link(&link, nd, &cookie); if (err) break; - err = lookup_last(nd, &path); + err = lookup_last(nd); put_link(nd, &link, cookie); } } @@ -2304,8 +2307,10 @@ done: } path->dentry = dentry; path->mnt = nd->path.mnt; - if (should_follow_link(dentry, nd->flags & LOOKUP_FOLLOW)) + if (should_follow_link(dentry, nd->flags & LOOKUP_FOLLOW)) { + nd->link = *path; return 1; + } mntget(path->mnt); follow_mount(path); error = 0; @@ -3034,6 +3039,7 @@ finish_lookup: } } BUG_ON(inode != path->dentry->d_inode); + nd->link = *path; return 1; } @@ -3222,7 +3228,7 @@ static struct file *path_openat(int dfd, struct filename *pathname, error = do_last(nd, &path, file, op, &opened, pathname); while (unlikely(error > 0)) { /* trailing symlink */ - struct path link = path; + struct path link = nd->link; void *cookie; error = may_follow_link(&link, nd); if (unlikely(error))