linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
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	[thread overview]
Message-ID: <1406172114-10793-1-git-send-email-guihc.fnst@cn.fujitsu.com> (raw)

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 <guihc.fnst@cn.fujitsu.com>
---
 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++;
 	}
 }
 
-- 
1.8.1.4


             reply	other threads:[~2014-07-24  3:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-24  3:21 Gui Hecheng [this message]
2014-07-24  3:21 ` [PATCH 2/3] btrfs-progs: output the correct path when fi-usage failed Gui Hecheng
2014-07-24  3:27   ` [PATCH v2 " Gui Hecheng
2014-07-24  3:21 ` [PATCH 3/3] btrfs-progs: fix improper output msg for btrfs-fi-usage Gui Hecheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406172114-10793-1-git-send-email-guihc.fnst@cn.fujitsu.com \
    --to=guihc.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).