On 2018/05/17 6:38, je...@suse.com wrote:
> From: Jeff Mahoney
>
> The btrfs qgroup show command currently only exports qgroup IDs,
> forcing the user to resolve which subvolume each corresponds to.
>
> This patch adds pathname resolution to qgroup show so that when
> the -P option is used, the last column contains the pathname of
> the root of the subvolume it describes. In the case of nested
> qgroups, it will show the number of member qgroups or the paths
> of the members if the -v option is used.
>
> Pathname can also be used as a sort parameter.
>
> Reviewed-by: Qu Wenruo
> Signed-off-by: Jeff Mahoney
> ---
> Documentation/btrfs-qgroup.asciidoc | 4 +
> cmds-qgroup.c | 18 -
> kerncompat.h| 1 +
> qgroup.c| 149
>
> qgroup.h| 4 +-
> 5 files changed, 157 insertions(+), 19 deletions(-)
>
> diff --git a/Documentation/btrfs-qgroup.asciidoc
> b/Documentation/btrfs-qgroup.asciidoc
> index 3108457c..360b3269 100644
> --- a/Documentation/btrfs-qgroup.asciidoc
> +++ b/Documentation/btrfs-qgroup.asciidoc
> @@ -97,10 +97,14 @@ print child qgroup id.
> print limit of referenced size of qgroup.
> -e
> print limit of exclusive size of qgroup.
> +-P
> +print pathname to the root of the subvolume managed by qgroup. For nested
> qgroups, the number of members will be printed unless -v is specified.
> -F
> list all qgroups which impact the given path(include ancestral qgroups)
> -f
> list all qgroups which impact the given path(exclude ancestral qgroups)
> +-v
> +Be more verbose. Print pathnames of member qgroups when nested.
> --raw
> raw numbers in bytes, without the 'B' suffix.
> --human-readable
> diff --git a/cmds-qgroup.c b/cmds-qgroup.c
> index 93206900..33053725 100644
> --- a/cmds-qgroup.c
> +++ b/cmds-qgroup.c
> @@ -282,8 +282,11 @@ static const char * const cmd_qgroup_show_usage[] = {
> " (including ancestral qgroups)",
> "-f list all qgroups which impact the given path",
> " (excluding ancestral qgroups)",
> + "-P print first-level qgroups using pathname",
> + " - nested qgroups will be reported as a count",
> + "-v verbose, prints pathnames for all nested qgroups",
> HELPINFO_UNITS_LONG,
> - "--sort=qgroupid,rfer,excl,max_rfer,max_excl",
> + "--sort=qgroupid,rfer,excl,max_rfer,max_excl,pathname",
> " list qgroups sorted by specified items",
> " you can use '+' or '-' in front of each item.",
> " (+:ascending, -:descending, ascending default)",
> @@ -302,6 +305,7 @@ static int cmd_qgroup_show(int argc, char **argv)
> unsigned unit_mode;
> int sync = 0;
> enum btrfs_util_error err;
> + bool verbose = false;
>
> struct btrfs_qgroup_comparer_set *comparer_set;
> struct btrfs_qgroup_filter_set *filter_set;
> @@ -319,10 +323,11 @@ static int cmd_qgroup_show(int argc, char **argv)
> static const struct option long_options[] = {
> {"sort", required_argument, NULL, GETOPT_VAL_SORT},
> {"sync", no_argument, NULL, GETOPT_VAL_SYNC},
> + {"verbose", no_argument, NULL, 'v'},
> { NULL, 0, NULL, 0 }
> };
>
> - c = getopt_long(argc, argv, "pcreFf", long_options, NULL);
> + c = getopt_long(argc, argv, "pPcreFfv", long_options, NULL);
> if (c < 0)
> break;
> switch (c) {
> @@ -330,6 +335,10 @@ static int cmd_qgroup_show(int argc, char **argv)
> btrfs_qgroup_setup_print_column(
> BTRFS_QGROUP_PARENT);
> break;
> + case 'P':
> + btrfs_qgroup_setup_print_column(
> + BTRFS_QGROUP_PATHNAME);
> + break;
> case 'c':
> btrfs_qgroup_setup_print_column(
> BTRFS_QGROUP_CHILD);
> @@ -357,6 +366,9 @@ static int cmd_qgroup_show(int argc, char **argv)
> case GETOPT_VAL_SYNC:
> sync = 1;
> break;
> + case 'v':
> + verbose = true;
> + break;
> default:
> usage(cmd_qgroup_show_usage);
> }
> @@ -398,7 +410,7 @@ static int cmd_qgroup_show(int argc, char **argv)
> BTRFS_QGROUP_FILTER_PARENT,
> qgroupid);
> }
> - ret = btrfs_show_qgroups(fd, filter_set, comparer_set);
> + ret = btrfs_show_qgroups(fd, filter_set, comparer_set, verbose);
>