Skip to content

Commit 9f6dec4

Browse files
Qu Wenruokdave
authored andcommitted
btrfs-progs: Refactor read_node_slot function to get rid of btrfs_root
parameter Signed-off-by: Qu Wenruo <[email protected]>
1 parent 8690c88 commit 9f6dec4

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

cmds-restore.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ static int next_leaf(struct btrfs_root *root, struct btrfs_path *path)
181181
int offset = 1;
182182
struct extent_buffer *c;
183183
struct extent_buffer *next = NULL;
184+
struct btrfs_fs_info *fs_info = root->fs_info;
184185

185186
again:
186187
for (; level < BTRFS_MAX_LEVEL; level++) {
@@ -210,7 +211,7 @@ static int next_leaf(struct btrfs_root *root, struct btrfs_path *path)
210211
if (path->reada)
211212
reada_for_search(root, path, level, slot, 0);
212213

213-
next = read_node_slot(root, c, slot);
214+
next = read_node_slot(fs_info, c, slot);
214215
if (extent_buffer_uptodate(next))
215216
break;
216217
offset++;
@@ -226,7 +227,7 @@ static int next_leaf(struct btrfs_root *root, struct btrfs_path *path)
226227
break;
227228
if (path->reada)
228229
reada_for_search(root, path, level, 0, 0);
229-
next = read_node_slot(root, next, 0);
230+
next = read_node_slot(fs_info, next, 0);
230231
if (!extent_buffer_uptodate(next))
231232
goto again;
232233
}

ctree.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static int bin_search(struct extent_buffer *eb, struct btrfs_key *key,
637637
slot);
638638
}
639639

