Skip to content

Commit 5d51853

Browse files
SaltyKitkatkdave
authored andcommitted
btrfs-progs: tree-stats: accept numeric or text tree id for -t
Allow specification of string tree names same as dump-tree -t. Pull-request: #1025 Signed-off-by: David Sterba <[email protected]>
1 parent 8206b92 commit 5d51853

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

Documentation/btrfs-inspect-internal.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,17 @@ tree-stats [options] <device>
317317
-b|--raw
318318
raw numbers in bytes, without the *B* suffix
319319

320-
-t <treeid>
321-
Print stats only for the given treeid.
320+
-t <tree_id>
321+
print only the tree with the specified ID, where the ID can be numerical or
322+
common name in a flexible human readable form
323+
324+
The tree id name recognition rules:
325+
326+
* case does not matter
327+
* the C source definition, e.g. BTRFS_ROOT_TREE_OBJECTID
328+
* short forms without BTRFS\_ prefix, without _TREE and _OBJECTID suffix, e.g. ROOT_TREE, ROOT
329+
* convenience aliases, e.g. DEVICE for the DEV tree, CHECKSUM for CSUM
330+
* unrecognized ID is an error
322331
--human-readable
323332
print human friendly numbers, base 1024, this is the default
324333

cmds/inspect-tree-stats.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "common/messages.h"
3737
#include "common/open-utils.h"
3838
#include "common/string-utils.h"
39+
#include "common/parse-utils.h"
3940
#include "common/units.h"
4041
#include "cmds/commands.h"
4142

@@ -441,7 +442,7 @@ static const char * const cmd_inspect_tree_stats_usage[] = {
441442
"",
442443
OPTLINE("-b", "raw numbers in bytes"),
443444
HELPINFO_UNITS_LONG,
444-
OPTLINE("-t <rootid>", "print only tree with the given rootid"),
445+
OPTLINE("-t <tree_id>", "print only tree with the given id (string or number)"),
445446
NULL
446447
};
447448

@@ -467,11 +468,7 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd,
467468
unit_mode = UNITS_RAW;
468469
break;
469470
case 't':
470-
tree_id = arg_strtou64(optarg);
471-
if (!tree_id) {
472-
error("unrecognized tree id: %s", optarg);
473-
exit(1);
474-
}
471+
tree_id = parse_tree_id(optarg);
475472
break;
476473
default:
477474
usage_unknown_option(cmd, argv);

0 commit comments

Comments
 (0)