Commit f9e03706 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: kill the XFS_WANT_CORRUPT_* macros

The XFS_WANT_CORRUPT_* macros conceal subtle side effects such as the
creation of local variables and redirections of the code flow.  This is
pretty ugly, so replace them with explicit XFS_IS_CORRUPT tests that
remove both of those ugly points.  The change was performed with the
following coccinelle script:

@@
expression mp, test;
identifier label;
@@

- XFS_WANT_CORRUPTED_GOTO(mp, test, label);
+ if (XFS_IS_CORRUPT(mp, !test)) { error = -EFSCORRUPTED; goto label; }

@@
expression mp, test;
@@

- XFS_WANT_CORRUPTED_RETURN(mp, test);
+ if (XFS_IS_CORRUPT(mp, !test)) return -EFSCORRUPTED;

@@
expression mp, lval, rval;
@@

- XFS_IS_CORRUPT(mp, !(lval == rval))
+ XFS_IS_CORRUPT(mp, lval != rval)

@@
expression mp, e1, e2;
@@

- XFS_IS_CORRUPT(mp, !(e1 && e2))
+ XFS_IS_CORRUPT(mp, !e1 || !e2)

@@
expression e1, e2;
@@

- !(e1 == e2)
+ e1 != e2

@@
expression e1, e2, e3, e4, e5, e6;
@@

- !(e1 == e2 && e3 == e4) || e5 != e6
+ e1 != e2 || e3 != e4 || e5 != e6

@@
expression e1, e2, e3, e4, e5, e6;
@@

- !(e1 == e2 || (e3 <= e4 && e5 <= e6))
+ e1 != e2 && (e3 > e4 || e5 > e6)

@@
expression mp, e1, e2;
@@

- XFS_IS_CORRUPT(mp, !(e1 <= e2))
+ XFS_IS_CORRUPT(mp, e1 > e2)

@@
expression mp, e1, e2;
@@

- XFS_IS_CORRUPT(mp, !(e1 < e2))
+ XFS_IS_CORRUPT(mp, e1 >= e2)

@@
expression mp, e1;
@@

- XFS_IS_CORRUPT(mp, !!e1)
+ XFS_IS_CORRUPT(mp, e1)

@@
expression mp, e1, e2;
@@

- XFS_IS_CORRUPT(mp, !(e1 || e2))
+ XFS_IS_CORRUPT(mp, !e1 && !e2)

@@
expression mp, e1, e2, e3, e4;
@@

- XFS_IS_CORRUPT(mp, !(e1 == e2) && !(e3 == e4))
+ XFS_IS_CORRUPT(mp, e1 != e2 && e3 != e4)

@@
expression mp, e1, e2, e3, e4;
@@

- XFS_IS_CORRUPT(mp, !(e1 <= e2) || !(e3 >= e4))
+ XFS_IS_CORRUPT(mp, e1 > e2 || e3 < e4)

@@
expression mp, e1, e2, e3, e4;
@@

