From: jeffm@suse.com
To: linux-btrfs@vger.kernel.org
Cc: Jeff Mahoney <jeffm@suse.com>
Subject: [PATCH 7/8] btrfs-progs: subvolume: add quota info to btrfs sub show
Date: Fri, 2 Mar 2018 13:47:03 -0500 [thread overview]
Message-ID: <20180302184704.22399-8-jeffm@suse.com> (raw)
In-Reply-To: <20180302184704.22399-1-jeffm@suse.com>
From: Jeff Mahoney <jeffm@suse.com>
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 <jeffm@suse.com>
---
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, <subvol-path> will be shown, otherwise",
"the rootid or uuid are resolved relative to the <mnt> 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
next prev parent reply other threads:[~2018-03-02 18:47 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-02 18:46 [PATCH 0/8] btrfs-progs: qgroups usability [corrected] jeffm
2018-03-02 18:46 ` [PATCH 1/8] btrfs-progs: quota: Add -W option to rescan to wait without starting rescan jeffm
2018-03-02 18:59 ` Nikolay Borisov
2018-03-03 2:46 ` Jeff Mahoney
2018-03-02 18:46 ` [PATCH 2/8] btrfs-progs: qgroups: fix misleading index check jeffm
2018-03-07 8:05 ` Nikolay Borisov
2018-03-02 18:46 ` [PATCH 3/8] btrfs-progs: constify pathnames passed as arguments jeffm
2018-03-07 8:17 ` Nikolay Borisov
2018-03-07 20:45 ` Jeff Mahoney
2018-03-02 18:47 ` [PATCH 4/8] btrfs-progs: qgroups: add pathname to show output jeffm
2018-03-07 5:45 ` Qu Wenruo
2018-03-07 16:37 ` Jeff Mahoney
2018-03-02 18:47 ` [PATCH 5/8] btrfs-progs: qgroups: introduce and use info and limit structures jeffm
2018-03-07 9:19 ` Nikolay Borisov
2018-03-02 18:47 ` [PATCH 6/8] btrfs-progs: qgroups: introduce btrfs_qgroup_query jeffm
2018-03-07 5:58 ` Qu Wenruo
2018-03-07 19:42 ` Jeff Mahoney
2018-03-07 6:08 ` Qu Wenruo
2018-03-07 8:02 ` Misono, Tomohiro
2018-03-07 20:24 ` Jeff Mahoney
2018-03-02 18:47 ` jeffm [this message]
2018-03-07 6:09 ` [PATCH 7/8] btrfs-progs: subvolume: add quota info to btrfs sub show Qu Wenruo
2018-03-07 20:21 ` Jeff Mahoney
2018-03-02 18:47 ` [PATCH 8/8] btrfs-progs: qgroups: export qgroups usage information as JSON jeffm
2018-03-07 6:34 ` Qu Wenruo
2018-03-07 15:28 ` Jeff Mahoney
2018-03-06 12:10 ` [PATCH 0/8] btrfs-progs: qgroups usability [corrected] Qu Wenruo
2018-03-06 14:59 ` Jeffrey Mahoney
2018-03-07 6:11 ` Qu Wenruo
-- strict thread matches above, loose matches on Subject: below --
2018-03-02 18:39 [PATCH 0/8] btrfs-progs: qgroups usability jeffm
2018-03-02 18:40 ` [PATCH 7/8] btrfs-progs: subvolume: add quota info to btrfs sub show jeffm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180302184704.22399-8-jeffm@suse.com \
--to=jeffm@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).