aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2010-10-14 14:52:27 -0400
committerJosef Bacik <josef@redhat.com>2010-10-22 15:54:55 -0400
commit89a55897a2fbbceb94480952784004bf23911d38 (patch)
treee62ea1ced4c7941ab53e7aa7047ce8f0af0add9f /fs/btrfs
parentbf5fc093c5b625e4259203f1cee7ca73488a5620 (diff)
Btrfs: fix df regression
The new ENOSPC stuff breaks out the raid types which breaks the way we were reporting df to the system. This fixes it back so that Available is the total space available to data and used is the actual bytes used by the filesystem. This means that Available is Total - data used - all of the metadata space. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/ctree.h5
-rw-r--r--fs/btrfs/extent-tree.c10
-rw-r--r--fs/btrfs/super.c11
3 files changed, 23 insertions, 3 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 29c20092847e..014fd52c01bf 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -675,7 +675,8 @@ struct btrfs_block_group_item {
675struct btrfs_space_info { 675struct btrfs_space_info {
676 u64 flags; 676 u64 flags;
677 677
678 u64 total_bytes; /* total bytes in the space */ 678 u64 total_bytes; /* total bytes in the space,
679 this doesn't take mirrors into account */
679 u64 bytes_used; /* total bytes used, 680 u64 bytes_used; /* total bytes used,
680 this does't take mirrors into account */ 681 this does't take mirrors into account */
681 u64 bytes_pinned; /* total bytes pinned, will be freed when the 682 u64 bytes_pinned; /* total bytes pinned, will be freed when the
@@ -687,6 +688,8 @@ struct btrfs_space_info {
687 u64 bytes_may_use; /* number of bytes that may be used for 688 u64 bytes_may_use; /* number of bytes that may be used for
688 delalloc/allocations */ 689 delalloc/allocations */
689 u64 disk_used; /* total bytes used on disk */ 690 u64 disk_used; /* total bytes used on disk */
691 u64 disk_total; /* total bytes on disk, takes mirrors into
692 account */
690 693
691 int full; /* indicates that we cannot allocate any more 694 int full; /* indicates that we cannot allocate any more
692 chunks for this space */ 695 chunks for this space */
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index c6a5d9095d5f..4669c6f8a44d 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2763,6 +2763,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
2763 if (found) { 2763 if (found) {
2764 spin_lock(&found->lock); 2764 spin_lock(&found->lock);
2765 found->total_bytes += total_bytes; 2765 found->total_bytes += total_bytes;
2766 found->disk_total += total_bytes * factor;
2766 found->bytes_used += bytes_used; 2767 found->bytes_used += bytes_used;
2767 found->disk_used += bytes_used * factor; 2768 found->disk_used += bytes_used * factor;
2768 found->full = 0; 2769 found->full = 0;
@@ -2782,6 +2783,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
2782 BTRFS_BLOCK_GROUP_SYSTEM | 2783 BTRFS_BLOCK_GROUP_SYSTEM |
2783 BTRFS_BLOCK_GROUP_METADATA); 2784 BTRFS_BLOCK_GROUP_METADATA);
2784 found->total_bytes = total_bytes; 2785 found->total_bytes = total_bytes;
2786 found->disk_total = total_bytes * factor;
2785 found->bytes_used = bytes_used; 2787 found->bytes_used = bytes_used;
2786 found->disk_used = bytes_used * factor; 2788 found->disk_used = bytes_used * factor;
2787 found->bytes_pinned = 0; 2789 found->bytes_pinned = 0;
@@ -8095,6 +8097,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
8095 struct btrfs_free_cluster *cluster; 8097 struct btrfs_free_cluster *cluster;
8096 struct btrfs_key key; 8098 struct btrfs_key key;
8097 int ret; 8099 int ret;
8100 int factor;
8098 8101
8099 root = root->fs_info->extent_root; 8102 root = root->fs_info->extent_root;
8100 8103
@@ -8103,6 +8106,12 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
8103 BUG_ON(!block_group->ro); 8106 BUG_ON(!block_group->ro);
8104 8107
8105 memcpy(&key, &block_group->key, sizeof(key)); 8108 memcpy(&key, &block_group->key, sizeof(key));
8109 if (block_group->flags & (BTRFS_BLOCK_GROUP_DUP |
8110 BTRFS_BLOCK_GROUP_RAID1 |
8111 BTRFS_BLOCK_GROUP_RAID10))
8112 factor = 2;
8113 else
8114 factor = 1;
8106 8115
8107 /* make sure this block group isn't part of an allocation cluster */ 8116 /* make sure this block group isn't part of an allocation cluster */
8108 cluster = &root->fs_info->data_alloc_cluster; 8117 cluster = &root->fs_info->data_alloc_cluster;
@@ -8143,6 +8152,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
8143 spin_lock(&block_group->space_info->lock); 8152 spin_lock(&block_group->space_info->lock);
8144 block_group->space_info->total_bytes -= block_group->key.offset; 8153 block_group->space_info->total_bytes -= block_group->key.offset;
8145 block_group->space_info->bytes_readonly -= block_group->key.offset; 8154 block_group->space_info->bytes_readonly -= block_group->key.offset;
8155 block_group->space_info->disk_total -= block_group->key.offset * factor;
8146 spin_unlock(&block_group->space_info->lock); 8156 spin_unlock(&block_group->space_info->lock);
8147 8157
8148 btrfs_clear_space_info_full(root->fs_info); 8158 btrfs_clear_space_info_full(root->fs_info);
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index f2393b390318..afab6ca14d03 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -716,18 +716,25 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
716 struct list_head *head = &root->fs_info->space_info; 716 struct list_head *head = &root->fs_info->space_info;
717 struct btrfs_space_info *found; 717 struct btrfs_space_info *found;
718 u64 total_used = 0; 718 u64 total_used = 0;
719 u64 total_used_data = 0;
719 int bits = dentry->d_sb->s_blocksize_bits; 720 int bits = dentry->d_sb->s_blocksize_bits;
720 __be32 *fsid = (__be32 *)root->fs_info->fsid; 721 __be32 *fsid = (__be32 *)root->fs_info->fsid;
721 722
722 rcu_read_lock(); 723 rcu_read_lock();
723 list_for_each_entry_rcu(found, head, list) 724 list_for_each_entry_rcu(found, head, list) {
725 if (found->flags & (BTRFS_BLOCK_GROUP_METADATA |
726 BTRFS_BLOCK_GROUP_SYSTEM))
727 total_used_data += found->disk_total;
728 else
729 total_used_data += found->disk_used;
724 total_used += found->disk_used; 730 total_used += found->disk_used;
731 }
725 rcu_read_unlock(); 732 rcu_read_unlock();
726 733
727 buf->f_namelen = BTRFS_NAME_LEN; 734 buf->f_namelen = BTRFS_NAME_LEN;
728 buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; 735 buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits;
729 buf->f_bfree = buf->f_blocks - (total_used >> bits); 736 buf->f_bfree = buf->f_blocks - (total_used >> bits);
730 buf->f_bavail = buf->f_bfree; 737 buf->f_bavail = buf->f_blocks - (total_used_data >> bits);
731 buf->f_bsize = dentry->d_sb->s_blocksize; 738 buf->f_bsize = dentry->d_sb->s_blocksize;
732 buf->f_type = BTRFS_SUPER_MAGIC; 739 buf->f_type = BTRFS_SUPER_MAGIC;
733 740