Btrfs-progs, add units to 'usage' subcommands
Subsystems (2)
cover Btrfs-progs, add units to 'usage' subcommands
Copy from 'fi df' to 'fi usage' and 'dev usage'.
David Sterba (6):
btrfs-progs: fi usage, change option for tabular output to T
btrfs-progs: fi usage, add switches to set output units
btrfs-progs: fi usage, update manpage
btrfs-progs: dev usage, add switches to set output units
btrfs-progs: dev usage, update manpage
btrfs-progs: unify unit mode parameters and variables
Documentation/btrfs-device.txt | 26 ++++++++ Documentation/btrfs-filesystem.txt | 28 ++++++++ cmds-device.c | 66 ++++++++++++++---- cmds-fi-disk_usage.c | 133 ++++++++++++++++++++++++------------- cmds-fi-disk_usage.h | 4 +- 5 files changed, 197 insertions(+), 60 deletions(-)
Signature · 1 line
2.1.3
PATCH 1/6 btrfs-progs: fi usage, change option for tabular output to T
We're going to use -t for tera- units prefix, same as 'fi df' does.
--- cmds-fi-disk_usage.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
cmds-fi-disk_usage.c +3 -3
@@ -848,7 +848,7 @@ const char * const cmd_filesystem_usage_usage[] = {"Show in which disk the chunks are allocated." ,"" ,"-b\tSet byte as unit" , -"-t\tShow data in tabular format" , +"-T\tShow data in tabular format" , NULL };
@@ -861,7 +861,7 @@ int cmd_filesystem_usage(int argc, char **argv) optind =1 ;while (1 ) { -int c =getopt (argc, argv,"bt" ); +int c =getopt (argc, argv,"bT" );if (c <0 )break ;
@@ -870,7 +870,7 @@ int cmd_filesystem_usage(int argc, char **argv)case 'b' : mode =UNITS_RAW ;break ; -case 't' : +case 'T' : tabular =1 ;break ;default :
Signature · 1 line
2.1.3
PATCH 2/6 btrfs-progs: fi usage, add switches to set output units
In reply to David SterbaSame set of options as 'fi df': binary and decimal bases, human readable options etc.
--- cmds-fi-disk_usage.c | 64 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 11 deletions(-)
cmds-fi-disk_usage.c +53 -11
@@ -21,6 +21,7 @@#include <sys/ioctl.h> #include <errno.h> #include <stdarg.h> +#include <getopt.h> #include "utils.h" #include "kerncompat.h"
@@ -844,31 +845,72 @@ out: }const char *const cmd_filesystem_usage_usage[] = { -"btrfs filesystem usage [-b][-t] <path> [<path>..]" , -"Show in which disk the chunks are allocated." , -"" , -"-b\tSet byte as unit" , -"-T\tShow data in tabular format" , +"btrfs filesystem usage [options] <path> [<path>..]" , +"Show detailed information about internal filesystem usage ." , +"-b|--raw raw numbers in bytes" , +"-h human friendly numbers, base 1024 (default)" , +"-H human friendly numbers, base 1000" , +"--iec use 1024 as a base (KiB, MiB, GiB, TiB)" , +"--si use 1000 as a base (kB, MB, GB, TB)" , +"-k|--kbytes show sizes in KiB, or kB with --si" , +"-m|--mbytes show sizes in MiB, or MB with --si" , +"-g|--gbytes show sizes in GiB, or GB with --si" , +"-t|--tbytes show sizes in TiB, or TB with --si" , +"-T show data in tabular format" ,NULL };int cmd_filesystem_usage (int argc,char **argv) { -int mode =UNITS_HUMAN ; +unsigned unit_mode =UNITS_DEFAULT ;int ret =0 ;int i, more_than_one =0 ;int tabular =0 ; optind =1 ;while (1 ) { -int c =getopt (argc, argv,"bT" ); +int long_index; +static const struct option long_options[] = { + {"raw" , no_argument,NULL ,'b' }, + {"kbytes" , no_argument,NULL ,'k' }, + {"mbytes" , no_argument,NULL ,'m' }, + {"gbytes" , no_argument,NULL ,'g' }, + {"tbytes" , no_argument,NULL ,'t' }, + {"si" , no_argument,NULL ,256 }, + {"iec" , no_argument,NULL ,257 }, + }; +int c =getopt_long (argc, argv,"bhHkmgtT" , long_options, + &long_index);if (c <0 )break ; -switch (c) {case 'b' : - mode =UNITS_RAW ; + unit_mode =UNITS_RAW ; +break ; +case 'k' : +units_set_base (&unit_mode,UNITS_KBYTES ); +break ; +case 'm' : +units_set_base (&unit_mode,UNITS_MBYTES ); +break ; +case 'g' : +units_set_base (&unit_mode,UNITS_GBYTES ); +break ; +case 't' : +units_set_base (&unit_mode,UNITS_TBYTES ); +break ; +case 'h' : + unit_mode =UNITS_HUMAN_BINARY ; +break ; +case 'H' : + unit_mode =UNITS_HUMAN_DECIMAL ; +break ; +case 256 : +units_set_mode (&unit_mode,UNITS_DECIMAL ); +break ; +case 257 : +units_set_mode (&unit_mode,UNITS_BINARY );break ;case 'T' : tabular =1 ;
@@ -905,12 +947,12 @@ int cmd_filesystem_usage(int argc, char **argv) goto cleanup; ret =print_filesystem_usage_overall (fd, chunkinfo, chunkcount, - devinfo, devcount, argv[i], mode); + devinfo, devcount, argv[i], unit_mode);if (ret) goto cleanup;printf ("\n" ); ret =print_filesystem_usage_by_chunk (fd, chunkinfo, chunkcount, - devinfo, devcount, argv[i], mode, tabular); + devinfo, devcount, argv[i], unit_mode, tabular); cleanup:close_file_or_dir (fd, dirstream);free (chunkinfo);
Signature · 1 line
2.1.3
PATCH 3/6 btrfs-progs: fi usage, update manpage
In reply to David Sterba--- Documentation/btrfs-filesystem.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
Documentation/btrfs-filesystem.txt +28 -0
@@ -123,6 +123,34 @@ Show or update the label of a filesystem. If a newlabel optional argument is passed, the label is changed. NOTE: the maximum allowable length shall be less than 256 chars +*usage* [options] <path> [<path>...]:: +Show detailed information about internal filesystem usage. ++ +`Options` ++ +-b|--raw:::: +raw numbers in bytes, without the 'B' suffix +-h:::: +print human friendly numbers, base 1024, this is the default +-H:::: +print human friendly numbers, base 1000 +--iec:::: +select the 1024 base for the following options, according to the IEC standard +--si:::: +select the 1000 base for the following options, according to the SI standard +-k|--kbytes:::: +show sizes in KiB, or kB with --si +-m|--mbytes:::: +show sizes in MiB, or MB with --si +-g|--gbytes:::: +show sizes in GiB, or GB with --si +-t|--tbytes:::: +show sizes in TiB, or TB with --si +-T:::: +show data in tabular format + +If conflicting options are passed, the last one takes precedence. + EXIT STATUS ----------- *btrfs filesystem* returns a zero exit status if it succeeds. Non zero is
Signature · 1 line
2.1.3
Re: [PATCH 3/6] btrfs-progs: fi usage, update manpage
Hi David,
Quoted 10 lines · David Sterba
Signed-off-by David Sterba <[email protected]>--- Documentation/btrfs-filesystem.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)Documentation/btrfs-filesystem.txt +0
-0
Documentation/btrfs-filesystem.txt Show or update the label of a filesystem. · line 127
Quoted 5 lines
Documentation/btrfs-filesystem.txt +2
-0@@ -123,6 +123,34 @@ Show or update the label of a filesystem. If a newlabel optional argument is passed, the label is changed. NOTE: the maximum allowable length shall be less than 256 chars +*usage* [options] <path> [<path>...]:: +Show detailed information about internal filesystem usage.
Options from "-b" to "-t" are the completely same as "btrfs fi df"'s ones. So how about pointing the df's options as follows?
===============================================================================
...
+Options
+
-T::::
Show data in tabular format
+
There are some option to set unit. See description of *df*'s options from '-b' to '-t'.
+
If conflicting options are passed, the last one takes precedence.
...
===============================================================================
I consider it can prevent mistakes caused by further changes.
Thanks,
Satoru
Quoted 30 lines
Documentation/btrfs-filesystem.txt +26
-0++ +`Options` ++ +-b|--raw:::: +raw numbers in bytes, without the 'B' suffix +-h:::: +print human friendly numbers, base 1024, this is the default +-H:::: +print human friendly numbers, base 1000 +--iec:::: +select the 1024 base for the following options, according to the IEC standard +--si:::: +select the 1000 base for the following options, according to the SI standard +-k|--kbytes:::: +show sizes in KiB, or kB with --si +-m|--mbytes:::: +show sizes in MiB, or MB with --si +-g|--gbytes:::: +show sizes in GiB, or GB with --si +-t|--tbytes:::: +show sizes in TiB, or TB with --si +-T:::: +show data in tabular format + +If conflicting options are passed, the last one takes precedence. + EXIT STATUS ----------- *btrfs filesystem* returns a zero exit status if it succeeds. Non zero is
Re: [PATCH 3/6] btrfs-progs: fi usage, update manpage
Hi David,
Quoted 35 lines · David Sterba
Quoted 10 lines
Signed-off-by David Sterba <[email protected]>--- Documentation/btrfs-filesystem.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)Documentation/btrfs-filesystem.txt +0
-0Documentation/btrfs-filesystem.txt Show or update the label of a filesystem. · line 127
Quoted 5 lines
Documentation/btrfs-filesystem.txt +2
-0@@ -123,6 +123,34 @@ Show or update the label of a filesystem. If a newlabel optional argument is passed, the label is changed. NOTE: the maximum allowable length shall be less than 256 chars +*usage* [options] <path> [<path>...]:: +Show detailed information about internal filesystem usage.Options from "-b" to "-t" are the completely same as "btrfs fi df"'s ones. So how about pointing the df's options as follows?
===============================================================================
...
+Options(quoted diff) +1
-1+ -T::::Show data in tabular format
+
There are some option to set unit. See description of *df*'s options from '-b' to '-t'.
+
If conflicting options are passed, the last one takes precedence.
...
===============================================================================
Quoted 1 line
I consider it can prevent mistakes caused by further changes.
This patch seems to already be in devel/integration-20141218. Here is the patch example.
---
From: Satoru Takeuchi <[email protected]>
Subject: [PATCH] btrfs-progs: Cleanup: Fix the redundancy of btrfs-filesystem.
--- Documentation/btrfs-filesystem.txt | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
Documentation/btrfs-filesystem.txt +3 -18
@@ -128,27 +128,12 @@ Show detailed information about internal filesystem usage. + `Options` + --b|--raw:::: -raw numbers in bytes, without the 'B' suffix --h:::: -print human friendly numbers, base 1024, this is the default --H:::: -print human friendly numbers, base 1000 ---iec:::: -select the 1024 base for the following options, according to the IEC standard ---si:::: -select the 1000 base for the following options, according to the SI standard --k|--kbytes:::: -show sizes in KiB, or kB with --si --m|--mbytes:::: -show sizes in MiB, or MB with --si --g|--gbytes:::: -show sizes in GiB, or GB with --si --t|--tbytes:::: -show sizes in TiB, or TB with --si -T:::: show data in tabular format +There are some options to set unit. See the description of *df* subcommand +from '-b' option to '-t' option. + If conflicting options are passed, the last one takes precedence. EXIT STATUS
Signature · 1 line
1.8.3.1
Re: [PATCH 3/6] btrfs-progs: fi usage, update manpage
Documentation/btrfs-filesystem.txt Show detailed information about internal filesystem usage. · line 135
Quoted 2 lines · Satoru Takeuchi
Documentation/btrfs-filesystem.txt +2
-0+There are some options to set unit. See the description of *df* subcommand +from '-b' option to '-t' option.
The unit options exist only for very few subcommands so I found it more convenient to list all of them near to the command itself rather than pointing somewhere else.
Re: [PATCH 3/6] btrfs-progs: fi usage, update manpage
Quoted 8 lines · David Sterba
Documentation/btrfs-filesystem.txt Show detailed information about internal filesystem usage. · line 135
Quoted 2 lines · Satoru Takeuchi
Documentation/btrfs-filesystem.txt +2
-0+There are some options to set unit. See the description of *df* subcommand +from '-b' option to '-t' option.The unit options exist only for very few subcommands so I found it more convenient to list all of them near to the command itself rather than pointing somewhere else.
OK, got it.
Thanks,
Satoru
PATCH 4/6 btrfs-progs: dev usage, add switches to set output units
In reply to David SterbaSame set of options as 'fi df': binary and decimal bases, human readable options etc.
--- cmds-device.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 10 deletions(-)
cmds-device.c +50 -10
@@ -451,10 +451,17 @@ out: }const char *const cmd_device_usage_usage[] = { -"btrfs device usage [-b] <path> [<path>..]" , -"Show which chunks are in a device." , -"" , -"-b\tSet byte as unit" , +"btrfs device usage [options] <path> [<path>..]" , +"Show detailed information about internal allocations in devices." , +"-b|--raw raw numbers in bytes" , +"-h human friendly numbers, base 1024 (default)" , +"-H human friendly numbers, base 1000" , +"--iec use 1024 as a base (KiB, MiB, GiB, TiB)" , +"--si use 1000 as a base (kB, MB, GB, TB)" , +"-k|--kbytes show sizes in KiB, or kB with --si" , +"-m|--mbytes show sizes in MiB, or MB with --si" , +"-g|--gbytes show sizes in GiB, or GB with --si" , +"-t|--tbytes show sizes in TiB, or TB with --si" ,NULL };
@@ -489,21 +496,54 @@ out:int cmd_device_usage (int argc,char **argv) { - -int mode =UNITS_HUMAN ; +unsigned unit_mode =UNITS_DEFAULT ;int ret =0 ;int i, more_than_one =0 ; optind =1 ;while (1 ) { -int c =getopt (argc, argv,"b" ); +int long_index; +static const struct option long_options[] = { + {"raw" , no_argument,NULL ,'b' }, + {"kbytes" , no_argument,NULL ,'k' }, + {"mbytes" , no_argument,NULL ,'m' }, + {"gbytes" , no_argument,NULL ,'g' }, + {"tbytes" , no_argument,NULL ,'t' }, + {"si" , no_argument,NULL ,256 }, + {"iec" , no_argument,NULL ,257 }, + }; +int c =getopt_long (argc, argv,"bhHkmgt" , long_options, + &long_index);if (c <0 )break ; -switch (c) {case 'b' : - mode =UNITS_RAW ; + unit_mode =UNITS_RAW ; +break ; +case 'k' : +units_set_base (&unit_mode,UNITS_KBYTES ); +break ; +case 'm' : +units_set_base (&unit_mode,UNITS_MBYTES ); +break ; +case 'g' : +units_set_base (&unit_mode,UNITS_GBYTES ); +break ; +case 't' : +units_set_base (&unit_mode,UNITS_TBYTES ); +break ; +case 'h' : + unit_mode =UNITS_HUMAN_BINARY ; +break ; +case 'H' : + unit_mode =UNITS_HUMAN_DECIMAL ; +break ; +case 256 : +units_set_mode (&unit_mode,UNITS_DECIMAL ); +break ; +case 257 : +units_set_mode (&unit_mode,UNITS_BINARY );break ;default :usage (cmd_device_usage_usage);
@@ -527,7 +567,7 @@ int cmd_device_usage(int argc, char **argv) goto out; } - ret =_cmd_device_usage (fd, argv[i], mode); + ret =_cmd_device_usage (fd, argv[i], unit_mode);close_file_or_dir (fd, dirstream);if (ret)
Signature · 1 line
2.1.3
PATCH 5/6 btrfs-progs: dev usage, update manpage
In reply to David Sterba--- Documentation/btrfs-device.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
Documentation/btrfs-device.txt +26 -0
@@ -98,6 +98,32 @@ identified by <path> or for a single <device>. -z:::: Reset stats to zero after reading them. +*usage* [options] <path> [<path>...]:: +Show detailed information about internal allocations in devices. ++ +`Options` ++ +-b|--raw:::: +raw numbers in bytes, without the 'B' suffix +-h:::: +print human friendly numbers, base 1024, this is the default +-H:::: +print human friendly numbers, base 1000 +--iec:::: +select the 1024 base for the following options, according to the IEC standard +--si:::: +select the 1000 base for the following options, according to the SI standard +-k|--kbytes:::: +show sizes in KiB, or kB with --si +-m|--mbytes:::: +show sizes in MiB, or MB with --si +-g|--gbytes:::: +show sizes in GiB, or GB with --si +-t|--tbytes:::: +show sizes in TiB, or TB with --si + +If conflicting options are passed, the last one takes precedence. + EXIT STATUS ----------- *btrfs device* returns a zero exit status if it succeeds. Non zero is
Signature · 1 line
2.1.3
PATCH 6/6 btrfs-progs: unify unit mode parameters and variables
In reply to David SterbaUse unsigned type and a common name everywhere.
--- cmds-device.c | 6 ++--- cmds-fi-disk_usage.c | 69 ++++++++++++++++++++++++++-------------------------- cmds-fi-disk_usage.h | 4 +-- 3 files changed, 40 insertions(+), 39 deletions(-)
cmds-device.c +3 -3
@@ -465,7 +465,7 @@ const char * const cmd_device_usage_usage[] = { NULL }; -static int _cmd_device_usage (int fd,char *path,int mode) +static int _cmd_device_usage (int fd,char *path,unsigned unit_mode) {int i;int ret =0 ;
@@ -481,9 +481,9 @@ static int _cmd_device_usage(int fd, char *path, int mode)for (i =0 ; i < devcount; i++) {printf ("%s, ID: %llu\n" , devinfo[i].path, devinfo[i].devid); -print_device_sizes (fd, &devinfo[i], mode); +print_device_sizes (fd, &devinfo[i], unit_mode);print_device_chunks (fd, &devinfo[i], chunkinfo, chunkcount, - mode); + unit_mode);printf ("\n" ); }
cmds-fi-disk_usage.c +35 -34
210 lines not on this page · raw message
cmds-fi-disk_usage.h +2 -2
@@ -48,7 +48,7 @@ int load_chunk_and_device_info(int fd, struct chunk_info **chunkinfo, int *chunkcount, struct device_info **devinfo, int *devcount);void print_device_chunks (int fd,struct device_info *devinfo,struct chunk_info *chunks_info_ptr, -int chunks_info_count,int mode); -void print_device_sizes (int fd,struct device_info *devinfo,int mode); +int chunks_info_count,unsigned unit_mode); +void print_device_sizes (int fd,struct device_info *devinfo,unsigned unit_mode);#endif
Signature · 1 line
2.1.3