提交 89a55897 编写于 作者: J Josef Bacik

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: NJosef Bacik <josef@redhat.com>
上级 bf5fc093
...@@ -675,7 +675,8 @@ struct btrfs_block_group_item { ...@@ -675,7 +675,8 @@ struct btrfs_block_group_item {
struct btrfs_space_info { struct btrfs_space_info {
u64 flags; u64 flags;
u64 total_bytes; /* total bytes in the space */ u64 total_bytes; /* total bytes in the space,
this doesn't take mirrors into account */
u64 bytes_used; /* total bytes used, u64 bytes_used; /* total bytes used,
this does't take mirrors into account */ this does't take mirrors into account */
u64 bytes_pinned; /* total bytes pinned, will be freed when the u64 bytes_pinned; /* total bytes pinned, will be freed when the
...@@ -687,6 +688,8 @@ struct btrfs_space_info { ...@@ -687,6 +688,8 @@ struct btrfs_space_info {
u64 bytes_may_use; /* number of bytes that may be used for u64 bytes_may_use; /* number of bytes that may be used for
delalloc/allocations */ delalloc/allocations */
u64 disk_used; /* total bytes used on disk */ u64 disk_used; /* total bytes used on disk */
u64 disk_total; /* total bytes on disk, takes mirrors into
account */
int full; /* indicates that we cannot allocate any more int full; /* indicates that we cannot allocate any more
chunks for this space */ chunks for this space */
......
...@@ -2763,6 +2763,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags, ...@@ -2763,6 +2763,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
if (found) { if (found) {
spin_lock(&found->lock); spin_lock(&found->lock);
found->total_bytes += total_bytes; found->total_bytes += total_bytes;
found->disk_total += total_bytes * factor;
found->bytes_used += bytes_used; found->bytes_used += bytes_used;
found->disk_used += bytes_used * factor; found->disk_used += bytes_used * factor;
found->full = 0; found->full = 0;
...@@ -2782,6 +2783,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags, ...@@ -2782,6 +2783,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
BTRFS_BLOCK_GROUP_SYSTEM | BTRFS_BLOCK_GROUP_SYSTEM |
BTRFS_BLOCK_GROUP_METADATA); BTRFS_BLOCK_GROUP_METADATA);
found->total_bytes = total_bytes; found->total_bytes = total_bytes;
found->disk_total = total_bytes * factor;
found->bytes_used = bytes_used; found->bytes_used = bytes_used;
found->disk_used = bytes_used * factor; found->disk_used = bytes_used * factor;
found->bytes_pinned = 0; found->bytes_pinned = 0;
...@@ -8095,6 +8097,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, ...@@ -8095,6 +8097,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
struct btrfs_free_cluster *cluster; struct btrfs_free_cluster *cluster;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
int factor;
root = root->fs_info->extent_root; root = root->fs_info->extent_root;
...@@ -8103,6 +8106,12 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, ...@@ -8103,6 +8106,12 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
BUG_ON(!block_group->ro); BUG_ON(!block_group->ro);
memcpy(&key, &block_group->key, sizeof(key)); memcpy(&key, &block_group->key, sizeof(key));
if (block_group->flags & (BTRFS_BLOCK_GROUP_DUP |
BTRFS_BLOCK_GROUP_RAID1 |
BTRFS_BLOCK_GROUP_RAID10))
factor = 2;
else
factor = 1;
/* make sure this block group isn't part of an allocation cluster */ /* make sure this block group isn't part of an allocation cluster */
cluster = &root->fs_info->data_alloc_cluster; cluster = &root->fs_info->data_alloc_cluster;
...@@ -8143,6 +8152,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, ...@@ -8143,6 +8152,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
spin_lock(&block_group->space_info->lock); spin_lock(&block_group->space_info->lock);
block_group->space_info->total_bytes -= block_group->key.offset; block_group->space_info->total_bytes -= block_group->key.offset;
block_group->space_info->bytes_readonly -= block_group->key.offset; block_group->space_info->bytes_readonly -= block_group->key.offset;
block_group->space_info->disk_total -= block_group->key.offset * factor;
spin_unlock(&block_group->space_info->lock); spin_unlock(&block_group->space_info->lock);
btrfs_clear_space_info_full(root->fs_info); btrfs_clear_space_info_full(root->fs_info);
......
...@@ -716,18 +716,25 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) ...@@ -716,18 +716,25 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
struct list_head *head = &root->fs_info->space_info; struct list_head *head = &root->fs_info->space_info;
struct btrfs_space_info *found; struct btrfs_space_info *found;
u64 total_used = 0; u64 total_used = 0;
u64 total_used_data = 0;
int bits = dentry->d_sb->s_blocksize_bits; int bits = dentry->d_sb->s_blocksize_bits;
__be32 *fsid = (__be32 *)root->fs_info->fsid; __be32 *fsid = (__be32 *)root->fs_info->fsid;
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(found, head, list) list_for_each_entry_rcu(found, head, list) {
if (found->flags & (BTRFS_BLOCK_GROUP_METADATA |
BTRFS_BLOCK_GROUP_SYSTEM))
total_used_data += found->disk_total;
else
total_used_data += found->disk_used;
total_used += found->disk_used; total_used += found->disk_used;
}
rcu_read_unlock(); rcu_read_unlock();
buf->f_namelen = BTRFS_NAME_LEN; buf->f_namelen = BTRFS_NAME_LEN;
buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits;
buf->f_bfree = buf->f_blocks - (total_used >> bits); buf->f_bfree = buf->f_blocks - (total_used >> bits);
buf->f_bavail = buf->f_bfree; buf->f_bavail = buf->f_blocks - (total_used_data >> bits);
buf->f_bsize = dentry->d_sb->s_blocksize; buf->f_bsize = dentry->d_sb->s_blocksize;
buf->f_type = BTRFS_SUPER_MAGIC; buf->f_type = BTRFS_SUPER_MAGIC;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册