lkml.org 
[lkml]   [2007]   [Sep]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[RFC][PATCH 2/5] move mnt_want_write() into open_namei_create()
From
Date

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.

---
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-27 11:51:32.000000000 -0700
+++ lxc-dave/fs/namei.c 2007-09-27 11:51:32.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 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/
\
 
 \ /
  Last update: 2007-09-27 20:57    [from the cache]
©2003-2011 Jasper Spaans