Skip to content

Commit 742ae1e

Browse files
dgchinnerBen Myers
authored andcommitted
xfs: introduce CONFIG_XFS_WARN
Running a CONFIG_XFS_DEBUG kernel in production environments is not the best idea as it introduces significant overhead, can change the behaviour of algorithms (such as allocation) to improve test coverage, and (most importantly) panic the machine on non-fatal errors. There are many cases where all we want to do is run a kernel with more bounds checking enabled, such as is provided by the ASSERT() statements throughout the code, but without all the potential overhead and drawbacks. This patch converts all the ASSERT statements to evaluate as WARN_ON(1) statements and hence if they fail dump a warning and a stack trace to the log. This has minimal overhead and does not change any algorithms, and will allow us to find strange "out of bounds" problems more easily on production machines. There are a few places where assert statements contain debug only code. These are converted to be debug-or-warn only code so that we still get all the assert checks in the code. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Brian Foster <bfoster@redhat.com> Signed-off-by: Ben Myers <bpm@sgi.com>
1 parent cab09a8 commit 742ae1e

13 files changed

Lines changed: 63 additions & 24 deletions

fs/xfs/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ config XFS_RT
6969

7070
If unsure, say N.
7171

72+
config XFS_WARN
73+
bool "XFS Verbose Warnings"
74+
depends on XFS_FS && !XFS_DEBUG
75+
help
76+
Say Y here to get an XFS build with many additional warnings.
77+
It converts ASSERT checks to WARN, so will log any out-of-bounds
78+
conditions that occur that would otherwise be missed. It is much
79+
lighter weight than XFS_DEBUG and does not modify algorithms and will
80+
not cause the kernel to panic on non-fatal errors.
81+
82+
However, similar to XFS_DEBUG, it is only advisable to use this if you
83+
are debugging a particular problem.
84+
7285
config XFS_DEBUG
7386
bool "XFS Debugging support"
7487
depends on XFS_FS

fs/xfs/mrlock.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
typedef struct {
2424
struct rw_semaphore mr_lock;
25-
#ifdef DEBUG
25+
#if defined(DEBUG) || defined(XFS_WARN)
2626
int mr_writer;
2727
#endif
2828
} mrlock_t;
2929

30-
#ifdef DEBUG
30+
#if defined(DEBUG) || defined(XFS_WARN)
3131
#define mrinit(mrp, name) \
3232
do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)
3333
#else
@@ -46,7 +46,7 @@ static inline void mraccess_nested(mrlock_t *mrp, int subclass)
4646
static inline void mrupdate_nested(mrlock_t *mrp, int subclass)
4747
{
4848
down_write_nested(&mrp->mr_lock, subclass);
49-
#ifdef DEBUG
49+
#if defined(DEBUG) || defined(XFS_WARN)
5050
mrp->mr_writer = 1;
5151
#endif
5252
}
@@ -60,15 +60,15 @@ static inline int mrtryupdate(mrlock_t *mrp)
6060
{
6161
if (!down_write_trylock(&mrp->mr_lock))
6262
return 0;
63-
#ifdef DEBUG
63+
#if defined(DEBUG) || defined(XFS_WARN)
6464
mrp->mr_writer = 1;
6565
#endif
6666
return 1;
6767
}
6868

