]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
xfs: remove xlog_in_core_2_t
authorChristoph Hellwig <hch@lst.de>
Sun, 22 Feb 2026 22:41:00 +0000 (14:41 -0800)
committerAndrey Albershteyn <aalbersh@kernel.org>
Mon, 2 Mar 2026 09:54:27 +0000 (10:54 +0100)
Source kernel commit: fe985b910e03fd91193f399a1aca9d1ea22c2557

xlog_in_core_2_t is a really odd type, not only is it grossly
misnamed because it actually is an on-disk structure, but it also
reprents the actual on-disk structure in a rather odd way.

A v1 or small v2 log header look like:

+-----------------------+
|      xlog_record      |
+-----------------------+

while larger v2 log headers look like:

+-----------------------+
|      xlog_record      |
+-----------------------+
|  xlog_rec_ext_header  |
+-------------------+---+
|         .....         |
+-----------------------+
|  xlog_rec_ext_header  |
+-----------------------+

I.e., the ext headers are a variable sized array at the end of the
header.  So instead of declaring a union of xlog_rec_header,
xlog_rec_ext_header and padding to BBSIZE, add the proper padding to
struct struct xlog_rec_header and struct xlog_rec_ext_header, and
add a variable sized array of the latter to the former.  This also
exposes the somewhat unusual scope of the log checksums, which is
made explicitly now by adding proper padding and macro designating
the actual payload length.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_log_format.h
libxfs/xfs_ondisk.h
libxlog/xfs_log_recover.c

