]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/ext4/ioctl.c
ext4: elevate write count for migrate ioctl
[linux-2.6-omap-h63xx.git] / fs / ext4 / ioctl.c
index 25b13ede8086c606a4b1320c2a364889434c7b7c..9f3044ac6994a52e7be4211f185f8c81665e296b 100644 (file)
 #include <linux/fs.h>
 #include <linux/jbd2.h>
 #include <linux/capability.h>
-#include <linux/ext4_fs.h>
-#include <linux/ext4_jbd2.h>
 #include <linux/time.h>
 #include <linux/compat.h>
 #include <linux/smp_lock.h>
 #include <linux/mount.h>
 #include <asm/uaccess.h>
+#include "ext4_jbd2.h"
+#include "ext4.h"
 
-int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
-               unsigned long arg)
+long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
+       struct inode *inode = filp->f_dentry->d_inode;
        struct ext4_inode_info *ei = EXT4_I(inode);
        unsigned int flags;
        unsigned short rsv_window_size;
 
-       ext4_debug ("cmd = %u, arg = %lu\n", cmd, arg);
+       ext4_debug("cmd = %u, arg = %lu\n", cmd, arg);
 
        switch (cmd) {
        case EXT4_IOC_GETFLAGS:
@@ -186,7 +186,7 @@ setversion_out:
        case EXT4_IOC_SETRSVSZ: {
                int err;
 
-               if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
+               if (!test_opt(inode->i_sb, RESERVATION) || !S_ISREG(inode->i_mode))
                        return -ENOTTY;
 
                if (!is_owner_or_cap(inode))
@@ -267,7 +267,26 @@ setversion_out:
        }
 
        case EXT4_IOC_MIGRATE:
-               return ext4_ext_migrate(inode, filp, cmd, arg);
+       {
+               int err;
+               if (!is_owner_or_cap(inode))
+                       return -EACCES;
+
+               err = mnt_want_write(filp->f_path.mnt);
+               if (err)
+                       return err;
+               /*
+                * inode_mutex prevent write and truncate on the file.
+                * Read still goes through. We take i_data_sem in
+                * ext4_ext_swap_inode_data before we switch the
+                * inode format to prevent read.
+                */
+               mutex_lock(&(inode->i_mutex));
+               err = ext4_ext_migrate(inode);
+               mutex_unlock(&(inode->i_mutex));
+               mnt_drop_write(filp->f_path.mnt);
+               return err;
+       }
 
        default:
                return -ENOTTY;
@@ -277,9 +296,6 @@ setversion_out:
 #ifdef CONFIG_COMPAT
 long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
-       struct inode *inode = file->f_path.dentry->d_inode;
-       int ret;
-
        /* These are just misnamed, they actually get/put from/to user an int */
        switch (cmd) {
        case EXT4_IOC32_GETFLAGS:
@@ -319,9 +335,6 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        default:
                return -ENOIOCTLCMD;
        }
-       lock_kernel();
-       ret = ext4_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
-       unlock_kernel();
-       return ret;
+       return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
 }
 #endif