diff mbox

Provide a better free space estimate on RAID1

Message ID 20140208172142.44243c67@natsu (mailing list archive)
State New, archived
Headers show

Commit Message

Roman Mamedov Feb. 8, 2014, 11:21 a.m. UTC
On Fri, 7 Feb 2014 12:08:12 +0600
Roman Mamedov <rm@romanrm.net> wrote:

> > Earlier conventions would have stated Size ~900GB, and Avail ~900GB. But that's not exactly true either, is it?
> 
> Much better, and matching the user expectations of how RAID1 should behave,
> without a major "gotcha" blowing up into their face the first minute they are
> trying it out. In fact next step that I planned would be finding how to adjust
> also Size and Used on all my machines to show what you just mentioned.

OK done; again, this is just what I will personally use from now on (and for
anyone who finds this helpful).

----



----

2x1TB RAID1 with a 1GB file:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       912G  1.1G  911G   1% /mnt/p2
diff mbox

Patch

--- fs/btrfs/super.c.orig	2014-02-06 01:28:36.636164982 +0600
+++ fs/btrfs/super.c	2014-02-08 17:16:50.361931959 +0600
@@ -1481,6 +1481,11 @@ 
 	}
 
 	kfree(devices_info);
+
+	if (type & BTRFS_BLOCK_GROUP_RAID1) {
+		do_div(avail_space, min_stripes);
+	}
+  
 	*free_bytes = avail_space;
 	return 0;
 }
@@ -1491,8 +1496,10 @@ 
 	struct btrfs_super_block *disk_super = fs_info->super_copy;
 	struct list_head *head = &fs_info->space_info;
 	struct btrfs_space_info *found;
+	u64 total_size;
 	u64 total_used = 0;
 	u64 total_free_data = 0;
+	u64 type;
 	int bits = dentry->d_sb->s_blocksize_bits;
 	__be32 *fsid = (__be32 *)fs_info->fsid;
 	int ret;
@@ -1512,7 +1519,13 @@ 
 	rcu_read_unlock();
 
 	buf->f_namelen = BTRFS_NAME_LEN;
-	buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits;
+	total_size = btrfs_super_total_bytes(disk_super);
+	type = btrfs_get_alloc_profile(fs_info->tree_root, 1);
+	if (type & BTRFS_BLOCK_GROUP_RAID1) {
+		do_div(total_size, 2);
+		do_div(total_used, 2);
+	}
+	buf->f_blocks = total_size >> bits;
 	buf->f_bfree = buf->f_blocks - (total_used >> bits);
 	buf->f_bsize = dentry->d_sb->s_blocksize;
 	buf->f_type = BTRFS_SUPER_MAGIC;