]> www.infradead.org Git - users/hch/xfsprogs.git/log
users/hch/xfsprogs.git
8 months agoxfs_repair: refactor root directory initialization
Darrick J. Wong [Tue, 15 Oct 2024 19:44:02 +0000 (12:44 -0700)]
xfs_repair: refactor root directory initialization

Refactor root directory initialization into a separate function we can
call for both the root dir and the metadir.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_repair: refactor marking of metadata inodes
Darrick J. Wong [Tue, 15 Oct 2024 19:44:02 +0000 (12:44 -0700)]
xfs_repair: refactor marking of metadata inodes

Refactor the mechanics of marking a metadata inode into a helper
function so that we don't have to open-code that for every single
metadata inode.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_repair: refactor fixing dotdot
Darrick J. Wong [Tue, 15 Oct 2024 19:44:02 +0000 (12:44 -0700)]
xfs_repair: refactor fixing dotdot

Pull the code that fixes a directory's dot-dot entry into a separate
helper function so that we can call it on the rootdir and (later) the
metadir.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_repair: dont check metadata directory dirent inumbers
Darrick J. Wong [Tue, 15 Oct 2024 19:44:02 +0000 (12:44 -0700)]
xfs_repair: dont check metadata directory dirent inumbers

Phase 6 always rebuilds the entire metadata directory tree, and repair
quietly ignores all the DIFLAG2_METADATA directory inodes that it finds.
As a result, none of the metadata directories are marked inuse in the
incore data.  Therefore, the is_inode_free checks are not valid for
anything we find in a metadata directory.

Therefore, avoid checking is_inode_free when scanning metadata directory
dirents.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_repair: preserve the metadirino field when zeroing supers
Darrick J. Wong [Tue, 15 Oct 2024 19:44:01 +0000 (12:44 -0700)]
xfs_repair: preserve the metadirino field when zeroing supers

The metadata directory root inumber is now the last field in the
superblock, so extend the zeroing code to know about that.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_scrub: re-run metafile scrubbers during phase 5
Darrick J. Wong [Tue, 15 Oct 2024 19:44:01 +0000 (12:44 -0700)]
xfs_scrub: re-run metafile scrubbers during phase 5

For metadata files on a metadir filesystem, re-run the scrubbers during
phase 5 to ensure that the metadata files are still connected.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_scrub: scan metadata directories during phase 3
Darrick J. Wong [Tue, 15 Oct 2024 19:44:01 +0000 (12:44 -0700)]
xfs_scrub: scan metadata directories during phase 3

Scan metadata directories for correctness during phase 3.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_scrub: tread zero-length read verify as an IO error
Darrick J. Wong [Tue, 15 Oct 2024 19:44:01 +0000 (12:44 -0700)]
xfs_scrub: tread zero-length read verify as an IO error

While doing some chaos testing on the xfs_scrub read verify code, I
noticed that if the device under a live filesystem gets resized while
scrub is running a media scan, reads will start returning 0.  This
causes read_verify() to run around in an infinite loop instead of
erroring out like it should.

Cc: <linux-xfs@vger.kernel.org> # v5.3.0
Fixes: 27464242956fac ("xfs_scrub: fix read verify disk error handling strategy")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_spaceman: report health of metadir inodes too
Darrick J. Wong [Tue, 15 Oct 2024 19:44:00 +0000 (12:44 -0700)]
xfs_spaceman: report health of metadir inodes too

If the filesystem has a metadata directory tree, we should include those
inodes in the health report.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_io: support scrubbing metadata directory paths
Darrick J. Wong [Tue, 15 Oct 2024 19:44:00 +0000 (12:44 -0700)]
xfs_io: support scrubbing metadata directory paths

Support invoking the metadata directory path scrubber from xfs_io for
testing.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_io: support the bulkstat metadata directory flag
Darrick J. Wong [Tue, 15 Oct 2024 19:44:00 +0000 (12:44 -0700)]
xfs_io: support the bulkstat metadata directory flag

Support the new XFS_BULK_IREQ_METADIR flag for bulkstat commands.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_db: display di_metatype
Darrick J. Wong [Tue, 15 Oct 2024 19:44:00 +0000 (12:44 -0700)]
xfs_db: display di_metatype

Print the metadata file type if available.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_db: show the metadata root directory when dumping superblocks
Darrick J. Wong [Tue, 15 Oct 2024 22:37:40 +0000 (15:37 -0700)]
xfs_db: show the metadata root directory when dumping superblocks

Show the metadirino field when appropriate.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_db: support metadata directories in the path command
Darrick J. Wong [Tue, 15 Oct 2024 19:44:00 +0000 (12:44 -0700)]
xfs_db: support metadata directories in the path command

Teach various directory tree debugger commands to traverse the metadata
directory tree by adding a -m switch to select that tree.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_db: don't obfuscate metadata directories and attributes
Darrick J. Wong [Tue, 15 Oct 2024 19:43:59 +0000 (12:43 -0700)]
xfs_db: don't obfuscate metadata directories and attributes

