This patch adds two function mnt_want_write() and
mnt_drop_write().  These are used like a lock pair around
and fs operations that might cause a write to the filesystem.

Before these can become useful, we must first cover each
place in the VFS where writes are performed with a
want/drop pair.  When that is complete, we can actually
introduce code that will safely check the counts before
allowing r/w<->r/o transitions to occur.

Note that we put the linux/fs.h #include as far down in
mount.h as possible.  This is to keep the mount.h->fs.h->
sched.h->mount.h include dependency from biting us.

Signed-off-by: Dave Hansen <[EMAIL PROTECTED]>
---

 lxc-dave/fs/namespace.c        |   13 +++++++++++++
 lxc-dave/include/linux/mount.h |   13 +++++++++++++
 2 files changed, 26 insertions(+)

diff -puN fs/namespace.c~03-24-add-vfsmount-writer-count fs/namespace.c
--- lxc/fs/namespace.c~03-24-add-vfsmount-writer-count  2007-06-21 
23:23:14.000000000 -0700
+++ lxc-dave/fs/namespace.c     2007-06-21 23:23:14.000000000 -0700
@@ -76,6 +76,19 @@ struct vfsmount *alloc_vfsmnt(const char
        return mnt;
 }
 
+int mnt_want_write(struct vfsmount *mnt)
+{
+       if (__mnt_is_readonly(mnt))
+               return -EROFS;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(mnt_want_write);
+
+void mnt_drop_write(struct vfsmount *mnt)
+{
+}
+EXPORT_SYMBOL_GPL(mnt_drop_write);
+
 int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb)
 {
        mnt->mnt_sb = sb;
diff -puN include/linux/mount.h~03-24-add-vfsmount-writer-count 
include/linux/mount.h
--- lxc/include/linux/mount.h~03-24-add-vfsmount-writer-count   2007-06-21 
23:23:14.000000000 -0700
+++ lxc-dave/include/linux/mount.h      2007-06-21 23:23:14.000000000 -0700
@@ -70,6 +70,19 @@ static inline struct vfsmount *mntget(st
        return mnt;
 }
 
+#include <linux/fs.h>
+
+/*
+ * This shouldn't be used directly ouside of the VFS,
+ * use mnt_want/drop_write() instead.
+ */
+static inline int __mnt_is_readonly(struct vfsmount *mnt)
+{
+       return (mnt->mnt_sb->s_flags & MS_RDONLY);
+}
+
+extern int mnt_want_write(struct vfsmount *mnt);
+extern void mnt_drop_write(struct vfsmount *mnt);
 extern void mntput_no_expire(struct vfsmount *mnt);
 extern void mnt_pin(struct vfsmount *mnt);
 extern void mnt_unpin(struct vfsmount *mnt);
_
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to