Btrfs: Link block groups of different raid types in the same space_info
PATCH v2 1/12 Btrfs: Link block groups of different raid types in the same space_info
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 Yan Zheng <[email protected]>
---
fs/btrfs/ctree.h +5 -2
@@ -662,6 +662,7 @@ struct btrfs_csum_item {#define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)#define BTRFS_BLOCK_GROUP_DUP (1 << 5)#define BTRFS_BLOCK_GROUP_RAID10 (1 << 6) +#define BTRFS_NR_RAID_TYPES 5struct btrfs_block_group_item {__le64 used;
@@ -673,7 +674,8 @@ struct btrfs_space_info {u64 flags;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 transaction finishes */ u64 bytes_reserved;/* total bytes the allocator has reserved for
@@ -686,6 +688,7 @@ struct btrfs_space_info {delalloc/allocations */ u64 bytes_delalloc;/* number of bytes currently reserved for delayed allocation */ +u64 disk_used;/* total bytes used on disk */ int full;/* indicates that we cannot allocate any more chunks for this space */
@@ -703,7 +706,7 @@ struct btrfs_space_info {int flushing;/* for block groups in our same type */ -struct list_head block_groups; +struct list_head block_groups[BTRFS_NR_RAID_TYPES ];spinlock_t lock;struct rw_semaphore groups_sem;atomic_t caching_threads;
fs/btrfs/extent-tree.c +112 -33
300 lines not on this page · raw message
fs/btrfs/super.c +3 -19
@@ -713,34 +713,18 @@ static int btrfs_statfs(struct dentry *dstruct list_head *head = &root->fs_info->space_info;struct btrfs_space_info *found;u64 total_used =0 ; -u64 data_used =0 ;int bits = dentry->d_sb->s_blocksize_bits;__be32 *fsid = (__be32 *)root->fs_info->fsid;rcu_read_lock (); -list_for_each_entry_rcu (found, head, list) { -if (found->flags & (BTRFS_BLOCK_GROUP_DUP | -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; - } +list_for_each_entry_rcu (found, head, list) + total_used += found->disk_used;rcu_read_unlock (); buf->f_namelen =BTRFS_NAME_LEN ; buf->f_blocks =btrfs_super_total_bytes (disk_super) >> 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_type =BTRFS_SUPER_MAGIC ;