OSDN Git Service

xfs: compile time offset checks for common v4/v5 metadata
authorBrian Foster <bfoster@redhat.com>
Fri, 8 Feb 2019 17:02:29 +0000 (09:02 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Tue, 12 Feb 2019 00:07:01 +0000 (16:07 -0800)
The v5 superblock format added various metadata fields (such as crc,
metadata lsn, owner uuid, etc.) to v4 metadata headers or created
new v5 headers for blocks where no such headers existed on v4. Where
v4 headers did exist, the v5 structures are careful to place v4
metadata at the original location. For example, the magic value is
expected to be at the same location in certain blocks to facilitate
version detection.

While failure of this invariant is likely to cause severe and
obvious problems at runtime, we can detect this condition at compile
time via the more recently added on-disk format check
infrastructure. Since there is no runtime cost, add some offset
checks that start with v5 structure definitions, traverse down to
the first bit of common metadata with v4 and ensure that common
metadata is at the expected offset. Note that we don't care about
blocks which had no v4 header because there is no common metadata in
those cases. No functional changes.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/xfs/xfs_ondisk.h

index d3e04d2..c8ba98f 100644 (file)
@@ -125,6 +125,27 @@ xfs_check_ondisk_structs(void)
        XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format,      56);
        XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat,        20);
        XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header,          16);
+
+       /*
+        * The v5 superblock format extended several v4 header structures with
+        * additional data. While new fields are only accessible on v5
+        * superblocks, it's important that the v5 structures place original v4
+        * fields/headers in the correct location on-disk. For example, we must
+        * be able to find magic values at the same location in certain blocks
+        * regardless of superblock version.
+        *
+        * The following checks ensure that various v5 data structures place the
+        * subset of v4 metadata associated with the same type of block at the
+        * start of the on-disk block. If there is no data structure definition
+        * for certain types of v4 blocks, traverse down to the first field of
+        * common metadata (e.g., magic value) and make sure it is at offset
+        * zero.
+        */
+       XFS_CHECK_OFFSET(struct xfs_dir3_leaf, hdr.info.hdr,    0);
+       XFS_CHECK_OFFSET(struct xfs_da3_intnode, hdr.info.hdr,  0);
+       XFS_CHECK_OFFSET(struct xfs_dir3_data_hdr, hdr.magic,   0);
+       XFS_CHECK_OFFSET(struct xfs_dir3_free, hdr.hdr.magic,   0);
+       XFS_CHECK_OFFSET(struct xfs_attr3_leafblock, hdr.info.hdr, 0);
 }
 
 #endif /* __XFS_ONDISK_H */