aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Bo <bo.li.liu@oracle.com>2012-11-21 09:18:10 -0500
committerChris Mason <chris.mason@fusionio.com>2012-12-16 20:46:28 -0500
commit31e502298d80e2af9001d17dc419a3fd4b0bebef (patch)
tree24606ea4998e962fff864eb24e8be6f56b095e14
parent4ded4f639533ed5f02a0f0ab20d43bb9659c91f8 (diff)
Btrfs: put raid properties into global table
Raid properties can be shared among raid calculation code, we can put them into a global table to keep it simple. Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r--fs/btrfs/ctree.h1
-rw-r--r--fs/btrfs/extent-tree.c6
-rw-r--r--fs/btrfs/volumes.c46
-rw-r--r--fs/btrfs/volumes.h9
4 files changed, 29 insertions, 33 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index cd02205f13c8..44d9bc87e863 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3077,6 +3077,7 @@ int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range);
3077int btrfs_init_space_info(struct btrfs_fs_info *fs_info); 3077int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
3078int btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans, 3078int btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans,
3079 struct btrfs_fs_info *fs_info); 3079 struct btrfs_fs_info *fs_info);
3080int __get_raid_index(u64 flags);
3080/* ctree.c */ 3081/* ctree.c */
3081int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, 3082int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key,
3082 int level, int *slot); 3083 int level, int *slot);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index e15280989188..b9526f749049 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5479,7 +5479,7 @@ wait_block_group_cache_done(struct btrfs_block_group_cache *cache)
5479 return 0; 5479 return 0;
5480} 5480}
5481 5481
5482static int __get_block_group_index(u64 flags) 5482int __get_raid_index(u64 flags)
5483{ 5483{
5484 int index; 5484 int index;
5485 5485
@@ -5499,7 +5499,7 @@ static int __get_block_group_index(u64 flags)
5499 5499
5500static int get_block_group_index(struct btrfs_block_group_cache *cache) 5500static int get_block_group_index(struct btrfs_block_group_cache *cache)
5501{ 5501{
5502 return __get_block_group_index(cache->flags); 5502 return __get_raid_index(cache->flags);
5503} 5503}
5504 5504
5505enum btrfs_loop_type { 5505enum btrfs_loop_type {
@@ -7441,7 +7441,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
7441 */ 7441 */
7442 target = get_restripe_target(root->fs_info, block_group->flags); 7442 target = get_restripe_target(root->fs_info, block_group->flags);
7443 if (target) { 7443 if (target) {
7444 index = __get_block_group_index(extended_to_chunk(target)); 7444 index = __get_raid_index(extended_to_chunk(target));
7445 } else { 7445 } else {
7446 /* 7446 /*
7447 * this is just a balance, so if we were marked as full 7447 * this is just a balance, so if we were marked as full
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index d79b5b620e94..5cce6aa74012 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3491,6 +3491,14 @@ static int btrfs_cmp_device_info(const void *a, const void *b)
3491 return 0; 3491 return 0;
3492} 3492}
3493 3493
3494struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
3495 { 2, 1, 0, 4, 2, 2 /* raid10 */ },
3496 { 1, 1, 2, 2, 2, 2 /* raid1 */ },
3497 { 1, 2, 1, 1, 1, 2 /* dup */ },
3498 { 1, 1, 0, 2, 1, 1 /* raid0 */ },
3499 { 1, 1, 0, 1, 1, 1 /* single */ },
3500};
3501
3494static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, 3502static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
3495 struct btrfs_root *extent_root, 3503 struct btrfs_root *extent_root,
3496 struct map_lookup **map_ret, 3504 struct map_lookup **map_ret,
@@ -3520,43 +3528,21 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
3520 int ndevs; 3528 int ndevs;
3521 int i; 3529 int i;
3522 int j; 3530 int j;
3531 int index;
3523 3532
3524 BUG_ON(!alloc_profile_is_valid(type, 0)); 3533 BUG_ON(!alloc_profile_is_valid(type, 0));
3525 3534
3526 if (list_empty(&fs_devices->alloc_list)) 3535 if (list_empty(&fs_devices->alloc_list))
3527 return -ENOSPC; 3536 return -ENOSPC;
3528 3537
3529 sub_stripes = 1; 3538 index = __get_raid_index(type);
3530 dev_stripes = 1;
3531 devs_increment = 1;
3532 ncopies = 1;
3533 devs_max = 0; /* 0 == as many as possible */
3534 devs_min = 1;
3535 3539
3536 /* 3540 sub_stripes = btrfs_raid_array[index].sub_stripes;
3537 * define the properties of each RAID type. 3541 dev_stripes = btrfs_raid_array[index].dev_stripes;
3538 * FIXME: move this to a global table and use it in all RAID 3542 devs_max = btrfs_raid_array[index].devs_max;
3539 * calculation code 3543 devs_min = btrfs_raid_array[index].devs_min;
3540 */ 3544 devs_increment = btrfs_raid_array[index].devs_increment;
3541 if (type & (BTRFS_BLOCK_GROUP_DUP)) { 3545 ncopies = btrfs_raid_array[index].ncopies;
3542 dev_stripes = 2;
3543 ncopies = 2;
3544 devs_max = 1;
3545 } else if (type & (BTRFS_BLOCK_GROUP_RAID0)) {
3546 devs_min = 2;
3547 } else if (type & (BTRFS_BLOCK_GROUP_RAID1)) {
3548 devs_increment = 2;
3549 ncopies = 2;
3550 devs_max = 2;
3551 devs_min = 2;
3552 } else if (type & (BTRFS_BLOCK_GROUP_RAID10)) {
3553 sub_stripes = 2;
3554 devs_increment = 2;
3555 ncopies = 2;
3556 devs_min = 4;
3557 } else {
3558 devs_max = 1;
3559 }
3560 3546
3561 if (type & BTRFS_BLOCK_GROUP_DATA) { 3547 if (type & BTRFS_BLOCK_GROUP_DATA) {
3562 max_stripe_size = 1024 * 1024 * 1024; 3548 max_stripe_size = 1024 * 1024 * 1024;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 37d0157167b0..d3c3939ac751 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -180,6 +180,15 @@ struct btrfs_device_info {
180 u64 total_avail; 180 u64 total_avail;
181}; 181};
182 182
183struct btrfs_raid_attr {
184 int sub_stripes; /* sub_stripes info for map */
185 int dev_stripes; /* stripes per dev */
186 int devs_max; /* max devs to use */
187 int devs_min; /* min devs needed */
188 int devs_increment; /* ndevs has to be a multiple of this */
189 int ncopies; /* how many copies to data has */
190};
191
183struct map_lookup { 192struct map_lookup {
184 u64 type; 193 u64 type;
185 int io_align; 194 int io_align;