Commit 0e95f19a authored by Dave Chinner's avatar Dave Chinner Committed by Ben Myers

xfs: check for buffer errors before waiting

If we call xfs_buf_iowait() on a buffer that failed dispatch due to
an IO error, it will wait forever for an Io that does not exist.
This is hndled in xfs_buf_read, but there is other code that calls
xfs_buf_iowait directly that doesn't.

Rather than make the call sites have to handle checking for dispatch
errors and then checking for completion errors, make
xfs_buf_iowait() check for dispatch errors on the buffer before
waiting. This means we handle both dispatch and completion errors
with one set of error handling at the caller sites.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarMark Tinguely <tinguely@sgi.com>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent fe2429b0
...@@ -600,17 +600,15 @@ _xfs_buf_read( ...@@ -600,17 +600,15 @@ _xfs_buf_read(
xfs_buf_t *bp, xfs_buf_t *bp,
xfs_buf_flags_t flags) xfs_buf_flags_t flags)
{ {
int status;
ASSERT(!(flags & XBF_WRITE)); ASSERT(!(flags & XBF_WRITE));
ASSERT(bp->b_bn != XFS_BUF_DADDR_NULL); ASSERT(bp->b_bn != XFS_BUF_DADDR_NULL);
bp->b_flags &= ~(XBF_WRITE | XBF_ASYNC | XBF_READ_AHEAD); bp->b_flags &= ~(XBF_WRITE | XBF_ASYNC | XBF_READ_AHEAD);
bp->b_flags |= flags & (XBF_READ | XBF_ASYNC | XBF_READ_AHEAD); bp->b_flags |= flags & (XBF_READ | XBF_ASYNC | XBF_READ_AHEAD);
status = xfs_buf_iorequest(bp); xfs_buf_iorequest(bp);
if (status || bp->b_error || (flags & XBF_ASYNC)) if (flags & XBF_ASYNC)
return status; return 0;
return xfs_buf_iowait(bp); return xfs_buf_iowait(bp);
} }
...@@ -695,7 +693,7 @@ xfs_buf_read_uncached( ...@@ -695,7 +693,7 @@ xfs_buf_read_uncached(
xfsbdstrat(mp, bp); xfsbdstrat(mp, bp);
error = xfs_buf_iowait(bp); error = xfs_buf_iowait(bp);
if (error || bp->b_error) { if (error) {
xfs_buf_relse(bp); xfs_buf_relse(bp);
return NULL; return NULL;
} }
...@@ -1252,7 +1250,7 @@ _xfs_buf_ioapply( ...@@ -1252,7 +1250,7 @@ _xfs_buf_ioapply(
} }
} }
int void
xfs_buf_iorequest( xfs_buf_iorequest(
xfs_buf_t *bp) xfs_buf_t *bp)
{ {
...@@ -1273,13 +1271,12 @@ xfs_buf_iorequest( ...@@ -1273,13 +1271,12 @@ xfs_buf_iorequest(
_xfs_buf_ioend(bp, 0); _xfs_buf_ioend(bp, 0);
xfs_buf_rele(bp); xfs_buf_rele(bp);
return 0;
} }
/* /*
* Waits for I/O to complete on the buffer supplied. * Waits for I/O to complete on the buffer supplied. It returns immediately if
* It returns immediately if no I/O is pending. * no I/O is pending or there is already a pending error on the buffer. It
* It returns the I/O error code, if any, or 0 if there was no error. * returns the I/O error code, if any, or 0 if there was no error.
*/ */
int int
xfs_buf_iowait( xfs_buf_iowait(
...@@ -1287,7 +1284,8 @@ xfs_buf_iowait( ...@@ -1287,7 +1284,8 @@ xfs_buf_iowait(
{ {
trace_xfs_buf_iowait(bp, _RET_IP_); trace_xfs_buf_iowait(bp, _RET_IP_);
wait_for_completion(&bp->b_iowait); if (!bp->b_error)
wait_for_completion(&bp->b_iowait);
trace_xfs_buf_iowait_done(bp, _RET_IP_); trace_xfs_buf_iowait_done(bp, _RET_IP_);
return bp->b_error; return bp->b_error;
......
...@@ -191,7 +191,7 @@ extern int xfs_bdstrat_cb(struct xfs_buf *); ...@@ -191,7 +191,7 @@ extern int xfs_bdstrat_cb(struct xfs_buf *);
extern void xfs_buf_ioend(xfs_buf_t *, int); extern void xfs_buf_ioend(xfs_buf_t *, int);
extern void xfs_buf_ioerror(xfs_buf_t *, int); extern void xfs_buf_ioerror(xfs_buf_t *, int);
extern void xfs_buf_ioerror_alert(struct xfs_buf *, const char *func); extern void xfs_buf_ioerror_alert(struct xfs_buf *, const char *func);
extern int xfs_buf_iorequest(xfs_buf_t *); extern void xfs_buf_iorequest(xfs_buf_t *);
extern int xfs_buf_iowait(xfs_buf_t *); extern int xfs_buf_iowait(xfs_buf_t *);
extern void xfs_buf_iomove(xfs_buf_t *, size_t, size_t, void *, extern void xfs_buf_iomove(xfs_buf_t *, size_t, size_t, void *,
xfs_buf_rw_t); xfs_buf_rw_t);
......
...@@ -179,6 +179,7 @@ xlog_bread_noalign( ...@@ -179,6 +179,7 @@ xlog_bread_noalign(
XFS_BUF_SET_ADDR(bp, log->l_logBBstart + blk_no); XFS_BUF_SET_ADDR(bp, log->l_logBBstart + blk_no);
XFS_BUF_READ(bp); XFS_BUF_READ(bp);
XFS_BUF_SET_COUNT(bp, BBTOB(nbblks)); XFS_BUF_SET_COUNT(bp, BBTOB(nbblks));
bp->b_error = 0;
xfsbdstrat(log->l_mp, bp); xfsbdstrat(log->l_mp, bp);
error = xfs_buf_iowait(bp); error = xfs_buf_iowait(bp);
...@@ -266,6 +267,7 @@ xlog_bwrite( ...@@ -266,6 +267,7 @@ xlog_bwrite(
xfs_buf_hold(bp); xfs_buf_hold(bp);
xfs_buf_lock(bp); xfs_buf_lock(bp);
XFS_BUF_SET_COUNT(bp, BBTOB(nbblks)); XFS_BUF_SET_COUNT(bp, BBTOB(nbblks));
bp->b_error = 0;
error = xfs_bwrite(bp); error = xfs_bwrite(bp);
if (error) if (error)
......
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