Skip to content

Commit

Permalink
btrfs: expand btrfs_find_item() to include find_root_ref functionality
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
shegeek authored and masoncl committed Jan 28, 2014
1 parent e33d5c3 commit 75ac2dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
10 changes: 8 additions & 2 deletions fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,13 @@ static int key_search(struct extent_buffer *b, struct btrfs_key *key,
/* Proposed generic search function, meant to take the place of the
* various small search helper functions throughout the code and standardize
* the search interface. Right now, it only replaces the former __inode_info
* in backref.c.
* in backref.c, and the former btrfs_find_root_ref in root-tree.c.
*
* If a null key is passed, it returns immediately after running
* btrfs_search_slot, leaving the path filled as it is and passing its
* return value upward. If a real key is passed, it will set the caller's
* path to point to the first item in the tree after its specified
* objectid, type, and offset for which objectid and type match the input.
*/
int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
u64 iobjectid, u64 ioff, u8 key_type,
Expand All @@ -2479,7 +2485,7 @@ int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
key.offset = ioff;

ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
if (ret < 0)
if ((ret < 0) || (found_key == NULL))
return ret;

eb = path->nodes[0];
Expand Down
6 changes: 3 additions & 3 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -4673,9 +4673,9 @@ static int fixup_tree_root_location(struct btrfs_root *root,
}

err = -ENOENT;
ret = btrfs_find_root_ref(root->fs_info->tree_root, path,
BTRFS_I(dir)->root->root_key.objectid,
location->objectid);
ret = btrfs_find_item(root->fs_info->tree_root, path,
BTRFS_I(dir)->root->root_key.objectid,
location->objectid, BTRFS_ROOT_REF_KEY, NULL);
if (ret) {
if (ret < 0)
err = ret;
Expand Down
15 changes: 0 additions & 15 deletions fs/btrfs/root-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,21 +400,6 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
return err;
}

int btrfs_find_root_ref(struct btrfs_root *tree_root,
struct btrfs_path *path,
u64 root_id, u64 ref_id)
{
struct btrfs_key key;
int ret;

key.objectid = root_id;
key.type = BTRFS_ROOT_REF_KEY;
key.offset = ref_id;

ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0);
return ret;
}

/*
* add a btrfs_root_ref item. type is either BTRFS_ROOT_REF_KEY
* or BTRFS_ROOT_BACKREF_KEY.
Expand Down

0 comments on commit 75ac2dd

Please sign in to comment.