From f114e655915851afe172f5c363d818f3ec933ca8 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Mon, 23 Oct 2017 17:09:27 -0400 Subject: [PATCH] btrfs-progs: subvolume: add quota info to btrfs sub show This patch reports on the first-level qgroup, if any, associated with a particular subvolume. It displays the usage and limit, subject to the usual unit parameters. Signed-off-by: Jeff Mahoney Signed-off-by: David Sterba --- cmds-subvolume.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 9521f1fd..8cb1d4fb 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -918,6 +918,7 @@ static const char * const cmd_subvol_show_usage[] = { "Show more information about the subvolume (UUIDs, generations, times, snapshots)", "-r|--rootid rootid of the subvolume", "-u|--uuid uuid of the subvolume", + HELPINFO_UNITS_SHORT_LONG, "", "If no option is specified, subvolume at will be shown, otherwise", "the rootid or uuid are resolved relative to the .", @@ -940,6 +941,13 @@ static int cmd_subvol_show(int argc, char **argv) struct btrfs_util_subvolume_info subvol; char *subvol_path = NULL; enum btrfs_util_error err; + struct btrfs_qgroup_stats stats; + unsigned int unit_mode; + const char *referenced_size; + const char *referenced_limit_size = "-"; + unsigned int field_width = 0; + + unit_mode = get_unit_mode_from_arg(&argc, argv, 1); optind = 0; while (1) { @@ -1110,7 +1118,48 @@ static int cmd_subvol_show(int argc, char **argv) } btrfs_util_destroy_subvolume_iterator(iter); - ret = 0; + ret = btrfs_qgroup_query(fd, subvol.id, &stats); + if (ret && ret != -ENOTTY && ret != -ENODATA) { + fprintf(stderr, + "\nERROR: BTRFS_IOC_QUOTA_QUERY failed: %s\n", + strerror(-ret)); + goto out; + } + + printf("\tQuota Usage:\t\t"); + fflush(stdout); + if (ret) { + if (ret == -ENOTTY) + printf("quotas not enabled\n"); + else + printf("quotas not available\n"); + goto out; + } + + referenced_size = pretty_size_mode(stats.info.referenced, unit_mode); + if (stats.limit.max_referenced) + referenced_limit_size = pretty_size_mode( + stats.limit.max_referenced, + unit_mode); + field_width = max(strlen(referenced_size), + strlen(referenced_limit_size)); + + printf("%-*s referenced, %s exclusive\n ", field_width, + referenced_size, + pretty_size_mode(stats.info.exclusive, unit_mode)); + + printf("\tQuota Limits:\t\t"); + if (stats.limit.max_referenced || stats.limit.max_exclusive) { + const char *excl = "-"; + + if (stats.limit.max_exclusive) + excl = pretty_size_mode(stats.limit.max_exclusive, + unit_mode); + printf("%-*s referenced, %s exclusive\n", field_width, + referenced_limit_size, excl); + } else + printf("None\n"); + out: free(subvol_path); close_file_or_dir(fd, dirstream1);