index 91a841ea5bb36d3606e510abd6e07958b9cb17e4..4cb69bd285ca13cc29cf7de6e07beb016f41688b 100644 (file)
@@ -126,6 +126,16 @@ struct xlog_op_header {
 #define XLOG_FMT XLOG_FMT_LINUX_LE
 #endif
 
+struct xlog_rec_ext_header {
+       __be32          xh_cycle;       /* write cycle of log */
+       __be32          xh_cycle_data[XLOG_CYCLE_DATA_SIZE];
+       __u8            xh_reserved[252];
+};
+
+/* actual ext header payload size for checksumming */
+#define XLOG_REC_EXT_SIZE \
+       offsetofend(struct xlog_rec_ext_header, xh_cycle_data)
+
 typedef struct xlog_rec_header {
        __be32    h_magicno;    /* log record (LR) identifier           :  4 */
        __be32    h_cycle;      /* write cycle of log                   :  4 */
@@ -161,30 +171,19 @@ typedef struct xlog_rec_header {
         * (little-endian) architectures.
         */
        __u32     h_pad0;
+
+       __u8      h_reserved[184];
+       struct xlog_rec_ext_header h_ext[];
 } xlog_rec_header_t;
 
 #ifdef __i386__
 #define XLOG_REC_SIZE          offsetofend(struct xlog_rec_header, h_size)
-#define XLOG_REC_SIZE_OTHER    sizeof(struct xlog_rec_header)
+#define XLOG_REC_SIZE_OTHER    offsetofend(struct xlog_rec_header, h_pad0)
 #else
-#define XLOG_REC_SIZE          sizeof(struct xlog_rec_header)
+#define XLOG_REC_SIZE          offsetofend(struct xlog_rec_header, h_pad0)
 #define XLOG_REC_SIZE_OTHER    offsetofend(struct xlog_rec_header, h_size)
 #endif /* __i386__ */
 
-typedef struct xlog_rec_ext_header {
-       __be32    xh_cycle;     /* write cycle of log                   : 4 */
-       __be32    xh_cycle_data[XLOG_CYCLE_DATA_SIZE];          /*      : 256 */
-} xlog_rec_ext_header_t;
-
-/*
- * Quite misnamed, because this union lays out the actual on-disk log buffer.
- */
-typedef union xlog_in_core2 {
-       xlog_rec_header_t       hic_header;
-       xlog_rec_ext_header_t   hic_xheader;
-       char                    hic_sector[XLOG_HEADER_SIZE];
-} xlog_in_core_2_t;
-
 /* not an on-disk structure, but needed by log recovery in userspace */
 struct xfs_log_iovec {
        void            *i_addr;        /* beginning address of region */
index 7bfa3242e2c536bb519130ac01c730ce214b1891..2e9715cc1641dfc3b3dc82cbe766d966253143e4 100644 (file)
@@ -174,9 +174,11 @@ xfs_check_ondisk_structs(void)
        XFS_CHECK_STRUCT_SIZE(struct xfs_rud_log_format,        16);
        XFS_CHECK_STRUCT_SIZE(struct xfs_map_extent,            32);
        XFS_CHECK_STRUCT_SIZE(struct xfs_phys_extent,           16);
-       XFS_CHECK_STRUCT_SIZE(struct xlog_rec_header,           328);
-       XFS_CHECK_STRUCT_SIZE(struct xlog_rec_ext_header,       260);
+       XFS_CHECK_STRUCT_SIZE(struct xlog_rec_header,           512);
+       XFS_CHECK_STRUCT_SIZE(struct xlog_rec_ext_header,       512);
 
+       XFS_CHECK_OFFSET(struct xlog_rec_header, h_reserved,            328);
+       XFS_CHECK_OFFSET(struct xlog_rec_ext_header, xh_reserved,       260);
        XFS_CHECK_OFFSET(struct xfs_bui_log_format, bui_extents,        16);
        XFS_CHECK_OFFSET(struct xfs_cui_log_format, cui_extents,        16);
        XFS_CHECK_OFFSET(struct xfs_rui_log_format, rui_extents,        16);
index 6ab8b8b0635c7bc53f053aebca8df8b7b1be57ba..843b8e9c47a4551e32289469b73f5d66ded61c57 100644 (file)
@@ -1324,35 +1324,41 @@ xlog_unpack_data_crc(
        return 0;
 }
 
+/*
+ * Cycles over XLOG_CYCLE_DATA_SIZE overflow into the extended header that was
+ * added for v2 logs.  Addressing for the cycles array there is off by one,
+ * because the first batch of cycles is in the original header.
+ */
+static inline __be32 *xlog_cycle_data(struct xlog_rec_header *rhead, unsigned i)
+{
+       if (i >= XLOG_CYCLE_DATA_SIZE) {
+               unsigned        j = i / XLOG_CYCLE_DATA_SIZE;
+               unsigned        k = i % XLOG_CYCLE_DATA_SIZE;
+
+               return &rhead->h_ext[j - 1].xh_cycle_data[k];
+       }
+
+       return &rhead->h_cycle_data[i];
+}
+
 STATIC int
 xlog_unpack_data(
        struct xlog_rec_header  *rhead,
        char                    *dp,
        struct xlog             *log)
 {
-       int                     i, j, k;
+       int                     i;
        int                     error;
 
        error = xlog_unpack_data_crc(rhead, dp, log);
        if (error)
                return error;
 
-       for (i = 0; i < BTOBB(be32_to_cpu(rhead->h_len)) &&
-                 i < XLOG_CYCLE_DATA_SIZE; i++) {
-               *(__be32 *)dp = *(__be32 *)&rhead->h_cycle_data[i];
+       for (i = 0; i < BTOBB(be32_to_cpu(rhead->h_len)); i++) {
+               *(__be32 *)dp = *xlog_cycle_data(rhead, i);
                dp += BBSIZE;
        }
 
-       if (xfs_has_logv2(log->l_mp)) {
-               xlog_in_core_2_t *xhdr = (xlog_in_core_2_t *)rhead;
-               for ( ; i < BTOBB(be32_to_cpu(rhead->h_len)); i++) {
-                       j = i / XLOG_CYCLE_DATA_SIZE;
-                       k = i % XLOG_CYCLE_DATA_SIZE;
-                       *(__be32 *)dp = xhdr[j].hic_xheader.xh_cycle_data[k];
-                       dp += BBSIZE;
-               }
-       }
-
        return 0;
 }