@@ -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 <tree_id>", "print only tree with the given id"),
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);
tree-stats currently displays only some global trees and fs-tree 5. Add support to show the stats of a specified tree. Signed-off-by: Chung-Chiang Cheng <cccheng@synology.com> --- cmds/inspect-tree-stats.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)