linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs: replace BUG_ON() in btrfs_csum_one_bio() with proper error handling
Date: Mon, 2 Aug 2021 10:53:48 +0300	[thread overview]
Message-ID: <594df624-3895-8787-9058-a00dba01c0cc@suse.com> (raw)
In-Reply-To: <20210802065447.178726-3-wqu@suse.com>



On 2.08.21 г. 9:54, Qu Wenruo wrote:
> The BUG_ON() in btrfs_csum_one_bio() means we're trying to submit a bio
> while we don't have ordered extent for it at all.
> 
> Normally this won't happen and is indeed a code logical error.
> 
> But previous fix has already shown another possibility that, some call
> sites don't handle error properly and submit the write bio after its
> ordered extent has already been cleaned up.
> 
> This patch will add an extra safe net by replacing the BUG_ON() to
> proper error handling.
> 
> And even if some day we hit a regression that we're submitting bio
> without an ordered extent, we will return error and the pages will be
> marked Error, and being caught properly.

Would this hamper debugability? I.e it will result in some writes
failing with an error, right?

> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  fs/btrfs/file-item.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
> index 2673c6ba7a4e..25205b9dad69 100644
> --- a/fs/btrfs/file-item.c
> +++ b/fs/btrfs/file-item.c
> @@ -665,7 +665,19 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
>  
>  		if (!ordered) {
>  			ordered = btrfs_lookup_ordered_extent(inode, offset);
> -			BUG_ON(!ordered); /* Logic error */
> +			/*
> +			 * No ordered extent mostly means the OE has been
> +			 * removed (mostly for error handling). Normally for
> +			 * such case we should not flush_write_bio(), but
> +			 * end_write_bio().
> +			 *
> +			 * But an extra safe net will never hurt. Just error
> +			 * out.
> +			 */
> +			if (unlikely(!ordered)) {
> +				kvfree(sums);
> +				return BLK_STS_IOERR;
> +			}
>  		}
>  
>  		nr_sectors = BTRFS_BYTES_TO_BLKS(fs_info,
> 

  reply	other threads:[~2021-08-02  7:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02  6:54 [PATCH 0/2] btrfs: fix the generic/475 crash for subpage case Qu Wenruo
2021-08-02  6:54 ` [PATCH 1/2] btrfs: don't try to flush data write bio if we hit error preparing it Qu Wenruo
2021-08-02  6:54 ` [PATCH 2/2] btrfs: replace BUG_ON() in btrfs_csum_one_bio() with proper error handling Qu Wenruo
2021-08-02  7:53   ` Nikolay Borisov [this message]
2021-08-02  8:03     ` Qu Wenruo
2021-08-02  8:49       ` Nikolay Borisov
2021-08-16 14:21         ` David Sterba
2021-08-16 23:30           ` Qu Wenruo
2021-08-03  5:31 ` [PATCH 0/2] btrfs: fix the generic/475 crash for subpage case Qu Wenruo

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=594df624-3895-8787-9058-a00dba01c0cc@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /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;
as well as URLs for NNTP newsgroup(s).