Don't obfuscate the directory and attribute names of metadata inodes.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_db: report metadir support for version command
Darrick J. Wong [Tue, 15 Oct 2024 19:43:59 +0000 (12:43 -0700)]
xfs_db: report metadir support for version command

Report metadir support if we have it enabled.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_db: disable xfs_check when metadir is enabled
Darrick J. Wong [Tue, 15 Oct 2024 19:43:59 +0000 (12:43 -0700)]
xfs_db: disable xfs_check when metadir is enabled

As of July 2024, xfs_repair can detect more types of corruptions than
xfs_check does.  I don't think it makes sense to maintain the xfs_check
code anymore, so let's just turn it off for any filesystem that has
metadata directory trees.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_io: support scrubbing metadata directory paths
Darrick J. Wong [Tue, 15 Oct 2024 19:43:59 +0000 (12:43 -0700)]
xfs_io: support scrubbing metadata directory paths

Support invoking the metadata directory path scrubber from xfs_io for
testing.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agolibfrog: allow METADIR in xfrog_bulkstat_single5
Darrick J. Wong [Tue, 15 Oct 2024 19:43:58 +0000 (12:43 -0700)]
libfrog: allow METADIR in xfrog_bulkstat_single5

This is a valid flag for a single-file bulkstat, so add that to the
filter.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agolibfrog: report metadata directories in the geometry report
Darrick J. Wong [Tue, 15 Oct 2024 19:43:58 +0000 (12:43 -0700)]
libfrog: report metadata directories in the geometry report

Report the presence of a metadata directory tree in the geometry report.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: check metadata directory file path connectivity
Darrick J. Wong [Tue, 15 Oct 2024 19:43:58 +0000 (12:43 -0700)]
xfs: check metadata directory file path connectivity

Create a new scrubber type that checks that well known metadata
directory paths are connected to the metadata inode that the incore
structures think is in use.  IOWs, check that "/quota/user" in the
metadata directory tree actually points to
mp->m_quotainfo->qi_uquotaip->i_ino.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: record health problems with the metadata directory
Darrick J. Wong [Tue, 15 Oct 2024 19:43:58 +0000 (12:43 -0700)]
xfs: record health problems with the metadata directory

Make a report to the health monitoring subsystem any time we encounter
something in the metadata directory tree that looks like corruption.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: adjust xfs_bmap_add_attrfork for metadir
Darrick J. Wong [Tue, 15 Oct 2024 19:43:58 +0000 (12:43 -0700)]
xfs: adjust xfs_bmap_add_attrfork for metadir

Online repair might use the xfs_bmap_add_attrfork to repair a file in
the metadata directory tree if (say) the metadata file lacks the correct
parent pointers.  In that case, it is not correct to check that the file
is dqattached -- metadata files must be not have /any/ dquot attached at
all.  Adjust the assertions appropriately.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: allow bulkstat to return metadata directories
Darrick J. Wong [Tue, 15 Oct 2024 19:43:57 +0000 (12:43 -0700)]
xfs: allow bulkstat to return metadata directories

Allow the V5 bulkstat ioctl to return information about metadata
directory files so that xfs_scrub can find and scrub them, since they
are otherwise ordinary directories.

(Metadata files of course require per-file scrub code and hence do not
need exposure.)

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: advertise metadata directory feature
Darrick J. Wong [Tue, 15 Oct 2024 19:43:57 +0000 (12:43 -0700)]
xfs: advertise metadata directory feature

Advertise the existence of the metadata directory feature; this will be
used by scrub to decide if it needs to scan the metadir too.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: disable the agi rotor for metadata inodes
Darrick J. Wong [Tue, 15 Oct 2024 19:43:57 +0000 (12:43 -0700)]
xfs: disable the agi rotor for metadata inodes

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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: read and write metadata inode directory tree
Darrick J. Wong [Tue, 15 Oct 2024 19:43:57 +0000 (12:43 -0700)]
xfs: read and write metadata inode directory tree

Plumb in the bits we need to load metadata inodes from a named entry in
a metadir directory, create (or hardlink) inodes into a metadir
directory, create metadir directories, and flag inodes as being metadata
files.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: enforce metadata inode flag
Darrick J. Wong [Tue, 15 Oct 2024 19:43:57 +0000 (12:43 -0700)]
xfs: enforce metadata inode flag

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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: load metadata directory root at mount time
Darrick J. Wong [Tue, 15 Oct 2024 19:43:56 +0000 (12:43 -0700)]
xfs: load metadata directory root at mount time

Load the metadata directory root inode into memory at mount time and
release it at unmount time.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: iget for metadata inodes
Darrick J. Wong [Tue, 15 Oct 2024 19:43:56 +0000 (12:43 -0700)]
xfs: iget for metadata inodes

Create a xfs_trans_metafile_iget function for metadata inodes to ensure
that when we try to iget a metadata file, the inode is allocated and its
file mode matches the metadata file type the caller expects.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: define the on-disk format for the metadir feature
Darrick J. Wong [Tue, 15 Oct 2024 19:38:22 +0000 (12:38 -0700)]
xfs: define the on-disk format for the metadir feature

