aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2007-09-14 10:22:57 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-09-14 10:22:57 -0400
commitd03581f4345e30db078ea8f81189e8177280bbb8 (patch)
treea1cd3ad16cd4f39090c960b6bcb93751412e0d94 /fs/btrfs/inode.c
parent34287aa3605d52ef5a4b6e5e2cca98667166508b (diff)
split up btrfs_ioctl
Add a helper per ioctl function to make the code more readable. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c106
1 files changed, 59 insertions, 47 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 3901a7fa0947..e24b875327da 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1957,65 +1957,77 @@ out_unlock:
1957 return 0; 1957 return 0;
1958} 1958}
1959 1959
1960long btrfs_ioctl(struct file *file, unsigned int 1960static int btrfs_ioctl_snap_create(struct btrfs_root *root, void __user *arg)
1961 cmd, unsigned long arg)
1962{ 1961{
1963 struct inode *inode = file->f_path.dentry->d_inode;
1964 struct btrfs_root *root = BTRFS_I(inode)->root;
1965 struct btrfs_ioctl_vol_args vol_args; 1962 struct btrfs_ioctl_vol_args vol_args;
1966 int ret = 0;
1967 struct btrfs_dir_item *di; 1963 struct btrfs_dir_item *di;
1968 int namelen;
1969 struct btrfs_path *path; 1964 struct btrfs_path *path;
1965 int namelen;
1970 u64 root_dirid; 1966 u64 root_dirid;
1971 1967
1972 switch (cmd) { 1968 if (copy_from_user(&vol_args, arg, sizeof(vol_args)))
1973 case BTRFS_IOC_SNAP_CREATE: 1969 return -EFAULT;
1974 if (copy_from_user(&vol_args, 1970
1975 (struct btrfs_ioctl_vol_args __user *)arg, 1971 namelen = strlen(vol_args.name);
1976 sizeof(vol_args))) 1972 if (namelen > BTRFS_VOL_NAME_MAX)
1977 return -EFAULT; 1973 return -EINVAL;
1978 namelen = strlen(vol_args.name); 1974 if (strchr(vol_args.name, '/'))
1979 if (namelen > BTRFS_VOL_NAME_MAX) 1975 return -EINVAL;
1980 return -EINVAL; 1976
1981 if (strchr(vol_args.name, '/')) 1977 path = btrfs_alloc_path();
1982 return -EINVAL; 1978 if (!path)
1983 path = btrfs_alloc_path(); 1979 return -ENOMEM;
1984 if (!path) 1980
1985 return -ENOMEM; 1981 root_dirid = root->fs_info->sb->s_root->d_inode->i_ino,
1986 root_dirid = root->fs_info->sb->s_root->d_inode->i_ino, 1982 mutex_lock(&root->fs_info->fs_mutex);
1983 di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root,
1984 path, root_dirid,
1985 vol_args.name, namelen, 0);
1986 mutex_unlock(&root->fs_info->fs_mutex);
1987 btrfs_free_path(path);
1988 if (di && !IS_ERR(di))
1989 return -EEXIST;
1990 if (IS_ERR(di))
1991 return PTR_ERR(di);
1992
1993 if (root == root->fs_info->tree_root)
1994 return create_subvol(root, vol_args.name, namelen);
1995 return create_snapshot(root, vol_args.name, namelen);
1996}
1997
1998static int btrfs_ioctl_defrag(struct file *file)
1999{
2000 struct inode *inode = file->f_path.dentry->d_inode;
2001 struct btrfs_root *root = BTRFS_I(inode)->root;
2002
2003 switch (inode->i_mode & S_IFMT) {
2004 case S_IFDIR:
1987 mutex_lock(&root->fs_info->fs_mutex); 2005 mutex_lock(&root->fs_info->fs_mutex);
1988 di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root, 2006 btrfs_defrag_root(root, 0);
1989 path, root_dirid, 2007 btrfs_defrag_root(root->fs_info->extent_root, 0);
1990 vol_args.name, namelen, 0);
1991 mutex_unlock(&root->fs_info->fs_mutex); 2008 mutex_unlock(&root->fs_info->fs_mutex);
1992 btrfs_free_path(path);
1993 if (di && !IS_ERR(di))
1994 return -EEXIST;
1995 if (IS_ERR(di))
1996 return PTR_ERR(di);
1997
1998 if (root == root->fs_info->tree_root)
1999 ret = create_subvol(root, vol_args.name, namelen);
2000 else
2001 ret = create_snapshot(root, vol_args.name, namelen);
2002 break; 2009 break;
2010 case S_IFREG:
2011 btrfs_defrag_file(file);
2012 break;
2013 }
2014
2015 return 0;
2016}
2003 2017
2018long btrfs_ioctl(struct file *file, unsigned int
2019 cmd, unsigned long arg)
2020{
2021 struct btrfs_root *root = BTRFS_I(file->f_path.dentry->d_inode)->root;
2022
2023 switch (cmd) {
2024 case BTRFS_IOC_SNAP_CREATE:
2025 return btrfs_ioctl_snap_create(root, (void __user *)arg);
2004 case BTRFS_IOC_DEFRAG: 2026 case BTRFS_IOC_DEFRAG:
2005 if (S_ISDIR(inode->i_mode)) { 2027 return btrfs_ioctl_defrag(file);
2006 mutex_lock(&root->fs_info->fs_mutex);
2007 btrfs_defrag_root(root, 0);
2008 btrfs_defrag_root(root->fs_info->extent_root, 0);
2009 mutex_unlock(&root->fs_info->fs_mutex);
2010 } else if (S_ISREG(inode->i_mode)) {
2011 btrfs_defrag_file(file);
2012 }
2013 ret = 0;
2014 break;
2015 default:
2016 return -ENOTTY;
2017 } 2028 }
2018 return ret; 2029
2030 return -ENOTTY;
2019} 2031}
2020 2032
2021/* 2033/*