Skip to contentSkip to conversation

xfs: Fix oops on IO error during xlog_recover_process_iunlinks()

PATCH Superseded Jan Kara 2 participants 3 messages Mar 6, 2012 – Mar 7, 2012 XFS filesystem

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 xfs: Fix oops on IO error during xlog_recover_process_iunlinks()

When an IO error happens during inode deletion run from xlog_recover_process_iunlinks() filesystem gets shutdown. Thus any subsequent attempt to read buffers fails. Code in xlog_recover_process_iunlinks() does not count with the fact that read of a buffer which was read a while ago can really fail which results in the oops on
agi = XFS_BUF_TO_AGI(agibp);

Fix the problem by handling error from xfs_read_agi() in all cases.

---
 fs/xfs/xfs_log_recover.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
fs/xfs/xfs_log_recover.c +12 -3
index 0ed9ee7..3899264 100644
@@ -3178,11 +3178,17 @@ xlog_recover_process_iunlinks(
 
 				/*
 				 * Reacquire the agibuffer and continue around
-				 * the loop. This should never fail as we know
-				 * the buffer was good earlier on.
+				 * the loop.
 				 */
 				error = xfs_read_agi(mp, NULL, agno, &agibp);
-				ASSERT(error == 0);
+				/*
+				 * We failed to read a buffer we succeeded
+				 * reading just a while ago. Likely because the
+				 * filesystem is shutdown now. Just try the
+				 * next AG.
+				 */
+				if (error)
+					goto next_ag;
 				agi = XFS_BUF_TO_AGI(agibp);
 			}
 		}
@@ -3192,6 +3198,9 @@ xlog_recover_process_iunlinks(
 		 * go on to the next one.
 		 */
 		xfs_buf_relse(agibp);
+next_ag:
+		/* Hrm... C9x seems to require this */
+		;
 	}
 
 	mp->m_dmevmask = mp_dmevmask;
Signature · 6 lines
1.7.1

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 29 lines · Jan Kara

When an IO error happens during inode deletion run from xlog_recover_process_iunlinks() filesystem gets shutdown. Thus any subsequent attempt to read buffers fails. Code in xlog_recover_process_iunlinks() does not count with the fact that read of a buffer which was read a while ago can really fail which results in the oops on
agi = XFS_BUF_TO_AGI(agibp);

Fix the problem by handling error from xfs_read_agi() in all cases.

---
 fs/xfs/xfs_log_recover.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
fs/xfs/xfs_log_recover.c +2 -3
index 0ed9ee7..3899264 100644
@@ -3178,11 +3178,17 @@ xlog_recover_process_iunlinks(
 
 				/*
 				 * Reacquire the agibuffer and continue around
-				 * the loop. This should never fail as we know
-				 * the buffer was good earlier on.
+				 * the loop.
 				 */
 				error = xfs_read_agi(mp, NULL, agno, &agibp);
-				ASSERT(error == 0);
+				/*

fs/xfs/xfs_log_recover.c xlog_recover_process_iunlinks( · line 3194

Quoted 10 lines
fs/xfs/xfs_log_recover.c +7 -0
+				 * We failed to read a buffer we succeeded
+				 * reading just a while ago. Likely because the
+				 * filesystem is shutdown now. Just try the
+				 * next AG.
+				 */
+				if (error)
+					goto next_ag;
 				agi = XFS_BUF_TO_AGI(agibp);
 			}
 		}

That function is full of ugly code. We don't need to continually lock and unlock the AGI in the inner loop. Indeed, we probably don't even need to lock the buffer to read the AGI bucket entries because we aren't going to be racing with anyone here. Hence all we really need is an extra hold on the agi buffer to make sure it doesn't go away once we've dropped the lock via xfs_buf_relse(). i.e.

	/*
	 * take an extra reference to the buffer and then release it
	 * to drop the lock so that it can be acquired in the normal
	 * course of the transaction to truncate and free each
	 * inode.  Because we are not racing with anyone else here
	 * for the AGI buffer, we don't even need to hold it locked
	 * to read the initial unlinked bucket entries out of the
	 * buffer.
	 */
	agi = XFS_BUF_TO_AGI(agibp);
	xfs_buf_hold(agibp);
	xfs_buf_relse(agibp);
	for (bucket = 0; bucket < XFS_AGI_UNLINKED_BUCKETS; bucket++) {
		agino = be32_to_cpu(agi->agi_unlinked[bucket]);
		while (agino != NULLAGINO) {
			agino = xlog_recover_process_one_iunlink(mp,
					agno, agino, bucket);
		}
	}
	xfs_buf_rele(agibp)

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#2 lore raw
Quoted 61 lines · Dave Chinner
Quoted 29 lines · Jan Kara

When an IO error happens during inode deletion run from xlog_recover_process_iunlinks() filesystem gets shutdown. Thus any subsequent attempt to read buffers fails. Code in xlog_recover_process_iunlinks() does not count with the fact that read of a buffer which was read a while ago can really fail which results in the oops on
agi = XFS_BUF_TO_AGI(agibp);

Fix the problem by handling error from xfs_read_agi() in all cases.

---
 fs/xfs/xfs_log_recover.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
