From patchwork Thu Dec 6 09:45:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 1844221 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 1ADDBDF2F9 for ; Thu, 6 Dec 2012 09:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422710Ab2LFJpY (ORCPT ); Thu, 6 Dec 2012 04:45:24 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:56179 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1422691Ab2LFJpT (ORCPT ); Thu, 6 Dec 2012 04:45:19 -0500 X-IronPort-AV: E=Sophos;i="4.84,229,1355068800"; d="scan'208";a="6346210" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 06 Dec 2012 17:43:29 +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 qB69jIOT032362; Thu, 6 Dec 2012 17:45:18 +0800 Received: from [10.167.225.199] ([10.167.225.199]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012120617443770-274184 ; Thu, 6 Dec 2012 17:44:37 +0800 Message-ID: <50C06944.4050409@cn.fujitsu.com> Date: Thu, 06 Dec 2012 17:45:40 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Linux Btrfs CC: Arne Jansen Subject: [PATCH 2/9] Btrfs-progs: introduces '-p' option to print the ID of the parent qgroups References: <50C068D4.6020105@cn.fujitsu.com> In-Reply-To: <50C068D4.6020105@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/12/06 17:44:37, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/12/06 17:44:38, Serialize complete at 2012/12/06 17:44:38 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Wang Shilong This patch introduces '-p' option to print the ID of the parent qgroups. You may use it like: btrfs qgroup show -p For Example: qgroupid(2/0) / \ / \ / \ qgroupid(1/0) qgroupid(1/1) \ / \ / qgroupid(0/1) If we use the command: btrfs qgroup show -p The result will output 0/1 -- -- 1/0,1/1 1/0 -- -- 2/0 1/1 -- -- 2/0 2/0 -- -- -- Signed-off-by: Wang Shilong Signed-off-by: Miao Xie --- cmds-qgroup.c | 24 +++++++++++++++++++++--- qgroup.c | 22 ++++++++++++++++++++++ qgroup.h | 1 + 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 2d5b59b..f402587 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -199,20 +199,38 @@ static int cmd_qgroup_destroy(int argc, char **argv) } static const char * const cmd_qgroup_show_usage[] = { - "btrfs qgroup show ", + "btrfs qgroup show -p ", "Show all subvolume quota groups.", + "-p print parent qgroup id", NULL }; static int cmd_qgroup_show(int argc, char **argv) { int ret = 0; + char *path; int fd; - char *path = argv[1]; + int c; + + optind = 1; + while (1) { + c = getopt(argc, argv, "p"); + if (c < 0) + break; - if (check_argc_exact(argc, 2)) + switch (c) { + case 'p': + btrfs_qgroup_setup_print_column( + BTRFS_QGROUP_PARENT); + break; + default: + usage(cmd_qgroup_show_usage); + } + } + if (check_argc_exact(argc - optind, 1)) usage(cmd_qgroup_show_usage); + path = argv[optind]; fd = open_file_or_dir(path); if (fd < 0) { fprintf(stderr, "ERROR: can't access '%s'\n", path); diff --git a/qgroup.c b/qgroup.c index 097811e..ebe7d17 100644 --- a/qgroup.c +++ b/qgroup.c @@ -88,6 +88,11 @@ struct { .need_print = 1, }, { + .name = "parent", + .column_name = "Parent", + .need_print = 0, + }, + { .name = NULL, .column_name = NULL, .need_print = 0, @@ -108,6 +113,20 @@ void btrfs_qgroup_setup_print_column(enum btrfs_qgroup_column_enum column) btrfs_qgroup_columns[i].need_print = 1; } +static void print_parent_column(struct btrfs_qgroup *qgroup) +{ + struct btrfs_qgroup_list *list = NULL; + + list_for_each_entry(list, &qgroup->qgroups, next_qgroup) { + printf("%llu/%llu", (list->qgroup)->qgroupid >> 48, + ((1ll << 48) - 1) & (list->qgroup)->qgroupid); + if (!list_is_last(&list->next_qgroup, &qgroup->qgroups)) + printf(","); + } + if (list_empty(&qgroup->qgroups)) + printf("---"); +} + static void print_qgroup_column(struct btrfs_qgroup *qgroup, enum btrfs_qgroup_column_enum column) { @@ -125,6 +144,9 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup, case BTRFS_QGROUP_EXCL: printf("%llu", qgroup->excl); break; + case BTRFS_QGROUP_PARENT: + print_parent_column(qgroup); + break; default: break; } diff --git a/qgroup.h b/qgroup.h index 138c48c..e1de675 100644 --- a/qgroup.h +++ b/qgroup.h @@ -26,6 +26,7 @@ enum btrfs_qgroup_column_enum { BTRFS_QGROUP_QGROUPID, BTRFS_QGROUP_RFER, BTRFS_QGROUP_EXCL, + BTRFS_QGROUP_PARENT, BTRFS_QGROUP_ALL, };