Commit 15814082 authored by Dave Chinner's avatar Dave Chinner Committed by Luis Henriques

xfs: inode recovery readahead can race with inode buffer creation

commit b79f4a1c upstream.

When we do inode readahead in log recovery, we do can do the
readahead before we've replayed the icreate transaction that stamps
the buffer with inode cores. The inode readahead verifier catches
this and marks the buffer as !done to indicate that it doesn't yet
contain valid inodes.

In adding buffer error notification  (i.e. setting b_error = -EIO at
the same time as as we clear the done flag) to such a readahead
verifier failure, we can then get subsequent inode recovery failing
with this error:

XFS (dm-0): metadata I/O error: block 0xa00060 ("xlog_recover_do..(read#2)") error 5 numblks 32

This occurs when readahead completion races with icreate item replay
such as:

	inode readahead
		find buffer
		lock buffer
		submit RA io
	....
	icreate recovery
	    xfs_trans_get_buffer
		find buffer
		lock buffer
		<blocks on RA completion>
	.....
	<ra completion>
		fails verifier
		clear XBF_DONE
		set bp->b_error = -EIO
		release and unlock buffer
	<icreate gains lock>
	icreate initialises buffer
	marks buffer as done
	adds buffer to delayed write queue
	releases buffer

At this point, we have an initialised inode buffer that is up to
date but has an -EIO state registered against it. When we finally
get to recovering an inode in that buffer:

	inode item recovery
	    xfs_trans_read_buffer
		find buffer
		lock buffer
		sees XBF_DONE is set, returns buffer
	    sees bp->b_error is set
		fail log recovery!

Essentially, we need xfs_trans_get_buf_map() to clear the error status of
the buffer when doing a lookup. This function returns uninitialised
buffers, so the buffer returned can not be in an error state and
none of the code that uses this function expects b_error to be set
on return. Indeed, there is an ASSERT(!bp->b_error); in the
transaction case in xfs_trans_get_buf_map() that would have caught
this if log recovery used transactions....

This patch firstly changes the inode readahead failure to set -EIO
on the buffer, and secondly changes xfs_buf_get_map() to never
return a buffer with an error state set so this first change doesn't
cause unexpected log recovery failures.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
[ luis: backported to 3.16:
  - file rename: fs/xfs/libxfs/xfs_inode_buf.c -> fs/xfs/xfs_inode_buf.c
  - adjusted context ]
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 5dcdcf49
...@@ -607,6 +607,13 @@ xfs_buf_get_map( ...@@ -607,6 +607,13 @@ xfs_buf_get_map(
} }
} }
/*
* Clear b_error if this is a lookup from a caller that doesn't expect
* valid data to be found in the buffer.
*/
if (!(flags & XBF_READ))
xfs_buf_ioerror(bp, 0);
XFS_STATS_INC(xb_get); XFS_STATS_INC(xb_get);
trace_xfs_buf_get(bp, flags, _RET_IP_); trace_xfs_buf_get(bp, flags, _RET_IP_);
return bp; return bp;
......
...@@ -66,11 +66,12 @@ xfs_inobp_check( ...@@ -66,11 +66,12 @@ xfs_inobp_check(
* has not had the inode cores stamped into it. Hence for readahead, the buffer * has not had the inode cores stamped into it. Hence for readahead, the buffer
* may be potentially invalid. * may be potentially invalid.
* *
* If the readahead buffer is invalid, we don't want to mark it with an error, * If the readahead buffer is invalid, we need to mark it with an error and
* but we do want to clear the DONE status of the buffer so that a followup read * clear the DONE status of the buffer so that a followup read will re-read it
* will re-read it from disk. This will ensure that we don't get an unnecessary * from disk. We don't report the error otherwise to avoid warnings during log
* warnings during log recovery and we don't get unnecssary panics on debug * recovery and we don't get unnecssary panics on debug kernels. We use EIO here
* kernels. * because all we want to do is say readahead failed; there is no-one to report
* the error to, so this will distinguish it from a non-ra verifier failure.
*/ */
static void static void
xfs_inode_buf_verify( xfs_inode_buf_verify(
...@@ -98,6 +99,7 @@ xfs_inode_buf_verify( ...@@ -98,6 +99,7 @@ xfs_inode_buf_verify(
XFS_RANDOM_ITOBP_INOTOBP))) { XFS_RANDOM_ITOBP_INOTOBP))) {
if (readahead) { if (readahead) {
bp->b_flags &= ~XBF_DONE; bp->b_flags &= ~XBF_DONE;
xfs_buf_ioerror(bp, -EIO);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment