Hello,

On a freshly-created RAID1 filesystem of two 1TB disks:

# df -h /mnt/p2/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       1.8T  1.1M  1.8T   1% /mnt/p2

I cannot write 2TB of user data to that RAID1, so this estimate is clearly
misleading. I got tired of looking at the bogus disk free space on all my
RAID1 btrfs systems, so today I decided to do something about this:

--- fs/btrfs/super.c.orig       2014-02-06 01:28:36.636164982 +0600
+++ fs/btrfs/super.c    2014-02-06 01:28:58.304164370 +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;
 }


After:

# df -h /mnt/p2/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       1.8T  1.1M  912G   1% /mnt/p2

Until per-subvolume RAID profiles are implemented, this estimate will be
correct, and even after, it should be closer to the truth than assuming the
user will fill their RAID1 FS only with subvolumes of single or raid0 profiles.

If anyone likes feel free to reimplement my PoC patch in a better way, e.g.
integrate this into the calculation 'while' block of that function immediately
before it (logic of which I couldn't yet grasp due to it lacking comments),
and not just tacked onto the tail of it.

-- 
With respect,
Roman

Attachment: signature.asc
Description: PGP signature

Reply via email to