Btrfs: fix eof while discarding extents
We miscalculate the length of extents we're discarding, and it leads to an eof of device. Reported-by: Daniel Blueman <daniel@quora.org> Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
parent
d95603b262
commit
b89203f74b
|
@ -3833,6 +3833,7 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
|
||||||
int sub_stripes = 0;
|
int sub_stripes = 0;
|
||||||
u64 stripes_per_dev = 0;
|
u64 stripes_per_dev = 0;
|
||||||
u32 remaining_stripes = 0;
|
u32 remaining_stripes = 0;
|
||||||
|
u32 last_stripe = 0;
|
||||||
|
|
||||||
if (map->type &
|
if (map->type &
|
||||||
(BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10)) {
|
(BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10)) {
|
||||||
|
@ -3846,6 +3847,8 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
|
||||||
stripe_nr_orig,
|
stripe_nr_orig,
|
||||||
factor,
|
factor,
|
||||||
&remaining_stripes);
|
&remaining_stripes);
|
||||||
|
div_u64_rem(stripe_nr_end - 1, factor, &last_stripe);
|
||||||
|
last_stripe *= sub_stripes;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < num_stripes; i++) {
|
for (i = 0; i < num_stripes; i++) {
|
||||||
|
@ -3858,16 +3861,29 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
|
||||||
BTRFS_BLOCK_GROUP_RAID10)) {
|
BTRFS_BLOCK_GROUP_RAID10)) {
|
||||||
bbio->stripes[i].length = stripes_per_dev *
|
bbio->stripes[i].length = stripes_per_dev *
|
||||||
map->stripe_len;
|
map->stripe_len;
|
||||||
|
|
||||||
if (i / sub_stripes < remaining_stripes)
|
if (i / sub_stripes < remaining_stripes)
|
||||||
bbio->stripes[i].length +=
|
bbio->stripes[i].length +=
|
||||||
map->stripe_len;
|
map->stripe_len;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Special for the first stripe and
|
||||||
|
* the last stripe:
|
||||||
|
*
|
||||||
|
* |-------|...|-------|
|
||||||
|
* |----------|
|
||||||
|
* off end_off
|
||||||
|
*/
|
||||||
if (i < sub_stripes)
|
if (i < sub_stripes)
|
||||||
bbio->stripes[i].length -=
|
bbio->stripes[i].length -=
|
||||||
stripe_offset;
|
stripe_offset;
|
||||||
if ((i / sub_stripes + 1) %
|
|
||||||
sub_stripes == remaining_stripes)
|
if (stripe_index >= last_stripe &&
|
||||||
|
stripe_index <= (last_stripe +
|
||||||
|
sub_stripes - 1))
|
||||||
bbio->stripes[i].length -=
|
bbio->stripes[i].length -=
|
||||||
stripe_end_offset;
|
stripe_end_offset;
|
||||||
|
|
||||||
if (i == sub_stripes - 1)
|
if (i == sub_stripes - 1)
|
||||||
stripe_offset = 0;
|
stripe_offset = 0;
|
||||||
} else
|
} else
|
||||||
|
|
Loading…
Reference in New Issue