btrfs-progs: check/lowmem: Fix false alert of data extent backref lost for snapshot
[platform/upstream/btrfs-progs.git] / chunk-recover.c
index 08d2f07..705bcf5 100644 (file)
@@ -451,24 +451,6 @@ static void print_device_extent_tree(struct device_extent_tree *tree)
        printf("\n");
 }
 
-static void print_device_info(struct btrfs_device *device, char *prefix)
-{
-       if (prefix)
-               printf("%s", prefix);
-       printf("Device: id = %llu, name = %s\n",
-              device->devid, device->name);
-}
-
-static void print_all_devices(struct list_head *devices)
-{
-       struct btrfs_device *dev;
-
-       printf("All Devices:\n");
-       list_for_each_entry(dev, devices, dev_list)
-               print_device_info(dev, "\t");
-       printf("\n");
-}
-
 static void print_scan_result(struct recover_control *rc)
 {
        if (!rc->verbose)
@@ -942,11 +924,12 @@ static int build_device_map_by_chunk_record(struct btrfs_root *root,
        u64 devid;
        u8 uuid[BTRFS_UUID_SIZE];
        u16 num_stripes;
+       struct btrfs_fs_info *fs_info = root->fs_info;
        struct btrfs_mapping_tree *map_tree;
        struct map_lookup *map;
        struct stripe *stripe;
 
-       map_tree = &root->fs_info->mapping_tree;
+       map_tree = &fs_info->mapping_tree;
        num_stripes = chunk->num_stripes;
        map = malloc(btrfs_map_lookup_size(num_stripes));
        if (!map)
@@ -965,7 +948,7 @@ static int build_device_map_by_chunk_record(struct btrfs_root *root,
                devid = stripe->devid;
                memcpy(uuid, stripe->dev_uuid, BTRFS_UUID_SIZE);
                map->stripes[i].physical = stripe->offset;
-               map->stripes[i].dev = btrfs_find_device(root, devid,
+               map->stripes[i].dev = btrfs_find_device(fs_info, devid,
                                                        uuid, NULL);
                if (!map->stripes[i].dev) {
                        free(map);
@@ -1286,13 +1269,14 @@ static int rebuild_chunk_tree(struct btrfs_trans_handle *trans,
 static int rebuild_sys_array(struct recover_control *rc,
                             struct btrfs_root *root)
 {
+       struct btrfs_fs_info *fs_info = root->fs_info;
        struct btrfs_chunk *chunk;
        struct btrfs_key key;
        struct chunk_record *chunk_rec;
        int ret = 0;
        u16 num_stripes;
 
-       btrfs_set_super_sys_array_size(root->fs_info->super_copy, 0);
+       btrfs_set_super_sys_array_size(fs_info->super_copy, 0);
 
        list_for_each_entry(chunk_rec, &rc->good_chunks, list) {
                if (!(chunk_rec->type_flags & BTRFS_BLOCK_GROUP_SYSTEM))
@@ -1309,7 +1293,7 @@ static int rebuild_sys_array(struct recover_control *rc,
                key.type = BTRFS_CHUNK_ITEM_KEY;
                key.offset = chunk_rec->offset;
 
-               ret = btrfs_add_system_chunk(root, &key, chunk,
+               ret = btrfs_add_system_chunk(fs_info, &key, chunk,
                                btrfs_chunk_item_size(num_stripes));
                free(chunk);
                if (ret)
@@ -2387,6 +2371,7 @@ int btrfs_recover_chunk_tree(char *path, int verbose, int yes)
        }
 
        trans = btrfs_start_transaction(root, 1);
+       BUG_ON(IS_ERR(trans));
        ret = remove_chunk_extent_item(trans, &rc, root);
        BUG_ON(ret);