Skip to content

Commit

Permalink
btrfs: handle bio_split() errors
Browse files Browse the repository at this point in the history
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 <john.g.garry@oracle.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Johannes Thumshirn authored and David Sterba committed Dec 6, 2024
1 parent c83d77e commit c7c97ce
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions fs/btrfs/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info,

bio = bio_split(&orig_bbio->bio, map_length >> SECTOR_SHIFT, GFP_NOFS,
&btrfs_clone_bioset);
if (IS_ERR(bio))
return ERR_CAST(bio);

bbio = btrfs_bio(bio);
btrfs_bio_init(bbio, fs_info, NULL, orig_bbio);
bbio->inode = orig_bbio->inode;
Expand Down Expand Up @@ -678,15 +681,24 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
&bioc, &smap, &mirror_num);
if (error) {
ret = errno_to_blk_status(error);
goto fail;
btrfs_bio_counter_dec(fs_info);
goto end_bbio;
}

map_length = min(map_length, length);
if (use_append)
map_length = btrfs_append_map_length(bbio, map_length);

if (map_length < length) {
bbio = btrfs_split_bio(fs_info, bbio, map_length);
struct btrfs_bio *split;

split = btrfs_split_bio(fs_info, bbio, map_length);
if (IS_ERR(split)) {
ret = errno_to_blk_status(PTR_ERR(split));
btrfs_bio_counter_dec(fs_info);
goto end_bbio;
}
bbio = split;
bio = &bbio->bio;
}

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

btrfs_bio_end_io(remaining, ret);
}
end_bbio:
btrfs_bio_end_io(bbio, ret);
/* Do not submit another chunk */
return true;
Expand Down

0 comments on commit c7c97ce

Please sign in to comment.