aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/backref.c
diff options
context:
space:
mode:
authorKelley Nielsen <kelleynnn@gmail.com>2013-11-04 22:33:33 -0500
committerChris Mason <clm@fb.com>2014-01-28 16:19:36 -0500
commite33d5c3d6d61518c7f115af6d11d3dffa230d31f (patch)
treedab8d84917d8f5c1f736324aec371fb665f33b31 /fs/btrfs/backref.c
parenta3df41ee377b2766a7525f9ca05207698efe4551 (diff)
btrfs: bootstrap generic btrfs_find_item interface
There are many btrfs functions that manually search the tree for an item. They all reimplement the same mechanism and differ in the conditions that they use to find the item. __inode_info() is one such example. Zach Brown proposed creating a new interface to take the place of these functions. This patch is the first step to creating the interface. A new function, btrfs_find_item, has been added to ctree.c and prototyped in ctree.h. It is identical to __inode_info, except that the order of the parameters has been rearranged to more closely those of similar functions elsewhere in the code (now, root and path come first, then the objectid, offset and type, and the key to be filled in last). __inode_info's callers have been set to call this new function instead, and __inode_info itself has been removed. 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>
Diffstat (limited to 'fs/btrfs/backref.c')
-rw-r--r--fs/btrfs/backref.c40
1 files changed, 4 insertions, 36 deletions
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 826b98c211ae..6a3f7f50ad37 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -1107,38 +1107,6 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
1107 return 0; 1107 return 0;
1108} 1108}
1109 1109
1110
1111static int __inode_info(u64 inum, u64 ioff, u8 key_type,
1112 struct btrfs_root *fs_root, struct btrfs_path *path,
1113 struct btrfs_key *found_key)
1114{
1115 int ret;
1116 struct btrfs_key key;
1117 struct extent_buffer *eb;
1118
1119 key.type = key_type;
1120 key.objectid = inum;
1121 key.offset = ioff;
1122
1123 ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
1124 if (ret < 0)
1125 return ret;
1126
1127 eb = path->nodes[0];
1128 if (ret && path->slots[0] >= btrfs_header_nritems(eb)) {
1129 ret = btrfs_next_leaf(fs_root, path);
1130 if (ret)
1131 return ret;
1132 eb = path->nodes[0];
1133 }
1134
1135 btrfs_item_key_to_cpu(eb, found_key, path->slots[0]);
1136 if (found_key->type != key.type || found_key->objectid != key.objectid)
1137 return 1;
1138
1139 return 0;
1140}
1141
1142/* 1110/*
1143 * this makes the path point to (inum INODE_ITEM ioff) 1111 * this makes the path point to (inum INODE_ITEM ioff)
1144 */ 1112 */
@@ -1146,16 +1114,16 @@ int inode_item_info(u64 inum, u64 ioff, struct btrfs_root *fs_root,
1146 struct btrfs_path *path) 1114 struct btrfs_path *path)
1147{ 1115{
1148 struct btrfs_key key; 1116 struct btrfs_key key;
1149 return __inode_info(inum, ioff, BTRFS_INODE_ITEM_KEY, fs_root, path, 1117 return btrfs_find_item(fs_root, path, inum, ioff,
1150 &key); 1118 BTRFS_INODE_ITEM_KEY, &key);
1151} 1119}
1152 1120
1153static int inode_ref_info(u64 inum, u64 ioff, struct btrfs_root *fs_root, 1121static int inode_ref_info(u64 inum, u64 ioff, struct btrfs_root *fs_root,
1154 struct btrfs_path *path, 1122 struct btrfs_path *path,
1155 struct btrfs_key *found_key) 1123 struct btrfs_key *found_key)
1156{ 1124{
1157 return __inode_info(inum, ioff, BTRFS_INODE_REF_KEY, fs_root, path, 1125 return btrfs_find_item(fs_root, path, inum, ioff,
1158 found_key); 1126 BTRFS_INODE_REF_KEY, found_key);
1159} 1127}
1160 1128
1161int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid, 1129int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid,