Re: [PATCH 06/24] r/o bind mounts: elevate write count for some ioctls

2007-09-19 Thread Christoph Hellwig
On Mon, Sep 17, 2007 at 11:27:25AM -0700, Dave Hansen wrote:
> 
> Some ioctl()s can cause writes to the filesystem.  Take
> these, and make them use mnt_want/drop_write() instead.
> 
> We need to pass the filp one layer deeper in XFS, but
> somebody _just_ pulled it out in February because nobody
> was using it, so I don't feel guilty for adding it back.

Ok.
-
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/


[PATCH 06/24] r/o bind mounts: elevate write count for some ioctls

2007-09-17 Thread Dave Hansen

Some ioctl()s can cause writes to the filesystem.  Take
these, and make them use mnt_want/drop_write() instead.

We need to pass the filp one layer deeper in XFS, but
somebody _just_ pulled it out in February because nobody
was using it, so I don't feel guilty for adding it back.

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

 lxc-dave/fs/ext2/ioctl.c  |   46 +-
 lxc-dave/fs/ext3/ioctl.c  |  100 +---
 lxc-dave/fs/ext4/ioctl.c  |  105 +-
 lxc-dave/fs/fat/file.c|   10 +--
 lxc-dave/fs/hfsplus/ioctl.c   |   39 +++-
 lxc-dave/fs/jfs/ioctl.c   |   33 ++
 lxc-dave/fs/ocfs2/ioctl.c |   11 +--
 lxc-dave/fs/reiserfs/ioctl.c  |   55 +++--
 lxc-dave/fs/xfs/linux-2.6/xfs_ioctl.c |   15 +++-
 lxc-dave/fs/xfs/linux-2.6/xfs_iops.c  |7 --
 lxc-dave/fs/xfs/linux-2.6/xfs_lrw.c   |9 ++
 11 files changed, 273 insertions(+), 157 deletions(-)

diff -puN fs/ext2/ioctl.c~ioctl-mnt-takers fs/ext2/ioctl.c
--- lxc/fs/ext2/ioctl.c~ioctl-mnt-takers2007-09-17 09:43:58.0 
-0700
+++ lxc-dave/fs/ext2/ioctl.c2007-09-17 09:43:58.0 -0700
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -23,6 +24,7 @@ int ext2_ioctl (struct inode * inode, st
struct ext2_inode_info *ei = EXT2_I(inode);
unsigned int flags;
unsigned short rsv_window_size;
+   int ret;
 
ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg);
 
@@ -34,14 +36,19 @@ int ext2_ioctl (struct inode * inode, st
case EXT2_IOC_SETFLAGS: {
unsigned int oldflags;
 
-   if (IS_RDONLY(inode))
-   return -EROFS;
-
-   if (!is_owner_or_cap(inode))
-   return -EACCES;
+   ret = mnt_want_write(filp->f_vfsmnt);
+   if (ret)
+   return ret;
+
+   if (!is_owner_or_cap(inode)) {
+   ret = -EACCES;
+   goto setflags_out;
+   }
 
-   if (get_user(flags, (int __user *) arg))
-   return -EFAULT;
+   if (get_user(flags, (int __user *) arg)) {
+   ret = -EFAULT;
+   goto setflags_out;
+   }
 
if (!S_ISDIR(inode->i_mode))
flags &= ~EXT2_DIRSYNC_FL;
@@ -58,7 +65,8 @@ int ext2_ioctl (struct inode * inode, st
if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
if (!capable(CAP_LINUX_IMMUTABLE)) {
mutex_unlock(&inode->i_mutex);
-   return -EPERM;
+   ret = -EPERM;
+   goto setflags_out;
}
}
 
@@ -70,20 +78,26 @@ int ext2_ioctl (struct inode * inode, st
ext2_set_inode_flags(inode);
inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(inode);
-   return 0;
+setflags_out:
+   mnt_drop_write(filp->f_vfsmnt);
+   return ret;
}
case EXT2_IOC_GETVERSION:
return put_user(inode->i_generation, (int __user *) arg);
case EXT2_IOC_SETVERSION:
if (!is_owner_or_cap(inode))
return -EPERM;
-   if (IS_RDONLY(inode))
-   return -EROFS;
-   if (get_user(inode->i_generation, (int __user *) arg))
-   return -EFAULT; 
-   inode->i_ctime = CURRENT_TIME_SEC;
-   mark_inode_dirty(inode);
-   return 0;
+   ret = mnt_want_write(filp->f_vfsmnt);
+   if (ret)
+   return ret;
+   if (get_user(inode->i_generation, (int __user *) arg)) {
+   ret = -EFAULT;
+   } else {
+   inode->i_ctime = CURRENT_TIME_SEC;
+   mark_inode_dirty(inode);
+   }
+   mnt_drop_write(filp->f_vfsmnt);
+   return ret;
case EXT2_IOC_GETRSVSZ:
if (test_opt(inode->i_sb, RESERVATION)
&& S_ISREG(inode->i_mode)
diff -puN fs/ext3/ioctl.c~ioctl-mnt-takers fs/ext3/ioctl.c
--- lxc/fs/ext3/ioctl.c~ioctl-mnt-takers2007-09-17 09:43:58.0 
-0700
+++ lxc-dave/fs/ext3/ioctl.c2007-09-17 09:43:58.0 -0700
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -38,14 +39,19 @@ int ext3_ioctl (struct inode * inode, st
unsigned int oldflags;
unsigned int jflag;
 
-   if (IS_RDONLY(inode))
-   return -EROFS;
+   err = mnt_want_write(filp->f_vfsmn