Commit eb77b23b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: add a xfs_valid_startblock helper

Add a helper that validates the startblock is valid.  This checks for a
non-zero block on the main device, but skips that check for blocks on
the realtime device.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 1baa2800
...@@ -4515,7 +4515,7 @@ xfs_bmapi_convert_delalloc( ...@@ -4515,7 +4515,7 @@ xfs_bmapi_convert_delalloc(
if (WARN_ON_ONCE(bma.blkno == NULLFSBLOCK)) if (WARN_ON_ONCE(bma.blkno == NULLFSBLOCK))
goto out_finish; goto out_finish;
error = -EFSCORRUPTED; error = -EFSCORRUPTED;
if (WARN_ON_ONCE(!bma.got.br_startblock && !XFS_IS_REALTIME_INODE(ip))) if (WARN_ON_ONCE(!xfs_valid_startblock(ip, bma.got.br_startblock)))
goto out_finish; goto out_finish;
XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length)); XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length));
......
...@@ -171,6 +171,13 @@ static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec) ...@@ -171,6 +171,13 @@ static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec)
!isnullstartblock(irec->br_startblock); !isnullstartblock(irec->br_startblock);
} }
/*
* Check the mapping for obviously garbage allocations that could trash the
* filesystem immediately.
*/
#define xfs_valid_startblock(ip, startblock) \
((startblock) != 0 || XFS_IS_REALTIME_INODE(ip))
void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno, void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno,
xfs_filblks_t len); xfs_filblks_t len);
int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd); int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);
......
...@@ -58,7 +58,7 @@ xfs_bmbt_to_iomap( ...@@ -58,7 +58,7 @@ xfs_bmbt_to_iomap(
{ {
struct xfs_mount *mp = ip->i_mount; struct xfs_mount *mp = ip->i_mount;
if (unlikely(!imap->br_startblock && !XFS_IS_REALTIME_INODE(ip))) if (unlikely(!xfs_valid_startblock(ip, imap->br_startblock)))
return xfs_alert_fsblock_zero(ip, imap); return xfs_alert_fsblock_zero(ip, imap);
if (imap->br_startblock == HOLESTARTBLOCK) { if (imap->br_startblock == HOLESTARTBLOCK) {
...@@ -297,7 +297,7 @@ xfs_iomap_write_direct( ...@@ -297,7 +297,7 @@ xfs_iomap_write_direct(
goto out_unlock; goto out_unlock;
} }
if (!(imap->br_startblock || XFS_IS_REALTIME_INODE(ip))) if (unlikely(!xfs_valid_startblock(ip, imap->br_startblock)))
error = xfs_alert_fsblock_zero(ip, imap); error = xfs_alert_fsblock_zero(ip, imap);
out_unlock: out_unlock:
...@@ -814,7 +814,7 @@ xfs_iomap_write_unwritten( ...@@ -814,7 +814,7 @@ xfs_iomap_write_unwritten(
if (error) if (error)
return error; return error;
if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip))) if (unlikely(!xfs_valid_startblock(ip, imap.br_startblock)))
return xfs_alert_fsblock_zero(ip, &imap); return xfs_alert_fsblock_zero(ip, &imap);
if ((numblks_fsb = imap.br_blockcount) == 0) { if ((numblks_fsb = imap.br_blockcount) == 0) {
......
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