]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: add a xfs_valid_startblock helper
authorChristoph Hellwig <hch@lst.de>
Fri, 13 Dec 2019 00:54:33 +0000 (19:54 -0500)
committerEric Sandeen <sandeen@redhat.com>
Fri, 13 Dec 2019 00:54:33 +0000 (19:54 -0500)
Source kernel commit: eb77b23b565e7e1d2cc3a7d9e4cc186fb54e81a8

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: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_bmap.c
libxfs/xfs_bmap.h

index d3b5e348a04fb6021e9da86339e5c87c8ce21a01..d95f0de01504aa43d32b47798a50faf740c02eb3 100644 (file)
@@ -4508,7 +4508,7 @@ xfs_bmapi_convert_delalloc(
        if (WARN_ON_ONCE(bma.blkno == NULLFSBLOCK))
                goto out_finish;
        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;
 
        XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length));
index c409871a096e0a2d9da1769e5ccf7fa88f6087de..5bb446d8054243d21867cf54279560cd5b637436 100644 (file)
@@ -171,6 +171,13 @@ static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec)
                !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,
                xfs_filblks_t len);
 int    xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);