diff mbox

Reporting free space to userspace programs

Message ID 23a15591002231427i4cacb74ahb09fe9c98d74bd16@mail.gmail.com (mailing list archive)
State Accepted
Headers show

Commit Message

Leszek Ciesielski Feb. 23, 2010, 10:27 p.m. UTC
None
diff mbox

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 8a1ea6e..893c154 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -623,13 +623,18 @@  static int btrfs_statfs(struct dentry *dentry,
struct kstatfs *buf)
 {
 	struct btrfs_root *root = btrfs_sb(dentry->d_sb);
 	struct btrfs_super_block *disk_super = &root->fs_info->super_copy;
+	struct btrfs_device *device;
 	int bits = dentry->d_sb->s_blocksize_bits;
 	__be32 *fsid = (__be32 *)root->fs_info->fsid;

 	buf->f_namelen = BTRFS_NAME_LEN;
 	buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits;
-	buf->f_bfree = buf->f_blocks -
-		(btrfs_super_bytes_used(disk_super) >> bits);
+	buf->f_bfree = buf->f_blocks;
+	mutex_lock(&root->fs_info->fs_devices->device_list_mutex);
+	list_for_each_entry(device, &root->fs_info->fs_devices->devices, dev_list) {
+	    buf->f_bfree -= (device->bytes_used >> bits);
+	}
+	mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
 	buf->f_bavail = buf->f_bfree;
 	buf->f_bsize = dentry->d_sb->s_blocksize;