IOCTL-XFS-SCRUB-METADATA(2)
β¨ NAME β¨
ioctl_xfs_scrub_metadata β check XFS filesystem metadata π
okay so real talk, this is a page from section 2, the System Calls Manual, and it's the whole entire tea on the XFS ioctl that goes "hey bestie, is my metadata okay or is it giving damaged". Buckle up, it's a long one π«Ά
π SYNOPSIS π
#include <xfs/xfs_fs.h>
int ioctl(int dest_fd, XFS_IOC_SCRUB_METADATA, struct xfs_scrub_metadata
*arg);
π¦ DESCRIPTION π¦
So basically, this XFS ioctl slides into the kernel driver and is like "bestie, pls examine a piece of filesystem metadata for errors or for suboptimal metadata" π. And "examine" here is doing a LOT of heavy lifting β it means:
- running the metadata verifiers,
- checking records for obviously incorrect or straight-up impossible values,
- and cross-referencing every record against any other available metadata in the filesystem. the way it cross-checks everything?? iconic π₯
This ioctl can also try to repair or optimize metadata, but heads up, that can block normal filesystem operations for a long period of time π so like, don't be shocked.
The type and location of the metadata you wanna scrub gets passed in a struct that looks exactly like this:
struct xfs_scrub_metadata {
__u32 sm_type;
__u32 sm_flags;
__u64 sm_ino;
__u32 sm_gen;
__u32 sm_agno;
__u64 sm_reserved[5];
};
The field sm_reserved must be zero. no exceptions, don't be cute with it π
πΈ sm_type β what are we even checking πΈ
The field sm_type tells the kernel the type of metadata to check:
XFS_SCRUB_TYPE_PROBEβ probe the kernel to see if it's even willing to try to check or repair this filesystem.sm_agno,sm_ino, andsm_genmust all be zero.XFS_SCRUB_TYPE_SB,XFS_SCRUB_TYPE_AGF,XFS_SCRUB_TYPE_AGFL,XFS_SCRUB_TYPE_AGIβ examine a given allocation group's superblock, free space header, free block list, or inode header, respectively. headers get checked for obviously incorrect values and cross-referenced against the allocation group's metadata btrees, if possible. you gotta put the allocation group number insm_agno. andsm_inoandsm_genmust be zero.XFS_SCRUB_TYPE_BNOBT,XFS_SCRUB_TYPE_CNTBT,XFS_SCRUB_TYPE_INOBT,XFS_SCRUB_TYPE_FINOBT,XFS_SCRUB_TYPE_RMAPBT,XFS_SCRUB_TYPE_REFCNTBTβ examine a given allocation group's two free space btrees, two inode btrees, reverse mapping btrees, or reference count btrees, respectively. records get checked for obviously incorrect values and cross-referenced with other allocation group metadata records so we can be sure there are no conflicts π¨. the allocation group number goes insm_agno, andsm_inoandsm_genmust be zero.XFS_SCRUB_TYPE_RGSUPERβ examine a given realtime allocation group's superblock. the realtime allocation group number goes insm_agno.sm_inoandsm_genmust be zero.XFS_SCRUB_TYPE_INODEβ examine a given inode record for obviously incorrect values and discrepancies with the rest of the filesystem metadata. parent pointers get checked for impossible inode values and then followed up to the parent directory to make sure the linkage is correct π§. you can specify the inode to examine either throughsm_inoandsm_gen, or, if you don't specify it, then the file described bydest_fdgets examined instead.sm_agnomust be zero.XFS_SCRUB_TYPE_BMBTD,XFS_SCRUB_TYPE_BMBTA,XFS_SCRUB_TYPE_BMBTCβ examine a given inode's data block map, extended attribute block map, or copy on write block map. inode records get examined for obviously incorrect values and discrepancies with the three block map types. the block maps get checked for obviously wrong values and cross-referenced with the allocation group space extent metadata to catch discrepancies. the inode to examine can be specified in the same manner asXFS_SCRUB_TYPE_INODE.XFS_SCRUB_TYPE_XATTRβ examine the extended attribute records and indices of a given inode for incorrect pointers and other signs of damage π. the inode to examine can be specified in the same manner asXFS_SCRUB_TYPE_INODE.XFS_SCRUB_TYPE_DIRβ examine the entries in a given directory for invalid data or dangling pointers. if the filesystem supports directory parent pointers, every entry gets checked to confirm that the child file has a matching parent pointer π. the directory to examine can be specified in the same manner asXFS_SCRUB_TYPE_INODE.XFS_SCRUB_TYPE_PARENTβ for filesystems that support directory parent pointers, this scrubber examines all the parent pointers attached to a file and confirms that the parent directory has an entry matching the parent pointer. for filesystems that do not support directory parent pointers, this scrubber instead checks that a subdirectory's dotdot entry points to a directory with an entry that points back to the subdirectory π. the inode to examine can be specified in the same manner asXFS_SCRUB_TYPE_INODE.XFS_SCRUB_TYPE_DIRTREEβ this scrubber looks for problems in the directory tree structure, like loops and directories reachable through more than one path π. problems get detected by walking parent pointers upwards towards the root. loops get detected by comparing the parent directory at each step against the directories already examined. directories with multiple paths get detected by counting the parent pointers attached to a directory. non-directories don't have links pointing away from the directory tree root and can be skipped, so don't even worry about them. the directory to examine can be specified in the same manner asXFS_SCRUB_TYPE_INODE.XFS_SCRUB_TYPE_SYMLINKβ examine the target of a symbolic link for obvious pathname problems π. the link to examine can be specified in the same manner asXFS_SCRUB_TYPE_INODE.XFS_SCRUB_TYPE_RTBITMAP,XFS_SCRUB_TYPE_RTSUM,XFS_SCRUB_TYPE_RTRMAPBT,XFS_SCRUB_TYPE_RTREFCBTβ examine a given realtime allocation group's free space bitmap, summary file, reverse mapping btree, or reference count btree, respectively.XFS_SCRUB_TYPE_UQUOTA,XFS_SCRUB_TYPE_GQUOTA,XFS_SCRUB_TYPE_PQUOTAβ examine all user, group, or project quota records for corruption π§Ύ.XFS_SCRUB_TYPE_FSCOUNTERSβ examine all filesystem summary counters (free blocks, inode count, free inode count) for errors.XFS_SCRUB_TYPE_NLINKSβ scan all inodes in the filesystem to verify each file's link count π’.XFS_SCRUB_TYPE_HEALTHYβ mark everything healthy after a clean scrub run β¨. this clears out all the indirect health problem markers that might still be lurking in the system.XFS_SCRUB_TYPE_METAPATHβ check that a metadata directory path actually points to the active metadata inode. metadata inodes are usually cached for the duration of the mount, so this scrubber makes sure that the same inode will still be reachable after an unmount and mount cycle π. discrepancies can happen if the directory or parent pointer scrubbers rebuild a metadata directory but lose a link in the process.sm_inoshould be passed one of the following special values to communicate which path to check:XFS_SCRUB_METAPATH_RTDIRβ realtime metadata file subdirectory.XFS_SCRUB_METAPATH_RTBITMAPβ realtime bitmap file.XFS_SCRUB_METAPATH_RTSUMMARYβ realtime summary file.XFS_SCRUB_METAPATH_QUOTADIRβ quota metadata file subdirectory.XFS_SCRUB_METAPATH_USRQUOTAβ user quota file.XFS_SCRUB_METAPATH_GRPQUOTAβ group quota file.XFS_SCRUB_METAPATH_PRJQUOTAβ project quota file.XFS_SCRUB_METAPATH_RTRMAPBTβ realtime rmap btree file.XFS_SCRUB_METAPATH_RTREFCOUNTBTβ realtime reference count btree file.
and for this one, the values of sm_agno and sm_gen must be zero.
π sm_flags β behavior + the receipts π
The field sm_flags controls the behavior of the scrub operation and also carries more info about how the operation turned out π. And here's the vibe check: if none of the XFS_SCRUB_OFLAG_* flags are set when the call returns, the metadata is clean β¨.
XFS_SCRUB_IFLAG_REPAIRβ if the caller sets this flag, the kernel driver will examine the metadata and try to fix all the problems and optimize the metadata when possible π οΈ. if no errors happen during the repair operation, the check gets performed a second time to determine whether the repair actually succeeded. if errors happen, the call returns an error status immediately.XFS_SCRUB_OFLAG_CORRUPTβ the metadata was corrupt when the call returned π. ifXFS_SCRUB_IFLAG_REPAIRwas specified, then an attempted repair failed to fix the problem. unmount the filesystem and runxfs_repairto fix the filesystem.XFS_SCRUB_OFLAG_PREENβ the metadata is ok, but some aspect of it could be optimized to increase performance π. call again withXFS_SCRUB_IFLAG_REPAIRto optimize the metadata.XFS_SCRUB_OFLAG_XFAILβ filesystem errors were encountered when accessing other metadata to cross-reference the records attached to this metadata object π.XFS_SCRUB_OFLAG_XCORRUPTβ discrepancies were found when cross-referencing the records attached to this metadata object against all other available metadata in the system π.XFS_SCRUB_OFLAG_INCOMPLETEβ the checker was unable to complete its check of all records π.XFS_SCRUB_OFLAG_WARNINGβ the checker encountered a metadata object with potentially problematic records. however, the records were not obviously corrupt. so like, sus but not confirmed π€.
For metadata checkers that operate on inodes or inode metadata, the fields sm_ino and sm_gen are the inode number and generation number of the inode to check π§. if the inode number is zero, the inode represented by dest_fd gets used instead. if the generation number of the inode doesn't match sm_gen, the call will return an error code for the invalid argument π«. and the sm_agno field must be zero.
bestie this page is long and it does not end here β there's more coming in part 2, so don't go anywhere π
okay bestie, picking up right where we left off π for the metadata checkers that do their thing on allocation group metadata, the field sm_agno tells you which allocation group to go dig around in for that metadata. and the sm_ino and sm_gen fields? yeah those gotta be zero. no exceptions, babe. π
ββοΈ
and for the metadata checkers that work on filesystem-wide metadata? no extra arguments needed, you're already that girl. sm_agno, sm_ino, and sm_gen must all be zero. periodt. π
β¨ RETURN VALUE β¨
if something goes wrong, -1 gets returned and errno gets set to spill all the tea about what happened. π
π ERRORS π
so the error codes can be one of these, but ngl it's not limited to these either β the universe is vast and so is the error space:
EBUSYβ the filesystem object is busy bestie π© like it's occupied. you're gonna have to try the whole operation again later.EFSCORRUPTEDβ yikes!! severe filesystem corruption was detected and it could not be repaired. unmount the filesystem and runxfs_repairto fix the filesystem. no skipping this step, fr fr.EINVALβ one or more of the arguments you specified is invalid. check ur inputs bestie πENOENTβ the specified metadata object does not exist. for example, this error code is returned for aXFS_SCRUB_TYPE_REFCNTBTrequest on a filesystem that does not support reflink. it's giving "you're looking for something that was never there" πENOMEMβ there was not sufficient memory to perform the scrub or repair operation. some operations (most notably reference count checking) require large amounts of memory. she's hungry and you didn't feed her πENOSPCβ there is not enough free disk space to attempt a repair. disk said "no room at the inn" πENOTRECOVERABLEβ filesystem was mounted innorecoverymode and therefore has an unclean log. neither scrub nor repair operations can be attempted with an unclean log. like, at all. don't even try it.ENOTTYβ online scrubbing or repair were not enabled. the feature said "not today" π ββοΈEOPNOTSUPPβ repairs of the requested metadata object are not supported. it's just not in her repertoire, queen. πEROFSβ filesystem is read-only and a repair was requested. you literally cannot write to a read-only filesystem bestie, that's the whole vibe. πESHUTDOWNβ filesystem is shut down due to previous errors. she's not coming to the function rn, previous drama took her out. π
π CONFORMING TO π
this API is specific to XFS filesystem on the Linux kernel. iykyk. no portability arc here, it's a one-filesystem kinda love story. π¦
π NOTES π
okay real talk for a sec bestie: these operations may block other filesystem operations for a long time. like, a while. a minute. potentially more. so plan accordingly. β³
a calling process can stop the operation by being sent a fatal signal, but heads up β non-fatal signals are blocked. so like, if you're trying to politely nudge it with something non-fatal, that's not gonna land. only the fatal ones get through, periodt. π
β SEE ALSO β
go read those too, they're iconic. πβ¨
and that's a wrap on the whole page bestie!! πβ¨ this one came from the XFS corner of the world, dated 2017-12-01, and it lives as IOCTL-XFS-SCRUB-METADATA(2) in the manual. slay, ate, no crumbs left. πππ¦
π¦ where this page comes from
- alpine 3.22: xfsprogs-doc 6.14.0-r0 Β· LGPL-2.1-or-later
- alpine 3.23: xfsprogs-doc 6.17.0-r0 Β· LGPL-2.1-or-later
- alpine 3.24: xfsprogs-doc 7.0.1-r0 Β· LGPL-2.1-or-later
- arch rolling: xfsprogs 7.2.0-1
- arch rolling: xfsprogs 7.2.1-1 Β· GPL-2.0-only AND LGPL-2.1-only
- centos-stream 10: xfsprogs-devel 6.16.0-1.el10 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 43: xfsprogs-devel 6.15.0-3.fc43 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 43: xfsprogs-devel 6.15.0-3.fc43 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 6.18.0-2.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 6.18.0-2.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 7.1.1-1.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 7.1.1-1.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- nixos 26.05: xfsprogs 6.19.0
- nixpkgs unstable: xfsprogs 7.2.1
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- ubuntu resolute: xfslibs-dev 6.18.0-3 Β· GPL-2.0-only
- ubuntu stonking: xfslibs-dev 6.19.0-1 Β· GPL-2.0-only
- π the page's license: GPL-2.0+
- Copyright (c) 2017, Oracle. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms