summaryrefslogtreecommitdiff
path: root/fs/xfs/scrub
AgeCommit message (Collapse)Author
2022-10-14xfs: refactor realtime inode lockingDarrick J. Wong
Create helper functions to deal with locking realtime metadata inodes. This enables us to maintain correct locking order once we start adding the realtime rmap and refcount btree inodes. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: use accessor functions for summary info wordsrefactor-rtbitmap-macros_2022-10-14Darrick J. Wong
Create get and set functions for rtsummary words so that we can redefine the ondisk format with a specific endianness. Note that this requires the definition of a distinct type for ondisk summary info words so that the compiler can perform proper typechecking. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: create helpers for rtsummary block/wordcount computationsDarrick J. Wong
Create helper functions that compute the number of blocks or words necessary to store the rt summary file. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: create helpers for rtbitmap block/wordcount computationsDarrick J. Wong
Create helper functions that compute the number of blocks or words necessary to store the rt bitmap. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: convert rt summary macros to helpersDarrick J. Wong
Convert the realtime summary file macros to helper functions so that we can improve type checking. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: convert the rtbitmap block and bit macros to static inline functionsDarrick J. Wong
Replace these macros with typechecked helper functions. Eventually we're going to add more logic to the helpers and it'll be easier if we don't have to macro it up. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: convert do_div calls to xfs_rtb_to_rtx helper callsDarrick J. Wong
Convert these calls to use the helpers, and clean up all these places where the same variable can have different units depending on where it is in the function. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: create a helper to compute leftovers of realtime extentsDarrick J. Wong
Create a helper to compute the misalignment between a file extent (xfs_extlen_t) and a realtime extent. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: create a helper to convert rtextents to rtblocksDarrick J. Wong
Create a helper to convert a realtime extent to a realtime block. Later on we'll change the helper to use bit shifts when possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: convert rt extent numbers to xfs_rtxnum_tclean-up-realtime-units_2022-10-14Darrick J. Wong
Further disambiguate the xfs_rtblock_t uses by creating a new type, xfs_rtxnum_t, to store the position of an extent within the realtime section, in units of rtextents. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: rename xfs_verify_rtext to xfs_verify_rtbextDarrick J. Wong
This helper function validates that a range of *blocks* in the realtime section is completely contained within the realtime section. It does /not/ validate ranges of *rtextents*. Rename the function to avoid suggesting that it does, and change the type of the @len parameter since xfs_rtblock_t is a position unit, not a length unit. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: convert rt bitmap extent lengths to xfs_rtbxlen_tDarrick J. Wong
XFS uses xfs_rtblock_t for many different uses, which makes it much more difficult to perform a unit analysis on the codebase. One of these (ab)uses is when we need to store the length of a free space extent as stored in the realtime bitmap. Because there can be up to 2^64 realtime extents in a filesystem, we need a new type that is larger than xfs_rtxlen_t for callers that are querying the bitmap directly. This means scrub and growfs. Create this type as "xfs_rtbxlen_t" and use it to store 64-bit rtx lengths. 'b' stands for 'bitmap' or 'big'; reader's choice. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: convert rt bitmap/summary block numbers to xfs_fileoff_tDarrick J. Wong
We should use xfs_fileoff_t to store the file block offset of any location within the realtime bitmap or summary files. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocatorDarrick J. Wong
In most of the filesystem, we use xfs_extlen_t to store the length of a file (or AG) space mapping in units of fs blocks. Unfortunately, the realtime allocator also uses it to store the length of a rt space mapping in units of rt extents. This is confusing, since one rt extent can consist of many fs blocks. Separate the two by introducing a new type (xfs_rtxlen_t) to store the length of a space mapping (in units of realtime extents) that would be found in a file. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.hDarrick J. Wong
Move all the declarations for functionality in xfs_rtbitmap.c into a separate xfs_rtbitmap.h header file. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: refactor realtime scrubbing context managementDarrick J. Wong
Create a pair of helpers to deal with setting up the necessary incore context to check metadata records against the realtime metadata. Right now this is limited to locking the realtime bitmap and summary inodes, but as we add rmap and reflink to the realtime device this will grow to include btree cursors. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: support leaves in the incore btree root block in xfs_iroot_reallocDarrick J. Wong
Add some logic to xfs_iroot_realloc so that we can handle leaf records in the btree root block correctly. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: replace shouty XFS_BM{BT,DR} macrosDarrick J. Wong
Replace all the shouty bmap btree and bmap disk root macros with actual functions, and fix a type handling error in the xattr code that the macros previously didn't care about. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: don't check secondary super inode pointers when metadir enabledDarrick J. Wong
When metadata directories are enabled, the rt and quota inodes are no longer pointed to by the superblock, so it doesn't make sense to check these. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: teach nlink scrubber to deal with metadata directory rootsDarrick J. Wong
Enhance the inode link count online fsck code alter their behavior when they detect metadata directory tree roots, just like they do for the regular root directory. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: scrub metadata directoriesDarrick J. Wong
Teach online scrub about the metadata directory tree. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: hide metadata inodes from everyone because they are specialDarrick J. Wong
Metadata inodes are private files and therefore cannot be exposed to userspace. This means no bulkstat, no open-by-handle, no linking them into the directory tree, and no feeding them to LSMs. As such, we mark them S_PRIVATE, which stops all that. While we're at it, put them in a separate lockdep class so that it won't get confused by "recursive" i_rwsem locking such as what happens when we write to a rt file and need to allocate from the rt bitmap file. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: disable the agi rotor for metadata inodesDarrick J. Wong
Ideally, we'd put all the metadata inodes in one place if we could, so that the metadata all stay reasonably close together instead of spreading out over the disk. Furthermore, if the log is internal we'd probably prefer to keep the metadata near the log. Therefore, disable AGI rotoring for metadata inode allocations. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: enforce metadata inode flagDarrick J. Wong
Add checks for the metadata inode flag so that we don't ever leak metadata inodes out to userspace, and we don't ever try to read a regular inode as metadata. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: wrap inode creation dqalloc callsDarrick J. Wong
Create a helper that calls dqalloc to allocate and grab a reference to dquots for the user, group, and project ids listed in an icreate structure. This simplifies the creat-related dqalloc callsites scattered around the code base. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: pack icreate initialization parameters into a separate structureDarrick J. Wong
Callers that want to create an inode currently pass all possible file attribute values for the new inode into xfs_init_new_inode as ten separate parameters. This causes two code maintenance issues: first, we have large multi-line call sites which programmers must read carefully to make sure they did not accidentally invert a value. Second, all three file id parameters must be passed separately to the quota functions; any discrepancy results in quota count errors. Clean this up by creating a new icreate_args structure to hold all this information, some helpers to initialize them properly, and make the callers pass this structure through to the creation function, whose name we shorten to xfs_icreate. This eliminates the issues, enables us to keep the inode init code in sync with userspace via libxfs, and is needed for future metadata directory tree management. (A subsequent cleanup will also fix the quota alloc calls.) Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: repair AGI unlinked inode bucket listsrepair-iunlink_2022-10-14Darrick J. Wong
Teach the AGI repair code to rebuild the unlinked buckets and lists. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: hoist AGI repair context to a heap objectDarrick J. Wong
Save ~460 bytes of stack space by moving all the repair context to a heap object. We're going to add even more context data in the next patch, which is why we really need to do this now. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: check AGI unlinked inode bucketsDarrick J. Wong
Look for corruptions in the AGI unlinked bucket chains. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: online repair of symbolic linksrepair-symlink_2022-10-14Darrick J. Wong
If a symbolic link target looks bad, try to sift through the rubble to find as much of the target buffer that we can, and stage a new target (short or remote format as needed) in a temporary file and use the atomic extent swapping mechanism to commit the results. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: ensure dentry consistency when the orphanage adopts a filerepair-orphanage_2022-10-14Darrick J. Wong
When the orphanage adopts a file, that file becomes a child of the orphanage. The dentry cache may have entries for the orphanage directory and the name we've chosen, so (1) make sure we abort if the dcache has a positive entry because something's not right; and (2) invalidate and purge negative dentries if the adoption goes through. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: move files to orphanage instead of letting nlinks drop to zeroDarrick J. Wong
If we encounter an inode with a nonzero link count but zero observed links, move it to the orphanage. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: move orphan files to the orphanageDarrick J. Wong
If we can't find a parent for a file, move it to the orphanage. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: ask the dentry cache if it knows the parent of a directoryrepair-dirs_2022-10-14Darrick J. Wong
It's possible that the dentry cache can tell us the parent of a directory. Therefore, when repairing directory dot dot entries, query the dcache as a last resort before scanning the entire filesystem. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: online repair of parent pointersDarrick J. Wong
Teach the online repair code to fix directory '..' entries (aka directory parent pointers). Since this requires us to know how to scan every dirent in every directory on the filesystem, we can reuse the parent scanner components to validate (or find!) the correct parent entry when rebuilding directories too. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: online repair of directoriesDarrick J. Wong
If a directory looks like it's in bad shape, try to sift through the rubble to find whatever directory entries we can, scan the directory tree for the parent (if needed), stage the new directory contents in a temporary file and use the atomic extent swapping mechanism to commit the results in bulk. As a side effect of this patch, directory inactivation will be able to purge any leftover dir blocks. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: flag empty xattr leaf blocks for optimizationrepair-xattrs_2022-10-14Darrick J. Wong
Empty xattr leaf blocks at offset zero are a waste of space but otherwise harmless. If we encounter one, flag it as an opportunity for optimization. If we encounter empty attr leaf blocks anywhere else in the attr fork, that's corruption. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: scrub should set preen if attr leaf has holesDarrick J. Wong
If an attr block indicates that it could use compaction, set the preen flag to have the attr fork rebuilt, since the attr fork rebuilder can take care of that for us. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-10-14xfs: repair extended attributesDarrick J. Wong
If the extended attributes look bad, try to sift through the rubble to find whatever keys/values we can, stage a new attribute structure in a temporary file and use the atomic extent swapping mechanism to commit the results in bulk. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: use atomic extent swapping to fix user file fork dataDarrick J. Wong
Build on the code that was recently added to the temporary repair file code so that we can atomically switch the contents of any file fork, even if the fork is in local format. The upcoming functions to repair xattrs, directories, and symlinks will need that capability. Repair can lock out access to these user files by holding IOLOCK_EXCL on these user files. Therefore, it is safe to drop the ILOCK of both the file being repaired and the tempfile being used for staging, and cancel the scrub transaction. We do this so that we can reuse the resource estimation and transaction allocation functions used by a regular file exchange operation. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: create a blob array data structureDarrick J. Wong
Create a simple 'blob array' data structure for storage of arbitrarily sized metadata objects that will be used to reconstruct metadata. For the intended usage (temporarily storing extended attribute names and values) we only have to support storing objects and retrieving them. Use the xfile abstraction to store the attribute information in memory that can be swapped out. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: validate explicit directory free block ownersdirattr-validate-owners_2022-10-14Darrick J. Wong
Port the existing directory freespace block header checking function to accept an owner number instead of an xfs_inode, then update the callsites to use xfs_da_args.owner when possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: validate explicit directory block buffer ownersDarrick J. Wong
Port the existing directory block header checking function to accept an owner number instead of an xfs_inode, then update the callsites to use xfs_da_args.owner when possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: validate explicit directory data buffer ownersDarrick J. Wong
Port the existing directory data header checking function to accept an owner number instead of an xfs_inode, then update the callsites to use xfs_da_args.owner when possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: validate directory leaf buffer ownersDarrick J. Wong
Check the owner field of directory leaf blocks. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: validate attr leaf buffer ownersDarrick J. Wong
Create a leaf block header checking function to validate the owner field of xattr leaf blocks. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: add an explicit owner field to xfs_da_argsDarrick J. Wong
Add an explicit owner field to xfs_da_args, which will make it easier for online fsck to set the owner field of the temporary directory and xattr structures that it builds to repair damaged metadata. Note: I hopefully found all the xfs_da_args definitions by looking for automatic stack variable declarations and xfs_da_args.dp assignments: git grep -E '(args.*dp =|struct xfs_da_args[[:space:]]*[a-z0-9][a-z0-9]*)' Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: online repair of realtime summariesrepair-rtsummary_2022-10-14Darrick J. Wong
Repair the realtime summary data by constructing a new rtsummary file in the scrub temporary file, then atomically swapping the contents. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: teach the tempfile to support atomic extent swappingDarrick J. Wong
Create some new routines to exchange the contents of a temporary file created to stage a repair with another ondisk file. This will be used by the realtime summary repair function to commit atomically the new rtsummary data, which will be staged in the tempfile. The rest of XFS coordinates access to the realtime metadata inodes solely through the ILOCK. For repair to hold its exclusive access to the realtime summary file, it has to allocate a single large transaction and roll it repeatedly throughout the repair while holding the ILOCK. In turn, this means that for now there's only a partial swapext implementation for the temporary file, because we can only work within an existing transaction. Hence the only tempswap functions needed here are to estimate the resource requirements of swapext between, reserve more space/quota to an existing transaction, and kick off the actual swap. The rest will be added in a later patch in preparation for repairing xattrs and directories. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: support preallocating and copying content into temporary filesDarrick J. Wong
Create the routines we need to preallocate space in a temporary ondisk file and then copy the contents of an xfile into the tempfile. The upcoming rtsummary repair feature will construct the contents of a realtime summary file in memory, after which it will want to copy all that into the ondisk temporary file before atomically committing the new rtsummary contents. Signed-off-by: Darrick J. Wong <djwong@kernel.org>