X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=chunk-recover.c;h=e6b26ac3aa8add50c3ab49835d40a1d48c30020c;hb=52bfe9ef78fdf6c1f1c5ceb3f7a8bf8bf2164775;hp=d1e6c38631d0002f1a6be767ec3a185c8bad3f60;hpb=ff9ee51677818b7e6ea5caacb03dbbc45f5be706;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/chunk-recover.c b/chunk-recover.c index d1e6c38..e6b26ac 100644 --- a/chunk-recover.c +++ b/chunk-recover.c @@ -1398,26 +1398,24 @@ static int rebuild_block_group(struct btrfs_trans_handle *trans, { struct chunk_record *chunk_rec; struct btrfs_key search_key; - struct btrfs_path *path; + struct btrfs_path path; u64 used = 0; int ret = 0; if (list_empty(&rc->rebuild_chunks)) return 0; - path = btrfs_alloc_path(); - if (!path) - return -ENOMEM; + btrfs_init_path(&path); list_for_each_entry(chunk_rec, &rc->rebuild_chunks, list) { search_key.objectid = chunk_rec->offset; search_key.type = BTRFS_EXTENT_ITEM_KEY; search_key.offset = 0; ret = btrfs_search_slot(NULL, root->fs_info->extent_root, - &search_key, path, 0, 0); + &search_key, &path, 0, 0); if (ret < 0) goto out; ret = calculate_bg_used(root->fs_info->extent_root, - chunk_rec, path, &used); + chunk_rec, &path, &used); /* * Extent tree is damaged, better to rebuild the whole extent * tree. Currently, change the used to chunk's len to prevent @@ -1432,7 +1430,7 @@ static int rebuild_block_group(struct btrfs_trans_handle *trans, "Mark the block group full to prevent block rsv problems\n"); used = chunk_rec->length; } - btrfs_release_path(path); + btrfs_release_path(&path); ret = __insert_block_group(trans, chunk_rec, root->fs_info->extent_root, used); @@ -1440,7 +1438,7 @@ static int rebuild_block_group(struct btrfs_trans_handle *trans, goto out; } out: - btrfs_free_path(path); + btrfs_release_path(&path); return ret; } @@ -1479,7 +1477,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc) memcpy(fs_info->fsid, &disk_super->fsid, BTRFS_FSID_SIZE); - ret = btrfs_check_fs_compatibility(disk_super, 1); + ret = btrfs_check_fs_compatibility(disk_super, OPEN_CTREE_WRITES); if (ret) goto out_devices; @@ -1488,7 +1486,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc) sectorsize = btrfs_super_sectorsize(disk_super); stripesize = btrfs_super_stripesize(disk_super); - __setup_root(nodesize, leafsize, sectorsize, stripesize, + btrfs_setup_root(nodesize, leafsize, sectorsize, stripesize, fs_info->chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID); ret = build_device_maps_by_chunk_records(rc, fs_info->chunk_root); @@ -2250,6 +2248,13 @@ static int btrfs_recover_chunks(struct recover_control *rc) chunk->sub_stripes = calc_sub_nstripes(bg->flags); ret = insert_cache_extent(&rc->chunk, &chunk->cache); + if (ret == -EEXIST) { + error("duplicate entry in cache start %llu size %llu", + (unsigned long long)chunk->cache.start, + (unsigned long long)chunk->cache.size); + free(chunk); + return ret; + } BUG_ON(ret); list_del_init(&bg->list);