From patchwork Tue Feb 25 15:28:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitch Harder X-Patchwork-Id: 3717661 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7089ABF13A for ; Tue, 25 Feb 2014 15:28:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D3FB2017E for ; Tue, 25 Feb 2014 15:28:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3EFCC20170 for ; Tue, 25 Feb 2014 15:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753025AbaBYP2q (ORCPT ); Tue, 25 Feb 2014 10:28:46 -0500 Received: from mail-yh0-f47.google.com ([209.85.213.47]:35552 "EHLO mail-yh0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752827AbaBYP2p (ORCPT ); Tue, 25 Feb 2014 10:28:45 -0500 Received: by mail-yh0-f47.google.com with SMTP id c41so7097802yho.34 for ; Tue, 25 Feb 2014 07:28:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zYRA5fkJ9YMyQ6ceh61GYPE1V6t1JVZn6ch8eKUTRbU=; b=Cfl6sMOqaDRKT6++gzgxKE3oZ4EyPpV2m+hLrmJImP89DR9ExSDUOWAWw3DO3UBNQI 4nEG29dk1nzLVIfH+Jc1Ei3dGpbJvycr8JgxCkfNBCNQ1WUadYyj/XeSA31c2tlG+h2y WseV3AWVj/7yea1RSJ60g/wn7SX808m3+13BGLEoCH350QTn4i5mZ9t+lQmgiN8ewgoN MroLLl69f8VJIHxUYr1iSbzWdwFNCr1ZXXRQN4hnSEdJo+ZEYts65fLX/rCffX/1MLny M2KXcCSHVHhoGVKHb6Ad5YEQHtGbS8qnC5aNUyr7C+ExyQ8B51V2AFVH08w19iouJqyM 4eLw== X-Gm-Message-State: ALoCoQlX64vmjLqRO6xMRuBFO5SCTWSPhios7Ozv7f4Wg9ifxHs5rKVY/+cAngyHf1ozb3N6/5Y2 X-Received: by 10.236.207.73 with SMTP id m49mr465553yho.5.1393342125010; Tue, 25 Feb 2014 07:28:45 -0800 (PST) Received: from core2duo.gateway.2wire.net (108-84-253-144.lightspeed.moblal.sbcglobal.net. [108.84.253.144]) by mx.google.com with ESMTPSA id 57sm9512994yhl.4.2014.02.25.07.28.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Feb 2014 07:28:44 -0800 (PST) From: Mitch Harder To: linux-btrfs@vger.kernel.org Cc: Mitch Harder Subject: [PATCH] [RFC] btrfs-progs: Expand BUG_ON/WARN_ON Macros Date: Tue, 25 Feb 2014 09:28:38 -0600 Message-Id: <1393342118-22771-1-git-send-email-mitch.harder@sabayonlinux.org> X-Mailer: git-send-email 1.8.3.2 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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); \