Skip to content

Commit d4b4087

Browse files
Josef BacikChris Mason
authored andcommitted
Btrfs: do a full search everytime in btrfs_search_old_slot
While running some snashot aware defrag tests I noticed I was panicing every once and a while in key_search. This is because of the optimization that says if we find a key at slot 0 it will be at slot 0 all the way down the rest of the tree. This isn't the case for btrfs_search_old_slot since it will likely replay changes to a buffer if something has changed since we took our sequence number. So short circuit this optimization by setting prev_cmp to -1 every time we call key_search so we will do our normal binary search. With this patch I am no longer seeing the panics I was seeing before. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
1 parent 06ea65a commit d4b4087

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎fs/btrfs/ctree.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key,
27582758
int level;
27592759
int lowest_unlock = 1;
27602760
u8 lowest_level = 0;
2761-
int prev_cmp;
2761+
int prev_cmp = -1;
27622762

27632763
lowest_level = p->lowest_level;
27642764
WARN_ON(p->nodes[0] != NULL);
@@ -2769,7 +2769,6 @@ int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key,
27692769
}
27702770

27712771
again:
2772-
prev_cmp = -1;
27732772
b = get_old_root(root, time_seq);
27742773
level = btrfs_header_level(b);
27752774
p->locks[level] = BTRFS_READ_LOCK;
@@ -2787,6 +2786,11 @@ int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key,
27872786
*/
27882787
btrfs_unlock_up_safe(p, level + 1);
27892788

2789+
/*
2790+
* Since we can unwind eb's we want to do a real search every
2791+
* time.
2792+
*/
2793+
prev_cmp = -1;
27902794
ret = key_search(b, key, level, &prev_cmp, &slot);
27912795

27922796
if (level != 0) {

0 commit comments

Comments
 (0)