Btrfs: make balance code choose wiser when relocating block groups V2
PATCH 1/1 Btrfs: make balance code choose wiser when relocating block groups V2
Currently, we can panic the box if the first block group we go to move is of a type where there is no space left to move those extents. For example, if we fill the disk up with data, and then we try to balance and we have no room to move the data nor room to allocate new chunks, we will panic. Change this by checking to see if we have room to move this chunk around, and if not, return -ENOSPC and move on to the next chunk. This will make sure we remove block groups that are moveable, like if we have alot of empty metadata block groups, and then that way we make room to be able to balance our data chunks as well. Tested this with an fs that would panic on btrfs-vol -b normally, but no longer panics with this patch.
V1->V2:
-actually search for a free extent on the device to make sure we can allocate a chunk if need be.
-fix btrfs_shrink_device to make sure we actually try to relocate all the chunks, and then if we can't return -ENOSPC so if we are doing a btrfs-vol -r we don't remove the device with data still on it.
-check to make sure the block group we are going to relocate isn't the last one in that particular space
-fix a bug in btrfs_shrink_device where we would change the device's size and not fix it if we fail to do our relocate
--- fs/btrfs/ctree.h | 1 + fs/btrfs/extent-tree.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.c | 75 +++++++++++++++++++++++++++++++---------- fs/btrfs/volumes.h | 3 ++ 4 files changed, 148 insertions(+), 18 deletions(-)
fs/btrfs/ctree.h +1 -0
@@ -1998,6 +1998,7 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,int btrfs_extent_readonly (struct btrfs_root *root,u64 bytenr);int btrfs_free_block_groups (struct btrfs_fs_info *info);int btrfs_read_block_groups (struct btrfs_root *root); +int btrfs_can_relocate (struct btrfs_root *root,u64 bytenr); int btrfs_make_block_group(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 bytes_used, u64 type, u64 chunk_objectid, u64 chunk_offset,
fs/btrfs/extent-tree.c +87 -0
93 lines not on this page · raw message
fs/btrfs/volumes.c +57 -18
178 lines not on this page · raw message
fs/btrfs/volumes.h +3 -0
@@ -181,4 +181,7 @@ int btrfs_balance(struct btrfs_root *dev_root);void btrfs_unlock_volumes (void );void btrfs_lock_volumes (void );int btrfs_chunk_readonly (struct btrfs_root *root,u64 chunk_offset); +int find_free_dev_extent (struct btrfs_trans_handle *trans, +struct btrfs_device *device,u64 num_bytes, +u64 *start,u64 *max_avail);#endif
Signature · 1 line
1.5.4.3