提交 c58aaad2 编写于 作者: M Miao Xie 提交者: Josef Bacik

Btrfs: fix wrong reserved space when deleting a snapshot/subvolume

When deleting a snapshot/subvolume, we need remove root ref/backref,
dir entries and update the dir inode, so we must reserve free space
for those operations.
Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: NJosef Bacik <jbacik@fusionio.com>
上级 d5c12070
...@@ -2064,6 +2064,8 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, ...@@ -2064,6 +2064,8 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
struct btrfs_root *dest = NULL; struct btrfs_root *dest = NULL;
struct btrfs_ioctl_vol_args *vol_args; struct btrfs_ioctl_vol_args *vol_args;
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_block_rsv block_rsv;
u64 qgroup_reserved;
int namelen; int namelen;
int ret; int ret;
int err = 0; int err = 0;
...@@ -2153,12 +2155,23 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, ...@@ -2153,12 +2155,23 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
if (err) if (err)
goto out_up_write; 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); trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
err = PTR_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, ret = btrfs_unlink_subvol(trans, root, dir,
dest->root_key.objectid, dest->root_key.objectid,
...@@ -2188,10 +2201,14 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, ...@@ -2188,10 +2201,14 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
} }
} }
out_end_trans: out_end_trans:
trans->block_rsv = NULL;
trans->bytes_reserved = 0;
ret = btrfs_end_transaction(trans, root); ret = btrfs_end_transaction(trans, root);
if (ret && !err) if (ret && !err)
err = ret; err = ret;
inode->i_flags |= S_DEAD; inode->i_flags |= S_DEAD;
out_release:
btrfs_subvolume_release_metadata(root, &block_rsv, qgroup_reserved);
out_up_write: out_up_write:
up_write(&root->fs_info->subvol_sem); up_write(&root->fs_info->subvol_sem);
out_unlock: out_unlock:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册