Skip to content

Commit 0195647

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: move write verification out of _xfs_buf_ioapply
Split the write verification logic out of _xfs_buf_ioapply into a new xfs_buf_verify_write helper called by xfs_buf_submit given that it isn't about applying the I/O and doesn't really fit in with the rest of _xfs_buf_ioapply. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Acked-by: Dave Chinner <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent 72842db commit 0195647

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

fs/xfs/xfs_buf.c

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,36 +1612,6 @@ _xfs_buf_ioapply(
16121612

16131613
if (bp->b_flags & XBF_WRITE) {
16141614
op = REQ_OP_WRITE;
1615-
1616-
/*
1617-
* Run the write verifier callback function if it exists. If
1618-
* this function fails it will mark the buffer with an error and
1619-
* the IO should not be dispatched.
1620-
*/
1621-
if (bp->b_ops) {
1622-
bp->b_ops->verify_write(bp);
1623-
if (bp->b_error) {
1624-
xfs_force_shutdown(bp->b_mount,
1625-
SHUTDOWN_CORRUPT_INCORE);
1626-
return;
1627-
}
1628-
} else if (bp->b_rhash_key != XFS_BUF_DADDR_NULL) {
1629-
struct xfs_mount *mp = bp->b_mount;
1630-
1631-
/*
1632-
* non-crc filesystems don't attach verifiers during
1633-
* log recovery, so don't warn for such filesystems.
1634-
*/
1635-
if (xfs_has_crc(mp)) {
1636-
xfs_warn(mp,
1637-
"%s: no buf ops on daddr 0x%llx len %d",
1638-
__func__, xfs_buf_daddr(bp),
1639-
bp->b_length);
1640-
xfs_hex_dump(bp->b_addr,
1641-
XFS_CORRUPTION_DUMP_LEN);
1642-
dump_stack();
1643-
}
1644-
}
16451615
} else {
16461616
op = REQ_OP_READ;
16471617
if (bp->b_flags & XBF_READ_AHEAD)
@@ -1690,6 +1660,36 @@ xfs_buf_iowait(
16901660
return bp->b_error;
16911661
}
16921662

1663+
/*
1664+
* Run the write verifier callback function if it exists. If this fails, mark
1665+
* the buffer with an error and do not dispatch the I/O.
1666+
*/
1667+
static bool
1668+
xfs_buf_verify_write(
1669+
struct xfs_buf *bp)
1670+
{
1671+
if (bp->b_ops) {
1672+
bp->b_ops->verify_write(bp);
1673+
if (bp->b_error)
1674+
return false;
1675+
} else if (bp->b_rhash_key != XFS_BUF_DADDR_NULL) {
1676+
/*
1677+
* Non-crc filesystems don't attach verifiers during log
1678+
* recovery, so don't warn for such filesystems.
1679+
*/
1680+
if (xfs_has_crc(bp->b_mount)) {
1681+
xfs_warn(bp->b_mount,
1682+
"%s: no buf ops on daddr 0x%llx len %d",
1683+
__func__, xfs_buf_daddr(bp),
1684+
bp->b_length);
1685+
xfs_hex_dump(bp->b_addr, XFS_CORRUPTION_DUMP_LEN);
1686+
dump_stack();
1687+
}
1688+
}
1689+
1690+
return true;
1691+
}
1692+
16931693
/*
16941694
* Buffer I/O submission path, read or write. Asynchronous submission transfers
16951695
* the buffer lock ownership and the current reference to the IO. It is not
@@ -1745,8 +1745,15 @@ xfs_buf_submit(
17451745
atomic_set(&bp->b_io_remaining, 1);
17461746
if (bp->b_flags & XBF_ASYNC)
17471747
xfs_buf_ioacct_inc(bp);
1748+
1749+
if ((bp->b_flags & XBF_WRITE) && !xfs_buf_verify_write(bp)) {
1750+
xfs_force_shutdown(bp->b_mount, SHUTDOWN_CORRUPT_INCORE);
1751+
goto done;
1752+
}
1753+
17481754
_xfs_buf_ioapply(bp);
17491755

1756+
done:
17501757
/*
17511758
* If _xfs_buf_ioapply failed, we can get back here with only the IO
17521759
* reference we took above. If we drop it to zero, run completion so

0 commit comments

Comments
 (0)