- XFS_IS_CORRUPT(mp, !(e1 == e2) && !(e3 <= e4))
+ XFS_IS_CORRUPT(mp, e1 != e2 && e3 > e4)
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent 1ec28615
This diff is collapsed.
This diff is collapsed.
...@@ -1971,7 +1971,8 @@ xfs_btree_lookup( ...@@ -1971,7 +1971,8 @@ xfs_btree_lookup(
error = xfs_btree_increment(cur, 0, &i); error = xfs_btree_increment(cur, 0, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
return -EFSCORRUPTED;
*stat = 1; *stat = 1;
return 0; return 0;
} }
...@@ -2426,7 +2427,10 @@ xfs_btree_lshift( ...@@ -2426,7 +2427,10 @@ xfs_btree_lshift(
if (error) if (error)
goto error0; goto error0;
i = xfs_btree_firstrec(tcur, level); i = xfs_btree_firstrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(tcur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(tcur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_decrement(tcur, level, &i); error = xfs_btree_decrement(tcur, level, &i);
if (error) if (error)
...@@ -2593,7 +2597,10 @@ xfs_btree_rshift( ...@@ -2593,7 +2597,10 @@ xfs_btree_rshift(
if (error) if (error)
goto error0; goto error0;
i = xfs_btree_lastrec(tcur, level); i = xfs_btree_lastrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(tcur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(tcur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_increment(tcur, level, &i); error = xfs_btree_increment(tcur, level, &i);
if (error) if (error)
...@@ -3447,7 +3454,10 @@ xfs_btree_insert( ...@@ -3447,7 +3454,10 @@ xfs_btree_insert(
goto error0; goto error0;
} }
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
level++; level++;
/* /*
...@@ -3851,15 +3861,24 @@ xfs_btree_delrec( ...@@ -3851,15 +3861,24 @@ xfs_btree_delrec(
* Actually any entry but the first would suffice. * Actually any entry but the first would suffice.
*/ */
i = xfs_btree_lastrec(tcur, level); i = xfs_btree_lastrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_increment(tcur, level, &i); error = xfs_btree_increment(tcur, level, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
i = xfs_btree_lastrec(tcur, level); i = xfs_btree_lastrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
/* Grab a pointer to the block. */ /* Grab a pointer to the block. */
right = xfs_btree_get_block(tcur, level, &rbp); right = xfs_btree_get_block(tcur, level, &rbp);
...@@ -3903,12 +3922,18 @@ xfs_btree_delrec( ...@@ -3903,12 +3922,18 @@ xfs_btree_delrec(
rrecs = xfs_btree_get_numrecs(right); rrecs = xfs_btree_get_numrecs(right);
if (!xfs_btree_ptr_is_null(cur, &lptr)) { if (!xfs_btree_ptr_is_null(cur, &lptr)) {
i = xfs_btree_firstrec(tcur, level); i = xfs_btree_firstrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_decrement(tcur, level, &i); error = xfs_btree_decrement(tcur, level, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
} }
} }
...@@ -3922,13 +3947,19 @@ xfs_btree_delrec( ...@@ -3922,13 +3947,19 @@ xfs_btree_delrec(
* previous block. * previous block.
*/ */
i = xfs_btree_firstrec(tcur, level); i = xfs_btree_firstrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_decrement(tcur, level, &i); error = xfs_btree_decrement(tcur, level, &i);
if (error) if (error)
goto error0; goto error0;
i = xfs_btree_firstrec(tcur, level); i = xfs_btree_firstrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
/* Grab a pointer to the block. */ /* Grab a pointer to the block. */
left = xfs_btree_get_block(tcur, level, &lbp); left = xfs_btree_get_block(tcur, level, &lbp);
......
...@@ -544,7 +544,10 @@ xfs_inobt_insert_sprec( ...@@ -544,7 +544,10 @@ xfs_inobt_insert_sprec(
nrec->ir_free, &i); nrec->ir_free, &i);
if (error) if (error)
goto error; goto error;
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error); if (XFS_IS_CORRUPT(mp, i != 1)) {
error = -EFSCORRUPTED;
goto error;
}
goto out; goto out;
} }
...@@ -557,17 +560,23 @@ xfs_inobt_insert_sprec( ...@@ -557,17 +560,23 @@ xfs_inobt_insert_sprec(
error = xfs_inobt_get_rec(cur, &rec, &i); error = xfs_inobt_get_rec(cur, &rec, &i);
if (error) if (error)
goto error; goto error;
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error); if (XFS_IS_CORRUPT(mp, i != 1)) {
XFS_WANT_CORRUPTED_GOTO(mp, error = -EFSCORRUPTED;
rec.ir_startino == nrec->ir_startino, goto error;
error); }
if (XFS_IS_CORRUPT(mp, rec.ir_startino != nrec->ir_startino)) {
error = -EFSCORRUPTED;
goto error;
}
/* /*
* This should never fail. If we have coexisting records that * This should never fail. If we have coexisting records that
* cannot merge, something is seriously wrong. * cannot merge, something is seriously wrong.
*/ */
XFS_WANT_CORRUPTED_GOTO(mp, __xfs_inobt_can_merge(nrec, &rec), if (XFS_IS_CORRUPT(mp, !__xfs_inobt_can_merge(nrec, &rec))) {
error); error = -EFSCORRUPTED;
goto error;
}
trace_xfs_irec_merge_pre(mp, agno, rec.ir_startino, trace_xfs_irec_merge_pre(mp, agno, rec.ir_startino,
rec.ir_holemask, nrec->ir_startino, rec.ir_holemask, nrec->ir_startino,
...@@ -1057,7 +1066,8 @@ xfs_ialloc_next_rec( ...@@ -1057,7 +1066,8 @@ xfs_ialloc_next_rec(
error = xfs_inobt_get_rec(cur, rec, &i); error = xfs_inobt_get_rec(cur, rec, &i);
if (error) if (error)
return error; return error;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
return -EFSCORRUPTED;
} }
return 0; return 0;
...@@ -1081,7 +1091,8 @@ xfs_ialloc_get_rec( ...@@ -1081,7 +1091,8 @@ xfs_ialloc_get_rec(
error = xfs_inobt_get_rec(cur, rec, &i); error = xfs_inobt_get_rec(cur, rec, &i);
if (error) if (error)
return error; return error;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
return -EFSCORRUPTED;
} }
return 0; return 0;
...@@ -1161,12 +1172,18 @@ xfs_dialloc_ag_inobt( ...@@ -1161,12 +1172,18 @@ xfs_dialloc_ag_inobt(
error = xfs_inobt_lookup(cur, pagino, XFS_LOOKUP_LE, &i); error = xfs_inobt_lookup(cur, pagino, XFS_LOOKUP_LE, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0); if (XFS_IS_CORRUPT(mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_inobt_get_rec(cur, &rec, &j); error = xfs_inobt_get_rec(cur, &rec, &j);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(mp, j == 1, error0); if (XFS_IS_CORRUPT(mp, j != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
if (rec.ir_freecount > 0) { if (rec.ir_freecount > 0) {
/* /*
...@@ -1321,19 +1338,28 @@ xfs_dialloc_ag_inobt( ...@@ -1321,19 +1338,28 @@ xfs_dialloc_ag_inobt(
error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i); error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0); if (XFS_IS_CORRUPT(mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
for (;;) { for (;;) {
error = xfs_inobt_get_rec(cur, &rec, &i); error = xfs_inobt_get_rec(cur, &rec, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0); if (XFS_IS_CORRUPT(mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
if (rec.ir_freecount > 0) if (rec.ir_freecount > 0)
break; break;
error = xfs_btree_increment(cur, 0, &i); error = xfs_btree_increment(cur, 0, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0); if (XFS_IS_CORRUPT(mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
} }
alloc_inode: alloc_inode:
...@@ -1393,7 +1419,8 @@ xfs_dialloc_ag_finobt_near( ...@@ -1393,7 +1419,8 @@ xfs_dialloc_ag_finobt_near(
error = xfs_inobt_get_rec(lcur, rec, &i); error = xfs_inobt_get_rec(lcur, rec, &i);
if (error) if (error)
return error; return error;
XFS_WANT_CORRUPTED_RETURN(lcur->bc_mp, i == 1); if (XFS_IS_CORRUPT(lcur->bc_mp, i != 1))
return -EFSCORRUPTED;
/* /*
* See if we've landed in the parent inode record. The finobt * See if we've landed in the parent inode record. The finobt
...@@ -1416,10 +1443,16 @@ xfs_dialloc_ag_finobt_near( ...@@ -1416,10 +1443,16 @@ xfs_dialloc_ag_finobt_near(
error = xfs_inobt_get_rec(rcur, &rrec, &j); error = xfs_inobt_get_rec(rcur, &rrec, &j);
if (error) if (error)
goto error_rcur; goto error_rcur;
XFS_WANT_CORRUPTED_GOTO(lcur->bc_mp, j == 1, error_rcur); if (XFS_IS_CORRUPT(lcur->bc_mp, j != 1)) {
error = -EFSCORRUPTED;
goto error_rcur;
}
} }
XFS_WANT_CORRUPTED_GOTO(lcur->bc_mp, i == 1 || j == 1, error_rcur); if (XFS_IS_CORRUPT(lcur->bc_mp, i != 1 && j != 1)) {
error = -EFSCORRUPTED;
goto error_rcur;
}
if (i == 1 && j == 1) { if (i == 1 && j == 1) {
/* /*
* Both the left and right records are valid. Choose the closer * Both the left and right records are valid. Choose the closer
...@@ -1472,7 +1505,8 @@ xfs_dialloc_ag_finobt_newino( ...@@ -1472,7 +1505,8 @@ xfs_dialloc_ag_finobt_newino(
error = xfs_inobt_get_rec(cur, rec, &i); error = xfs_inobt_get_rec(cur, rec, &i);
if (error) if (error)
return error; return error;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
return -EFSCORRUPTED;
return 0; return 0;
} }
} }
...@@ -1483,12 +1517,14 @@ xfs_dialloc_ag_finobt_newino( ...@@ -1483,12 +1517,14 @@ xfs_dialloc_ag_finobt_newino(
error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i); error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
if (error) if (error)
return error; return error;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
return -EFSCORRUPTED;
error = xfs_inobt_get_rec(cur, rec, &i); error = xfs_inobt_get_rec(cur, rec, &i);
if (error) if (error)
return error; return error;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
return -EFSCORRUPTED;
return 0; return 0;
} }
...@@ -1510,20 +1546,24 @@ xfs_dialloc_ag_update_inobt( ...@@ -1510,20 +1546,24 @@ xfs_dialloc_ag_update_inobt(
error = xfs_inobt_lookup(cur, frec->ir_startino, XFS_LOOKUP_EQ, &i); error = xfs_inobt_lookup(cur, frec->ir_startino, XFS_LOOKUP_EQ, &i);
if (error) if (error)
return error; return error;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
return -EFSCORRUPTED;
error = xfs_inobt_get_rec(cur, &rec, &i); error = xfs_inobt_get_rec(cur, &rec, &i);
if (error) if (error)
return error; return error;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
return -EFSCORRUPTED;
ASSERT((XFS_AGINO_TO_OFFSET(cur->bc_mp, rec.ir_startino) % ASSERT((XFS_AGINO_TO_OFFSET(cur->bc_mp, rec.ir_startino) %
XFS_INODES_PER_CHUNK) == 0); XFS_INODES_PER_CHUNK) == 0);
rec.ir_free &= ~XFS_INOBT_MASK(offset); rec.ir_free &= ~XFS_INOBT_MASK(offset);
rec.ir_freecount--; rec.ir_freecount--;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, (rec.ir_free == frec->ir_free) && if (XFS_IS_CORRUPT(cur->bc_mp,
(rec.ir_freecount == frec->ir_freecount)); rec.ir_free != frec->ir_free ||
rec.ir_freecount != frec->ir_freecount))
return -EFSCORRUPTED;
return xfs_inobt_update(cur, &rec); return xfs_inobt_update(cur, &rec);
} }
...@@ -1933,14 +1973,20 @@ xfs_difree_inobt( ...@@ -1933,14 +1973,20 @@ xfs_difree_inobt(
__func__, error); __func__, error);
goto error0; goto error0;
} }
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0); if (XFS_IS_CORRUPT(mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_inobt_get_rec(cur, &rec, &i); error = xfs_inobt_get_rec(cur, &rec, &i);
if (error) { if (error) {
xfs_warn(mp, "%s: xfs_inobt_get_rec() returned error %d.", xfs_warn(mp, "%s: xfs_inobt_get_rec() returned error %d.",
__func__, error); __func__, error);
goto error0; goto error0;
} }
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0); if (XFS_IS_CORRUPT(mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
/* /*
* Get the offset in the inode chunk. * Get the offset in the inode chunk.
*/ */
...@@ -2052,7 +2098,10 @@ xfs_difree_finobt( ...@@ -2052,7 +2098,10 @@ xfs_difree_finobt(
* freed an inode in a previously fully allocated chunk. If not, * freed an inode in a previously fully allocated chunk. If not,
* something is out of sync. * something is out of sync.
*/ */
XFS_WANT_CORRUPTED_GOTO(mp, ibtrec->ir_freecount == 1, error); if (XFS_IS_CORRUPT(mp, ibtrec->ir_freecount != 1)) {
error = -EFSCORRUPTED;
goto error;
}
error = xfs_inobt_insert_rec(cur, ibtrec->ir_holemask, error = xfs_inobt_insert_rec(cur, ibtrec->ir_holemask,
ibtrec->ir_count, ibtrec->ir_count,
...@@ -2075,14 +2124,20 @@ xfs_difree_finobt( ...@@ -2075,14 +2124,20 @@ xfs_difree_finobt(
error = xfs_inobt_get_rec(cur, &rec, &i); error = xfs_inobt_get_rec(cur, &rec, &i);
if (error) if (error)
goto error; goto error;
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error); if (XFS_IS_CORRUPT(mp, i != 1)) {
error = -EFSCORRUPTED;
goto error;
}
rec.ir_free |= XFS_INOBT_MASK(offset); rec.ir_free |= XFS_INOBT_MASK(offset);
rec.ir_freecount++; rec.ir_freecount++;
XFS_WANT_CORRUPTED_GOTO(mp, (rec.ir_free == ibtrec->ir_free) && if (XFS_IS_CORRUPT(mp,
(rec.ir_freecount == ibtrec->ir_freecount), rec.ir_free != ibtrec->ir_free ||
error); rec.ir_freecount != ibtrec->ir_freecount)) {
error = -EFSCORRUPTED;
goto error;
}
/* /*
* The content of inobt records should always match between the inobt * The content of inobt records should always match between the inobt
......
...@@ -200,7 +200,10 @@ xfs_refcount_insert( ...@@ -200,7 +200,10 @@ xfs_refcount_insert(
error = xfs_btree_insert(cur, i); error = xfs_btree_insert(cur, i);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, *i == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, *i != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
out_error: out_error:
if (error) if (error)
...@@ -227,10 +230,16 @@ xfs_refcount_delete( ...@@ -227,10 +230,16 @@ xfs_refcount_delete(
error = xfs_refcount_get_rec(cur, &irec, &found_rec); error = xfs_refcount_get_rec(cur, &irec, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
trace_xfs_refcount_delete(cur->bc_mp, cur->bc_private.a.agno, &irec); trace_xfs_refcount_delete(cur->bc_mp, cur->bc_private.a.agno, &irec);
error = xfs_btree_delete(cur, i); error = xfs_btree_delete(cur, i);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, *i == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, *i != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
if (error) if (error)
goto out_error; goto out_error;
error = xfs_refcount_lookup_ge(cur, irec.rc_startblock, &found_rec); error = xfs_refcount_lookup_ge(cur, irec.rc_startblock, &found_rec);
...@@ -349,7 +358,10 @@ xfs_refcount_split_extent( ...@@ -349,7 +358,10 @@ xfs_refcount_split_extent(
error = xfs_refcount_get_rec(cur, &rcext, &found_rec); error = xfs_refcount_get_rec(cur, &rcext, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
if (rcext.rc_startblock == agbno || xfs_refc_next(&rcext) <= agbno) if (rcext.rc_startblock == agbno || xfs_refc_next(&rcext) <= agbno)
return 0; return 0;
...@@ -371,7 +383,10 @@ xfs_refcount_split_extent( ...@@ -371,7 +383,10 @@ xfs_refcount_split_extent(
error = xfs_refcount_insert(cur, &tmp, &found_rec); error = xfs_refcount_insert(cur, &tmp, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
return error; return error;
out_error: out_error:
...@@ -410,19 +425,27 @@ xfs_refcount_merge_center_extents( ...@@ -410,19 +425,27 @@ xfs_refcount_merge_center_extents(
&found_rec); &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
error = xfs_refcount_delete(cur, &found_rec); error = xfs_refcount_delete(cur, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
if (center->rc_refcount > 1) { if (center->rc_refcount > 1) {
error = xfs_refcount_delete(cur, &found_rec); error = xfs_refcount_delete(cur, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
out_error); error = -EFSCORRUPTED;
goto out_error;
}
} }
/* Enlarge the left extent. */ /* Enlarge the left extent. */
...@@ -430,7 +453,10 @@ xfs_refcount_merge_center_extents( ...@@ -430,7 +453,10 @@ xfs_refcount_merge_center_extents(
&found_rec); &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
left->rc_blockcount = extlen; left->rc_blockcount = extlen;
error = xfs_refcount_update(cur, left); error = xfs_refcount_update(cur, left);
...@@ -469,14 +495,18 @@ xfs_refcount_merge_left_extent( ...@@ -469,14 +495,18 @@ xfs_refcount_merge_left_extent(
&found_rec); &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
out_error); error = -EFSCORRUPTED;
goto out_error;
}
error = xfs_refcount_delete(cur, &found_rec); error = xfs_refcount_delete(cur, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
out_error); error = -EFSCORRUPTED;
goto out_error;
}
} }
/* Enlarge the left extent. */ /* Enlarge the left extent. */
...@@ -484,7 +514,10 @@ xfs_refcount_merge_left_extent( ...@@ -484,7 +514,10 @@ xfs_refcount_merge_left_extent(
&found_rec); &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
left->rc_blockcount += cleft->rc_blockcount; left->rc_blockcount += cleft->rc_blockcount;
error = xfs_refcount_update(cur, left); error = xfs_refcount_update(cur, left);
...@@ -526,14 +559,18 @@ xfs_refcount_merge_right_extent( ...@@ -526,14 +559,18 @@ xfs_refcount_merge_right_extent(
&found_rec); &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
out_error); error = -EFSCORRUPTED;
goto out_error;
}
error = xfs_refcount_delete(cur, &found_rec); error = xfs_refcount_delete(cur, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
out_error); error = -EFSCORRUPTED;
goto out_error;
}
} }
/* Enlarge the right extent. */ /* Enlarge the right extent. */
...@@ -541,7 +578,10 @@ xfs_refcount_merge_right_extent( ...@@ -541,7 +578,10 @@ xfs_refcount_merge_right_extent(
&found_rec); &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
right->rc_startblock -= cright->rc_blockcount; right->rc_startblock -= cright->rc_blockcount;
right->rc_blockcount += cright->rc_blockcount; right->rc_blockcount += cright->rc_blockcount;
...@@ -587,7 +627,10 @@ xfs_refcount_find_left_extents( ...@@ -587,7 +627,10 @@ xfs_refcount_find_left_extents(
error = xfs_refcount_get_rec(cur, &tmp, &found_rec); error = xfs_refcount_get_rec(cur, &tmp, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
if (xfs_refc_next(&tmp) != agbno) if (xfs_refc_next(&tmp) != agbno)
return 0; return 0;
...@@ -605,8 +648,10 @@ xfs_refcount_find_left_extents( ...@@ -605,8 +648,10 @@ xfs_refcount_find_left_extents(
error = xfs_refcount_get_rec(cur, &tmp, &found_rec); error = xfs_refcount_get_rec(cur, &tmp, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
out_error); error = -EFSCORRUPTED;
goto out_error;
}
/* if tmp starts at the end of our range, just use that */ /* if tmp starts at the end of our range, just use that */
if (tmp.rc_startblock == agbno) if (tmp.rc_startblock == agbno)
...@@ -671,7 +716,10 @@ xfs_refcount_find_right_extents( ...@@ -671,7 +716,10 @@ xfs_refcount_find_right_extents(
error = xfs_refcount_get_rec(cur, &tmp, &found_rec); error = xfs_refcount_get_rec(cur, &tmp, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
if (tmp.rc_startblock != agbno + aglen) if (tmp.rc_startblock != agbno + aglen)
return 0; return 0;
...@@ -689,8 +737,10 @@ xfs_refcount_find_right_extents( ...@@ -689,8 +737,10 @@ xfs_refcount_find_right_extents(
error = xfs_refcount_get_rec(cur, &tmp, &found_rec); error = xfs_refcount_get_rec(cur, &tmp, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
out_error); error = -EFSCORRUPTED;
goto out_error;
}
/* if tmp ends at the end of our range, just use that */ /* if tmp ends at the end of our range, just use that */
if (xfs_refc_next(&tmp) == agbno + aglen) if (xfs_refc_next(&tmp) == agbno + aglen)
...@@ -913,8 +963,11 @@ xfs_refcount_adjust_extents( ...@@ -913,8 +963,11 @@ xfs_refcount_adjust_extents(
&found_tmp); &found_tmp);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, if (XFS_IS_CORRUPT(cur->bc_mp,
found_tmp == 1, out_error); found_tmp != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
cur->bc_private.a.priv.refc.nr_ops++; cur->bc_private.a.priv.refc.nr_ops++;
} else { } else {
fsbno = XFS_AGB_TO_FSB(cur->bc_mp, fsbno = XFS_AGB_TO_FSB(cur->bc_mp,
...@@ -955,8 +1008,10 @@ xfs_refcount_adjust_extents( ...@@ -955,8 +1008,10 @@ xfs_refcount_adjust_extents(
error = xfs_refcount_delete(cur, &found_rec); error = xfs_refcount_delete(cur, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
found_rec == 1, out_error); error = -EFSCORRUPTED;
goto out_error;
}
cur->bc_private.a.priv.refc.nr_ops++; cur->bc_private.a.priv.refc.nr_ops++;
goto advloop; goto advloop;
} else { } else {
...@@ -1272,7 +1327,10 @@ xfs_refcount_find_shared( ...@@ -1272,7 +1327,10 @@ xfs_refcount_find_shared(
error = xfs_refcount_get_rec(cur, &tmp, &i); error = xfs_refcount_get_rec(cur, &tmp, &i);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
/* If the extent ends before the start, look at the next one */ /* If the extent ends before the start, look at the next one */
if (tmp.rc_startblock + tmp.rc_blockcount <= agbno) { if (tmp.rc_startblock + tmp.rc_blockcount <= agbno) {
...@@ -1284,7 +1342,10 @@ xfs_refcount_find_shared( ...@@ -1284,7 +1342,10 @@ xfs_refcount_find_shared(
error = xfs_refcount_get_rec(cur, &tmp, &i); error = xfs_refcount_get_rec(cur, &tmp, &i);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
} }
/* If the extent starts after the range we want, bail out */ /* If the extent starts after the range we want, bail out */
...@@ -1312,7 +1373,10 @@ xfs_refcount_find_shared( ...@@ -1312,7 +1373,10 @@ xfs_refcount_find_shared(
error = xfs_refcount_get_rec(cur, &tmp, &i); error = xfs_refcount_get_rec(cur, &tmp, &i);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, out_error); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
if (tmp.rc_startblock >= agbno + aglen || if (tmp.rc_startblock >= agbno + aglen ||
tmp.rc_startblock != *fbno + *flen) tmp.rc_startblock != *fbno + *flen)
break; break;
...@@ -1413,8 +1477,11 @@ xfs_refcount_adjust_cow_extents( ...@@ -1413,8 +1477,11 @@ xfs_refcount_adjust_cow_extents(
switch (adj) { switch (adj) {
case XFS_REFCOUNT_ADJUST_COW_ALLOC: case XFS_REFCOUNT_ADJUST_COW_ALLOC:
/* Adding a CoW reservation, there should be nothing here. */ /* Adding a CoW reservation, there should be nothing here. */
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, if (XFS_IS_CORRUPT(cur->bc_mp,
ext.rc_startblock >= agbno + aglen, out_error); agbno + aglen > ext.rc_startblock)) {
error = -EFSCORRUPTED;
goto out_error;
}
tmp.rc_startblock = agbno; tmp.rc_startblock = agbno;
tmp.rc_blockcount = aglen; tmp.rc_blockcount = aglen;
...@@ -1426,17 +1493,25 @@ xfs_refcount_adjust_cow_extents( ...@@ -1426,17 +1493,25 @@ xfs_refcount_adjust_cow_extents(
&found_tmp); &found_tmp);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, if (XFS_IS_CORRUPT(cur->bc_mp, found_tmp != 1)) {
found_tmp == 1, out_error); error = -EFSCORRUPTED;
goto out_error;
}
break; break;
case XFS_REFCOUNT_ADJUST_COW_FREE: case XFS_REFCOUNT_ADJUST_COW_FREE:
/* Removing a CoW reservation, there should be one extent. */ /* Removing a CoW reservation, there should be one extent. */
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, if (XFS_IS_CORRUPT(cur->bc_mp, ext.rc_startblock != agbno)) {
ext.rc_startblock == agbno, out_error); error = -EFSCORRUPTED;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, goto out_error;
ext.rc_blockcount == aglen, out_error); }
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, if (XFS_IS_CORRUPT(cur->bc_mp, ext.rc_blockcount != aglen)) {
ext.rc_refcount == 1, out_error); error = -EFSCORRUPTED;
goto out_error;
}
if (XFS_IS_CORRUPT(cur->bc_mp, ext.rc_refcount != 1)) {
error = -EFSCORRUPTED;
goto out_error;
}
ext.rc_refcount = 0; ext.rc_refcount = 0;
trace_xfs_refcount_modify_extent(cur->bc_mp, trace_xfs_refcount_modify_extent(cur->bc_mp,
...@@ -1444,8 +1519,10 @@ xfs_refcount_adjust_cow_extents( ...@@ -1444,8 +1519,10 @@ xfs_refcount_adjust_cow_extents(
error = xfs_refcount_delete(cur, &found_rec); error = xfs_refcount_delete(cur, &found_rec);
if (error) if (error)
goto out_error; goto out_error;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
found_rec == 1, out_error); error = -EFSCORRUPTED;
goto out_error;
}
break; break;
default: default:
ASSERT(0); ASSERT(0);
......
This diff is collapsed.
...@@ -71,7 +71,10 @@ xfs_trim_extents( ...@@ -71,7 +71,10 @@ xfs_trim_extents(
error = xfs_alloc_get_rec(cur, &fbno, &flen, &i); error = xfs_alloc_get_rec(cur, &fbno, &flen, &i);
if (error) if (error)
goto out_del_cursor; goto out_del_cursor;
XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_del_cursor); if (XFS_IS_CORRUPT(mp, i != 1)) {
error = -EFSCORRUPTED;
goto out_del_cursor;
}
ASSERT(flen <= be32_to_cpu(XFS_BUF_TO_AGF(agbp)->agf_longest)); ASSERT(flen <= be32_to_cpu(XFS_BUF_TO_AGF(agbp)->agf_longest));
/* /*
......
...@@ -38,32 +38,6 @@ extern void xfs_inode_verifier_error(struct xfs_inode *ip, int error, ...@@ -38,32 +38,6 @@ extern void xfs_inode_verifier_error(struct xfs_inode *ip, int error,
/* Dump 128 bytes of any corrupt buffer */ /* Dump 128 bytes of any corrupt buffer */
#define XFS_CORRUPTION_DUMP_LEN (128) #define XFS_CORRUPTION_DUMP_LEN (128)
/*
* Macros to set EFSCORRUPTED & return/branch.
*/
#define XFS_WANT_CORRUPTED_GOTO(mp, x, l) \
{ \
int fs_is_ok = (x); \
ASSERT(fs_is_ok); \
if (unlikely(!fs_is_ok)) { \
XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_GOTO", \
XFS_ERRLEVEL_LOW, mp); \
error = -EFSCORRUPTED; \
goto l; \
} \
}
#define XFS_WANT_CORRUPTED_RETURN(mp, x) \
{ \
int fs_is_ok = (x); \
ASSERT(fs_is_ok); \
if (unlikely(!fs_is_ok)) { \
XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_RETURN", \
XFS_ERRLEVEL_LOW, mp); \
return -EFSCORRUPTED; \
} \
}
#ifdef DEBUG #ifdef DEBUG
extern int xfs_errortag_init(struct xfs_mount *mp); extern int xfs_errortag_init(struct xfs_mount *mp);
extern void xfs_errortag_del(struct xfs_mount *mp); extern void xfs_errortag_del(struct xfs_mount *mp);
......
...@@ -298,7 +298,8 @@ xfs_iwalk_ag_start( ...@@ -298,7 +298,8 @@ xfs_iwalk_ag_start(
error = xfs_inobt_get_rec(*curpp, irec, has_more); error = xfs_inobt_get_rec(*curpp, irec, has_more);
if (error) if (error)
return error; return error;
XFS_WANT_CORRUPTED_RETURN(mp, *has_more == 1); if (XFS_IS_CORRUPT(mp, *has_more != 1))
return -EFSCORRUPTED;
/* /*
* If the LE lookup yielded an inobt record before the cursor position, * If the LE lookup yielded an inobt record before the cursor position,
......
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