Btrfs: fix OOPS of empty filesystem after balance
btrfs will remove unused block groups after balance. When a empty filesystem is balanced, the block group with tag "DATA" may be dropped, and after umount and mount again, it will not find "DATA" space_info and lead to OOPS. So we initial the necessary space_infos(DATA, SYSTEM, METADATA) to avoid OOPS. Reported-by: Daniel J Blueman <daniel.blueman@gmail.com> Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
parent
9f7c43c967
commit
c59021f846
@ -2234,6 +2234,7 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans,
|
|||||||
struct btrfs_root *root, u64 type);
|
struct btrfs_root *root, u64 type);
|
||||||
int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range);
|
int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range);
|
||||||
|
|
||||||
|
int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
|
||||||
/* ctree.c */
|
/* ctree.c */
|
||||||
int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key,
|
int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key,
|
||||||
int level, int *slot);
|
int level, int *slot);
|
||||||
|
@ -2065,6 +2065,12 @@ struct btrfs_root *open_ctree(struct super_block *sb,
|
|||||||
fs_info->metadata_alloc_profile = (u64)-1;
|
fs_info->metadata_alloc_profile = (u64)-1;
|
||||||
fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
|
fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
|
||||||
|
|
||||||
|
ret = btrfs_init_space_info(fs_info);
|
||||||
|
if (ret) {
|
||||||
|
printk(KERN_ERR "Failed to initial space info: %d\n", ret);
|
||||||
|
goto fail_block_groups;
|
||||||
|
}
|
||||||
|
|
||||||
ret = btrfs_read_block_groups(extent_root);
|
ret = btrfs_read_block_groups(extent_root);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk(KERN_ERR "Failed to read block groups: %d\n", ret);
|
printk(KERN_ERR "Failed to read block groups: %d\n", ret);
|
||||||
|
@ -8778,6 +8778,29 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int btrfs_init_space_info(struct btrfs_fs_info *fs_info)
|
||||||
|
{
|
||||||
|
struct btrfs_space_info *space_info;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = update_space_info(fs_info, BTRFS_BLOCK_GROUP_SYSTEM, 0, 0,
|
||||||
|
&space_info);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = update_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA, 0, 0,
|
||||||
|
&space_info);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = update_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA, 0, 0,
|
||||||
|
&space_info);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int btrfs_error_unpin_extent_range(struct btrfs_root *root, u64 start, u64 end)
|
int btrfs_error_unpin_extent_range(struct btrfs_root *root, u64 start, u64 end)
|
||||||
{
|
{
|
||||||
return unpin_extent_range(root, start, end);
|
return unpin_extent_range(root, start, end);
|
||||||
|
Loading…
Reference in New Issue
Block a user