From bedef66c0b8e1ded5aad6366b648f72d09e080d2 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Thu, 6 Mar 2014 13:53:56 +0800 Subject: Btrfs-progs: fsck: deal with really corrupted extent tree To reinit extent root, we need find a free extent, however, we may have a really corrupted extent tree, so we can't rely on existed extent tree to cache block group any more. During test, we fail to reinit extent tree which is because we can not find a free extent so let's make block group cache ourselves firstly. Signed-off-by: Wang Shilong Signed-off-by: David Sterba Signed-off-by: Chris Mason --- cmds-check.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cmds-check.c') diff --git a/cmds-check.c b/cmds-check.c index 98199ce0..3cf59b61 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -6030,11 +6030,13 @@ static int pin_metadata_blocks(struct btrfs_fs_info *fs_info) static int reset_block_groups(struct btrfs_fs_info *fs_info) { + struct btrfs_block_group_cache *cache; struct btrfs_path *path; struct extent_buffer *leaf; struct btrfs_chunk *chunk; struct btrfs_key key; int ret; + u64 start; path = btrfs_alloc_path(); if (!path) @@ -6085,8 +6087,19 @@ static int reset_block_groups(struct btrfs_fs_info *fs_info) btrfs_chunk_type(leaf, chunk), key.objectid, key.offset, btrfs_chunk_length(leaf, chunk)); + set_extent_dirty(&fs_info->free_space_cache, key.offset, + key.offset + btrfs_chunk_length(leaf, chunk), + GFP_NOFS); path->slots[0]++; } + start = 0; + while (1) { + cache = btrfs_lookup_first_block_group(fs_info, start); + if (!cache) + break; + cache->cached = 1; + start = cache->key.objectid + cache->key.offset; + } btrfs_free_path(path); return 0; -- cgit v1.2.3