[PATCH] btrfs-progs:qgroup:make large size aligned
problem: when the size is too big, the output format will be unaligned. the __update__columns_max_len function has been updated to fix this problem Signed-off-by: Fan Chengniang --- In my patch "[PATCH v3] make btrfs qgroups show human readable sizes" I forget to update the function __update__columns_max_len which may cause large size unaligned. qgroup.c | 13 + 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/qgroup.c b/qgroup.c index 8ec55df..3e4a6ed 100644 --- a/qgroup.c +++ b/qgroup.c @@ -915,6 +915,7 @@ static void __update_columns_max_len(struct btrfs_qgroup *bq, struct btrfs_qgroup_list *list = NULL; char tmp[100]; int len; + unsigned unit_mode = btrfs_qgroup_columns[column].unit_mode; switch (column) { @@ -926,26 +927,22 @@ static void __update_columns_max_len(struct btrfs_qgroup *bq, btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_RFER: - sprintf(tmp, "%llu", bq->rfer); - len = strlen(tmp); + len = strlen(pretty_size_mode(bq->rfer, unit_mode)); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_EXCL: - sprintf(tmp, "%llu", bq->excl); - len = strlen(tmp); + len = strlen(pretty_size_mode(bq->excl, unit_mode)); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_MAX_RFER: - sprintf(tmp, "%llu", bq->max_rfer); - len = strlen(tmp); + len = strlen(pretty_size_mode(bq->max_rfer, unit_mode)); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_MAX_EXCL: - sprintf(tmp, "%llu", bq->max_excl); - len = strlen(tmp); + len = strlen(pretty_size_mode(bq->max_excl, unit_mode)); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4] btrfs-progs: make btrfs qgroups show human readable sizes
在 2015年01月23日 00:24, David Sterba 写道: On Thu, Jan 22, 2015 at 04:11:43PM +0800, Fan Chengniang wrote: v3: - remove --human-readable option - add --raw, --si, --iec, --kbytes, --mbytes, --gbytes, --tbytes options - by default, sizes are shown in human readable format - make columns which show sizes align to right. Others aligned to left. v4: - change default output be raw, instead of human readable.Because xfstest result depend on the raw output. I've merged v3, that's what we want to present to the user. I'll send a patch to fstests to force the raw bytes output. there is a bug in v3 which will cause the output format unaligned. I found it and fix it in v4. I will send it to you. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v4] 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 37.90MiB 37.90MiB 1.00GiB0.00B 1/1,1/2 --- 0/256144.00KiB 144.00KiB0.00B0.00B 1/2 --- 1/1 37.90MiB 37.90MiB0.00B0.00B --- 0/5 1/2 38.04MiB 38.04MiB0.00B0.00B --- 0/5,0/256 Signed-off-by: Fan Chengniang --- v2: - change -h option to --human-readable - merge need_print and human_readable into format - add print_group_size function v3: - remove --human-readable option - add --raw, --si, --iec, --kbytes, --mbytes, --gbytes, --tbytes options - by default, sizes are shown in human readable format - make columns which show sizes align to right. Others aligned to left. v4: - change default output be raw, instead of human readable.Because xfstest result depend on the raw output. Documentation/btrfs-qgroup.txt | 14 cmds-qgroup.c | 59 -- qgroup.c | 82 +++--- qgroup.h | 1 + 4 files changed, 117 insertions(+), 39 deletions(-) diff --git a/Documentation/btrfs-qgroup.txt b/Documentation/btrfs-qgroup.txt index 3e13373..89dbd6c 100644 --- a/Documentation/btrfs-qgroup.txt +++ b/Documentation/btrfs-qgroup.txt @@ -73,6 +73,20 @@ print max exclusive size of qgroup. list all qgroups which impact the given path(include ancestral qgroups) -f list all qgroups which impact the given path(exclude ancestral qgroups) +--raw +raw numbers in bytes, without the 'B' suffix. +--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. +--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=[\+/-][,[+/-]]... list qgroups in order of . + diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 957fbc9..2883ca2 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] ", "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 }; @@ -234,6 +241,8 @@ static int cmd_qgroup_show(int argc, char **argv) int c; u64 qgroupid; int filter_flag = 0; + int option_index = 0; + unsigned unit_mode = UNITS_RAW; struct btrfs_qgroup_comparer_set *comparer_set; struct btrfs_qgroup_filter_set *filter_set; @@ -241,16 +250,41 @@ static int cm
Re: [PATCH v3] btrfs-progs: make btrfs qgroups show human readable sizes
在 2015年01月19日 15:31, Wang Shilong 写道: Hello, 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.58MiB299.58MiB300.00MiB300.00MiB 1/1 --- 0/265 299.58MiB 16.00KiB400.00MiB0.00B 1/1 --- 0/266 299.58MiB 16.00KiB350.00MiB0.00B --- --- 1/1 599.16MiB299.59MiB800.00MiB0.00B --- 0/5,0/265 Signed-off-by: Fan Chengniang --- v2: - change -h option to --human-readable - merge need_print and human_readable into format - add print_group_size function v3: - remove --human-readable option - add --raw, --si, --iec, --kbytes, --mbytes, --gbytes, --tbytes options - by default, sizes are shown in human readable format Oh, really... Have you run with this patch with xfstests? I am not sure whether some qgroup tests could pass this, if not you need keep default raw output, or please modify xfstests to make it pass. I will test and repair it.thanx - make columns which show sizes align to right. Othersligned to left. Documentation/btrfs-qgroup.txt | 14 cmds-qgroup.c | 56 -- qgroup.c | 77 -- qgroup.h | 1 + 4 files changed, 113 insertions(+), 35 deletions(-) diff --git a/Documentation/btrfs-qgroup.txt b/Documentation/btrfs-qgroup.txt index 3e13373..89dbd6c 100644 --- a/Documentation/btrfs-qgroup.txt +++ b/Documentation/btrfs-qgroup.txt @@ -73,6 +73,20 @@ print max exclusive size of qgroup. list all qgroups which impact the given path(include ancestral qgroups) -f list all qgroups which impact the given path(exclude ancestral qgroups) +--raw +raw numbers in bytes, without the 'B' suffix. +--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. +--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=[\+/-][,[+/-]]... list qgroups in order of . + diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 957fbc9..2474251 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] ", "Show subvolume quota groups.", - "-pprint parent qgroup id", - "-cprint child qgroup id", - "-rprint max referenced size of qgroup", - "-eprint max exclusive size of qgroup", - "-Flist 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)", - "-flist 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 }; @@ -234,6 +241,8 @@ static int cmd_qgroup_show(int argc, char **argv) int c; u64 qgroupid;
[PATCH v2 2/2] btrfs-progs:btrfstune:fix multiple options error
when we use multiple options, error return status will be override by the last option status. example: btrfstune -S 1 -r /dev/loop0 when -S option fails and -r option succeeds, return value is 0, rather than 1, where 1 is the right return status. Reported-by: Chen Hanxiao Signed-off-by: Fan Chengniang --- btrfstune.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/btrfstune.c b/btrfstune.c index 15f68c8..075fbc6 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -114,6 +114,7 @@ int main(int argc, char *argv[]) { struct btrfs_root *root; int success = 0; + int total = 0; int extrefs_flag = 0; int seeding_flag = 0; u64 seeding_value = 0; @@ -190,19 +191,22 @@ int main(int argc, char *argv[]) ret = update_seeding_flag(root, seeding_value); if (!ret) success++; + total++; } if (extrefs_flag) { enable_extrefs_flag(root); success++; + total++; } if (skinny_flag) { enable_skinny_metadata(root); success++; + total++; } - if (success > 0) { + if (success == total) { ret = 0; } else { root->fs_info->readonly = 1; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 1/2] btrfs-progs:btrfstune:force to set seeding flags
Now we can use -f with -S option when setting seeding flags or clearing seeding flags Reported-by: Chen Hanxiao Signed-off-by: Fan Chengniang --- Documentation/btrfstune.txt | 2 +- btrfstune.c | 10 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Documentation/btrfstune.txt b/Documentation/btrfstune.txt index d49a974..2448e27 100644 --- a/Documentation/btrfstune.txt +++ b/Documentation/btrfstune.txt @@ -25,7 +25,7 @@ Enable extended inode refs. -x:: Enable skinny metadata extent refs. -f:: -Allow dangerous changes, e.g. clear the seeding flag +Force to set or clear seeding flag. Allow dangerous changes, e.g. clear the seeding flag When mounting the new device, btrfs will check whether the seeding flag is set when try to open seeding device. If the user clears the seeding flag of the diff --git a/btrfstune.c b/btrfstune.c index 050418a..15f68c8 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -33,6 +33,7 @@ #include "version.h" static char *device; +static int force = 0; static int update_seeding_flag(struct btrfs_root *root, int set_flag) { @@ -44,8 +45,10 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag) super_flags = btrfs_super_flags(disk_super); if (set_flag) { if (super_flags & BTRFS_SUPER_FLAG_SEEDING) { - fprintf(stderr, "seeding flag is already set on %s\n", - device); + if (force) + return 0; + else + fprintf(stderr, "seeding flag is already set on %s\n", device); return 1; } super_flags |= BTRFS_SUPER_FLAG_SEEDING; @@ -104,7 +107,7 @@ static void print_usage(void) fprintf(stderr, "\t-S value\tpositive value will enable seeding, zero to disable, negative is not allowed\n"); fprintf(stderr, "\t-r \t\tenable extended inode refs\n"); fprintf(stderr, "\t-x \t\tenable skinny metadata extent refs\n"); - fprintf(stderr, "\t-f \t\tforce to clear flags, make sure that you are aware of the dangers\n"); + fprintf(stderr, "\t-f \t\tforce to set or clear flags, make sure that you are aware of the dangers\n"); } int main(int argc, char *argv[]) @@ -115,7 +118,6 @@ int main(int argc, char *argv[]) int seeding_flag = 0; u64 seeding_value = 0; int skinny_flag = 0; - int force = 0; int ret; optind = 1; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3] 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.58MiB299.58MiB300.00MiB300.00MiB 1/1 --- 0/265 299.58MiB 16.00KiB400.00MiB0.00B 1/1 --- 0/266 299.58MiB 16.00KiB350.00MiB0.00B --- --- 1/1 599.16MiB299.59MiB800.00MiB0.00B --- 0/5,0/265 Signed-off-by: Fan Chengniang --- v2: - change -h option to --human-readable - merge need_print and human_readable into format - add print_group_size function v3: - remove --human-readable option - add --raw, --si, --iec, --kbytes, --mbytes, --gbytes, --tbytes options - by default, sizes are shown in human readable format - make columns which show sizes align to right. Others aligned to left. Documentation/btrfs-qgroup.txt | 14 cmds-qgroup.c | 56 -- qgroup.c | 77 -- qgroup.h | 1 + 4 files changed, 113 insertions(+), 35 deletions(-) diff --git a/Documentation/btrfs-qgroup.txt b/Documentation/btrfs-qgroup.txt index 3e13373..89dbd6c 100644 --- a/Documentation/btrfs-qgroup.txt +++ b/Documentation/btrfs-qgroup.txt @@ -73,6 +73,20 @@ print max exclusive size of qgroup. list all qgroups which impact the given path(include ancestral qgroups) -f list all qgroups which impact the given path(exclude ancestral qgroups) +--raw +raw numbers in bytes, without the 'B' suffix. +--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. +--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=[\+/-][,[+/-]]... list qgroups in order of . + diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 957fbc9..2474251 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] ", "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 }; @@ -234,6 +241,8 @@ static int cmd_qgroup_show(int argc, char **argv) int c; u64 qgroupid; int filter_flag = 0; + int option_index = 0; + unsigned unit_mode = UNITS_DEFAULT; struct btrfs_qgroup_comparer_set *comparer_set; struct btrfs_qgroup_filter_set *filter_set; @@ -241,16 +250,41 @@ static int cmd_qgroup_show(int argc, cha
Re: [PATCH 1/2] btrfs-progs:btrfstune: choose to ignore error when setting seeding enabled
在 2015年01月14日 23:48, David Sterba 写道: On Fri, Jan 09, 2015 at 04:11:41PM +0800, Fan Chengniang wrote: Before with -S option, setting positive value on seeding-enabled btrfs filesystem will cause error. So I add -i option which can ignore it. Why can't we use the existing --force/-f option for that? That is a good idea. I will use -f instead of adding -i. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 RESEND] btrfs-progs: make btrfs qgroups show human readable sizes
在 2015年01月14日 23:46, David Sterba 写道: On Tue, Jan 13, 2015 at 01:53:39PM +0800, Fan Chengniang wrote: make btrfs qgroups show human readable sizes using --human-readable option, example: That's too long to type and the idea was to add all the long options that force the specific unit base, ie. --kbytes/--mbytes/..., --raw, --si and --iec. We can possibly make the human readable the default because that's what I'd expect to see to have a quick overview and can use the other options otherwise. The geopt parser accepts short options if they're unique, so --kb or even --k works as a very convenient shorcut for frequent commandline use. I have sent a mail for your advise of adding options. In that mail, I asked whether I should use --human-readable and add --kbytes --mbytes ... But you have not reply to me. So, your advise is add --kbytes --mbytes ... and make human-readable default behaviour? qgroupid rfer excl max_rfer max_excl parent child -- - 0/5 299.58MiB299.58MiB400.00MiB0.00B1/1 --- 0/265299.58MiB16.00KiB 0.00B320.00MiB1/1 --- 0/266299.58MiB16.00KiB 350.00MiB0.00B--- --- 1/1 599.16MiB299.59MiB800.00MiB0.00B--- 0/5,0/265 The values should be also aligned to the right. It is aligned to left before my patch. I just keep it. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 RESEND] btrfs-progs: make btrfs qgroups show human readable sizes
make btrfs qgroups show human readable sizes using --human-readable option, example: qgroupid rfer excl max_rfer max_excl parent child -- - 0/5 299.58MiB299.58MiB400.00MiB0.00B1/1 --- 0/265299.58MiB16.00KiB 0.00B320.00MiB1/1 --- 0/266299.58MiB16.00KiB 350.00MiB0.00B--- --- 1/1 599.16MiB299.59MiB800.00MiB0.00B--- 0/5,0/265 Signed-off-by: Fan Chengniang --- v2: - change -h option to --human-readable - merge need_print and human_readable into format - add print_group_size function Documentation/btrfs-qgroup.txt | 2 ++ cmds-qgroup.c | 10 +- qgroup.c | 69 -- qgroup.h | 1 + 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/Documentation/btrfs-qgroup.txt b/Documentation/btrfs-qgroup.txt index 3e13373..d8ed028 100644 --- a/Documentation/btrfs-qgroup.txt +++ b/Documentation/btrfs-qgroup.txt @@ -73,6 +73,8 @@ print max exclusive size of qgroup. list all qgroups which impact the given path(include ancestral qgroups) -f list all qgroups which impact the given path(exclude ancestral qgroups) +--human-readable +print sizes in human readable format (e.g., 1KiB 234MiB 2GiB). --sort=[\+/-][,[+/-]]... list qgroups in order of . + diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 957fbc9..ba6f19b 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -216,6 +216,8 @@ static const char * const cmd_qgroup_show_usage[] = { "(include ancestral qgroups)", "-f list all qgroups which impact the given path" "(exclude ancestral qgroups)", + "--human-readable", + " print sizes in human readable format (e.g., 1KiB 234MiB 2GiB)", "--sort=qgroupid,rfer,excl,max_rfer,max_excl", " list qgroups in order of qgroupid," "rfer,max_rfer or max_excl", @@ -234,6 +236,7 @@ static int cmd_qgroup_show(int argc, char **argv) int c; u64 qgroupid; int filter_flag = 0; + int option_index = 0; struct btrfs_qgroup_comparer_set *comparer_set; struct btrfs_qgroup_filter_set *filter_set; @@ -241,16 +244,21 @@ static int cmd_qgroup_show(int argc, char **argv) comparer_set = btrfs_qgroup_alloc_comparer_set(); struct option long_options[] = { {"sort", 1, NULL, 'S'}, + {"human-readable", 0, NULL, 0}, {0, 0, 0, 0} }; optind = 1; while (1) { c = getopt_long(argc, argv, "pcreFf", - long_options, NULL); + long_options, &option_index); if (c < 0) break; switch (c) { + case 0: + if (option_index == 1) + btrfs_qgroup_setup_human_readable(); + break; case 'p': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_PARENT); diff --git a/qgroup.c b/qgroup.c index 1a4866c..ce87fe4 100644 --- a/qgroup.c +++ b/qgroup.c @@ -20,10 +20,14 @@ #include #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) +#define BTRFS_QGROUP_FORMAT_PRINT 1 +#define BTRFS_QGROUP_FORMAT_HUMAN (1U << 1) + struct qgroup_lookup { struct rb_root root; }; @@ -79,54 +83,54 @@ struct btrfs_qgroup_list { static struct { char *name; char *column_name; - int need_print; + unsigned int format; int max_len; } btrfs_qgroup_columns[] = { { .name = "qgroupid", .column_name= "Qgroupid", - .need_print = 1, + .format = BTRFS_QGROUP_FORMAT_PRINT, .max_len= 8, }, { .name = "rfer", .column_name= "Rfer", - .need_print = 1, - .max_len= 4, + .format = BTRFS_QGROUP_FORMAT_PRINT, + .max_len= 12, }, { .name = "excl", .column_name= "Excl", - .need_print = 1, - .max_len= 4, + .format = BTRFS_QGROUP_FORMAT_PRINT, + .max_len= 12, },
[PATCH] btrfs-progs: add missing options to qgroup limit
btrfs qgroup limit has two options -c and -e,. They were forgotten to add to manpage. Signed-off-by: Fan Chengniang --- Documentation/btrfs-qgroup.txt | 9 + 1 file changed, 9 insertions(+) diff --git a/Documentation/btrfs-qgroup.txt b/Documentation/btrfs-qgroup.txt index 8ce1c27..7e370bd 100644 --- a/Documentation/btrfs-qgroup.txt +++ b/Documentation/btrfs-qgroup.txt @@ -58,6 +58,15 @@ identified by . + If is not given, qgroup of the subvolume identified by is used if possible. ++ +`Options` ++ +-c +limit amount of data after compression. This is the default, it is currently not +possible to turn off this option. ++ +-e +limit space exclusively assigned to this qgroup. *remove* :: Remove the relationship between child qgroup and parent qgroup in -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2] btrfs-progs: make btrfs qgroups show human readable sizes
make btrfs qgroups show human readable sizes using --human-readable option, example: qgroupid rfer excl max_rfer max_excl parent child -- - 0/5 299.58MiB299.58MiB400.00MiB0.00B1/1 --- 0/265299.58MiB16.00KiB 0.00B320.00MiB1/1 --- 0/266299.58MiB16.00KiB 350.00MiB0.00B--- --- 1/1 599.16MiB299.59MiB800.00MiB0.00B--- 0/5,0/265 Signed-off-by: Fan Chengniang --- Documentation/btrfs-qgroup.txt | 2 ++ cmds-qgroup.c | 12 ++-- qgroup.c | 69 -- qgroup.h | 1 + 4 files changed, 59 insertions(+), 25 deletions(-) diff --git a/Documentation/btrfs-qgroup.txt b/Documentation/btrfs-qgroup.txt index 3e13373..d8ed028 100644 --- a/Documentation/btrfs-qgroup.txt +++ b/Documentation/btrfs-qgroup.txt @@ -73,6 +73,8 @@ print max exclusive size of qgroup. list all qgroups which impact the given path(include ancestral qgroups) -f list all qgroups which impact the given path(exclude ancestral qgroups) +--human-readable +print sizes in human readable format (e.g., 1KiB 234MiB 2GiB). --sort=[\+/-][,[+/-]]... list qgroups in order of . + diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 957fbc9..84c3df8 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -216,6 +216,8 @@ static const char * const cmd_qgroup_show_usage[] = { "(include ancestral qgroups)", "-f list all qgroups which impact the given path" "(exclude ancestral qgroups)", + "--human-readable", + " print sizes in human readable format (e.g., 1KiB 234MiB 2GiB)", "--sort=qgroupid,rfer,excl,max_rfer,max_excl", " list qgroups in order of qgroupid," "rfer,max_rfer or max_excl", @@ -234,6 +236,7 @@ static int cmd_qgroup_show(int argc, char **argv) int c; u64 qgroupid; int filter_flag = 0; + int option_index = 0; struct btrfs_qgroup_comparer_set *comparer_set; struct btrfs_qgroup_filter_set *filter_set; @@ -241,16 +244,21 @@ static int cmd_qgroup_show(int argc, char **argv) comparer_set = btrfs_qgroup_alloc_comparer_set(); struct option long_options[] = { {"sort", 1, NULL, 'S'}, + {"human-readable", 0, NULL, 0}, {0, 0, 0, 0} }; optind = 1; while (1) { - c = getopt_long(argc, argv, "pcreFf", - long_options, NULL); + c = getopt_long(argc, argv, "pcrehFf", + long_options, &option_index); if (c < 0) break; switch (c) { + case 0: + if (option_index == 1) + btrfs_qgroup_setup_human_readable(); + break; case 'p': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_PARENT); diff --git a/qgroup.c b/qgroup.c index 1a4866c..ce87fe4 100644 --- a/qgroup.c +++ b/qgroup.c @@ -20,10 +20,14 @@ #include #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) +#define BTRFS_QGROUP_FORMAT_PRINT 1 +#define BTRFS_QGROUP_FORMAT_HUMAN (1U << 1) + struct qgroup_lookup { struct rb_root root; }; @@ -79,54 +83,54 @@ struct btrfs_qgroup_list { static struct { char *name; char *column_name; - int need_print; + unsigned int format; int max_len; } btrfs_qgroup_columns[] = { { .name = "qgroupid", .column_name= "Qgroupid", - .need_print = 1, + .format = BTRFS_QGROUP_FORMAT_PRINT, .max_len= 8, }, { .name = "rfer", .column_name= "Rfer", - .need_print = 1, - .max_len= 4, + .format = BTRFS_QGROUP_FORMAT_PRINT, + .max_len= 12, }, { .name = "excl", .column_name= "Excl", - .need_print = 1, - .max_len= 4, + .format = BTRFS_QGROUP_FORMAT_PRINT, + .max_len= 12, }, { .name = "max_rfer",
Re: [PATCH] btrfs-progs: make btrfs qgroups show human readable sizes
在 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. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/2] btrfs-progs:btrfstune: choose to ignore error when setting seeding enabled
Before with -S option, setting positive value on seeding-enabled btrfs filesystem will cause error. So I add -i option which can ignore it. Reported-by: Chen Hanxiao Signed-off-by: Fan Chengniang --- Documentation/btrfstune.txt | 9 +++-- btrfstune.c | 25 ++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Documentation/btrfstune.txt b/Documentation/btrfstune.txt index d49a974..494a716 100644 --- a/Documentation/btrfstune.txt +++ b/Documentation/btrfstune.txt @@ -18,8 +18,13 @@ OPTIONS --- -S :: Updates the seeding value. -A positive value will enable seeding, zero will disable seeding, negtive is not allowed. -Enable seeding forces a fs readonly so that you can use it to build other filesystems. +A positive value will enable seeding, zero will disable seeding, negtive is not +allowed. If seeding is already enabled, positive value will cause reporting +error. Enable seeding forces a fs readonly so that you can use it to build other +filesystems. +-i:: +Use with -S option. If seeding is already enabled, ignore it and do not report +error. -r:: Enable extended inode refs. -x:: diff --git a/btrfstune.c b/btrfstune.c index 050418a..9a9e855 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -34,7 +34,8 @@ static char *device; -static int update_seeding_flag(struct btrfs_root *root, int set_flag) +static int update_seeding_flag(struct btrfs_root *root, int set_flag, + int ignore_enabled_seeding) { struct btrfs_trans_handle *trans; struct btrfs_super_block *disk_super; @@ -44,9 +45,12 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag) super_flags = btrfs_super_flags(disk_super); if (set_flag) { if (super_flags & BTRFS_SUPER_FLAG_SEEDING) { - fprintf(stderr, "seeding flag is already set on %s\n", - device); - return 1; + if (!ignore_enabled_seeding) { + fprintf(stderr, "seeding flag is already set on %s\n", + device); + return 1; + } + return 0; } super_flags |= BTRFS_SUPER_FLAG_SEEDING; } else { @@ -101,7 +105,9 @@ static int enable_skinny_metadata(struct btrfs_root *root) static void print_usage(void) { fprintf(stderr, "usage: btrfstune [options] device\n"); - fprintf(stderr, "\t-S value\tpositive value will enable seeding, zero to disable, negative is not allowed\n"); + fprintf(stderr, "\t-S value\tpositive value will enable seeding, zero to disable, negative is not allowed. " + "If seeding is already enabled, positive value will cause reporting error\n"); + fprintf(stderr, "\t-i \t\tuse with -S option. If seeding is already enabled, ignore it and do not report error\n"); fprintf(stderr, "\t-r \t\tenable extended inode refs\n"); fprintf(stderr, "\t-x \t\tenable skinny metadata extent refs\n"); fprintf(stderr, "\t-f \t\tforce to clear flags, make sure that you are aware of the dangers\n"); @@ -114,13 +120,14 @@ int main(int argc, char *argv[]) int extrefs_flag = 0; int seeding_flag = 0; u64 seeding_value = 0; + int ignore_enabled_seeding = 0; int skinny_flag = 0; int force = 0; int ret; optind = 1; while(1) { - int c = getopt(argc, argv, "S:rxf"); + int c = getopt(argc, argv, "S:irxf"); if (c < 0) break; switch(c) { @@ -128,6 +135,9 @@ int main(int argc, char *argv[]) seeding_flag = 1; seeding_value = arg_strtou64(optarg); break; + case 'i': + ignore_enabled_seeding = 1; + break; case 'r': extrefs_flag = 1; break; @@ -185,7 +195,8 @@ int main(int argc, char *argv[]) } } - ret = update_seeding_flag(root, seeding_value); + ret = update_seeding_flag(root, seeding_value, + ignore_enabled_seeding); if (!ret) success++; } -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/2] btrfs-progs:btrfstune:fix multiple options error
when we use multiple options, error return status will be override by the last option status. example: btrfstune -S 1 -r /dev/loop0 when -S option fails and -r option succeeds, return value is 0, rather than 1, where 1 is the right return status. Reported-by: Chen Hanxiao Signed-off-by: Fan Chengniang --- btrfstune.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/btrfstune.c b/btrfstune.c index 9a9e855..499a71d 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -117,6 +117,7 @@ int main(int argc, char *argv[]) { struct btrfs_root *root; int success = 0; + int total = 0; int extrefs_flag = 0; int seeding_flag = 0; u64 seeding_value = 0; @@ -199,19 +200,22 @@ int main(int argc, char *argv[]) ignore_enabled_seeding); if (!ret) success++; + total++; } if (extrefs_flag) { enable_extrefs_flag(root); success++; + total++; } if (skinny_flag) { enable_skinny_metadata(root); success++; + total++; } - if (success > 0) { + if (success == total) { ret = 0; } else { root->fs_info->readonly = 1; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: fix some format errors in doc
Signed-off-by: Fan Chengniang --- Documentation/btrfs-mount.txt| 2 +- Documentation/btrfs-property.txt | 14 +++--- Documentation/btrfs-replace.txt | 3 +-- Documentation/btrfs-scrub.txt| 4 +--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Documentation/btrfs-mount.txt b/Documentation/btrfs-mount.txt index 4fb7137..8cf7a0b 100644 --- a/Documentation/btrfs-mount.txt +++ b/Documentation/btrfs-mount.txt @@ -91,7 +91,7 @@ MOUNT OPTIONS operations). This was previously the behavior only when a snapshot is created. -*inode_cache*: +*inode_cache*:: Enable free inode number caching. Defaults to off due to an overflow problem when the free space crcs don't fit inside a single page. diff --git a/Documentation/btrfs-property.txt b/Documentation/btrfs-property.txt index 28ede4b..8b9b7f0 100644 --- a/Documentation/btrfs-property.txt +++ b/Documentation/btrfs-property.txt @@ -28,10 +28,16 @@ A btrfs object, which is set by , can be a btrfs filesystem itself, a btrfs subvolume, an inode(file or directory) inside btrfs, or a device on which a btrfs exists. + +The '-t ' option can be used to explicitly +specify what type of object you meant. This is only needed when a +property could be set for more then one object type. ++ +Possible types are 's[ubvol]', 'f[ilesystem]', 'i[node]' and 'd[evice]'. ++ Set the name of property by ''. If no '' is specified, all properties for the given object are printed. '' is one of the followings. -+ + ro read-only flag of subvolume: true or false label @@ -39,12 +45,6 @@ label of device compression compression setting for an inode: lzo, zlib, or "" (empty string) -The '-t ' option can be used to explicitly -specify what type of object you meant. This is only needed when a -property could be set for more then one object type. -+ -Possible types are 's[ubvol]', 'f[ilesystem]', 'i[node]' and 'd[evice]'. - *list* [-t ] :: Lists available properties with their descriptions for the given object. + diff --git a/Documentation/btrfs-replace.txt b/Documentation/btrfs-replace.txt index 7402484..b2a21b9 100644 --- a/Documentation/btrfs-replace.txt +++ b/Documentation/btrfs-replace.txt @@ -13,9 +13,8 @@ DESCRIPTION --- *btrfs replace* is used to replace btrfs managed devices with other device. -Note: this is not currently supported for RAID5/6 profiles and must use the +NOTE: this is not currently supported for RAID5/6 profiles and must use the device add/delete workaround. - It is recommended to see `btrfs-device`(8) for more details about btrfs device management. diff --git a/Documentation/btrfs-scrub.txt b/Documentation/btrfs-scrub.txt index c0fafca..6ebce60 100644 --- a/Documentation/btrfs-scrub.txt +++ b/Documentation/btrfs-scrub.txt @@ -59,9 +59,7 @@ Read only mode. Do not attempt to correct anything. -R Raw print mode. Print full data instead of summary. -c -Set IO priority class (see - ionice (1) -manpage). +Set IO priority class (see `ionice`(1) manpage). -n Set IO priority classdata (see `ionice`(1) manpage). -f -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: make btrfs qgroups show human readable sizes
make btrfs qgroups show human readable sizes, using -h option, example: qgroupid rfer excl max_rfer max_excl parent child -- - 0/5 299.58MiB299.58MiB400.00MiB0.00B1/1 --- 0/265299.58MiB16.00KiB 0.00B320.00MiB1/1 --- 0/266299.58MiB16.00KiB 350.00MiB0.00B--- --- 1/1 599.16MiB299.59MiB800.00MiB0.00B--- 0/5,0/265 Signed-off-by: Fan Chengniang --- 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 #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", .