6969
static inline void mrunlock_excl(mrlock_t *mrp)
7070
{
71-
#ifdef DEBUG
71+
#if defined(DEBUG) || defined(XFS_WARN)
7272
mrp->mr_writer = 0;
7373
#endif
7474
up_write(&mrp->mr_lock);
@@ -81,7 +81,7 @@ static inline void mrunlock_shared(mrlock_t *mrp)
8181

8282
static inline void mrdemote(mrlock_t *mrp)
8383
{
84-
#ifdef DEBUG
84+
#if defined(DEBUG) || defined(XFS_WARN)
8585
mrp->mr_writer = 0;
8686
#endif
8787
downgrade_write(&mrp->mr_lock);

fs/xfs/xfs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
#define XFS_BUF_LOCK_TRACKING 1
2525
#endif
2626

27+
#ifdef CONFIG_XFS_WARN
28+
#define XFS_WARN 1
29+
#endif
30+
31+
2732
#include "xfs_linux.h"
2833

2934
#endif /* __XFS_H__ */

fs/xfs/xfs_alloc_btree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ const struct xfs_buf_ops xfs_allocbt_buf_ops = {
386386
};
387387

388388

389-
#ifdef DEBUG
389+
#if defined(DEBUG) || defined(XFS_WARN)
390390
STATIC int
391391
xfs_allocbt_keys_inorder(
392392
struct xfs_btree_cur *cur,
@@ -442,7 +442,7 @@ static const struct xfs_btree_ops xfs_allocbt_ops = {
442442
.init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur,
443443
.key_diff = xfs_allocbt_key_diff,
444444
.buf_ops = &xfs_allocbt_buf_ops,
445-
#ifdef DEBUG
445+
#if defined(DEBUG) || defined(XFS_WARN)
446446
.keys_inorder = xfs_allocbt_keys_inorder,
447447
.recs_inorder = xfs_allocbt_recs_inorder,
448448
#endif

fs/xfs/xfs_bmap_btree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ const struct xfs_buf_ops xfs_bmbt_buf_ops = {
813813
};
814814

815815

816-
#ifdef DEBUG
816+
#if defined(DEBUG) || defined(XFS_WARN)
817817
STATIC int
818818
xfs_bmbt_keys_inorder(
819819
struct xfs_btree_cur *cur,
@@ -853,7 +853,7 @@ static const struct xfs_btree_ops xfs_bmbt_ops = {
853853
.init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur,
854854
.key_diff = xfs_bmbt_key_diff,
855855
.buf_ops = &xfs_bmbt_buf_ops,
856-
#ifdef DEBUG
856+
#if defined(DEBUG) || defined(XFS_WARN)
857857
.keys_inorder = xfs_bmbt_keys_inorder,
858858
.recs_inorder = xfs_bmbt_recs_inorder,
859859
#endif

fs/xfs/xfs_btree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ struct xfs_btree_ops {
215215

216216
const struct xfs_buf_ops *buf_ops;
217217

218-
#ifdef DEBUG
218+
#if defined(DEBUG) || defined(XFS_WARN)
219219
/* check that k1 is lower than k2 */
220220
int (*keys_inorder)(struct xfs_btree_cur *cur,
221221
union xfs_btree_key *k1,

fs/xfs/xfs_dir2_node.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ xfs_dir2_leafn_rebalance(
993993
xfs_dir2_leaf_t *leaf1; /* first leaf structure */
994994
xfs_dir2_leaf_t *leaf2; /* second leaf structure */
995995
int mid; /* midpoint leaf index */
996-
#ifdef DEBUG
996+
#if defined(DEBUG) || defined(XFS_WARN)
997997
int oldstale; /* old count of stale leaves */
998998
#endif
999999
int oldsum; /* old total leaf count */
@@ -1022,7 +1022,7 @@ xfs_dir2_leafn_rebalance(
10221022
ents2 = xfs_dir3_leaf_ents_p(leaf2);
10231023

10241024
oldsum = hdr1.count + hdr2.count;
1025-
#ifdef DEBUG
1025+
#if defined(DEBUG) || defined(XFS_WARN)
10261026
oldstale = hdr1.stale + hdr2.stale;
10271027
#endif
10281028
mid = oldsum >> 1;

fs/xfs/xfs_ialloc_btree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ const struct xfs_buf_ops xfs_inobt_buf_ops = {
272272
.verify_write = xfs_inobt_write_verify,
273273
};
274274

275-
#ifdef DEBUG
275+
#if defined(DEBUG) || defined(XFS_WARN)
276276
STATIC int
277277
xfs_inobt_keys_inorder(
278278
struct xfs_btree_cur *cur,
@@ -310,7 +310,7 @@ static const struct xfs_btree_ops xfs_inobt_ops = {
310310
.init_ptr_from_cur = xfs_inobt_init_ptr_from_cur,
311311
.key_diff = xfs_inobt_key_diff,
312312
.buf_ops = &xfs_inobt_buf_ops,
313-
#ifdef DEBUG
313+
#if defined(DEBUG) || defined(XFS_WARN)
314314
.keys_inorder = xfs_inobt_keys_inorder,
315315
.recs_inorder = xfs_inobt_recs_inorder,
316316
#endif

fs/xfs/xfs_inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ xfs_ilock_demote(
287287
trace_xfs_ilock_demote(ip, lock_flags, _RET_IP_);
288288
}
289289

290-
#ifdef DEBUG
290+
#if defined(DEBUG) || defined(XFS_WARN)
291291
int
292292
xfs_isilocked(
293293
xfs_inode_t *ip,

fs/xfs/xfs_linux.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,34 @@ static inline __uint64_t howmany_64(__uint64_t x, __uint32_t y)
293293
#define ASSERT_ALWAYS(expr) \
294294
(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
295295

296-
#ifndef DEBUG
297-
#define ASSERT(expr) ((void)0)
296+
#ifdef DEBUG
297+
#define ASSERT(expr) \
298+
(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
298299

299300
#ifndef STATIC
300-
# define STATIC static noinline
301+
# define STATIC noinline
301302
#endif
302303

303-
#else /* DEBUG */
304+
#else /* !DEBUG */
305+
306+
#ifdef XFS_WARN
304307

305308
#define ASSERT(expr) \
306-
(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
309+
(unlikely(expr) ? (void)0 : asswarn(#expr, __FILE__, __LINE__))
307310

308311
#ifndef STATIC
309-
# define STATIC noinline
312+
# define STATIC static noinline
313+
#endif
314+
315+
#else /* !DEBUG && !XFS_WARN */
316+
317+
#define ASSERT(expr) ((void)0)
318+
319+
#ifndef STATIC
320+
# define STATIC static noinline
310321
#endif
311322

323+
#endif /* XFS_WARN */
312324
#endif /* DEBUG */
313325

314326
#endif /* __XFS_LINUX__ */

0 commit comments

Comments
 (0)