linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Valerie Aurora <valerie.aurora@gmail.com>
To: linux-fsdevel@vger.kernel.org, linux@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, Jan Blunck <jblunck@suse.de>,
	Valerie Aurora <vaurora@redhat.com>,
	Valerie Aurora <valerie.aurora@gmail.com>
Subject: [PATCH 02/74] VFS: Make lookup_hash() return a struct path
Date: Tue, 22 Mar 2011 18:58:38 -0700	[thread overview]
Message-ID: <1300845590-14184-3-git-send-email-valerie.aurora@gmail.com> (raw)
In-Reply-To: <1300845590-14184-1-git-send-email-valerie.aurora@gmail.com>

From: Jan Blunck <jblunck@suse.de>

Signed-off-by: Jan Blunck <jblunck@suse.de>
Signed-off-by: Valerie Aurora <vaurora@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Valerie Aurora <valerie.aurora@gmail.com>
---
 fs/namei.c |  113 ++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 57 insertions(+), 56 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index db0e7ce..99fc88b 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1154,7 +1154,7 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
 }
 
 static struct dentry *__lookup_hash(struct qstr *name,
-		struct dentry *base, struct nameidata *nd)
+				    struct dentry *base, struct nameidata *nd)
 {
 	struct dentry *dentry;
 	struct inode *inode;
@@ -1194,14 +1194,22 @@ out:
  * needs parent already locked. Doesn't follow mounts.
  * SMP-safe.
  */
-static struct dentry *lookup_hash(struct nameidata *nd)
+static int lookup_hash(struct nameidata *nd, struct qstr *name,
+		       struct path *path)
 {
 	int err;
 
 	err = exec_permission(nd->path.dentry->d_inode);
 	if (err)
-		return ERR_PTR(err);
-	return __lookup_hash(&nd->last, nd->path.dentry, nd);
+		return err;
+	path->mnt = nd->path.mnt;
+	path->dentry =  __lookup_hash(name, nd->path.dentry, nd);
+	if (IS_ERR(path->dentry)) {
+		err = PTR_ERR(path->dentry);
+		path->dentry = NULL;
+		path->mnt = NULL;
+	}
+	return err;
 }
 
 static int __lookup_one_len(const char *name, struct qstr *this,
@@ -1682,12 +1690,9 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
 
 	/* OK, it's O_CREAT */
 	mutex_lock(&dir->d_inode->i_mutex);
+	error = lookup_hash(nd, &nd->last, path);
 
-	path->dentry = lookup_hash(nd);
-	path->mnt = nd->path.mnt;
-
-	error = PTR_ERR(path->dentry);
-	if (IS_ERR(path->dentry)) {
+	if (error) {
 		mutex_unlock(&dir->d_inode->i_mutex);
 		goto exit;
 	}
@@ -1939,7 +1944,8 @@ EXPORT_SYMBOL(filp_open);
  */
 struct dentry *lookup_create(struct nameidata *nd, int is_dir)
 {
-	struct dentry *dentry = ERR_PTR(-EEXIST);
+	struct path path;
+	int err;
 
 	mutex_lock_nested(&nd->path.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
 	/*
@@ -1947,7 +1953,7 @@ struct dentry *lookup_create(struct nameidata *nd, int is_dir)
 	 * (foo/., foo/.., /////)
 	 */
 	if (nd->last_type != LAST_NORM)
-		goto fail;
+		return ERR_PTR(-EEXIST);
 	nd->flags &= ~LOOKUP_PARENT;
 	nd->flags |= LOOKUP_CREATE | LOOKUP_EXCL;
 	nd->intent.open.flags = O_EXCL;
@@ -1955,11 +1961,11 @@ struct dentry *lookup_create(struct nameidata *nd, int is_dir)
 	/*
 	 * Do the final lookup.
 	 */
-	dentry = lookup_hash(nd);
-	if (IS_ERR(dentry))
-		goto fail;
+	err = lookup_hash(nd, &nd->last, &path);
+	if (err)
+		return ERR_PTR(err);
 
-	if (dentry->d_inode)
+	if (path.dentry->d_inode)
 		goto eexist;
 	/*
 	 * Special case - lookup gave negative, but... we had foo/bar/
@@ -1968,15 +1974,14 @@ struct dentry *lookup_create(struct nameidata *nd, int is_dir)
 	 * been asking for (non-existent) directory. -ENOENT for you.
 	 */
 	if (unlikely(!is_dir && nd->last.name[nd->last.len])) {
-		dput(dentry);
-		dentry = ERR_PTR(-ENOENT);
+		dput(path.dentry);
+		return ERR_PTR(-ENOENT);
 	}
-	return dentry;
+
+	return path.dentry;
 eexist:
-	dput(dentry);
-	dentry = ERR_PTR(-EEXIST);
-fail:
-	return dentry;
+	path_put_conditional(&path, nd);
+	return ERR_PTR(-EEXIST);
 }
 EXPORT_SYMBOL_GPL(lookup_create);
 
@@ -2211,7 +2216,7 @@ static long do_rmdir(int dfd, const char __user *pathname)
 {
 	int error = 0;
 	char * name;
-	struct dentry *dentry;
+	struct path path;
 	struct nameidata nd;
 
 	error = user_path_parent(dfd, pathname, &nd, &name);
@@ -2233,21 +2238,20 @@ static long do_rmdir(int dfd, const char __user *pathname)
 	nd.flags &= ~LOOKUP_PARENT;
 
 	mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
-	dentry = lookup_hash(&nd);
-	error = PTR_ERR(dentry);
-	if (IS_ERR(dentry))
+	error = lookup_hash(&nd, &nd.last, &path);
+	if (error)
 		goto exit2;
 	error = mnt_want_write(nd.path.mnt);
 	if (error)
 		goto exit3;
-	error = security_path_rmdir(&nd.path, dentry);
+	error = security_path_rmdir(&nd.path, path.dentry);
 	if (error)
 		goto exit4;
-	error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
+	error = vfs_rmdir(nd.path.dentry->d_inode, path.dentry);
 exit4:
 	mnt_drop_write(nd.path.mnt);
 exit3:
-	dput(dentry);
+	path_put_conditional(&path, &nd);
 exit2:
 	mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
 exit1:
@@ -2303,7 +2307,7 @@ static long do_unlinkat(int dfd, const char __user *pathname)
 {
 	int error;
 	char *name;
-	struct dentry *dentry;
+	struct path path;
 	struct nameidata nd;
 	struct inode *inode = NULL;
 
@@ -2318,26 +2322,25 @@ static long do_unlinkat(int dfd, const char __user *pathname)
 	nd.flags &= ~LOOKUP_PARENT;
 
 	mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
-	dentry = lookup_hash(&nd);
-	error = PTR_ERR(dentry);
-	if (!IS_ERR(dentry)) {
+	error = lookup_hash(&nd, &nd.last, &path);
+	if (!error) {
 		/* Why not before? Because we want correct error value */
 		if (nd.last.name[nd.last.len])
 			goto slashes;
-		inode = dentry->d_inode;
+		inode = path.dentry->d_inode;
 		if (inode)
 			atomic_inc(&inode->i_count);
 		error = mnt_want_write(nd.path.mnt);
 		if (error)
 			goto exit2;
-		error = security_path_unlink(&nd.path, dentry);
+		error = security_path_unlink(&nd.path, path.dentry);
 		if (error)
 			goto exit3;
-		error = vfs_unlink(nd.path.dentry->d_inode, dentry);
+		error = vfs_unlink(nd.path.dentry->d_inode, path.dentry);
 exit3:
 		mnt_drop_write(nd.path.mnt);
 	exit2:
-		dput(dentry);
+		path_put_conditional(&path, &nd);
 	}
 	mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
 	if (inode)
@@ -2348,8 +2351,8 @@ exit1:
 	return error;
 
 slashes:
-	error = !dentry->d_inode ? -ENOENT :
-		S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
+	error = !path.dentry->d_inode ? -ENOENT :
+		S_ISDIR(path.dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
 	goto exit2;
 }
 
@@ -2687,7 +2690,7 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
 		int, newdfd, const char __user *, newname)
 {
 	struct dentry *old_dir, *new_dir;
-	struct dentry *old_dentry, *new_dentry;
+	struct path old, new;
 	struct dentry *trap;
 	struct nameidata oldnd, newnd;
 	char *from;
@@ -2721,16 +2724,15 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
 
 	trap = lock_rename(new_dir, old_dir);
 
-	old_dentry = lookup_hash(&oldnd);
-	error = PTR_ERR(old_dentry);
-	if (IS_ERR(old_dentry))
+	error = lookup_hash(&oldnd, &oldnd.last, &old);
+	if (error)
 		goto exit3;
 	/* source must exist */
 	error = -ENOENT;
-	if (!old_dentry->d_inode)
+	if (!old.dentry->d_inode)
 		goto exit4;
 	/* unless the source is a directory trailing slashes give -ENOTDIR */
-	if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
+	if (!S_ISDIR(old.dentry->d_inode->i_mode)) {
 		error = -ENOTDIR;
 		if (oldnd.last.name[oldnd.last.len])
 			goto exit4;
@@ -2739,32 +2741,31 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
 	}
 	/* source should not be ancestor of target */
 	error = -EINVAL;
-	if (old_dentry == trap)
+	if (old.dentry == trap)
 		goto exit4;
-	new_dentry = lookup_hash(&newnd);
-	error = PTR_ERR(new_dentry);
-	if (IS_ERR(new_dentry))
+	error = lookup_hash(&newnd, &newnd.last, &new);
+	if (error)
 		goto exit4;
 	/* target should not be an ancestor of source */
 	error = -ENOTEMPTY;
-	if (new_dentry == trap)
+	if (new.dentry == trap)
 		goto exit5;
 
 	error = mnt_want_write(oldnd.path.mnt);
 	if (error)
 		goto exit5;
-	error = security_path_rename(&oldnd.path, old_dentry,
-				     &newnd.path, new_dentry);
+	error = security_path_rename(&oldnd.path, old.dentry,
+				     &newnd.path, new.dentry);
 	if (error)
 		goto exit6;
-	error = vfs_rename(old_dir->d_inode, old_dentry,
-				   new_dir->d_inode, new_dentry);
+	error = vfs_rename(old_dir->d_inode, old.dentry,
+				   new_dir->d_inode, new.dentry);
 exit6:
 	mnt_drop_write(oldnd.path.mnt);
 exit5:
-	dput(new_dentry);
+	path_put_conditional(&new, &newnd);
 exit4:
-	dput(old_dentry);
+	path_put_conditional(&old, &oldnd);
 exit3:
 	unlock_rename(new_dir, old_dir);
 exit2:
-- 
1.7.0.4


  parent reply	other threads:[~2011-03-23  2:00 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-23  1:58 [PATCH 00/74] Union mounts version something or other Valerie Aurora
2011-03-23  1:58 ` [PATCH 01/74] VFS: Comment follow_mount() and friends Valerie Aurora
2011-03-23  1:58 ` Valerie Aurora [this message]
2011-03-23  1:58 ` [PATCH 03/74] autofs4: Save autofs trigger's vfsmount in super block info Valerie Aurora
2011-03-23  1:58 ` [PATCH 04/74] Documentation: Fix trivial typo in filesystems/sharedsubtree.txt Valerie Aurora
2011-03-23  1:58 ` [PATCH 05/74] whiteout/NFSD: Don't return information about whiteouts to userspace Valerie Aurora
2011-03-23  1:58 ` [PATCH 06/74] whiteout: Define opaque inode flags and operations Valerie Aurora
2011-03-23  1:58 ` [PATCH 07/74] whiteout: Add vfs_whiteout() and whiteout inode operation Valerie Aurora
2011-03-23  1:58 ` [PATCH 08/74] whiteout: Allow removal of a directory with whiteouts Valerie Aurora
2011-03-23  1:58 ` [PATCH 09/74] whiteout: tmpfs whiteout support Valerie Aurora
2011-03-23  1:58 ` [PATCH 10/74] ext2: Add ext2_dirent_in_use() Valerie Aurora
2011-03-23  1:58 ` [PATCH 11/74] ext2: Split ext2_add_entry() from ext2_add_link() Valerie Aurora
2011-03-23  1:58 ` [PATCH 12/74] whiteout: ext2 whiteout support Valerie Aurora
2011-03-23  1:58 ` [PATCH 13/74] whiteout: jffs2 " Valerie Aurora
2011-03-23  1:58 ` [PATCH 14/74] fallthru: Basic fallthru definitions Valerie Aurora
2011-03-23  1:58 ` [PATCH 15/74] fallthru: ext2 fallthru support Valerie Aurora
2011-03-23  1:58 ` [PATCH 16/74] fallthru: tmpfs " Valerie Aurora
2011-03-23  1:58 ` [PATCH 17/74] fallthru: jffs2 " Valerie Aurora
2011-03-23  1:58 ` [PATCH 18/74] VFS: Add hard read-only users count to superblock Valerie Aurora
2011-03-23  1:58 ` [PATCH 19/74] VFS: Make clone_mnt()/copy_tree()/collect_mounts() return errors Valerie Aurora
2011-03-23  1:58 ` [PATCH 20/74] VFS: Add CL_NO_SHARED flag to clone_mnt()/copy_tree() Valerie Aurora
2011-03-23  1:58 ` [PATCH 21/74] VFS: Add CL_NO_SLAVE " Valerie Aurora
2011-03-23  1:58 ` [PATCH 22/74] VFS: Add CL_MAKE_HARD_READONLY " Valerie Aurora
2011-03-23  1:58 ` [PATCH 23/74] union-mount: Union mounts documentation Valerie Aurora
2011-03-23  1:59 ` [PATCH 24/74] union-mount: Introduce MNT_UNION and MS_UNION flags Valerie Aurora
2011-03-23  1:59 ` [PATCH 25/74] union-mount: Add CONFIG_UNION_MOUNT option Valerie Aurora
2011-03-23  1:59 ` [PATCH 26/74] union-mount: Create union_stack structure Valerie Aurora
2011-03-23  1:59 ` [PATCH 27/74] union-mount: Add two superblock fields for union mounts Valerie Aurora
2011-03-23  1:59 ` [PATCH 28/74] union-mount: Add union_alloc() Valerie Aurora
2011-03-23  1:59 ` [PATCH 29/74] union-mount: Add union_find_dir() Valerie Aurora
2011-03-23  1:59 ` [PATCH 30/74] union-mount: Create d_free_unions() Valerie Aurora
2011-03-23  1:59 ` [PATCH 31/74] union-mount: Free union stack on removal of topmost dentry from dcache Valerie Aurora
2011-03-23  1:59 ` [PATCH 32/74] union-mount: Create union_add_dir() Valerie Aurora
2011-03-23  1:59 ` [PATCH 33/74] union-mount: Add union_create_topmost_dir() Valerie Aurora
2011-03-23  1:59 ` [PATCH 34/74] union-mount: Create IS_MNT_UNION() Valerie Aurora
2011-03-23  1:59 ` [PATCH 35/74] union-mount: Create needs_lookup_union() Valerie Aurora
2011-03-23  1:59 ` [PATCH 36/74] union-mount: Create check_topmost_union_mnt() Valerie Aurora
2011-03-23  1:59 ` [PATCH 37/74] union-mount: Add clone_union_tree() and put_union_sb() Valerie Aurora
2011-03-23  1:59 ` [PATCH 38/74] union-mount: Create build_root_union() Valerie Aurora
2011-03-23  1:59 ` [PATCH 39/74] union-mount: Create prepare_mnt_union() and cleanup_mnt_union() Valerie Aurora
2011-03-23  1:59 ` [PATCH 40/74] union-mount: Prevent improper union-related remounts Valerie Aurora
2011-03-23  1:59 ` [PATCH 41/74] union-mount: Prevent topmost file system from being mounted elsewhere Valerie Aurora
2011-03-23  1:59 ` [PATCH 42/74] union-mount: Prevent bind mounts of union mounts Valerie Aurora
2011-03-23  1:59 ` [PATCH 43/74] union-mount: Implement union mount Valerie Aurora
2011-03-23  1:59 ` [PATCH 44/74] union-mount: Temporarily disable some syscalls Valerie Aurora
2011-03-23  2:12 ` [PATCH 00/74] Union mounts version something or other Valerie Aurora
2011-03-24 13:43   ` Union mounts comparison with overlay file system prototype? Ric Wheeler
2011-03-25 11:38     ` Szeredi Miklos
2011-03-25 12:12       ` Ric Wheeler
2011-03-23  8:38 ` [PATCH 00/74] Union mounts version something or other Sedat Dilek
2011-03-24 22:40   ` Ben Hutchings
2011-03-25  2:32     ` Sedat Dilek
2011-03-30 14:30 ` David Howells
2011-04-01 16:48   ` Valerie Aurora
2011-04-21 13:09   ` David Howells
2011-04-24 21:48     ` Valerie Aurora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1300845590-14184-3-git-send-email-valerie.aurora@gmail.com \
    --to=valerie.aurora@gmail.com \
    --cc=jblunck@suse.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux@vger.kernel.org \
    --cc=vaurora@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).