linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: make btrfs qgroups show human readable sizes
@ 2015-01-09  6:47 Fan Chengniang
  2015-01-09 13:48 ` Christian Robottom Reis
  2015-01-09 18:03 ` David Sterba
  0 siblings, 2 replies; 5+ messages in thread
From: Fan Chengniang @ 2015-01-09  6:47 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Fan Chengniang

make btrfs qgroups show human readable sizes, using -h option, example:

qgroupid rfer         excl         max_rfer     max_excl     parent  child
-------- ----         ----         --------     --------     ------  -----
0/5      299.58MiB    299.58MiB    400.00MiB    0.00B        1/1     ---
0/265    299.58MiB    16.00KiB     0.00B        320.00MiB    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>
---
 Documentation/btrfs-qgroup.txt |  2 ++
 cmds-qgroup.c                  |  6 +++++-
 qgroup.c                       | 46 ++++++++++++++++++++++++++++++++++--------
 qgroup.h                       |  1 +
 4 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/Documentation/btrfs-qgroup.txt b/Documentation/btrfs-qgroup.txt
index 3e13373..6a3d649 100644
--- a/Documentation/btrfs-qgroup.txt
+++ b/Documentation/btrfs-qgroup.txt
@@ -69,6 +69,8 @@ print child qgroup id.
 print max referenced size of qgroup.
 -e::::
 print max exclusive size of qgroup.
