xfs: refactor "does this fork map blocks" predicate
Replace the open-coded checks for whether or not an inode fork maps blocks with a macro that will implant the code for us. This helps us declutter the bmap code a bit. Note that I had to use a macro instead of a static inline function because of C header dependency problems between xfs_inode.h and xfs_inode_fork.h. Conversion was performed with the following Coccinelle script: @@ expression ip, w; @@ - XFS_IFORK_FORMAT(ip, w) == XFS_DINODE_FMT_EXTENTS || XFS_IFORK_FORMAT(ip, w) == XFS_DINODE_FMT_BTREE + xfs_ifork_has_extents(ip, w) @@ expression ip, w; @@ - XFS_IFORK_FORMAT(ip, w) != XFS_DINODE_FMT_EXTENTS && XFS_IFORK_FORMAT(ip, w) != XFS_DINODE_FMT_BTREE + !xfs_ifork_has_extents(ip, w) @@ expression ip, w; @@ - XFS_IFORK_FORMAT(ip, w) == XFS_DINODE_FMT_BTREE || XFS_IFORK_FORMAT(ip, w) == XFS_DINODE_FMT_EXTENTS + xfs_ifork_has_extents(ip, w) @@ expression ip, w; @@ - XFS_IFORK_FORMAT(ip, w) != XFS_DINODE_FMT_BTREE && XFS_IFORK_FORMAT(ip, w) != XFS_DINODE_FMT_EXTENTS + !xfs_ifork_has_extents(ip, w) @@ expression ip, w; @@ - (xfs_ifork_has_extents(ip, w)) + xfs_ifork_has_extents(ip, w) @@ expression ip, w; @@ - (!xfs_ifork_has_extents(ip, w)) + !xfs_ifork_has_extents(ip, w) Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
5113f8ec37
commit
2fe4f92834
|
@ -1283,8 +1283,7 @@ xfs_bmap_first_unused(
|
|||
xfs_fileoff_t lowest, max;
|
||||
int error;
|
||||
|
||||
ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE ||
|
||||
XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS ||
|
||||
ASSERT(xfs_ifork_has_extents(ip, whichfork) ||
|
||||
XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL);
|
||||
|
||||
if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL) {
|
||||
|
@ -1440,8 +1439,7 @@ xfs_bmap_last_offset(
|
|||
if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL)
|
||||
return 0;
|
||||
|
||||
if (XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE &&
|
||||
XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS) {
|
||||
if (!xfs_ifork_has_extents(ip, whichfork)) {
|
||||
ASSERT(0);
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
|
@ -3769,8 +3767,7 @@ xfs_bmapi_read(
|
|||
ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED|XFS_ILOCK_EXCL));
|
||||
|
||||
if (unlikely(XFS_TEST_ERROR(
|
||||
(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
|
||||
XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE),
|
||||
!xfs_ifork_has_extents(ip, whichfork),
|
||||
mp, XFS_ERRTAG_BMAPIFORMAT))) {
|
||||
XFS_ERROR_REPORT("xfs_bmapi_read", XFS_ERRLEVEL_LOW, mp);
|
||||
return -EFSCORRUPTED;
|
||||
|
@ -4281,8 +4278,7 @@ xfs_bmapi_write(
|
|||
(XFS_BMAPI_PREALLOC | XFS_BMAPI_ZERO));
|
||||
|
||||
if (unlikely(XFS_TEST_ERROR(
|
||||
(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
|
||||
XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE),
|
||||
!xfs_ifork_has_extents(ip, whichfork),
|
||||
mp, XFS_ERRTAG_BMAPIFORMAT))) {
|
||||
XFS_ERROR_REPORT("xfs_bmapi_write", XFS_ERRLEVEL_LOW, mp);
|
||||
return -EFSCORRUPTED;
|
||||
|
@ -4551,8 +4547,7 @@ xfs_bmapi_remap(
|
|||
(XFS_BMAPI_ATTRFORK | XFS_BMAPI_PREALLOC));
|
||||
|
||||
if (unlikely(XFS_TEST_ERROR(
|
||||
(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
|
||||
XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE),
|
||||
!xfs_ifork_has_extents(ip, whichfork),
|
||||
mp, XFS_ERRTAG_BMAPIFORMAT))) {
|
||||
XFS_ERROR_REPORT("xfs_bmapi_remap", XFS_ERRLEVEL_LOW, mp);
|
||||
return -EFSCORRUPTED;
|
||||
|
@ -5181,9 +5176,7 @@ __xfs_bunmapi(
|
|||
whichfork = xfs_bmapi_whichfork(flags);
|
||||
ASSERT(whichfork != XFS_COW_FORK);
|
||||
ifp = XFS_IFORK_PTR(ip, whichfork);
|
||||
if (unlikely(
|
||||
XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
|
||||
XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE)) {
|
||||
if (unlikely(!xfs_ifork_has_extents(ip, whichfork))) {
|
||||
XFS_ERROR_REPORT("xfs_bunmapi", XFS_ERRLEVEL_LOW,
|
||||
ip->i_mount);
|
||||
return -EFSCORRUPTED;
|
||||
|
@ -5678,8 +5671,7 @@ xfs_bmap_collapse_extents(
|
|||
int logflags = 0;
|
||||
|
||||
if (unlikely(XFS_TEST_ERROR(
|
||||
(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
|
||||
XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE),
|
||||
!xfs_ifork_has_extents(ip, whichfork),
|
||||
mp, XFS_ERRTAG_BMAPIFORMAT))) {
|
||||
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
|
||||
return -EFSCORRUPTED;
|
||||
|
@ -5796,8 +5788,7 @@ xfs_bmap_insert_extents(
|
|||
int logflags = 0;
|
||||
|
||||
if (unlikely(XFS_TEST_ERROR(
|
||||
(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
|
||||
XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE),
|
||||
!xfs_ifork_has_extents(ip, whichfork),
|
||||
mp, XFS_ERRTAG_BMAPIFORMAT))) {
|
||||
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
|
||||
return -EFSCORRUPTED;
|
||||
|
@ -5903,8 +5894,7 @@ xfs_bmap_split_extent_at(
|
|||
int i = 0;
|
||||
|
||||
if (unlikely(XFS_TEST_ERROR(
|
||||
(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
|
||||
XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE),
|
||||
!xfs_ifork_has_extents(ip, whichfork),
|
||||
mp, XFS_ERRTAG_BMAPIFORMAT))) {
|
||||
XFS_ERROR_REPORT("xfs_bmap_split_extent_at",
|
||||
XFS_ERRLEVEL_LOW, mp);
|
||||
|
|
|
@ -87,6 +87,10 @@ struct xfs_ifork {
|
|||
#define XFS_IFORK_MAXEXT(ip, w) \
|
||||
(XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
|
||||
|
||||
#define xfs_ifork_has_extents(ip, w) \
|
||||
(XFS_IFORK_FORMAT((ip), (w)) == XFS_DINODE_FMT_EXTENTS || \
|
||||
XFS_IFORK_FORMAT((ip), (w)) == XFS_DINODE_FMT_BTREE)
|
||||
|
||||
struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state);
|
||||
|
||||
int xfs_iformat_fork(struct xfs_inode *, struct xfs_dinode *);
|
||||
|
|
|
@ -485,8 +485,7 @@ xchk_da_btree(
|
|||
int error;
|
||||
|
||||
/* Skip short format data structures; no btree to scan. */
|
||||
if (XFS_IFORK_FORMAT(sc->ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
|
||||
XFS_IFORK_FORMAT(sc->ip, whichfork) != XFS_DINODE_FMT_BTREE)
|
||||
if (!xfs_ifork_has_extents(sc->ip, whichfork))
|
||||
return 0;
|
||||
|
||||
/* Set up initial da state. */
|
||||
|
|
|
@ -847,8 +847,7 @@ xfs_buffered_write_iomap_begin(
|
|||
xfs_ilock(ip, XFS_ILOCK_EXCL);
|
||||
|
||||
if (unlikely(XFS_TEST_ERROR(
|
||||
(XFS_IFORK_FORMAT(ip, XFS_DATA_FORK) != XFS_DINODE_FMT_EXTENTS &&
|
||||
XFS_IFORK_FORMAT(ip, XFS_DATA_FORK) != XFS_DINODE_FMT_BTREE),
|
||||
!xfs_ifork_has_extents(ip, XFS_DATA_FORK),
|
||||
mp, XFS_ERRTAG_BMAPIFORMAT))) {
|
||||
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
|
||||
error = -EFSCORRUPTED;
|
||||
|
|
Loading…
Reference in New Issue