All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: Zach Brown <zab@redhat.com>
Cc: Josef Bacik <jbacik@fusionio.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: add support for asserts
Date: Mon, 26 Aug 2013 17:02:35 -0500	[thread overview]
Message-ID: <521BD07B.2050600@redhat.com> (raw)
In-Reply-To: <20130826215326.GH26818@lenny.home.zabbo.net>

On 8/26/13 4:53 PM, Zach Brown wrote:
>> With this we can
>> go through and convert any BUG_ON()'s that we have to catch actual programming
>> mistakes to the new ASSERT() and then fix everybody else to return errors.
> 
> I like the sound of that!
> 
>> --- a/fs/btrfs/ctree.h
>> +++ b/fs/btrfs/ctree.h
>> @@ -3814,6 +3814,22 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
>>  #define btrfs_debug(fs_info, fmt, args...) \
>>  	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
>>  
>> +#ifdef BTRFS_ASSERT
>> +
>> +static inline void assfail(char *expr, char *file, int lin)
>> +{
>> +	printk(KERN_ERR "BTRFS assertion failed: %s, file: %s, line: %d",
>> +	       expr, file, line);
>> +	BUG();
>> +}
> 
> I'm not sure why this is needed.

I think it's because we'd like to see the assertion that failed in plain text,
which then would need a function as above, but we'd rather not see that
_every_ ASSERT() failure was at the line of the BUG() in the helper function...

i.e. when xfs trips it does this:

XFS: Assertion failed: first <= last && last < BBTOB(bp->b_length),
file: fs/xfs/xfs_trans_buf.c, line: 568
------------[ cut here ]------------
kernel BUG at fs/xfs/xfs_message.c:108!

note the 2 different line numbers; 568 is what's relevant, 108 is not.

>> +#define ASSERT(expr)	\
>> +	(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
> 
> (Passing the assertion is unlikely()?  I know, this is from xfs...
> still.)

hah, that's great.

>> +#else
>> +#define ASSERT(expr)	((void)0)
>> +#endif
> 
> Anyway, if you're going to do it this way, why not:
> 
> 	#ifdef BTRFS_ASSERT
> 	#define btrfs_assert(cond)  BUG_ON(!(cond))
> 	#else
> 	#define btrfs_assert(cond)  do { if (cond) ; } while (0)
> 	#endif

I think the only downside is that the BUG_ON() won't print the
conditional that failed, IIRC.

-Eric

> ?
> 
> - z


  reply	other threads:[~2013-08-26 22:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-26 20:56 [PATCH] Btrfs: add support for asserts Josef Bacik
2013-08-26 21:21 ` Eric Sandeen
2013-08-26 21:53 ` Zach Brown
2013-08-26 22:02   ` Eric Sandeen [this message]
2013-08-26 22:09     ` Zach Brown
2013-08-27 13:47   ` Josef Bacik
2013-08-27 19:23     ` Jeff Mahoney
2013-08-27 19:28 ` Jeff Mahoney
2013-08-27 20:56   ` Josef Bacik
2013-08-27 21:07     ` Jeff Mahoney
2013-08-27 21:21       ` Eric Sandeen
2013-08-27 21:25         ` Jeff Mahoney
2013-08-27 21:28           ` Eric Sandeen
2013-08-27 21:38             ` Jeff Mahoney
2013-08-28 16:32 ` 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=521BD07B.2050600@redhat.com \
    --to=sandeen@redhat.com \
    --cc=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=zab@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.