Skip to content

Commit 85c5b27

Browse files
author
Darrick J. Wong
committed
xfs: refactor xfs_icache_free_{eof,cow}blocks call sites
In anticipation of more restructuring of the eof/cowblocks gc code, refactor calling of those two functions into a single internal helper function, then present a new standard interface to purge speculative block preallocations and start shifting higher level code to use that. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Brian Foster <[email protected]>
1 parent 38899f8 commit 85c5b27

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

fs/xfs/xfs_file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ xfs_file_buffered_aio_write(
718718

719719
xfs_iunlock(ip, iolock);
720720
eofb.eof_flags = XFS_EOF_FLAGS_SYNC;
721-
xfs_icache_free_eofblocks(ip->i_mount, &eofb);
722-
xfs_icache_free_cowblocks(ip->i_mount, &eofb);
721+
xfs_blockgc_free_space(ip->i_mount, &eofb);
723722
goto write_retry;
724723
}
725724

fs/xfs/xfs_icache.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,38 @@ xfs_start_block_reaping(
16451645
xfs_queue_cowblocks(mp);
16461646
}
16471647

1648+
/* Scan all incore inodes for block preallocations that we can remove. */
1649+
static inline int
1650+
xfs_blockgc_scan(
1651+
struct xfs_mount *mp,
1652+
struct xfs_eofblocks *eofb)
1653+
{
1654+
int error;
1655+
1656+
error = xfs_icache_free_eofblocks(mp, eofb);
1657+
if (error)
1658+
return error;
1659+
1660+
error = xfs_icache_free_cowblocks(mp, eofb);
1661+
if (error)
1662+
return error;
1663+
1664+
return 0;
1665+
}
1666+
1667+
/*
1668+
* Try to free space in the filesystem by purging eofblocks and cowblocks.
1669+
*/
1670+
int
1671+
xfs_blockgc_free_space(
1672+
struct xfs_mount *mp,
1673+
struct xfs_eofblocks *eofb)
1674+
{
1675+
trace_xfs_blockgc_free_space(mp, eofb, _RET_IP_);
1676+
1677+
return xfs_blockgc_scan(mp, eofb);
1678+
}
1679+
16481680
/*
16491681
* Run cow/eofblocks scans on the supplied dquots. We don't know exactly which
16501682
* quota caused an allocation failure, so we make a best effort by including
@@ -1665,7 +1697,6 @@ xfs_blockgc_free_dquots(
16651697
{
16661698
struct xfs_eofblocks eofb = {0};
16671699
bool do_work = false;
1668-
int error;
16691700

16701701
if (!udqp && !gdqp && !pdqp)
16711702
return 0;
@@ -1697,11 +1728,7 @@ xfs_blockgc_free_dquots(
16971728
if (!do_work)
16981729
return 0;
16991730

1700-
error = xfs_icache_free_eofblocks(mp, &eofb);
1701-
if (error)
1702-
return error;
1703-
1704-
return xfs_icache_free_cowblocks(mp, &eofb);
1731+
return xfs_blockgc_free_space(mp, &eofb);
17051732
}
17061733

17071734
/* Run cow/eofblocks scans on the quotas attached to the inode. */

fs/xfs/xfs_icache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ int xfs_blockgc_free_dquots(struct xfs_mount *mp, struct xfs_dquot *udqp,
5858
struct xfs_dquot *gdqp, struct xfs_dquot *pdqp,
5959
unsigned int eof_flags);
6060
int xfs_blockgc_free_quota(struct xfs_inode *ip, unsigned int eof_flags);
61+
int xfs_blockgc_free_space(struct xfs_mount *mp, struct xfs_eofblocks *eofb);
6162

6263
void xfs_inode_set_eofblocks_tag(struct xfs_inode *ip);
6364
void xfs_inode_clear_eofblocks_tag(struct xfs_inode *ip);

fs/xfs/xfs_trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3928,6 +3928,7 @@ DEFINE_EVENT(xfs_eofblocks_class, name, \
39283928
unsigned long caller_ip), \
39293929
TP_ARGS(mp, eofb, caller_ip))
39303930
DEFINE_EOFBLOCKS_EVENT(xfs_ioc_free_eofblocks);
3931+
DEFINE_EOFBLOCKS_EVENT(xfs_blockgc_free_space);
39313932

39323933
#endif /* _TRACE_XFS_H */
39333934

0 commit comments

Comments
 (0)