From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: dsterba@suse.cz, Nikolay Borisov <nborisov@suse.com>,
Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2] btrfs: replace BUG_ON() in btrfs_csum_one_bio() with proper error handling
Date: Thu, 19 Aug 2021 09:08:00 +0800 [thread overview]
Message-ID: <0f469eae-d30f-64cf-b07f-fb0a097e6741@gmx.com> (raw)
In-Reply-To: <20210818230032.GA5047@twin.jikos.cz>
On 2021/8/19 上午7:00, David Sterba wrote:
> On Tue, Aug 17, 2021 at 04:10:43PM +0800, Qu Wenruo wrote:
>> On 2021/8/17 下午3:55, Nikolay Borisov wrote:
>>> On 17.08.21 г. 2:55, Qu Wenruo wrote:
>>>> @@ -665,7 +665,18 @@ 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 */
>>>> + /*
>>>> + * The bio range is not covered by any ordered extent,
>>>> + * must be a code logic error.
>>>> + */
>>>> + if (unlikely(!ordered)) {
>>>> + WARN(1, KERN_WARNING
>>>> + "no ordered extent for root %llu ino %llu offset %llu\n",
>>>> + inode->root->root_key.objectid,
>>>> + btrfs_ino(inode), offset);
>>>> + kvfree(sums);
>>>> + return BLK_STS_IOERR;
>>>> + }
>>>
>>> nit: How about :
>>>
>>> if (WARN_ON(!ordered) {
>>
>> I still remember that if (WARN_ON()) usage is not recommended by David.
>>
>> Is that still the case?
>
> Quick grep shows there are many if (WARN_ON(...)) so as long as it's a
> simple "if (WARN_ON(condition))" and the code is readable I won't
> object.
>
> The problematic one is "if (!WARN_ON(condition))", because it warns when
> condition is true, but the if does not continue and that breaks the
> reading flow. The acceptable pattern read like "if condition and warn
> eventually and continue".
>
I want to play safe by never bothering the WARN_ON() in if () condition
anymore.
The fact that some if (WARN_ON()) is acceptable and some is not is
already worrying.
Can we just stick to no-WARN_ON-in-if policy?
Thanks,
Qu
next prev parent reply other threads:[~2021-08-19 1:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-16 23:55 [PATCH v2] btrfs: replace BUG_ON() in btrfs_csum_one_bio() with proper error handling Qu Wenruo
2021-08-17 7:55 ` Nikolay Borisov
2021-08-17 8:03 ` Nikolay Borisov
2021-08-17 8:10 ` Qu Wenruo
2021-08-18 23:00 ` David Sterba
2021-08-19 1:08 ` Qu Wenruo [this message]
2021-08-19 12:23 ` David Sterba
2021-08-19 12:34 ` Qu Wenruo
2021-09-07 14:13 ` David Sterba
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=0f469eae-d30f-64cf-b07f-fb0a097e6741@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.com \
--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