Define the on-disk layout and feature flags for the metadata inode
directory feature.  Add a xfs_sb_version_hasmetadir for benefit of
xfs_repair, which needs to know where the new end of the superblock
lies.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: rename metadata inode predicates
Darrick J. Wong [Tue, 15 Oct 2024 21:50:14 +0000 (14:50 -0700)]
xfs: rename metadata inode predicates

The predicate xfs_internal_inum tells us if an inumber refers to one of
the inodes rooted in the superblock.  Soon we're going to have internal
inodes in a metadata directory tree, so this helper should be renamed
to capture its limited scope.

Ondisk inodes will soon have a flag to indicate that they're metadata
inodes.  Head off some confusion by renaming the xfs_is_metadata_inode
predicate to xfs_is_internal_inode.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: constify the xfs_inode predicates
Darrick J. Wong [Tue, 15 Oct 2024 19:43:55 +0000 (12:43 -0700)]
xfs: constify the xfs_inode predicates

Change the xfs_inode predicates to take a const struct xfs_inode pointer
because they do not change the inode.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: constify the xfs_sb predicates
Darrick J. Wong [Tue, 15 Oct 2024 19:43:55 +0000 (12:43 -0700)]
xfs: constify the xfs_sb predicates

Change the xfs_sb predicates to take a const struct xfs_sb pointer
because they do not change the superblock.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: store a generic group structure in the intents
Christoph Hellwig [Tue, 15 Oct 2024 19:38:20 +0000 (12:38 -0700)]
xfs: store a generic group structure in the intents

Replace the pag pointers in the extent free, bmap, rmap and refcount
intent structures with a pointer to the generic group to prepare
for adding intents for realtime groups.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: add group based bno conversion helpers
Christoph Hellwig [Tue, 15 Oct 2024 19:38:18 +0000 (12:38 -0700)]
xfs: add group based bno conversion helpers

Add/move the blocks, blklog and blkmask fields to the generic groups
structure so that code can work with AGs and RTGs by just using the
right index into the array.

Then, add convenience helpers to convert block numbers based on the
generic group.  This will allow writing code that doesn't care if it is
used on AGs or the upcoming realtime groups.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: add a generic group pointer to the btree cursor
Christoph Hellwig [Tue, 15 Oct 2024 19:38:17 +0000 (12:38 -0700)]
xfs: add a generic group pointer to the btree cursor

Replace the pag pointers in the type specific union with a generic
xfs_group pointer.  This prepares for adding realtime group support.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: convert busy extent tracking to the generic group structure
Christoph Hellwig [Tue, 15 Oct 2024 19:38:16 +0000 (12:38 -0700)]
xfs: convert busy extent tracking to the generic group structure

Split busy extent tracking from struct xfs_perag into its own private
structure, which can be pointed to by the generic group structure.

Note that this structure is now dynamically allocated instead of embedded
as the upcoming zone XFS code doesn't need it and will also have an
unusually high number of groups due to hardware constraints.  Dynamically
allocating the structure this is a big memory saver for this case.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: move the online repair rmap hooks to the generic group structure
Christoph Hellwig [Tue, 15 Oct 2024 19:38:14 +0000 (12:38 -0700)]
xfs: move the online repair rmap hooks to the generic group structure

Prepare for the upcoming realtime groups feature by moving the online
repair rmap hooks to based to the generic xfs_group structure.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: move draining of deferred operations to the generic group structure
Christoph Hellwig [Tue, 15 Oct 2024 19:43:54 +0000 (12:43 -0700)]
xfs: move draining of deferred operations to the generic group structure

Prepare supporting the upcoming realtime groups feature by moving the
deferred operation draining to the generic xfs_group structure.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: move metadata health tracking to the generic group structure
Christoph Hellwig [Tue, 15 Oct 2024 19:38:11 +0000 (12:38 -0700)]
xfs: move metadata health tracking to the generic group structure

Prepare for also tracking the health status of the upcoming realtime
groups by moving the health tracking code to the generic xfs_group
structure.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: switch perag iteration from the for_each macros to a while based iterator
Christoph Hellwig [Tue, 15 Oct 2024 19:43:53 +0000 (12:43 -0700)]
xfs: switch perag iteration from the for_each macros to a while based iterator

The current for_each_perag* macros are a bit annoying in that they
require the caller to both provide an object and an index iterator, and
also somewhat obsfucate the underlying control flow mechanism.

Switch to open coded while loops using new xfs_perag_next{,_from,_range}
helpers that return the next pag structure to iterate on based on the
previous one or NULL for the loop start.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: add a xfs_group_next_range helper
Christoph Hellwig [Tue, 15 Oct 2024 19:43:53 +0000 (12:43 -0700)]
xfs: add a xfs_group_next_range helper

Add a helper to iterate over iterate over all groups, which can be used
as a simple while loop:

struct xfs_group *xg = NULL;

while ((xg = xfs_group_next_range(mp, xg, 0, MAX_GROUP))) {
...
}