640-
struct extent_buffer *read_node_slot(struct btrfs_root *root,
640+
struct extent_buffer *read_node_slot(struct btrfs_fs_info *fs_info,
641641
struct extent_buffer *parent, int slot)
642642
{
643643
int level = btrfs_header_level(parent);
@@ -649,8 +649,8 @@ struct extent_buffer *read_node_slot(struct btrfs_root *root,
649649
if (level == 0)
650650
return NULL;
651651

652-
return read_tree_block(root->fs_info, btrfs_node_blockptr(parent, slot),
653-
root->fs_info->nodesize,
652+
return read_tree_block(fs_info, btrfs_node_blockptr(parent, slot),
653+
fs_info->nodesize,
654654
btrfs_node_ptr_generation(parent, slot));
655655
}
656656

@@ -662,6 +662,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
662662
struct extent_buffer *mid;
663663
struct extent_buffer *left = NULL;
664664
struct extent_buffer *parent = NULL;
665+
struct btrfs_fs_info *fs_info = root->fs_info;
665666
int ret = 0;
666667
int wret;
667668
int pslot;
@@ -692,7 +693,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
692693
return 0;
693694

694695
/* promote the child to a root */
695-
child = read_node_slot(root, mid, 0);
696+
child = read_node_slot(fs_info, mid, 0);
696697
BUG_ON(!extent_buffer_uptodate(child));
697698
ret = btrfs_cow_block(trans, root, child, mid, 0, &child);
698699
BUG_ON(ret);
@@ -715,7 +716,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
715716
BTRFS_NODEPTRS_PER_BLOCK(root) / 4)
716717
return 0;
717718

718-
left = read_node_slot(root, parent, pslot - 1);
719+
left = read_node_slot(fs_info, parent, pslot - 1);
719720
if (extent_buffer_uptodate(left)) {
720721
wret = btrfs_cow_block(trans, root, left,
721722
parent, pslot - 1, &left);
@@ -724,7 +725,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
724725
goto enospc;
725726
}
726727
}
727-
right = read_node_slot(root, parent, pslot + 1);
728+
right = read_node_slot(fs_info, parent, pslot + 1);
728729
if (extent_buffer_uptodate(right)) {
729730
wret = btrfs_cow_block(trans, root, right,
730731
parent, pslot + 1, &right);
@@ -854,6 +855,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans,
854855
struct extent_buffer *mid;
855856
struct extent_buffer *left = NULL;
856857
struct extent_buffer *parent = NULL;
858+
struct btrfs_fs_info *fs_info = root->fs_info;
857859
int ret = 0;
858860
int wret;
859861
int pslot;
@@ -873,7 +875,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans,
873875
if (!parent)
874876
return 1;
875877

876-
left = read_node_slot(root, parent, pslot - 1);
878+
left = read_node_slot(fs_info, parent, pslot - 1);
877879

878880
/* first, try to make some room in the middle buffer */
879881
if (extent_buffer_uptodate(left)) {
@@ -914,7 +916,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans,
914916
}
915917
free_extent_buffer(left);
916918
}
917-
right= read_node_slot(root, parent, pslot + 1);
919+
right= read_node_slot(fs_info, parent, pslot + 1);
918920

919921
/*
920922
* then try to empty the right most buffer into the middle
@@ -1102,6 +1104,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
11021104
int ret;
11031105
int level;
11041106
int should_reada = p->reada;
1107+
struct btrfs_fs_info *fs_info = root->fs_info;
11051108
u8 lowest_level = 0;
11061109

11071110
lowest_level = p->lowest_level;
@@ -1169,7 +1172,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
11691172
reada_for_search(root, p, level, slot,
11701173
key->objectid);
11711174

1172-
b = read_node_slot(root, b, slot);
1175+
b = read_node_slot(fs_info, b, slot);
11731176
if (!extent_buffer_uptodate(b))
11741177
return -EIO;
11751178
} else {
@@ -1644,6 +1647,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
16441647
struct extent_buffer *right;
16451648
struct extent_buffer *upper;
16461649
struct btrfs_disk_key disk_key;
1650+
struct btrfs_fs_info *fs_info = root->fs_info;
16471651
int slot;
16481652
u32 i;
16491653
int free_space;
@@ -1665,7 +1669,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
16651669
if (slot >= btrfs_header_nritems(upper) - 1)
16661670
return 1;
16671671

1668-
right = read_node_slot(root, upper, slot + 1);
1672+
right = read_node_slot(fs_info, upper, slot + 1);
16691673
if (!extent_buffer_uptodate(right)) {
16701674
if (IS_ERR(right))
16711675
return PTR_ERR(right);
@@ -1797,6 +1801,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
17971801
struct btrfs_disk_key disk_key;
17981802
struct extent_buffer *right = path->nodes[0];
17991803
struct extent_buffer *left;
1804+
struct btrfs_fs_info *fs_info = root->fs_info;
18001805
int slot;
18011806
int i;
18021807
int free_space;
@@ -1821,7 +1826,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
18211826
return 1;
18221827
}
18231828

1824-
left = read_node_slot(root, path->nodes[1], slot - 1);
1829+
left = read_node_slot(fs_info, path->nodes[1], slot - 1);
18251830
free_space = btrfs_leaf_free_space(root, left);
18261831
if (free_space < data_size) {
18271832
free_extent_buffer(left);
@@ -2770,6 +2775,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
27702775
int level = 1;
27712776
struct extent_buffer *c;
27722777
struct extent_buffer *next = NULL;
2778+
struct btrfs_fs_info *fs_info = root->fs_info;
27732779

27742780
while(level < BTRFS_MAX_LEVEL) {
27752781
if (!path->nodes[level])
@@ -2785,7 +2791,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
27852791
}
27862792
slot--;
27872793

2788-
next = read_node_slot(root, c, slot);
2794+
next = read_node_slot(fs_info, c, slot);
27892795
if (!extent_buffer_uptodate(next)) {
27902796
if (IS_ERR(next))
27912797
return PTR_ERR(next);
@@ -2805,7 +2811,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
28052811
path->slots[level] = slot;
28062812
if (!level)
28072813
break;
2808-
next = read_node_slot(root, next, slot);
2814+
next = read_node_slot(fs_info, next, slot);
28092815
if (!extent_buffer_uptodate(next)) {
28102816
if (IS_ERR(next))
28112817
return PTR_ERR(next);
@@ -2826,6 +2832,7 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
28262832
int level = 1;
28272833
struct extent_buffer *c;
28282834
struct extent_buffer *next = NULL;
2835+
struct btrfs_fs_info *fs_info = root->fs_info;
28292836

28302837
while(level < BTRFS_MAX_LEVEL) {
28312838
if (!path->nodes[level])
@@ -2843,7 +2850,7 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
28432850
if (path->reada)
28442851
reada_for_search(root, path, level, slot, 0);
28452852

2846-
next = read_node_slot(root, c, slot);
2853+
next = read_node_slot(fs_info, c, slot);
28472854
if (!extent_buffer_uptodate(next))
28482855
return -EIO;
28492856
break;
@@ -2859,7 +2866,7 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
28592866
break;
28602867
if (path->reada)
28612868
reada_for_search(root, path, level, 0, 0);
2862-
next = read_node_slot(root, next, 0);
2869+
next = read_node_slot(fs_info, next, 0);
28632870
if (!extent_buffer_uptodate(next))
28642871
return -EIO;
28652872
}

ctree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ btrfs_check_leaf(struct btrfs_root *root, struct btrfs_disk_key *parent_key,
25332533
struct extent_buffer *buf);
25342534
void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
25352535
int level, int slot, u64 objectid);
2536-
struct extent_buffer *read_node_slot(struct btrfs_root *root,
2536+
struct extent_buffer *read_node_slot(struct btrfs_fs_info *fs_info,
25372537
struct extent_buffer *parent, int slot);
25382538
int btrfs_previous_item(struct btrfs_root *root,
25392539
struct btrfs_path *path, u64 min_objectid,

0 commit comments

Comments
 (0)