From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Hansen Subject: [PATCH 05/26] r/o bind mounts: stub functions Date: Fri, 22 Jun 2007 13:03:09 -0700 Message-ID: <20070622200309.985982F5@kernel> References: <20070622200303.82D9CC3A@kernel> Cc: linux-fsdevel@vger.kernel.org, hch@infradead.org, viro@ftp.linux.org.uk, Dave Hansen To: akpm@osdl.org Return-path: Received: from e34.co.us.ibm.com ([32.97.110.152]:59110 "EHLO e34.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751215AbXFVUD1 (ORCPT ); Fri, 22 Jun 2007 16:03:27 -0400 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e34.co.us.ibm.com (8.13.8/8.13.8) with ESMTP id l5MK3Q5v023885 for ; Fri, 22 Jun 2007 16:03:26 -0400 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v8.3) with ESMTP id l5MK3C4T226224 for ; Fri, 22 Jun 2007 14:03:15 -0600 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id l5MK3Bl4032525 for ; Fri, 22 Jun 2007 14:03:11 -0600 In-Reply-To: <20070622200303.82D9CC3A@kernel> Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org 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 --- 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 + +/* + * 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); _