From patchwork Thu Jul 24 03:21:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 4614191 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 D8500C0514 for ; Thu, 24 Jul 2014 03:27:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 09207201D5 for ; Thu, 24 Jul 2014 03:27:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1B9C201CE for ; Thu, 24 Jul 2014 03:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758647AbaGXD1p (ORCPT ); Wed, 23 Jul 2014 23:27:45 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:23303 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1758482AbaGXD1p (ORCPT ); Wed, 23 Jul 2014 23:27:45 -0400 X-IronPort-AV: E=Sophos;i="5.00,931,1396972800"; d="scan'208";a="33711009" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Jul 2014 11:24:56 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s6O3Rf1O016902 for ; Thu, 24 Jul 2014 11:27:41 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 24 Jul 2014 11:27:54 +0800 From: Gui Hecheng To: CC: Gui Hecheng Subject: [PATCH 1/3] btrfs-progs: fix wrong data ratio for raid56 in btrfs-file-usage Date: Thu, 24 Jul 2014 11:21:52 +0800 Message-ID: <1406172114-10793-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.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 When run btrfs-file-usage on a btrfs with data profile raid5/6, the output message for "Free" & "Data to device ratio" seems wrong as follows: ... Device size: 100.00GiB Device allocated: 2.04GiB Device unallocated: 97.96GiB Used: 1.12MiB Free (Estimated): 197.89GiB <== Free > Device size Data to device ratio: 198 % <== > 100% Global reserve: 0.00B ... It is because the function get_raid56_used() is not iterating the chunk_info array correctly, it is just repeating adding the first chunk_info statistics. Just add a ptr to iterate over the array. Signed-off-by: Gui Hecheng --- cmds-fi-disk_usage.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c index 453410f..78dc414 100644 --- a/cmds-fi-disk_usage.c +++ b/cmds-fi-disk_usage.c @@ -293,14 +293,16 @@ static struct btrfs_ioctl_space_args *load_space_info(int fd, char *path) static void get_raid56_used(int fd, struct chunk_info *chunks, int chunkcount, u64 *raid5_used, u64 *raid6_used) { + struct chunk_info *info_ptr = chunks; *raid5_used = 0; *raid6_used = 0; while (chunkcount-- > 0) { - if (chunks->type & BTRFS_BLOCK_GROUP_RAID5) - (*raid5_used) += chunks->size / (chunks->num_stripes - 1); - if (chunks->type & BTRFS_BLOCK_GROUP_RAID6) - (*raid6_used) += chunks->size / (chunks->num_stripes - 2); + if (info_ptr->type & BTRFS_BLOCK_GROUP_RAID5) + (*raid5_used) += info_ptr->size / (info_ptr->num_stripes - 1); + if (info_ptr->type & BTRFS_BLOCK_GROUP_RAID6) + (*raid6_used) += info_ptr->size / (info_ptr->num_stripes - 2); + info_ptr++; } }