xfs_buf_submit error handling fix v2
Hi all,
currently xfs_buf_submit can execute the endio handling twice when failing for a synchronous submission. This series refactors the surrounding code a bit to allow for a non-hacky fix and then applies that.
Changes since v1:
- fix a commit message typo
Diffstat:
xfs_buf.c | 86 ++++++++++++++++++++++++++++----------------------------- xfs_buf.h | 2 - xfs_buf_item.c | 3 - xfs_inode.c | 3 - 4 files changed, 46 insertions(+), 48 deletions(-)
PATCH 1/6 xfs: open code xfs_buf_ioend_fail in xfs_buf_submit
This better integrates with the other failure handling in xfs_buf_submit, and prepares for a better API in xfs_buf_ioend_fail.
--- fs/xfs/xfs_buf.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
fs/xfs/xfs_buf.c +13 -10
@@ -1383,10 +1383,8 @@ xfs_buf_submit(* state here rather than mount state to avoid corrupting the log tail * on shutdown. */ -if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) { -xfs_buf_ioend_fail (bp); -return ; - } +if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) + goto ioerror;if (bp->b_flags &XBF_WRITE )xfs_buf_wait_unpin (bp);
@@ -1399,17 +1397,22 @@ xfs_buf_submit(if ((bp->b_flags &XBF_WRITE ) && !xfs_buf_verify_write (bp)) {xfs_force_shutdown (bp->b_mount,SHUTDOWN_CORRUPT_INCORE ); -xfs_buf_ioend (bp); -return ; + goto end_io; }/* In-memory targets are directly mapped, no I/O required. */ -if (xfs_buftarg_is_mem (bp->b_target)) { -xfs_buf_ioend (bp); -return ; - } +if (xfs_buftarg_is_mem (bp->b_target)) + goto end_io;xfs_buf_submit_bio (bp); +return ; + +ioerror: + bp->b_flags &= ~XBF_DONE ; +xfs_buf_stale (bp); +xfs_buf_ioerror (bp, -EIO ); +end_io: +xfs_buf_ioend (bp); }/*
Signature · 1 line
2.53.0
PATCH 2/6 xfs: also mark the buffer stale on verifier failure in xfs_buf_submit
In reply to Christoph HellwigWe should treat the buffer that caused a shutdown the same as handling buffers after a shutdown, so use the same stale && !DONE logic here.
--- fs/xfs/xfs_buf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/xfs/xfs_buf.c +4 -3
@@ -1383,8 +1383,10 @@ xfs_buf_submit(* state here rather than mount state to avoid corrupting the log tail * on shutdown. */ -if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) +if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) { +xfs_buf_ioerror (bp, -EIO ); goto ioerror; + }if (bp->b_flags &XBF_WRITE )xfs_buf_wait_unpin (bp);
@@ -1397,7 +1399,7 @@ xfs_buf_submit(if ((bp->b_flags &XBF_WRITE ) && !xfs_buf_verify_write (bp)) {xfs_force_shutdown (bp->b_mount,SHUTDOWN_CORRUPT_INCORE ); - goto end_io; + goto ioerror; }/* In-memory targets are directly mapped, no I/O required. */
@@ -1410,7 +1412,6 @@ xfs_buf_submit( ioerror: bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp); -xfs_buf_ioerror (bp, -EIO ); end_io:xfs_buf_ioend (bp); }
Signature · 1 line
2.53.0
Re: [PATCH 2/6] xfs: also mark the buffer stale on verifier failure in xfs_buf_submit
Quoted 14 lines · Christoph Hellwig
We should treat the buffer that caused a shutdown the same as handling buffers after a shutdown, so use the same stale && !DONE logic here.
Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Carlos Maiolino <[email protected]>--- fs/xfs/xfs_buf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/xfs/xfs_buf.c +0
-0
fs/xfs/xfs_buf.c xfs_buf_submit( · line 1388
Quoted 7 lines
fs/xfs/xfs_buf.c +2
-1@@ -1383,8 +1383,10 @@ xfs_buf_submit(* state here rather than mount state to avoid corrupting the log tail * on shutdown. */ -if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) +if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) { +xfs_buf_ioerror (bp, -EIO ); goto ioerror;
IDGI. If the filesystem was already shut down, we set EIO on the buffer, stale it, and complete the ioend...
fs/xfs/xfs_buf.c xfs_buf_submit( · line 1402
Quoted 10 lines
fs/xfs/xfs_buf.c +2
-1+ }if (bp->b_flags &XBF_WRITE )xfs_buf_wait_unpin (bp);@@ -1397,7 +1399,7 @@ xfs_buf_submit(if ((bp->b_flags &XBF_WRITE ) && !xfs_buf_verify_write (bp)) {xfs_force_shutdown (bp->b_mount,SHUTDOWN_CORRUPT_INCORE ); - goto end_io; + goto ioerror;
...but if bp itself causes the shutdown, we now leave b_error at 0, but do the same stale-and-complete thing? Shouldn't we set EIO on the buffer in both cases?
--D
Quoted 15 lines
fs/xfs/xfs_buf.c +0
-1}/* In-memory targets are directly mapped, no I/O required. */ @@ -1410,7 +1412,6 @@ xfs_buf_submit( ioerror: bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp); -xfs_buf_ioerror (bp, -EIO ); end_io:xfs_buf_ioend (bp); }Signature · 1 line
2.53.0
Re: [PATCH 2/6] xfs: also mark the buffer stale on verifier failure in xfs_buf_submit
Quoted 14 lines · Darrick J. Wong
fs/xfs/xfs_buf.c xfs_buf_submit( · line 1388
Quoted 4 lines
fs/xfs/xfs_buf.c +2
-1-if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) +if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) { +xfs_buf_ioerror (bp, -EIO ); goto ioerror;IDGI. If the filesystem was already shut down, we set EIO on the buffer, stale it, and complete the ioend...
Quoted 6 lines
fs/xfs/xfs_buf.c +1
-0+ }if (bp->b_flags &XBF_WRITE )xfs_buf_wait_unpin (bp);@@ -1397,7 +1399,7 @@ xfs_buf_submit(
Quoted 8 lines
fs/xfs/xfs_buf.c xfs_buf_submit( · line 1402
Quoted 4 lines
fs/xfs/xfs_buf.c +1
-1if ((bp->b_flags &XBF_WRITE ) && !xfs_buf_verify_write (bp)) {xfs_force_shutdown (bp->b_mount,SHUTDOWN_CORRUPT_INCORE ); - goto end_io; + goto ioerror;...but if bp itself causes the shutdown, we now leave
b_errorat 0, but do the same stale-and-complete thing? Shouldn't we set EIO on the buffer in both cases?
->verify_write is expected to set b_error when it fails (and yes, the API in that area is awful).
Re: [PATCH 2/6] xfs: also mark the buffer stale on verifier failure in xfs_buf_submit
Quoted 24 lines · Christoph Hellwig
Quoted 14 lines · Darrick J. Wong
fs/xfs/xfs_buf.c xfs_buf_submit( · line 1388
Quoted 4 lines
fs/xfs/xfs_buf.c +2
-1-if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) +if (bp->b_mount->m_log &&xlog_is_shutdown (bp->b_mount->m_log)) { +xfs_buf_ioerror (bp, -EIO ); goto ioerror;IDGI. If the filesystem was already shut down, we set EIO on the buffer, stale it, and complete the ioend...
Quoted 6 lines
fs/xfs/xfs_buf.c +1
-0+ }if (bp->b_flags &XBF_WRITE )xfs_buf_wait_unpin (bp);@@ -1397,7 +1399,7 @@ xfs_buf_submit(Quoted 8 lines
fs/xfs/xfs_buf.c xfs_buf_submit( · line 1402
Quoted 4 lines
fs/xfs/xfs_buf.c +1
-1if ((bp->b_flags &XBF_WRITE ) && !xfs_buf_verify_write (bp)) {xfs_force_shutdown (bp->b_mount,SHUTDOWN_CORRUPT_INCORE ); - goto end_io; + goto ioerror;...but if bp itself causes the shutdown, we now leave
b_errorat 0, but do the same stale-and-complete thing? Shouldn't we set EIO on the buffer in both cases?
Quoted 2 lines
->verify_write is expected to set
b_errorwhen it fails (and yes, the API in that area is awful).
Would you mind leaving a comment here, then?
if ((bp->b_flags & XBF_WRITE) && !xfs_buf_verify_write(bp)) {
/* ->verify_write should have set b_error already */
xfs_force_shutdown(...);
goto out_ioerror;
}--D
Re: [PATCH 2/6] xfs: also mark the buffer stale on verifier failure in xfs_buf_submit
Quoted 10 lines · Darrick J. Wong
Quoted 2 lines
->verify_write is expected to set
b_errorwhen it fails (and yes, the API in that area is awful).Would you mind leaving a comment here, then?
if ((bp->b_flags & XBF_WRITE) && !xfs_buf_verify_write(bp)) { /* ->verify_write should have set b_error already */ xfs_force_shutdown(...); goto out_ioerror; }
Sure.
Darrick J. Wong
Reviewed-byRe: [PATCH 2/6] xfs: also mark the buffer stale on verifier failure in xfs_buf_submit
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Darrick J. Wong
Quoted 2 lines
->verify_write is expected to set
b_errorwhen it fails (and yes, the API in that area is awful).Would you mind leaving a comment here, then?
Quoted 7 lines
Quoted 5 lines
if ((bp->b_flags & XBF_WRITE) && !xfs_buf_verify_write(bp)) { /* ->verify_write should have set b_error already */ xfs_force_shutdown(...); goto out_ioerror; }Sure.
With the comment added,
--D
PATCH 3/6 xfs: improve the xfs_buf_ioend_fail calling convention
In reply to Christoph HellwigMove setting the ASYNC flag into xfs_buf_ioend_fail, assert that the buffer is locked as expected, and drop the confusing _ioend in the name.
--- fs/xfs/xfs_buf.c | 13 +++++++------ fs/xfs/xfs_buf.h | 2 +- fs/xfs/xfs_buf_item.c | 3 +-- fs/xfs/xfs_inode.c | 3 +-- 4 files changed, 10 insertions(+), 11 deletions(-)
fs/xfs/xfs_buf.c +7 -6
@@ -1192,17 +1192,18 @@ xfs_buf_ioerror_alert( }/* -* To simulate an I/O failure, the buffer must be locked and held with at least -* two references. +* Fail a locked and referenced buffer outside the I/O path. * -* The buf item reference is dropped via ioend processing. The second reference -* is owned by the caller and is dropped on I/O completion if the buffer is -* XBF_ASYNC. +* The caller transfers a reference which will be released after processing the +* error. */ void -xfs_buf_ioend_fail ( +xfs_buf_fail (struct xfs_buf *bp) { +ASSERT (xfs_buf_islocked (bp)); + + bp->b_flags |=XBF_ASYNC ; bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp);xfs_buf_ioerror (bp, -EIO );
fs/xfs/xfs_buf.h +1 -1
@@ -290,7 +290,7 @@ extern void __xfs_buf_ioerror(struct xfs_buf *bp, int error, xfs_failaddr_t failaddr);#define xfs_buf_ioerror (bp, err) __xfs_buf_ioerror((bp), (err), __this_address)extern void xfs_buf_ioerror_alert (struct xfs_buf *bp,xfs_failaddr_t fa); -void xfs_buf_ioend_fail (struct xfs_buf *); +void xfs_buf_fail (struct xfs_buf *bp);void __xfs_buf_mark_corrupt (struct xfs_buf *bp,xfs_failaddr_t fa);#define xfs_buf_mark_corrupt (bp) __xfs_buf_mark_corrupt((bp), __this_address)
fs/xfs/xfs_buf_item.c +1 -2
@@ -549,8 +549,7 @@ xfs_buf_item_unpin(* wait for the lock and then run the IO failure completion. */ xfs_buf_lock (bp); - bp->b_flags |=XBF_ASYNC ; -xfs_buf_ioend_fail (bp); +xfs_buf_fail (bp);return ; }
fs/xfs/xfs_inode.c +1 -2
@@ -2646,8 +2646,7 @@ xfs_iflush_cluster(* inode cluster buffers. */ xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE ); - bp->b_flags |=XBF_ASYNC ; -xfs_buf_ioend_fail (bp); +xfs_buf_fail (bp);return error; }
Signature · 1 line
2.53.0
Re: [PATCH 3/6] xfs: improve the xfs_buf_ioend_fail calling convention
Quoted 6 lines · Christoph Hellwig
Move setting the ASYNC flag into
xfs_buf_ioend_fail, assert that the buffer is locked as expected, and drop the confusing_ioendin the name.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Carlos Maiolino <[email protected]>
Looks straightforward to me...
--D
Quoted 81 lines
--- fs/xfs/xfs_buf.c | 13 +++++++------ fs/xfs/xfs_buf.h | 2 +- fs/xfs/xfs_buf_item.c | 3 +-- fs/xfs/xfs_inode.c | 3 +-- 4 files changed, 10 insertions(+), 11 deletions(-)fs/xfs/xfs_buf.c +7
-6@@ -1192,17 +1192,18 @@ xfs_buf_ioerror_alert( }/* -* To simulate an I/O failure, the buffer must be locked and held with at least -* two references. +* Fail a locked and referenced buffer outside the I/O path. * -* The buf item reference is dropped via ioend processing. The second reference -* is owned by the caller and is dropped on I/O completion if the buffer is -* XBF_ASYNC. +* The caller transfers a reference which will be released after processing the +* error. */ void -xfs_buf_ioend_fail ( +xfs_buf_fail (struct xfs_buf *bp) { +ASSERT (xfs_buf_islocked (bp)); + + bp->b_flags |=XBF_ASYNC ; bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp);xfs_buf_ioerror (bp, -EIO );fs/xfs/xfs_buf.h +1
-1@@ -290,7 +290,7 @@ extern void __xfs_buf_ioerror(struct xfs_buf *bp, int error, xfs_failaddr_t failaddr);#define xfs_buf_ioerror (bp, err) __xfs_buf_ioerror((bp), (err), __this_address)extern void xfs_buf_ioerror_alert (struct xfs_buf *bp,xfs_failaddr_t fa); -void xfs_buf_ioend_fail (struct xfs_buf *); +void xfs_buf_fail (struct xfs_buf *bp);void __xfs_buf_mark_corrupt (struct xfs_buf *bp,xfs_failaddr_t fa);#define xfs_buf_mark_corrupt (bp) __xfs_buf_mark_corrupt((bp), __this_address)fs/xfs/xfs_buf_item.c +1
-2@@ -549,8 +549,7 @@ xfs_buf_item_unpin(* wait for the lock and then run the IO failure completion. */ xfs_buf_lock (bp); - bp->b_flags |=XBF_ASYNC ; -xfs_buf_ioend_fail (bp); +xfs_buf_fail (bp);return ; }fs/xfs/xfs_inode.c +1
-2@@ -2646,8 +2646,7 @@ xfs_iflush_cluster(* inode cluster buffers. */ xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE ); - bp->b_flags |=XBF_ASYNC ; -xfs_buf_ioend_fail (bp); +xfs_buf_fail (bp);return error; }Signature · 1 line
2.53.0
PATCH 4/6 xfs: remove xfs_buf_ioend
In reply to Christoph HellwigThere are two callers of xfs_buf_ioend, one of which always has the XBF_ASYNC flag set. Open code the logic in both callers to prepare for a bug fix.
--- fs/xfs/xfs_buf.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
fs/xfs/xfs_buf.c +8 -14
@@ -1146,18 +1146,6 @@ __xfs_buf_ioend(return true; } -static void -xfs_buf_ioend ( -struct xfs_buf *bp) -{ -if (!__xfs_buf_ioend (bp)) -return ; -if (bp->b_flags &XBF_ASYNC ) -xfs_buf_relse (bp); -else -complete (&bp->b_iowait); -} -static void xfs_buf_ioend_work (struct work_struct *work)
@@ -1207,7 +1195,8 @@ xfs_buf_fail( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp);xfs_buf_ioerror (bp, -EIO ); -xfs_buf_ioend (bp); +if (__xfs_buf_ioend (bp)) +xfs_buf_relse (bp); }int
@@ -1414,7 +1403,12 @@ xfs_buf_submit( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp); end_io: -xfs_buf_ioend (bp); +if (!__xfs_buf_ioend (bp)) +return ; +if (bp->b_flags &XBF_ASYNC ) +xfs_buf_relse (bp); +else +complete (&bp->b_iowait); }/*
Signature · 1 line
2.53.0
Re: [PATCH 4/6] xfs: remove xfs_buf_ioend
Quoted 6 lines · Christoph Hellwig
There are two callers of
xfs_buf_ioend, one of which always has theXBF_ASYNCflag set. Open code the logic in both callers to prepare for a bug fix.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Carlos Maiolino <[email protected]>
Seems fine to me,
--D
Quoted 55 lines
--- fs/xfs/xfs_buf.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)fs/xfs/xfs_buf.c +8
-14@@ -1146,18 +1146,6 @@ __xfs_buf_ioend(return true; } -static void -xfs_buf_ioend ( -struct xfs_buf *bp) -{ -if (!__xfs_buf_ioend (bp)) -return ; -if (bp->b_flags &XBF_ASYNC ) -xfs_buf_relse (bp); -else -complete (&bp->b_iowait); -} -static void xfs_buf_ioend_work (struct work_struct *work)@@ -1207,7 +1195,8 @@ xfs_buf_fail( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp);xfs_buf_ioerror (bp, -EIO ); -xfs_buf_ioend (bp); +if (__xfs_buf_ioend (bp)) +xfs_buf_relse (bp); }int @@ -1414,7 +1403,12 @@ xfs_buf_submit( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp); end_io: -xfs_buf_ioend (bp); +if (!__xfs_buf_ioend (bp)) +return ; +if (bp->b_flags &XBF_ASYNC ) +xfs_buf_relse (bp); +else +complete (&bp->b_iowait); }/* Signature · 1 line
2.53.0
PATCH 5/6 xfs: fix handling of synchronous errors in xfs_buf_submit
In reply to Christoph HellwigSynchronous readers and writers already run __xfs_buf_ioend from xfs_buf_iowait after being woken through bp->b_iowait, so we should not call it here, which can lead to double completions.
--- fs/xfs/xfs_buf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/xfs/xfs_buf.c +5 -5
@@ -1403,12 +1403,12 @@ xfs_buf_submit( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp); end_io: -if (!__xfs_buf_ioend (bp)) -return ; -if (bp->b_flags &XBF_ASYNC ) -xfs_buf_relse (bp); -else +if (bp->b_flags &XBF_ASYNC ) { +if (__xfs_buf_ioend (bp)) +xfs_buf_relse (bp); + }else {complete (&bp->b_iowait); + } }/*
Signature · 1 line
2.53.0
Re: [PATCH 5/6] xfs: fix handling of synchronous errors in xfs_buf_submit
Quoted 3 lines · Christoph Hellwig
Synchronous readers and writers already run
__xfs_buf_ioendfromxfs_buf_iowaitafter being woken throughbp->b_iowait, so we should not call it here, which can lead to double completions.
How hard is it to trip the double completion? I guess all you need is an IO failure (or a verifier failure) on a synchronous read?
Quoted 3 lines
Fixes 4b90de5bc0f5 ("xfs: reduce context switches for synchronous buffered I/O")Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Carlos Maiolino <[email protected]>
If so, then
--D
Quoted 30 lines
--- fs/xfs/xfs_buf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)fs/xfs/xfs_buf.c +5
-5@@ -1403,12 +1403,12 @@ xfs_buf_submit( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp); end_io: -if (!__xfs_buf_ioend (bp)) -return ; -if (bp->b_flags &XBF_ASYNC ) -xfs_buf_relse (bp); -else +if (bp->b_flags &XBF_ASYNC ) { +if (__xfs_buf_ioend (bp)) +xfs_buf_relse (bp); + }else {complete (&bp->b_iowait); + } }/* Signature · 1 line
2.53.0
Re: [PATCH 5/6] xfs: fix handling of synchronous errors in xfs_buf_submit
Quoted 7 lines · Darrick J. Wong
Quoted 3 lines · Christoph Hellwig
Synchronous readers and writers already run
__xfs_buf_ioendfromxfs_buf_iowaitafter being woken throughbp->b_iowait, so we should not call it here, which can lead to double completions.How hard is it to trip the double completion? I guess all you need is an IO failure (or a verifier failure) on a synchronous read?
Yes. Or synchronous write for that matter. Note that due to what the completion handling does, the double completion might not be that harmful for synchronous I/O, but it sure as hell is wrong..
PATCH 6/6 xfs: simplify __xfs_buf_ioend
In reply to Christoph Hellwig__xfs_buf_ioend can only resubmit the buffer for asynchronous writes, which means the retry handling xfs_buf_iowait is not needed.
Because of this can stop returning a value from __xfs_buf_ioend and just release the buffer for async I/O that does not require retries.
Also drop the __-prefix now that the semantics are straight forward.
--- fs/xfs/xfs_buf.c | 51 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 25 deletions(-)
fs/xfs/xfs_buf.c +26 -25
@@ -1098,11 +1098,17 @@ xfs_buf_ioend_handle_error(return false; } -/* returns false if the caller needs to resubmit the I/O, else true */ -static bool -__xfs_buf_ioend ( +/* +* Complete a buffer read or write. +* +* Releases the buffer if the I/O was asynchronous. +*/ +static void +xfs_buf_ioend (struct xfs_buf *bp) { +bool async = bp->b_flags &XBF_ASYNC ; +trace_xfs_buf_iodone (bp, _RET_IP_);if (bp->b_flags &XBF_READ ) {
@@ -1116,14 +1122,16 @@ __xfs_buf_ioend(if (bp->b_flags &XBF_READ_AHEAD )percpu_counter_dec (&bp->b_target->bt_readahead_count); }else { -if (!bp->b_error) { +if (unlikely (bp->b_error)) { +if (xfs_buf_ioend_handle_error (bp)) { +ASSERT (async); +return ; + } + }else { bp->b_flags &= ~XBF_WRITE_FAIL ; bp->b_flags |=XBF_DONE ; } -if (unlikely (bp->b_error) &&xfs_buf_ioend_handle_error (bp)) -return false; -/* clear the retry state */ bp->b_last_error =0 ; bp->b_retries =0 ;
@@ -1143,18 +1151,15 @@ __xfs_buf_ioend( bp->b_flags &= ~(XBF_READ |XBF_WRITE |XBF_READ_AHEAD | _XBF_LOGRECOVERY); -return true; +if (async) +xfs_buf_relse (bp); }static void xfs_buf_ioend_work (struct work_struct *work) { -struct xfs_buf *bp = - container_of(work, struct xfs_buf, b_ioend_work); - -if (__xfs_buf_ioend (bp)) -xfs_buf_relse (bp); +xfs_buf_ioend (container_of(work ,struct xfs_buf ,b_ioend_work )); }void
@@ -1195,8 +1200,7 @@ xfs_buf_fail( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp);xfs_buf_ioerror (bp, -EIO ); -if (__xfs_buf_ioend (bp)) -xfs_buf_relse (bp); +xfs_buf_ioend (bp); }int
@@ -1305,12 +1309,11 @@ xfs_buf_iowait( {ASSERT (!(bp->b_flags &XBF_ASYNC )); -do { -trace_xfs_buf_iowait (bp, _RET_IP_); -wait_for_completion (&bp->b_iowait); -trace_xfs_buf_iowait_done (bp, _RET_IP_); - }while (!__xfs_buf_ioend (bp)); +trace_xfs_buf_iowait (bp, _RET_IP_); +wait_for_completion (&bp->b_iowait); +trace_xfs_buf_iowait_done (bp, _RET_IP_); +xfs_buf_ioend (bp);return bp->b_error; }
@@ -1403,12 +1406,10 @@ xfs_buf_submit( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp); end_io: -if (bp->b_flags &XBF_ASYNC ) { -if (__xfs_buf_ioend (bp)) -xfs_buf_relse (bp); - }else { +if (bp->b_flags &XBF_ASYNC ) +xfs_buf_ioend (bp); +else complete (&bp->b_iowait); - } }/*
Signature · 1 line
2.53.0
Re: [PATCH 6/6] xfs: simplify __xfs_buf_ioend
Quoted 10 lines · Christoph Hellwig
__xfs_buf_ioendcan only resubmit the buffer for asynchronous writes, which means the retry handlingxfs_buf_iowaitis not needed.Because of this can stop returning a value from
__xfs_buf_ioendand just release the buffer for async I/O that does not require retries.Also drop the __-prefix now that the semantics are straight forward.
Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Carlos Maiolino <[email protected]>
This makes sense to me -- only async writes (e.g. logged buffers written by the ail) get to go through the write retry mechanism; the synchronous writers are either regular threads and can report errors, or they're dquot/inode items and a cluster flush just marks the log item as failed.
--D
Quoted 119 lines
--- fs/xfs/xfs_buf.c | 51 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 25 deletions(-)fs/xfs/xfs_buf.c +26
-25@@ -1098,11 +1098,17 @@ xfs_buf_ioend_handle_error(return false; } -/* returns false if the caller needs to resubmit the I/O, else true */ -static bool -__xfs_buf_ioend ( +/* +* Complete a buffer read or write. +* +* Releases the buffer if the I/O was asynchronous. +*/ +static void +xfs_buf_ioend (struct xfs_buf *bp) { +bool async = bp->b_flags &XBF_ASYNC ; +trace_xfs_buf_iodone (bp, _RET_IP_);if (bp->b_flags &XBF_READ ) {@@ -1116,14 +1122,16 @@ __xfs_buf_ioend(if (bp->b_flags &XBF_READ_AHEAD )percpu_counter_dec (&bp->b_target->bt_readahead_count); }else { -if (!bp->b_error) { +if (unlikely (bp->b_error)) { +if (xfs_buf_ioend_handle_error (bp)) { +ASSERT (async); +return ; + } + }else { bp->b_flags &= ~XBF_WRITE_FAIL ; bp->b_flags |=XBF_DONE ; } -if (unlikely (bp->b_error) &&xfs_buf_ioend_handle_error (bp)) -return false; -/* clear the retry state */ bp->b_last_error =0 ; bp->b_retries =0 ;@@ -1143,18 +1151,15 @@ __xfs_buf_ioend( bp->b_flags &= ~(XBF_READ |XBF_WRITE |XBF_READ_AHEAD | _XBF_LOGRECOVERY); -return true; +if (async) +xfs_buf_relse (bp); }static void xfs_buf_ioend_work (struct work_struct *work) { -struct xfs_buf *bp = - container_of(work, struct xfs_buf, b_ioend_work); - -if (__xfs_buf_ioend (bp)) -xfs_buf_relse (bp); +xfs_buf_ioend (container_of(work ,struct xfs_buf ,b_ioend_work )); }void @@ -1195,8 +1200,7 @@ xfs_buf_fail( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp);xfs_buf_ioerror (bp, -EIO ); -if (__xfs_buf_ioend (bp)) -xfs_buf_relse (bp); +xfs_buf_ioend (bp); }int @@ -1305,12 +1309,11 @@ xfs_buf_iowait( {ASSERT (!(bp->b_flags &XBF_ASYNC )); -do { -trace_xfs_buf_iowait (bp, _RET_IP_); -wait_for_completion (&bp->b_iowait); -trace_xfs_buf_iowait_done (bp, _RET_IP_); - }while (!__xfs_buf_ioend (bp)); +trace_xfs_buf_iowait (bp, _RET_IP_); +wait_for_completion (&bp->b_iowait); +trace_xfs_buf_iowait_done (bp, _RET_IP_); +xfs_buf_ioend (bp);return bp->b_error; }@@ -1403,12 +1406,10 @@ xfs_buf_submit( bp->b_flags &= ~XBF_DONE ;xfs_buf_stale (bp); end_io: -if (bp->b_flags &XBF_ASYNC ) { -if (__xfs_buf_ioend (bp)) -xfs_buf_relse (bp); - }else { +if (bp->b_flags &XBF_ASYNC ) +xfs_buf_ioend (bp); +else complete (&bp->b_iowait); - } }/* Signature · 1 line
2.53.0
Quoted 8 lines · Christoph Hellwig
currently
xfs_buf_submitcan execute the endio handling twice when failing for a synchronous submission. This series refactors the surrounding code a bit to allow for a non-hacky fix and then applies that.Changes since v1:
- fix a commit message typo[...]
Applied to for-next, thanks!
[1/6] xfs: open code xfs_buf_ioend_fail in xfs_buf_submit
commit: 6769087fd856889a32caf09590703813e3763575
[2/6] xfs: also mark the buffer stale on verifier failure in xfs_buf_submit
commit: 0b434b552ecd19f33e2f85ea8e55dbb65352810d
[3/6] xfs: improve the xfs_buf_ioend_fail calling convention
commit: 4c8b46d832bd98eab914e2bbcd32447b584b03a7
[4/6] xfs: remove xfs_buf_ioend
commit: b53177d418225b15d23b1817fac1b5c668e56c2f
[5/6] xfs: fix handling of synchronous errors in xfs_buf_submit
commit: 93e21ef2a819348fce899bd1bd1303979bba3f1d
[6/6] xfs: simplify __xfs_buf_ioend
commit: e4281086ae6caf006b6ef0670479eb5f96880fb9Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>