ext4: take handling of EXT4_IOC_GROUP_ADD into a helper, get rid of set_fs()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2017-09-29 21:39:59 -04:00
Родитель 24219d21c7
Коммит e145b35bb9
1 изменённых файлов: 43 добавлений и 43 удалений

Просмотреть файл

@ -583,6 +583,44 @@ static int ext4_ioc_getfsmap(struct super_block *sb,
return 0; return 0;
} }
static long ext4_ioctl_group_add(struct file *file,
struct ext4_new_group_data *input)
{
struct super_block *sb = file_inode(file)->i_sb;
int err, err2=0;
err = ext4_resize_begin(sb);
if (err)
return err;
if (ext4_has_feature_bigalloc(sb)) {
ext4_msg(sb, KERN_ERR,
"Online resizing not supported with bigalloc");
err = -EOPNOTSUPP;
goto group_add_out;
}
err = mnt_want_write_file(file);
if (err)
goto group_add_out;
err = ext4_group_add(sb, input);
if (EXT4_SB(sb)->s_journal) {
jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
}
if (err == 0)
err = err2;
mnt_drop_write_file(file);
if (!err && ext4_has_group_desc_csum(sb) &&
test_opt(sb, INIT_INODE_TABLE))
err = ext4_register_li_request(sb, input->group);
group_add_out:
ext4_resize_end(sb);
return err;
}
long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
@ -767,44 +805,12 @@ mext_out:
case EXT4_IOC_GROUP_ADD: { case EXT4_IOC_GROUP_ADD: {
struct ext4_new_group_data input; struct ext4_new_group_data input;
int err, err2=0;
err = ext4_resize_begin(sb);
if (err)
return err;
if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg, if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
sizeof(input))) { sizeof(input)))
err = -EFAULT; return -EFAULT;
goto group_add_out;
}
if (ext4_has_feature_bigalloc(sb)) { return ext4_ioctl_group_add(filp, &input);
ext4_msg(sb, KERN_ERR,
"Online resizing not supported with bigalloc");
err = -EOPNOTSUPP;
goto group_add_out;
}
err = mnt_want_write_file(filp);
if (err)
goto group_add_out;
err = ext4_group_add(sb, &input);
if (EXT4_SB(sb)->s_journal) {
jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
}
if (err == 0)
err = err2;
mnt_drop_write_file(filp);
if (!err && ext4_has_group_desc_csum(sb) &&
test_opt(sb, INIT_INODE_TABLE))
err = ext4_register_li_request(sb, input.group);
group_add_out:
ext4_resize_end(sb);
return err;
} }
case EXT4_IOC_MIGRATE: case EXT4_IOC_MIGRATE:
@ -1075,8 +1081,7 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
break; break;
case EXT4_IOC32_GROUP_ADD: { case EXT4_IOC32_GROUP_ADD: {
struct compat_ext4_new_group_input __user *uinput; struct compat_ext4_new_group_input __user *uinput;
struct ext4_new_group_input input; struct ext4_new_group_data input;
mm_segment_t old_fs;
int err; int err;
uinput = compat_ptr(arg); uinput = compat_ptr(arg);
@ -1089,12 +1094,7 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
&uinput->reserved_blocks); &uinput->reserved_blocks);
if (err) if (err)
return -EFAULT; return -EFAULT;
old_fs = get_fs(); return ext4_ioctl_group_add(file, &input);
set_fs(KERNEL_DS);
err = ext4_ioctl(file, EXT4_IOC_GROUP_ADD,
(unsigned long) &input);
set_fs(old_fs);
return err;
} }
case EXT4_IOC_MOVE_EXT: case EXT4_IOC_MOVE_EXT:
case EXT4_IOC_RESIZE_FS: case EXT4_IOC_RESIZE_FS: