btrfs: use need_full_stripe() in __btrfs_map_block()

A cleanup patch, use need_full_stripe() to replace the open code.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Anand Jain 2017-10-12 16:43:00 +08:00 committed by David Sterba
parent 79f015f216
commit de48373454
1 changed files with 6 additions and 10 deletions

View File

@ -5691,10 +5691,10 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
if (map->type & BTRFS_BLOCK_GROUP_RAID0) { if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
stripe_nr = div_u64_rem(stripe_nr, map->num_stripes, stripe_nr = div_u64_rem(stripe_nr, map->num_stripes,
&stripe_index); &stripe_index);
if (op != BTRFS_MAP_WRITE && op != BTRFS_MAP_GET_READ_MIRRORS) if (!need_full_stripe(op))
mirror_num = 1; mirror_num = 1;
} else if (map->type & BTRFS_BLOCK_GROUP_RAID1) { } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) if (need_full_stripe(op))
num_stripes = map->num_stripes; num_stripes = map->num_stripes;
else if (mirror_num) else if (mirror_num)
stripe_index = mirror_num - 1; stripe_index = mirror_num - 1;
@ -5707,7 +5707,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
} }
} else if (map->type & BTRFS_BLOCK_GROUP_DUP) { } else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) { if (need_full_stripe(op)) {
num_stripes = map->num_stripes; num_stripes = map->num_stripes;
} else if (mirror_num) { } else if (mirror_num) {
stripe_index = mirror_num - 1; stripe_index = mirror_num - 1;
@ -5721,7 +5721,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index); stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index);
stripe_index *= map->sub_stripes; stripe_index *= map->sub_stripes;
if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) if (need_full_stripe(op))
num_stripes = map->sub_stripes; num_stripes = map->sub_stripes;
else if (mirror_num) else if (mirror_num)
stripe_index += mirror_num - 1; stripe_index += mirror_num - 1;
@ -5736,9 +5736,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
} }
} else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
if (need_raid_map && if (need_raid_map && (need_full_stripe(op) || mirror_num > 1)) {
(op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS ||
mirror_num > 1)) {
/* push stripe_nr back to the start of the full stripe */ /* push stripe_nr back to the start of the full stripe */
stripe_nr = div64_u64(raid56_full_stripe_start, stripe_nr = div64_u64(raid56_full_stripe_start,
stripe_len * nr_data_stripes(map)); stripe_len * nr_data_stripes(map));
@ -5765,9 +5763,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
/* We distribute the parity blocks across stripes */ /* We distribute the parity blocks across stripes */
div_u64_rem(stripe_nr + stripe_index, map->num_stripes, div_u64_rem(stripe_nr + stripe_index, map->num_stripes,
&stripe_index); &stripe_index);
if ((op != BTRFS_MAP_WRITE && if (!need_full_stripe(op) && mirror_num <= 1)
op != BTRFS_MAP_GET_READ_MIRRORS) &&
mirror_num <= 1)
mirror_num = 1; mirror_num = 1;
} }
} else { } else {