summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
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 dabtree node buffer ownersDarrick J. Wong
Check the owner field of dabtree node blocks. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: validate attr remote value buffer ownersDarrick J. Wong
Check the owner field of xattr remote value 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: use the xfs_da_args owner field to set new dir/attr block ownerDarrick J. Wong
When we're creating leaf, data, freespace, or dabtree blocks for directories and xattrs, use the explicit owner field (instead of the xfs_inode) to set the owner field. This will enable online repair to construct replacement data structures in a temporary file without having to change the owner fields prior to swapping the new and old structures. 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>
2022-10-14xfs: add the ability to reap entire inode forksrepair-tempfiles_2022-10-14Darrick J. Wong
In preparation for supporting repair of indexed file-based metadata (such as realtime bitmaps, directories, and extended attribute data), add a function to reap the old blocks after a metadata repair finishes. IOWs, this is an elaborate bunmapi call that deals with crosslinked blocks by unmapping them without freeing them, and also scans for incore buffers to invalidate. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: refactor stale buffer scanning for repairsDarrick J. Wong
In an upcoming patch, we will need to be able to look for xfs_buf objects caching file-based metadata blocks without needing to walk the (possibly corrupt) structures to find all the buffers. Repair already has most of the code needed to scan the buffer cache, so hoist these utility functions. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: create temporary files and directories for online repairDarrick J. Wong
Teach the online repair code how to create temporary files or directories. These temporary files can be used to stage reconstructed information until we're ready to perform an atomic extent swap to commit the new metadata. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: hide private inodes from bulkstat and handle functionsDarrick J. Wong
We're about to start adding functionality that uses internal inodes that are private to XFS. What this means is that userspace should never be able to access any information about these files, and should not be able to open these files by handle. Callers are not allowed to link these files into the directory tree, which should suffice to make these private inodes actually private. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: enable atomic swapext featureatomic-file-updates_2022-10-14Darrick J. Wong
Add the atomic swapext feature to the set of features that we will permit. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: support non-power-of-two rtextsize with exchange-rangeDarrick J. Wong
The VFS exchange-range alignment checks use (fast) bitmasks to perform block alignment checks on the exchange parameters. Unfortunately, bitmasks require that the alignment size be a power of two. This isn't true for realtime devices, so we have to copy-pasta the VFS checks using long division for this to work properly. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: make atomic extent swapping support realtime filesDarrick J. Wong
Now that bmap items support the realtime device, we can add the necessary pieces to the atomic extent swapping code to support such things. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: condense symbolic links after an atomic swapDarrick J. Wong
The previous commit added a new swapext flag that enables us to perform post-swap processing on file2 once we're done swapping the extent maps. Now add this ability for symlinks. This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online symlink repair feature can salvage the remote target in a temporary link and swap the data forks when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the swap. After the swap, we can try to condense the fixed symlink down to inline format if possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: condense directories after an atomic swapDarrick J. Wong
The previous commit added a new swapext flag that enables us to perform post-swap processing on file2 once we're done swapping the extent maps. Now add this ability for directories. This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online directory repair feature can create salvaged dirents in a temporary directory and swap the data forks when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the swap. After the swap, we can try to condense the fixed directory down to inline format if possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: condense extended attributes after an atomic swapDarrick J. Wong
Add a new swapext flag that enables us to perform post-swap processing on file2 once we're done swapping the extent maps. If we were swapping the extended attributes, we want to be able to convert file2's attr fork from block to inline format. This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online xattr repair feature can create salvaged attrs in a temporary file and swap the attr forks when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the swap. After the swap, we can try to condense the fixed file's attr fork back down to inline format if possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: remove old swap extents implementationDarrick J. Wong
Migrate the old XFS_IOC_SWAPEXT implementation to use our shiny new one. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: allow xfs_swap_range to use older extent swap algorithmsDarrick J. Wong
If userspace permits non-atomic swap operations, use the older code paths to implement the same functionality. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: port xfs_swap_extent_forks to use xfs_swapext_reqDarrick J. Wong
Port the old extent fork swapping function to take a xfs_swapext_req as input, which aligns it with the new fiexchange interface. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: consolidate all of the xfs_swap_extent_forks codeDarrick J. Wong
Now that we've moved the old swapext code to use the new log-assisted extent swap code for rmap filesystems, let's start porting the old implementation to the new ioctl interface so that later we can port the old interface to the new interface. Consolidate the reflink flag swap code and the the bmbt owner change scan code in xfs_swap_extent_forks, since both interfaces are going to need that. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: port xfs_swap_extents_rmap to our new codeDarrick J. Wong
The inner loop of xfs_swap_extents_rmap does the same work as xfs_swapext_finish_one, so adapt it to use that. Doing so has the side benefit that the older code path no longer wastes its time remapping shared extents. This forms the basis of the non-atomic swaprange implementation. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: add error injection to test swapext recoveryDarrick J. Wong
Add an errortag so that we can test recovery of swapext log items. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: add a ->xchg_file_range handlerDarrick J. Wong
Add a function to handle file range exchange requests from the vfs. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: enable xlog users to toggle atomic extent swappingDarrick J. Wong
Plumb the necessary bits into the xlog code so that higher level callers can enable the atomic extent swapping feature and have it clear automatically when possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: create deferred log items for extent swappingDarrick J. Wong
Now that we've created the skeleton of a log intent item to track and restart extent swap operations, add the upper level logic to commit intent items and turn them into concrete work recorded in the log. We use the deferred item "multihop" feature that was introduced a few patches ago to constrain the number of active swap operations to one per thread. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: introduce a swap-extent log intent itemDarrick J. Wong
Introduce a new intent log item to handle swapping extents. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: create a log incompat flag for atomic extent swappingDarrick J. Wong
Create a log incompat flag so that we only attempt to process swap extent log items if the filesystem supports it, and a geometry flag to advertise support if it's present. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: parameterize all the incompat log feature helpersDarrick J. Wong
We're about to define a new XFS_SB_FEAT_INCOMPAT_LOG_ bit, which means that callers will soon require the ability to toggle on and off different log incompat feature bits. Parameterize the xlog_{use,drop}_incompat_feat and xfs_sb_remove_incompat_log_features functions so that callers can specify which feature they're trying to use and so that we can clear individual log incompat bits as needed. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: refactor non-power-of-two alignment checksDarrick J. Wong
Create a helper function that can compute if a 64-bit number is an integer multiple of a 32-bit number, where the 32-bit number is not required to be an even power of two. This is needed for some new code for the realtime device, where we can set 37k allocation units and then have to remap them. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: create a new helper to return a file's allocation unitDarrick J. Wong
Create a new helper function to calculate the fundamental allocation unit (i.e. the smallest unit of space we can allocate) of a file. Things are going to get hairy with range-exchange on the realtime device, so prepare for this now. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14vfs: introduce new file range exchange ioctlDarrick J. Wong
Introduce a new ioctl to handle swapping ranges of bytes between files. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2022-10-14xfs: move symlink target write function to libxfssymlink-cleanups_2022-10-14Darrick J. Wong
Move xfs_symlink_write_target to xfs_symlink_remote.c so that kernel and mkfs can share the same function. Signed-off-by: Darrick J. Wong <djwong@kernel.org>