This will be wrapped by the realtime group code first, and eventually
replace the for_each_rtgroup_from and for_each_rtgroup_range helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: factor out a generic xfs_group structure
Christoph Hellwig [Tue, 15 Oct 2024 19:38:09 +0000 (12:38 -0700)]
xfs: factor out a generic xfs_group structure

Split the lookup and refcount handling of struct xfs_perag into an
embedded xfs_group structure that can be reused for the upcoming
realtime groups.

It will be extended with more features later.

Note that he xg_type field will only need a single bit even with
realtime group support.  For now it fills a hole, but it might be
worth to fold it into another field if we can use this space better.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: insert the pag structures into the xarray later
Christoph Hellwig [Tue, 15 Oct 2024 19:43:52 +0000 (12:43 -0700)]
xfs: insert the pag structures into the xarray later

Cleaning up is much easier if a structure can't be looked up yet, so only
insert the pag once it is fully set up.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: split xfs_initialize_perag
Christoph Hellwig [Tue, 15 Oct 2024 19:38:06 +0000 (12:38 -0700)]
xfs: split xfs_initialize_perag

Factor out a xfs_perag_alloc helper that allocates a single perag
structure.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: convert remaining trace points to pass pag structures
Christoph Hellwig [Tue, 15 Oct 2024 19:43:52 +0000 (12:43 -0700)]
xfs: convert remaining trace points to pass pag structures

Convert all tracepoints that take [mp,agno] tuples to take a pag argument
instead so that decoding only happens when tracepoints are enabled and to
clean up the callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: pass objects to the xfs_irec_merge_{pre,post} trace points
Christoph Hellwig [Tue, 15 Oct 2024 19:43:52 +0000 (12:43 -0700)]
xfs: pass objects to the xfs_irec_merge_{pre,post} trace points

Pass the perag structure and the irec to these tracepoints so that the
decoding is only done when tracing is actually enabled and the call sites
look a lot neater.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: pass a perag structure to the xfs_ag_resv_init_error trace point
Christoph Hellwig [Tue, 15 Oct 2024 19:43:52 +0000 (12:43 -0700)]
xfs: pass a perag structure to the xfs_ag_resv_init_error trace point

And remove the single instance class indirection for it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: pass a pag to xfs_extent_busy_{search,reuse}
Christoph Hellwig [Tue, 15 Oct 2024 19:43:51 +0000 (12:43 -0700)]
xfs: pass a pag to xfs_extent_busy_{search,reuse}

Replace the [mp,agno] tuple with the perag structure, which will become
more useful later.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: add a xfs_agino_to_ino helper
Christoph Hellwig [Tue, 15 Oct 2024 19:43:51 +0000 (12:43 -0700)]
xfs: add a xfs_agino_to_ino helper

Add a helpers to convert an agino to an ino based on a pag structure.

This provides a simpler conversion and better type safety compared to the
existing code that passes the mount structure and the agno separately.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: add xfs_agbno_to_fsb and xfs_agbno_to_daddr helpers
Christoph Hellwig [Tue, 15 Oct 2024 19:43:51 +0000 (12:43 -0700)]
xfs: add xfs_agbno_to_fsb and xfs_agbno_to_daddr helpers

Add helpers to convert an agbno to a daddr or fsbno based on a pag
structure.

This provides a simpler conversion and better type safety compared to the
existing code that passes the mount structure and the agno separately.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: remove the agno argument to xfs_free_ag_extent
Christoph Hellwig [Tue, 15 Oct 2024 19:43:51 +0000 (12:43 -0700)]
xfs: remove the agno argument to xfs_free_ag_extent

xfs_free_ag_extent already has a pointer to the pag structure through
the agf buffer.  Use that instead of passing the redundant argument,
and do the same for the tracepoint.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: pass a pag to xfs_difree_inode_chunk
Christoph Hellwig [Tue, 15 Oct 2024 19:43:50 +0000 (12:43 -0700)]
xfs: pass a pag to xfs_difree_inode_chunk

We'll want to use more than just the agno field in a bit.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: remove the unused pag_active_wq field in struct xfs_perag
Christoph Hellwig [Tue, 15 Oct 2024 19:43:50 +0000 (12:43 -0700)]
xfs: remove the unused pag_active_wq field in struct xfs_perag

pag_active_wq is only woken, but never waited for.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: remove the unused pagb_count field in struct xfs_perag
Christoph Hellwig [Tue, 15 Oct 2024 19:43:50 +0000 (12:43 -0700)]
xfs: remove the unused pagb_count field in struct xfs_perag

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agomkfs: add a config file for 6.12 LTS kernels
Darrick J. Wong [Fri, 25 Oct 2024 21:06:46 +0000 (14:06 -0700)]
mkfs: add a config file for 6.12 LTS kernels

We didn't add any new ondisk features in 2023, so the config file is the
same.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_scrub_all: wait for services to start activating
Darrick J. Wong [Tue, 22 Oct 2024 00:44:13 +0000 (17:44 -0700)]
xfs_scrub_all: wait for services to start activating

