Commit cc7539ed authored by Zhao Lei's avatar Zhao Lei Committed by Chris Mason

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: default avatarZhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent e34c330d
...@@ -4876,18 +4876,17 @@ static inline int parity_smaller(u64 a, u64 b) ...@@ -4876,18 +4876,17 @@ static inline int parity_smaller(u64 a, u64 b)
} }
/* Bubble-sort the stripe set to put the parity/syndrome stripes last */ /* Bubble-sort the stripe set to put the parity/syndrome stripes last */
static void sort_parity_stripes(struct btrfs_bio *bbio, u64 *raid_map) static void sort_parity_stripes(struct btrfs_bio *bbio, u64 *raid_map,
int num_stripes)
{ {
struct btrfs_bio_stripe s; struct btrfs_bio_stripe s;
int real_stripes = bbio->num_stripes - bbio->num_tgtdevs;
int i; int i;
u64 l; u64 l;
int again = 1; int again = 1;
int m;
while (again) { while (again) {
again = 0; again = 0;
for (i = 0; i < real_stripes - 1; i++) { for (i = 0; i < num_stripes - 1; i++) {
if (parity_smaller(raid_map[i], raid_map[i+1])) { if (parity_smaller(raid_map[i], raid_map[i+1])) {
s = bbio->stripes[i]; s = bbio->stripes[i];
l = raid_map[i]; l = raid_map[i];
...@@ -4896,13 +4895,6 @@ static void sort_parity_stripes(struct btrfs_bio *bbio, u64 *raid_map) ...@@ -4896,13 +4895,6 @@ static void sort_parity_stripes(struct btrfs_bio *bbio, u64 *raid_map)
bbio->stripes[i+1] = s; bbio->stripes[i+1] = s;
raid_map[i+1] = l; raid_map[i+1] = l;
if (bbio->tgtdev_map) {
m = bbio->tgtdev_map[i];
bbio->tgtdev_map[i] =
bbio->tgtdev_map[i + 1];
bbio->tgtdev_map[i + 1] = m;
}
again = 1; again = 1;
} }
} }
...@@ -5340,6 +5332,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, ...@@ -5340,6 +5332,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS))
max_errors = btrfs_chunk_max_errors(map); max_errors = btrfs_chunk_max_errors(map);
if (raid_map)
sort_parity_stripes(bbio, raid_map, num_stripes);
tgtdev_indexes = 0; tgtdev_indexes = 0;
if (dev_replace_is_ongoing && (rw & (REQ_WRITE | REQ_DISCARD)) && if (dev_replace_is_ongoing && (rw & (REQ_WRITE | REQ_DISCARD)) &&
dev_replace->tgtdev != NULL) { dev_replace->tgtdev != NULL) {
...@@ -5443,10 +5438,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, ...@@ -5443,10 +5438,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
bbio->stripes[0].physical = physical_to_patch_in_first_stripe; bbio->stripes[0].physical = physical_to_patch_in_first_stripe;
bbio->mirror_num = map->num_stripes + 1; bbio->mirror_num = map->num_stripes + 1;
} }
if (raid_map) {
sort_parity_stripes(bbio, raid_map); if (raid_map_ret)
*raid_map_ret = raid_map; *raid_map_ret = raid_map;
}
out: out:
if (dev_replace_is_ongoing) if (dev_replace_is_ongoing)
btrfs_dev_replace_unlock(dev_replace); btrfs_dev_replace_unlock(dev_replace);
......
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