Commit 1d4c08e0 authored by David Sterba's avatar David Sterba

btrfs: expand btrfs_find_item if found_key is NULL

If the found_key is NULL, then btrfs_find_item becomes a verbose wrapper
for simple btrfs_search_slot.

After we've removed all such callers, passing a NULL key is not valid
anymore.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.cz>
parent 9c4f61f0
...@@ -2618,13 +2618,14 @@ int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, ...@@ -2618,13 +2618,14 @@ int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
struct extent_buffer *eb; struct extent_buffer *eb;
ASSERT(path); ASSERT(path);
ASSERT(found_key);
key.type = key_type; key.type = key_type;
key.objectid = iobjectid; key.objectid = iobjectid;
key.offset = ioff; key.offset = ioff;
ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
if ((ret < 0) || (found_key == NULL)) if (ret < 0)
return ret; return ret;
eb = path->nodes[0]; eb = path->nodes[0];
......
...@@ -1631,6 +1631,7 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info, ...@@ -1631,6 +1631,7 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info,
{ {
struct btrfs_root *root; struct btrfs_root *root;
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_key key;
int ret; int ret;
if (location->objectid == BTRFS_ROOT_TREE_OBJECTID) if (location->objectid == BTRFS_ROOT_TREE_OBJECTID)
...@@ -1675,8 +1676,11 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info, ...@@ -1675,8 +1676,11 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info,
ret = -ENOMEM; ret = -ENOMEM;
goto fail; goto fail;
} }
ret = btrfs_find_item(fs_info->tree_root, path, BTRFS_ORPHAN_OBJECTID, key.objectid = BTRFS_ORPHAN_OBJECTID;
location->objectid, BTRFS_ORPHAN_ITEM_KEY, NULL); key.type = BTRFS_ORPHAN_ITEM_KEY;
key.offset = location->objectid;
ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
btrfs_free_path(path); btrfs_free_path(path);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
......
...@@ -5009,6 +5009,7 @@ static int fixup_tree_root_location(struct btrfs_root *root, ...@@ -5009,6 +5009,7 @@ static int fixup_tree_root_location(struct btrfs_root *root,
struct btrfs_root *new_root; struct btrfs_root *new_root;
struct btrfs_root_ref *ref; struct btrfs_root_ref *ref;
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_key key;
int ret; int ret;
int err = 0; int err = 0;
...@@ -5019,9 +5020,12 @@ static int fixup_tree_root_location(struct btrfs_root *root, ...@@ -5019,9 +5020,12 @@ static int fixup_tree_root_location(struct btrfs_root *root,
} }
err = -ENOENT; err = -ENOENT;
ret = btrfs_find_item(root->fs_info->tree_root, path, key.objectid = BTRFS_I(dir)->root->root_key.objectid;
BTRFS_I(dir)->root->root_key.objectid, key.type = BTRFS_ROOT_REF_KEY;
location->objectid, BTRFS_ROOT_REF_KEY, NULL); key.offset = location->objectid;
ret = btrfs_search_slot(NULL, root->fs_info->tree_root, &key, path,
0, 0);
if (ret) { if (ret) {
if (ret < 0) if (ret < 0)
err = ret; err = ret;
......
...@@ -520,6 +520,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, ...@@ -520,6 +520,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root,
struct inode_fs_paths *ipath = NULL; struct inode_fs_paths *ipath = NULL;
struct btrfs_root *local_root; struct btrfs_root *local_root;
struct btrfs_key root_key; struct btrfs_key root_key;
struct btrfs_key key;
root_key.objectid = root; root_key.objectid = root;
root_key.type = BTRFS_ROOT_ITEM_KEY; root_key.type = BTRFS_ROOT_ITEM_KEY;
...@@ -533,8 +534,11 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, ...@@ -533,8 +534,11 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root,
/* /*
* this makes the path point to (inum INODE_ITEM ioff) * this makes the path point to (inum INODE_ITEM ioff)
*/ */
ret = btrfs_find_item(local_root, swarn->path, inum, 0, key.objectid = inum;
BTRFS_INODE_ITEM_KEY, NULL); key.type = BTRFS_INODE_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, local_root, &key, swarn->path, 0, 0);
if (ret) { if (ret) {
btrfs_release_path(swarn->path); btrfs_release_path(swarn->path);
goto err; goto err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment