linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: Goldwyn Rodrigues <rgoldwyn@suse.de>,
	<linux-btrfs@vger.kernel.org>, David Sterba <dsterba@suse.com>
Cc: Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: Re: [PATCH 1/2] btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON
Date: Wed, 7 Dec 2016 08:31:14 +0800	[thread overview]
Message-ID: <269500a6-a96d-c23e-fced-f74d55059b63@cn.fujitsu.com> (raw)
In-Reply-To: <b929d5ff-2ec1-9ac0-eb39-d2ed3ddff6da@suse.de>



At 12/06/2016 08:44 PM, Goldwyn Rodrigues wrote:
>
>
> On 12/05/2016 09:08 PM, Qu Wenruo wrote:
>>
>>
>> At 12/06/2016 10:51 AM, Goldwyn Rodrigues wrote:
>>>
>>>
>>> On 12/05/2016 08:03 PM, Qu Wenruo wrote:
>>>> BTW, the DISABLE_BACKTRACE branch seems quite different from
>>>> backtrace one.
>>>>
>>>> #define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__,
>>>> (long)(c))
>>>> #define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
>>>> (long)(c))
>>>> #define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__,
>>>> (long)!(c))
>>>> #define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1)
>>>> #else
>>>> #define BUG_ON(c) assert(!(c))
>>>> #define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
>>>> (long)(c))
>>>> #define ASSERT(c) assert(!(c))
>>>> #define BUG() assert(0)
>>>>
>>>> Condition of BUG_ON/ASSERT/BUG are all logical notted for
>>>> DISABLE_BACKTRACE.
>>>> While WARN_ON() of both branch are the same condition.
>>>
>>> WARN_ON is using warning_trace as opposed to assert, and that is the
>>> reason it is not notted.
>>>
>>>>
>>>> This seems quite confusing to me.
>>>>
>>>> Any idea to make it more straightforward?
>>>>
>>>
>>> I just kept it the same as before. warning_trace was using an extra
>>> variable, trace, which was not needed because the print_trace was
>>> already in ifndefs.
>>
>> I mean, better make the condition the same for both BUG/BUG_ON/ASSERT.
>> So that we don't need to manually logical not the condition.
>
> First of all, ASSERT and BUG_ON have opposite meanings. ASSERT() checks
> if the condition is true and continues (halts if false). BUG_ON() "bugs"
> if condition is true and halts (continues if false). So you would have
> to use opposite conditions.

I know, I mean, for both backtrace disabled and enabled case, the 
condition should be the same.

If not the same condition, it means assert_trace() has different meaning 
than original assert.

>
>>
>> For example:
>> #define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__,(long)
>> (c))
>> and
>> #define ASSERT(c) assert((c))
>>
>> This looks much more straightforward, and easier to expose bug at review
>> time.
>
> Could you explain with a patch? You idea seems to add more code than
> reduce it.

Sure, will submit one soon.

Thanks,
Qu



      reply	other threads:[~2016-12-07  0:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29 16:24 [PATCH 1/2] btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON Goldwyn Rodrigues
2016-11-30 14:43 ` David Sterba
2016-12-05  7:10 ` Qu Wenruo
2016-12-05 11:38   ` Goldwyn Rodrigues
2016-12-06  2:03     ` Qu Wenruo
2016-12-06  2:51       ` Goldwyn Rodrigues
2016-12-06  3:08         ` Qu Wenruo
2016-12-06 12:44           ` Goldwyn Rodrigues
2016-12-07  0:31             ` Qu Wenruo [this message]

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=269500a6-a96d-c23e-fced-f74d55059b63@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=rgoldwyn@suse.com \
    --cc=rgoldwyn@suse.de \
    /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).