All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHSET 0/2] xfs: minor fixes to log recovery problems
@ 2021-06-16 23:55 Darrick J. Wong
  2021-06-16 23:55 ` [PATCH 1/2] xfs: fix log intent recovery ENOSPC shutdowns when inactivating inodes Darrick J. Wong
  2021-06-16 23:55 ` [PATCH 2/2] xfs: force the log offline when log intent item recovery fails Darrick J. Wong
  0 siblings, 2 replies; 5+ messages in thread
From: Darrick J. Wong @ 2021-06-16 23:55 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

Hi all,

This series fixes a couple of bugs that I found in log recovery.  The
first problem is that we don't reserve space for per-AG btree expansion
when we inactivate inodes during log recovery.  If a file with shared
blocks were to be unlinked, this can result in transaction failure
because inactivation assumes that it doesn't need to reserve blocks to
free files and cannot handle a refcount btree expansion.

The second problem addressed here is that if log recovery fails due to
something that doesn't directly impact the log (like ENOSPC during
transaction allocation, or ENOMEM allocating buffers) it will leave the
log running, which means that it writes an unmount record after recovery
fails.  The /next/ mount will see a clean log and start running, even
though the metadata isn't consistent.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=log-recovery-fixes-5.14
---
 fs/xfs/xfs_log.c         |    3 +++
 fs/xfs/xfs_log_recover.c |    5 ++++-
 fs/xfs/xfs_mount.c       |   10 +++++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] xfs: fix log intent recovery ENOSPC shutdowns when inactivating inodes
  2021-06-16 23:55 [PATCHSET 0/2] xfs: minor fixes to log recovery problems Darrick J. Wong
@ 2021-06-16 23:55 ` Darrick J. Wong
  2021-06-17  8:12   ` Christoph Hellwig
  2021-06-16 23:55 ` [PATCH 2/2] xfs: force the log offline when log intent item recovery fails Darrick J. Wong
  1 sibling, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2021-06-16 23:55 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

During regular operation, the xfs_inactive operations create
transactions with zero block reservation because in general we're
freeing space, not asking for more.  The per-AG space reservations
created at mount time enable us to handle expansions of the refcount
btree without needing to reserve blocks to the transaction.

Unfortunately, log recovery doesn't create the per-AG space reservations
when intent items are being recovered.  This isn't an issue for intent
item recovery itself because they explicitly request blocks, but any
inode inactivation that can happen during log recovery uses the same
xfs_inactive paths as regular runtime.  If a refcount btree expansion
happens, the transaction will fail due to blk_res_used > blk_res, and we
shut down the filesystem unnecessarily.

Fix this problem by making per-AG reservations temporarily so that we
can handle the inactivations, and releasing them at the end.  This
brings the recovery environment closer to the runtime environment.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_mount.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)


diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index c3a96fb3ad80..d0755494597f 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -859,9 +859,17 @@ xfs_mountfs(
 	/*
 	 * Finish recovering the file system.  This part needed to be delayed
 	 * until after the root and real-time bitmap inodes were consistently
-	 * read in.
+	 * read in.  Temporarily create per-AG space reservations for metadata
+	 * btree shape changes because space freeing transactions (for inode
+	 * inactivation) require the per-AG reservation in lieu of reserving
+	 * blocks.
 	 */
+	error = xfs_fs_reserve_ag_blocks(mp);
+	if (error && error == -ENOSPC)
+		xfs_warn(mp,
+	"ENOSPC reserving per-AG metadata pool, log recovery may fail.");
 	error = xfs_log_mount_finish(mp);
+	xfs_fs_unreserve_ag_blocks(mp);
 	if (error) {
 		xfs_warn(mp, "log mount finish failed");
 		goto out_rtunmount;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] xfs: force the log offline when log intent item recovery fails
  2021-06-16 23:55 [PATCHSET 0/2] xfs: minor fixes to log recovery problems Darrick J. Wong
  2021-06-16 23:55 ` [PATCH 1/2] xfs: fix log intent recovery ENOSPC shutdowns when inactivating inodes Darrick J. Wong
@ 2021-06-16 23:55 ` Darrick J. Wong
  2021-06-17  8:14   ` Christoph Hellwig
  1 sibling, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2021-06-16 23:55 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

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>
---
 fs/xfs/xfs_log.c         |    3 +++
 fs/xfs/xfs_log_recover.c |    5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)


diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index e921b554b683..f945df46c7e1 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -776,6 +776,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;
 }
 
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 1227503d2246..1721fce2ec94 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -2458,8 +2458,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
@@ -3449,6 +3451,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;
 		}


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] xfs: fix log intent recovery ENOSPC shutdowns when inactivating inodes
  2021-06-16 23:55 ` [PATCH 1/2] xfs: fix log intent recovery ENOSPC shutdowns when inactivating inodes Darrick J. Wong
@ 2021-06-17  8:12   ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-06-17  8:12 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] xfs: force the log offline when log intent item recovery fails
  2021-06-16 23:55 ` [PATCH 2/2] xfs: force the log offline when log intent item recovery fails Darrick J. Wong
@ 2021-06-17  8:14   ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-06-17  8:14 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Wed, Jun 16, 2021 at 04:55:49PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> 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>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-17  8:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16 23:55 [PATCHSET 0/2] xfs: minor fixes to log recovery problems Darrick J. Wong
2021-06-16 23:55 ` [PATCH 1/2] xfs: fix log intent recovery ENOSPC shutdowns when inactivating inodes Darrick J. Wong
2021-06-17  8:12   ` Christoph Hellwig
2021-06-16 23:55 ` [PATCH 2/2] xfs: force the log offline when log intent item recovery fails Darrick J. Wong
2021-06-17  8:14   ` Christoph Hellwig

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.