* [PATCH 2/7] Make shrink_dcache_for_umount_subtree() use ANNOTATED_BUG()
2011-12-16 14:13 [PATCH 1/7] Add conditional oopsing with annotation David Howells
@ 2011-12-16 14:14 ` David Howells
2011-12-16 14:14 ` [PATCH 3/7] Add assertion checking macros David Howells
` (7 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: David Howells @ 2011-12-16 14:14 UTC (permalink / raw)
To: linux-arch, mingo; +Cc: linux-kernel, David Howells
Make shrink_dcache_for_umount_subtree() use ANNOTATED_BUG() rather than doing
printk() then BUG() so that the annotation appears _after_ the "cut here" line
instead of before it.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/dcache.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index 89509b5..4083c50 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -37,6 +37,7 @@
#include <linux/rculist_bl.h>
#include <linux/prefetch.h>
#include <linux/ratelimit.h>
+#include <linux/bug.h>
#include "internal.h"
/*
@@ -889,9 +890,9 @@ static void shrink_dcache_for_umount_subtree(struct dentry *dentry)
dentry_lru_prune(dentry);
__d_shrink(dentry);
- if (dentry->d_count != 0) {
- printk(KERN_ERR
- "BUG: Dentry %p{i=%lx,n=%s}"
+ if (unlikely(dentry->d_count != 0))
+ ANNOTATED_BUG(
+ "Dentry %p{i=%lx,n=%s}"
" still in use (%d)"
" [unmount of %s %s]\n",
dentry,
@@ -901,8 +902,6 @@ static void shrink_dcache_for_umount_subtree(struct dentry *dentry)
dentry->d_count,
dentry->d_sb->s_type->name,
dentry->d_sb->s_id);
- BUG();
- }
if (IS_ROOT(dentry)) {
parent = NULL;
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH 3/7] Add assertion checking macros
2011-12-16 14:13 [PATCH 1/7] Add conditional oopsing with annotation David Howells
2011-12-16 14:14 ` [PATCH 2/7] Make shrink_dcache_for_umount_subtree() use ANNOTATED_BUG() David Howells
@ 2011-12-16 14:14 ` David Howells
2011-12-16 14:14 ` David Howells
` (2 more replies)
2011-12-16 14:14 ` [PATCH 4/7] FS-Cache: Use new core assertion macros David Howells
` (6 subsequent siblings)
8 siblings, 3 replies; 18+ messages in thread
From: David Howells @ 2011-12-16 14:14 UTC (permalink / raw)
To: linux-arch, mingo; +Cc: linux-kernel, David Howells
Add a range of ASSERT* macros to linux/assert.h for performing runtime
assertions. These will use ANNOTATED_BUG() to create an annotated oops if the
check fails.
All but the first macro will display the values and condition(s) involved in
the failed check as these are very useful for working out the cause of the
problem and may not necessarily be easily determinable from the register and
stack dumps.
The checks are only enabled under two circumstances:
(1) CONFIG_DEBUG_ENABLE_ASSERTIONS=y
(2) ENABLE_ASSERTIONS is defined prior to the #inclusion of <linux/assert.h>
There are five macros provided:
(a) ASSERT(X)
Issue an assertion failure error if X is false. In other words, require
the expression X to be true. For example:
ASSERT(val != 0);
There is no need to display val here in the case the expression fails
since it can only be 0. If this fails, it produces an error like the
following:
------------[ cut here ]------------
kernel BUG at fs/fscache/main.c:109!
ASSERTION FAILED
invalid opcode: 0000 [#1] SMP
(b) ASSERTCMP(X, OP, Y)
Issue an assertion failure error if the expression X OP Y is false. For
example:
ASSERTCMP(x, >, 12)
If an oops is produced, then the values of X and Y will be displayed in
hex, along with OP:
------------[ cut here ]------------
kernel BUG at fs/fscache/main.c:109!
ASSERTION FAILED: 2 > c is false
invalid opcode: 0000 [#1] SMP
(c) ASSERTRANGE(X, OP, Y, OP2, Z)
Issue an assertion failure error if the expression X OP Y or if the
expression Y OP2 Z is false. Typically OP and OP2 would be < or <=,
looking something like:
ASSERTRANGE(11, <, x, <=, 13);
and giving the following error:
------------[ cut here ]------------
kernel BUG at fs/fscache/main.c:109!
ASSERTION FAILED: b < 2 <= d is false
invalid opcode: 0000 [#1] SMP
and for compactness, where an assertion should only apply under certain
circumstances:
(d) ASSERTIF(C, X)
If condition C is true, issue an assertion failure error if X is false.
For example:
ASSERTIF(test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags),
object->n_exclusive != 0);
(e) ASSERTIFCMP(C, X, OP, Y)
This is a combination of ASSERTIF and ASSERTCMP. For example:
ASSERTIFCMP(test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags),
object->n_exclusive, >, 0);
Signed-off-by: David Howells <dhowells@redhat.com>
---
include/linux/assert.h | 111 ++++++++++++++++++++++++++++++++++++++++++++++++
lib/Kconfig.debug | 8 +++
2 files changed, 119 insertions(+), 0 deletions(-)
create mode 100644 include/linux/assert.h
diff --git a/include/linux/assert.h b/include/linux/assert.h
new file mode 100644
index 0000000..e1e9264
--- /dev/null
+++ b/include/linux/assert.h
@@ -0,0 +1,111 @@
+/* Assertion checking
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_ASSERT_H
+#define _LINUX_ASSERT_H
+
+#include <linux/bug.h>
+
+/*
+ * ENABLE_ASSERTIONS can be set by an individual module to override the global
+ * setting and turn assertions on for just that module.
+ */
+#if defined(CONFIG_DEBUG_ENABLE_ASSERTIONS) || defined(ENABLE_ASSERTIONS)
+
+#define cond_assertion_failed(FMT, ...) \
+ do { \
+ ANNOTATED_BUG("ASSERTION FAILED" FMT, ## __VA_ARGS__); \
+ } while (0)
+
+#else
+
+#define cond_assertion_failed(FMT, ...) \
+ do { \
+ no_printk("ASSERTION FAILED" FMT, ## __VA_ARGS__); \
+ } while (0)
+
+#endif
+
+/**
+ * ASSERT - Oops if the given expression is not true
+ * X: The expression to check
+ */
+#define ASSERT(X) \
+do { \
+ if (unlikely(!(X))) \
+ cond_assertion_failed(""); \
+} while (0)
+
+/**
+ * ASSERTCMP - Oops if the specified check fails
+ * X: The value to check
+ * OP: The operator to use for comparison
+ * Y: The value to compare against
+ *
+ * The two values are displayed in the oops report if the assertion fails.
+ */
+#define ASSERTCMP(X, OP, Y) \
+do { \
+ if (unlikely(!((X) OP (Y)))) \
+ cond_assertion_failed(": %lx " #OP " %lx is false\n", \
+ (unsigned long)(X), \
+ (unsigned long)(Y)); \
+} while (0)
+
+/**
+ * ASSERTIF - If condition is true, oops if the given expression is not true
+ * C: The condition under which to perform the check
+ * X: The expression to check
+ */
+#define ASSERTIF(C, X) \
+do { \
+ if (unlikely((C) && !(X))) \
+ cond_assertion_failed(""); \
+} while (0)
+
+/**
+ * ASSERTIFCMP - If condition is true, oops if the specified check fails
+ * C: The condition under which to perform the check
+ * X: The value to check
+ * OP: The operator to use for comparison
+ * Y: The value to compare against
+ *
+ * The two values are displayed in the oops report if the assertion fails.
+ */
+#define ASSERTIFCMP(C, X, OP, Y) \
+do { \
+ if (unlikely((C) && !((X) OP (Y)))) \
+ cond_assertion_failed(": %lx " #OP " %lx is false\n", \
+ (unsigned long)(X), \
+ (unsigned long)(Y)); \
+} while (0)
+
+/**
+ * ASSERTCMP - Oops if the value is outside of the specified range
+ * X: The lower bound
+ * OP: The operator to use to check against the lower bound (< or <=)
+ * Y: The value to check
+ * OP2: The operator to use to check against the upper bound (< or <=)
+ * Z: The upper bound
+ *
+ * The three values are displayed in the oops report if the assertion fails.
+ */
+#define ASSERTRANGE(X, OP, Y, OP2, Z) \
+do { \
+ if (unlikely(!((X) OP (Y)) || !((Y) OP2 (Z)))) \
+ cond_assertion_failed(": %lx " #OP " %lx " #OP2 \
+ " %lx is false\n", \
+ (unsigned long)(X), \
+ (unsigned long)(Y), \
+ (unsigned long)(Z)); \
+} while(0)
+
+#endif /* _LINUX_ASSERT_H */
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 82928f5..b14acf9 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -149,6 +149,14 @@ config DEBUG_KERNEL
Say Y here if you are developing drivers or trying to debug and
identify kernel problems.
+config DEBUG_ENABLE_ASSERTIONS
+ bool "Enable assertion checks"
+ depends on BUG
+ help
+ Say Y here to globally enable checks made by the ASSERT*() macros.
+ If such a check fails, BUG() processing will be invoked and an
+ annotated oops will be emitted.
+
config DEBUG_SHIRQ
bool "Debug shared IRQ handlers"
depends on DEBUG_KERNEL && GENERIC_HARDIRQS
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH 3/7] Add assertion checking macros
2011-12-16 14:14 ` [PATCH 3/7] Add assertion checking macros David Howells
@ 2011-12-16 14:14 ` David Howells
2011-12-16 21:36 ` Andi Kleen
2011-12-20 15:38 ` David Howells
2 siblings, 0 replies; 18+ messages in thread
From: David Howells @ 2011-12-16 14:14 UTC (permalink / raw)
To: linux-arch, mingo; +Cc: linux-kernel, David Howells
Add a range of ASSERT* macros to linux/assert.h for performing runtime
assertions. These will use ANNOTATED_BUG() to create an annotated oops if the
check fails.
All but the first macro will display the values and condition(s) involved in
the failed check as these are very useful for working out the cause of the
problem and may not necessarily be easily determinable from the register and
stack dumps.
The checks are only enabled under two circumstances:
(1) CONFIG_DEBUG_ENABLE_ASSERTIONS=y
(2) ENABLE_ASSERTIONS is defined prior to the #inclusion of <linux/assert.h>
There are five macros provided:
(a) ASSERT(X)
Issue an assertion failure error if X is false. In other words, require
the expression X to be true. For example:
ASSERT(val != 0);
There is no need to display val here in the case the expression fails
since it can only be 0. If this fails, it produces an error like the
following:
------------[ cut here ]------------
kernel BUG at fs/fscache/main.c:109!
ASSERTION FAILED
invalid opcode: 0000 [#1] SMP
(b) ASSERTCMP(X, OP, Y)
Issue an assertion failure error if the expression X OP Y is false. For
example:
ASSERTCMP(x, >, 12)
If an oops is produced, then the values of X and Y will be displayed in
hex, along with OP:
------------[ cut here ]------------
kernel BUG at fs/fscache/main.c:109!
ASSERTION FAILED: 2 > c is false
invalid opcode: 0000 [#1] SMP
(c) ASSERTRANGE(X, OP, Y, OP2, Z)
Issue an assertion failure error if the expression X OP Y or if the
expression Y OP2 Z is false. Typically OP and OP2 would be < or <=,
looking something like:
ASSERTRANGE(11, <, x, <=, 13);
and giving the following error:
------------[ cut here ]------------
kernel BUG at fs/fscache/main.c:109!
ASSERTION FAILED: b < 2 <= d is false
invalid opcode: 0000 [#1] SMP
and for compactness, where an assertion should only apply under certain
circumstances:
(d) ASSERTIF(C, X)
If condition C is true, issue an assertion failure error if X is false.
For example:
ASSERTIF(test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags),
object->n_exclusive != 0);
(e) ASSERTIFCMP(C, X, OP, Y)
This is a combination of ASSERTIF and ASSERTCMP. For example:
ASSERTIFCMP(test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags),
object->n_exclusive, >, 0);
Signed-off-by: David Howells <dhowells@redhat.com>
---
include/linux/assert.h | 111 ++++++++++++++++++++++++++++++++++++++++++++++++
lib/Kconfig.debug | 8 +++
2 files changed, 119 insertions(+), 0 deletions(-)
create mode 100644 include/linux/assert.h
diff --git a/include/linux/assert.h b/include/linux/assert.h
new file mode 100644
index 0000000..e1e9264
--- /dev/null
+++ b/include/linux/assert.h
@@ -0,0 +1,111 @@
+/* Assertion checking
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_ASSERT_H
+#define _LINUX_ASSERT_H
+
+#include <linux/bug.h>
+
+/*
+ * ENABLE_ASSERTIONS can be set by an individual module to override the global
+ * setting and turn assertions on for just that module.
+ */
+#if defined(CONFIG_DEBUG_ENABLE_ASSERTIONS) || defined(ENABLE_ASSERTIONS)
+
+#define cond_assertion_failed(FMT, ...) \
+ do { \
+ ANNOTATED_BUG("ASSERTION FAILED" FMT, ## __VA_ARGS__); \
+ } while (0)
+
+#else
+
+#define cond_assertion_failed(FMT, ...) \
+ do { \
+ no_printk("ASSERTION FAILED" FMT, ## __VA_ARGS__); \
+ } while (0)
+
+#endif
+
+/**
+ * ASSERT - Oops if the given expression is not true
+ * X: The expression to check
+ */
+#define ASSERT(X) \
+do { \
+ if (unlikely(!(X))) \
+ cond_assertion_failed(""); \
+} while (0)
+
+/**
+ * ASSERTCMP - Oops if the specified check fails
+ * X: The value to check
+ * OP: The operator to use for comparison
+ * Y: The value to compare against
+ *
+ * The two values are displayed in the oops report if the assertion fails.
+ */
+#define ASSERTCMP(X, OP, Y) \
+do { \
+ if (unlikely(!((X) OP (Y)))) \
+ cond_assertion_failed(": %lx " #OP " %lx is false\n", \
+ (unsigned long)(X), \
+ (unsigned long)(Y)); \
+} while (0)
+
+/**
+ * ASSERTIF - If condition is true, oops if the given expression is not true
+ * C: The condition under which to perform the check
+ * X: The expression to check
+ */
+#define ASSERTIF(C, X) \
+do { \
+ if (unlikely((C) && !(X))) \
+ cond_assertion_failed(""); \
+} while (0)
+
+/**
+ * ASSERTIFCMP - If condition is true, oops if the specified check fails
+ * C: The condition under which to perform the check
+ * X: The value to check
+ * OP: The operator to use for comparison
+ * Y: The value to compare against
+ *
+ * The two values are displayed in the oops report if the assertion fails.
+ */
+#define ASSERTIFCMP(C, X, OP, Y) \
+do { \
+ if (unlikely((C) && !((X) OP (Y)))) \
+ cond_assertion_failed(": %lx " #OP " %lx is false\n", \
+ (unsigned long)(X), \
+ (unsigned long)(Y)); \
+} while (0)
+
+/**
+ * ASSERTCMP - Oops if the value is outside of the specified range
+ * X: The lower bound
+ * OP: The operator to use to check against the lower bound (< or <=)
+ * Y: The value to check
+ * OP2: The operator to use to check against the upper bound (< or <=)
+ * Z: The upper bound
+ *
+ * The three values are displayed in the oops report if the assertion fails.
+ */
+#define ASSERTRANGE(X, OP, Y, OP2, Z) \
+do { \
+ if (unlikely(!((X) OP (Y)) || !((Y) OP2 (Z)))) \
+ cond_assertion_failed(": %lx " #OP " %lx " #OP2 \
+ " %lx is false\n", \
+ (unsigned long)(X), \
+ (unsigned long)(Y), \
+ (unsigned long)(Z)); \
+} while(0)
+
+#endif /* _LINUX_ASSERT_H */
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 82928f5..b14acf9 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -149,6 +149,14 @@ config DEBUG_KERNEL
Say Y here if you are developing drivers or trying to debug and
identify kernel problems.
+config DEBUG_ENABLE_ASSERTIONS
+ bool "Enable assertion checks"
+ depends on BUG
+ help
+ Say Y here to globally enable checks made by the ASSERT*() macros.
+ If such a check fails, BUG() processing will be invoked and an
+ annotated oops will be emitted.
+
config DEBUG_SHIRQ
bool "Debug shared IRQ handlers"
depends on DEBUG_KERNEL && GENERIC_HARDIRQS
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH 3/7] Add assertion checking macros
2011-12-16 14:14 ` [PATCH 3/7] Add assertion checking macros David Howells
2011-12-16 14:14 ` David Howells
@ 2011-12-16 21:36 ` Andi Kleen
2011-12-20 15:38 ` David Howells
2 siblings, 0 replies; 18+ messages in thread
From: Andi Kleen @ 2011-12-16 21:36 UTC (permalink / raw)
To: David Howells; +Cc: linux-arch, mingo, linux-kernel
David Howells <dhowells@redhat.com> writes:
>
> There is no need to display val here in the case the expression fails
> since it can only be 0. If this fails, it produces an error like the
> following:
>
> ------------[ cut here ]------------
> kernel BUG at fs/fscache/main.c:109!
> ASSERTION FAILED
It would be nice to display the expression here like an user space
assert. While it can be looked up in the source it would
make quick eyeballing easier.
Probably wouldn't cost too much additional text size?
>
> (e) ASSERTIFCMP(C, X, OP, Y)
>
> This is a combination of ASSERTIF and ASSERTCMP. For example:
>
> ASSERTIFCMP(test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags),
> object->n_exclusive, >, 0);
You probably want a checkpatch rule with those to only allow a few
selected functions like test_bit. Otherwise people will put real side
effects in there.
-Andi
--
ak@linux.intel.com -- Speaking for myself only
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 3/7] Add assertion checking macros
2011-12-16 14:14 ` [PATCH 3/7] Add assertion checking macros David Howells
2011-12-16 14:14 ` David Howells
2011-12-16 21:36 ` Andi Kleen
@ 2011-12-20 15:38 ` David Howells
2 siblings, 0 replies; 18+ messages in thread
From: David Howells @ 2011-12-20 15:38 UTC (permalink / raw)
To: Andi Kleen; +Cc: dhowells, linux-arch, mingo, linux-kernel
Andi Kleen <andi@firstfloor.org> wrote:
> David Howells <dhowells@redhat.com> writes:
> >
> > There is no need to display val here in the case the expression fails
> > since it can only be 0. If this fails, it produces an error like the
> > following:
> >
> > ------------[ cut here ]------------
> > kernel BUG at fs/fscache/main.c:109!
> > ASSERTION FAILED
>
> It would be nice to display the expression here like an user space
> assert. While it can be looked up in the source it would
> make quick eyeballing easier.
>
> Probably wouldn't cost too much additional text size?
It can easily be made selectable. I don't think text size should be much of
an issue - but it will also add a bunch of strings (preprocessed expressions)
to the rodata, and I'm not sure how big those can get - particularly if
they've got nested macros within (test_bit() for example).
David
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 4/7] FS-Cache: Use new core assertion macros
2011-12-16 14:13 [PATCH 1/7] Add conditional oopsing with annotation David Howells
2011-12-16 14:14 ` [PATCH 2/7] Make shrink_dcache_for_umount_subtree() use ANNOTATED_BUG() David Howells
2011-12-16 14:14 ` [PATCH 3/7] Add assertion checking macros David Howells
@ 2011-12-16 14:14 ` David Howells
2011-12-16 14:14 ` [PATCH 5/7] CacheFiles: " David Howells
` (5 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: David Howells @ 2011-12-16 14:14 UTC (permalink / raw)
To: linux-arch, mingo; +Cc: linux-kernel, David Howells
Make FS-Cache use the new core assertion macros in place of its own.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/fscache/debug.h | 82 ++++++++++++++++++++++++++++++++
fs/fscache/internal.h | 126 +------------------------------------------------
2 files changed, 84 insertions(+), 124 deletions(-)
create mode 100644 fs/fscache/debug.h
diff --git a/fs/fscache/debug.h b/fs/fscache/debug.h
new file mode 100644
index 0000000..fcdbbab
--- /dev/null
+++ b/fs/fscache/debug.h
@@ -0,0 +1,82 @@
+/* Debug tracing
+ *
+ * Copyright (C) 2004-2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/printk.h>
+#define ENABLE_ASSERTIONS
+#include <linux/assert.h>
+
+/*
+ * debug tracing
+ */
+#define dbgprintk(FMT, ...) \
+ printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
+
+#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
+#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
+#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
+
+#define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
+
+#ifdef __KDEBUG
+#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
+#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
+#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
+
+#elif defined(CONFIG_FSCACHE_DEBUG)
+#define _enter(FMT, ...) \
+do { \
+ if (__do_kdebug(ENTER)) \
+ kenter(FMT, ##__VA_ARGS__); \
+} while (0)
+
+#define _leave(FMT, ...) \
+do { \
+ if (__do_kdebug(LEAVE)) \
+ kleave(FMT, ##__VA_ARGS__); \
+} while (0)
+
+#define _debug(FMT, ...) \
+do { \
+ if (__do_kdebug(DEBUG)) \
+ kdebug(FMT, ##__VA_ARGS__); \
+} while (0)
+
+#else
+#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
+#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
+#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
+#endif
+
+/*
+ * determine whether a particular optional debugging point should be logged
+ * - we need to go through three steps to persuade cpp to correctly join the
+ * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
+ */
+#define ____do_kdebug(LEVEL, POINT) \
+ unlikely((fscache_debug & \
+ (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
+#define ___do_kdebug(LEVEL, POINT) \
+ ____do_kdebug(LEVEL, POINT)
+#define __do_kdebug(POINT) \
+ ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
+
+#define FSCACHE_DEBUG_CACHE 0
+#define FSCACHE_DEBUG_COOKIE 1
+#define FSCACHE_DEBUG_PAGE 2
+#define FSCACHE_DEBUG_OPERATION 3
+
+#define FSCACHE_POINT_ENTER 1
+#define FSCACHE_POINT_LEAVE 2
+#define FSCACHE_POINT_DEBUG 4
+
+#ifndef FSCACHE_DEBUG_LEVEL
+#define FSCACHE_DEBUG_LEVEL CACHE
+#endif
diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
index f6aad48..4be65c9 100644
--- a/fs/fscache/internal.h
+++ b/fs/fscache/internal.h
@@ -24,6 +24,7 @@
#include <linux/fscache-cache.h>
#include <linux/sched.h>
+#include "debug.h"
#define FSCACHE_MIN_THREADS 4
#define FSCACHE_MAX_THREADS 32
@@ -288,7 +289,7 @@ static inline void fscache_raise_event(struct fscache_object *object,
*/
static inline void fscache_cookie_put(struct fscache_cookie *cookie)
{
- BUG_ON(atomic_read(&cookie->usage) <= 0);
+ ASSERTCMP(atomic_read(&cookie->usage), >, 0);
if (atomic_dec_and_test(&cookie->usage))
__fscache_cookie_put(cookie);
}
@@ -313,126 +314,3 @@ void fscache_put_context(struct fscache_cookie *cookie, void *context)
if (cookie->def->put_context)
cookie->def->put_context(cookie->netfs_data, context);
}
-
-/*****************************************************************************/
-/*
- * debug tracing
- */
-#define dbgprintk(FMT, ...) \
- printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
-
-#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
-#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
-#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
-
-#define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
-
-#ifdef __KDEBUG
-#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
-#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
-#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
-
-#elif defined(CONFIG_FSCACHE_DEBUG)
-#define _enter(FMT, ...) \
-do { \
- if (__do_kdebug(ENTER)) \
- kenter(FMT, ##__VA_ARGS__); \
-} while (0)
-
-#define _leave(FMT, ...) \
-do { \
- if (__do_kdebug(LEAVE)) \
- kleave(FMT, ##__VA_ARGS__); \
-} while (0)
-
-#define _debug(FMT, ...) \
-do { \
- if (__do_kdebug(DEBUG)) \
- kdebug(FMT, ##__VA_ARGS__); \
-} while (0)
-
-#else
-#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
-#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
-#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
-#endif
-
-/*
- * determine whether a particular optional debugging point should be logged
- * - we need to go through three steps to persuade cpp to correctly join the
- * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
- */
-#define ____do_kdebug(LEVEL, POINT) \
- unlikely((fscache_debug & \
- (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
-#define ___do_kdebug(LEVEL, POINT) \
- ____do_kdebug(LEVEL, POINT)
-#define __do_kdebug(POINT) \
- ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
-
-#define FSCACHE_DEBUG_CACHE 0
-#define FSCACHE_DEBUG_COOKIE 1
-#define FSCACHE_DEBUG_PAGE 2
-#define FSCACHE_DEBUG_OPERATION 3
-
-#define FSCACHE_POINT_ENTER 1
-#define FSCACHE_POINT_LEAVE 2
-#define FSCACHE_POINT_DEBUG 4
-
-#ifndef FSCACHE_DEBUG_LEVEL
-#define FSCACHE_DEBUG_LEVEL CACHE
-#endif
-
-/*
- * assertions
- */
-#if 1 /* defined(__KDEBUGALL) */
-
-#define ASSERT(X) \
-do { \
- if (unlikely(!(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
- if (unlikely(!((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- printk(KERN_ERR "%lx " #OP " %lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTIF(C, X) \
-do { \
- if (unlikely((C) && !(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
- if (unlikely((C) && !((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- printk(KERN_ERR "%lx " #OP " %lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while (0)
-
-#else
-
-#define ASSERT(X) do {} while (0)
-#define ASSERTCMP(X, OP, Y) do {} while (0)
-#define ASSERTIF(C, X) do {} while (0)
-#define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
-
-#endif /* assert or not */
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH 5/7] CacheFiles: Use new core assertion macros
2011-12-16 14:13 [PATCH 1/7] Add conditional oopsing with annotation David Howells
` (2 preceding siblings ...)
2011-12-16 14:14 ` [PATCH 4/7] FS-Cache: Use new core assertion macros David Howells
@ 2011-12-16 14:14 ` David Howells
2011-12-16 14:14 ` [PATCH 6/7] AFS: " David Howells
` (4 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: David Howells @ 2011-12-16 14:14 UTC (permalink / raw)
To: linux-arch, mingo; +Cc: linux-kernel, David Howells
Make CacheFiles use the new core assertion macros in place of its own.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/cachefiles/internal.h | 53 ++--------------------------------------------
1 files changed, 2 insertions(+), 51 deletions(-)
diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
index bd6bc1b..fd88085 100644
--- a/fs/cachefiles/internal.h
+++ b/fs/cachefiles/internal.h
@@ -14,6 +14,8 @@
#include <linux/wait.h>
#include <linux/workqueue.h>
#include <linux/security.h>
+#define ENABLE_ASSERTIONS
+#include <linux/assert.h>
struct cachefiles_cache;
struct cachefiles_object;
@@ -301,54 +303,3 @@ do { \
#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
#endif
-
-#if 1 /* defined(__KDEBUGALL) */
-
-#define ASSERT(X) \
-do { \
- if (unlikely(!(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "CacheFiles: Assertion failed\n"); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
- if (unlikely(!((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "CacheFiles: Assertion failed\n"); \
- printk(KERN_ERR "%lx " #OP " %lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTIF(C, X) \
-do { \
- if (unlikely((C) && !(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "CacheFiles: Assertion failed\n"); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
- if (unlikely((C) && !((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "CacheFiles: Assertion failed\n"); \
- printk(KERN_ERR "%lx " #OP " %lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while (0)
-
-#else
-
-#define ASSERT(X) do {} while (0)
-#define ASSERTCMP(X, OP, Y) do {} while (0)
-#define ASSERTIF(C, X) do {} while (0)
-#define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
-
-#endif
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH 6/7] AFS: Use new core assertion macros
2011-12-16 14:13 [PATCH 1/7] Add conditional oopsing with annotation David Howells
` (3 preceding siblings ...)
2011-12-16 14:14 ` [PATCH 5/7] CacheFiles: " David Howells
@ 2011-12-16 14:14 ` David Howells
2011-12-16 14:14 ` David Howells
2011-12-16 14:14 ` [PATCH 7/7] RxRPC: " David Howells
` (3 subsequent siblings)
8 siblings, 1 reply; 18+ messages in thread
From: David Howells @ 2011-12-16 14:14 UTC (permalink / raw)
To: linux-arch, mingo; +Cc: linux-kernel, David Howells
Make AFS use the new core assertion macros in place of its own.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/afs/internal.h | 90 +----------------------------------------------------
1 files changed, 2 insertions(+), 88 deletions(-)
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index d2b0888..36989c0 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -20,6 +20,8 @@
#include <linux/sched.h>
#include <linux/fscache.h>
#include <linux/backing-dev.h>
+#define ENABLE_ASSERTIONS
+#include <linux/assert.h>
#include "afs.h"
#include "afs_vl.h"
@@ -800,91 +802,3 @@ do { \
#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
#endif
-
-/*
- * debug assertion checking
- */
-#if 1 // defined(__KDEBUGALL)
-
-#define ASSERT(X) \
-do { \
- if (unlikely(!(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
- if (unlikely(!((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- printk(KERN_ERR "%lu " #OP " %lu is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTRANGE(L, OP1, N, OP2, H) \
-do { \
- if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
- (unsigned long)(L), (unsigned long)(N), \
- (unsigned long)(H)); \
- printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
- (unsigned long)(L), (unsigned long)(N), \
- (unsigned long)(H)); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTIF(C, X) \
-do { \
- if (unlikely((C) && !(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
- if (unlikely((C) && !((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- printk(KERN_ERR "%lu " #OP " %lu is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while(0)
-
-#else
-
-#define ASSERT(X) \
-do { \
-} while(0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
-} while(0)
-
-#define ASSERTRANGE(L, OP1, N, OP2, H) \
-do { \
-} while(0)
-
-#define ASSERTIF(C, X) \
-do { \
-} while(0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
-} while(0)
-
-#endif /* __KDEBUGALL */
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH 6/7] AFS: Use new core assertion macros
2011-12-16 14:14 ` [PATCH 6/7] AFS: " David Howells
@ 2011-12-16 14:14 ` David Howells
0 siblings, 0 replies; 18+ messages in thread
From: David Howells @ 2011-12-16 14:14 UTC (permalink / raw)
To: linux-arch, mingo; +Cc: linux-kernel, David Howells
Make AFS use the new core assertion macros in place of its own.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/afs/internal.h | 90 +----------------------------------------------------
1 files changed, 2 insertions(+), 88 deletions(-)
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index d2b0888..36989c0 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -20,6 +20,8 @@
#include <linux/sched.h>
#include <linux/fscache.h>
#include <linux/backing-dev.h>
+#define ENABLE_ASSERTIONS
+#include <linux/assert.h>
#include "afs.h"
#include "afs_vl.h"
@@ -800,91 +802,3 @@ do { \
#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
#endif
-
-/*
- * debug assertion checking
- */
-#if 1 // defined(__KDEBUGALL)
-
-#define ASSERT(X) \
-do { \
- if (unlikely(!(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
- if (unlikely(!((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- printk(KERN_ERR "%lu " #OP " %lu is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTRANGE(L, OP1, N, OP2, H) \
-do { \
- if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
- (unsigned long)(L), (unsigned long)(N), \
- (unsigned long)(H)); \
- printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
- (unsigned long)(L), (unsigned long)(N), \
- (unsigned long)(H)); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTIF(C, X) \
-do { \
- if (unlikely((C) && !(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
- if (unlikely((C) && !((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "AFS: Assertion failed\n"); \
- printk(KERN_ERR "%lu " #OP " %lu is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while(0)
-
-#else
-
-#define ASSERT(X) \
-do { \
-} while(0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
-} while(0)
-
-#define ASSERTRANGE(L, OP1, N, OP2, H) \
-do { \
-} while(0)
-
-#define ASSERTIF(C, X) \
-do { \
-} while(0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
-} while(0)
-
-#endif /* __KDEBUGALL */
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 7/7] RxRPC: Use new core assertion macros
2011-12-16 14:13 [PATCH 1/7] Add conditional oopsing with annotation David Howells
` (4 preceding siblings ...)
2011-12-16 14:14 ` [PATCH 6/7] AFS: " David Howells
@ 2011-12-16 14:14 ` David Howells
2011-12-16 14:14 ` David Howells
2011-12-17 19:15 ` [PATCH 1/7] Add conditional oopsing with annotation Mike Frysinger
` (2 subsequent siblings)
8 siblings, 1 reply; 18+ messages in thread
From: David Howells @ 2011-12-16 14:14 UTC (permalink / raw)
To: linux-arch, mingo; +Cc: linux-kernel, David Howells
Make RxRPC use the new core assertion macros in place of its own.
Signed-off-by: David Howells <dhowells@redhat.com>
---
net/rxrpc/ar-internal.h | 71 +----------------------------------------------
1 files changed, 2 insertions(+), 69 deletions(-)
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 8e22bd3..b86fe78 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -10,6 +10,8 @@
*/
#include <rxrpc/packet.h>
+#define ENABLE_ASSERTIONS
+#include <linux/assert.h>
#if 0
#define CHECK_SLAB_OKAY(X) \
@@ -657,75 +659,6 @@ do { \
#endif
/*
- * debug assertion checking
- */
-#if 1 // defined(__KDEBUGALL)
-
-#define ASSERT(X) \
-do { \
- if (unlikely(!(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "RxRPC: Assertion failed\n"); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
- if (unlikely(!((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "RxRPC: Assertion failed\n"); \
- printk(KERN_ERR "%lu " #OP " %lu is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTIF(C, X) \
-do { \
- if (unlikely((C) && !(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "RxRPC: Assertion failed\n"); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
- if (unlikely((C) && !((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "RxRPC: Assertion failed\n"); \
- printk(KERN_ERR "%lu " #OP " %lu is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while(0)
-
-#else
-
-#define ASSERT(X) \
-do { \
-} while(0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
-} while(0)
-
-#define ASSERTIF(C, X) \
-do { \
-} while(0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
-} while(0)
-
-#endif /* __KDEBUGALL */
-
-/*
* socket buffer accounting / leak finding
*/
static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH 7/7] RxRPC: Use new core assertion macros
2011-12-16 14:14 ` [PATCH 7/7] RxRPC: " David Howells
@ 2011-12-16 14:14 ` David Howells
0 siblings, 0 replies; 18+ messages in thread
From: David Howells @ 2011-12-16 14:14 UTC (permalink / raw)
To: linux-arch, mingo; +Cc: linux-kernel, David Howells
Make RxRPC use the new core assertion macros in place of its own.
Signed-off-by: David Howells <dhowells@redhat.com>
---
net/rxrpc/ar-internal.h | 71 +----------------------------------------------
1 files changed, 2 insertions(+), 69 deletions(-)
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 8e22bd3..b86fe78 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -10,6 +10,8 @@
*/
#include <rxrpc/packet.h>
+#define ENABLE_ASSERTIONS
+#include <linux/assert.h>
#if 0
#define CHECK_SLAB_OKAY(X) \
@@ -657,75 +659,6 @@ do { \
#endif
/*
- * debug assertion checking
- */
-#if 1 // defined(__KDEBUGALL)
-
-#define ASSERT(X) \
-do { \
- if (unlikely(!(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "RxRPC: Assertion failed\n"); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
- if (unlikely(!((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "RxRPC: Assertion failed\n"); \
- printk(KERN_ERR "%lu " #OP " %lu is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTIF(C, X) \
-do { \
- if (unlikely((C) && !(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "RxRPC: Assertion failed\n"); \
- BUG(); \
- } \
-} while(0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
- if (unlikely((C) && !((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "RxRPC: Assertion failed\n"); \
- printk(KERN_ERR "%lu " #OP " %lu is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while(0)
-
-#else
-
-#define ASSERT(X) \
-do { \
-} while(0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
-} while(0)
-
-#define ASSERTIF(C, X) \
-do { \
-} while(0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
-} while(0)
-
-#endif /* __KDEBUGALL */
-
-/*
* socket buffer accounting / leak finding
*/
static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH 1/7] Add conditional oopsing with annotation
2011-12-16 14:13 [PATCH 1/7] Add conditional oopsing with annotation David Howells
` (5 preceding siblings ...)
2011-12-16 14:14 ` [PATCH 7/7] RxRPC: " David Howells
@ 2011-12-17 19:15 ` Mike Frysinger
2011-12-17 19:15 ` Mike Frysinger
2011-12-18 8:02 ` Ingo Molnar
2011-12-20 15:34 ` David Howells
8 siblings, 1 reply; 18+ messages in thread
From: Mike Frysinger @ 2011-12-17 19:15 UTC (permalink / raw)
To: David Howells; +Cc: linux-arch, mingo, linux-kernel
[-- Attachment #1: Type: Text/Plain, Size: 1477 bytes --]
On Friday 16 December 2011 09:13:57 David Howells wrote:
> --- a/arch/x86/include/asm/bug.h
> +++ b/arch/x86/include/asm/bug.h
>
> +extern const void __arch_annotated_bug;
> +#define arch_annotated_bug(desc) \
> + do { \
> + asm volatile(".globl __arch_annotated_bug\n" \
> + "__arch_annotated_bug:\n" \
> + " ud2\n" \
> + : : "d" (desc)); \
> + unreachable(); \
> + } while (0)
> +
> +#define is_arch_annotated_bug(regs) \
> + ({ ((const void *)regs->ip == &__arch_annotated_bug) ? \
> + (struct annotated_bug *)regs->dx : NULL; })
seems like this is making arches duplicate a bit of logic they shouldn't have
to ... you could have asm-generic/bug.h do:
#ifdef arch_annotated_bug_fail
extern const void __arch_annotated_bug;
# define ARCH_ANNOTATED_SYM_STR CONFIG_SYMBOL_PREFIX"__arch_annotated_bug"
# define arch_annotated_bug(desc) \
do { \
asm volatile(".globl " ARCH_ANNOTATED_SYM ";\n" \
ARCH_ANNOTATED_SYM_STR":\n"); \
arch_annotated_bug_fail(desc) ; \
unreachable(); \
} while (0)
# define is_arch_annotated_bug(regs) \
({ (instruction_pointer(regs) == &__arch_annotated_bug) ? \
(struct annotated_bug *)arch_annotated_bug_struct(regs) : \
NULL; })
#endif
so now arches have to define two small bits. in the x86 case:
#define arch_annotated_bug_fail(desc) asm volatile("ud2;" : : "d" (desc))
#define arch_annotated_bug_struct(regs) (regs)->dx
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH 1/7] Add conditional oopsing with annotation
2011-12-17 19:15 ` [PATCH 1/7] Add conditional oopsing with annotation Mike Frysinger
@ 2011-12-17 19:15 ` Mike Frysinger
0 siblings, 0 replies; 18+ messages in thread
From: Mike Frysinger @ 2011-12-17 19:15 UTC (permalink / raw)
To: David Howells; +Cc: linux-arch, mingo, linux-kernel
[-- Attachment #1: Type: Text/Plain, Size: 1477 bytes --]
On Friday 16 December 2011 09:13:57 David Howells wrote:
> --- a/arch/x86/include/asm/bug.h
> +++ b/arch/x86/include/asm/bug.h
>
> +extern const void __arch_annotated_bug;
> +#define arch_annotated_bug(desc) \
> + do { \
> + asm volatile(".globl __arch_annotated_bug\n" \
> + "__arch_annotated_bug:\n" \
> + " ud2\n" \
> + : : "d" (desc)); \
> + unreachable(); \
> + } while (0)
> +
> +#define is_arch_annotated_bug(regs) \
> + ({ ((const void *)regs->ip == &__arch_annotated_bug) ? \
> + (struct annotated_bug *)regs->dx : NULL; })
seems like this is making arches duplicate a bit of logic they shouldn't have
to ... you could have asm-generic/bug.h do:
#ifdef arch_annotated_bug_fail
extern const void __arch_annotated_bug;
# define ARCH_ANNOTATED_SYM_STR CONFIG_SYMBOL_PREFIX"__arch_annotated_bug"
# define arch_annotated_bug(desc) \
do { \
asm volatile(".globl " ARCH_ANNOTATED_SYM ";\n" \
ARCH_ANNOTATED_SYM_STR":\n"); \
arch_annotated_bug_fail(desc) ; \
unreachable(); \
} while (0)
# define is_arch_annotated_bug(regs) \
({ (instruction_pointer(regs) == &__arch_annotated_bug) ? \
(struct annotated_bug *)arch_annotated_bug_struct(regs) : \
NULL; })
#endif
so now arches have to define two small bits. in the x86 case:
#define arch_annotated_bug_fail(desc) asm volatile("ud2;" : : "d" (desc))
#define arch_annotated_bug_struct(regs) (regs)->dx
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 1/7] Add conditional oopsing with annotation
2011-12-16 14:13 [PATCH 1/7] Add conditional oopsing with annotation David Howells
` (6 preceding siblings ...)
2011-12-17 19:15 ` [PATCH 1/7] Add conditional oopsing with annotation Mike Frysinger
@ 2011-12-18 8:02 ` Ingo Molnar
2011-12-20 15:34 ` David Howells
8 siblings, 0 replies; 18+ messages in thread
From: Ingo Molnar @ 2011-12-18 8:02 UTC (permalink / raw)
To: David Howells; +Cc: linux-arch, linux-kernel, Linus Torvalds, Andrew Morton
* David Howells <dhowells@redhat.com> wrote:
> This facility can be made use of by one of:
>
> ANNOTATED_BUG(const char *fmt, ...);
> ANNOTATED_BUG_ON(bool condition, const char *fmt, ...);
Hm, what about WARN_ON()s?
WARN_ON() and WARN_ON_ONCE() covers like 99% of the *actual*
bugreports we get: we are actively getting rid of BUG()s that do
trigger and are asking all new patches to come with WARN_ON()s.
BUG()s are generally a poor way of reporting bugs.
Another, much bigger issue is the actual syntax:
> - BUG_ON(atomic_read(&cookie->usage) <= 0);
> + ASSERTCMP(atomic_read(&cookie->usage), >, 0);
NAK on that concept on two grounds!
1) BUG_ON() is a well-known pattern. Changing it to the inverted
assert() braindamage is going to cause confusion years down
the road. Years ago we've settled on using BUG*() and WARN*()
assertions to include conditions that check the 'bad'
condition'. assert() covers the negated 'good' condition -
which works but the two are truly awful when mixed.
2) The '>,0' syntax is ugly.
Why don't we simply extend the *existing* primitives with a
'verbose' variant that saves the text string of the macro using
the '#param' syntax, intead of modifying the usage sites with a
pointless splitting along logical ops?
Doing that would also remove the rather pointess ANNOTATED_()
prefix, which is like totally uninteresting in the actual usage
sites. WARN()s want to be as short, obvious and low-profile as
possible.
So the whole schizophrenic split between BUG_ON()/WARN_ON() and
the assert() world is nonsensical and confusing - we should
settle on *one* logical variant to make code reading easier. And
i thought in the kernel we already settled on one of these
variants and are using it almost exclusively ...
So this series does not look good enough to me yet.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH 1/7] Add conditional oopsing with annotation
2011-12-16 14:13 [PATCH 1/7] Add conditional oopsing with annotation David Howells
` (7 preceding siblings ...)
2011-12-18 8:02 ` Ingo Molnar
@ 2011-12-20 15:34 ` David Howells
8 siblings, 0 replies; 18+ messages in thread
From: David Howells @ 2011-12-20 15:34 UTC (permalink / raw)
To: Ingo Molnar
Cc: dhowells, linux-arch, linux-kernel, Linus Torvalds, Andrew Morton
Ingo Molnar <mingo@elte.hu> wrote:
> Hm, what about WARN_ON()s?
Good point.
> BUG()s are generally a poor way of reporting bugs.
Sometimes you can't continue, and there's no way you can know how to clean up
- after all, if you see values you don't expect, how can you handle them?
> 1) BUG_ON() is a well-known pattern. Changing it to the inverted
> assert() braindamage is going to cause confusion years down
> the road.
In my opinion, BUG_ON() is usually inverted from what it should be.
Frequently, it seems to be bugging on an inverted condition.
assert() is generally well known from userspace. You lay out your
expectations with asserts. An assert says "I expect this value to comply with
this condition" - such as a value being in a specific range. Generally I
would turn them on whilst debugging stuff, and suppressing them at other
times, but I'd leave BUG[_ON]() and WARN[_ON]() enabled.
> 2) The '>,0' syntax is ugly.
And works rather well. I've been using it for a while now in the kernel quite
successfully.
> Why don't we simply extend the *existing* primitives with a
> 'verbose' variant that saves the text string of the macro using
> the '#param' syntax, intead of modifying the usage sites with a
> pointless splitting along logical ops?
You've completely missed the point. Go back and re-read the description.
> Doing that would also remove the rather pointess ANNOTATED_()
> prefix, which is like totally uninteresting in the actual usage
> sites. WARN()s want to be as short, obvious and low-profile as
> possible.
You need to distinguish annotated errors/warnings from non-annotated ones...
unless you're planning on completely converting all the BUG/WARN calls in one
patch?
You could call it BUG_ON_VERBOSE() - but verbose BUG_ON already exists as a
concept within the kernel, so I chose a different name.
Note that my preferred mechanism would be to permit the cut-here line to be
emitted early, and have the one that's emitted by the BUG handler then
suppressed, but Linus doesn't like that. I think it would be preferable to
trying to pass a va_list argument through the exception handler.
David
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 4/7] FS-Cache: Use new core assertion macros
2011-10-12 16:47 [PATCH 1/7] Add assertion support with annotated oopsing David Howells
@ 2011-10-12 16:47 ` David Howells
2011-10-12 16:47 ` David Howells
0 siblings, 1 reply; 18+ messages in thread
From: David Howells @ 2011-10-12 16:47 UTC (permalink / raw)
To: linux-arch; +Cc: dhowells, linux-kernel
Make FS-Cache use the new core assertion macros in place of its own.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/fscache/debug.h | 82 +++++++++++++++++++++++++++++++
fs/fscache/internal.h | 128 +-----------------------------------------------
fs/fscache/operation.c | 3 -
3 files changed, 86 insertions(+), 127 deletions(-)
create mode 100644 fs/fscache/debug.h
diff --git a/fs/fscache/debug.h b/fs/fscache/debug.h
new file mode 100644
index 0000000..fcdbbab
--- /dev/null
+++ b/fs/fscache/debug.h
@@ -0,0 +1,82 @@
+/* Debug tracing
+ *
+ * Copyright (C) 2004-2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/printk.h>
+#define ENABLE_ASSERTIONS
+#include <linux/assert.h>
+
+/*
+ * debug tracing
+ */
+#define dbgprintk(FMT, ...) \
+ printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
+
+#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
+#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
+#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
+
+#define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
+
+#ifdef __KDEBUG
+#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
+#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
+#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
+
+#elif defined(CONFIG_FSCACHE_DEBUG)
+#define _enter(FMT, ...) \
+do { \
+ if (__do_kdebug(ENTER)) \
+ kenter(FMT, ##__VA_ARGS__); \
+} while (0)
+
+#define _leave(FMT, ...) \
+do { \
+ if (__do_kdebug(LEAVE)) \
+ kleave(FMT, ##__VA_ARGS__); \
+} while (0)
+
+#define _debug(FMT, ...) \
+do { \
+ if (__do_kdebug(DEBUG)) \
+ kdebug(FMT, ##__VA_ARGS__); \
+} while (0)
+
+#else
+#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
+#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
+#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
+#endif
+
+/*
+ * determine whether a particular optional debugging point should be logged
+ * - we need to go through three steps to persuade cpp to correctly join the
+ * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
+ */
+#define ____do_kdebug(LEVEL, POINT) \
+ unlikely((fscache_debug & \
+ (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
+#define ___do_kdebug(LEVEL, POINT) \
+ ____do_kdebug(LEVEL, POINT)
+#define __do_kdebug(POINT) \
+ ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
+
+#define FSCACHE_DEBUG_CACHE 0
+#define FSCACHE_DEBUG_COOKIE 1
+#define FSCACHE_DEBUG_PAGE 2
+#define FSCACHE_DEBUG_OPERATION 3
+
+#define FSCACHE_POINT_ENTER 1
+#define FSCACHE_POINT_LEAVE 2
+#define FSCACHE_POINT_DEBUG 4
+
+#ifndef FSCACHE_DEBUG_LEVEL
+#define FSCACHE_DEBUG_LEVEL CACHE
+#endif
diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
index dcb3e1d..4c1a1ba 100644
--- a/fs/fscache/internal.h
+++ b/fs/fscache/internal.h
@@ -24,6 +24,7 @@
#include <linux/fscache-cache.h>
#include <linux/sched.h>
+#include "debug.h"
#define FSCACHE_MIN_THREADS 4
#define FSCACHE_MAX_THREADS 32
@@ -288,7 +289,7 @@ extern const struct file_operations fscache_stats_fops;
static inline void fscache_raise_event(struct fscache_object *object,
unsigned event)
{
- BUG_ON(event >= NR_FSCACHE_OBJECT_EVENTS);
+ ASSERTCMP(event, <, NR_FSCACHE_OBJECT_EVENTS);
if (!test_and_set_bit(event, &object->events) &&
test_bit(event, &object->event_mask))
fscache_enqueue_object(object);
@@ -299,7 +300,7 @@ static inline void fscache_raise_event(struct fscache_object *object,
*/
static inline void fscache_cookie_put(struct fscache_cookie *cookie)
{
- BUG_ON(atomic_read(&cookie->usage) <= 0);
+ ASSERTCMP(atomic_read(&cookie->usage), >, 0);
if (atomic_dec_and_test(&cookie->usage))
__fscache_cookie_put(cookie);
}
@@ -324,126 +325,3 @@ void fscache_put_context(struct fscache_cookie *cookie, void *context)
if (cookie->def->put_context)
cookie->def->put_context(cookie->netfs_data, context);
}
-
-/*****************************************************************************/
-/*
- * debug tracing
- */
-#define dbgprintk(FMT, ...) \
- printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
-
-#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
-#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
-#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
-
-#define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
-
-#ifdef __KDEBUG
-#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
-#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
-#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
-
-#elif defined(CONFIG_FSCACHE_DEBUG)
-#define _enter(FMT, ...) \
-do { \
- if (__do_kdebug(ENTER)) \
- kenter(FMT, ##__VA_ARGS__); \
-} while (0)
-
-#define _leave(FMT, ...) \
-do { \
- if (__do_kdebug(LEAVE)) \
- kleave(FMT, ##__VA_ARGS__); \
-} while (0)
-
-#define _debug(FMT, ...) \
-do { \
- if (__do_kdebug(DEBUG)) \
- kdebug(FMT, ##__VA_ARGS__); \
-} while (0)
-
-#else
-#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
-#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
-#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
-#endif
-
-/*
- * determine whether a particular optional debugging point should be logged
- * - we need to go through three steps to persuade cpp to correctly join the
- * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
- */
-#define ____do_kdebug(LEVEL, POINT) \
- unlikely((fscache_debug & \
- (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
-#define ___do_kdebug(LEVEL, POINT) \
- ____do_kdebug(LEVEL, POINT)
-#define __do_kdebug(POINT) \
- ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
-
-#define FSCACHE_DEBUG_CACHE 0
-#define FSCACHE_DEBUG_COOKIE 1
-#define FSCACHE_DEBUG_PAGE 2
-#define FSCACHE_DEBUG_OPERATION 3
-
-#define FSCACHE_POINT_ENTER 1
-#define FSCACHE_POINT_LEAVE 2
-#define FSCACHE_POINT_DEBUG 4
-
-#ifndef FSCACHE_DEBUG_LEVEL
-#define FSCACHE_DEBUG_LEVEL CACHE
-#endif
-
-/*
- * assertions
- */
-#if 1 /* defined(__KDEBUGALL) */
-
-#define ASSERT(X) \
-do { \
- if (unlikely(!(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
- if (unlikely(!((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- printk(KERN_ERR "%lx " #OP " %lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTIF(C, X) \
-do { \
- if (unlikely((C) && !(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
- if (unlikely((C) && !((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- printk(KERN_ERR "%lx " #OP " %lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while (0)
-
-#else
-
-#define ASSERT(X) do {} while (0)
-#define ASSERTCMP(X, OP, Y) do {} while (0)
-#define ASSERTIF(C, X) do {} while (0)
-#define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
-
-#endif /* assert or not */
diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
index cafba83..be15b09 100644
--- a/fs/fscache/operation.c
+++ b/fs/fscache/operation.c
@@ -429,8 +429,7 @@ void fscache_put_operation(struct fscache_operation *op)
printk("FS-Cache: Asserting on %s operation\n",
fscache_op_names[op->name]);
- ASSERTIFCMP(op->state != FSCACHE_OP_ST_COMPLETE,
- op->state, ==, FSCACHE_OP_ST_CANCELLED);
+ ASSERTRANGE(FSCACHE_OP_ST_COMPLETE, <=, op->state, <=, FSCACHE_OP_ST_CANCELLED);
op->state = FSCACHE_OP_ST_DEAD;
fscache_stat(&fscache_n_op_release);
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH 4/7] FS-Cache: Use new core assertion macros
2011-10-12 16:47 ` [PATCH 4/7] FS-Cache: Use new core assertion macros David Howells
@ 2011-10-12 16:47 ` David Howells
0 siblings, 0 replies; 18+ messages in thread
From: David Howells @ 2011-10-12 16:47 UTC (permalink / raw)
To: linux-arch; +Cc: dhowells, linux-kernel
Make FS-Cache use the new core assertion macros in place of its own.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/fscache/debug.h | 82 +++++++++++++++++++++++++++++++
fs/fscache/internal.h | 128 +-----------------------------------------------
fs/fscache/operation.c | 3 -
3 files changed, 86 insertions(+), 127 deletions(-)
create mode 100644 fs/fscache/debug.h
diff --git a/fs/fscache/debug.h b/fs/fscache/debug.h
new file mode 100644
index 0000000..fcdbbab
--- /dev/null
+++ b/fs/fscache/debug.h
@@ -0,0 +1,82 @@
+/* Debug tracing
+ *
+ * Copyright (C) 2004-2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/printk.h>
+#define ENABLE_ASSERTIONS
+#include <linux/assert.h>
+
+/*
+ * debug tracing
+ */
+#define dbgprintk(FMT, ...) \
+ printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
+
+#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
+#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
+#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
+
+#define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
+
+#ifdef __KDEBUG
+#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
+#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
+#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
+
+#elif defined(CONFIG_FSCACHE_DEBUG)
+#define _enter(FMT, ...) \
+do { \
+ if (__do_kdebug(ENTER)) \
+ kenter(FMT, ##__VA_ARGS__); \
+} while (0)
+
+#define _leave(FMT, ...) \
+do { \
+ if (__do_kdebug(LEAVE)) \
+ kleave(FMT, ##__VA_ARGS__); \
+} while (0)
+
+#define _debug(FMT, ...) \
+do { \
+ if (__do_kdebug(DEBUG)) \
+ kdebug(FMT, ##__VA_ARGS__); \
+} while (0)
+
+#else
+#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
+#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
+#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
+#endif
+
+/*
+ * determine whether a particular optional debugging point should be logged
+ * - we need to go through three steps to persuade cpp to correctly join the
+ * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
+ */
+#define ____do_kdebug(LEVEL, POINT) \
+ unlikely((fscache_debug & \
+ (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
+#define ___do_kdebug(LEVEL, POINT) \
+ ____do_kdebug(LEVEL, POINT)
+#define __do_kdebug(POINT) \
+ ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
+
+#define FSCACHE_DEBUG_CACHE 0
+#define FSCACHE_DEBUG_COOKIE 1
+#define FSCACHE_DEBUG_PAGE 2
+#define FSCACHE_DEBUG_OPERATION 3
+
+#define FSCACHE_POINT_ENTER 1
+#define FSCACHE_POINT_LEAVE 2
+#define FSCACHE_POINT_DEBUG 4
+
+#ifndef FSCACHE_DEBUG_LEVEL
+#define FSCACHE_DEBUG_LEVEL CACHE
+#endif
diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
index dcb3e1d..4c1a1ba 100644
--- a/fs/fscache/internal.h
+++ b/fs/fscache/internal.h
@@ -24,6 +24,7 @@
#include <linux/fscache-cache.h>
#include <linux/sched.h>
+#include "debug.h"
#define FSCACHE_MIN_THREADS 4
#define FSCACHE_MAX_THREADS 32
@@ -288,7 +289,7 @@ extern const struct file_operations fscache_stats_fops;
static inline void fscache_raise_event(struct fscache_object *object,
unsigned event)
{
- BUG_ON(event >= NR_FSCACHE_OBJECT_EVENTS);
+ ASSERTCMP(event, <, NR_FSCACHE_OBJECT_EVENTS);
if (!test_and_set_bit(event, &object->events) &&
test_bit(event, &object->event_mask))
fscache_enqueue_object(object);
@@ -299,7 +300,7 @@ static inline void fscache_raise_event(struct fscache_object *object,
*/
static inline void fscache_cookie_put(struct fscache_cookie *cookie)
{
- BUG_ON(atomic_read(&cookie->usage) <= 0);
+ ASSERTCMP(atomic_read(&cookie->usage), >, 0);
if (atomic_dec_and_test(&cookie->usage))
__fscache_cookie_put(cookie);
}
@@ -324,126 +325,3 @@ void fscache_put_context(struct fscache_cookie *cookie, void *context)
if (cookie->def->put_context)
cookie->def->put_context(cookie->netfs_data, context);
}
-
-/*****************************************************************************/
-/*
- * debug tracing
- */
-#define dbgprintk(FMT, ...) \
- printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
-
-#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
-#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
-#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
-
-#define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
-
-#ifdef __KDEBUG
-#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
-#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
-#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
-
-#elif defined(CONFIG_FSCACHE_DEBUG)
-#define _enter(FMT, ...) \
-do { \
- if (__do_kdebug(ENTER)) \
- kenter(FMT, ##__VA_ARGS__); \
-} while (0)
-
-#define _leave(FMT, ...) \
-do { \
- if (__do_kdebug(LEAVE)) \
- kleave(FMT, ##__VA_ARGS__); \
-} while (0)
-
-#define _debug(FMT, ...) \
-do { \
- if (__do_kdebug(DEBUG)) \
- kdebug(FMT, ##__VA_ARGS__); \
-} while (0)
-
-#else
-#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
-#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
-#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
-#endif
-
-/*
- * determine whether a particular optional debugging point should be logged
- * - we need to go through three steps to persuade cpp to correctly join the
- * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
- */
-#define ____do_kdebug(LEVEL, POINT) \
- unlikely((fscache_debug & \
- (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
-#define ___do_kdebug(LEVEL, POINT) \
- ____do_kdebug(LEVEL, POINT)
-#define __do_kdebug(POINT) \
- ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
-
-#define FSCACHE_DEBUG_CACHE 0
-#define FSCACHE_DEBUG_COOKIE 1
-#define FSCACHE_DEBUG_PAGE 2
-#define FSCACHE_DEBUG_OPERATION 3
-
-#define FSCACHE_POINT_ENTER 1
-#define FSCACHE_POINT_LEAVE 2
-#define FSCACHE_POINT_DEBUG 4
-
-#ifndef FSCACHE_DEBUG_LEVEL
-#define FSCACHE_DEBUG_LEVEL CACHE
-#endif
-
-/*
- * assertions
- */
-#if 1 /* defined(__KDEBUGALL) */
-
-#define ASSERT(X) \
-do { \
- if (unlikely(!(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTCMP(X, OP, Y) \
-do { \
- if (unlikely(!((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- printk(KERN_ERR "%lx " #OP " %lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTIF(C, X) \
-do { \
- if (unlikely((C) && !(X))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- BUG(); \
- } \
-} while (0)
-
-#define ASSERTIFCMP(C, X, OP, Y) \
-do { \
- if (unlikely((C) && !((X) OP (Y)))) { \
- printk(KERN_ERR "\n"); \
- printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
- printk(KERN_ERR "%lx " #OP " %lx is false\n", \
- (unsigned long)(X), (unsigned long)(Y)); \
- BUG(); \
- } \
-} while (0)
-
-#else
-
-#define ASSERT(X) do {} while (0)
-#define ASSERTCMP(X, OP, Y) do {} while (0)
-#define ASSERTIF(C, X) do {} while (0)
-#define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
-
-#endif /* assert or not */
diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
index cafba83..be15b09 100644
--- a/fs/fscache/operation.c
+++ b/fs/fscache/operation.c
@@ -429,8 +429,7 @@ void fscache_put_operation(struct fscache_operation *op)
printk("FS-Cache: Asserting on %s operation\n",
fscache_op_names[op->name]);
- ASSERTIFCMP(op->state != FSCACHE_OP_ST_COMPLETE,
- op->state, ==, FSCACHE_OP_ST_CANCELLED);
+ ASSERTRANGE(FSCACHE_OP_ST_COMPLETE, <=, op->state, <=, FSCACHE_OP_ST_CANCELLED);
op->state = FSCACHE_OP_ST_DEAD;
fscache_stat(&fscache_n_op_release);
^ permalink raw reply related [flat|nested] 18+ messages in thread