Re: [PATCH 19/45] xfs: factor out the CIL transaction header building

Darrick J. Wong
2021-03-08T23:48:30Z

On Fri, Mar 05, 2021 at 04:11:17PM +1100, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> It is static code deep in the middle of the CIL push logic. Factor
> it out into a helper so that it is clear and easy to modify
> separately.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Looks straightforward,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
> fs/xfs/xfs_log_cil.c | 71 +++++++++++++++++++++++++++++---------------
> 1 file changed, 47 insertions(+), 24 deletions(-)
>
> diff --git a/fs/xfs/xfs_log_cil.c b/fs/xfs/xfs_log_cil.c
> index dfc9ef692a80..b515002e7959 100644
> --- a/fs/xfs/xfs_log_cil.c
> +++ b/fs/xfs/xfs_log_cil.c
> @@ -651,6 +651,41 @@ xlog_cil_process_committed(
> }
> }
>
> +struct xlog_cil_trans_hdr {
> + struct xfs_trans_header thdr;
> + struct xfs_log_iovec lhdr;
> +};
> +
> +/*
> + * Build a checkpoint transaction header to begin the journal transaction. We
> + * need to account for the space used by the transaction header here as it is
> + * not accounted for in xlog_write().
> + */
> +static void
> +xlog_cil_build_trans_hdr(
> + struct xfs_cil_ctx *ctx,
> + struct xlog_cil_trans_hdr *hdr,
> + struct xfs_log_vec *lvhdr,
> + int num_iovecs)
> +{
> + struct xlog_ticket *tic = ctx->ticket;
> +
> + memset(hdr, 0, sizeof(*hdr));
> +
> + hdr->thdr.th_magic = XFS_TRANS_HEADER_MAGIC;
> + hdr->thdr.th_type = XFS_TRANS_CHECKPOINT;
> + hdr->thdr.th_tid = tic->t_tid;
> + hdr->thdr.th_num_items = num_iovecs;
> + hdr->lhdr.i_addr = &hdr->thdr;
> + hdr->lhdr.i_len = sizeof(xfs_trans_header_t);
> + hdr->lhdr.i_type = XLOG_REG_TYPE_TRANSHDR;
> + tic->t_curr_res -= hdr->lhdr.i_len + sizeof(xlog_op_header_t);
> +
> + lvhdr->lv_niovecs = 1;
> + lvhdr->lv_iovecp = &hdr->lhdr;
> + lvhdr->lv_next = ctx->lv_chain;
> +}
> +
> /*
> * Push the Committed Item List to the log.
> *
> @@ -676,11 +711,9 @@ xlog_cil_push_work(
> struct xfs_log_vec *lv;
> struct xfs_cil_ctx *new_ctx;
> struct xlog_in_core *commit_iclog;
> - struct xlog_ticket *tic;
> int num_iovecs;
> int error = 0;
> - struct xfs_trans_header thdr;
> - struct xfs_log_iovec lhdr;
> + struct xlog_cil_trans_hdr thdr;
> struct xfs_log_vec lvhdr = { NULL };
> xfs_lsn_t commit_lsn;
> xfs_lsn_t push_seq;
> @@ -827,24 +860,8 @@ xlog_cil_push_work(
> * Build a checkpoint transaction header and write it to the log to
> * begin the transaction. We need to account for the space used by the
> * transaction header here as it is not accounted for in xlog_write().
> - *
> - * The LSN we need to pass to the log items on transaction commit is
> - * the LSN reported by the first log vector write. If we use the commit
> - * record lsn then we can move the tail beyond the grant write head.
> */
> - tic = ctx->ticket;
> - thdr.th_magic = XFS_TRANS_HEADER_MAGIC;
> - thdr.th_type = XFS_TRANS_CHECKPOINT;
> - thdr.th_tid = tic->t_tid;
> - thdr.th_num_items = num_iovecs;
> - lhdr.i_addr = &thdr;
> - lhdr.i_len = sizeof(xfs_trans_header_t);
> - lhdr.i_type = XLOG_REG_TYPE_TRANSHDR;
> - tic->t_curr_res -= lhdr.i_len + sizeof(xlog_op_header_t);
> -
> - lvhdr.lv_niovecs = 1;
> - lvhdr.lv_iovecp = &lhdr;
> - lvhdr.lv_next = ctx->lv_chain;
> + xlog_cil_build_trans_hdr(ctx, &thdr, &lvhdr, num_iovecs);
>
> /*
> * Before we format and submit the first iclog, we have to ensure that
> @@ -852,7 +869,13 @@ xlog_cil_push_work(
> */
> wait_for_completion(&bdev_flush);
>
> - error = xlog_write(log, &lvhdr, tic, &ctx->start_lsn, NULL,
> + /*
> + * The LSN we need to pass to the log items on transaction commit is the
> + * LSN reported by the first log vector write, not the commit lsn. If we
> + * use the commit record lsn then we can move the tail beyond the grant
> + * write head.
> + */
> + error = xlog_write(log, &lvhdr, ctx->ticket, &ctx->start_lsn, NULL,
> XLOG_START_TRANS);
> if (error)
> goto out_abort_free_ticket;
> @@ -891,11 +914,11 @@ xlog_cil_push_work(
> }
> spin_unlock(&cil->xc_push_lock);
>
> - error = xlog_commit_record(log, tic, &commit_iclog, &commit_lsn);
> + error = xlog_commit_record(log, ctx->ticket, &commit_iclog, &commit_lsn);
> if (error)
> goto out_abort_free_ticket;
>
> - xfs_log_ticket_ungrant(log, tic);
> + xfs_log_ticket_ungrant(log, ctx->ticket);
>
> spin_lock(&commit_iclog->ic_callback_lock);
> if (commit_iclog->ic_state == XLOG_STATE_IOERROR) {
> @@ -946,7 +969,7 @@ xlog_cil_push_work(
> return;
>
> out_abort_free_ticket:
> - xfs_log_ticket_ungrant(log, tic);
> + xfs_log_ticket_ungrant(log, ctx->ticket);
> out_abort:
> ASSERT(XLOG_FORCED_SHUTDOWN(log));
> xlog_cil_committed(ctx);
> --
> 2.28.0
>