Btrfs-progs: chunk-recover: add new flag to prepare recovering for ordered data chunk
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>
Thu, 28 Nov 2013 05:32:49 +0000 (13:32 +0800)
committerChris Mason <clm@fb.com>
Fri, 31 Jan 2014 16:22:07 +0000 (08:22 -0800)
When reading block groups we will searching it's corresponding chunk, however, at this
time, some chunks has not been built(data chunks raid0/raid10/raid56), don't bug_on here,
we will try to rebuild these chunks later.

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>
chunk-recover.c
ctree.h
volumes.c

index e880bbc..ae0d318 100644 (file)
@@ -1197,6 +1197,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
                fprintf(stderr, "Failed to allocate memory for fs_info\n");
                return ERR_PTR(-ENOMEM);
        }
+       fs_info->is_chunk_recover = 1;
 
        fs_info->fs_devices = rc->fs_devices;
        ret = btrfs_open_devices(fs_info->fs_devices, O_RDWR);
diff --git a/ctree.h b/ctree.h
index 187026c..6d10184 100644 (file)
--- a/ctree.h
+++ b/ctree.h
@@ -973,6 +973,7 @@ struct btrfs_fs_info {
        int system_allocs;
        int readonly;
        int on_restoring;
+       int is_chunk_recover;
        int (*free_extent_hook)(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root,
                                u64 bytenr, u64 num_bytes, u64 parent,
index c38da6c..bd01270 100644 (file)
--- a/volumes.c
+++ b/volumes.c
@@ -1496,8 +1496,15 @@ int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset)
        int readonly = 0;
        int i;
 
+       /*
+        * During chunk recovering, we may fail to find block group's
+        * corresponding chunk, we will rebuild it later
+        */
        ce = search_cache_extent(&map_tree->cache_tree, chunk_offset);
-       BUG_ON(!ce);
+       if (!root->fs_info->is_chunk_recover)
+               BUG_ON(!ce);
+       else
+               return 0;
 
        map = container_of(ce, struct map_lookup, ce);
        for (i = 0; i < map->num_stripes; i++) {