]> Pileus Git - ~andy/linux/blobdiff - fs/btrfs/ioctl.c
pinctrl: sunxi: Add Allwinner A13 pin functions
[~andy/linux] / fs / btrfs / ioctl.c
index 56d92549389c61af18421aa5470821e55ce7c8c6..c83086fdda055e25f2f9c378ca71fc420f807ed3 100644 (file)
@@ -152,7 +152,7 @@ void btrfs_inherit_iflags(struct inode *inode, struct inode *dir)
 
 static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
 {
-       struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
+       struct btrfs_inode *ip = BTRFS_I(file_inode(file));
        unsigned int flags = btrfs_flags_to_ioctl(ip->flags);
 
        if (copy_to_user(arg, &flags, sizeof(flags)))
@@ -177,7 +177,7 @@ static int check_flags(unsigned int flags)
 
 static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 {
-       struct inode *inode = file->f_path.dentry->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_inode *ip = BTRFS_I(inode);
        struct btrfs_root *root = ip->root;
        struct btrfs_trans_handle *trans;
@@ -310,7 +310,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 
 static int btrfs_ioctl_getversion(struct file *file, int __user *arg)
 {
-       struct inode *inode = file->f_path.dentry->d_inode;
+       struct inode *inode = file_inode(file);
 
        return put_user(inode->i_generation, arg);
 }
@@ -1348,7 +1348,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
        u64 new_size;
        u64 old_size;
        u64 devid = 1;
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
        struct btrfs_ioctl_vol_args *vol_args;
        struct btrfs_trans_handle *trans;
        struct btrfs_device *device = NULL;
@@ -1518,8 +1518,8 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file,
                        goto out_drop_write;
                }
 
-               src_inode = src.file->f_path.dentry->d_inode;
-               if (src_inode->i_sb != file->f_path.dentry->d_inode->i_sb) {
+               src_inode = file_inode(src.file);
+               if (src_inode->i_sb != file_inode(file)->i_sb) {
                        printk(KERN_INFO "btrfs: Snapshot src from "
                               "another FS\n");
                        ret = -EINVAL;
@@ -1611,7 +1611,7 @@ out:
 static noinline int btrfs_ioctl_subvol_getflags(struct file *file,
                                                void __user *arg)
 {
-       struct inode *inode = fdentry(file)->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_root *root = BTRFS_I(inode)->root;
        int ret = 0;
        u64 flags = 0;
@@ -1633,7 +1633,7 @@ static noinline int btrfs_ioctl_subvol_getflags(struct file *file,
 static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
                                              void __user *arg)
 {
-       struct inode *inode = fdentry(file)->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_trans_handle *trans;
        u64 root_flags;
@@ -1927,7 +1927,7 @@ static noinline int btrfs_ioctl_tree_search(struct file *file,
        if (IS_ERR(args))
                return PTR_ERR(args);
 
-       inode = fdentry(file)->d_inode;
+       inode = file_inode(file);
        ret = search_ioctl(inode, args);
        if (ret == 0 && copy_to_user(argp, args, sizeof(*args)))
                ret = -EFAULT;
@@ -2037,7 +2037,7 @@ static noinline int btrfs_ioctl_ino_lookup(struct file *file,
        if (IS_ERR(args))
                return PTR_ERR(args);
 
-       inode = fdentry(file)->d_inode;
+       inode = file_inode(file);
 
        if (args->treeid == 0)
                args->treeid = BTRFS_I(inode)->root->root_key.objectid;
@@ -2064,6 +2064,8 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
        struct btrfs_root *dest = NULL;
        struct btrfs_ioctl_vol_args *vol_args;
        struct btrfs_trans_handle *trans;
+       struct btrfs_block_rsv block_rsv;
+       u64 qgroup_reserved;
        int namelen;
        int ret;
        int err = 0;
@@ -2153,12 +2155,23 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
        if (err)
                goto out_up_write;
 
+       btrfs_init_block_rsv(&block_rsv, BTRFS_BLOCK_RSV_TEMP);
+       /*
+        * One for dir inode, two for dir entries, two for root
+        * ref/backref.
+        */
+       err = btrfs_subvolume_reserve_metadata(root, &block_rsv,
+                                              5, &qgroup_reserved);
+       if (err)
+               goto out_up_write;
+
        trans = btrfs_start_transaction(root, 0);
        if (IS_ERR(trans)) {
                err = PTR_ERR(trans);
-               goto out_up_write;
+               goto out_release;
        }
-       trans->block_rsv = &root->fs_info->global_block_rsv;
+       trans->block_rsv = &block_rsv;
+       trans->bytes_reserved = block_rsv.size;
 
        ret = btrfs_unlink_subvol(trans, root, dir,
                                dest->root_key.objectid,
@@ -2188,10 +2201,14 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
                }
        }
 out_end_trans:
+       trans->block_rsv = NULL;
+       trans->bytes_reserved = 0;
        ret = btrfs_end_transaction(trans, root);
        if (ret && !err)
                err = ret;
        inode->i_flags |= S_DEAD;
+out_release:
+       btrfs_subvolume_release_metadata(root, &block_rsv, qgroup_reserved);
 out_up_write:
        up_write(&root->fs_info->subvol_sem);
 out_unlock:
@@ -2219,7 +2236,7 @@ out:
 
 static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
 {
-       struct inode *inode = fdentry(file)->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_ioctl_defrag_range_args *range;
        int ret;
@@ -2279,7 +2296,7 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
                        /* the rest are all set to zero by kzalloc */
                        range->len = (u64)-1;
                }
-               ret = btrfs_defrag_file(fdentry(file)->d_inode, file,
+               ret = btrfs_defrag_file(file_inode(file), file,
                                        range, 0, 0);
                if (ret > 0)
                        ret = 0;
@@ -2327,7 +2344,7 @@ out:
 
 static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 {
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
        struct btrfs_ioctl_vol_args *vol_args;
        int ret;
 
@@ -2450,7 +2467,7 @@ out:
 static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
                                       u64 off, u64 olen, u64 destoff)
 {
-       struct inode *inode = fdentry(file)->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct fd src_file;
        struct inode *src;
@@ -2496,7 +2513,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
        if (src_file.file->f_path.mnt != file->f_path.mnt)
                goto out_fput;
 
-       src = src_file.file->f_dentry->d_inode;
+       src = file_inode(src_file.file);
 
        ret = -EINVAL;
        if (src == inode)
@@ -2858,7 +2875,7 @@ static long btrfs_ioctl_clone_range(struct file *file, void __user *argp)
  */
 static long btrfs_ioctl_trans_start(struct file *file)
 {
-       struct inode *inode = fdentry(file)->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_trans_handle *trans;
        int ret;
@@ -2898,7 +2915,7 @@ out:
 
 static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
 {
-       struct inode *inode = fdentry(file)->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_root *new_root;
        struct btrfs_dir_item *di;
@@ -3122,7 +3139,7 @@ out:
  */
 long btrfs_ioctl_trans_end(struct file *file)
 {
-       struct inode *inode = fdentry(file)->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_trans_handle *trans;
 
@@ -3184,7 +3201,7 @@ static noinline long btrfs_ioctl_wait_sync(struct btrfs_root *root,
 
 static long btrfs_ioctl_scrub(struct file *file, void __user *arg)
 {
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
        struct btrfs_ioctl_scrub_args *sa;
        int ret;
 
@@ -3475,7 +3492,7 @@ void update_ioctl_balance_args(struct btrfs_fs_info *fs_info, int lock,
 
 static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 {
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
        struct btrfs_fs_info *fs_info = root->fs_info;
        struct btrfs_ioctl_balance_args *bargs;
        struct btrfs_balance_control *bctl;
@@ -3665,7 +3682,7 @@ out:
 
 static long btrfs_ioctl_quota_ctl(struct file *file, void __user *arg)
 {
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
        struct btrfs_ioctl_quota_ctl_args *sa;
        struct btrfs_trans_handle *trans = NULL;
        int ret;
@@ -3724,7 +3741,7 @@ drop_write:
 
 static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)
 {
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
        struct btrfs_ioctl_qgroup_assign_args *sa;
        struct btrfs_trans_handle *trans;
        int ret;
@@ -3771,7 +3788,7 @@ drop_write:
 
 static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg)
 {
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
        struct btrfs_ioctl_qgroup_create_args *sa;
        struct btrfs_trans_handle *trans;
        int ret;
@@ -3822,7 +3839,7 @@ drop_write:
 
 static long btrfs_ioctl_qgroup_limit(struct file *file, void __user *arg)
 {
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
        struct btrfs_ioctl_qgroup_limit_args *sa;
        struct btrfs_trans_handle *trans;
        int ret;
@@ -3872,7 +3889,7 @@ static long btrfs_ioctl_set_received_subvol(struct file *file,
                                            void __user *arg)
 {
        struct btrfs_ioctl_received_subvol_args *sa = NULL;
-       struct inode *inode = fdentry(file)->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_root_item *root_item = &root->root_item;
        struct btrfs_trans_handle *trans;
@@ -4011,7 +4028,7 @@ out_unlock:
 long btrfs_ioctl(struct file *file, unsigned int
                cmd, unsigned long arg)
 {
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
        void __user *argp = (void __user *)arg;
 
        switch (cmd) {