aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2018-09-25 02:37:46 -0400
committerDavid Sterba <dsterba@suse.com>2018-10-15 11:23:35 -0400
commitfa6ac71524f206c33accfc12294fd35e17478fe0 (patch)
treeb492ce45628cdf6e4049957e314c86d4b802e206
parent4779cc04248deff676c56ff9f3b2c679388a7d5e (diff)
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: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/relocation.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 87afd3c395bb..a5c5e9b3aceb 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -648,8 +648,8 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
648 int level, u64 bytenr) 648 int level, u64 bytenr)
649{ 649{
650 struct backref_cache *cache = &rc->backref_cache; 650 struct backref_cache *cache = &rc->backref_cache;
651 struct btrfs_path *path1; 651 struct btrfs_path *path1; /* For searching extent root */
652 struct btrfs_path *path2; 652 struct btrfs_path *path2; /* For searching parent of TREE_BLOCK_REF */
653 struct extent_buffer *eb; 653 struct extent_buffer *eb;
654 struct btrfs_root *root; 654 struct btrfs_root *root;
655 struct backref_node *cur; 655 struct backref_node *cur;
@@ -662,7 +662,7 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
662 struct btrfs_key key; 662 struct btrfs_key key;
663 unsigned long end; 663 unsigned long end;
664 unsigned long ptr; 664 unsigned long ptr;
665 LIST_HEAD(list); 665 LIST_HEAD(list); /* Pending edge list, upper node needs to be checked */
666 LIST_HEAD(useless); 666 LIST_HEAD(useless);
667 int cowonly; 667 int cowonly;
668 int ret; 668 int ret;
@@ -778,6 +778,10 @@ again:
778 key.type != BTRFS_SHARED_BLOCK_REF_KEY); 778 key.type != BTRFS_SHARED_BLOCK_REF_KEY);
779 } 779 }
780 780
781 /*
782 * Parent node found and matches current inline ref, no need to
783 * rebuild this node for this inline ref.
784 */
781 if (exist && 785 if (exist &&
782 ((key.type == BTRFS_TREE_BLOCK_REF_KEY && 786 ((key.type == BTRFS_TREE_BLOCK_REF_KEY &&
783 exist->owner == key.offset) || 787 exist->owner == key.offset) ||
@@ -787,11 +791,12 @@ again:
787 goto next; 791 goto next;
788 } 792 }
789 793
794 /* SHARED_BLOCK_REF means key.offset is the parent bytenr */
790 if (key.type == BTRFS_SHARED_BLOCK_REF_KEY) { 795 if (key.type == BTRFS_SHARED_BLOCK_REF_KEY) {
791 if (key.objectid == key.offset) { 796 if (key.objectid == key.offset) {
792 /* 797 /*
793 * only root blocks of reloc trees use 798 * Only root blocks of reloc trees use backref
794 * backref of this type. 799 * pointing to itself.
795 */ 800 */
796 root = find_reloc_root(rc, cur->bytenr); 801 root = find_reloc_root(rc, cur->bytenr);
797 ASSERT(root); 802 ASSERT(root);
@@ -840,7 +845,11 @@ again:
840 goto next; 845 goto next;
841 } 846 }
842 847
843 /* key.type == BTRFS_TREE_BLOCK_REF_KEY */ 848 /*
849 * key.type == BTRFS_TREE_BLOCK_REF_KEY, inline ref offset
850 * means the root objectid. We need to search the tree to get
851 * its parent bytenr.
852 */
844 root = read_fs_root(rc->extent_root->fs_info, key.offset); 853 root = read_fs_root(rc->extent_root->fs_info, key.offset);
845 if (IS_ERR(root)) { 854 if (IS_ERR(root)) {
846 err = PTR_ERR(root); 855 err = PTR_ERR(root);
@@ -863,10 +872,7 @@ again:
863 872
864 level = cur->level + 1; 873 level = cur->level + 1;
865 874
866 /* 875 /* Search the tree to find parent blocks referring the block. */
867 * searching the tree to find upper level blocks
868 * reference the block.
869 */
870 path2->search_commit_root = 1; 876 path2->search_commit_root = 1;
871 path2->skip_locking = 1; 877 path2->skip_locking = 1;
872 path2->lowest_level = level; 878 path2->lowest_level = level;
@@ -893,6 +899,8 @@ again:
893 } 899 }
894 lower = cur; 900 lower = cur;
895 need_check = true; 901 need_check = true;
902
903 /* Add all nodes and edges in the path */
896 for (; level < BTRFS_MAX_LEVEL; level++) { 904 for (; level < BTRFS_MAX_LEVEL; level++) {
897 if (!path2->nodes[level]) { 905 if (!path2->nodes[level]) {
898 ASSERT(btrfs_root_bytenr(&root->root_item) == 906 ASSERT(btrfs_root_bytenr(&root->root_item) ==