summaryrefslogtreecommitdiff
path: root/cmds-inspect-tree-stats.c
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
commit951e6276e63efb48ce8232862f76444decebc7e4 (patch)
tree259c364b6754c11b6eff0949b5b946ed1632819c /cmds-inspect-tree-stats.c
parent9733b4b92640d96e0b5d3918430a359223f9059b (diff)
btrfs-progs: tree-stats: use on-stack path buffer in calc_root_size
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>
Diffstat (limited to 'cmds-inspect-tree-stats.c')
-rw-r--r--cmds-inspect-tree-stats.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/cmds-inspect-tree-stats.c b/cmds-inspect-tree-stats.c
index 5ec787a..0e2786c 100644
--- a/cmds-inspect-tree-stats.c
+++ b/cmds-inspect-tree-stats.c
@@ -313,7 +313,7 @@ static int calc_root_size(struct btrfs_root *tree_root, struct btrfs_key *key,
int find_inline)
{
struct btrfs_root *root;
- struct btrfs_path *path;
+ struct btrfs_path path;
struct rb_node *n;
struct timeval start, end, diff = {0};
struct root_stats stat;
@@ -327,31 +327,26 @@ static int calc_root_size(struct btrfs_root *tree_root, struct btrfs_key *key,
return 1;
}
- path = btrfs_alloc_path();
- if (!path) {
- error("could not allocate path");
- return 1;
- }
-
+ btrfs_init_path(&path);
memset(&stat, 0, sizeof(stat));
level = btrfs_header_level(root->node);
stat.lowest_bytenr = btrfs_header_bytenr(root->node);
stat.highest_bytenr = stat.lowest_bytenr;
stat.min_cluster_size = (u64)-1;
stat.max_cluster_size = root->nodesize;
- path->nodes[level] = root->node;
+ path.nodes[level] = root->node;
if (gettimeofday(&start, NULL)) {
error("cannot get time: %s", strerror(errno));
goto out;
}
if (!level) {
- ret = walk_leaf(root, path, &stat, find_inline);
+ ret = walk_leaf(root, &path, &stat, find_inline);
if (ret)
goto out;
goto out_print;
}
- ret = walk_nodes(root, path, &stat, level, find_inline);
+ ret = walk_nodes(root, &path, &stat, level, find_inline);
if (ret)
goto out;
if (gettimeofday(&end, NULL)) {
@@ -417,13 +412,11 @@ out:
}
/*
- * We only use path to save node data in iterating,
- * without holding eb's ref_cnt in path.
- * Don't use btrfs_free_path() here, it will free these
- * eb again, and cause many problems, as negative ref_cnt
- * or invalid memory access.
+ * We only use path to save node data in iterating, without holding
+ * eb's ref_cnt in path. Don't use btrfs_release_path() here, it will
+ * free these eb again, and cause many problems, as negative ref_cnt or
+ * invalid memory access.
*/
- free(path);
return ret;
}