All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mitch Harder <mitch.harder@sabayonlinux.org>
To: linux-btrfs@vger.kernel.org
Cc: Mitch Harder <mitch.harder@sabayonlinux.org>
Subject: [PATCH] [RFC] btrfs-progs: Expand BUG_ON/WARN_ON Macros
Date: Tue, 25 Feb 2014 09:28:38 -0600	[thread overview]
Message-ID: <1393342118-22771-1-git-send-email-mitch.harder@sabayonlinux.org> (raw)

I'm providing this patch as an example of how to expand the
BUG_ON/WARN_ON macros to provide more information or extra
capabilities.

Josef Bacik has been working on working with a user on IRC
to recover data from a btrfs volume, and the 'work-in-progress'
solution involved expanding the BUG_ON/WARN_ON macros in a
different method that would lose the information on where
the BUG_ON/WARN_ON occured.

When the macro is structured like this patch, it will still
provide the location of the BUG_ON/WARN_ON in the code.

This patch also highlights that BUG_ON and WARN_ON are the
same thing in btrfs-progs.  All WARN_ONs are treated the same
as BUG_ONs, and the program is halted.

Should we convert all our btrfs-progs WARN_ONs to BUG_ONs to
allow us to implement a true WARN_ON functionality?

Signed-off-by: Mitch Harder <mitch.harder@sabayonlinux.org>
---
 kerncompat.h | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/kerncompat.h b/kerncompat.h
index f370cd8..79661f5 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -233,9 +233,19 @@ static inline long IS_ERR(const void *ptr)
 #define kstrdup(x, y) strdup(x)
 #define kfree(x) free(x)
 
-#define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) assert(!(c))
+#define BUG_ON(c) do { \
+	if (c) { \
+		fprintf(stderr, "BUG_ON!\n"); \
+		assert(!(c)); \
+	} \
+} while (0)
 
+#define WARN_ON(c) do { \
+	if (c) { \
+		fprintf(stderr, "WARN_ON!\n"); \
+		assert(!(c)); \
+	} \
+} while (0)
 
 #define container_of(ptr, type, member) ({                      \
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
-- 
1.8.3.2


                 reply	other threads:[~2014-02-25 15:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1393342118-22771-1-git-send-email-mitch.harder@sabayonlinux.org \
    --to=mitch.harder@sabayonlinux.org \
    --cc=linux-btrfs@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 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.