Skip to content

Commit 8408c71

Browse files
Miao XieChris Mason
authored andcommitted
Btrfs: fix wrong error handle when the device is missing or is not writeable
The original bio might be submitted, so we shoud increase bi_remaining to account for it when we deal with the error that the device is missing or is not writeable, or we would skip the endio handle. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent c55f139 commit 8408c71

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

‎fs/btrfs/volumes.c‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5359,6 +5359,15 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
53595359
return 0;
53605360
}
53615361

5362+
static inline void btrfs_end_bbio(struct btrfs_bio *bbio, struct bio *bio, int err)
5363+
{
5364+
if (likely(bbio->flags & BTRFS_BIO_ORIG_BIO_SUBMITTED))
5365+
bio_endio_nodec(bio, err);
5366+
else
5367+
bio_endio(bio, err);
5368+
kfree(bbio);
5369+
}
5370+
53625371
static void btrfs_end_bio(struct bio *bio, int err)
53635372
{
53645373
struct btrfs_bio *bbio = bio->bi_private;
@@ -5416,11 +5425,7 @@ static void btrfs_end_bio(struct bio *bio, int err)
54165425
err = 0;
54175426
}
54185427

5419-
if (likely(bbio->flags & BTRFS_BIO_ORIG_BIO_SUBMITTED))
5420-
bio_endio_nodec(bio, err);
5421-
else
5422-
bio_endio(bio, err);
5423-
kfree(bbio);
5428+
btrfs_end_bbio(bbio, bio, err);
54245429
} else if (!is_orig_bio) {
54255430
bio_put(bio);
54265431
}
@@ -5583,12 +5588,15 @@ static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical)
55835588
{
55845589
atomic_inc(&bbio->error);
55855590
if (atomic_dec_and_test(&bbio->stripes_pending)) {
5591+
/* Shoud be the original bio. */
5592+
WARN_ON(bio != bbio->orig_bio);
5593+
55865594
bio->bi_private = bbio->private;
55875595
bio->bi_end_io = bbio->end_io;
55885596
btrfs_io_bio(bio)->mirror_num = bbio->mirror_num;
55895597
bio->bi_iter.bi_sector = logical >> 9;
5590-
kfree(bbio);
5591-
bio_endio(bio, -EIO);
5598+
5599+
btrfs_end_bbio(bbio, bio, -EIO);
55925600
}
55935601
}
55945602

0 commit comments

Comments
 (0)