linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>, <zblaxell@furryterror.org>, <clm@fb.com>
Cc: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Subject: [PATCH v3 3/3] Btrfs: adapt df command to RAID5/6.
Date: Thu, 5 Mar 2015 10:18:38 +0800	[thread overview]
Message-ID: <1425521918-30212-4-git-send-email-yangds.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1425521918-30212-1-git-send-email-yangds.fnst@cn.fujitsu.com>

When we use btrfs with raid5/6, the output of df is unexpected as below.
Example:
        # mkfs.btrfs -f /dev/vdf1 /dev/vdf2 -d raid5
        # mount /dev/vdf1 /mnt
        # dd if=/dev/zero of=/mnt/zero bs=1M count=1000
        # df -h /mnt
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdf1       4.2G  1.3G  2.9G  32% /mnt
[root@atest-guest linux_btrfs]# btrfs fi show /mnt
Label: none  uuid: f7fac7f2-3898-482e-9cf2-fbcd7fdd7084
	Total devices 2 FS bytes used 1001.53MiB
	devid    1 size 2.00GiB used 1.85GiB path /dev/vdf1
	devid    2 size 4.00GiB used 1.83GiB path /dev/vdf2
The @size should be 2G rather than 4.2G.

This patch makes the btrfs_calc_avail_data_space() consider raid5/6,
then we can get the correct result of it.

Example:
        # mkfs.btrfs -f /dev/vdf1 /dev/vdf2 -d raid5
        # mount /dev/vdf1 /mnt
        # dd if=/dev/zero of=/mnt/zero bs=1M count=1000
        # df -h /mnt
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdf1       2.0G  1.3G  713M  66% /mnt
[root@atest-guest linux_btrfs]# btrfs fi show /mnt
Label: none  uuid: ea3a6e6e-fbe1-47aa-b4b5-bc37b98565d9
	Total devices 2 FS bytes used 1001.53MiB
	devid    1 size 2.00GiB used 1.85GiB path /dev/vdf1
	devid    2 size 4.00GiB used 1.83GiB path /dev/vdf2

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
---
 fs/btrfs/super.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 25b0f79..7cac6b4 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -52,6 +52,7 @@
 #include "props.h"
 #include "xattr.h"
 #include "volumes.h"
+#include "raid56.h"
 #include "export.h"
 #include "compression.h"
 #include "rcu-string.h"
@@ -1698,6 +1699,14 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
 		min_stripes = 4;
 		num_stripes = 4;
 		data_stripes = 2;
+	} else if (type & BTRFS_BLOCK_GROUP_RAID5) {
+		min_stripes = 2;
+		num_stripes = nr_devices;
+		data_stripes = num_stripes - nr_parity_stripes(type);
+	} else if (type & BTRFS_BLOCK_GROUP_RAID6) {
+		min_stripes = 3;
+		num_stripes = nr_devices;
+		data_stripes = num_stripes - nr_parity_stripes(type);
 	}
 
 	if (type & BTRFS_BLOCK_GROUP_DUP)
@@ -1787,8 +1796,11 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
 	while (nr_devices >= min_stripes) {
 		if (num_stripes > nr_devices) {
 			num_stripes = nr_devices;
-			if (type & BTRFS_BLOCK_GROUP_RAID0)
-				data_stripes = num_stripes;
+			/* Only RAID0, RAID5 and RAID6 will get here.
+			 * And we can use the following calculation
+			 * for all the three cases.
+			 **/
+			data_stripes = num_stripes - nr_parity_stripes(type);
 		}
 
 		if (devices_info[i].max_avail >= min_stripe_size) {
-- 
1.8.4.2


      parent reply	other threads:[~2015-03-05  2:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-05  2:18 [PATCH v3 0/3] Enhancement for df command Dongsheng Yang
2015-03-05  2:18 ` [PATCH v3 1/3] Btrfs: get more accurate output in " Dongsheng Yang
2015-03-06  6:50   ` [PATCH v4 " Dongsheng Yang
2015-03-05  2:18 ` [PATCH v3 2/3] Btrfs: raid56: simplify the parameter of nr_parity_stripes() Dongsheng Yang
2015-03-05  2:18 ` Dongsheng Yang [this message]

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=1425521918-30212-4-git-send-email-yangds.fnst@cn.fujitsu.com \
    --to=yangds.fnst@cn.fujitsu.com \
    --cc=clm@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=zblaxell@furryterror.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).