Commit ff30a622 authored by Alex Elder's avatar Alex Elder

xfs: encapsulate bbcount validity checking

Define a function that encapsulates checking the validity of a log
block count.

(Updated from previous version--no longer includes error reporting in the
encapsulated validation function.)
Signed-off-by: default avatarAlex Elder <aelder@sgi.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
parent 5c17f533
...@@ -63,15 +63,29 @@ STATIC void xlog_recover_check_summary(xlog_t *); ...@@ -63,15 +63,29 @@ STATIC void xlog_recover_check_summary(xlog_t *);
/* Number of basic blocks in a log sector */ /* Number of basic blocks in a log sector */
#define xlog_sectbb(log) (1 << (log)->l_sectbb_log) #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.
* Returns nonzero if the count is valid, 0 otherwise.
*/
static inline int
xlog_buf_bbcount_valid(
xlog_t *log,
int bbcount)
{
return bbcount > 0 && bbcount <= log->l_logBBsize;
}
STATIC xfs_buf_t * STATIC xfs_buf_t *
xlog_get_bp( xlog_get_bp(
xlog_t *log, xlog_t *log,
int nbblks) int nbblks)
{ {
if (nbblks <= 0 || nbblks > log->l_logBBsize) { if (!xlog_buf_bbcount_valid(log, nbblks)) {
xlog_warn("XFS: Invalid block length (0x%x) given for buffer", nbblks); xlog_warn("XFS: Invalid block length (0x%x) given for buffer",
XFS_ERROR_REPORT("xlog_get_bp(1)", nbblks);
XFS_ERRLEVEL_HIGH, log->l_mp); XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_HIGH, log->l_mp);
return NULL; return NULL;
} }
...@@ -121,10 +135,10 @@ xlog_bread_noalign( ...@@ -121,10 +135,10 @@ xlog_bread_noalign(
{ {
int error; int error;
if (nbblks <= 0 || nbblks > log->l_logBBsize) { if (!xlog_buf_bbcount_valid(log, nbblks)) {
xlog_warn("XFS: Invalid block length (0x%x) given for buffer", nbblks); xlog_warn("XFS: Invalid block length (0x%x) given for buffer",
XFS_ERROR_REPORT("xlog_bread(1)", nbblks);
XFS_ERRLEVEL_HIGH, log->l_mp); XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_HIGH, log->l_mp);
return EFSCORRUPTED; return EFSCORRUPTED;
} }
...@@ -183,10 +197,10 @@ xlog_bwrite( ...@@ -183,10 +197,10 @@ xlog_bwrite(
{ {
int error; int error;
if (nbblks <= 0 || nbblks > log->l_logBBsize) { if (!xlog_buf_bbcount_valid(log, nbblks)) {
xlog_warn("XFS: Invalid block length (0x%x) given for buffer", nbblks); xlog_warn("XFS: Invalid block length (0x%x) given for buffer",
XFS_ERROR_REPORT("xlog_bwrite(1)", nbblks);
XFS_ERRLEVEL_HIGH, log->l_mp); XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_HIGH, log->l_mp);
return EFSCORRUPTED; return EFSCORRUPTED;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment