From patchwork Mon Oct 7 07:21:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 2994651 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DBEFABF925 for ; Mon, 7 Oct 2013 07:25:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D800F201F6 for ; Mon, 7 Oct 2013 07:25:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9EBEF201F5 for ; Mon, 7 Oct 2013 07:25:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753921Ab3JGHZ2 (ORCPT ); Mon, 7 Oct 2013 03:25:28 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:64316 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753383Ab3JGHZM (ORCPT ); Mon, 7 Oct 2013 03:25:12 -0400 X-IronPort-AV: E=Sophos;i="4.90,1048,1371052800"; d="scan'208";a="8675848" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 07 Oct 2013 15:21:42 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r977OtkC012733; Mon, 7 Oct 2013 15:24:58 +0800 Received: from localhost.localdomain ([10.167.226.104]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013100715225286-2033126 ; Mon, 7 Oct 2013 15:22:52 +0800 From: Wang Shilong To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v3 12/12] Btrfs-progs: add '-h' options to print sizes in human readable format Date: Mon, 7 Oct 2013 15:21:48 +0800 Message-Id: <1381130508-8458-13-git-send-email-wangsl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1381130508-8458-1-git-send-email-wangsl.fnst@cn.fujitsu.com> References: <1381130508-8458-1-git-send-email-wangsl.fnst@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/10/07 15:22:52, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/10/07 15:22:55, Serialize complete at 2013/10/07 15:22:55 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a short cut for people who don't want to use '--block-size',it will print sizes in human readable format. Signed-off-by: Wang Shilong --- cmds-qgroup.c | 17 +++++++++++++--- qgroup.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++------------ qgroup.h | 2 ++ 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 912cc42..7ea752b 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -204,6 +204,7 @@ static int cmd_qgroup_destroy(int argc, char **argv) static const char * const cmd_qgroup_show_usage[] = { "btrfs qgroup show [options] ", "Show subvolume quota groups.", + "-h print size in human readable format", "-p print parent qgroup id", "-c print child qgroup id", "-r print max referenced size of qgroup", @@ -246,7 +247,7 @@ static int cmd_qgroup_show(int argc, char **argv) optind = 1; while (1) { - c = getopt_long(argc, argv, "pcreFf", + c = getopt_long(argc, argv, "pcreFfh", long_options, NULL); if (c < 0) break; @@ -280,11 +281,21 @@ static int cmd_qgroup_show(int argc, char **argv) usage(cmd_qgroup_show_usage); break; case 'B': - block_size = parse_block_size(optarg); - if (block_size < 0) { + ret = parse_block_size(optarg); + if (ret < 0) { fprintf(stderr, "Invalid block size\n"); usage(cmd_qgroup_show_usage); } + /* force to print in human readable format + * if -h is given + */ + if (block_size == BTRFS_QGROUP_PRINT_HUMAN_READABLE) + break; + else + block_size = ret; + break; + case 'h': + block_size = BTRFS_QGROUP_PRINT_HUMAN_READABLE; break; default: usage(cmd_qgroup_show_usage); diff --git a/qgroup.c b/qgroup.c index 0de6c7d..b1b7cef 100644 --- a/qgroup.c +++ b/qgroup.c @@ -206,15 +206,27 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup, print_qgroup_column_add_blank(BTRFS_QGROUP_QGROUPID, len); break; case BTRFS_QGROUP_RFER: - len = block_size_snprintf((signed long long)qgroup->rfer, tmp, - sizeof(tmp), block_size); + if (block_size == BTRFS_QGROUP_PRINT_HUMAN_READABLE) + len = pretty_size_snprintf( + (signed long long)qgroup->rfer, + tmp, sizeof(tmp)); + else + len = block_size_snprintf( + (signed long long)qgroup->rfer, + tmp, sizeof(tmp), block_size); BUG_ON(len < 0); printf("%s", tmp); print_qgroup_column_add_blank(BTRFS_QGROUP_RFER, len); break; case BTRFS_QGROUP_EXCL: - len = block_size_snprintf((signed long long)qgroup->excl, tmp, - sizeof(tmp), block_size); + if (block_size == BTRFS_QGROUP_PRINT_HUMAN_READABLE) + len = pretty_size_snprintf( + (signed long long)qgroup->excl, + tmp, sizeof(tmp)); + else + len = block_size_snprintf( + (signed long long)qgroup->excl, + tmp, sizeof(tmp), block_size); BUG_ON(len < 0); printf("%s", tmp); print_qgroup_column_add_blank(BTRFS_QGROUP_EXCL, len); @@ -224,14 +236,22 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup, print_qgroup_column_add_blank(BTRFS_QGROUP_PARENT, len); break; case BTRFS_QGROUP_MAX_RFER: - len = block_size_snprintf(qgroup->max_rfer, tmp, + if (block_size == BTRFS_QGROUP_PRINT_HUMAN_READABLE) + len = pretty_size_snprintf(qgroup->max_rfer, tmp, + sizeof(tmp)); + else + len = block_size_snprintf(qgroup->max_rfer, tmp, sizeof(tmp), block_size); BUG_ON(len < 0); printf("%s", tmp); print_qgroup_column_add_blank(BTRFS_QGROUP_MAX_RFER, len); break; case BTRFS_QGROUP_MAX_EXCL: - len = block_size_snprintf(qgroup->max_excl, tmp, + if (block_size == BTRFS_QGROUP_PRINT_HUMAN_READABLE) + len = pretty_size_snprintf(qgroup->max_excl, tmp, + sizeof(tmp)); + else + len = block_size_snprintf(qgroup->max_excl, tmp, sizeof(tmp), block_size); BUG_ON(len < 0); printf("%s", tmp); @@ -917,28 +937,46 @@ static void __update_columns_max_len(struct btrfs_qgroup *bq, btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_RFER: - len = block_size_snprintf((signed long long)bq->rfer, tmp, - sizeof(tmp), block_size); + if (block_size == BTRFS_QGROUP_PRINT_HUMAN_READABLE) + len = pretty_size_snprintf( + (signed long long)bq->rfer, + tmp, sizeof(tmp)); + else + len = block_size_snprintf((signed long long)bq->rfer, + tmp, sizeof(tmp), block_size); BUG_ON(len < 0); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_EXCL: - len = block_size_snprintf((signed long long)bq->excl, tmp, - sizeof(tmp), block_size); + if (block_size == BTRFS_QGROUP_PRINT_HUMAN_READABLE) + len = pretty_size_snprintf( + (signed long long)bq->excl, + tmp, sizeof(tmp)); + else + len = block_size_snprintf((signed long long)bq->excl, + tmp, sizeof(tmp), block_size); BUG_ON(len < 0); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_MAX_RFER: - len = block_size_snprintf(bq->max_rfer, tmp, + if (block_size == BTRFS_QGROUP_PRINT_HUMAN_READABLE) + len = pretty_size_snprintf(bq->max_rfer, tmp, + sizeof(tmp)); + else + len = block_size_snprintf(bq->max_rfer, tmp, sizeof(tmp), block_size); BUG_ON(len < 0); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_MAX_EXCL: - len = block_size_snprintf(bq->max_excl, tmp, + if (block_size == BTRFS_QGROUP_PRINT_HUMAN_READABLE) + len = pretty_size_snprintf(bq->max_excl, tmp, + sizeof(tmp)); + else + len = block_size_snprintf(bq->max_excl, tmp, sizeof(tmp), block_size); BUG_ON(len < 0); if (btrfs_qgroup_columns[column].max_len < len) diff --git a/qgroup.h b/qgroup.h index 1113a24..aa05de5 100644 --- a/qgroup.h +++ b/qgroup.h @@ -22,6 +22,8 @@ #include "ioctl.h" #include "kerncompat.h" +#define BTRFS_QGROUP_PRINT_HUMAN_READABLE (-1) + struct btrfs_qgroup; typedef int (*btrfs_qgroup_filter_func)(struct btrfs_qgroup *, u64);