Documentation/filesystems/xfs/xfs-self-describing-metadata.rst

Source file repositories/reference/linux-study-clean/Documentation/filesystems/xfs/xfs-self-describing-metadata.rst

File Facts

System
Linux kernel
Corpus path
Documentation/filesystems/xfs/xfs-self-describing-metadata.rst
Extension
.rst
Size
17052 bytes
Lines
354
Domain
Support Tooling And Documentation
Bucket
Documentation
Inferred role
Support Tooling And Documentation: documentation
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct xfs_ondisk_hdr {
	    __be32  magic;		/* magic number */
	    __be32  crc;		/* CRC, not logged */
	    uuid_t  uuid;		/* filesystem identifier */
	    __be64  owner;		/* parent object */
	    __be64  blkno;		/* location on disk */
	    __be64  lsn;		/* last modification in log, not logged */
    };

Depending on the metadata, this information may be part of a header structure
separate to the metadata contents, or may be distributed through an existing
structure. The latter occurs with metadata that already contains some of this
information, such as the superblock and AG headers.

Other metadata may have different formats for the information, but the same
level of information is generally provided. For example:

	- short btree blocks have a 32 bit owner (ag number) and a 32 bit block
	  number for location. The two of these combined provide the same
	  information as @owner and @blkno in eh above structure, but using 8
	  bytes less space on disk.

	- directory/attribute node blocks have a 16 bit magic number, and the
	  header that contains the magic number has other information in it as
	  well. hence the additional metadata headers change the overall format
	  of the metadata.

A typical buffer read verifier is structured as follows::

    #define XFS_FOO_CRC_OFF		offsetof(struct xfs_ondisk_hdr, crc)

    static void
    xfs_foo_read_verify(
	    struct xfs_buf	*bp)
    {
	struct xfs_mount *mp = bp->b_mount;

	    if ((xfs_sb_version_hascrc(&mp->m_sb) &&
		!xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length),
					    XFS_FOO_CRC_OFF)) ||
		!xfs_foo_verify(bp)) {
		    XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr);
		    xfs_buf_ioerror(bp, EFSCORRUPTED);
	    }
    }

The code ensures that the CRC is only checked if the filesystem has CRCs enabled
by checking the superblock of the feature bit, and then if the CRC verifies OK
(or is not needed) it verifies the actual contents of the block.

The verifier function will take a couple of different forms, depending on
whether the magic number can be used to determine the format of the block. In
the case it can't, the code is structured as follows::

    static bool
    xfs_foo_verify(
	    struct xfs_buf		*bp)
    {
	    struct xfs_mount	*mp = bp->b_mount;
	    struct xfs_ondisk_hdr	*hdr = bp->b_addr;

	    if (hdr->magic != cpu_to_be32(XFS_FOO_MAGIC))
		    return false;

	    if (!xfs_sb_version_hascrc(&mp->m_sb)) {
		    if (!uuid_equal(&hdr->uuid, &mp->m_sb.sb_uuid))
			    return false;
		    if (bp->b_bn != be64_to_cpu(hdr->blkno))
			    return false;
		    if (hdr->owner == 0)

Annotation

Implementation Notes