Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Josef Bacik and committed by
Chris Mason
d4b4087c 06ea65a3

+6 -2
+6 -2
fs/btrfs/ctree.c
··· 2758 2758 int level; 2759 2759 int lowest_unlock = 1; 2760 2760 u8 lowest_level = 0; 2761 - int prev_cmp; 2761 + int prev_cmp = -1; 2762 2762 2763 2763 lowest_level = p->lowest_level; 2764 2764 WARN_ON(p->nodes[0] != NULL); ··· 2769 2769 } 2770 2770 2771 2771 again: 2772 - prev_cmp = -1; 2773 2772 b = get_old_root(root, time_seq); 2774 2773 level = btrfs_header_level(b); 2775 2774 p->locks[level] = BTRFS_READ_LOCK; ··· 2786 2787 */ 2787 2788 btrfs_unlock_up_safe(p, level + 1); 2788 2789 2790 + /* 2791 + * Since we can unwind eb's we want to do a real search every 2792 + * time. 2793 + */ 2794 + prev_cmp = -1; 2789 2795 ret = key_search(b, key, level, &prev_cmp, &slot); 2790 2796 2791 2797 if (level != 0) {