From patchwork Tue Jun 17 07:15:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 4364431 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 954C49F36A for ; Tue, 17 Jun 2014 07:14:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B65AE202F2 for ; Tue, 17 Jun 2014 07:14:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B18FA202EC for ; Tue, 17 Jun 2014 07:14:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752576AbaFQHO0 (ORCPT ); Tue, 17 Jun 2014 03:14:26 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:37916 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752160AbaFQHOZ (ORCPT ); Tue, 17 Jun 2014 03:14:25 -0400 X-IronPort-AV: E=Sophos;i="5.00,723,1396972800"; d="scan'208";a="32010960" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Jun 2014 15:11:43 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s5H7ELch026526 for ; Tue, 17 Jun 2014 15:14:21 +0800 Received: from adam-work.lan (10.167.226.24) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 17 Jun 2014 15:14:26 +0800 From: Qu Wenruo To: Subject: [PATCH v3] btrfs-progs: Add human readable flags output for chunk/block group type. Date: Tue, 17 Jun 2014 15:15:26 +0800 Message-ID: <1402989326-14134-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.0.0 MIME-Version: 1.0 X-Originating-IP: [10.167.226.24] 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Current btrfs-debug-tree output chunk/block group type as numbers, which makes it hard to understand and need to check the source to understand the meaning. This patch will convert numeric type output to human readable strings. Signed-off-by: Qu Wenruo --- changelog: v2: allow mixed chunk v3: fix typo in commit message --- print-tree.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/print-tree.c b/print-tree.c index 7f831ad..6cf59ca 100644 --- a/print-tree.c +++ b/print-tree.c @@ -160,15 +160,60 @@ static int print_inode_ref_item(struct extent_buffer *eb, struct btrfs_item *ite return 0; } +/* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */ +static void bg_flags_to_str(u64 flags, char *ret) +{ + int empty = 1; + + if (flags & BTRFS_BLOCK_GROUP_DATA) { + empty = 0; + strcpy(ret, "DATA"); + } + if (flags & BTRFS_BLOCK_GROUP_METADATA) { + if (!empty) + strcat(ret, "|"); + strcat(ret, "METADATA"); + } + if (flags & BTRFS_BLOCK_GROUP_SYSTEM) { + if (!empty) + strcat(ret, "|"); + strcat(ret, "SYSTEM"); + } + switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) { + case BTRFS_BLOCK_GROUP_RAID0: + strcat(ret, "|RAID0"); + break; + case BTRFS_BLOCK_GROUP_RAID1: + strcat(ret, "|RAID1"); + break; + case BTRFS_BLOCK_GROUP_DUP: + strcat(ret, "|DUP"); + break; + case BTRFS_BLOCK_GROUP_RAID10: + strcat(ret, "|RAID10"); + break; + case BTRFS_BLOCK_GROUP_RAID5: + strcat(ret, "|RAID5"); + break; + case BTRFS_BLOCK_GROUP_RAID6: + strcat(ret, "|RAID6"); + break; + default: + break; + } +} + static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk) { int num_stripes = btrfs_chunk_num_stripes(eb, chunk); int i; - printf("\t\tchunk length %llu owner %llu type %llu num_stripes %d\n", + char chunk_flags_str[32] = {0}; + + bg_flags_to_str(btrfs_chunk_type(eb, chunk), chunk_flags_str); + printf("\t\tchunk length %llu owner %llu type %s num_stripes %d\n", (unsigned long long)btrfs_chunk_length(eb, chunk), (unsigned long long)btrfs_chunk_owner(eb, chunk), - (unsigned long long)btrfs_chunk_type(eb, chunk), - num_stripes); + chunk_flags_str, num_stripes); for (i = 0 ; i < num_stripes ; i++) { printf("\t\t\tstripe %d devid %llu offset %llu\n", i, (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i), @@ -744,6 +789,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) u32 nr = btrfs_header_nritems(l); u64 objectid; u32 type; + char bg_flags_str[32]; printf("leaf %llu items %d free space %d generation %llu owner %llu\n", (unsigned long long)btrfs_header_bytenr(l), nr, @@ -858,10 +904,13 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) struct btrfs_block_group_item); read_extent_buffer(l, &bg_item, (unsigned long)bi, sizeof(bg_item)); - printf("\t\tblock group used %llu chunk_objectid %llu flags %llu\n", + memset(bg_flags_str, 0, sizeof(bg_flags_str)); + bg_flags_to_str(btrfs_block_group_flags(&bg_item), + bg_flags_str); + printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n", (unsigned long long)btrfs_block_group_used(&bg_item), (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item), - (unsigned long long)btrfs_block_group_flags(&bg_item)); + bg_flags_str); break; case BTRFS_CHUNK_ITEM_KEY: print_chunk(l, btrfs_item_ptr(l, i, struct btrfs_chunk));