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
8 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
9 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
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
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);
24 -extern int ext4_ext_migrate(struct inode *, struct file *, unsigned int,
26 +extern int ext4_ext_migrate(struct inode *);
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
34 @@ -277,7 +277,26 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
37 case EXT4_IOC_MIGRATE:
38 - return ext4_ext_migrate(inode, filp, cmd, arg);
41 + if (!is_owner_or_cap(inode))
44 + err = mnt_want_write(filp->f_path.mnt);
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.
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);
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)
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)
76 @@ -516,12 +515,6 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp,
77 * when we add extents we extent the journal
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.
84 - mutex_lock(&(inode->i_mutex));
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));
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