Move ext4-use-percpu-data-for-lg_prealloc_list to stable series
[ext4-patch-queue.git] / elevate_write_count_for_migrate_ioctl
blob5a0cbabec9384f5932e4a9a24eae69fc67ede5c1
1 ext4: elevate write count for migrate ioctl
3 From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
5 The migrate ioctl writes to the filsystem, so we need to elevate the
6 write count.
8 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
9 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 ---
11  fs/ext4/ext4.h    |    3 +--
12  fs/ext4/ioctl.c   |   21 ++++++++++++++++++++-
13  fs/ext4/migrate.c |   10 +---------
14  3 files changed, 22 insertions(+), 12 deletions(-)
16 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
17 index bc856e3..103892b 100644
18 --- a/fs/ext4/ext4.h
19 +++ b/fs/ext4/ext4.h
20 @@ -1165,8 +1165,7 @@ extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
21  extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long);
23  /* migrate.c */
24 -extern int ext4_ext_migrate(struct inode *, struct file *, unsigned int,
25 -                      unsigned long);
26 +extern int ext4_ext_migrate(struct inode *);
27  /* namei.c */
28  extern int ext4_orphan_add(handle_t *, struct inode *);
29  extern int ext4_orphan_del(handle_t *, struct inode *);
30 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
31 index 9daa40a..6e02967 100644
32 --- a/fs/ext4/ioctl.c
33 +++ b/fs/ext4/ioctl.c
34 @@ -277,7 +277,26 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35         }
37         case EXT4_IOC_MIGRATE:
38 -               return ext4_ext_migrate(inode, filp, cmd, arg);
39 +       {
40 +               int err;
41 +               if (!is_owner_or_cap(inode))
42 +                       return -EACCES;
44 +               err = mnt_want_write(filp->f_path.mnt);
45 +               if (err)
46 +                       return err;
47 +               /*
48 +                * inode_mutex prevent write and truncate on the file.
49 +                * Read still goes through. We take i_data_sem in
50 +                * ext4_ext_swap_inode_data before we switch the
51 +                * inode format to prevent read.
52 +                */
53 +               mutex_lock(&(inode->i_mutex));
54 +               err = ext4_ext_migrate(inode);
55 +               mutex_unlock(&(inode->i_mutex));
56 +               mnt_drop_write(filp->f_path.mnt);
57 +               return err;
58 +       }
60         default:
61                 return -ENOTTY;
62 diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
63 index 46fc0b5..f2a9cf4 100644
64 --- a/fs/ext4/migrate.c
65 +++ b/fs/ext4/migrate.c
66 @@ -447,8 +447,7 @@ static int free_ext_block(handle_t *handle, struct inode *inode)
68  }
70 -int ext4_ext_migrate(struct inode *inode, struct file *filp,
71 -                               unsigned int cmd, unsigned long arg)
72 +int ext4_ext_migrate(struct inode *inode)
73  {
74         handle_t *handle;
75         int retval = 0, i;
76 @@ -516,12 +515,6 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp,
77          * when we add extents we extent the journal
78          */
79         /*
80 -        * inode_mutex prevent write and truncate on the file. Read still goes
81 -        * through. We take i_data_sem in ext4_ext_swap_inode_data before we
82 -        * switch the inode format to prevent read.
83 -        */
84 -       mutex_lock(&(inode->i_mutex));
85 -       /*
86          * Even though we take i_mutex we can still cause block allocation
87          * via mmap write to holes. If we have allocated new blocks we fail
88          * migrate.  New block allocation will clear EXT4_EXT_MIGRATE flag.
89 @@ -623,7 +616,6 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp,
90         tmp_inode->i_nlink = 0;
92         ext4_journal_stop(handle);
93 -       mutex_unlock(&(inode->i_mutex));
95         if (tmp_inode)
96                 iput(tmp_inode);
98 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
99 the body of a message to majordomo@vger.kernel.org
100 More majordomo info at  http://vger.kernel.org/majordomo-info.html