[RFC][PATCH 2/8] move mnt_want_write() into open_namei_create()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In a moment, we're going to make may_open() stop doing
the mnt_want/drop_write() pair.  Doing this first makes
the next patch simpler.

Signed-off-by: Dave Hansen <[email protected]>
---

 lxc-dave/fs/namei.c |   28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff -puN fs/namei.c~move-mnt_want_write-into-open_namei_create fs/namei.c
--- lxc/fs/namei.c~move-mnt_want_write-into-open_namei_create	2007-09-28 11:03:19.000000000 -0700
+++ lxc-dave/fs/namei.c	2007-09-28 11:03:19.000000000 -0700
@@ -1686,6 +1686,19 @@ static int open_namei_create(struct name
 	int error;
 	struct dentry *dir = nd->dentry;
 
+	/*
+	 * This ensures that the mnt stays writable
+	 * over the vfs_create() call to may_open(),
+	 * which takes a more persistent
+	 * mnt_want_write().
+	 */
+	error = mnt_want_write(nd->mnt);
+	if (error) {
+		mutex_unlock(&dir->d_inode->i_mutex);
+		dput(nd->dentry);
+		return error;
+	}
+
 	if (!IS_POSIXACL(dir->d_inode))
 		mode &= ~current->fs->umask;
 	error = vfs_create(dir->d_inode, path->dentry, mode, nd);
@@ -1693,9 +1706,16 @@ static int open_namei_create(struct name
 	dput(nd->dentry);
 	nd->dentry = path->dentry;
 	if (error)
-		return error;
+		goto out;
 	/* Don't check for write permission, don't truncate */
-	return may_open(nd, 0, flag & ~O_TRUNC);
+	error = may_open(nd, 0, flag & ~O_TRUNC);
+out:
+	/*
+	 * if needed, may_open() has taken a write
+	 * on the mnt for us, so we can release ours.
+	 */
+	mnt_drop_write(nd->mnt);
+	return error;
 }
 
 /*
@@ -1778,11 +1798,7 @@ do_last:
 
 	/* Negative dentry, just create the file */
 	if (!path.dentry->d_inode) {
-		error = mnt_want_write(nd->mnt);
-		if (error)
-			goto exit_mutex_unlock;
 		error = open_namei_create(nd, &path, flag, mode);
-		mnt_drop_write(nd->mnt);
 		if (error)
 			goto exit;
 		return 0;
_
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux