Re: [PATCH 7/8] btrfs-progs: subvolume: add quota info to btrfs sub show
On 3/7/18 1:09 AM, Qu Wenruo wrote: > > > On 2018年03月03日 02:47, je...@suse.com wrote: >> From: Jeff Mahoney >> >> 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 >> --- >> cmds-subvolume.c | 46 ++ >> 1 file changed, 46 insertions(+) >> >> diff --git a/cmds-subvolume.c b/cmds-subvolume.c >> index 8a473f7a..29d0e0e5 100644 >> --- a/cmds-subvolume.c >> +++ b/cmds-subvolume.c >> @@ -972,6 +972,7 @@ static const char * const cmd_subvol_show_usage[] = { >> "Show more information about the subvolume", >> "-r|--rootid rootid of the subvolume", >> "-u|--uuid uuid of the subvolume", >> +HELPINFO_UNITS_SHORT_LONG, >> "", >> "If no option is specified, will be shown, otherwise", >> "the rootid or uuid are resolved relative to the path.", >> @@ -993,6 +994,13 @@ static int cmd_subvol_show(int argc, char **argv) >> int by_uuid = 0; >> u64 rootid_arg; >> u8 uuid_arg[BTRFS_UUID_SIZE]; >> +struct btrfs_qgroup_stats stats; >> +unsigned int unit_mode; >> +const char *referenced_size; >> +const char *referenced_limit_size = "-"; >> +unsigned field_width = 0; >> + >> +unit_mode = get_unit_mode_from_arg(&argc, argv, 1); >> >> while (1) { >> int c; >> @@ -1112,6 +1120,44 @@ static int cmd_subvol_show(int argc, char **argv) >> btrfs_list_subvols_print(fd, filter_set, NULL, BTRFS_LIST_LAYOUT_RAW, >> 1, raw_prefix); >> >> +ret = btrfs_qgroup_query(fd, get_ri.root_id, &stats); >> +if (ret < 0) { >> +if (ret == -ENODATA) >> +printf("Quotas must be enabled for per-subvolume >> usage\n"); > > This seems a little confusing. > If quota is disabled, we get ENOTTY not ENODATA. > > For ENODATA we know quota is enabled but just no info for this qgroup. Yep. Thanks, -Jeff > Thanks, > Qu > >> +else if (ret != -ENOTTY) >> +fprintf(stderr, >> +"\nERROR: BTRFS_IOC_QUOTA_QUERY failed: %s\n", >> +strerror(errno)); >> +goto out; >> +} >> + >> +printf("\tQuota Usage:\t\t"); >> +fflush(stdout); >> + >> +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: >> /* clean up */ >> free(get_ri.path); >> > -- Jeff Mahoney SUSE Labs signature.asc Description: OpenPGP digital signature
Re: [PATCH 7/8] btrfs-progs: subvolume: add quota info to btrfs sub show
On 2018年03月03日 02:47, je...@suse.com wrote: > From: Jeff Mahoney > > 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 > --- > cmds-subvolume.c | 46 ++ > 1 file changed, 46 insertions(+) > > diff --git a/cmds-subvolume.c b/cmds-subvolume.c > index 8a473f7a..29d0e0e5 100644 > --- a/cmds-subvolume.c > +++ b/cmds-subvolume.c > @@ -972,6 +972,7 @@ static const char * const cmd_subvol_show_usage[] = { > "Show more information about the subvolume", > "-r|--rootid rootid of the subvolume", > "-u|--uuid uuid of the subvolume", > + HELPINFO_UNITS_SHORT_LONG, > "", > "If no option is specified, will be shown, otherwise", > "the rootid or uuid are resolved relative to the path.", > @@ -993,6 +994,13 @@ static int cmd_subvol_show(int argc, char **argv) > int by_uuid = 0; > u64 rootid_arg; > u8 uuid_arg[BTRFS_UUID_SIZE]; > + struct btrfs_qgroup_stats stats; > + unsigned int unit_mode; > + const char *referenced_size; > + const char *referenced_limit_size = "-"; > + unsigned field_width = 0; > + > + unit_mode = get_unit_mode_from_arg(&argc, argv, 1); > > while (1) { > int c; > @@ -1112,6 +1120,44 @@ static int cmd_subvol_show(int argc, char **argv) > btrfs_list_subvols_print(fd, filter_set, NULL, BTRFS_LIST_LAYOUT_RAW, > 1, raw_prefix); > > + ret = btrfs_qgroup_query(fd, get_ri.root_id, &stats); > + if (ret < 0) { > + if (ret == -ENODATA) > + printf("Quotas must be enabled for per-subvolume > usage\n"); This seems a little confusing. If quota is disabled, we get ENOTTY not ENODATA. For ENODATA we know quota is enabled but just no info for this qgroup. Thanks, Qu > + else if (ret != -ENOTTY) > + fprintf(stderr, > + "\nERROR: BTRFS_IOC_QUOTA_QUERY failed: %s\n", > + strerror(errno)); > + goto out; > + } > + > + printf("\tQuota Usage:\t\t"); > + fflush(stdout); > + > + 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: > /* clean up */ > free(get_ri.path); > signature.asc Description: OpenPGP digital signature
[PATCH 7/8] btrfs-progs: subvolume: add quota info to btrfs sub show
From: Jeff Mahoney 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 --- cmds-subvolume.c | 46 ++ 1 file changed, 46 insertions(+) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 8a473f7a..29d0e0e5 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -972,6 +972,7 @@ static const char * const cmd_subvol_show_usage[] = { "Show more information about the subvolume", "-r|--rootid rootid of the subvolume", "-u|--uuid uuid of the subvolume", + HELPINFO_UNITS_SHORT_LONG, "", "If no option is specified, will be shown, otherwise", "the rootid or uuid are resolved relative to the path.", @@ -993,6 +994,13 @@ static int cmd_subvol_show(int argc, char **argv) int by_uuid = 0; u64 rootid_arg; u8 uuid_arg[BTRFS_UUID_SIZE]; + struct btrfs_qgroup_stats stats; + unsigned int unit_mode; + const char *referenced_size; + const char *referenced_limit_size = "-"; + unsigned field_width = 0; + + unit_mode = get_unit_mode_from_arg(&argc, argv, 1); while (1) { int c; @@ -1112,6 +1120,44 @@ static int cmd_subvol_show(int argc, char **argv) btrfs_list_subvols_print(fd, filter_set, NULL, BTRFS_LIST_LAYOUT_RAW, 1, raw_prefix); + ret = btrfs_qgroup_query(fd, get_ri.root_id, &stats); + if (ret < 0) { + if (ret == -ENODATA) + printf("Quotas must be enabled for per-subvolume usage\n"); + else if (ret != -ENOTTY) + fprintf(stderr, + "\nERROR: BTRFS_IOC_QUOTA_QUERY failed: %s\n", + strerror(errno)); + goto out; + } + + printf("\tQuota Usage:\t\t"); + fflush(stdout); + + 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: /* clean up */ free(get_ri.path); -- 2.15.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 7/8] btrfs-progs: subvolume: add quota info to btrfs sub show
From: Jeff Mahoney 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 --- cmds-subvolume.c | 46 ++ 1 file changed, 46 insertions(+) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 8a473f7a..29d0e0e5 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -972,6 +972,7 @@ static const char * const cmd_subvol_show_usage[] = { "Show more information about the subvolume", "-r|--rootid rootid of the subvolume", "-u|--uuid uuid of the subvolume", + HELPINFO_UNITS_SHORT_LONG, "", "If no option is specified, will be shown, otherwise", "the rootid or uuid are resolved relative to the path.", @@ -993,6 +994,13 @@ static int cmd_subvol_show(int argc, char **argv) int by_uuid = 0; u64 rootid_arg; u8 uuid_arg[BTRFS_UUID_SIZE]; + struct btrfs_qgroup_stats stats; + unsigned int unit_mode; + const char *referenced_size; + const char *referenced_limit_size = "-"; + unsigned field_width = 0; + + unit_mode = get_unit_mode_from_arg(&argc, argv, 1); while (1) { int c; @@ -1112,6 +1120,44 @@ static int cmd_subvol_show(int argc, char **argv) btrfs_list_subvols_print(fd, filter_set, NULL, BTRFS_LIST_LAYOUT_RAW, 1, raw_prefix); + ret = btrfs_qgroup_query(fd, get_ri.root_id, &stats); + if (ret < 0) { + if (ret == -ENODATA) + printf("Quotas must be enabled for per-subvolume usage\n"); + else if (ret != -ENOTTY) + fprintf(stderr, + "\nERROR: BTRFS_IOC_QUOTA_QUERY failed: %s\n", + strerror(errno)); + goto out; + } + + printf("\tQuota Usage:\t\t"); + fflush(stdout); + + 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: /* clean up */ free(get_ri.path); -- 2.15.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