Commit d3541834 authored by Chris Mason's avatar Chris Mason

Merge branch 'fix/find-item-path-leak' of...

Merge branch 'fix/find-item-path-leak' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux into for-linus
parents ce93ec54 1d4c08e0
...@@ -1246,25 +1246,6 @@ int btrfs_check_shared(struct btrfs_trans_handle *trans, ...@@ -1246,25 +1246,6 @@ int btrfs_check_shared(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
/*
* this makes the path point to (inum INODE_ITEM ioff)
*/
int inode_item_info(u64 inum, u64 ioff, struct btrfs_root *fs_root,
struct btrfs_path *path)
{
struct btrfs_key key;
return btrfs_find_item(fs_root, path, inum, ioff,
BTRFS_INODE_ITEM_KEY, &key);
}
static int inode_ref_info(u64 inum, u64 ioff, struct btrfs_root *fs_root,
struct btrfs_path *path,
struct btrfs_key *found_key)
{
return btrfs_find_item(fs_root, path, inum, ioff,
BTRFS_INODE_REF_KEY, found_key);
}
int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid, int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid,
u64 start_off, struct btrfs_path *path, u64 start_off, struct btrfs_path *path,
struct btrfs_inode_extref **ret_extref, struct btrfs_inode_extref **ret_extref,
...@@ -1374,7 +1355,8 @@ char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path, ...@@ -1374,7 +1355,8 @@ char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
btrfs_tree_read_unlock_blocking(eb); btrfs_tree_read_unlock_blocking(eb);
free_extent_buffer(eb); free_extent_buffer(eb);
} }
ret = inode_ref_info(parent, 0, fs_root, path, &found_key); ret = btrfs_find_item(fs_root, path, parent, 0,
BTRFS_INODE_REF_KEY, &found_key);
if (ret > 0) if (ret > 0)
ret = -ENOENT; ret = -ENOENT;
if (ret) if (ret)
...@@ -1727,8 +1709,10 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root, ...@@ -1727,8 +1709,10 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
struct btrfs_key found_key; struct btrfs_key found_key;
while (!ret) { while (!ret) {
ret = inode_ref_info(inum, parent ? parent+1 : 0, fs_root, path, ret = btrfs_find_item(fs_root, path, inum,
parent ? parent + 1 : 0, BTRFS_INODE_REF_KEY,
&found_key); &found_key);
if (ret < 0) if (ret < 0)
break; break;
if (ret) { if (ret) {
......
...@@ -32,9 +32,6 @@ struct inode_fs_paths { ...@@ -32,9 +32,6 @@ struct inode_fs_paths {
typedef int (iterate_extent_inodes_t)(u64 inum, u64 offset, u64 root, typedef int (iterate_extent_inodes_t)(u64 inum, u64 offset, u64 root,
void *ctx); void *ctx);
int inode_item_info(u64 inum, u64 ioff, struct btrfs_root *fs_root,
struct btrfs_path *path);
int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical, int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
struct btrfs_path *path, struct btrfs_key *found_key, struct btrfs_path *path, struct btrfs_key *found_key,
u64 *flags); u64 *flags);
......
...@@ -2617,32 +2617,24 @@ static int key_search(struct extent_buffer *b, struct btrfs_key *key, ...@@ -2617,32 +2617,24 @@ static int key_search(struct extent_buffer *b, struct btrfs_key *key,
return 0; return 0;
} }
int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *found_path, int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
u64 iobjectid, u64 ioff, u8 key_type, u64 iobjectid, u64 ioff, u8 key_type,
struct btrfs_key *found_key) struct btrfs_key *found_key)
{ {
int ret; int ret;
struct btrfs_key key; struct btrfs_key key;
struct extent_buffer *eb; struct extent_buffer *eb;
struct btrfs_path *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;
if (found_path == NULL) {
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
} else
path = found_path;
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)
if (path != found_path)
btrfs_free_path(path);
return ret; return ret;
}
eb = path->nodes[0]; eb = path->nodes[0];
if (ret && path->slots[0] >= btrfs_header_nritems(eb)) { if (ret && path->slots[0] >= btrfs_header_nritems(eb)) {
......
...@@ -1630,6 +1630,8 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info, ...@@ -1630,6 +1630,8 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info,
bool check_ref) bool check_ref)
{ {
struct btrfs_root *root; struct btrfs_root *root;
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)
...@@ -1669,8 +1671,17 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info, ...@@ -1669,8 +1671,17 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info,
if (ret) if (ret)
goto fail; goto fail;
ret = btrfs_find_item(fs_info->tree_root, NULL, BTRFS_ORPHAN_OBJECTID, path = btrfs_alloc_path();
location->objectid, BTRFS_ORPHAN_ITEM_KEY, NULL); if (!path) {
ret = -ENOMEM;
goto fail;
}
key.objectid = BTRFS_ORPHAN_OBJECTID;
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);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
if (ret == 0) if (ret == 0)
......
...@@ -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;
...@@ -530,7 +531,14 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, ...@@ -530,7 +531,14 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root,
goto err; goto err;
} }
ret = inode_item_info(inum, 0, local_root, swarn->path); /*
* this makes the path point to (inum INODE_ITEM ioff)
*/
key.objectid = inum;
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;
......
...@@ -1254,13 +1254,14 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans, ...@@ -1254,13 +1254,14 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
} }
static int insert_orphan_item(struct btrfs_trans_handle *trans, static int insert_orphan_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 offset) struct btrfs_root *root, u64 ino)
{ {
int ret; int ret;
ret = btrfs_find_item(root, NULL, BTRFS_ORPHAN_OBJECTID,
offset, BTRFS_ORPHAN_ITEM_KEY, NULL); ret = btrfs_insert_orphan_item(trans, root, ino);
if (ret > 0) if (ret == -EEXIST)
ret = btrfs_insert_orphan_item(trans, root, offset); ret = 0;
return ret; return ret;
} }
......
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