X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=qgroup-verify.c;h=571b4d4f7171053755fc102da37852f253674429;hb=905b3d18ae118931839b0a1ece17870073b51484;hp=df0e5474a77c10e4e6a41de2f89d101bb256c5fb;hpb=d89205c4a5304572d8b6e67cee25594d4baaedee;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/qgroup-verify.c b/qgroup-verify.c index df0e547..571b4d4 100644 --- a/qgroup-verify.c +++ b/qgroup-verify.c @@ -27,7 +27,7 @@ #include "disk-io.h" #include "print-tree.h" #include "utils.h" -#include "ulist.h" +#include "kernel-shared/ulist.h" #include "rbtree-utils.h" #include "transaction.h" #include "repair.h" @@ -369,6 +369,11 @@ static int find_parent_roots(struct ulist *roots, u64 parent) if (ret < 0) goto out; } + } else if (ref->parent == ref->bytenr) { + /* + * Special loop case for tree reloc tree + */ + ref->root = BTRFS_TREE_RELOC_OBJECTID; } else { ret = find_parent_roots(roots, ref->parent); if (ret < 0) @@ -578,6 +583,8 @@ static u64 resolve_one_root(u64 bytenr) if (ref->root) return ref->root; + if (ref->parent == bytenr) + return BTRFS_TREE_RELOC_OBJECTID; return resolve_one_root(ref->parent); } @@ -704,7 +711,7 @@ static int travel_tree(struct btrfs_fs_info *info, struct btrfs_root *root, // printf("travel_tree: bytenr: %llu\tnum_bytes: %llu\tref_parent: %llu\n", // bytenr, num_bytes, ref_parent); - eb = read_tree_block(root, bytenr, num_bytes, 0); + eb = read_tree_block(info, bytenr, 0); if (!extent_buffer_uptodate(eb)) return -EIO; @@ -729,7 +736,7 @@ static int travel_tree(struct btrfs_fs_info *info, struct btrfs_root *root, nr = btrfs_header_nritems(eb); for (i = 0; i < nr; i++) { new_bytenr = btrfs_node_blockptr(eb, i); - new_num_bytes = root->nodesize; + new_num_bytes = info->nodesize; ret = travel_tree(info, root, new_bytenr, new_num_bytes, ref_parent); @@ -748,6 +755,9 @@ static int add_refs_for_implied(struct btrfs_fs_info *info, u64 bytenr, struct btrfs_root *root; struct btrfs_key key; + /* Tree reloc tree doesn't contribute qgroup, skip it */ + if (root_id == BTRFS_TREE_RELOC_OBJECTID) + return 0; key.objectid = root_id; key.type = BTRFS_ROOT_ITEM_KEY; key.offset = (u64)-1; @@ -1175,7 +1185,7 @@ static int scan_extents(struct btrfs_fs_info *info, bytenr = key.objectid; num_bytes = key.offset; if (key.type == BTRFS_METADATA_ITEM_KEY) { - num_bytes = info->extent_root->nodesize; + num_bytes = info->nodesize; meta = 1; } @@ -1469,29 +1479,24 @@ static int repair_qgroup_info(struct btrfs_fs_info *info, int ret; struct btrfs_root *root = info->quota_root; struct btrfs_trans_handle *trans; - struct btrfs_path *path; + struct btrfs_path path; struct btrfs_qgroup_info_item *info_item; struct btrfs_key key; printf("Repair qgroup %llu/%llu\n", btrfs_qgroup_level(count->qgroupid), btrfs_qgroup_subvid(count->qgroupid)); - path = btrfs_alloc_path(); - if (!path) - return -ENOMEM; - trans = btrfs_start_transaction(root, 1); - if (IS_ERR(trans)) { - btrfs_free_path(path); + if (IS_ERR(trans)) return PTR_ERR(trans); - } + btrfs_init_path(&path); key.objectid = 0; key.type = BTRFS_QGROUP_INFO_KEY; key.offset = count->qgroupid; - ret = btrfs_search_slot(trans, root, &key, path, 0, 1); + ret = btrfs_search_slot(trans, root, &key, &path, 0, 1); if (ret) { - error("Could not find disk item for qgroup %llu/%llu.\n", + error("could not find disk item for qgroup %llu/%llu", btrfs_qgroup_level(count->qgroupid), btrfs_qgroup_subvid(count->qgroupid)); if (ret > 0) @@ -1499,27 +1504,27 @@ static int repair_qgroup_info(struct btrfs_fs_info *info, goto out; } - info_item = btrfs_item_ptr(path->nodes[0], path->slots[0], + info_item = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_qgroup_info_item); - btrfs_set_qgroup_info_generation(path->nodes[0], info_item, + btrfs_set_qgroup_info_generation(path.nodes[0], info_item, trans->transid); - btrfs_set_qgroup_info_referenced(path->nodes[0], info_item, + btrfs_set_qgroup_info_referenced(path.nodes[0], info_item, count->info.referenced); - btrfs_set_qgroup_info_referenced_compressed(path->nodes[0], info_item, + btrfs_set_qgroup_info_referenced_compressed(path.nodes[0], info_item, count->info.referenced_compressed); - btrfs_set_qgroup_info_exclusive(path->nodes[0], info_item, + btrfs_set_qgroup_info_exclusive(path.nodes[0], info_item, count->info.exclusive); - btrfs_set_qgroup_info_exclusive_compressed(path->nodes[0], info_item, + btrfs_set_qgroup_info_exclusive_compressed(path.nodes[0], info_item, count->info.exclusive_compressed); - btrfs_mark_buffer_dirty(path->nodes[0]); + btrfs_mark_buffer_dirty(path.nodes[0]); out: btrfs_commit_transaction(trans, root); - btrfs_free_path(path); + btrfs_release_path(&path); return ret; } @@ -1529,53 +1534,48 @@ static int repair_qgroup_status(struct btrfs_fs_info *info) int ret; struct btrfs_root *root = info->quota_root; struct btrfs_trans_handle *trans; - struct btrfs_path *path; + struct btrfs_path path; struct btrfs_key key; struct btrfs_qgroup_status_item *status_item; printf("Repair qgroup status item\n"); - path = btrfs_alloc_path(); - if (!path) - return -ENOMEM; - trans = btrfs_start_transaction(root, 1); - if (IS_ERR(trans)) { - btrfs_free_path(path); + if (IS_ERR(trans)) return PTR_ERR(trans); - } + btrfs_init_path(&path); key.objectid = 0; key.type = BTRFS_QGROUP_STATUS_KEY; key.offset = 0; - ret = btrfs_search_slot(trans, root, &key, path, 0, 1); + ret = btrfs_search_slot(trans, root, &key, &path, 0, 1); if (ret) { - error("Could not find qgroup status item\n"); + error("could not find qgroup status item"); if (ret > 0) ret = -ENOENT; goto out; } - status_item = btrfs_item_ptr(path->nodes[0], path->slots[0], + status_item = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_qgroup_status_item); - btrfs_set_qgroup_status_flags(path->nodes[0], status_item, + btrfs_set_qgroup_status_flags(path.nodes[0], status_item, BTRFS_QGROUP_STATUS_FLAG_ON); - btrfs_set_qgroup_status_rescan(path->nodes[0], status_item, 0); - btrfs_set_qgroup_status_generation(path->nodes[0], status_item, + btrfs_set_qgroup_status_rescan(path.nodes[0], status_item, 0); + btrfs_set_qgroup_status_generation(path.nodes[0], status_item, trans->transid); - btrfs_mark_buffer_dirty(path->nodes[0]); + btrfs_mark_buffer_dirty(path.nodes[0]); out: btrfs_commit_transaction(trans, root); - btrfs_free_path(path); + btrfs_release_path(&path); return ret; } int repair_qgroups(struct btrfs_fs_info *info, int *repaired) { - int ret; + int ret = 0; struct qgroup_count *count, *tmpcount; *repaired = 0;