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

Btrfs: ensure btrfs_prev_leaf doesn't miss 1 item

We might have had an item with the previous key in the tree right
before we released our path. And after we released our path, that
item might have been pushed to the first slot (0) of the leaf we
were holding due to a tree balance. Alternatively, an item with the
previous key can exist as the only element of a leaf (big fat item).
Therefore account for these 2 cases, so that our callers (like
btrfs_previous_item) don't miss an existing item with a key matching
the previous key we computed above.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Chris Mason <clm@fb.com>

authored by

Filipe Manana and committed by
Chris Mason
337c6f68 f82a9901

+11 -1
+11 -1
fs/btrfs/ctree.c
··· 5097 5097 return ret; 5098 5098 btrfs_item_key(path->nodes[0], &found_key, 0); 5099 5099 ret = comp_keys(&found_key, &key); 5100 - if (ret < 0) 5100 + /* 5101 + * We might have had an item with the previous key in the tree right 5102 + * before we released our path. And after we released our path, that 5103 + * item might have been pushed to the first slot (0) of the leaf we 5104 + * were holding due to a tree balance. Alternatively, an item with the 5105 + * previous key can exist as the only element of a leaf (big fat item). 5106 + * Therefore account for these 2 cases, so that our callers (like 5107 + * btrfs_previous_item) don't miss an existing item with a key matching 5108 + * the previous key we computed above. 5109 + */ 5110 + if (ret <= 0) 5101 5111 return 0; 5102 5112 return 1; 5103 5113 }