From: Christoph Hellwig <hch@infradead.org>
To: Dave Chinner <david@fromorbit.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 09/11] xfs: introduce xfs_buf_submit[_wait]
Date: Fri, 26 Sep 2014 05:33:38 -0700 [thread overview]
Message-ID: <20140926123338.GA18558@infradead.org> (raw)
In-Reply-To: <1411648461-29003-10-git-send-email-david@fromorbit.com>
Looks good, although I still think this would benefit from a helper
like the one below (patch lightly tested).
Reviewed-by: Christoph Hellwig <hch@lst.de>
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 0ac54a0..081ccf3 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1287,28 +1287,18 @@ _xfs_buf_ioapply(
blk_finish_plug(&plug);
}
-/*
- * Asynchronous IO submission path. This transfers the buffer lock ownership and
- * the current reference to the IO. It is not safe to reference the buffer after
- * a call to this function unless the caller holds an additional reference
- * itself.
- */
-void
-xfs_buf_submit(
+static int
+__xfs_buf_submit(
struct xfs_buf *bp)
{
- trace_xfs_buf_submit(bp, _RET_IP_);
-
ASSERT(!(bp->b_flags & _XBF_DELWRI_Q));
- ASSERT(bp->b_flags & XBF_ASYNC);
/* on shutdown we stale and complete the buffer immediately */
if (XFS_FORCED_SHUTDOWN(bp->b_target->bt_mount)) {
xfs_buf_ioerror(bp, -EIO);
bp->b_flags &= ~XBF_DONE;
xfs_buf_stale(bp);
- xfs_buf_ioend(bp);
- return;
+ return -EIO;
}
if (bp->b_flags & XBF_WRITE)
@@ -1318,12 +1308,8 @@ xfs_buf_submit(
bp->b_io_error = 0;
/*
- * The caller's reference is released during I/O completion.
- * This occurs some time after the last b_io_remaining reference is
- * released, so after we drop our Io reference we have to have some
- * other reference to ensure the buffer doesn't go away from underneath
- * us. Take a direct reference to ensure we have safe access to the
- * buffer until we are finished with it.
+ * Take a reference to ensure we have safe access to the buffer until
+ * we are finished with it.
*/
xfs_buf_hold(bp);
@@ -1341,64 +1327,56 @@ xfs_buf_submit(
* that we don't return to the caller with completion still pending.
*/
if (atomic_dec_and_test(&bp->b_io_remaining) == 1) {
- if (bp->b_error)
- xfs_buf_ioend(bp);
- else
+ if ((bp->b_flags & XBF_ASYNC) && !bp->b_error)
xfs_buf_ioend_async(bp);
+ else
+ xfs_buf_ioend(bp);
}
- xfs_buf_rele(bp);
- /* Note: it is not safe to reference bp now we've dropped our ref */
+ return 0;
}
/*
- * Synchronous buffer IO submission path, read or write.
+ * Asynchronous IO submission path. This transfers the buffer lock ownership and
+ * the current reference to the IO. It is not safe to reference the buffer after
+ * a call to this function unless the caller holds an additional reference
+ * itself.
*/
-int
-xfs_buf_submit_wait(
+void
+xfs_buf_submit(
struct xfs_buf *bp)
{
int error;
- trace_xfs_buf_submit_wait(bp, _RET_IP_);
+ trace_xfs_buf_submit(bp, _RET_IP_);
- ASSERT(!(bp->b_flags & (_XBF_DELWRI_Q | XBF_ASYNC)));
+ ASSERT(bp->b_flags & XBF_ASYNC);
- if (XFS_FORCED_SHUTDOWN(bp->b_target->bt_mount)) {
- xfs_buf_ioerror(bp, -EIO);
- xfs_buf_stale(bp);
- bp->b_flags &= ~XBF_DONE;
- return -EIO;
- }
+ error = __xfs_buf_submit(bp);
+ if (error)
+ xfs_buf_ioend(bp);
+ else
+ xfs_buf_rele(bp);
- if (bp->b_flags & XBF_WRITE)
- xfs_buf_wait_unpin(bp);
+ /* Note: it is not safe to reference bp now we've dropped our ref */
+}
- /* clear the internal error state to avoid spurious errors */
- bp->b_io_error = 0;
+/*
+ * Synchronous buffer IO submission path, read or write.
+ */
+int
+xfs_buf_submit_wait(
+ struct xfs_buf *bp)
+{
+ int error;
- /*
- * For synchronous IO, the IO does not inherit the submitters reference
- * count, nor the buffer lock. Hence we cannot release the reference we
- * are about to take until we've waited for all IO completion to occur,
- * including any xfs_buf_ioend_async() work that may be pending.
- */
- xfs_buf_hold(bp);
+ trace_xfs_buf_submit_wait(bp, _RET_IP_);
- /*
- * Set the count to 1 initially, this will stop an I/O completion
- * callout which happens before we have started all the I/O from calling
- * xfs_buf_ioend too early.
- */
- atomic_set(&bp->b_io_remaining, 1);
- _xfs_buf_ioapply(bp);
+ ASSERT(!(bp->b_flags & XBF_ASYNC));
- /*
- * make sure we run completion synchronously if it raced with us and is
- * already complete.
- */
- if (atomic_dec_and_test(&bp->b_io_remaining) == 1)
- xfs_buf_ioend(bp);
+ error = __xfs_buf_submit(bp);
+ if (error)
+ return error;
/* wait for completion before gathering the error from the buffer */
trace_xfs_buf_iowait(bp, _RET_IP_);
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2014-09-26 12:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-25 12:34 [PATCH 00/11 v2] xfs: clean up xfs_buf io interfaces Dave Chinner
2014-09-25 12:34 ` [PATCH 01/11] xfs: force the log before shutting down Dave Chinner
2014-09-26 10:37 ` Christoph Hellwig
2014-09-25 12:34 ` [PATCH 02/11] xfs: Don't use xfs_buf_iowait in the delwri buffer code Dave Chinner
2014-09-25 16:19 ` Christoph Hellwig
2014-09-25 12:34 ` [PATCH 03/11] xfs: synchronous buffer IO needs a reference Dave Chinner
2014-09-26 10:11 ` Christoph Hellwig
2014-09-25 12:34 ` [PATCH 04/11] xfs: xfs_buf_ioend and xfs_buf_iodone_work duplicate functionality Dave Chinner
2014-09-26 10:14 ` Christoph Hellwig
2014-09-25 12:34 ` [PATCH 05/11] xfs: rework xfs_buf_bio_endio error handling Dave Chinner
2014-09-26 10:15 ` Christoph Hellwig
2014-09-25 12:34 ` [PATCH 06/11] xfs: kill xfs_bdstrat_cb Dave Chinner
2014-09-25 12:34 ` [PATCH 07/11] xfs: xfs_bioerror can die Dave Chinner
2014-09-26 10:16 ` Christoph Hellwig
2014-09-25 12:34 ` [PATCH 08/11] xfs: kill xfs_bioerror_relse Dave Chinner
2014-09-26 10:18 ` Christoph Hellwig
2014-09-29 19:09 ` Brian Foster
2014-09-25 12:34 ` [PATCH 09/11] xfs: introduce xfs_buf_submit[_wait] Dave Chinner
2014-09-26 12:33 ` Christoph Hellwig [this message]
2014-10-01 23:03 ` Dave Chinner
2014-09-25 12:34 ` [PATCH 10/11] xfs: check xfs_buf_read_uncached returns correctly Dave Chinner
2014-09-26 10:21 ` Christoph Hellwig
2014-09-26 23:20 ` [PATCH 10/11 v2] " Dave Chinner
2014-09-29 10:40 ` Christoph Hellwig
2014-09-25 12:34 ` [PATCH 11/11] xfs: simplify xfs_zero_remaining_bytes Dave Chinner
2014-09-26 10:22 ` Christoph Hellwig
2014-09-29 19:09 ` Brian Foster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140926123338.GA18558@infradead.org \
--to=hch@infradead.org \
--cc=david@fromorbit.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.