ext4: elevate write count for migrate ioctl
From: Aneesh Kumar K.V <[email protected]>
migrate ioctl writes to the filsystem. So we need to elevate the write count.
Signed-off-by Aneesh Kumar K.V <[email protected]>
--- fs/ext4/ext4.h | 3 +-- fs/ext4/ioctl.c | 21 ++++++++++++++++++++- fs/ext4/migrate.c | 10 +--------- 3 files changed, 22 insertions(+), 12 deletions(-)
fs/ext4/ext4.h +1 -2
@@ -1165,8 +1165,7 @@ extern long ext4_ioctl(struct file *, unsigned int, unsigned long);extern long ext4_compat_ioctl (struct file *,unsigned int ,unsigned long );/* migrate.c */ -extern int ext4_ext_migrate (struct inode *,struct file *,unsigned int , -unsigned long ); +extern int ext4_ext_migrate (struct inode *);/* namei.c */ extern int ext4_orphan_add (handle_t *,struct inode *);extern int ext4_orphan_del (handle_t *,struct inode *);
fs/ext4/ioctl.c +20 -1
@@ -277,7 +277,26 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) }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 ;
fs/ext4/migrate.c +1 -9
@@ -447,8 +447,7 @@ static int free_ext_block(handle_t *handle, struct inode *inode) } -int ext4_ext_migrate (struct inode *inode,struct file *filp, -unsigned int cmd,unsigned long arg) +int ext4_ext_migrate (struct inode *inode) {handle_t *handle;int retval =0 , i;
@@ -516,12 +515,6 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp,* when we add extents we extent the journal */ /* -* 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)); -/* * Even though we take i_mutex we can still cause block allocation * via mmap write to holes. If we have allocated new blocks we fail * migrate. New block allocation will clear EXT4_EXT_MIGRATE flag.
@@ -623,7 +616,6 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp, tmp_inode->i_nlink =0 ;ext4_journal_stop (handle); -mutex_unlock (&(inode->i_mutex));if (tmp_inode)iput (tmp_inode);
From: Aneesh Kumar K.V <[email protected]>
This patch hooks the ext3 to ext4 migrate interface to EXT4_IOC_SETFLAGS ioctl. The userspace interface is via chattr +e. We only allow setting extent flags. Clearing extent flag (migrating from ext4 to ext3) is not supported.
Signed-off-by Aneesh Kumar K.V <[email protected]>
--- fs/ext4/ext4.h | 2 +- fs/ext4/ioctl.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-)
fs/ext4/ext4.h +1 -1
@@ -250,7 +250,7 @@ struct flex_groups {#define EXT4_RESERVED_FL 0x80000000/* reserved for ext4 lib */ #define EXT4_FL_USER_VISIBLE 0x000BDFFF/* User visible flags */ -#define EXT4_FL_USER_MODIFIABLE 0x000380FF/* User modifiable flags */ +#define EXT4_FL_USER_MODIFIABLE 0x000B80FF/* User modifiable flags */ /* * Inode dynamic state flags
fs/ext4/ioctl.c +16 -1
@@ -34,7 +34,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return put_user (flags, (int __user *) arg);case EXT4_IOC_SETFLAGS : {handle_t *handle =NULL ; -int err; +int err, migrate =0 ;struct ext4_iloc iloc;unsigned int oldflags;unsigned int jflag;
@@ -82,6 +82,17 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)if (!capable (CAP_SYS_RESOURCE )) goto flags_out; } +if (oldflags &EXT4_EXTENTS_FL ) { +/* We don't support clearning extent flags */ +if (!(flags &EXT4_EXTENTS_FL )) { + err = -EOPNOTSUPP ; + goto flags_out; + } + }else if (flags &EXT4_EXTENTS_FL ) { +/* migrate the file */ + migrate =1 ; + flags &= ~EXT4_EXTENTS_FL ; + } handle =ext4_journal_start (inode,1 );if (IS_ERR (handle)) {
@@ -109,6 +120,10 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL )) err =ext4_change_inode_journal_flag (inode, jflag); +if (err) + goto flags_out; +if (migrate) + err =ext4_ext_migrate (inode); flags_out:mutex_unlock (&inode->i_mutex);mnt_drop_write (filp->f_path.mnt);
Theodore Tso
maintainerThanks, both patches have been added to the ext4 patch queue. I updated the patch name on the second patch since it was clear you had overlooked doing so.
- Ted