]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: fix log CRC mismatches between i386 and other architectures
authorChristoph Hellwig <hch@lst.de>
Fri, 5 Dec 2025 15:03:59 +0000 (16:03 +0100)
committerAndrey Albershteyn <aalbersh@kernel.org>
Mon, 8 Dec 2025 17:03:15 +0000 (18:03 +0100)
Source kernel commit: e747883c7d7306acb4d683038d881528fbfbe749

When mounting file systems with a log that was dirtied on i386 on
other architectures or vice versa, log recovery is unhappy:

[   11.068052] XFS (vdb): Torn write (CRC failure) detected at log block 0x2. Truncating head block from 0xc.

This is because the CRCs generated by i386 and other architectures
always diff.  The reason for that is that sizeof(struct xlog_rec_header)
returns different values for i386 vs the rest (324 vs 328), because the
struct is not sizeof(uint64_t) aligned, and i386 has odd struct size
alignment rules.

This issue goes back to commit 13cdc853c519 ("Add log versioning, and new
super block field for the log stripe") in the xfs-import tree, which
adds log v2 support and the h_size field that causes the unaligned size.
At that time it only mattered for the crude debug only log header
checksum, but with commit 0e446be44806 ("xfs: add CRC checks to the log")
it became a real issue for v5 file system, because now there is a proper
CRC, and regular builds actually expect it match.

Fix this by allowing checksums with and without the padding.

Fixes: 0e446be44806 ("xfs: add CRC checks to the log")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
libxfs/xfs_log_format.h
libxfs/xfs_ondisk.h

index a42a8321172459ba58631beecca82b75165b0d0a..fd00b77af32b9daf1f0ed98a80e82d4699194c7d 100644 (file)
@@ -173,12 +173,40 @@ typedef struct xlog_rec_header {
        __be32    h_prev_block; /* block number to previous LR          :  4 */
        __be32    h_num_logops; /* number of log operations in this LR  :  4 */
        __be32    h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
-       /* new fields */
+
+       /* fields added by the Linux port: */
        __be32    h_fmt;        /* format of log record                 :  4 */
        uuid_t    h_fs_uuid;    /* uuid of FS                           : 16 */
+
+       /* fields added for log v2: */
        __be32    h_size;       /* iclog size                           :  4 */
+
+       /*
+        * When h_size added for log v2 support, it caused structure to have
+        * a different size on i386 vs all other architectures because the
+        * sum of the size ofthe  member is not aligned by that of the largest
+        * __be64-sized member, and i386 has really odd struct alignment rules.
+        *
+        * Due to the way the log headers are placed out on-disk that alone is
+        * not a problem becaue the xlog_rec_header always sits alone in a
+        * BBSIZEs area, and the rest of that area is padded with zeroes.
+        * But xlog_cksum used to calculate the checksum based on the structure
+        * size, and thus gives different checksums for i386 vs the rest.
+        * We now do two checksum validation passes for both sizes to allow
+        * moving v5 file systems with unclean logs between i386 and other
+        * (little-endian) architectures.
+        */
+       __u32     h_pad0;
 } 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)
+#else
+#define XLOG_REC_SIZE          sizeof(struct xlog_rec_header)
+#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_HEADER_CYCLE_SIZE / BBSIZE]; /*    : 256 */
index 5ed44fdf7491056a4011596151285cd00be29c91..7bfa3242e2c536bb519130ac01c730ce214b1891 100644 (file)
@@ -174,6 +174,8 @@ 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_OFFSET(struct xfs_bui_log_format, bui_extents,        16);
        XFS_CHECK_OFFSET(struct xfs_cui_log_format, cui_extents,        16);