It seems that the function call to start a systemd unit completes
asynchronously from any change in that unit's active state.  On a
lightly loaded system, a Start() call followed by an ActiveState()
call actually sees the change in state from inactive to activating.

Unfortunately, on a heavily loaded system, the state change may take a
few seconds.  If this is the case, the wait() call can see that the unit
state is "inactive", decide that the service already finished, and exit
early, when in reality it hasn't even gotten to 'activating'.

Fix this by adding a second method that watches either for the inactive
-> activating state transition or for the last exit from inactivation
timestamp to change before waiting for the unit to reach inactive state.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Cc: <linux-xfs@vger.kernel.org> # v6.10.0
Fixes: 6d831e770359ff ("xfs_scrub_all: convert systemctl calls to dbus")
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_repair: stop preallocating blocks in mk_rbmino and mk_rsumino
Christoph Hellwig [Tue, 15 Oct 2024 19:43:49 +0000 (12:43 -0700)]
xfs_repair: stop preallocating blocks in mk_rbmino and mk_rsumino

Now that repair is using libxfs_rtfile_initialize_blocks to write to the
rtbitmap and rtsummary inodes, space allocation is already taken care of
that helper and there is no need to preallocate it.  Remove the code to
do so.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_repair: use libxfs_rtfile_initialize_blocks
Christoph Hellwig [Tue, 15 Oct 2024 19:43:49 +0000 (12:43 -0700)]
xfs_repair: use libxfs_rtfile_initialize_blocks

Use libxfs_rtfile_initialize_blocks to write the re-computed rtbitmap
and rtsummary contents.  This removes duplicate code and prepares for
even more sharing once the rtgroup features adds a metadata header to
the rtbitmap and rtsummary blocks.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agomkfs: use xfs_rtfile_initialize_blocks
Christoph Hellwig [Tue, 15 Oct 2024 19:43:49 +0000 (12:43 -0700)]
mkfs: use xfs_rtfile_initialize_blocks

Use the new libxfs helper for initializing the rtbitmap/summary files
for rtgroup-enabled file systems.  Also skip the zeroing of the blocks
for rtgroup file systems as we'll overwrite every block instantly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agomkfs: remove a pointless rtfreesp_init forward declaration
Christoph Hellwig [Tue, 15 Oct 2024 19:43:49 +0000 (12:43 -0700)]
mkfs: remove a pointless rtfreesp_init forward declaration

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_repair: use xfs_validate_rt_geometry
Christoph Hellwig [Tue, 15 Oct 2024 19:43:48 +0000 (12:43 -0700)]
xfs_repair: use xfs_validate_rt_geometry

Use shared libxfs code with the kernel instead of reimplementing it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs_repair: checking rt free space metadata must happen during phase 4
Darrick J. Wong [Tue, 15 Oct 2024 19:43:48 +0000 (12:43 -0700)]
xfs_repair: checking rt free space metadata must happen during phase 4

Back in the really old days, xfs_repair would generate the new free
space information for the realtime section during phase 5, and write the
contents to the rtbitmap and summary files during phase 6.  This was ok
because the incore information isn't used until phase 6.

Then I changed the behavior to check the generated information against
what was on disk and complain about the discrepancies.  Unfortunately,
there was a subtle flaw here -- for a non -n run, we'll have regenerated
the AG metadata before we actually check the rt free space information.
If the AG btree regeneration should clobber one of the old rtbitmap or
summary blocks, this will be reported as a corruption even though
nothing's wrong.

Move check_rtmetadata to the end of phase 4 so that this doesn't happen.

Cc: <linux-xfs@vger.kernel.org> # v5.19.0
Fixes: f2e388616d7491 ("xfs_repair: check free rt extent count")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_db: allow setting current address to log blocks
Darrick J. Wong [Tue, 15 Oct 2024 19:43:48 +0000 (12:43 -0700)]
xfs_db: allow setting current address to log blocks

Add commands so that users can target blocks on an external log device.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_db: convert rtsummary geometry
Darrick J. Wong [Tue, 15 Oct 2024 19:43:48 +0000 (12:43 -0700)]
xfs_db: convert rtsummary geometry

Add two rtsummary related conversion routines to rtconvert:

Convert a rtbitmap file block number and free extent log length to a
file block number and info word offset within the rt summary file;

Convert a free extent log length, summary info word offset, and summary
file block number to a file block number within the rt bitmap file.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_db: convert rtbitmap geometry
Darrick J. Wong [Tue, 15 Oct 2024 19:43:48 +0000 (12:43 -0700)]
xfs_db: convert rtbitmap geometry

Teach the rtconvert command to convert locations on the realtime device
(e.g. rt daddrs, blocks, or extents) to a file block number and word
within the rt bitmap file.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_db: enable conversion of rt space units
Darrick J. Wong [Tue, 15 Oct 2024 19:43:48 +0000 (12:43 -0700)]
xfs_db: enable conversion of rt space units

Teach the xfs_db convert function about rt extents, rt block numbers,
and how to compute offsets within the rt bitmap and summary files.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_db: access arbitrary realtime blocks and extents
Darrick J. Wong [Tue, 15 Oct 2024 19:43:47 +0000 (12:43 -0700)]
xfs_db: access arbitrary realtime blocks and extents

