Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755264AbbEKSSG (ORCPT ); Mon, 11 May 2015 14:18:06 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:47467 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755024AbbEKSI2 (ORCPT ); Mon, 11 May 2015 14:08:28 -0400 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 086/110] namei: split off filename_lookupat() with LOOKUP_PARENT Date: Mon, 11 May 2015 19:07:46 +0100 Message-Id: <1431367690-5223-86-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-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2928 Lines: 93 From: Al Viro new functions: filename_parentat() and path_parentat() resp. Signed-off-by: Al Viro --- fs/namei.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 51e2214..6f95bc9 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2034,7 +2034,7 @@ static int path_lookupat(int dfd, const struct filename *name, * be able to complete). */ err = path_init(dfd, name, flags, nd); - if (!err && !(flags & LOOKUP_PARENT)) { + if (!err) { while ((err = lookup_last(nd)) > 0) { err = trailing_symlink(nd); if (err) @@ -2074,6 +2074,35 @@ static int filename_lookup(int dfd, struct filename *name, return retval; } +/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */ +static int path_parentat(int dfd, const struct filename *name, + unsigned int flags, struct nameidata *nd) +{ + int err = path_init(dfd, name, flags | LOOKUP_PARENT, nd); + if (!err) + err = complete_walk(nd); + path_cleanup(nd); + return err; +} + +static int filename_parentat(int dfd, struct filename *name, + unsigned int flags, struct nameidata *nd) +{ + int retval; + struct nameidata *saved_nd = set_nameidata(nd); + + retval = path_parentat(dfd, name, flags | LOOKUP_RCU, nd); + if (unlikely(retval == -ECHILD)) + retval = path_parentat(dfd, name, flags, nd); + if (unlikely(retval == -ESTALE)) + retval = path_parentat(dfd, name, flags | LOOKUP_REVAL, nd); + + if (likely(!retval)) + audit_inode(name, nd->path.dentry, LOOKUP_PARENT); + restore_nameidata(saved_nd); + return retval; +} + /* does lookup, returns the object with parent locked */ struct dentry *kern_path_locked(const char *name, struct path *path) { @@ -2085,7 +2114,7 @@ struct dentry *kern_path_locked(const char *name, struct path *path) if (IS_ERR(filename)) return ERR_CAST(filename); - err = filename_lookup(AT_FDCWD, filename, LOOKUP_PARENT, &nd); + err = filename_parentat(AT_FDCWD, filename, 0, &nd); if (err) { d = ERR_PTR(err); goto out; @@ -2255,7 +2284,7 @@ user_path_parent(int dfd, const char __user *path, if (IS_ERR(s)) return s; - error = filename_lookup(dfd, s, flags | LOOKUP_PARENT, &nd); + error = filename_parentat(dfd, s, flags, &nd); if (error) { putname(s); return ERR_PTR(error); @@ -3344,7 +3373,7 @@ static struct dentry *filename_create(int dfd, struct filename *name, */ lookup_flags &= LOOKUP_REVAL; - error = filename_lookup(dfd, name, LOOKUP_PARENT|lookup_flags, &nd); + error = filename_parentat(dfd, name, lookup_flags, &nd); if (error) return ERR_PTR(error); -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/