diff options
author | Zhao Lei <zhaolei@cn.fujitsu.com> | 2015-01-20 02:11:32 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-01-21 21:06:47 -0500 |
commit | cc7539edea6dd02536d56f0a3405b8bb7ae24168 (patch) | |
tree | cd1ab7dbecc7d7d4984002915277c2cba54989fc /fs/btrfs | |
parent | e34c330d639177bbb345bf2bde16613b00cc6e6b (diff) |
Btrfs: sort raid_map before adding tgtdev stripes
It can avoid complex calculation of real stripes in sort,
moreover, we can clean up code of sorting tgtdev_map because it
will be in order initially.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/volumes.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 0d9bfebdaa4c..711ce38543a1 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -4876,18 +4876,17 @@ static inline int parity_smaller(u64 a, u64 b) | |||
4876 | } | 4876 | } |
4877 | 4877 | ||
4878 | /* Bubble-sort the stripe set to put the parity/syndrome stripes last */ | 4878 | /* Bubble-sort the stripe set to put the parity/syndrome stripes last */ |
4879 | static void sort_parity_stripes(struct btrfs_bio *bbio, u64 *raid_map) | 4879 | static void sort_parity_stripes(struct btrfs_bio *bbio, u64 *raid_map, |
4880 | int num_stripes) | ||
4880 | { | 4881 | { |
4881 | struct btrfs_bio_stripe s; | 4882 | struct btrfs_bio_stripe s; |
4882 | int real_stripes = bbio->num_stripes - bbio->num_tgtdevs; | ||
4883 | int i; | 4883 | int i; |
4884 | u64 l; | 4884 | u64 l; |
4885 | int again = 1; | 4885 | int again = 1; |
4886 | int m; | ||
4887 | 4886 | ||
4888 | while (again) { | 4887 | while (again) { |
4889 | again = 0; | 4888 | again = 0; |
4890 | for (i = 0; i < real_stripes - 1; i++) { | 4889 | for (i = 0; i < num_stripes - 1; i++) { |
4891 | if (parity_smaller(raid_map[i], raid_map[i+1])) { | 4890 | if (parity_smaller(raid_map[i], raid_map[i+1])) { |
4892 | s = bbio->stripes[i]; | 4891 | s = bbio->stripes[i]; |
4893 | l = raid_map[i]; | 4892 | l = raid_map[i]; |
@@ -4896,13 +4895,6 @@ static void sort_parity_stripes(struct btrfs_bio *bbio, u64 *raid_map) | |||
4896 | bbio->stripes[i+1] = s; | 4895 | bbio->stripes[i+1] = s; |
4897 | raid_map[i+1] = l; | 4896 | raid_map[i+1] = l; |
4898 | 4897 | ||
4899 | if (bbio->tgtdev_map) { | ||
4900 | m = bbio->tgtdev_map[i]; | ||
4901 | bbio->tgtdev_map[i] = | ||
4902 | bbio->tgtdev_map[i + 1]; | ||
4903 | bbio->tgtdev_map[i + 1] = m; | ||
4904 | } | ||
4905 | |||
4906 | again = 1; | 4898 | again = 1; |
4907 | } | 4899 | } |
4908 | } | 4900 | } |
@@ -5340,6 +5332,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
5340 | if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) | 5332 | if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) |
5341 | max_errors = btrfs_chunk_max_errors(map); | 5333 | max_errors = btrfs_chunk_max_errors(map); |
5342 | 5334 | ||
5335 | if (raid_map) | ||
5336 | sort_parity_stripes(bbio, raid_map, num_stripes); | ||
5337 | |||
5343 | tgtdev_indexes = 0; | 5338 | tgtdev_indexes = 0; |
5344 | if (dev_replace_is_ongoing && (rw & (REQ_WRITE | REQ_DISCARD)) && | 5339 | if (dev_replace_is_ongoing && (rw & (REQ_WRITE | REQ_DISCARD)) && |
5345 | dev_replace->tgtdev != NULL) { | 5340 | dev_replace->tgtdev != NULL) { |
@@ -5443,10 +5438,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
5443 | bbio->stripes[0].physical = physical_to_patch_in_first_stripe; | 5438 | bbio->stripes[0].physical = physical_to_patch_in_first_stripe; |
5444 | bbio->mirror_num = map->num_stripes + 1; | 5439 | bbio->mirror_num = map->num_stripes + 1; |
5445 | } | 5440 | } |
5446 | if (raid_map) { | 5441 | |
5447 | sort_parity_stripes(bbio, raid_map); | 5442 | if (raid_map_ret) |
5448 | *raid_map_ret = raid_map; | 5443 | *raid_map_ret = raid_map; |
5449 | } | ||
5450 | out: | 5444 | out: |
5451 | if (dev_replace_is_ongoing) | 5445 | if (dev_replace_is_ongoing) |
5452 | btrfs_dev_replace_unlock(dev_replace); | 5446 | btrfs_dev_replace_unlock(dev_replace); |