diff options
author | Jeff Mahoney <jeffm@suse.com> | 2013-07-09 16:37:21 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2013-09-01 07:57:23 -0400 |
commit | ee3441b49092000402748f5345ee0a3d4c8ac04e (patch) | |
tree | 34ee8c6a2e89451eb8936f5d91d650c3bd475847 | |
parent | 74be9510876a66ad9826613ac8a526d26f9e7f01 (diff) |
btrfs: fall back to global reservation when removing subvolumes
I recently did some ENOSPC testing that involved filling the disk
while create and removing snapshots in a loop. During the test cycle,
I ran into an ENOSPC when trying to remove a snapshot, leaving the fs
stuck in ENOSPC even after a umount/mount cycle.
This patch allow subvolume removal to fall back onto the global
block reservation in order to succeed when it would have failed
otherwise.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r-- | fs/btrfs/ctree.h | 2 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 8 | ||||
-rw-r--r-- | fs/btrfs/ioctl.c | 7 |
3 files changed, 12 insertions, 5 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index e795bf135e80..8cc03321a368 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -3175,7 +3175,7 @@ void btrfs_orphan_release_metadata(struct inode *inode); | |||
3175 | int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, | 3175 | int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, |
3176 | struct btrfs_block_rsv *rsv, | 3176 | struct btrfs_block_rsv *rsv, |
3177 | int nitems, | 3177 | int nitems, |
3178 | u64 *qgroup_reserved); | 3178 | u64 *qgroup_reserved, bool use_global_rsv); |
3179 | void btrfs_subvolume_release_metadata(struct btrfs_root *root, | 3179 | void btrfs_subvolume_release_metadata(struct btrfs_root *root, |
3180 | struct btrfs_block_rsv *rsv, | 3180 | struct btrfs_block_rsv *rsv, |
3181 | u64 qgroup_reserved); | 3181 | u64 qgroup_reserved); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 3e7e05e6156f..7bea4d2f85dc 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -4742,10 +4742,12 @@ void btrfs_orphan_release_metadata(struct inode *inode) | |||
4742 | int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, | 4742 | int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, |
4743 | struct btrfs_block_rsv *rsv, | 4743 | struct btrfs_block_rsv *rsv, |
4744 | int items, | 4744 | int items, |
4745 | u64 *qgroup_reserved) | 4745 | u64 *qgroup_reserved, |
4746 | bool use_global_rsv) | ||
4746 | { | 4747 | { |
4747 | u64 num_bytes; | 4748 | u64 num_bytes; |
4748 | int ret; | 4749 | int ret; |
4750 | struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv; | ||
4749 | 4751 | ||
4750 | if (root->fs_info->quota_enabled) { | 4752 | if (root->fs_info->quota_enabled) { |
4751 | /* One for parent inode, two for dir entries */ | 4753 | /* One for parent inode, two for dir entries */ |
@@ -4764,6 +4766,10 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, | |||
4764 | BTRFS_BLOCK_GROUP_METADATA); | 4766 | BTRFS_BLOCK_GROUP_METADATA); |
4765 | ret = btrfs_block_rsv_add(root, rsv, num_bytes, | 4767 | ret = btrfs_block_rsv_add(root, rsv, num_bytes, |
4766 | BTRFS_RESERVE_FLUSH_ALL); | 4768 | BTRFS_RESERVE_FLUSH_ALL); |
4769 | |||
4770 | if (ret == -ENOSPC && use_global_rsv) | ||
4771 | ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes); | ||
4772 | |||
4767 | if (ret) { | 4773 | if (ret) { |
4768 | if (*qgroup_reserved) | 4774 | if (*qgroup_reserved) |
4769 | btrfs_qgroup_free(root, *qgroup_reserved); | 4775 | btrfs_qgroup_free(root, *qgroup_reserved); |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 238a05545ee2..841044b80658 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -396,7 +396,7 @@ static noinline int create_subvol(struct inode *dir, | |||
396 | * of create_snapshot(). | 396 | * of create_snapshot(). |
397 | */ | 397 | */ |
398 | ret = btrfs_subvolume_reserve_metadata(root, &block_rsv, | 398 | ret = btrfs_subvolume_reserve_metadata(root, &block_rsv, |
399 | 7, &qgroup_reserved); | 399 | 7, &qgroup_reserved, false); |
400 | if (ret) | 400 | if (ret) |
401 | return ret; | 401 | return ret; |
402 | 402 | ||
@@ -576,7 +576,8 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, | |||
576 | */ | 576 | */ |
577 | ret = btrfs_subvolume_reserve_metadata(BTRFS_I(dir)->root, | 577 | ret = btrfs_subvolume_reserve_metadata(BTRFS_I(dir)->root, |
578 | &pending_snapshot->block_rsv, 7, | 578 | &pending_snapshot->block_rsv, 7, |
579 | &pending_snapshot->qgroup_reserved); | 579 | &pending_snapshot->qgroup_reserved, |
580 | false); | ||
580 | if (ret) | 581 | if (ret) |
581 | goto out; | 582 | goto out; |
582 | 583 | ||
@@ -2174,7 +2175,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, | |||
2174 | * ref/backref. | 2175 | * ref/backref. |
2175 | */ | 2176 | */ |
2176 | err = btrfs_subvolume_reserve_metadata(root, &block_rsv, | 2177 | err = btrfs_subvolume_reserve_metadata(root, &block_rsv, |
2177 | 5, &qgroup_reserved); | 2178 | 5, &qgroup_reserved, true); |
2178 | if (err) | 2179 | if (err) |
2179 | goto out_up_write; | 2180 | goto out_up_write; |
2180 | 2181 | ||