btrfs-progs: check: use on-stack path buffer in try_to_fix_bad_block
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>
This commit is contained in:
parent
4cf9b7e2a1
commit
a88c8f17cb
30
cmds-check.c
30
cmds-check.c
|
@ -4300,7 +4300,7 @@ static int try_to_fix_bad_block(struct btrfs_root *root,
|
||||||
struct ulist *roots;
|
struct ulist *roots;
|
||||||
struct ulist_node *node;
|
struct ulist_node *node;
|
||||||
struct btrfs_root *search_root;
|
struct btrfs_root *search_root;
|
||||||
struct btrfs_path *path;
|
struct btrfs_path path;
|
||||||
struct ulist_iterator iter;
|
struct ulist_iterator iter;
|
||||||
struct btrfs_key root_key, key;
|
struct btrfs_key root_key, key;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -4309,17 +4309,11 @@ static int try_to_fix_bad_block(struct btrfs_root *root,
|
||||||
status != BTRFS_TREE_BLOCK_INVALID_OFFSETS)
|
status != BTRFS_TREE_BLOCK_INVALID_OFFSETS)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
ret = btrfs_find_all_roots(NULL, root->fs_info, buf->start, 0, &roots);
|
||||||
if (!path)
|
if (ret)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
ret = btrfs_find_all_roots(NULL, root->fs_info, buf->start,
|
btrfs_init_path(&path);
|
||||||
0, &roots);
|
|
||||||
if (ret) {
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
ULIST_ITER_INIT(&iter);
|
ULIST_ITER_INIT(&iter);
|
||||||
while ((node = ulist_next(roots, &iter))) {
|
while ((node = ulist_next(roots, &iter))) {
|
||||||
root_key.objectid = node->val;
|
root_key.objectid = node->val;
|
||||||
|
@ -4339,31 +4333,31 @@ static int try_to_fix_bad_block(struct btrfs_root *root,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
path->lowest_level = btrfs_header_level(buf);
|
path.lowest_level = btrfs_header_level(buf);
|
||||||
path->skip_check_block = 1;
|
path.skip_check_block = 1;
|
||||||
if (path->lowest_level)
|
if (path.lowest_level)
|
||||||
btrfs_node_key_to_cpu(buf, &key, 0);
|
btrfs_node_key_to_cpu(buf, &key, 0);
|
||||||
else
|
else
|
||||||
btrfs_item_key_to_cpu(buf, &key, 0);
|
btrfs_item_key_to_cpu(buf, &key, 0);
|
||||||
ret = btrfs_search_slot(trans, search_root, &key, path, 0, 1);
|
ret = btrfs_search_slot(trans, search_root, &key, &path, 0, 1);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
btrfs_commit_transaction(trans, search_root);
|
btrfs_commit_transaction(trans, search_root);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (status == BTRFS_TREE_BLOCK_BAD_KEY_ORDER)
|
if (status == BTRFS_TREE_BLOCK_BAD_KEY_ORDER)
|
||||||
ret = fix_key_order(trans, search_root, path);
|
ret = fix_key_order(trans, search_root, &path);
|
||||||
else if (status == BTRFS_TREE_BLOCK_INVALID_OFFSETS)
|
else if (status == BTRFS_TREE_BLOCK_INVALID_OFFSETS)
|
||||||
ret = fix_item_offset(trans, search_root, path);
|
ret = fix_item_offset(trans, search_root, &path);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
btrfs_commit_transaction(trans, search_root);
|
btrfs_commit_transaction(trans, search_root);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
btrfs_release_path(path);
|
btrfs_release_path(&path);
|
||||||
btrfs_commit_transaction(trans, search_root);
|
btrfs_commit_transaction(trans, search_root);
|
||||||
}
|
}
|
||||||
ulist_free(roots);
|
ulist_free(roots);
|
||||||
btrfs_free_path(path);
|
btrfs_release_path(&path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue