Skip to contentSkip to conversation

xfs: ASSERT should always evaluate its parameter

PATCH In review Darrick J. Wong 1 participant 2 messages Sep 1, 2017 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: ASSERT should always evaluate its parameter

Ensure that ASSERT evalulates its expression argument so that we don't get a ton of compiler warnings in non-warn non-debug mode. Fix up everything that breaks as a result.

---
 fs/xfs/libxfs/xfs_bmap.c      |    2 +-
 fs/xfs/libxfs/xfs_dir2_node.c |    2 --
 fs/xfs/xfs_inode.c            |    8 ++++++++
 fs/xfs/xfs_linux.h            |    3 ++-
 fs/xfs/xfs_trans.c            |    2 ++
 5 files changed, 13 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +1 -1
index 9558f5e..883a626 100644
@@ -579,7 +579,7 @@ xfs_bmap_validate_ret(
 
 #else
 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork)		do { } while (0)
-#define	xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
+#define	xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)	((void)0)
 #endif /* DEBUG */
 
 /*
fs/xfs/libxfs/xfs_dir2_node.c +0 -2
index 682e2bf..e57a80b 100644
@@ -1005,9 +1005,7 @@ xfs_dir2_leafn_rebalance(
 	xfs_dir2_leaf_t		*leaf1;		/* first leaf structure */
 	xfs_dir2_leaf_t		*leaf2;		/* second leaf structure */
 	int			mid;		/* midpoint leaf index */
-#if defined(DEBUG) || defined(XFS_WARN)
 	int			oldstale;	/* old count of stale leaves */
-#endif
 	int			oldsum;		/* old total leaf count */
 	int			swap;		/* swapped leaf blocks */
 	struct xfs_dir2_leaf_entry *ents1;
fs/xfs/xfs_inode.c +8 -0
index 5599dda..0eaf1f1 100644
@@ -382,6 +382,14 @@ xfs_isilocked(
 	ASSERT(0);
 	return 0;
 }
+#else
+int
+xfs_isilocked(
+	xfs_inode_t		*ip,
+	uint			lock_flags)
+{
+	return 0;
+}
 #endif
 
 #ifdef DEBUG
fs/xfs/xfs_linux.h +2 -1
index c19c999..7c69f08 100644
@@ -260,7 +260,8 @@ static inline uint64_t howmany_64(uint64_t x, uint32_t y)
 
 #else	/* !DEBUG && !XFS_WARN */
 
-#define ASSERT(expr)	((void)0)
+#define ASSERT(expr)	\
+	(likely(expr) ? (void)0 : (void)0)
 
 #ifndef STATIC
 # define STATIC static noinline
fs/xfs/xfs_trans.c +2 -0
index a87f657..45e30ba 100644
@@ -421,9 +421,11 @@ xfs_trans_apply_sb_deltas(
 	/*
 	 * Check that superblock mods match the mods made to AGF counters.
 	 */
+#if defined(DEBUG) || defined(XFS_WARN)
 	ASSERT((tp->t_fdblocks_delta + tp->t_res_fdblocks_delta) ==
 	       (tp->t_ag_freeblks_delta + tp->t_ag_flist_delta +
 		tp->t_ag_btree_delta));
+#endif
 
 	/*
 	 * Only update the superblock counters if we are logging them
#1 lore raw
Quoted 46 lines · Darrick J. Wong

Ensure that ASSERT evalulates its expression argument so that we don't get a ton of compiler warnings in non-warn non-debug mode. Fix up everything that breaks as a result.

---
 fs/xfs/libxfs/xfs_bmap.c      |    2 +-
 fs/xfs/libxfs/xfs_dir2_node.c |    2 --
 fs/xfs/xfs_inode.c            |    8 ++++++++
 fs/xfs/xfs_linux.h            |    3 ++-
 fs/xfs/xfs_trans.c            |    2 ++
 5 files changed, 13 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +1 -1
index 9558f5e..883a626 100644
@@ -579,7 +579,7 @@ xfs_bmap_validate_ret(
 
 #else
 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork)		do { } while (0)
-#define	xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
+#define	xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)	((void)0)
 #endif /* DEBUG */
 
 /*
fs/xfs/libxfs/xfs_dir2_node.c +0 -2
index 682e2bf..e57a80b 100644
@@ -1005,9 +1005,7 @@ xfs_dir2_leafn_rebalance(
 	xfs_dir2_leaf_t		*leaf1;		/* first leaf structure */
 	xfs_dir2_leaf_t		*leaf2;		/* second leaf structure */
 	int			mid;		/* midpoint leaf index */
-#if defined(DEBUG) || defined(XFS_WARN)
 	int			oldstale;	/* old count of stale leaves */
-#endif
 	int			oldsum;		/* old total leaf count */
 	int			swap;		/* swapped leaf blocks */
 	struct xfs_dir2_leaf_entry *ents1;
fs/xfs/xfs_inode.c +0 -0
index 5599dda..0eaf1f1 100644
@@ -382,6 +382,14 @@ xfs_isilocked(
 	ASSERT(0);

fs/xfs/xfs_inode.c xfs_isilocked( · line 392

Quoted 10 lines
fs/xfs/xfs_inode.c +8 -0
 	return 0;
 }
+#else
+int
+xfs_isilocked(
+	xfs_inode_t		*ip,
+	uint			lock_flags)
+{
+	return 0;
+}

Bah, this doesn't work, never mind. Kill this whole patch.

/me goes back for another cup of coffee.

--D

Quoted 37 lines
fs/xfs/xfs_inode.c +0 -0
 #endif
 
 #ifdef DEBUG
fs/xfs/xfs_linux.h +2 -1
index c19c999..7c69f08 100644
@@ -260,7 +260,8 @@ static inline uint64_t howmany_64(uint64_t x, uint32_t y)
 
 #else	/* !DEBUG && !XFS_WARN */
 
-#define ASSERT(expr)	((void)0)
+#define ASSERT(expr)	\
+	(likely(expr) ? (void)0 : (void)0)
 
 #ifndef STATIC
 # define STATIC static noinline
fs/xfs/xfs_trans.c +2 -1
index a87f657..45e30ba 100644
@@ -421,9 +421,11 @@ xfs_trans_apply_sb_deltas(
 	/*
 	 * Check that superblock mods match the mods made to AGF counters.
 	 */
+#if defined(DEBUG) || defined(XFS_WARN)
 	ASSERT((tp->t_fdblocks_delta + tp->t_res_fdblocks_delta) ==
 	       (tp->t_ag_freeblks_delta + tp->t_ag_flist_delta +
 		tp->t_ag_btree_delta));
+#endif
 
 	/*
 	 * Only update the superblock counters if we are logging them
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html