[4/6] xfs: add a XFS_CORRUPT_ON macro
diff mbox series

Message ID 157281987010.4151907.6435110079992395504.stgit@magnolia
State New
Headers show
Series
  • xfs: refactor corruption checking and reporting
Related show

Commit Message

Darrick J. Wong Nov. 3, 2019, 10:24 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Add a new macro, XFS_CORRUPT_ON, which we will use to integrate some
corruption reporting when the corruption test expression is true.  This
will be used in the next patch to remove the ugly XFS_WANT_CORRUPT*
macros.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_linux.h |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig Nov. 5, 2019, 12:48 a.m. UTC | #1
On Sun, Nov 03, 2019 at 02:24:30PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Add a new macro, XFS_CORRUPT_ON, which we will use to integrate some
> corruption reporting when the corruption test expression is true.  This
> will be used in the next patch to remove the ugly XFS_WANT_CORRUPT*
> macros.

I don't particularly like the XFS_CORRUPT_ON name, and seeing how it
is used I like it even less.

Maybe XFS_IS_CORRUPT instead?
Darrick J. Wong Nov. 5, 2019, 12:51 a.m. UTC | #2
On Mon, Nov 04, 2019 at 04:48:28PM -0800, Christoph Hellwig wrote:
> On Sun, Nov 03, 2019 at 02:24:30PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Add a new macro, XFS_CORRUPT_ON, which we will use to integrate some
> > corruption reporting when the corruption test expression is true.  This
> > will be used in the next patch to remove the ugly XFS_WANT_CORRUPT*
> > macros.
> 
> I don't particularly like the XFS_CORRUPT_ON name, and seeing how it
> is used I like it even less.
> 
> Maybe XFS_IS_CORRUPT instead?

Fine with me.

I'd derived the name from WARN_ON, then realized that if you squint just
right it becomes "XFS_CORRUPTION" and then wondered if I should just
shorten it to "IS_BAD()" but sent it out anyway. :)

--D

Patch
diff mbox series

diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index 2271db4e8d66..9265ba9fd028 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -229,6 +229,10 @@  int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
 #define ASSERT(expr)	\
 	(likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__))
 
+#define XFS_CORRUPT_ON(mp, expr)	\
+	(unlikely(expr) ? assfail((mp), #expr, __FILE__, __LINE__), \
+			  true : false)
+
 #else	/* !DEBUG */
 
 #ifdef XFS_WARN
@@ -236,9 +240,16 @@  int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
 #define ASSERT(expr)	\
 	(likely(expr) ? (void)0 : asswarn(NULL, #expr, __FILE__, __LINE__))
 
+#define XFS_CORRUPT_ON(mp, expr)	\
+	(unlikely(expr) ? asswarn((mp), #expr, __FILE__, __LINE__), \
+			  true : false)
+
 #else	/* !DEBUG && !XFS_WARN */
 
-#define ASSERT(expr)	((void)0)
+#define ASSERT(expr)		((void)0)
+#define XFS_CORRUPT_ON(mp, expr)	\
+	(unlikely(expr) ? XFS_ERROR_REPORT(#expr, XFS_ERRLEVEL_LOW, (mp)), \
+			  true : false)
 
 #endif /* XFS_WARN */
 #endif /* DEBUG */