mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-17 20:45:21 +00:00
btrfs-progs: check: use on-stack path buffer in fill_csum_tree_from_extent
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
02ca1e8a0f
commit
1b42d77eb6
32
cmds-check.c
32
cmds-check.c
@ -10711,36 +10711,32 @@ static int fill_csum_tree_from_extent(struct btrfs_trans_handle *trans,
|
|||||||
struct btrfs_root *csum_root)
|
struct btrfs_root *csum_root)
|
||||||
{
|
{
|
||||||
struct btrfs_root *extent_root = csum_root->fs_info->extent_root;
|
struct btrfs_root *extent_root = csum_root->fs_info->extent_root;
|
||||||
struct btrfs_path *path;
|
struct btrfs_path path;
|
||||||
struct btrfs_extent_item *ei;
|
struct btrfs_extent_item *ei;
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
char *buf;
|
char *buf;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
btrfs_init_path(&path);
|
||||||
if (!path)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
key.objectid = 0;
|
key.objectid = 0;
|
||||||
key.type = BTRFS_EXTENT_ITEM_KEY;
|
key.type = BTRFS_EXTENT_ITEM_KEY;
|
||||||
key.offset = 0;
|
key.offset = 0;
|
||||||
|
ret = btrfs_search_slot(NULL, extent_root, &key, &path, 0, 0);
|
||||||
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
btrfs_free_path(path);
|
btrfs_release_path(&path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = malloc(csum_root->sectorsize);
|
buf = malloc(csum_root->sectorsize);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
btrfs_free_path(path);
|
btrfs_release_path(&path);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
|
if (path.slots[0] >= btrfs_header_nritems(path.nodes[0])) {
|
||||||
ret = btrfs_next_leaf(extent_root, path);
|
ret = btrfs_next_leaf(extent_root, &path);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -10748,19 +10744,19 @@ static int fill_csum_tree_from_extent(struct btrfs_trans_handle *trans,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
leaf = path->nodes[0];
|
leaf = path.nodes[0];
|
||||||
|
|
||||||
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
|
btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
|
||||||
if (key.type != BTRFS_EXTENT_ITEM_KEY) {
|
if (key.type != BTRFS_EXTENT_ITEM_KEY) {
|
||||||
path->slots[0]++;
|
path.slots[0]++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ei = btrfs_item_ptr(leaf, path->slots[0],
|
ei = btrfs_item_ptr(leaf, path.slots[0],
|
||||||
struct btrfs_extent_item);
|
struct btrfs_extent_item);
|
||||||
if (!(btrfs_extent_flags(leaf, ei) &
|
if (!(btrfs_extent_flags(leaf, ei) &
|
||||||
BTRFS_EXTENT_FLAG_DATA)) {
|
BTRFS_EXTENT_FLAG_DATA)) {
|
||||||
path->slots[0]++;
|
path.slots[0]++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10768,10 +10764,10 @@ static int fill_csum_tree_from_extent(struct btrfs_trans_handle *trans,
|
|||||||
key.offset);
|
key.offset);
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
path->slots[0]++;
|
path.slots[0]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
btrfs_free_path(path);
|
btrfs_release_path(&path);
|
||||||
free(buf);
|
free(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user