From: "Darrick J. Wong" <djwong@kernel.org>
To: Dave Chinner <david@fromorbit.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 7/9] xfs: separate out log shutdown callback processing
Date: Wed, 14 Jul 2021 15:00:39 -0700 [thread overview]
Message-ID: <20210714220039.GP22402@magnolia> (raw)
In-Reply-To: <20210714031958.2614411-8-david@fromorbit.com>
On Wed, Jul 14, 2021 at 01:19:56PM +1000, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> The iclog callback processing done during a forced log shutdown has
> different logic to normal runtime IO completion callback processing.
> Separate out eh shutdown callbacks into their own function and call
"..out the shutdown callbacks..."
> that from the shutdown code instead.
>
> We don't need this shutdown specific logic in the normal runtime
> completion code - we'll always run the shutdown version on shutdown,
> and it will do what shutdown needs regardless of whether there are
> racing IO completion callbacks scheduled or in progress. Hence we
> can also simplify the normal IO completion callpath and only abort
> if shutdown occurred while we actively were processing callbacks.
>
> Further, separating out the IO completion logic from the shutdown
> logic avoids callback race conditions from being triggered by log IO
> completion after a shutdown. IO completion will now only run
> callbacks on iclogs that are in the correct state for a callback to
> be run, avoiding the possibility of running callbacks on a
> referenced iclog that hasn't yet been submitted for IO.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
With the typo fixed, I like this cleanup. :)
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
> fs/xfs/xfs_log.c | 53 ++++++++++++++++++++++++++++++++++--------------
> 1 file changed, 38 insertions(+), 15 deletions(-)
>
> diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
> index 302c1ce27974..4d72d9efed7c 100644
> --- a/fs/xfs/xfs_log.c
> +++ b/fs/xfs/xfs_log.c
> @@ -487,6 +487,32 @@ xfs_log_reserve(
> return error;
> }
>
> +/*
> + * Run all the pending iclog callbacks and wake log force waiters and iclog
> + * space waiters so they can process the newly set shutdown state. We really
> + * don't care what order we process callbacks here because the log is shut down
> + * and so state cannot change on disk anymore.
> + */
> +static void
> +xlog_state_shutdown_callbacks(
> + struct xlog *log)
> +{
> + struct xlog_in_core *iclog;
> + LIST_HEAD(cb_list);
> +
> + spin_lock(&log->l_icloglock);
> + iclog = log->l_iclog;
> + do {
> + list_splice_init(&iclog->ic_callbacks, &cb_list);
> + wake_up_all(&iclog->ic_force_wait);
> + } while ((iclog = iclog->ic_next) != log->l_iclog);
> +
> + wake_up_all(&log->l_flush_wait);
> + spin_unlock(&log->l_icloglock);
> +
> + xlog_cil_process_committed(&cb_list);
> +}
> +
> static bool
> __xlog_state_release_iclog(
> struct xlog *log,
> @@ -2762,7 +2788,10 @@ xlog_state_iodone_process_iclog(
>
> /*
> * Loop over all the iclogs, running attached callbacks on them. Return true if
> - * we ran any callbacks, indicating that we dropped the icloglock.
> + * we ran any callbacks, indicating that we dropped the icloglock. We don't need
> + * to handle transient shutdown state here at all because
> + * xlog_state_shutdown_callbacks() will be run to do the necessary shutdown
> + * cleanup of the callbacks.
> */
> static bool
> xlog_state_do_iclog_callbacks(
> @@ -2777,13 +2806,11 @@ xlog_state_do_iclog_callbacks(
> do {
> LIST_HEAD(cb_list);
>
> - if (!xlog_is_shutdown(log)) {
> - if (xlog_state_iodone_process_iclog(log, iclog))
> - break;
> - if (iclog->ic_state != XLOG_STATE_CALLBACK) {
> - iclog = iclog->ic_next;
> - continue;
> - }
> + if (xlog_state_iodone_process_iclog(log, iclog))
> + break;
> + if (iclog->ic_state != XLOG_STATE_CALLBACK) {
> + iclog = iclog->ic_next;
> + continue;
> }
> list_splice_init(&iclog->ic_callbacks, &cb_list);
> spin_unlock(&log->l_icloglock);
> @@ -2794,10 +2821,7 @@ xlog_state_do_iclog_callbacks(
> ran_callback = true;
>
> spin_lock(&log->l_icloglock);
> - if (xlog_is_shutdown(log))
> - wake_up_all(&iclog->ic_force_wait);
> - else
> - xlog_state_clean_iclog(log, iclog);
> + xlog_state_clean_iclog(log, iclog);
> iclog = iclog->ic_next;
> } while (iclog != first_iclog);
>
> @@ -2830,8 +2854,7 @@ xlog_state_do_callback(
> }
> }
>
> - if (log->l_iclog->ic_state == XLOG_STATE_ACTIVE ||
> - xlog_is_shutdown(log))
> + if (log->l_iclog->ic_state == XLOG_STATE_ACTIVE)
> wake_up_all(&log->l_flush_wait);
>
> spin_unlock(&log->l_icloglock);
> @@ -3764,7 +3787,7 @@ xlog_force_shutdown(
> spin_lock(&log->l_cilp->xc_push_lock);
> wake_up_all(&log->l_cilp->xc_commit_wait);
> spin_unlock(&log->l_cilp->xc_push_lock);
> - xlog_state_do_callback(log);
> + xlog_state_shutdown_callbacks(log);
>
> return log_error;
> }
> --
> 2.31.1
>
next prev parent reply other threads:[~2021-07-14 22:00 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-14 3:19 [PATCH 0/9 v2] xfs: shutdown is a racy mess Dave Chinner
2021-07-14 3:19 ` [PATCH 1/9] xfs: convert XLOG_FORCED_SHUTDOWN() to xlog_is_shutdown() Dave Chinner
2021-07-14 6:09 ` Christoph Hellwig
2021-07-14 3:19 ` [PATCH 2/9] xfs: XLOG_STATE_IOERROR must die Dave Chinner
2021-07-14 6:13 ` Christoph Hellwig
2021-07-14 21:51 ` Darrick J. Wong
2021-07-14 3:19 ` [PATCH 3/9] xfs: move recovery needed state updates to xfs_log_mount_finish Dave Chinner
2021-07-14 21:54 ` Darrick J. Wong
2021-07-14 3:19 ` [PATCH 4/9] xfs: convert log flags to an operational state field Dave Chinner
2021-07-14 3:19 ` [PATCH 5/9] xfs: make forced shutdown processing atomic Dave Chinner
2021-07-14 6:15 ` Christoph Hellwig
2021-07-14 21:57 ` Darrick J. Wong
2021-07-14 3:19 ` [PATCH 6/9] xfs: rework xlog_state_do_callback() Dave Chinner
2021-07-14 3:19 ` [PATCH 7/9] xfs: separate out log shutdown callback processing Dave Chinner
2021-07-14 6:17 ` Christoph Hellwig
2021-07-14 22:00 ` Darrick J. Wong [this message]
2021-07-14 3:19 ` [PATCH 8/9] xfs: don't run shutdown callbacks on active iclogs Dave Chinner
2021-07-14 22:09 ` Darrick J. Wong
2021-07-14 3:19 ` [PATCH 9/9] xfs: log head and tail aren't reliable during shutdown Dave Chinner
2021-07-14 22:12 ` Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2021-08-10 5:18 [PATCH 0/9 v3] xfs: shutdown is a racy mess Dave Chinner
2021-08-10 5:18 ` [PATCH 7/9] xfs: separate out log shutdown callback processing Dave Chinner
2021-06-30 6:38 [PATCH 0/9] xfs: shutdown is a racy mess Dave Chinner
2021-06-30 6:38 ` [PATCH 7/9] xfs: separate out log shutdown callback processing Dave Chinner
2021-07-02 8:36 ` Christoph Hellwig
2021-07-05 1:46 ` Dave Chinner
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=20210714220039.GP22402@magnolia \
--to=djwong@kernel.org \
--cc=david@fromorbit.com \
--cc=linux-xfs@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox