aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/ctree.c26
-rw-r--r--fs/btrfs/disk-io.c3
-rw-r--r--fs/btrfs/orphan.c20
-rw-r--r--fs/btrfs/tree-log.c3
4 files changed, 17 insertions, 35 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 64b87894460b..22629809c9c4 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2461,32 +2461,32 @@ static int key_search(struct extent_buffer *b, struct btrfs_key *key,
2461 return 0; 2461 return 0;
2462} 2462}
2463 2463
2464/* Proposed generic search function, meant to take the place of the 2464int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *found_path,
2465* various small search helper functions throughout the code and standardize
2466* the search interface. Right now, it only replaces the former __inode_info
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.
2474*/
2475int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
2476 u64 iobjectid, u64 ioff, u8 key_type, 2465 u64 iobjectid, u64 ioff, u8 key_type,
2477 struct btrfs_key *found_key) 2466 struct btrfs_key *found_key)
2478{ 2467{
2479 int ret; 2468 int ret;
2480 struct btrfs_key key; 2469 struct btrfs_key key;
2481 struct extent_buffer *eb; 2470 struct extent_buffer *eb;
2471 struct btrfs_path *path;
2482 2472
2483 key.type = key_type; 2473 key.type = key_type;
2484 key.objectid = iobjectid; 2474 key.objectid = iobjectid;
2485 key.offset = ioff; 2475 key.offset = ioff;
2486 2476
2477 if (found_path == NULL) {
2478 path = btrfs_alloc_path();
2479 if (!path)
2480 return -ENOMEM;
2481 } else
2482 path = found_path;
2483
2487 ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0); 2484 ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
2488 if ((ret < 0) || (found_key == NULL)) 2485 if ((ret < 0) || (found_key == NULL)) {
2486 if (path != found_path)
2487 btrfs_free_path(path);
2489 return ret; 2488 return ret;
2489 }
2490 2490
2491 eb = path->nodes[0]; 2491 eb = path->nodes[0];
2492 if (ret && path->slots[0] >= btrfs_header_nritems(eb)) { 2492 if (ret && path->slots[0] >= btrfs_header_nritems(eb)) {
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index d84667379f01..4ecee0a009cb 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1608,7 +1608,8 @@ again:
1608 if (ret) 1608 if (ret)
1609 goto fail; 1609 goto fail;
1610 1610
1611 ret = btrfs_find_orphan_item(fs_info->tree_root, location->objectid); 1611 ret = btrfs_find_item(fs_info->tree_root, NULL, BTRFS_ORPHAN_OBJECTID,
1612 location->objectid, BTRFS_ORPHAN_ITEM_KEY, NULL);
1612 if (ret < 0) 1613 if (ret < 0)
1613 goto fail; 1614 goto fail;
1614 if (ret == 0) 1615 if (ret == 0)
diff --git a/fs/btrfs/orphan.c b/fs/btrfs/orphan.c
index 24cad1695af7..65793edb38ca 100644
--- a/fs/btrfs/orphan.c
+++ b/fs/btrfs/orphan.c
@@ -69,23 +69,3 @@ out:
69 btrfs_free_path(path); 69 btrfs_free_path(path);
70 return ret; 70 return ret;
71} 71}
72
73int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset)
74{
75 struct btrfs_path *path;
76 struct btrfs_key key;
77 int ret;
78
79 key.objectid = BTRFS_ORPHAN_OBJECTID;
80 key.type = BTRFS_ORPHAN_ITEM_KEY;
81 key.offset = offset;
82
83 path = btrfs_alloc_path();
84 if (!path)
85 return -ENOMEM;
86
87 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
88
89 btrfs_free_path(path);
90 return ret;
91}
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index e7d7a837512a..ba2f15109dac 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -1238,7 +1238,8 @@ static int insert_orphan_item(struct btrfs_trans_handle *trans,
1238 struct btrfs_root *root, u64 offset) 1238 struct btrfs_root *root, u64 offset)
1239{ 1239{
1240 int ret; 1240 int ret;
1241 ret = btrfs_find_orphan_item(root, offset); 1241 ret = btrfs_find_item(root, NULL, BTRFS_ORPHAN_OBJECTID,
1242 offset, BTRFS_ORPHAN_ITEM_KEY, NULL);
1242 if (ret > 0) 1243 if (ret > 0)
1243 ret = btrfs_insert_orphan_item(trans, root, offset); 1244 ret = btrfs_insert_orphan_item(trans, root, offset);
1244 return ret; 1245 return ret;