summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2019-04-27 11:34:55 -0400
committerTom Rini <trini@konsulko.com>2019-04-27 11:35:44 -0400
commit6aebc0d11a10f48a54146c5e71bbef15a1a458fc (patch)
tree5745f1c3234e4540caafa51fcac5e619eba5022a /fs
parent6b8e57338f3c5b65fa5b883fa3f87124f11a9e19 (diff)
downloadu-boot-6aebc0d11a10f48a54146c5e71bbef15a1a458fc.tar.gz
Revert "fs: btrfs: fix false negatives in ROOT_ITEM search"
Per Pierre this change shouldn't have been applied as it was superseded by "fs: btrfs: fix btrfs_search_tree invalid results" which is also applied now as 1627e5e5985d. This reverts commit 633967f9818cb6a0e87ffa8cba33148a5bcc6edb. Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.h44
1 files changed, 6 insertions, 38 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index ca44a2404d..65c152a52f 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -292,52 +292,20 @@ btrfs_search_tree_key_type(const struct btrfs_root *root, u64 objectid,
{
struct btrfs_key key, *res;
- /*
- * In some cases (e.g. tree roots), we need to look for a given
- * objectid and type without knowing the offset value (3rd element of a
- * btrfs tree node key). We can rely on the fact that btrfs_search_tree
- * returns the first element with key >= search_key, and then perform
- * our own comparison between the returned element and the search key.
- *
- * It is tempting to use a search key with offset 0 to perform this
- * "fuzzy search". This would return the first item with the (objectid,
- * type) we're looking for. However, using offset 0 has the wrong
- * behavior when the wanted item is the first in a leaf: since our
- * search key will be lower than the wanted item, the recursive search
- * will explore the wrong branch of the tree.
- *
- * Instead, use the largest possible offset (-1). The result of this
- * search will either be:
- * 1. An element with the (objectid, type) we're looking for, if it
- * has offset -1 or if it is the last element in its leaf.
- * 2. The first element *after* an element with the (objectid, type)
- */
key.objectid = objectid;
key.type = type;
- key.offset = -1;
+ key.offset = 0;
if (btrfs_search_tree(root, &key, path))
return NULL;
- /*
- * Compare with the previous element first -- this is the likely case
- * since the result of the search is only what we want if it had offset
- * == -1 or if it was last in its leaf.
- */
- if (path->slots[0] > 0) {
- path->slots[0]--;
- res = btrfs_path_leaf_key(path);
- if (!btrfs_comp_keys_type(&key, res))
- return res;
- path->slots[0]++;
- }
-
res = btrfs_path_leaf_key(path);
- if (!btrfs_comp_keys_type(&key, res))
- return res;
+ if (btrfs_comp_keys_type(&key, res)) {
+ btrfs_free_path(path);
+ return NULL;
+ }
- btrfs_free_path(path);
- return NULL;
+ return res;
}
static inline u32 btrfs_path_item_size(struct btrfs_path *p)