From patchwork Wed May 13 22:26:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6401041 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 E36A69F1C2 for ; Wed, 13 May 2015 22:32:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DFBCD20411 for ; Wed, 13 May 2015 22:32:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ADE15203EB for ; Wed, 13 May 2015 22:32:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965587AbbEMWbl (ORCPT ); Wed, 13 May 2015 18:31:41 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:44901 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964835AbbEMW0S (ORCPT ); Wed, 13 May 2015 18:26:18 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1Ysf6V-0006mC-Ub; Wed, 13 May 2015 22:26:15 +0000 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 08/21] namei: pass the struct path to store the result down into path_lookupat() Date: Wed, 13 May 2015 23:26:02 +0100 Message-Id: <1431555975-25997-8-git-send-email-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <20150513222533.GA24192@ZenIV.linux.org.uk> References: <20150513222533.GA24192@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 Signed-off-by: Al Viro --- fs/namei.c | 72 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index ffa2e13..937ec33 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2084,8 +2084,8 @@ static inline int lookup_last(struct nameidata *nd) } /* 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) +static int path_lookupat(int dfd, const struct filename *name, unsigned flags, + struct nameidata *nd, struct path *path) { const char *s = path_init(dfd, name, flags, nd); int err; @@ -2106,27 +2106,31 @@ static int path_lookupat(int dfd, const struct filename *name, if (!err && nd->flags & LOOKUP_DIRECTORY) if (!d_can_lookup(nd->path.dentry)) err = -ENOTDIR; - if (err) - terminate_walk(nd); - + if (!err) { + *path = nd->path; + nd->path.mnt = NULL; + nd->path.dentry = NULL; + } + terminate_walk(nd); path_cleanup(nd); return err; } -static int filename_lookup(int dfd, struct filename *name, - unsigned int flags, struct nameidata *nd) +static int filename_lookup(int dfd, struct filename *name, unsigned flags, + struct nameidata *nd, struct path *path) { int retval; struct nameidata *saved_nd = set_nameidata(nd); - retval = path_lookupat(dfd, name, flags | LOOKUP_RCU, nd); + retval = path_lookupat(dfd, name, flags | LOOKUP_RCU, nd, path); if (unlikely(retval == -ECHILD)) - retval = path_lookupat(dfd, name, flags, nd); + retval = path_lookupat(dfd, name, flags, nd, path); if (unlikely(retval == -ESTALE)) - retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd); + retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, + nd, path); if (likely(!retval)) - audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT); + audit_inode(name, path->dentry, flags & LOOKUP_PARENT); restore_nameidata(saved_nd); return retval; } @@ -2207,10 +2211,8 @@ int kern_path(const char *name, unsigned int flags, struct path *path) int res = PTR_ERR(filename); if (!IS_ERR(filename)) { - res = filename_lookup(AT_FDCWD, filename, flags, &nd); + res = filename_lookup(AT_FDCWD, filename, flags, &nd, path); putname(filename); - if (!res) - *path = nd.path; } return res; } @@ -2239,9 +2241,7 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt, nd.root.dentry = dentry; nd.root.mnt = mnt; err = filename_lookup(AT_FDCWD, filename, - flags | LOOKUP_ROOT, &nd); - if (!err) - *path = nd.path; + flags | LOOKUP_ROOT, &nd, path); putname(filename); } return err; @@ -2309,10 +2309,8 @@ int user_path_at_empty(int dfd, const char __user *name, unsigned flags, BUG_ON(flags & LOOKUP_PARENT); - err = filename_lookup(dfd, tmp, flags, &nd); + err = filename_lookup(dfd, tmp, flags, &nd, path); putname(tmp); - if (!err) - *path = nd.path; } return err; } @@ -3259,44 +3257,42 @@ static int do_tmpfile(int dfd, struct filename *pathname, struct file *file, int *opened) { static const struct qstr name = QSTR_INIT("/", 1); - struct dentry *dentry, *child; + struct dentry *child; struct inode *dir; + struct path path; int error = path_lookupat(dfd, pathname, - flags | LOOKUP_DIRECTORY, nd); + flags | LOOKUP_DIRECTORY, nd, &path); if (unlikely(error)) return error; - error = mnt_want_write(nd->path.mnt); + error = mnt_want_write(path.mnt); if (unlikely(error)) goto out; + dir = path.dentry->d_inode; /* we want directory to be writable */ - error = inode_permission(nd->inode, MAY_WRITE | MAY_EXEC); + error = inode_permission(dir, MAY_WRITE | MAY_EXEC); if (error) goto out2; - dentry = nd->path.dentry; - dir = dentry->d_inode; if (!dir->i_op->tmpfile) { error = -EOPNOTSUPP; goto out2; } - child = d_alloc(dentry, &name); + child = d_alloc(path.dentry, &name); if (unlikely(!child)) { error = -ENOMEM; goto out2; } - nd->flags &= ~LOOKUP_DIRECTORY; - nd->flags |= op->intent; - dput(nd->path.dentry); - nd->path.dentry = child; - error = dir->i_op->tmpfile(dir, nd->path.dentry, op->mode); + dput(path.dentry); + path.dentry = child; + error = dir->i_op->tmpfile(dir, child, op->mode); if (error) goto out2; - audit_inode(pathname, nd->path.dentry, 0); + audit_inode(pathname, child, 0); /* Don't check for other permissions, the inode was just created */ - error = may_open(&nd->path, MAY_OPEN, op->open_flag); + error = may_open(&path, MAY_OPEN, op->open_flag); if (error) goto out2; - file->f_path.mnt = nd->path.mnt; - error = finish_open(file, nd->path.dentry, NULL, opened); + file->f_path.mnt = path.mnt; + error = finish_open(file, child, NULL, opened); if (error) goto out2; error = open_check_o_direct(file); @@ -3309,9 +3305,9 @@ static int do_tmpfile(int dfd, struct filename *pathname, spin_unlock(&inode->i_lock); } out2: - mnt_drop_write(nd->path.mnt); + mnt_drop_write(path.mnt); out: - path_put(&nd->path); + path_put(&path); return error; }