diff options
author | Filipe Manana <fdmanana@gmail.com> | 2014-06-09 14:22:13 +0200 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-06-10 02:21:09 +0200 |
commit | 337c6f6830a5ceb650eaf10d38ed8e8f496c8f61 (patch) | |
tree | 77e42e97eb36ecb958057a2d2c525565fa7e2f3c /fs | |
parent | Btrfs: fix clone to deal with holes when NO_HOLES feature is enabled (diff) | |
download | linux-337c6f6830a5ceb650eaf10d38ed8e8f496c8f61.tar.xz linux-337c6f6830a5ceb650eaf10d38ed8e8f496c8f61.zip |
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/ctree.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index d99d9651dd58..4eada52f3969 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -5097,7 +5097,17 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path) return ret; btrfs_item_key(path->nodes[0], &found_key, 0); ret = comp_keys(&found_key, &key); - if (ret < 0) + /* + * 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. + */ + if (ret <= 0) return 0; return 1; } |