Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: John Garry <john.g.garry@oracle.com>
To: Johannes Thumshirn <jth@kernel.org>, Chris Mason <clm@fb.com>,
	Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	"open list:BTRFS FILE SYSTEM" <linux-btrfs@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Cc: linux-block@vger.kernel.org,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: Re: [PATCH v2] btrfs: handle bio_split() error
Date: Fri, 1 Nov 2024 16:23:57 +0000	[thread overview]
Message-ID: <fd8a6edb-7775-4e15-9124-3be3c11adec0@oracle.com> (raw)
In-Reply-To: <20241031144458.11497-1-jth@kernel.org>

On 31/10/2024 14:44, Johannes Thumshirn wrote:
> From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> 
> Now that bio_split() can return errors, add error handling for it in
> btrfs_split_bio() and ultimately btrfs_submit_chunk().
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> 
> This is based on top of John Garry's series "bio_split() error handling
> rework" explicitly on the patch titled "block: Rework bio_split() return
> value", which are as of now (Tue Oct 29 10:02:16 2024) not yet merged into
> any tree.
> 
> Changes to v1:
> - convert ERR_PTR to blk_status_t
> - correctly fail already split bbios
> ---
>   fs/btrfs/bio.c | 16 ++++++++++++----
>   1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
> index 1f216d07eff6..d2cfef5e4d4a 100644
> --- a/fs/btrfs/bio.c
> +++ b/fs/btrfs/bio.c
> @@ -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;
> @@ -687,6 +690,10 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
>   
>   	if (map_length < length) {
>   		bbio = btrfs_split_bio(fs_info, bbio, map_length);
> +		if (IS_ERR(bbio)) {
> +			ret = errno_to_blk_status(PTR_ERR(bbio));

btrfs_split_bio() does splitting, but error means "goto fail". However 
other failure points "goto fail_split". I find that label naming odd.

Furthermore, at "fail", we call btrfs_bio_end_io() and that function 
dereferences bbio (which is -EINVAL or something like that)

Thanks,
John

> +			goto fail;
> +		}
>   		bio = &bbio->bio;
>   	}
>   
> @@ -698,7 +705,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
>   		bbio->saved_iter = bio->bi_iter;
>   		ret = btrfs_lookup_bio_sums(bbio);
>   		if (ret)
> -			goto fail;
> +			goto fail_split;
>   	}
>   
>   	if (btrfs_op(bio) == BTRFS_MAP_WRITE) {
> @@ -732,13 +739,13 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
>   
>   			ret = btrfs_bio_csum(bbio);
>   			if (ret)
> -				goto fail;
> +				goto fail_split;
>   		} else if (use_append ||
>   			   (btrfs_is_zoned(fs_info) && inode &&
>   			    inode->flags & BTRFS_INODE_NODATASUM)) {
>   			ret = btrfs_alloc_dummy_sum(bbio);
>   			if (ret)
> -				goto fail;
> +				goto fail_split;
>   		}
>   	}
>   
> @@ -746,7 +753,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
>   done:
>   	return map_length == length;
>   
> -fail:
> +fail_split:
>   	btrfs_bio_counter_dec(fs_info);
>   	/*
>   	 * We have split the original bbio, now we have to end both the current
> @@ -760,6 +767,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
>   
>   		btrfs_bio_end_io(remaining, ret);
>   	}
> +fail:
>   	btrfs_bio_end_io(bbio, ret);
>   	/* Do not submit another chunk */
>   	return true;


  reply	other threads:[~2024-11-01 16:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-31 14:44 [PATCH v2] btrfs: handle bio_split() error Johannes Thumshirn
2024-11-01 16:23 ` John Garry [this message]
2024-11-04  7:24   ` Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd8a6edb-7775-4e15-9124-3be3c11adec0@oracle.com \
    --to=john.g.garry@oracle.com \
    --cc=clm@fb.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=josef@toxicpanda.com \
    --cc=jth@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox