From ef8e050d640ad4afac7517b040798f6f9ec0d2a1 Mon Sep 17 00:00:00 2001 From: Chung-Chiang Cheng Date: Tue, 2 Jul 2024 16:55:02 +0800 Subject: [PATCH] btrfs-progs: inspect tree-stats: support to show a specified tree tree-stats currently displays only some global trees and fs-tree 5. Add support to show the stats of a specified tree. Issue: #268 Signed-off-by: Chung-Chiang Cheng Signed-off-by: David Sterba --- Documentation/btrfs-inspect-internal.rst | 3 +++ cmds/inspect-tree-stats.c | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Documentation/btrfs-inspect-internal.rst b/Documentation/btrfs-inspect-internal.rst index 53d5fcf0..b72651ed 100644 --- a/Documentation/btrfs-inspect-internal.rst +++ b/Documentation/btrfs-inspect-internal.rst @@ -228,6 +228,9 @@ tree-stats [options] -b Print raw numbers in bytes. + -t + Print stats only for the given treeid. + EXIT STATUS ----------- diff --git a/cmds/inspect-tree-stats.c b/cmds/inspect-tree-stats.c index 42dab804..15576b04 100644 --- a/cmds/inspect-tree-stats.c +++ b/cmds/inspect-tree-stats.c @@ -35,6 +35,7 @@ #include "common/help.h" #include "common/messages.h" #include "common/open-utils.h" +#include "common/string-utils.h" #include "common/units.h" #include "cmds/commands.h" @@ -441,6 +442,7 @@ static const char * const cmd_inspect_tree_stats_usage[] = { "Print various stats for trees", "", OPTLINE("-b", "raw numbers in bytes"), + OPTLINE("-t ", "print only tree with the given rootid"), NULL }; @@ -451,9 +453,10 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd, struct btrfs_root *root; int opt; int ret = 0; + u64 tree_id = 0; optind = 0; - while ((opt = getopt(argc, argv, "vb")) != -1) { + while ((opt = getopt(argc, argv, "vbt:")) != -1) { switch (opt) { case 'v': verbose++; @@ -461,6 +464,13 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd, case 'b': no_pretty = true; break; + case 't': + tree_id = arg_strtou64(optarg); + if (!tree_id) { + error("unrecognized tree id: %s", optarg); + exit(1); + } + break; default: usage_unknown_option(cmd, argv); } @@ -485,6 +495,14 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd, exit(1); } + if (tree_id) { + pr_verbose(LOG_DEFAULT, "Calculating size of tree (%llu)\n", tree_id); + key.objectid = tree_id; + key.offset = (u64)-1; + ret = calc_root_size(root, &key, 1); + goto out; + } + pr_verbose(LOG_DEFAULT, "Calculating size of root tree\n"); key.objectid = BTRFS_ROOT_TREE_OBJECTID; ret = calc_root_size(root, &key, 0);