All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 3/3] xfs: abort fstrim if kernel is suspending
Date: Thu, 21 Sep 2023 11:39:45 +1000	[thread overview]
Message-ID: <20230921013945.559634-4-david@fromorbit.com> (raw)
In-Reply-To: <20230921013945.559634-1-david@fromorbit.com>

From: Dave Chinner <dchinner@redhat.com>

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>
---
 fs/xfs/xfs_discard.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index f16b254b5eaa..d5787991bb5b 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -283,6 +283,12 @@ xfs_trim_gather_extents(
 	return error;
 }
 
+static bool
+xfs_trim_should_stop(void)
+{
+	return fatal_signal_pending(current) || freezing(current);
+}
+
 /*
  * Iterate the free list gathering extents and discarding them. We need a cursor
  * for the repeated iteration of gather/discard loop, so use the longest extent
@@ -336,10 +342,9 @@ xfs_trim_extents(
 		if (error)
 			break;
 
-		if (fatal_signal_pending(current)) {
-			error = -ERESTARTSYS;
+		if (xfs_trim_should_stop())
 			break;
-		}
+
 	} while (tcur.ar_blockcount != 0);
 
 	return error;
@@ -408,12 +413,12 @@ xfs_ioc_trim(
 	for_each_perag_range(mp, agno, xfs_daddr_to_agno(mp, end), pag) {
 		error = xfs_trim_extents(pag, start, end, minlen,
 					  &blocks_trimmed);
-		if (error) {
+		if (error)
 			last_error = error;
-			if (error == -ERESTARTSYS) {
-				xfs_perag_rele(pag);
-				break;
-			}
+
+		if (xfs_trim_should_stop()) {
+			xfs_perag_rele(pag);
+			break;
 		}
 	}
 
-- 
2.40.1


  parent reply	other threads:[~2023-09-21  1:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21  1:39 [PATCH 0/3] xfs: reduce AGF hold times during fstrim operations Dave Chinner
2023-09-21  1:39 ` [PATCH 1/3] xfs: move log discard work to xfs_discard.c Dave Chinner
2023-09-21 15:52   ` Darrick J. Wong
2023-09-22  1:04     ` Dave Chinner
2023-09-25 15:13       ` Darrick J. Wong
2023-09-21  1:39 ` [PATCH 2/3] xfs: reduce AGF hold times during fstrim operations Dave Chinner
2023-09-21 15:41   ` Darrick J. Wong
2023-09-21  1:39 ` Dave Chinner [this message]
2023-09-21 15:33   ` [PATCH 3/3] xfs: abort fstrim if kernel is suspending Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230921013945.559634-4-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.