From patchwork Thu Mar 8 02:40:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 10265911 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AD7146055B for ; Thu, 8 Mar 2018 02:42:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F4A929270 for ; Thu, 8 Mar 2018 02:42:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 942732928F; Thu, 8 Mar 2018 02:42:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E1E429270 for ; Thu, 8 Mar 2018 02:42:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935072AbeCHCmP (ORCPT ); Wed, 7 Mar 2018 21:42:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:60599 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934884AbeCHClE (ORCPT ); Wed, 7 Mar 2018 21:41:04 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 51E23AE90 for ; Thu, 8 Mar 2018 02:41:03 +0000 (UTC) Received: from sled4.home.jeffm.io (sled4.home.jeffm.io [192.168.111.8]) by mail.home.jeffm.io (Postfix) with ESMTPS id B3E6F81AD3ED; Wed, 7 Mar 2018 21:40:33 -0500 (EST) Received: by sled4.home.jeffm.io (Postfix, from userid 1000) id 565393A41; Wed, 7 Mar 2018 21:40:58 -0500 (EST) From: jeffm@suse.com To: linux-btrfs@vger.kernel.org Cc: Jeff Mahoney Subject: [PATCH 09/20] btrfs-progs: subvolume: add quota info to btrfs sub show Date: Wed, 7 Mar 2018 21:40:36 -0500 Message-Id: <20180308024047.10104-10-jeffm@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180308024047.10104-1-jeffm@suse.com> References: <20180308024047.10104-1-jeffm@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 769d2a76..96fb7b06 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 int field_width = 0; + + unit_mode = get_unit_mode_from_arg(&argc, argv, 1); while (1) { int c; @@ -1112,6 +1120,48 @@ 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 && 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: btrfs_cleanup_root_info(&get_ri); free(filter_set);