summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-11-03 00:37:51 +0100
committerDavid Sterba <dsterba@suse.com>2016-11-09 13:47:33 +0100
commit9733b4b92640d96e0b5d3918430a359223f9059b (patch)
tree72a95861cb94fcf91d7be36b2636a97716a6a9f1
parent5ec9951e7db69290682d8c129e81f18e8c75fb9d (diff)
btrfs-progs: check: use on-stack path buffer in repair_root_items
We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--cmds-check.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/cmds-check.c b/cmds-check.c
index cf58f95d..62e87b88 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -11020,7 +11020,7 @@ static int maybe_repair_root_item(struct btrfs_fs_info *info,
*/
static int repair_root_items(struct btrfs_fs_info *info)
{
- struct btrfs_path *path = NULL;
+ struct btrfs_path path;
struct btrfs_key key;
struct extent_buffer *leaf;
struct btrfs_trans_handle *trans = NULL;
@@ -11028,16 +11028,12 @@ static int repair_root_items(struct btrfs_fs_info *info)
int bad_roots = 0;
int need_trans = 0;
+ btrfs_init_path(&path);
+
ret = build_roots_info_cache(info);
if (ret)
goto out;
- path = btrfs_alloc_path();
- if (!path) {
- ret = -ENOMEM;
- goto out;
- }
-
key.objectid = BTRFS_FIRST_FREE_OBJECTID;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = 0;
@@ -11056,19 +11052,19 @@ again:
}
}
- ret = btrfs_search_slot(trans, info->tree_root, &key, path,
+ ret = btrfs_search_slot(trans, info->tree_root, &key, &path,
0, trans ? 1 : 0);
if (ret < 0)
goto out;
- leaf = path->nodes[0];
+ leaf = path.nodes[0];
while (1) {
struct btrfs_key found_key;
- if (path->slots[0] >= btrfs_header_nritems(leaf)) {
- int no_more_keys = find_next_key(path, &key);
+ if (path.slots[0] >= btrfs_header_nritems(leaf)) {
+ int no_more_keys = find_next_key(&path, &key);
- btrfs_release_path(path);
+ btrfs_release_path(&path);
if (trans) {
ret = btrfs_commit_transaction(trans,
info->tree_root);
@@ -11082,14 +11078,14 @@ again:
goto again;
}
- btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
+ btrfs_item_key_to_cpu(leaf, &found_key, path.slots[0]);
if (found_key.type != BTRFS_ROOT_ITEM_KEY)
goto next;
if (found_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
goto next;
- ret = maybe_repair_root_item(info, path, &found_key,
+ ret = maybe_repair_root_item(info, &path, &found_key,
trans ? 0 : 1);
if (ret < 0)
goto out;
@@ -11097,18 +11093,18 @@ again:
if (!trans && repair) {
need_trans = 1;
key = found_key;
- btrfs_release_path(path);
+ btrfs_release_path(&path);
goto again;
}
bad_roots++;
}
next:
- path->slots[0]++;
+ path.slots[0]++;
}
ret = 0;
out:
free_roots_info_cache();
- btrfs_free_path(path);
+ btrfs_release_path(&path);
if (trans)
btrfs_commit_transaction(trans, info->tree_root);
if (ret < 0)