Skip to content

Commit 75ac2dd

Browse files
shegeekChris Mason
authored andcommitted
btrfs: expand btrfs_find_item() to include find_root_ref functionality
This patch is the second step in bootstrapping the btrfs_find_item interface. The btrfs_find_root_ref() is similar to the former __inode_info(); it accepts four of its parameters, and duplicates the first half of its functionality. Replace the one former call to btrfs_find_root_ref() with a call to btrfs_find_item(), along with the defined key type that was used internally by btrfs_find_root ref, and a null found key. In btrfs_find_item(), add a test for the null key at the place where the functionality of btrfs_find_root_ref() ends; btrfs_find_item() then returns if the test passes. Finally, remove btrfs_find_root_ref(). Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com> Suggested-by: Zach Brown <zab@redhat.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent e33d5c3 commit 75ac2dd

3 files changed

Lines changed: 11 additions & 20 deletions

File tree

‎fs/btrfs/ctree.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,13 @@ static int key_search(struct extent_buffer *b, struct btrfs_key *key,
24642464
/* Proposed generic search function, meant to take the place of the
24652465
* various small search helper functions throughout the code and standardize
24662466
* the search interface. Right now, it only replaces the former __inode_info
2467-
* in backref.c.
2467+
* in backref.c, and the former btrfs_find_root_ref in root-tree.c.
2468+
*
2469+
* If a null key is passed, it returns immediately after running
2470+
* btrfs_search_slot, leaving the path filled as it is and passing its
2471+
* return value upward. If a real key is passed, it will set the caller's
2472+
* path to point to the first item in the tree after its specified
2473+
* objectid, type, and offset for which objectid and type match the input.
24682474
*/
24692475
int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
24702476
u64 iobjectid, u64 ioff, u8 key_type,
@@ -2479,7 +2485,7 @@ int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
24792485
key.offset = ioff;
24802486

24812487
ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
2482-
if (ret < 0)
2488+
if ((ret < 0) || (found_key == NULL))
24832489
return ret;
24842490

24852491
eb = path->nodes[0];

‎fs/btrfs/inode.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4673,9 +4673,9 @@ static int fixup_tree_root_location(struct btrfs_root *root,
46734673
}
46744674

46754675
err = -ENOENT;
4676-
ret = btrfs_find_root_ref(root->fs_info->tree_root, path,
4677-
BTRFS_I(dir)->root->root_key.objectid,
4678-
location->objectid);
4676+
ret = btrfs_find_item(root->fs_info->tree_root, path,
4677+
BTRFS_I(dir)->root->root_key.objectid,
4678+
location->objectid, BTRFS_ROOT_REF_KEY, NULL);
46794679
if (ret) {
46804680
if (ret < 0)
46814681
err = ret;

‎fs/btrfs/root-tree.c‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -400,21 +400,6 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
400400
return err;
401401
}
402402

403-
int btrfs_find_root_ref(struct btrfs_root *tree_root,
404-
struct btrfs_path *path,
405-
u64 root_id, u64 ref_id)
406-
{
407-
struct btrfs_key key;
408-
int ret;
409-
410-
key.objectid = root_id;
411-
key.type = BTRFS_ROOT_REF_KEY;
412-
key.offset = ref_id;
413-
414-
ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0);
415-
return ret;
416-
}
417-
418403
/*
419404
* add a btrfs_root_ref item. type is either BTRFS_ROOT_REF_KEY
420405
* or BTRFS_ROOT_BACKREF_KEY.

0 commit comments

Comments
 (0)