Add two commands to xfs_db so that we can point ourselves at any
arbitrary realtime block or extent.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_db: access realtime file blocks
Darrick J. Wong [Tue, 15 Oct 2024 19:43:47 +0000 (12:43 -0700)]
xfs_db: access realtime file blocks

Now that we have the ability to point the io cursor at the realtime
device, let's make it so that the "dblock" command can walk the contents
of realtime files.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_db: make the daddr command target the realtime device
Darrick J. Wong [Tue, 15 Oct 2024 19:43:47 +0000 (12:43 -0700)]
xfs_db: make the daddr command target the realtime device

Make it so that users can issue the command "daddr -r XXX" to select
disk block XXX on the realtime device.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_db: report the realtime device when associated with each io cursor
Darrick J. Wong [Tue, 15 Oct 2024 19:43:47 +0000 (12:43 -0700)]
xfs_db: report the realtime device when associated with each io cursor

When db is reporting on an io cursor and the cursor points to the
realtime device, print that fact.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_db: support passing the realtime device to the debugger
Darrick J. Wong [Tue, 15 Oct 2024 19:43:47 +0000 (12:43 -0700)]
xfs_db: support passing the realtime device to the debugger

Create a new -R flag so that sysadmins can pass the realtime device to
the xfs debugger.  Since we can now have superblocks on the rt device,
we need this to be able to inspect/dump/etc.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_io: add atomic file update commands to exercise file commit range
Darrick J. Wong [Tue, 15 Oct 2024 19:43:46 +0000 (12:43 -0700)]
xfs_io: add atomic file update commands to exercise file commit range

Add three commands to xfs_io so that we can exercise atomic file updates
as provided by reflink and the start-commit / commit-range functionality.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_io: add a commitrange option to the exchangerange command
Darrick J. Wong [Tue, 15 Oct 2024 19:43:46 +0000 (12:43 -0700)]
xfs_io: add a commitrange option to the exchangerange command

Teach the xfs_io exchangerange command to be able to use the commit
range functionality so that we can test it piece by piece.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs_fsr: port to new file exchange library function
Darrick J. Wong [Tue, 15 Oct 2024 19:43:46 +0000 (12:43 -0700)]
xfs_fsr: port to new file exchange library function

Port fsr to use the new libfrog library functions to handle exchanging
mappings between the target and donor files.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agolibxfs: validate inumber in xfs_iget
Darrick J. Wong [Tue, 15 Oct 2024 19:43:46 +0000 (12:43 -0700)]
libxfs: validate inumber in xfs_iget

Actually use the inumber validator to check the argument passed in here,
just like we now do in the kernel.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agolibxfs: remove unused xfs_inode fields
Darrick J. Wong [Tue, 15 Oct 2024 19:43:46 +0000 (12:43 -0700)]
libxfs: remove unused xfs_inode fields

Remove these unused fields; on the author's system this reduces the
struct size from 560 bytes to 448.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agolibfrog: add support for commit range ioctl family
Darrick J. Wong [Tue, 15 Oct 2024 19:43:45 +0000 (12:43 -0700)]
libfrog: add support for commit range ioctl family

Add some library code to support the new file range commit ioctls.  This
will be used to test the atomic file commit functionality in fstests.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoman: document file range commit ioctls
Darrick J. Wong [Tue, 15 Oct 2024 19:43:45 +0000 (12:43 -0700)]
man: document file range commit ioctls

Document the two new ioctls to support committing arbitrary dirty data
ranges of two files.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: update the pag for the last AG at recovery time
Christoph Hellwig [Mon, 28 Oct 2024 05:24:41 +0000 (22:24 -0700)]
xfs: update the pag for the last AG at recovery time

Source kernel commit: 4a201dcfa1ff0dcfe4348c40f3ad8bd68b97eb6c

Currently log recovery never updates the in-core perag values for the
last allocation group when they were grown by growfs.  This leads to
btree record validation failures for the alloc, ialloc or finotbt
trees if a transaction references this new space.

Found by Brian's new growfs recovery stress test.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: don't use __GFP_RETRY_MAYFAIL in xfs_initialize_perag
Christoph Hellwig [Mon, 28 Oct 2024 05:24:40 +0000 (22:24 -0700)]
xfs: don't use __GFP_RETRY_MAYFAIL in xfs_initialize_perag

Source kernel commit: 069cf5e32b700f94c6ac60f6171662bdfb04f325

__GFP_RETRY_MAYFAIL increases the likelyhood of allocations to fail,
which isn't really helpful during log recovery.  Remove the flag and
stick to the default GFP_KERNEL policies.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: merge the perag freeing helpers
Christoph Hellwig [Mon, 28 Oct 2024 05:24:40 +0000 (22:24 -0700)]
xfs: merge the perag freeing helpers

Source kernel commit: aa67ec6a25617e36eba4fb28a88159f500a6cac6

