public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Long Li <leo.lilong@huawei.com>
To: <djwong@kernel.org>
Cc: <david@fromorbit.com>, <linux-xfs@vger.kernel.org>,
	<houtao1@huawei.com>, <yi.zhang@huawei.com>,
	<guoxuenan@huawei.com>
Subject: [PATCH] xfs: xfs_trans_cancel() path must check for log shutdown
Date: Wed, 24 May 2023 20:11:21 +0800	[thread overview]
Message-ID: <20230524121121.GA4130562@ceph-admin> (raw)

The following error occurred when do IO fault injection test:

XFS: Assertion failed: xlog_is_shutdown(lip->li_log), file: fs/xfs/xfs_inode_item.c, line: 748

In commit 3c4cb76bce43 (xfs: xfs_trans_commit() path must check for log
shutdown) fix a problem that dirty transaction was canceled before log
shutdown, because of the log is still running, it result dirty and
unlogged inode item that isn't in the AIL in memory that can be flushed
to disk via writeback clustering.

xfs_trans_cancel() has the same problem, if a shut down races with
xfs_trans_cancel() and we have shut down the filesystem but not the log,
we will still cancel the transaction before log shutdown. So
xfs_trans_cancel() needs to check log state for shutdown, not mount.

Signed-off-by: Long Li <leo.lilong@huawei.com>
---
 fs/xfs/xfs_trans.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 8afc0c080861..033991854d4f 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -1059,11 +1059,9 @@ xfs_trans_commit(
  *
  * This is a high level function (equivalent to xfs_trans_commit()) and so can
  * be called after the transaction has effectively been aborted due to the mount
- * being shut down. However, if the mount has not been shut down and the
+ * being shut down. However, if the log has not been shut down and the
  * transaction is dirty we will shut the mount down and, in doing so, that
- * guarantees that the log is shut down, too. Hence we don't need to be as
- * careful with shutdown state and dirty items here as we need to be in
- * xfs_trans_commit().
+ * guarantees that the log is shut down.
  */
 void
 xfs_trans_cancel(
@@ -1089,11 +1087,12 @@ xfs_trans_cancel(
 
 	/*
 	 * See if the caller is relying on us to shut down the filesystem. We
-	 * only want an error report if there isn't already a shutdown in
-	 * progress, so we only need to check against the mount shutdown state
-	 * here.
+	 * only want an error report if there isn't already a log shutdown. We
+	 * must check against log shutdown here because we cannot abort log and
+	 * leave them dirty, inconsistent and unpinned in memory while the log
+	 * is active, as we needed in xfs_trans_commit().
 	 */
-	if (dirty && !xfs_is_shutdown(mp)) {
+	if (dirty && !xlog_is_shutdown(log)) {
 		XFS_ERROR_REPORT("xfs_trans_cancel", XFS_ERRLEVEL_LOW, mp);
 		xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
 	}
-- 
2.31.1


             reply	other threads:[~2023-05-24 12:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24 12:11 Long Li [this message]
2023-05-25  0:47 ` [PATCH] xfs: xfs_trans_cancel() path must check for log shutdown Dave Chinner
2023-05-27  9:30   ` Long Li
2023-06-01  8:02   ` Long Li

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=20230524121121.GA4130562@ceph-admin \
    --to=leo.lilong@huawei.com \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=guoxuenan@huawei.com \
    --cc=houtao1@huawei.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=yi.zhang@huawei.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox