Skip to content

Commit 87e6346

Browse files
Ravi Singhcmaiolino
authored andcommitted
xfs: flush delalloc blocks on ENOSPC in xfs_trans_alloc_icreate
xfs_trans_alloc_icreate() can fail with ENOSPC when delalloc reservations have consumed most of the available block count (fdblocks). xfs_trans_alloc() already retries internally with xfs_blockgc_flush_all(), but that only trims post-EOF speculative preallocation and may not free enough space for the transaction reservation. Add a retry with xfs_flush_inodes() when xfs_trans_alloc() returns ENOSPC. This forces writeback of all dirty inodes via sync_inodes_sb(), converting delalloc reservations to real allocations and freeing the over-reserved portion back to fdblocks. This fixes all callers of xfs_trans_alloc_icreate() and removes the existing caller-level retry from xfs_create(), which is now handled centrally. Signed-off-by: Ravi Singh <ravising@redhat.com> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent fca20fc commit 87e6346

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

fs/xfs/xfs_inode.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -699,12 +699,6 @@ xfs_create(
699699
*/
700700
error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp, resblks,
701701
&tp);
702-
if (error == -ENOSPC) {
703-
/* flush outstanding delalloc blocks and retry */
704-
xfs_flush_inodes(mp);
705-
error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp,
706-
resblks, &tp);
707-
}
708702
if (error)
709703
goto out_parent;
710704

fs/xfs/xfs_trans.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,10 +1199,21 @@ xfs_trans_alloc_icreate(
11991199
{
12001200
struct xfs_trans *tp;
12011201
bool retried = false;
1202+
bool flushed = false;
12021203
int error;
12031204

12041205
retry:
12051206
error = xfs_trans_alloc(mp, resv, dblocks, 0, 0, &tp);
1207+
if (error == -ENOSPC && !flushed) {
1208+
/*
1209+
* Flush all delalloc blocks to reclaim space from speculative
1210+
* preallocation. This is similar to the quota retry below
1211+
* but targets FS-wide ENOSPC.
1212+
*/
1213+
xfs_flush_inodes(mp);
1214+
flushed = true;
1215+
goto retry;
1216+
}
12061217
if (error)
12071218
return error;
12081219

0 commit comments

Comments
 (0)