Skip to content

Commit e78a40b

Browse files
Dave Chinnerdchinner
authored andcommitted
xfs: abort fstrim if kernel is suspending
A recent ext4 patch posting from Jan Kara reminded me of a discussion a year ago about fstrim in progress preventing kernels from suspending. The fix is simple, we should do the same for XFS. This removes the -ERESTARTSYS error return from this code, replacing it with either the last error seen or the number of blocks successfully trimmed up to the point where we detected the stop condition. References: https://bugzilla.kernel.org/show_bug.cgi?id=216322 Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
1 parent 89cfa89 commit e78a40b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

fs/xfs/xfs_discard.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ xfs_trim_gather_extents(
283283
return error;
284284
}
285285

286+
static bool
287+
xfs_trim_should_stop(void)
288+
{
289+
return fatal_signal_pending(current) || freezing(current);
290+
}
291+
286292
/*
287293
* Iterate the free list gathering extents and discarding them. We need a cursor
288294
* for the repeated iteration of gather/discard loop, so use the longest extent
@@ -336,10 +342,9 @@ xfs_trim_extents(
336342
if (error)
337343
break;
338344

339-
if (fatal_signal_pending(current)) {
340-
error = -ERESTARTSYS;
345+
if (xfs_trim_should_stop())
341346
break;
342-
}
347+
343348
} while (tcur.ar_blockcount != 0);
344349

345350
return error;
@@ -408,12 +413,12 @@ xfs_ioc_trim(
408413
for_each_perag_range(mp, agno, xfs_daddr_to_agno(mp, end), pag) {
409414
error = xfs_trim_extents(pag, start, end, minlen,
410415
&blocks_trimmed);
411-
if (error) {
416+
if (error)
412417
last_error = error;
413-
if (error == -ERESTARTSYS) {
414-
xfs_perag_rele(pag);
415-
break;
416-
}
418+
419+
if (xfs_trim_should_stop()) {
420+
xfs_perag_rele(pag);
421+
break;
417422
}
418423
}
419424

0 commit comments

Comments
 (0)