There is no good reason to have two different routines for freeing perag
structures for the unmount and error cases.  Add two arguments to specify
the range of AGs to free to xfs_free_perag, and use that to replace
xfs_free_unused_perag_range.

The addition RCU grace period for the error case is harmless, and the
extra check for the AG to actually exist is not required now that the
callers pass the exact known allocated range.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: pass the exact range to initialize to xfs_initialize_perag
Christoph Hellwig [Mon, 28 Oct 2024 05:24:40 +0000 (22:24 -0700)]
xfs: pass the exact range to initialize to xfs_initialize_perag

Source kernel commit: 82742f8c3f1a93787a05a00aca50c2a565231f84

Currently only the new agcount is passed to xfs_initialize_perag, which
requires lookups of existing AGs to skip them and complicates error
handling.  Also pass the previous agcount so that the range that
xfs_initialize_perag operates on is exactly defined.  That way the
extra lookups can be avoided, and error handling can clean up the
exact range from the old count to the last added perag structure.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc
Christoph Hellwig [Tue, 15 Oct 2024 19:43:45 +0000 (12:43 -0700)]
xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc

Source kernel commit: 6aac77059881e4419df499392c995bf02fb9630b

Currently the debug-only xfs_bmap_exact_minlen_extent_alloc allocation
variant fails to drop into the lowmode last resort allocator, and
thus can sometimes fail allocations for which the caller has a
transaction block reservation.

Fix this by using xfs_bmap_btalloc_low_space to do the actual allocation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc
Christoph Hellwig [Tue, 15 Oct 2024 19:43:45 +0000 (12:43 -0700)]
xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc

Source kernel commit: 405ee87c6938f67e6ab62a3f8f85b3c60a093886

xfs_bmap_exact_minlen_extent_alloc duplicates the args setup in
xfs_bmap_btalloc.  Switch to call it from xfs_bmap_btalloc after
doing the basic setup.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: don't ifdef around the exact minlen allocations
Christoph Hellwig [Tue, 15 Oct 2024 19:43:45 +0000 (12:43 -0700)]
xfs: don't ifdef around the exact minlen allocations

Source kernel commit: b611fddc0435738e64453bbf1dadd4b12a801858

Exact minlen allocations only exist as an error injection tool for debug
builds.  Currently this is implemented using ifdefs, which means the code
isn't even compiled for non-XFS_DEBUG builds.  Enhance the compile test
coverage by always building the code and use the compilers' dead code
elimination to remove it from the generated binary instead.

The only downside is that the alloc_minlen_only field is unconditionally
added to struct xfs_alloc_args now, but by moving it around and packing
it tightly this doesn't actually increase the size of the structure.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate
Christoph Hellwig [Tue, 15 Oct 2024 19:43:44 +0000 (12:43 -0700)]
xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate

Source kernel commit: 865469cd41bce2b04bef9539cbf70676878bc8df

Userdata and metadata allocations end up in the same allocation helpers.
Remove the separate xfs_bmap_alloc_userdata function to make this more
clear.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname
Christoph Hellwig [Tue, 15 Oct 2024 19:43:44 +0000 (12:43 -0700)]
xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname

Source kernel commit: b3f4e84e2f438a119b7ca8684a25452b3e57c0f0

Just like xfs_attr3_leaf_split, xfs_attr_node_try_addname can return
-ENOSPC both for an actual failure to allocate a disk block, but also
to signal the caller to convert the format of the attr fork.  Use magic
1 to ask for the conversion here as well.

Note that unlike the similar issue in xfs_attr3_leaf_split, this one was
only found by code review.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split
Christoph Hellwig [Tue, 15 Oct 2024 19:43:44 +0000 (12:43 -0700)]
xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split

Source kernel commit: a5f73342abe1f796140f6585e43e2aa7bc1b7975

xfs_attr3_leaf_split propagates the need for an extra btree split as
-ENOSPC to it's only caller, but the same return value can also be
returned from xfs_da_grow_inode when it fails to find free space.

Distinguish the two cases by returning 1 for the extra split case instead
of overloading -ENOSPC.

This can be triggered relatively easily with the pending realtime group
support and a file system with a lot of small zones that use metadata
space on the main device.  In this case every about 5-10th run of
xfs/538 runs into the following assert:

ASSERT(oldblk->magic == XFS_ATTR_LEAF_MAGIC);

in xfs_attr3_leaf_split caused by an allocation failure.  Note that
the allocation failure is caused by another bug that will be fixed
subsequently, but this commit at least sorts out the error handling.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: return bool from xfs_attr3_leaf_add
Christoph Hellwig [Tue, 15 Oct 2024 19:43:44 +0000 (12:43 -0700)]
xfs: return bool from xfs_attr3_leaf_add

Source kernel commit: 346c1d46d4c631c0c88592d371f585214d714da4

xfs_attr3_leaf_add only has two potential return values, indicating if the
entry could be added or not.  Replace the errno return with a bool so that
ENOSPC from it can't easily be confused with a real ENOSPC.

Remove the return value from the xfs_attr3_leaf_add_work helper entirely,
as it always return 0.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname
Christoph Hellwig [Tue, 15 Oct 2024 19:43:44 +0000 (12:43 -0700)]
xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname

