From: Darrick J. Wong <djwong@xxxxxxxxxx> 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 <djwong@xxxxxxxxxx> --- fs/xfs/xfs_file.c | 6 ++++-- fs/xfs/xfs_icache.c | 45 +++++++++++++++++++++++++++++++++++---------- fs/xfs/xfs_icache.h | 1 + fs/xfs/xfs_trace.h | 1 + 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index a318a4749b59..40b12db17a20 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -697,14 +697,16 @@ xfs_file_buffered_aio_write( iolock = 0; } else if (ret == -ENOSPC && !cleared_space) { struct xfs_eofblocks eofb = {0}; + int ret2; cleared_space = true; xfs_flush_inodes(ip->i_mount); xfs_iunlock(ip, iolock); eofb.eof_flags = XFS_EOF_FLAGS_SYNC; - xfs_icache_free_eofblocks(ip->i_mount, &eofb); - xfs_icache_free_cowblocks(ip->i_mount, &eofb); + ret2 = xfs_blockgc_free_space(ip->i_mount, &eofb); + if (ret2) + return ret2; goto write_retry; } diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index 9ba1ad69abb7..acf67384e52f 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -1645,6 +1645,38 @@ xfs_start_block_reaping( xfs_queue_cowblocks(mp); } +/* Scan all incore inodes for block preallocations that we can remove. */ +static inline int +xfs_blockgc_scan( + struct xfs_mount *mp, + struct xfs_eofblocks *eofb) +{ + int error; + + error = xfs_icache_free_eofblocks(mp, eofb); + if (error) + return error; + + error = xfs_icache_free_cowblocks(mp, eofb); + if (error) + return error; + + return 0; +} + +/* + * Try to free space in the filesystem by purging eofblocks and cowblocks. + */ +int +xfs_blockgc_free_space( + struct xfs_mount *mp, + struct xfs_eofblocks *eofb) +{ + trace_xfs_blockgc_free_space(mp, eofb, _RET_IP_); + + return xfs_blockgc_scan(mp, eofb); +} + /* * Run cow/eofblocks scans on the supplied dquots. We don't know exactly which * quota caused an allocation failure, so we make a best effort by including @@ -1661,7 +1693,6 @@ xfs_blockgc_free_dquots( { struct xfs_eofblocks eofb = {0}; struct xfs_mount *mp = NULL; - int error; *found_work = false; @@ -1698,18 +1729,12 @@ xfs_blockgc_free_dquots( *found_work = true; } - if (*found_work) { - error = xfs_icache_free_eofblocks(mp, &eofb); - if (error) - return error; - - error = xfs_icache_free_cowblocks(mp, &eofb); - if (error) - return error; - } + if (*found_work) + return xfs_blockgc_free_space(mp, &eofb); return 0; } + /* * Run cow/eofblocks scans on the quotas applicable to the inode. For inodes * with multiple quotas, we don't know exactly which quota caused an allocation diff --git a/fs/xfs/xfs_icache.h b/fs/xfs/xfs_icache.h index 8d8e7cabc27f..56ae668dcdcf 100644 --- a/fs/xfs/xfs_icache.h +++ b/fs/xfs/xfs_icache.h @@ -59,6 +59,7 @@ int xfs_blockgc_free_dquots(struct xfs_dquot *udqp, struct xfs_dquot *gdqp, bool *found_work); int xfs_blockgc_free_quota(struct xfs_inode *ip, unsigned int eof_flags, bool *found_work); +int xfs_blockgc_free_space(struct xfs_mount *mp, struct xfs_eofblocks *eofb); void xfs_inode_set_eofblocks_tag(struct xfs_inode *ip); void xfs_inode_clear_eofblocks_tag(struct xfs_inode *ip); diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 3f761f33099b..7ec9d4d703a6 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -3926,6 +3926,7 @@ DEFINE_EVENT(xfs_eofblocks_class, name, \ unsigned long caller_ip), \ TP_ARGS(mp, eofb, caller_ip)) DEFINE_EOFBLOCKS_EVENT(xfs_ioc_free_eofblocks); +DEFINE_EOFBLOCKS_EVENT(xfs_blockgc_free_space); #endif /* _TRACE_XFS_H */