xfs
[Top] [All Lists]

[PATCH 5/7] xfs: encapsulate bbcount validity checking

To: xfs@xxxxxxxxxxx
Subject: [PATCH 5/7] xfs: encapsulate bbcount validity checking
From: Alex Elder <aelder@xxxxxxx>
Date: Thu, 18 Mar 2010 17:54:06 -0500
User-agent: Heirloom mailx 12.4 7/29/08
This replaces is a duplicated block of essentially identical code
in three spots with a call to a common helper routine.

Signed-off-by: Alex Elder <aelder@xxxxxxx>

---
 fs/xfs/xfs_log_recover.c |   44 +++++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 15 deletions(-)

Index: b/fs/xfs/xfs_log_recover.c
===================================================================
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -63,17 +63,39 @@ STATIC void xlog_recover_check_summary(x
 /* Number of basic blocks in a log sector */
 #define xlog_sectbb(log) (1 << (log)->l_sectbb_log)
 
+/*
+ * Verify the given count of basic blocks is valid number of blocks
+ * to specify for an operation involving the given XFS log buffer.
+ * If not, report the error.
+ *
+ * Returns 1 if the count is valid, 0 otherwise.
+ */
+
+#define xlog_buf_bbcount_valid(log, bbcount) \
+               _xlog_buf_bbcount_valid(log, bbcount, __func__)
+inline static int
+_xlog_buf_bbcount_valid(
+       xlog_t          *log,
+       int             bbcount,
+       const void      *function)
+{
+       if (bbcount > 0 && bbcount <= log->l_logBBsize)
+               return 1;
+
+       xlog_warn("XFS: Invalid block length (0x%x) given for buffer",
+               bbcount);
+       XFS_ERROR_REPORT(function, XFS_ERRLEVEL_HIGH, log->l_mp);
+
+       return 0;       /* Basic block count out of log's range */
+}
+
 STATIC xfs_buf_t *
 xlog_get_bp(
        xlog_t          *log,
        int             nbblks)
 {
-       if (nbblks <= 0 || nbblks > log->l_logBBsize) {
-               xlog_warn("XFS: Invalid block length (0x%x) given for buffer", 
nbblks);
-               XFS_ERROR_REPORT("xlog_get_bp(1)",
-                                XFS_ERRLEVEL_HIGH, log->l_mp);
+       if (!xlog_buf_bbcount_valid(log, nbblks))
                return NULL;
-       }
 
        if (log->l_sectbb_log) {
                if (nbblks > 1)
@@ -121,12 +143,8 @@ xlog_bread_noalign(
 {
        int             error;
 
-       if (nbblks <= 0 || nbblks > log->l_logBBsize) {
-               xlog_warn("XFS: Invalid block length (0x%x) given for buffer", 
nbblks);
-               XFS_ERROR_REPORT("xlog_bread(1)",
-                                XFS_ERRLEVEL_HIGH, log->l_mp);
+       if (!xlog_buf_bbcount_valid(log, nbblks))
                return EFSCORRUPTED;
-       }
 
        if (log->l_sectbb_log) {
                blk_no = round_down(blk_no, xlog_sectbb(log));
@@ -183,12 +201,8 @@ xlog_bwrite(
 {
        int             error;
 
-       if (nbblks <= 0 || nbblks > log->l_logBBsize) {
-               xlog_warn("XFS: Invalid block length (0x%x) given for buffer", 
nbblks);
-               XFS_ERROR_REPORT("xlog_bwrite(1)",
-                                XFS_ERRLEVEL_HIGH, log->l_mp);
+       if (!xlog_buf_bbcount_valid(log, nbblks))
                return EFSCORRUPTED;
-       }
 
        if (log->l_sectbb_log) {
                blk_no = round_down(blk_no, xlog_sectbb(log));

<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH 5/7] xfs: encapsulate bbcount validity checking, Alex Elder <=