Source kernel commit: b1c649da15c2e4c86344c8e5af69c8afa215efec

xfs_attr_leaf_try_add is only called by xfs_attr_leaf_addname, and
merging the two will simplify a following error handling fix.

To facilitate this move the remote block state save/restore helpers up in
the file so that they don't need forward declarations now.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: enable block size larger than page size support
Pankaj Raghav [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: enable block size larger than page size support

Source kernel commit: 7df7c204c678e24cd32d33360538670b7b90e330

Page cache now has the ability to have a minimum order when allocating
a folio which is a prerequisite to add support for block size > page
size.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20240827-xfs-fix-wformat-bs-gt-ps-v1-1-aec6717609e0@kernel.org
Link: https://lore.kernel.org/r/20240822135018.1931258-11-kernel@pankajraghav.com
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
8 months agoxfs: ensure st_blocks never goes to zero during COW writes
Christoph Hellwig [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: ensure st_blocks never goes to zero during COW writes

Source kernel commit: 90fa22da6d6b41dc17435aff7b800f9ca3c00401

COW writes remove the amount overwritten either directly for delalloc
reservations, or in earlier deferred transactions than adding the new
amount back in the bmap map transaction.  This means st_blocks on an
inode where all data is overwritten using the COW path can temporarily
show a 0 st_blocks.  This can easily be reproduced with the pending
zoned device support where all writes use this path and trips the
check in generic/615, but could also happen on a reflink file without
that.

Fix this by temporarily add the pending blocks to be mapped to
i_delayed_blks while the item is queued.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: convert perag lookup to xarray
Christoph Hellwig [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: convert perag lookup to xarray

Source kernel commit: 32fa4059fe6776d7db1e9058f360e06b36c9f2ce

Convert the perag lookup from the legacy radix tree to the xarray,
which allows for much nicer iteration and bulk lookup semantics.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: move the tagged perag lookup helpers to xfs_icache.c
Christoph Hellwig [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: move the tagged perag lookup helpers to xfs_icache.c

Source kernel commit: f48f0a8e00b67028d4492e7656b346fa0d806570

The tagged perag helpers are only used in xfs_icache.c in the kernel code
and not at all in xfsprogs.  Move them to xfs_icache.c in preparation for
switching to an xarray, for which I have no plan to implement the tagged
lookup functions for userspace.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: use kfree_rcu_mightsleep to free the perag structures
Christoph Hellwig [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: use kfree_rcu_mightsleep to free the perag structures

Source kernel commit: 4ef7c6d39dc72dae983b836c8b2b5de7128c0da3

Using the kfree_rcu_mightsleep is simpler and removes the need for a
rcu_head in the perag structure.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: remove unnecessary check
Dan Carpenter [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: remove unnecessary check

Source kernel commit: fb8b941c75bd70ddfb0a8a3bb9bb770ed1d648f8

We checked that "pip" is non-NULL at the start of the if else statement
so there is no need to check again here.  Delete the check.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: use kvmalloc for xattr buffers
Dave Chinner [Tue, 15 Oct 2024 19:43:42 +0000 (12:43 -0700)]
xfs: use kvmalloc for xattr buffers

Source kernel commit: de631e1a8b71017b8a12b57d07db82e4052555af

Pankaj Raghav reported that when filesystem block size is larger
than page size, the xattr code can use kmalloc() for high order
allocations. This triggers a useless warning in the allocator as it
is a __GFP_NOFAIL allocation here:

static inline
struct page *rmqueue(struct zone *preferred_zone,
struct zone *zone, unsigned int order,
gfp_t gfp_flags, unsigned int alloc_flags,
int migratetype)
{
struct page *page;

/*
* We most definitely don't want callers attempting to
* allocate greater than order-1 page units with __GFP_NOFAIL.
*/
>>>>    WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1));
...

Fix this by changing all these call sites to use kvmalloc(), which
will strip the NOFAIL from the kmalloc attempt and if that fails
will do a __GFP_NOFAIL vmalloc().

This is not an issue that productions systems will see as
filesystems with block size > page size cannot be mounted by the
kernel; Pankaj is developing this functionality right now.

Reported-by: Pankaj Raghav <kernel@pankajraghav.com>
Fixes: f078d4ea8276 ("xfs: convert kmem_alloc() to kmalloc()")
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Link: https://lore.kernel.org/r/20240822135018.1931258-8-kernel@pankajraghav.com
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Daniel Gomez <da.gomez@samsung.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
8 months agoxfs: standardize the btree maxrecs function parameters
Darrick J. Wong [Tue, 15 Oct 2024 19:43:42 +0000 (12:43 -0700)]
xfs: standardize the btree maxrecs function parameters

Source kernel commit: 411a71256de6f5a0015a28929cfbe6bc36c503dc

Standardize the parameters in xfs_{alloc,bm,ino,rmap,refcount}bt_maxrecs
so that we have consistent calling conventions.  This doesn't affect the
kernel that much, but enables us to clean up userspace a bit.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>