diff options
author | liubo <liubo2009@cn.fujitsu.com> | 2011-03-06 21:13:14 -0500 |
---|---|---|
committer | root <Chris Mason chris.mason@oracle.com> | 2011-03-28 05:37:53 -0400 |
commit | c59021f846881a957ac5afe456d0f59d6a517b61 (patch) | |
tree | 63e0552f2850b55dcc6bde31e0610e5f22046675 /fs | |
parent | 9f7c43c96727a53bea45f7f2549d897f0a6117b8 (diff) |
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/ctree.h | 1 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 6 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 23 |
3 files changed, 30 insertions, 0 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 93a0191aded6..d47ce8307854 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -2234,6 +2234,7 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, | |||
2234 | struct btrfs_root *root, u64 type); | 2234 | struct btrfs_root *root, u64 type); |
2235 | int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range); | 2235 | int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range); |
2236 | 2236 | ||
2237 | int btrfs_init_space_info(struct btrfs_fs_info *fs_info); | ||
2237 | /* ctree.c */ | 2238 | /* ctree.c */ |
2238 | int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, | 2239 | int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, |
2239 | int level, int *slot); | 2240 | int level, int *slot); |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8ecc5419d8b6..b3fc8475870f 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -2065,6 +2065,12 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
2065 | fs_info->metadata_alloc_profile = (u64)-1; | 2065 | fs_info->metadata_alloc_profile = (u64)-1; |
2066 | fs_info->system_alloc_profile = fs_info->metadata_alloc_profile; | 2066 | fs_info->system_alloc_profile = fs_info->metadata_alloc_profile; |
2067 | 2067 | ||
2068 | ret = btrfs_init_space_info(fs_info); | ||
2069 | if (ret) { | ||
2070 | printk(KERN_ERR "Failed to initial space info: %d\n", ret); | ||
2071 | goto fail_block_groups; | ||
2072 | } | ||
2073 | |||
2068 | ret = btrfs_read_block_groups(extent_root); | 2074 | ret = btrfs_read_block_groups(extent_root); |
2069 | if (ret) { | 2075 | if (ret) { |
2070 | printk(KERN_ERR "Failed to read block groups: %d\n", ret); | 2076 | printk(KERN_ERR "Failed to read block groups: %d\n", ret); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a561060f5ffb..f619c3cb13b7 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -8778,6 +8778,29 @@ out: | |||
8778 | return ret; | 8778 | return ret; |
8779 | } | 8779 | } |
8780 | 8780 | ||
8781 | int btrfs_init_space_info(struct btrfs_fs_info *fs_info) | ||
8782 | { | ||
8783 | struct btrfs_space_info *space_info; | ||
8784 | int ret; | ||
8785 | |||
8786 | ret = update_space_info(fs_info, BTRFS_BLOCK_GROUP_SYSTEM, 0, 0, | ||
8787 | &space_info); | ||
8788 | if (ret) | ||
8789 | return ret; | ||
8790 | |||
8791 | ret = update_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA, 0, 0, | ||
8792 | &space_info); | ||
8793 | if (ret) | ||
8794 | return ret; | ||
8795 | |||
8796 | ret = update_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA, 0, 0, | ||
8797 | &space_info); | ||
8798 | if (ret) | ||
8799 | return ret; | ||
8800 | |||
8801 | return ret; | ||
8802 | } | ||
8803 | |||
8781 | int btrfs_error_unpin_extent_range(struct btrfs_root *root, u64 start, u64 end) | 8804 | int btrfs_error_unpin_extent_range(struct btrfs_root *root, u64 start, u64 end) |
8782 | { | 8805 | { |
8783 | return unpin_extent_range(root, start, end); | 8806 | return unpin_extent_range(root, start, end); |