X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=chunk-recover.c;h=705bcf52379da4d025f9aeb44a01f859a5cd404b;hb=0dc758d89e8ca57276d224a7efad608281dae5a5;hp=1a880038068c02aa1d74a9e25ccf84072f83b092;hpb=c4893f15cedc59c14656b06b83bb5c8a441efe66;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/chunk-recover.c b/chunk-recover.c index 1a88003..705bcf5 100644 --- a/chunk-recover.c +++ b/chunk-recover.c @@ -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); @@ -1070,7 +1053,7 @@ again: key.type == BTRFS_METADATA_ITEM_KEY) { old_val = btrfs_super_bytes_used(fs_info->super_copy); if (key.type == BTRFS_METADATA_ITEM_KEY) - old_val += root->nodesize; + old_val += fs_info->nodesize; else old_val += key.offset; btrfs_set_super_bytes_used(fs_info->super_copy, @@ -1086,7 +1069,7 @@ again: if (key.objectid < end) { if (key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { - key.objectid += root->sectorsize; + key.objectid += fs_info->sectorsize; key.type = BTRFS_EXTENT_ITEM_KEY; key.offset = 0; } @@ -1163,7 +1146,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle *trans, btrfs_set_disk_key_type(&disk_key, BTRFS_DEV_ITEM_KEY); btrfs_set_disk_key_offset(&disk_key, min_devid); - cow = btrfs_alloc_free_block(trans, root, root->nodesize, + cow = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize, BTRFS_CHUNK_TREE_OBJECTID, &disk_key, 0, 0, 0); btrfs_set_header_bytenr(cow, cow->start); @@ -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) @@ -1340,7 +1324,7 @@ static int calculate_bg_used(struct btrfs_root *extent_root, found_key.type != BTRFS_EXTENT_DATA_KEY) goto next; if (found_key.type == BTRFS_METADATA_ITEM_KEY) - used_ret += extent_root->nodesize; + used_ret += extent_root->fs_info->nodesize; else used_ret += found_key.offset; next: @@ -1448,9 +1432,6 @@ open_ctree_with_broken_chunk(struct recover_control *rc) struct btrfs_fs_info *fs_info; struct btrfs_super_block *disk_super; struct extent_buffer *eb; - u32 sectorsize; - u32 nodesize; - u32 stripesize; int ret; fs_info = btrfs_new_fs_info(1, BTRFS_SUPER_INFO_OFFSET); @@ -1483,12 +1464,8 @@ open_ctree_with_broken_chunk(struct recover_control *rc) if (ret) goto out_devices; - nodesize = btrfs_super_nodesize(disk_super); - sectorsize = btrfs_super_sectorsize(disk_super); - stripesize = btrfs_super_stripesize(disk_super); - - btrfs_setup_root(nodesize, sectorsize, stripesize, - fs_info->chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID); + btrfs_setup_root(fs_info->chunk_root, fs_info, + BTRFS_CHUNK_TREE_OBJECTID); ret = build_device_maps_by_chunk_records(rc, fs_info->chunk_root); if (ret) @@ -1840,7 +1817,7 @@ static int next_csum(struct btrfs_root *root, int ret = 0; struct btrfs_root *csum_root = root->fs_info->csum_root; struct btrfs_csum_item *csum_item; - u32 blocksize = root->sectorsize; + u32 blocksize = root->fs_info->sectorsize; u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); int csums_in_item = btrfs_item_size_nr(*leaf, *slot) / csum_size; @@ -1923,7 +1900,7 @@ out: static u64 item_end_offset(struct btrfs_root *root, struct btrfs_key *key, struct extent_buffer *leaf, int slot) { - u32 blocksize = root->sectorsize; + u32 blocksize = root->fs_info->sectorsize; u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); u64 offset = btrfs_item_size_nr(leaf, slot); @@ -2013,7 +1990,7 @@ static int rebuild_raid_data_chunk_stripes(struct recover_control *rc, u64 chunk_end = chunk->offset + chunk->length; u64 csum_offset = 0; u64 data_offset; - u32 blocksize = root->sectorsize; + u32 blocksize = root->fs_info->sectorsize; u32 tree_csum; int index = 0; int num_unordered = 0; @@ -2394,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);