fs/xfs/xfs_log_recover.c +2 -3
index 0ed9ee7..3899264 100644
@@ -3178,11 +3178,17 @@ xlog_recover_process_iunlinks(
 
 				/*
 				 * Reacquire the agibuffer and continue around
-				 * the loop. This should never fail as we know
-				 * the buffer was good earlier on.
+				 * the loop.
 				 */
 				error = xfs_read_agi(mp, NULL, agno, &agibp);
-				ASSERT(error == 0);
+				/*

fs/xfs/xfs_log_recover.c xlog_recover_process_iunlinks( · line 3194

Quoted 10 lines
fs/xfs/xfs_log_recover.c +7 -0
+				 * We failed to read a buffer we succeeded
+				 * reading just a while ago. Likely because the
+				 * filesystem is shutdown now. Just try the
+				 * next AG.
+				 */
+				if (error)
+					goto next_ag;
 				agi = XFS_BUF_TO_AGI(agibp);
 			}
 		}

That function is full of ugly code. We don't need to continually lock and unlock the AGI in the inner loop. Indeed, we probably don't even need to lock the buffer to read the AGI bucket entries because we aren't going to be racing with anyone here. Hence all we really need is an extra hold on the agi buffer to make sure it doesn't go away once we've dropped the lock via xfs_buf_relse(). i.e.

	/*
	 * take an extra reference to the buffer and then release it
	 * to drop the lock so that it can be acquired in the normal
	 * course of the transaction to truncate and free each
	 * inode.  Because we are not racing with anyone else here
	 * for the AGI buffer, we don't even need to hold it locked
	 * to read the initial unlinked bucket entries out of the
	 * buffer.
	 */
	agi = XFS_BUF_TO_AGI(agibp);
	xfs_buf_hold(agibp);
	xfs_buf_relse(agibp);
Quoted 8 lines
	for (bucket = 0; bucket < XFS_AGI_UNLINKED_BUCKETS; bucket++) {
		agino = be32_to_cpu(agi->agi_unlinked[bucket]);
		while (agino != NULLAGINO) {
			agino = xlog_recover_process_one_iunlink(mp,
					agno, agino, bucket);
		}
	}
	xfs_buf_rele(agibp)

Thanks for review Dave. So something like attached patch?

Honza

Quoted 1 line

From 276d5ecac71d9e6ec6ac970e594f5a49450d07e2 Mon Sep 17 00:00:00 2001

From: Jan Kara <[email protected]>
Date: Tue, 6 Mar 2012 11:39:48 +0100
Subject: [PATCH v2] xfs: Fix oops on IO error during xlog_recover_process_iunlinks()

When an IO error happens during inode deletion run from xlog_recover_process_iunlinks() filesystem gets shutdown. Thus any subsequent attempt to read buffers fails. Code in xlog_recover_process_iunlinks() does not count with the fact that read of a buffer which was read a while ago can really fail which results in the oops on
agi = XFS_BUF_TO_AGI(agibp);

Fix the problem by cleaning up the buffer handling in xlog_recover_process_iunlinks(). We release buffer lock but keep buffer reference to AG buffer. That is enough for buffer to not go away under us and we don't have to call xfs_read_agi() all the time.

---
 fs/xfs/xfs_log_recover.c |   34 ++++++++++++----------------------
 1 files changed, 12 insertions(+), 22 deletions(-)
fs/xfs/xfs_log_recover.c +12 -22
index 0ed9ee7..0827644 100644
@@ -3161,37 +3161,27 @@ xlog_recover_process_iunlinks(
 			 */
 			continue;
 		}
+		/*
+		 * Take an extra reference to the buffer and then release it
+		 * to drop the lock so that it can be acquired in the normal
+		 * course of the transaction to truncate and free each
+		 * inode.  Because we are not racing with anyone else here
+		 * for the AGI buffer, we don't even need to hold it locked
+		 * to read the initial unlinked bucket entries out of the
+		 * buffer.
+		 */
 		agi = XFS_BUF_TO_AGI(agibp);
+		xfs_buf_hold(agibp);
+		xfs_buf_relse(agibp);
 
 		for (bucket = 0; bucket < XFS_AGI_UNLINKED_BUCKETS; bucket++) {
 			agino = be32_to_cpu(agi->agi_unlinked[bucket]);
 			while (agino != NULLAGINO) {
-				/*
-				 * Release the agi buffer so that it can
-				 * be acquired in the normal course of the
-				 * transaction to truncate and free the inode.
-				 */
-				xfs_buf_relse(agibp);
-
 				agino = xlog_recover_process_one_iunlink(mp,
 							agno, agino, bucket);
-
-				/*
-				 * Reacquire the agibuffer and continue around
-				 * the loop. This should never fail as we know
-				 * the buffer was good earlier on.
-				 */
-				error = xfs_read_agi(mp, NULL, agno, &agibp);
-				ASSERT(error == 0);
-				agi = XFS_BUF_TO_AGI(agibp);
 			}
 		}
-
-		/*
-		 * Release the buffer for the current agi so we can
-		 * go on to the next one.
-		 */
-		xfs_buf_relse(agibp);
+		xfs_buf_rele(agibp);
 	}
 
 	mp->m_dmevmask = mp_dmevmask;
Signature · 1 line
1.7.1

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs