diff options
author | Dave Chinner <dchinner@redhat.com> | 2014-10-01 19:04:31 -0400 |
---|---|---|
committer | Dave Chinner <david@fromorbit.com> | 2014-10-01 19:04:31 -0400 |
commit | 61be9c529a4a715ab8679e9ca82bc3790c7ab66c (patch) | |
tree | 3e8d1c757133eb7c844cd4ba8815f4a6bc0218cb | |
parent | e8aaba9a783c8e5d2c58ebe69650ea31b91bb745 (diff) |
xfs: rework xfs_buf_bio_endio error handling
Currently the report of a bio error from completion
immediately marks the buffer with an error. The issue is that this
is racy w.r.t. synchronous IO - the submitter can see b_error being
set before the IO is complete, and hence we cannot differentiate
between submission failures and completion failures.
Add an internal b_io_error field protected by the b_lock to catch IO
completion errors, and only propagate that to the buffer during
final IO completion handling. Hence we can tell in xfs_buf_iorequest
if we've had a submission failure bey checking bp->b_error before
dropping our b_io_remaining reference - that reference will prevent
b_io_error values from being propagated to b_error in the event that
completion races with submission.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
-rw-r--r-- | fs/xfs/xfs_buf.c | 18 | ||||
-rw-r--r-- | fs/xfs/xfs_buf.h | 1 |
2 files changed, 17 insertions, 2 deletions
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index a046149e6099..170d6c0afe71 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c | |||
@@ -1008,6 +1008,13 @@ xfs_buf_ioend( | |||
1008 | 1008 | ||
1009 | bp->b_flags &= ~(XBF_READ | XBF_WRITE | XBF_READ_AHEAD); | 1009 | bp->b_flags &= ~(XBF_READ | XBF_WRITE | XBF_READ_AHEAD); |
1010 | 1010 | ||
1011 | /* | ||
1012 | * Pull in IO completion errors now. We are guaranteed to be running | ||
1013 | * single threaded, so we don't need the lock to read b_io_error. | ||
1014 | */ | ||
1015 | if (!bp->b_error && bp->b_io_error) | ||
1016 | xfs_buf_ioerror(bp, bp->b_io_error); | ||
1017 | |||
1011 | /* Only validate buffers that were read without errors */ | 1018 | /* Only validate buffers that were read without errors */ |
1012 | if (read && !bp->b_error && bp->b_ops) { | 1019 | if (read && !bp->b_error && bp->b_ops) { |
1013 | ASSERT(!bp->b_iodone); | 1020 | ASSERT(!bp->b_iodone); |
@@ -1192,8 +1199,12 @@ xfs_buf_bio_end_io( | |||
1192 | * don't overwrite existing errors - otherwise we can lose errors on | 1199 | * don't overwrite existing errors - otherwise we can lose errors on |
1193 | * buffers that require multiple bios to complete. | 1200 | * buffers that require multiple bios to complete. |
1194 | */ | 1201 | */ |
1195 | if (!bp->b_error) | 1202 | if (error) { |
1196 | xfs_buf_ioerror(bp, error); | 1203 | spin_lock(&bp->b_lock); |
1204 | if (!bp->b_io_error) | ||
1205 | bp->b_io_error = error; | ||
1206 | spin_unlock(&bp->b_lock); | ||
1207 | } | ||
1197 | 1208 | ||
1198 | if (!bp->b_error && xfs_buf_is_vmapped(bp) && (bp->b_flags & XBF_READ)) | 1209 | if (!bp->b_error && xfs_buf_is_vmapped(bp) && (bp->b_flags & XBF_READ)) |
1199 | invalidate_kernel_vmap_range(bp->b_addr, xfs_buf_vmap_len(bp)); | 1210 | invalidate_kernel_vmap_range(bp->b_addr, xfs_buf_vmap_len(bp)); |
@@ -1379,6 +1390,9 @@ xfs_buf_iorequest( | |||
1379 | if (bp->b_flags & XBF_WRITE) | 1390 | if (bp->b_flags & XBF_WRITE) |
1380 | xfs_buf_wait_unpin(bp); | 1391 | xfs_buf_wait_unpin(bp); |
1381 | 1392 | ||
1393 | /* clear the internal error state to avoid spurious errors */ | ||
1394 | bp->b_io_error = 0; | ||
1395 | |||
1382 | /* | 1396 | /* |
1383 | * Take references to the buffer. For XBF_ASYNC buffers, holding a | 1397 | * Take references to the buffer. For XBF_ASYNC buffers, holding a |
1384 | * reference for as long as submission takes is all that is necessary | 1398 | * reference for as long as submission takes is all that is necessary |
diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index 4585c1595a98..44db8cd67bda 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h | |||
@@ -158,6 +158,7 @@ typedef struct xfs_buf { | |||
158 | struct list_head b_lru; /* lru list */ | 158 | struct list_head b_lru; /* lru list */ |
159 | spinlock_t b_lock; /* internal state lock */ | 159 | spinlock_t b_lock; /* internal state lock */ |
160 | unsigned int b_state; /* internal state flags */ | 160 | unsigned int b_state; /* internal state flags */ |
161 | int b_io_error; /* internal IO error state */ | ||
161 | wait_queue_head_t b_waiters; /* unpin waiters */ | 162 | wait_queue_head_t b_waiters; /* unpin waiters */ |
162 | struct list_head b_list; | 163 | struct list_head b_list; |
163 | struct xfs_perag *b_pag; /* contains rbtree root */ | 164 | struct xfs_perag *b_pag; /* contains rbtree root */ |