Commit d03581f4 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Woodhouse

split up btrfs_ioctl

Add a helper per ioctl function to make the code more readable.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 34287aa3
...@@ -1957,32 +1957,27 @@ int btrfs_defrag_file(struct file *file) { ...@@ -1957,32 +1957,27 @@ int btrfs_defrag_file(struct file *file) {
return 0; return 0;
} }
long btrfs_ioctl(struct file *file, unsigned int static int btrfs_ioctl_snap_create(struct btrfs_root *root, void __user *arg)
cmd, unsigned long arg)
{ {
struct inode *inode = file->f_path.dentry->d_inode;
struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_ioctl_vol_args vol_args; struct btrfs_ioctl_vol_args vol_args;
int ret = 0;
struct btrfs_dir_item *di; struct btrfs_dir_item *di;
int namelen;
struct btrfs_path *path; struct btrfs_path *path;
int namelen;
u64 root_dirid; u64 root_dirid;
switch (cmd) { if (copy_from_user(&vol_args, arg, sizeof(vol_args)))
case BTRFS_IOC_SNAP_CREATE:
if (copy_from_user(&vol_args,
(struct btrfs_ioctl_vol_args __user *)arg,
sizeof(vol_args)))
return -EFAULT; return -EFAULT;
namelen = strlen(vol_args.name); namelen = strlen(vol_args.name);
if (namelen > BTRFS_VOL_NAME_MAX) if (namelen > BTRFS_VOL_NAME_MAX)
return -EINVAL; return -EINVAL;
if (strchr(vol_args.name, '/')) if (strchr(vol_args.name, '/'))
return -EINVAL; return -EINVAL;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
root_dirid = root->fs_info->sb->s_root->d_inode->i_ino, root_dirid = root->fs_info->sb->s_root->d_inode->i_ino,
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root, di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root,
...@@ -1996,26 +1991,43 @@ long btrfs_ioctl(struct file *file, unsigned int ...@@ -1996,26 +1991,43 @@ long btrfs_ioctl(struct file *file, unsigned int
return PTR_ERR(di); return PTR_ERR(di);
if (root == root->fs_info->tree_root) if (root == root->fs_info->tree_root)
ret = create_subvol(root, vol_args.name, namelen); return create_subvol(root, vol_args.name, namelen);
else return create_snapshot(root, vol_args.name, namelen);
ret = create_snapshot(root, vol_args.name, namelen); }
break;
case BTRFS_IOC_DEFRAG: static int btrfs_ioctl_defrag(struct file *file)
if (S_ISDIR(inode->i_mode)) { {
struct inode *inode = file->f_path.dentry->d_inode;
struct btrfs_root *root = BTRFS_I(inode)->root;
switch (inode->i_mode & S_IFMT) {
case S_IFDIR:
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
btrfs_defrag_root(root, 0); btrfs_defrag_root(root, 0);
btrfs_defrag_root(root->fs_info->extent_root, 0); btrfs_defrag_root(root->fs_info->extent_root, 0);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
} else if (S_ISREG(inode->i_mode)) { break;
case S_IFREG:
btrfs_defrag_file(file); btrfs_defrag_file(file);
}
ret = 0;
break; break;
default:
return -ENOTTY;
} }
return ret;
return 0;
}
long btrfs_ioctl(struct file *file, unsigned int
cmd, unsigned long arg)
{
struct btrfs_root *root = BTRFS_I(file->f_path.dentry->d_inode)->root;
switch (cmd) {
case BTRFS_IOC_SNAP_CREATE:
return btrfs_ioctl_snap_create(root, (void __user *)arg);
case BTRFS_IOC_DEFRAG:
return btrfs_ioctl_defrag(file);
}
return -ENOTTY;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment