summaryrefslogtreecommitdiff
path: root/cmds-qgroup.c
diff options
context:
space:
mode:
authorFan Chengniang <fancn.fnst@cn.fujitsu.com>2015-01-19 15:18:18 +0800
committerDavid Sterba <dsterba@suse.cz>2015-01-21 18:13:18 +0100
commit4d13434539052dcdcc738b68535d5e9bdb116dda (patch)
tree2007d2a6a3163e1f53684a1b7bfbc25855bf88ca /cmds-qgroup.c
parent07ce7005fc81289eb4c7dde7d601be08c977b92c (diff)
btrfs-progs: make btrfs qgroups show human readable sizes
add --raw, --si, --iec, --kbytes, --mbytes, --gbytes, --tbytes options make columns which show sizes align to right. Others aligned to left. example: qgroupid rfer excl max_rfer max_excl parent child -------- ---- ---- -------- -------- ------ ----- 0/5 299.58MiB 299.58MiB 300.00MiB 300.00MiB 1/1 --- 0/265 299.58MiB 16.00KiB 400.00MiB 0.00B 1/1 --- 0/266 299.58MiB 16.00KiB 350.00MiB 0.00B --- --- 1/1 599.16MiB 299.59MiB 800.00MiB 0.00B --- 0/5,0/265 Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'cmds-qgroup.c')
-rw-r--r--cmds-qgroup.c56
1 files changed, 46 insertions, 10 deletions
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index dfb38f71..26c87912 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -208,19 +208,26 @@ static const char * const cmd_qgroup_show_usage[] = {
"btrfs qgroup show -pcreFf "
"[--sort=qgroupid,rfer,excl,max_rfer,max_excl] <path>",
"Show subvolume quota groups.",
- "-p print parent qgroup id",
- "-c print child qgroup id",
- "-r print max referenced size of qgroup",
- "-e print max exclusive size of qgroup",
- "-F list all qgroups which impact the given path"
+ "-p print parent qgroup id",
+ "-c print child qgroup id",
+ "-r print max referenced size of qgroup",
+ "-e print max exclusive size of qgroup",
+ "-F list all qgroups which impact the given path"
"(include ancestral qgroups)",
- "-f list all qgroups which impact the given path"
+ "-f list all qgroups which impact the given path"
"(exclude ancestral qgroups)",
+ "--raw raw numbers in bytes",
+ "--iec use 1024 as a base (KiB, MiB, GiB, TiB)",
+ "--si use 1000 as a base (kB, MB, GB, TB)",
+ "--kbytes show sizes in KiB, or kB with --si",
+ "--mbytes show sizes in MiB, or MB with --si",
+ "--gbytes show sizes in GiB, or GB with --si",
+ "--tbytes show sizes in TiB, or TB with --si",
"--sort=qgroupid,rfer,excl,max_rfer,max_excl",
- " list qgroups in order of qgroupid,"
+ " list qgroups in order of qgroupid,"
"rfer,max_rfer or max_excl",
- " you can use '+' or '-' in front of each item.",
- " (+:ascending, -:descending, ascending default)",
+ " you can use '+' or '-' in front of each item.",
+ " (+:ascending, -:descending, ascending default)",
NULL
};
@@ -233,6 +240,7 @@ static int cmd_qgroup_show(int argc, char **argv)
DIR *dirstream = NULL;
u64 qgroupid;
int filter_flag = 0;
+ unsigned unit_mode = UNITS_DEFAULT;
struct btrfs_qgroup_comparer_set *comparer_set;
struct btrfs_qgroup_filter_set *filter_set;
@@ -242,12 +250,20 @@ static int cmd_qgroup_show(int argc, char **argv)
optind = 1;
while (1) {
int c;
+ int option_index = 0;
static const struct option long_options[] = {
{"sort", 1, NULL, 'S'},
+ {"raw", no_argument, NULL, 0},
+ {"kbytes", no_argument, NULL, 0},
+ {"mbytes", no_argument, NULL, 0},
+ {"gbytes", no_argument, NULL, 0},
+ {"tbytes", no_argument, NULL, 0},
+ {"si", no_argument, NULL, GETOPT_VAL_SI},
+ {"iec", no_argument, NULL, GETOPT_VAL_IEC},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, "pcreFf",
- long_options, NULL);
+ long_options, &option_index);
if (c < 0)
break;
@@ -280,10 +296,30 @@ static int cmd_qgroup_show(int argc, char **argv)
if (ret)
usage(cmd_qgroup_show_usage);
break;
+ case 0:
+ if (option_index == 1)
+ unit_mode = UNITS_RAW;
+ else if (option_index == 2)
+ units_set_base(&unit_mode, UNITS_KBYTES);
+ else if (option_index == 3)
+ units_set_base(&unit_mode, UNITS_MBYTES);
+ else if (option_index == 4)
+ units_set_base(&unit_mode, UNITS_GBYTES);
+ else if (option_index == 5)
+ units_set_base(&unit_mode, UNITS_TBYTES);
+ break;
+ case GETOPT_VAL_SI:
+ units_set_mode(&unit_mode, UNITS_DECIMAL);
+ break;
+ case GETOPT_VAL_IEC:
+ units_set_mode(&unit_mode, UNITS_BINARY);
+ break;
default:
usage(cmd_qgroup_show_usage);
}
}
+ btrfs_qgroup_setup_units(unit_mode);
+
if (check_argc_exact(argc - optind, 1))
usage(cmd_qgroup_show_usage);