Commit b742bb82 authored by Yan, Zheng's avatar Yan, Zheng Committed by Chris Mason

Btrfs: Link block groups of different raid types

The size of reserved space is stored in space_info. If block groups
of different raid types are linked to separate space_info, changing
allocation profile will corrupt reserved space accounting.
Signed-off-by: default avatarYan Zheng <zheng.yan@oracle.com>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent e40152ee
...@@ -663,6 +663,7 @@ struct btrfs_csum_item { ...@@ -663,6 +663,7 @@ struct btrfs_csum_item {
#define BTRFS_BLOCK_GROUP_RAID1 (1 << 4) #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
#define BTRFS_BLOCK_GROUP_DUP (1 << 5) #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
#define BTRFS_BLOCK_GROUP_RAID10 (1 << 6) #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
#define BTRFS_NR_RAID_TYPES 5
struct btrfs_block_group_item { struct btrfs_block_group_item {
__le64 used; __le64 used;
...@@ -674,7 +675,8 @@ struct btrfs_space_info { ...@@ -674,7 +675,8 @@ struct btrfs_space_info {
u64 flags; u64 flags;
u64 total_bytes; /* total bytes in the space */ u64 total_bytes; /* total bytes in the space */
u64 bytes_used; /* total bytes used on disk */ u64 bytes_used; /* total bytes used,
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
transaction finishes */ transaction finishes */
u64 bytes_reserved; /* total bytes the allocator has reserved for u64 bytes_reserved; /* total bytes the allocator has reserved for
...@@ -687,6 +689,7 @@ struct btrfs_space_info { ...@@ -687,6 +689,7 @@ struct btrfs_space_info {
delalloc/allocations */ delalloc/allocations */
u64 bytes_delalloc; /* number of bytes currently reserved for u64 bytes_delalloc; /* number of bytes currently reserved for
delayed allocation */ delayed allocation */
u64 disk_used; /* total bytes used on disk */
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 */
...@@ -704,7 +707,7 @@ struct btrfs_space_info { ...@@ -704,7 +707,7 @@ struct btrfs_space_info {
int flushing; int flushing;
/* for block groups in our same type */ /* for block groups in our same type */
struct list_head block_groups; struct list_head block_groups[BTRFS_NR_RAID_TYPES];
spinlock_t lock; spinlock_t lock;
struct rw_semaphore groups_sem; struct rw_semaphore groups_sem;
atomic_t caching_threads; atomic_t caching_threads;
......
This diff is collapsed.
...@@ -714,34 +714,18 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) ...@@ -714,34 +714,18 @@ 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 data_used = 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_DUP| total_used += found->disk_used;
BTRFS_BLOCK_GROUP_RAID10|
BTRFS_BLOCK_GROUP_RAID1)) {
total_used += found->bytes_used;
if (found->flags & BTRFS_BLOCK_GROUP_DATA)
data_used += found->bytes_used;
else
data_used += found->total_bytes;
}
total_used += found->bytes_used;
if (found->flags & BTRFS_BLOCK_GROUP_DATA)
data_used += found->bytes_used;
else
data_used += found->total_bytes;
}
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_blocks - (data_used >> bits); buf->f_bavail = buf->f_bfree;
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%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment