Skip to content

Commit c7c97ce

Browse files
morbidrsakdave
authored andcommitted
btrfs: handle bio_split() errors
Commit e546fe1 ("block: Rework bio_split() return value") changed bio_split() so that it can return errors. Add error handling for it in btrfs_split_bio() and ultimately btrfs_submit_chunk(). As the bio is not submitted, the bio counter must be decremented to pair btrfs_bio_counter_inc_blocked(). Reviewed-by: John Garry <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c83d77e commit c7c97ce

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

fs/btrfs/bio.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info,
8181

8282
bio = bio_split(&orig_bbio->bio, map_length >> SECTOR_SHIFT, GFP_NOFS,
8383
&btrfs_clone_bioset);
84+
if (IS_ERR(bio))
85+
return ERR_CAST(bio);
86+
8487
bbio = btrfs_bio(bio);
8588
btrfs_bio_init(bbio, fs_info, NULL, orig_bbio);
8689
bbio->inode = orig_bbio->inode;
@@ -678,15 +681,24 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
678681
&bioc, &smap, &mirror_num);
679682
if (error) {
680683
ret = errno_to_blk_status(error);
681-
goto fail;
684+
btrfs_bio_counter_dec(fs_info);
685+
goto end_bbio;
682686
}
683687

684688
map_length = min(map_length, length);
685689
if (use_append)
686690
map_length = btrfs_append_map_length(bbio, map_length);
687691

688692
if (map_length < length) {
689-
bbio = btrfs_split_bio(fs_info, bbio, map_length);
693+
struct btrfs_bio *split;
694+
695+
split = btrfs_split_bio(fs_info, bbio, map_length);
696+
if (IS_ERR(split)) {
697+
ret = errno_to_blk_status(PTR_ERR(split));
698+
btrfs_bio_counter_dec(fs_info);
699+
goto end_bbio;
700+
}
701+
bbio = split;
690702
bio = &bbio->bio;
691703
}
692704

@@ -760,6 +772,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
760772

761773
btrfs_bio_end_io(remaining, ret);
762774
}
775+
end_bbio:
763776
btrfs_bio_end_io(bbio, ret);
764777
/* Do not submit another chunk */
765778
return true;

0 commit comments

Comments
 (0)