Commit fa6ac715 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: relocation: Add basic extent backref related comments for build_backref_tree

fs/btrfs/relocation.c:build_backref_tree() is some code from 2009 era,
although it works pretty fine, it's not that easy to understand.
Especially combined with the complex btrfs backref format.

This patch adds some basic comment for the backref build part of the
code, making it less hard to read, at least for backref searching part.
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 4779cc04
...@@ -648,8 +648,8 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -648,8 +648,8 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
int level, u64 bytenr) int level, u64 bytenr)
{ {
struct backref_cache *cache = &rc->backref_cache; struct backref_cache *cache = &rc->backref_cache;
struct btrfs_path *path1; struct btrfs_path *path1; /* For searching extent root */
struct btrfs_path *path2; struct btrfs_path *path2; /* For searching parent of TREE_BLOCK_REF */
struct extent_buffer *eb; struct extent_buffer *eb;
struct btrfs_root *root; struct btrfs_root *root;
struct backref_node *cur; struct backref_node *cur;
...@@ -662,7 +662,7 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -662,7 +662,7 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
struct btrfs_key key; struct btrfs_key key;
unsigned long end; unsigned long end;
unsigned long ptr; unsigned long ptr;
LIST_HEAD(list); LIST_HEAD(list); /* Pending edge list, upper node needs to be checked */
LIST_HEAD(useless); LIST_HEAD(useless);
int cowonly; int cowonly;
int ret; int ret;
...@@ -778,6 +778,10 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -778,6 +778,10 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
key.type != BTRFS_SHARED_BLOCK_REF_KEY); key.type != BTRFS_SHARED_BLOCK_REF_KEY);
} }
/*
* Parent node found and matches current inline ref, no need to
* rebuild this node for this inline ref.
*/
if (exist && if (exist &&
((key.type == BTRFS_TREE_BLOCK_REF_KEY && ((key.type == BTRFS_TREE_BLOCK_REF_KEY &&
exist->owner == key.offset) || exist->owner == key.offset) ||
...@@ -787,11 +791,12 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -787,11 +791,12 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
goto next; goto next;
} }
/* SHARED_BLOCK_REF means key.offset is the parent bytenr */
if (key.type == BTRFS_SHARED_BLOCK_REF_KEY) { if (key.type == BTRFS_SHARED_BLOCK_REF_KEY) {
if (key.objectid == key.offset) { if (key.objectid == key.offset) {
/* /*
* only root blocks of reloc trees use * Only root blocks of reloc trees use backref
* backref of this type. * pointing to itself.
*/ */
root = find_reloc_root(rc, cur->bytenr); root = find_reloc_root(rc, cur->bytenr);
ASSERT(root); ASSERT(root);
...@@ -840,7 +845,11 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -840,7 +845,11 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
goto next; goto next;
} }
/* key.type == BTRFS_TREE_BLOCK_REF_KEY */ /*
* key.type == BTRFS_TREE_BLOCK_REF_KEY, inline ref offset
* means the root objectid. We need to search the tree to get
* its parent bytenr.
*/
root = read_fs_root(rc->extent_root->fs_info, key.offset); root = read_fs_root(rc->extent_root->fs_info, key.offset);
if (IS_ERR(root)) { if (IS_ERR(root)) {
err = PTR_ERR(root); err = PTR_ERR(root);
...@@ -863,10 +872,7 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -863,10 +872,7 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
level = cur->level + 1; level = cur->level + 1;
/* /* Search the tree to find parent blocks referring the block. */
* searching the tree to find upper level blocks
* reference the block.
*/
path2->search_commit_root = 1; path2->search_commit_root = 1;
path2->skip_locking = 1; path2->skip_locking = 1;
path2->lowest_level = level; path2->lowest_level = level;
...@@ -893,6 +899,8 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -893,6 +899,8 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
} }
lower = cur; lower = cur;
need_check = true; need_check = true;
/* Add all nodes and edges in the path */
for (; level < BTRFS_MAX_LEVEL; level++) { for (; level < BTRFS_MAX_LEVEL; level++) {
if (!path2->nodes[level]) { if (!path2->nodes[level]) {
ASSERT(btrfs_root_bytenr(&root->root_item) == ASSERT(btrfs_root_bytenr(&root->root_item) ==
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment