xfs: factor out the CIL transaction header building

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>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Chandan Babu R <chandan.babu@oracle.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
Dave Chinner 2022-04-21 10:33:23 +10:00 committed by Dave Chinner
parent ce522ba9ef
commit 735fbf67df

View File

@ -868,6 +868,41 @@ xlog_cil_write_commit_record(
return error;
}
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(struct xlog_op_header);
lvhdr->lv_niovecs = 1;
lvhdr->lv_iovecp = &hdr->lhdr;
lvhdr->lv_next = ctx->lv_chain;
}
/*
* Push the Committed Item List to the log.
*
@ -892,11 +927,9 @@ xlog_cil_push_work(
struct xlog *log = cil->xc_log;
struct xfs_log_vec *lv;
struct xfs_cil_ctx *new_ctx;
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_csn_t push_seq;
bool push_commit_stable;
@ -1025,24 +1058,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);
error = xlog_cil_write_chain(ctx, &lvhdr);
if (error)
@ -1052,7 +1069,7 @@ xlog_cil_push_work(
if (error)
goto out_abort_free_ticket;
xfs_log_ticket_ungrant(log, tic);
xfs_log_ticket_ungrant(log, ctx->ticket);
/*
* If the checkpoint spans multiple iclogs, wait for all previous iclogs
@ -1116,7 +1133,7 @@ out_skip:
return;
out_abort_free_ticket:
xfs_log_ticket_ungrant(log, tic);
xfs_log_ticket_ungrant(log, ctx->ticket);
ASSERT(xlog_is_shutdown(log));
if (!ctx->commit_iclog) {
xlog_cil_committed(ctx);