@@ -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;
}
@@ -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
@@ -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);
@@ -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 */