aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2010-03-05 16:59:21 -0500
committerChris Mason <chris.mason@oracle.com>2010-03-15 11:00:11 -0400
commitbd4d10888990f7e3f8029205d27eb155202d6969 (patch)
treedd8bfee4173f6bb5d0170768157e2a024bff34e1 /fs/btrfs
parent3a0524dc054791688177544fe510d2868ee20d9f (diff)
Btrfs: make df be a little bit more understandable
The way we report df usage is way confusing for everybody, including some other utilities (bacula for one). So this patch makes df a little bit more understandable. First we make used actually count the total amount of used space in all space info's. This will give us a real view of how much disk space is in use. Second, for blocks available, only count data space. This makes things like bacula work because it says 0 when you can no longer write anymore data to the disk. I think this is a nice compromise, since you will end up with something like the following [root@alpha ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 148G 30G 111G 21% / /dev/sda1 194M 116M 68M 64% /boot tmpfs 985M 12K 985M 1% /dev/shm /dev/mapper/VolGroup-LogVol02 145G 140G 0 100% /mnt/btrfs-test Compare this with btrfsctl -i output [root@alpha btrfs-progs-unstable]# ./btrfsctl -i /mnt/btrfs-test/ Metadata, DUP: total=4.62GB, used=2.46GB System, DUP: total=8.00MB, used=24.00KB Data: total=134.80GB, used=134.80GB Metadata: total=8.00MB, used=0.00 System: total=4.00MB, used=0.00 operation complete This way we show that there is no more data space to be used, but we have another 5GB of space left for metadata. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/super.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 9771eb8694b6..ff3dd55f294d 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -752,14 +752,37 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
752{ 752{
753 struct btrfs_root *root = btrfs_sb(dentry->d_sb); 753 struct btrfs_root *root = btrfs_sb(dentry->d_sb);
754 struct btrfs_super_block *disk_super = &root->fs_info->super_copy; 754 struct btrfs_super_block *disk_super = &root->fs_info->super_copy;
755 struct list_head *head = &root->fs_info->space_info;
756 struct btrfs_space_info *found;
757 u64 total_used = 0;
758 u64 data_used = 0;
755 int bits = dentry->d_sb->s_blocksize_bits; 759 int bits = dentry->d_sb->s_blocksize_bits;
756 __be32 *fsid = (__be32 *)root->fs_info->fsid; 760 __be32 *fsid = (__be32 *)root->fs_info->fsid;
757 761
762 rcu_read_lock();
763 list_for_each_entry_rcu(found, head, list) {
764 if (found->flags & (BTRFS_BLOCK_GROUP_DUP|
765 BTRFS_BLOCK_GROUP_RAID10|
766 BTRFS_BLOCK_GROUP_RAID1)) {
767 total_used += found->bytes_used;
768 if (found->flags & BTRFS_BLOCK_GROUP_DATA)
769 data_used += found->bytes_used;
770 else
771 data_used += found->total_bytes;
772 }
773
774 total_used += found->bytes_used;
775 if (found->flags & BTRFS_BLOCK_GROUP_DATA)
776 data_used += found->bytes_used;
777 else
778 data_used += found->total_bytes;
779 }
780 rcu_read_unlock();
781
758 buf->f_namelen = BTRFS_NAME_LEN; 782 buf->f_namelen = BTRFS_NAME_LEN;
759 buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; 783 buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits;
760 buf->f_bfree = buf->f_blocks - 784 buf->f_bfree = buf->f_blocks - (total_used >> bits);
761 (btrfs_super_bytes_used(disk_super) >> bits); 785 buf->f_bavail = buf->f_blocks - (data_used >> bits);
762 buf->f_bavail = buf->f_bfree;
763 buf->f_bsize = dentry->d_sb->s_blocksize; 786 buf->f_bsize = dentry->d_sb->s_blocksize;
764 buf->f_type = BTRFS_SUPER_MAGIC; 787 buf->f_type = BTRFS_SUPER_MAGIC;
765 788