Skip to content

Commit 58f7581

Browse files
Sun YangKaikdave
authored andcommitted
btrfs: remove partial support for lowest level from btrfs_search_forward()
Commit 323ac95 ("Btrfs: don't read leaf blocks containing only checksums during truncate") changed the condition from `level == 0` to `level == path->lowest_level`, while its original purpose is just to do some leaf node handling (calling btrfs_item_key_to_cpu()) and skip some code that doesn't fit leaf nodes. After changing the condition, the code path: 1. Also handles the non-leaf nodes when path->lowest_level is nonzero, which is wrong. However btrfs_search_forward() is never called with a nonzero path->lowest_level, which makes this bug not found before. 2. Makes the later if block with the same condition, which is originally used to handle non-leaf node (calling btrfs_node_key_to_cpu()) when lowest_level is not zero, dead code. Since btrfs_search_forward() is never called for a path with a lowest_level different from zero, just completely remove the partial support for a non-zero lowest_level, simplifying a bit the code, and assert that lowest_level is zero at the start of the function. Suggested-by: Qu Wenruo <wqu@suse.com> Fixes: 323ac95 ("Btrfs: don't read leaf blocks containing only checksums during truncate") Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Sun YangKai <sunk67188@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3cc4f7e commit 58f7581

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

fs/btrfs/ctree.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4594,16 +4594,13 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
45944594

45954595
/*
45964596
* A helper function to walk down the tree starting at min_key, and looking
4597-
* for nodes or leaves that are have a minimum transaction id.
4597+
* for leaves that have a minimum transaction id.
45984598
* This is used by the btree defrag code, and tree logging
45994599
*
46004600
* This does not cow, but it does stuff the starting key it finds back
46014601
* into min_key, so you can call btrfs_search_slot with cow=1 on the
46024602
* key and get a writable path.
46034603
*
4604-
* This honors path->lowest_level to prevent descent past a given level
4605-
* of the tree.
4606-
*
46074604
* min_trans indicates the oldest transaction that you are interested
46084605
* in walking through. Any nodes or leaves older than min_trans are
46094606
* skipped over (without reading them).
@@ -4624,6 +4621,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
46244621
int keep_locks = path->keep_locks;
46254622

46264623
ASSERT(!path->nowait);
4624+
ASSERT(path->lowest_level == 0);
46274625
path->keep_locks = 1;
46284626
again:
46294627
cur = btrfs_read_lock_root_node(root);
@@ -4645,8 +4643,8 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
46454643
goto out;
46464644
}
46474645

4648-
/* at the lowest level, we're done, setup the path and exit */
4649-
if (level == path->lowest_level) {
4646+
/* At level 0 we're done, setup the path and exit. */
4647+
if (level == 0) {
46504648
if (slot >= nritems)
46514649
goto find_next_key;
46524650
ret = 0;
@@ -4687,12 +4685,6 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
46874685
goto out;
46884686
}
46894687
}
4690-
if (level == path->lowest_level) {
4691-
ret = 0;
4692-
/* Save our key for returning back. */
4693-
btrfs_node_key_to_cpu(cur, min_key, slot);
4694-
goto out;
4695-
}
46964688
cur = btrfs_read_node_slot(cur, slot);
46974689
if (IS_ERR(cur)) {
46984690
ret = PTR_ERR(cur);
@@ -4708,7 +4700,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
47084700
out:
47094701
path->keep_locks = keep_locks;
47104702
if (ret == 0)
4711-
btrfs_unlock_up_safe(path, path->lowest_level + 1);
4703+
btrfs_unlock_up_safe(path, 1);
47124704
return ret;
47134705
}
47144706

0 commit comments

Comments
 (0)