]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
xfs: force the log offline when log intent item recovery fails
authorDarrick J. Wong <djwong@kernel.org>
Fri, 29 Jul 2022 16:16:05 +0000 (18:16 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Aug 2022 10:00:51 +0000 (12:00 +0200)
commit 4e6b8270c820c8c57a73f869799a0af2b56eff3e upstream.

If any part of log intent item recovery fails, we should shut down the
log immediately to stop the log from writing a clean unmount record to
disk, because the metadata is not consistent.  The inability to cancel a
dirty transaction catches most of these cases, but there are a few
things that have slipped through the cracks, such as ENOSPC from a
transaction allocation, or runtime errors that result in cancellation of
a non-dirty transaction.

This solves some weird behaviors reported by customers where a system
goes down, the first mount fails, the second succeeds, but then the fs
goes down later because of inconsistent metadata.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/xfs/xfs_log.c
fs/xfs/xfs_log_recover.c

index 05791456adbb5ca96bea2c9adbc9e4b7945b082e..22d7d74231d4221b0511bc9c76a329d233cd5b0a 100644 (file)
@@ -765,6 +765,9 @@ xfs_log_mount_finish(
        if (readonly)
                mp->m_flags |= XFS_MOUNT_RDONLY;
 
+       /* Make sure the log is dead if we're returning failure. */
+       ASSERT(!error || (mp->m_log->l_flags & XLOG_IO_ERROR));
+
        return error;
 }
 
index 87886b7f77dad0aeb51b7cdea4638c05319b612b..69408782019ebbd3560dcbb465bf1751c3d7b0aa 100644 (file)
@@ -2457,8 +2457,10 @@ xlog_finish_defer_ops(
 
                error = xfs_trans_alloc(mp, &resv, dfc->dfc_blkres,
                                dfc->dfc_rtxres, XFS_TRANS_RESERVE, &tp);
-               if (error)
+               if (error) {
+                       xfs_force_shutdown(mp, SHUTDOWN_LOG_IO_ERROR);
                        return error;
+               }
 
                /*
                 * Transfer to this new transaction all the dfops we captured
@@ -3454,6 +3456,7 @@ xlog_recover_finish(
                         * this) before we get around to xfs_log_mount_cancel.
                         */
                        xlog_recover_cancel_intents(log);
+                       xfs_force_shutdown(log->l_mp, SHUTDOWN_LOG_IO_ERROR);
                        xfs_alert(log->l_mp, "Failed to recover intents");
                        return error;
                }