Btrfs: make raid attr array more readable
PATCH 2/2 Btrfs: make raid attr array more readable
As the title said, this patch just make raid attr array more readable.
--- fs/btrfs/ctree.h | 10 +++++++++- fs/btrfs/extent-tree.c | 22 +++++++++------------- fs/btrfs/volumes.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 20 deletions(-)
fs/btrfs/ctree.h +9 -1
@@ -953,7 +953,15 @@ struct btrfs_dev_replace_item {#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)#define BTRFS_BLOCK_GROUP_RESERVED BTRFS_AVAIL_ALLOC_BIT_SINGLE -#define BTRFS_NR_RAID_TYPES 5 + +enum btrfs_raid_types { +BTRFS_RAID_RAID10 , +BTRFS_RAID_RAID1 , +BTRFS_RAID_DUP , +BTRFS_RAID_RAID0 , +BTRFS_RAID_SINGLE , +BTRFS_NR_RAID_TYPES +};#define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \ BTRFS_BLOCK_GROUP_SYSTEM | \
fs/btrfs/extent-tree.c +9 -13
@@ -5547,20 +5547,16 @@ wait_block_group_cache_done(struct btrfs_block_group_cache *cache)int __get_raid_index (u64 flags) { -int index; -if (flags &BTRFS_BLOCK_GROUP_RAID10 ) - index =0 ; +return BTRFS_RAID_RAID10 ;else if (flags &BTRFS_BLOCK_GROUP_RAID1 ) - index =1 ; +return BTRFS_RAID_RAID1 ;else if (flags &BTRFS_BLOCK_GROUP_DUP ) - index =2 ; +return BTRFS_RAID_DUP ;else if (flags &BTRFS_BLOCK_GROUP_RAID0 ) - index =3 ; +return BTRFS_RAID_RAID0 ;else - index =4 ; - -return index; +return BTRFS_RAID_SINGLE ; }static int get_block_group_index (struct btrfs_block_group_cache *cache)
@@ -7520,16 +7516,16 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr) index =get_block_group_index (block_group); } -if (index ==0 ) { +if (index ==BTRFS_RAID_RAID10 ) { dev_min =4 ;/* Divide by 2 */ min_free >>=1 ; - }else if (index ==1 ) { + }else if (index ==BTRFS_RAID_RAID1 ) { dev_min =2 ; - }else if (index ==2 ) { + }else if (index ==BTRFS_RAID_DUP ) {/* Multiply by 2 */ min_free <<=1 ; - }else if (index ==3 ) { + }else if (index ==BTRFS_RAID_RAID0 ) { dev_min = fs_devices->rw_devices;do_div (min_free, dev_min); }
fs/btrfs/volumes.c +41 -6
54 lines not on this page · raw message
Signature · 1 line
1.7.11.7
Quoted 1 line · Miao Xie
As the title said, this patch just make raid attr array more readable.
Nice cleanup, thanks.
fs/btrfs/volumes.c static int btrfs_cmp_device_info(const void *a, const void *b) · line 3499
Quoted 12 lines
fs/btrfs/volumes.c +4
-1@@ -3492,13 +3492,48 @@ static int btrfs_cmp_device_info(const void *a, const void *b) }struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES ] = { - {1 ,1 ,2 ,2 ,2 ,2 /* raid1 */ }, + [BTRFS_RAID_RAID1 ] = { + .sub_stripes =1 , + .dev_stripes =1 , + .devs_max =2 ,
Unrelated, but I'm curious why is this set to 2 (and was before)? This will give preference to the same 2 devices as long as there's space, so the allocator will not spread the data over the device set. I'd expect the same behaviour as in RAID10 profile here.
fs/btrfs/volumes.c static int btrfs_cmp_device_info(const void *a, const void *b) · line 3510
Quoted 4 lines
fs/btrfs/volumes.c +4
-0+ .devs_min = 2, + .devs_increment = 2, + .ncopies = 2, + },
david
PATCH v2 2/2 Btrfs: make raid attr array more readable
The current code of raid attr arry is hard to understand and it is easy to introduce some problem if we modify the array. So I changed it and made it more readable.
---
Changelog v1 -> v2:
- fix missing initialization for single profile
--- fs/btrfs/ctree.h | 10 +++++++++- fs/btrfs/extent-tree.c | 22 +++++++++------------- fs/btrfs/volumes.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 20 deletions(-)
fs/btrfs/ctree.h +9 -1
@@ -953,7 +953,15 @@ struct btrfs_dev_replace_item {#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)#define BTRFS_BLOCK_GROUP_RESERVED BTRFS_AVAIL_ALLOC_BIT_SINGLE -#define BTRFS_NR_RAID_TYPES 5 + +enum btrfs_raid_types { +BTRFS_RAID_RAID10 , +BTRFS_RAID_RAID1 , +BTRFS_RAID_DUP , +BTRFS_RAID_RAID0 , +BTRFS_RAID_SINGLE , +BTRFS_NR_RAID_TYPES +};#define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \ BTRFS_BLOCK_GROUP_SYSTEM | \
fs/btrfs/extent-tree.c +9 -13
@@ -5547,20 +5547,16 @@ wait_block_group_cache_done(struct btrfs_block_group_cache *cache)int __get_raid_index (u64 flags) { -int index; -if (flags &BTRFS_BLOCK_GROUP_RAID10 ) - index =0 ; +return BTRFS_RAID_RAID10 ;else if (flags &BTRFS_BLOCK_GROUP_RAID1 ) - index =1 ; +return BTRFS_RAID_RAID1 ;else if (flags &BTRFS_BLOCK_GROUP_DUP ) - index =2 ; +return BTRFS_RAID_DUP ;else if (flags &BTRFS_BLOCK_GROUP_RAID0 ) - index =3 ; +return BTRFS_RAID_RAID0 ;else - index =4 ; - -return index; +return BTRFS_RAID_SINGLE ; }static int get_block_group_index (struct btrfs_block_group_cache *cache)
@@ -7520,16 +7516,16 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr) index =get_block_group_index (block_group); } -if (index ==0 ) { +if (index ==BTRFS_RAID_RAID10 ) { dev_min =4 ;/* Divide by 2 */ min_free >>=1 ; - }else if (index ==1 ) { + }else if (index ==BTRFS_RAID_RAID1 ) { dev_min =2 ; - }else if (index ==2 ) { + }else if (index ==BTRFS_RAID_DUP ) {/* Multiply by 2 */ min_free <<=1 ; - }else if (index ==3 ) { + }else if (index ==BTRFS_RAID_RAID0 ) { dev_min = fs_devices->rw_devices;do_div (min_free, dev_min); }
fs/btrfs/volumes.c +41 -6
54 lines not on this page · raw message
Signature · 1 line
1.7.11.7