xfs: hoist recovered rmap intent checks out of xfs_rui_item_recover
When we recover a rmap intent from the log, we need to validate its contents before we try to replay them. Hoist the checking code into a separate function in preparation to refactor this code to use validation helpers. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com>
This commit is contained in:
parent
67d8679bd3
commit
dda7ba65bf
|
@ -460,6 +460,42 @@ const struct xfs_defer_op_type xfs_rmap_update_defer_type = {
|
||||||
.cancel_item = xfs_rmap_update_cancel_item,
|
.cancel_item = xfs_rmap_update_cancel_item,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Is this recovered RUI ok? */
|
||||||
|
static inline bool
|
||||||
|
xfs_rui_validate_map(
|
||||||
|
struct xfs_mount *mp,
|
||||||
|
struct xfs_map_extent *rmap)
|
||||||
|
{
|
||||||
|
xfs_fsblock_t startblock_fsb;
|
||||||
|
bool op_ok;
|
||||||
|
|
||||||
|
startblock_fsb = XFS_BB_TO_FSB(mp,
|
||||||
|
XFS_FSB_TO_DADDR(mp, rmap->me_startblock));
|
||||||
|
switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) {
|
||||||
|
case XFS_RMAP_EXTENT_MAP:
|
||||||
|
case XFS_RMAP_EXTENT_MAP_SHARED:
|
||||||
|
case XFS_RMAP_EXTENT_UNMAP:
|
||||||
|
case XFS_RMAP_EXTENT_UNMAP_SHARED:
|
||||||
|
case XFS_RMAP_EXTENT_CONVERT:
|
||||||
|
case XFS_RMAP_EXTENT_CONVERT_SHARED:
|
||||||
|
case XFS_RMAP_EXTENT_ALLOC:
|
||||||
|
case XFS_RMAP_EXTENT_FREE:
|
||||||
|
op_ok = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
op_ok = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!op_ok || startblock_fsb == 0 ||
|
||||||
|
rmap->me_len == 0 ||
|
||||||
|
startblock_fsb >= mp->m_sb.sb_dblocks ||
|
||||||
|
rmap->me_len >= mp->m_sb.sb_agblocks ||
|
||||||
|
(rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Process an rmap update intent item that was recovered from the log.
|
* Process an rmap update intent item that was recovered from the log.
|
||||||
* We need to update the rmapbt.
|
* We need to update the rmapbt.
|
||||||
|
@ -475,10 +511,8 @@ xfs_rui_item_recover(
|
||||||
struct xfs_trans *tp;
|
struct xfs_trans *tp;
|
||||||
struct xfs_btree_cur *rcur = NULL;
|
struct xfs_btree_cur *rcur = NULL;
|
||||||
struct xfs_mount *mp = lip->li_mountp;
|
struct xfs_mount *mp = lip->li_mountp;
|
||||||
xfs_fsblock_t startblock_fsb;
|
|
||||||
enum xfs_rmap_intent_type type;
|
enum xfs_rmap_intent_type type;
|
||||||
xfs_exntst_t state;
|
xfs_exntst_t state;
|
||||||
bool op_ok;
|
|
||||||
int i;
|
int i;
|
||||||
int whichfork;
|
int whichfork;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
@ -489,30 +523,13 @@ xfs_rui_item_recover(
|
||||||
* just toss the RUI.
|
* just toss the RUI.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < ruip->rui_format.rui_nextents; i++) {
|
for (i = 0; i < ruip->rui_format.rui_nextents; i++) {
|
||||||
rmap = &ruip->rui_format.rui_extents[i];
|
if (!xfs_rui_validate_map(mp,
|
||||||
startblock_fsb = XFS_BB_TO_FSB(mp,
|
&ruip->rui_format.rui_extents[i])) {
|
||||||
XFS_FSB_TO_DADDR(mp, rmap->me_startblock));
|
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
|
||||||
switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) {
|
&ruip->rui_format,
|
||||||
case XFS_RMAP_EXTENT_MAP:
|
sizeof(ruip->rui_format));
|
||||||
case XFS_RMAP_EXTENT_MAP_SHARED:
|
|
||||||
case XFS_RMAP_EXTENT_UNMAP:
|
|
||||||
case XFS_RMAP_EXTENT_UNMAP_SHARED:
|
|
||||||
case XFS_RMAP_EXTENT_CONVERT:
|
|
||||||
case XFS_RMAP_EXTENT_CONVERT_SHARED:
|
|
||||||
case XFS_RMAP_EXTENT_ALLOC:
|
|
||||||
case XFS_RMAP_EXTENT_FREE:
|
|
||||||
op_ok = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
op_ok = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!op_ok || startblock_fsb == 0 ||
|
|
||||||
rmap->me_len == 0 ||
|
|
||||||
startblock_fsb >= mp->m_sb.sb_dblocks ||
|
|
||||||
rmap->me_len >= mp->m_sb.sb_agblocks ||
|
|
||||||
(rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS))
|
|
||||||
return -EFSCORRUPTED;
|
return -EFSCORRUPTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
|
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
|
||||||
|
|
Loading…
Reference in New Issue