+-h::::
+print sizes in human readable format (e.g., 1KiB 234MiB 2GiB).
 -F::::
 list all qgroups which impact the given path(include ancestral qgroups)
 -f::::
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 957fbc9..c2bd0a3 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -212,6 +212,7 @@ static const char * const cmd_qgroup_show_usage[] = {
 	"-c		print child qgroup id",
 	"-r		print max referenced size of qgroup",
 	"-e		print max exclusive size of qgroup",
+	"-h		print sizes in human readable format (e.g., 1KiB 234MiB 2GiB)",
 	"-F		list all qgroups which impact the given path"
 	"(include ancestral qgroups)",
 	"-f		list all qgroups which impact the given path"
@@ -246,7 +247,7 @@ static int cmd_qgroup_show(int argc, char **argv)
 
 	optind = 1;
 	while (1) {
-		c = getopt_long(argc, argv, "pcreFf",
+		c = getopt_long(argc, argv, "pcrehFf",
 				long_options, NULL);
 		if (c < 0)
 			break;
@@ -267,6 +268,9 @@ static int cmd_qgroup_show(int argc, char **argv)
 			btrfs_qgroup_setup_print_column(
 				BTRFS_QGROUP_MAX_EXCL);
 			break;
+		case 'h':
+			btrfs_qgroup_setup_human_readable();
+			break;
 		case 'F':
 			filter_flag |= 0x1;
 			break;
diff --git a/qgroup.c b/qgroup.c
index 1a4866c..5cb239e 100644
--- a/qgroup.c
+++ b/qgroup.c
@@ -20,6 +20,7 @@
 #include <sys/ioctl.h>
 #include "ctree.h"
 #include "ioctl.h"
+#include "utils.h"
 
 #define BTRFS_QGROUP_NFILTERS_INCREASE (2 * BTRFS_QGROUP_FILTER_MAX)
 #define BTRFS_QGROUP_NCOMPS_INCREASE (2 * BTRFS_QGROUP_COMP_MAX)
@@ -80,53 +81,62 @@ static struct {
 	char *name;
 	char *column_name;
 	int need_print;
+	int human_readable;
 	int max_len;
 } btrfs_qgroup_columns[] = {
 	{
 		.name		= "qgroupid",
 		.column_name	= "Qgroupid",
 		.need_print	= 1,
+		.human_readable = 0,
 		.max_len	= 8,
 	},
 	{
 		.name		= "rfer",
 		.column_name	= "Rfer",
 		.need_print	= 1,
-		.max_len	= 4,
+		.human_readable = 0,
+		.max_len	= 12,
 	},
 	{
 		.name		= "excl",
 		.column_name	= "Excl",
 		.need_print	= 1,
-		.max_len	= 4,
+		.human_readable = 0,
+		.max_len	= 12,
 	},
 	{	.name		= "max_rfer",
 		.column_name	= "Max_rfer",
 		.need_print	= 0,
-		.max_len	= 8,
+		.human_readable = 0,
+		.max_len	= 12,
 	},
 	{
 		.name		= "max_excl",
 		.column_name	= "Max_excl",
 		.need_print	= 0,
-		.max_len	= 8,
+		.human_readable = 0,
+		.max_len	= 12,
 	},
 	{
 		.name		= "parent",
 		.column_name	= "Parent",
 		.need_print	= 0,
+		.human_readable = 0,
 		.max_len	= 7,
 	},
 	{
 		.name		= "child",
 		.column_name	= "Child",
 		.need_print	= 0,
+		.human_readable = 0,
 		.max_len	= 5,
 	},
 	{
 		.name		= NULL,
 		.column_name	= NULL,
 		.need_print	= 0,
+		.human_readable = 0,
 	},
 };
 
@@ -147,6 +157,14 @@ void btrfs_qgroup_setup_print_column(enum btrfs_qgroup_column_enum column)
 		btrfs_qgroup_columns[i].need_print = 1;
 }
 
+void btrfs_qgroup_setup_human_readable(void)
+{
+	btrfs_qgroup_columns[BTRFS_QGROUP_RFER].human_readable = 1;
+	btrfs_qgroup_columns[BTRFS_QGROUP_EXCL].human_readable = 1;
+	btrfs_qgroup_columns[BTRFS_QGROUP_MAX_RFER].human_readable = 1;
+	btrfs_qgroup_columns[BTRFS_QGROUP_MAX_EXCL].human_readable = 1;
+}
+
 static int print_parent_column(struct btrfs_qgroup *qgroup)
 {
 	struct btrfs_qgroup_list *list = NULL;
@@ -203,11 +221,17 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup,
 		print_qgroup_column_add_blank(BTRFS_QGROUP_QGROUPID, len);
 		break;
 	case BTRFS_QGROUP_RFER:
-		len = printf("%llu", qgroup->rfer);
+		if (btrfs_qgroup_columns[column].human_readable)
+			len = printf("%s", pretty_size(qgroup->rfer));
+		else
+			len = printf("%llu", qgroup->rfer);
 		print_qgroup_column_add_blank(BTRFS_QGROUP_RFER, len);
 		break;
 	case BTRFS_QGROUP_EXCL:
-		len = printf("%llu", qgroup->excl);
+		if (btrfs_qgroup_columns[column].human_readable)
+			len = printf("%s", pretty_size(qgroup->excl));
+		else
+			len = printf("%llu", qgroup->excl);
 		print_qgroup_column_add_blank(BTRFS_QGROUP_EXCL, len);
 		break;
 	case BTRFS_QGROUP_PARENT:
@@ -215,11 +239,17 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup,
 		print_qgroup_column_add_blank(BTRFS_QGROUP_PARENT, len);
 		break;
 	case BTRFS_QGROUP_MAX_RFER:
-		len = printf("%llu", qgroup->max_rfer);
+		if (btrfs_qgroup_columns[column].human_readable)
+			len = printf("%s", pretty_size(qgroup->max_rfer));
+		else
+			len = printf("%llu", qgroup->max_rfer);
 		print_qgroup_column_add_blank(BTRFS_QGROUP_MAX_RFER, len);
 		break;
 	case BTRFS_QGROUP_MAX_EXCL:
-		len = printf("%llu", qgroup->max_excl);
+		if (btrfs_qgroup_columns[column].human_readable)
+			len = printf("%s", pretty_size(qgroup->max_excl));
+		else
+			len = printf("%llu", qgroup->max_excl);
 		print_qgroup_column_add_blank(BTRFS_QGROUP_MAX_EXCL, len);
 		break;
 	case BTRFS_QGROUP_CHILD:
diff --git a/qgroup.h b/qgroup.h
index 653cf1c..cc8ae29 100644
--- a/qgroup.h
+++ b/qgroup.h
@@ -83,6 +83,7 @@ u64 btrfs_get_path_rootid(int fd);
 int btrfs_show_qgroups(int fd, struct btrfs_qgroup_filter_set *,
 		       struct btrfs_qgroup_comparer_set *);
 void btrfs_qgroup_setup_print_column(enum btrfs_qgroup_column_enum column);
+void btrfs_qgroup_setup_human_readable(void);
 struct btrfs_qgroup_filter_set *btrfs_qgroup_alloc_filter_set(void);
 void btrfs_qgroup_free_filter_set(struct btrfs_qgroup_filter_set *filter_set);
 int btrfs_qgroup_setup_filter(struct btrfs_qgroup_filter_set **filter_set,
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs-progs: make btrfs qgroups show human readable sizes
  2015-01-09  6:47 [PATCH] btrfs-progs: make btrfs qgroups show human readable sizes Fan Chengniang
@ 2015-01-09 13:48 ` Christian Robottom Reis
  2015-01-09 17:58   ` David Sterba
  2015-01-09 18:03 ` David Sterba
  1 sibling, 1 reply; 5+ messages in thread
From: Christian Robottom Reis @ 2015-01-09 13:48 UTC (permalink / raw)
  To: Fan Chengniang; +Cc: linux-btrfs

On Fri, Jan 09, 2015 at 02:47:05PM +0800, Fan Chengniang wrote:
> make btrfs qgroups show human readable sizes, using -h option, example:

Oh! This is really nice. I wonder, would there be a sane way to show the
actual path the qgroup is associated with as well?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs-progs: make btrfs qgroups show human readable sizes
  2015-01-09 13:48 ` Christian Robottom Reis
@ 2015-01-09 17:58   ` David Sterba
  0 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2015-01-09 17:58 UTC (permalink / raw)
  To: Christian Robottom Reis; +Cc: Fan Chengniang, linux-btrfs

On Fri, Jan 09, 2015 at 11:48:53AM -0200, Christian Robottom Reis wrote:
> On Fri, Jan 09, 2015 at 02:47:05PM +0800, Fan Chengniang wrote:
> > make btrfs qgroups show human readable sizes, using -h option, example:
> 
> Oh! This is really nice. I wonder, would there be a sane way to show the
> actual path the qgroup is associated with as well?

Yes, it's basically what 'btrfs inspect subvolid-resolve 1234 /path'
does. This obviously works only for the 0-level qgroups.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs-progs: make btrfs qgroups show human readable sizes
  2015-01-09  6:47 [PATCH] btrfs-progs: make btrfs qgroups show human readable sizes Fan Chengniang
  2015-01-09 13:48 ` Christian Robottom Reis
@ 2015-01-09 18:03 ` David Sterba
  2015-01-12  3:00   ` Fan Chengniang/樊成酿
  1 sibling, 1 reply; 5+ messages in thread
From: David Sterba @ 2015-01-09 18:03 UTC (permalink / raw)
  To: Fan Chengniang; +Cc: linux-btrfs

On Fri, Jan 09, 2015 at 02:47:05PM +0800, Fan Chengniang wrote:
> make btrfs qgroups show human readable sizes, using -h option, example:

Thanks.  Please add all the long options from the 'fi df' subcommands as
well. As the subcommand is not entierly space & size oriented, I'd like
to keep the single letter options unallocated for now.

> @@ -80,53 +81,62 @@ static struct {
>  	char *name;
>  	char *column_name;
>  	int need_print;
> +	int human_readable;

Would be better to make it more generic and store the format type
directly, then use it ...

> @@ -203,11 +221,17 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup,
>  		print_qgroup_column_add_blank(BTRFS_QGROUP_QGROUPID, len);
>  		break;
>  	case BTRFS_QGROUP_RFER:
> -		len = printf("%llu", qgroup->rfer);
> +		if (btrfs_qgroup_columns[column].human_readable)
> +			len = printf("%s", pretty_size(qgroup->rfer));
> +		else
> +			len = printf("%llu", qgroup->rfer);

... here instead of the switch, something like

	pretty_size_mode(number, btrfs_qgroup_columns[column].format);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs-progs: make btrfs qgroups show human readable sizes
  2015-01-09 18:03 ` David Sterba
@ 2015-01-12  3:00   ` Fan Chengniang/樊成酿
  0 siblings, 0 replies; 5+ messages in thread
From: Fan Chengniang/樊成酿 @ 2015-01-12  3:00 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs


在 2015年01月10日 02:03, David Sterba 写道:
> On Fri, Jan 09, 2015 at 02:47:05PM +0800, Fan Chengniang wrote:
>> make btrfs qgroups show human readable sizes, using -h option, example:
> Thanks.  Please add all the long options from the 'fi df' subcommands as
> well. As the subcommand is not entierly space & size oriented, I'd like
> to keep the single letter options unallocated for now.
>
I will use --human to subsititute -h option. Should I add other long 
options like --kbytes --mbytes --gbytes --tbytes --si --iec?
>> @@ -80,53 +81,62 @@ static struct {
>>   	char *name;
>>   	char *column_name;
>>   	int need_print;
>> +	int human_readable;
> Would be better to make it more generic and store the format type
> directly, then use it ...
I will merge need_print and human_readable into one variable.
>> @@ -203,11 +221,17 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup,
>>   		print_qgroup_column_add_blank(BTRFS_QGROUP_QGROUPID, len);
>>   		break;
>>   	case BTRFS_QGROUP_RFER:
>> -		len = printf("%llu", qgroup->rfer);
>> +		if (btrfs_qgroup_columns[column].human_readable)
>> +			len = printf("%s", pretty_size(qgroup->rfer));
>> +		else
>> +			len = printf("%llu", qgroup->rfer);
> ... here instead of the switch, something like
>
> 	pretty_size_mode(number, btrfs_qgroup_columns[column].format);
I wiil try to remove switch.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-01-12  3:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-09  6:47 [PATCH] btrfs-progs: make btrfs qgroups show human readable sizes Fan Chengniang
2015-01-09 13:48 ` Christian Robottom Reis
2015-01-09 17:58   ` David Sterba
2015-01-09 18:03 ` David Sterba
2015-01-12  3:00   ` Fan Chengniang/樊成酿

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).