]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: add a xlog_write_one_vec helper
authorChristoph Hellwig <hch@lst.de>
Thu, 22 May 2025 03:15:20 +0000 (05:15 +0200)
committerChristoph Hellwig <hch@lst.de>
Fri, 23 May 2025 03:27:52 +0000 (05:27 +0200)
Add a wrapper for xlog_write for the two callers who need to build a
log_vec and add it to a single-entry chain instead of duplicating the
code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_log.c
fs/xfs/xfs_log_cil.c
fs/xfs/xfs_log_priv.h

index 500f72929536ac12f1d1c48c72242d662c66a714..7323ed268c7d3c0564f41ead960c9e65a93ed19c 100644 (file)
@@ -792,6 +792,26 @@ xlog_wait_on_iclog(
        return 0;
 }
 
+int
+xlog_write_one_vec(
+       struct xlog             *log,
+       struct xfs_cil_ctx      *ctx,
+       struct xfs_log_iovec    *reg,
+       struct xlog_ticket      *ticket)
+{
+       struct xfs_log_vec      lv = {
+               .lv_niovecs     = 1,
+               .lv_iovecp      = reg,
+       };
+       LIST_HEAD               (lv_chain);
+
+       /* account for space used by record data */
+       ticket->t_curr_res -= reg->i_len;
+
+       list_add(&lv.lv_list, &lv_chain);
+       return xlog_write(log, ctx, &lv_chain, ticket, reg->i_len);
+}
+
 /*
  * Write out an unmount record using the ticket provided. We have to account for
  * the data space used in the unmount ticket as this write is not done from a
@@ -820,21 +840,8 @@ xlog_write_unmount_record(
                .i_len = sizeof(unmount_rec),
                .i_type = XLOG_REG_TYPE_UNMOUNT,
        };
-       struct xfs_log_vec vec = {
-               .lv_niovecs = 1,
-               .lv_iovecp = &reg,
-       };
-       LIST_HEAD(lv_chain);
-       list_add(&vec.lv_list, &lv_chain);
-
-       BUILD_BUG_ON((sizeof(struct xlog_op_header) +
-                     sizeof(struct xfs_unmount_log_format)) !=
-                                                       sizeof(unmount_rec));
-
-       /* account for space used by record data */
-       ticket->t_curr_res -= sizeof(unmount_rec);
 
-       return xlog_write(log, NULL, &lv_chain, ticket, reg.i_len);
+       return xlog_write_one_vec(log, NULL, &reg, ticket);
 }
 
 /*
index dd20ca57c1b9b281cdefe5be905d1553ef799eef..5a0f80cdfa5a7084c57446723c3bccf9226e93ba 100644 (file)
@@ -1194,13 +1194,7 @@ xlog_cil_write_commit_record(
                .i_len = sizeof(struct xlog_op_header),
                .i_type = XLOG_REG_TYPE_COMMIT,
        };
-       struct xfs_log_vec      vec = {
-               .lv_niovecs = 1,
-               .lv_iovecp = &reg,
-       };
        int                     error;
-       LIST_HEAD(lv_chain);
-       list_add(&vec.lv_list, &lv_chain);
 
        if (xlog_is_shutdown(log))
                return -EIO;
@@ -1208,10 +1202,7 @@ xlog_cil_write_commit_record(
        error = xlog_cil_order_write(ctx->cil, ctx->sequence, _COMMIT_RECORD);
        if (error)
                return error;
-
-       /* account for space used by record data */
-       ctx->ticket->t_curr_res -= reg.i_len;
-       error = xlog_write(log, ctx, &lv_chain, ctx->ticket, reg.i_len);
+       error = xlog_write_one_vec(log, ctx, &reg, ctx->ticket);
        if (error)
                xlog_force_shutdown(log, SHUTDOWN_LOG_IO_ERROR);
        return error;
index 39a102cc1b43e657e3c97665940bf5abba989c68..463daf51da1587006abac620198c899726e3954f 100644 (file)
@@ -511,6 +511,8 @@ void        xlog_print_trans(struct xfs_trans *);
 int    xlog_write(struct xlog *log, struct xfs_cil_ctx *ctx,
                struct list_head *lv_chain, struct xlog_ticket *tic,
                uint32_t len);
+int    xlog_write_one_vec(struct xlog *log, struct xfs_cil_ctx *ctx,
+               struct xfs_log_iovec *reg, struct xlog_ticket *ticket);
 void   xfs_log_ticket_ungrant(struct xlog *log, struct xlog_ticket *ticket);
 void   xfs_log_ticket_regrant(struct xlog *log, struct xlog_ticket *ticket);