Btrfs-progs: fsck: deal with really corrupted extent tree
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>
Thu, 6 Mar 2014 05:53:56 +0000 (13:53 +0800)
committerChris Mason <clm@fb.com>
Fri, 21 Mar 2014 13:23:34 +0000 (06:23 -0700)
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 <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
cmds-check.c

index 98199ce..3cf59b6 100644 (file)
@@ -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;