xfs: provide a centralized method for verifying inline fork data

Replace the current haphazard dir2 shortform verifier callsites with a
centralized verifier function that can be called either with the default
verifier functions or with a custom set.  This helps us strengthen
integrity checking while providing us with flexibility for repair tools.

xfs_repair wants this to be able to supply its own verifier functions
when trying to fix possibly corrupt metadata.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
This commit is contained in:
Darrick J. Wong
2018-01-08 10:51:06 -08:00
parent dc042c2d8f
commit 9cfb9b4747
6 changed files with 99 additions and 24 deletions

View File

@@ -3479,6 +3479,34 @@ abort_out:
return error;
}
/*
* If there are inline format data / attr forks attached to this inode,
* make sure they're not corrupt.
*/
bool
xfs_inode_verify_forks(
struct xfs_inode *ip)
{
xfs_failaddr_t fa;
fa = xfs_ifork_verify_data(ip, &xfs_default_ifork_ops);
if (fa) {
xfs_alert(ip->i_mount,
"%s: bad inode %llu inline data fork at %pF",
__func__, ip->i_ino, fa);
return false;
}
fa = xfs_ifork_verify_attr(ip, &xfs_default_ifork_ops);
if (fa) {
xfs_alert(ip->i_mount,
"%s: bad inode %llu inline attr fork at %pF",
__func__, ip->i_ino, fa);
return false;
}
return true;
}
STATIC int
xfs_iflush_int(
struct xfs_inode *ip,
@@ -3557,10 +3585,8 @@ xfs_iflush_int(
if (ip->i_d.di_version < 3)
ip->i_d.di_flushiter++;
/* Check the inline directory data. */
if (S_ISDIR(VFS_I(ip)->i_mode) &&
ip->i_d.di_format == XFS_DINODE_FMT_LOCAL &&
xfs_dir2_sf_verify(ip))
/* Check the inline fork data before we write out. */
if (!xfs_inode_verify_forks(ip))
goto corrupt_out;
/*