Skip to content

Commit a91bf99

Browse files
committed
xfs: refactor eofb matching into a single helper
Refactor the two eofb-matching logics into a single helper so that we don't repeat ourselves. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 8921a0f commit a91bf99

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

fs/xfs/xfs_icache.c

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,14 +1456,43 @@ xfs_inode_match_id_union(
14561456
return 0;
14571457
}
14581458

1459+
/*
1460+
* Is this inode @ip eligible for eof/cow block reclamation, given some
1461+
* filtering parameters @eofb? The inode is eligible if @eofb is null or
1462+
* if the predicate functions match.
1463+
*/
1464+
static bool
1465+
xfs_inode_matches_eofb(
1466+
struct xfs_inode *ip,
1467+
struct xfs_eofblocks *eofb)
1468+
{
1469+
int match;
1470+
1471+
if (!eofb)
1472+
return true;
1473+
1474+
if (eofb->eof_flags & XFS_EOF_FLAGS_UNION)
1475+
match = xfs_inode_match_id_union(ip, eofb);
1476+
else
1477+
match = xfs_inode_match_id(ip, eofb);
1478+
if (!match)
1479+
return false;
1480+
1481+
/* skip the inode if the file size is too small */
1482+
if ((eofb->eof_flags & XFS_EOF_FLAGS_MINFILESIZE) &&
1483+
XFS_ISIZE(ip) < eofb->eof_min_file_size)
1484+
return false;
1485+
1486+
return true;
1487+
}
1488+
14591489
STATIC int
14601490
xfs_inode_free_eofblocks(
14611491
struct xfs_inode *ip,
14621492
void *args)
14631493
{
14641494
struct xfs_eofblocks *eofb = args;
14651495
bool wait;
1466-
int match;
14671496
int ret;
14681497

14691498
wait = eofb && (eofb->eof_flags & XFS_EOF_FLAGS_SYNC);
@@ -1482,19 +1511,8 @@ xfs_inode_free_eofblocks(
14821511
if (!wait && mapping_tagged(VFS_I(ip)->i_mapping, PAGECACHE_TAG_DIRTY))
14831512
return 0;
14841513

1485-
if (eofb) {
1486-
if (eofb->eof_flags & XFS_EOF_FLAGS_UNION)
1487-
match = xfs_inode_match_id_union(ip, eofb);
1488-
else
1489-
match = xfs_inode_match_id(ip, eofb);
1490-
if (!match)
1491-
return 0;
1492-
1493-
/* skip the inode if the file size is too small */
1494-
if (eofb->eof_flags & XFS_EOF_FLAGS_MINFILESIZE &&
1495-
XFS_ISIZE(ip) < eofb->eof_min_file_size)
1496-
return 0;
1497-
}
1514+
if (!xfs_inode_matches_eofb(ip, eofb))
1515+
return 0;
14981516

14991517
/*
15001518
* If the caller is waiting, return -EAGAIN to keep the background
@@ -1737,25 +1755,13 @@ xfs_inode_free_cowblocks(
17371755
void *args)
17381756
{
17391757
struct xfs_eofblocks *eofb = args;
1740-
int match;
17411758
int ret = 0;
17421759

17431760
if (!xfs_prep_free_cowblocks(ip))
17441761
return 0;
17451762

1746-
if (eofb) {
1747-
if (eofb->eof_flags & XFS_EOF_FLAGS_UNION)
1748-
match = xfs_inode_match_id_union(ip, eofb);
1749-
else
1750-
match = xfs_inode_match_id(ip, eofb);
1751-
if (!match)
1752-
return 0;
1753-
1754-
/* skip the inode if the file size is too small */
1755-
if (eofb->eof_flags & XFS_EOF_FLAGS_MINFILESIZE &&
1756-
XFS_ISIZE(ip) < eofb->eof_min_file_size)
1757-
return 0;
1758-
}
1763+
if (!xfs_inode_matches_eofb(ip, eofb))
1764+
return 0;
17591765

17601766
/* Free the CoW blocks */
17611767
xfs_ilock(ip, XFS_IOLOCK_EXCL);

0 commit comments

Comments
 (0)