]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/log
thirdparty/xfsprogs-dev.git
2 years agoxfs_repair: explicitly cast resource usage counts in do_warn
Darrick J. Wong [Fri, 25 Feb 2022 22:42:16 +0000 (17:42 -0500)] 
xfs_repair: explicitly cast resource usage counts in do_warn

Explicitly cast the ondisk dquot counter argument to do_warn when
complaining about incorrect quota counts.  This avoids build warnings on
ppc64le.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs_db: fix nbits parameter in fa_ino[48] functions
Darrick J. Wong [Fri, 25 Feb 2022 22:42:16 +0000 (17:42 -0500)] 
xfs_db: fix nbits parameter in fa_ino[48] functions

Use the proper macro to convert ino4 and ino8 field byte sizes to a bit
count in the functions that navigate shortform directories.  This just
happens to work correctly for ino4 entries, but omits the upper 4 bytes
of an ino8 entry.  Note that the entries display correctly; it's just
the command "addr u3.sfdir3.list[X].inumber.i8" that won't.

Found by running smatch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs-apply: support filterdiff >= 0.4.2 only
Dave Chinner [Fri, 25 Feb 2022 22:41:33 +0000 (17:41 -0500)] 
libxfs-apply: support filterdiff >= 0.4.2 only

We currently require filterdiff v0.3.4 as a minimum for handling git
based patches. This was the first version to handle git diff
metadata well enough to do patch reformatting. It was, however, very
buggy and required several workarounds to get it to do what we
needed.

However, these bugs have been fixed and on a machine with v0.4.2,
the workarounds result in libxfs-apply breaking and creating corrupt
patches. Rather than try to carry around workarounds for a broken
filterdiff version and one that just works, just increase the
minimum required version to 0.4.2 and remove all the workarounds for
the bugs in 0.3.4.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agomisc: add a crc32c self test to mkfs and repair
Darrick J. Wong [Fri, 25 Feb 2022 22:37:56 +0000 (17:37 -0500)] 
misc: add a crc32c self test to mkfs and repair

Enhance mkfs and xfs_repair to run the crc32c self test when they start
up, and refuse to continue if the self test fails.   We don't want to
format a filesystem if the checksum algorithm produces incorrect
results, and we especially don't want repair to tear a filesystem apart
because it thinks the checksum is wrong.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibfrog: always use the kernel GETFSMAP definitions
Darrick J. Wong [Fri, 25 Feb 2022 22:37:50 +0000 (17:37 -0500)] 
libfrog: always use the kernel GETFSMAP definitions

The GETFSMAP ioctl has been a part of the kernel since 4.12.  We have no
business shipping a stale copy of kernel header contents in the xfslibs
package, so get rid of it.  This means that xfs_scrub now has a hard
dependency on the build system having new kernel headers.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: don't leave dangling perag references from xfs_buf
Darrick J. Wong [Fri, 25 Feb 2022 22:32:48 +0000 (17:32 -0500)] 
libxfs: don't leave dangling perag references from xfs_buf

When we're preparing to move a list of xfs_buf(fers) to the freelist, be
sure to detach the perag reference so that we don't leak the reference
or leave dangling pointers.  Currently this has no negative effects
since we only call libxfs_bulkrelse while exiting programs, but let's
not be sloppy.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: shut down filesystem if we xfs_trans_cancel with deferred work items
Darrick J. Wong [Fri, 25 Feb 2022 22:32:48 +0000 (17:32 -0500)] 
libxfs: shut down filesystem if we xfs_trans_cancel with deferred work items

While debugging some very strange rmap corruption reports in connection
with the online directory repair code.  I root-caused the error to the
following incorrect sequence:

<start repair transaction>
<expand directory, causing a deferred rmap to be queued>
<roll transaction>
<cancel transaction>

Obviously, we should have committed the transaction instead of
cancelling it.  Thinking more broadly, however, xfs_trans_cancel should
have warned us that we were throwing away work item that we already
committed to performing.  This is not correct, and we need to shut down
the filesystem.

Change xfs_trans_cancel to complain in the loudest manner if we're
cancelling any transaction with deferred work items attached.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxcmd: use emacs mode for command history editing
Darrick J. Wong [Fri, 25 Feb 2022 22:32:48 +0000 (17:32 -0500)] 
libxcmd: use emacs mode for command history editing

Prior to xfsprogs 5.7.0, we built xfsprogs with libreadline support by
default.  In its default configuration, that library interpreted various
keystrokes in a direct manner (e.g. backspace deletes the character to
the left of the cursor), which seems consistent with how emacs behaves.

However, libeditline's default keybindings are consistent with vim,
which means that suddenly users are presented with not the same line
editing interface that they had before.  Since libeditline is
configurable (put "bind -v" in editrc if you really want vim mode),
let's put things back the way they were.  At least as much as we can.

Fixes: bbe12eb9 ("xfsprogs: remove libreadline support")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfsprogs: Release v5.15.0-rc0 libxfs-5.15-sync v5.15.0-rc0
Eric Sandeen [Thu, 3 Feb 2022 20:00:27 +0000 (15:00 -0500)] 
xfsprogs: Release v5.15.0-rc0

Update all the necessary files for a 5.15.0-rc0 release.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: rename buffer cache index variable b_bn
Darrick J. Wong [Thu, 3 Feb 2022 19:58:35 +0000 (14:58 -0500)] 
libxfs: rename buffer cache index variable b_bn

To stop external users from using b_bn as the disk address of the
buffer, rename it to b_rhash_key to indicate that it is the buffer
cache index, not the block number of the buffer. Code that needs the
disk address should use xfs_buf_daddr() to obtain it.

Inspired-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[sandeen: moved the xfs_buf_daddr changes to prior patch]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: convert bp->b_bn references to xfs_buf_daddr()
Dave Chinner [Thu, 3 Feb 2022 19:58:32 +0000 (14:58 -0500)] 
xfs: convert bp->b_bn references to xfs_buf_daddr()

Source kernel commit: 9343ee76909e3f6466d85c9ebb0e343cdf54de71

Stop directly referencing b_bn in code outside the buffer cache, as
b_bn is supposed to be used only as an internal cache index.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: introduce xfs_buf_daddr()
Dave Chinner [Mon, 31 Jan 2022 22:46:05 +0000 (17:46 -0500)] 
xfs: introduce xfs_buf_daddr()

Source kernel commit: 04fcad80cd068731a779fb442f78234732683755

Introduce a helper function xfs_buf_daddr() to extract the disk
address of the buffer from the struct xfs_buf. This will replace
direct accesses to bp->b_bn and bp->b_maps[0].bm_bn, as well as
the XFS_BUF_ADDR() macro.

This patch introduces the helper function and replaces all uses of
XFS_BUF_ADDR() as this is just a simple sed replacement.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[sandeen: remove b_maps[0].bm_bn assignment in alloc_write_buf now]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: replace XFS_BUF_SET_ADDR with a function
Darrick J. Wong [Mon, 31 Jan 2022 22:46:05 +0000 (17:46 -0500)] 
libxfs: replace XFS_BUF_SET_ADDR with a function

Replace XFS_BUF_SET_ADDR with a new function that will set the buffer
block number correctly, then port the two users to it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[sandeen: leave b_maps[0].bm_bn until next patch]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: always initialize internal buffer map
Darrick J. Wong [Mon, 31 Jan 2022 22:46:05 +0000 (17:46 -0500)] 
libxfs: always initialize internal buffer map

The __initbuf function is responsible for initializing the fields of an
xfs_buf.  Buffers are always required to have a mapping, though in the
typical case there's only one mapping, so we can use the internal one.

The single-mapping b_maps init code at the end of the function doesn't
quite get this right though -- if a single-mapping buffer in the cache
was allowed to expire and now is being repurposed, it'll come out with
b_maps == &__b_map, in which case we incorrectly skip initializing the
map.  This has gone unnoticed until now because (AFAICT) the code paths
that use b_maps are the same ones that are called with multi-mapping
buffers, which are initialized correctly.

Anyway, the improperly initialized single-mappings will cause problems
in upcoming patches where we turn b_bn into the cache key and require
the use of b_maps[0].bm_bn for the buffer LBA.  Fix this.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: clean up remaining LIBXFS_MOUNT flags
Darrick J. Wong [Mon, 31 Jan 2022 22:46:04 +0000 (17:46 -0500)] 
libxfs: clean up remaining LIBXFS_MOUNT flags

Now that userspace libxfs also uses m_opstate to track operational
state, the LIBXFS_MOUNT_* flags are only used for the flags argument
passed to libxfs_mount().  Update the comment to reflect this, and clean
up the flags and function declaration whiel we're at it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoGet rid of these flags and the m_flags field, since none of them do
Darrick J. Wong [Mon, 31 Jan 2022 22:46:02 +0000 (17:46 -0500)] 
Get rid of these flags and the m_flags field, since none of them do
anything anymore.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
[sandeen: keep xfs_set_inode_alloc similar to kernel for now]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: use opstate flags and functions for libxfs mount options
Darrick J. Wong [Mon, 31 Jan 2022 22:27:45 +0000 (17:27 -0500)] 
libxfs: use opstate flags and functions for libxfs mount options

Port the three LIBXFS_MOUNT flags that actually do anything to set
opstate flags in preparation for removing m_flags in a later patch.
Retain the LIBXFS_MOUNT #defines so that libxfs clients can pass them
into libxfs_mount.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[sandeen: drop now-unused flags arg from rtmount_init]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: kill xfs_sb_version_has_v3inode()
Dave Chinner [Mon, 31 Jan 2022 22:27:45 +0000 (17:27 -0500)] 
xfs: kill xfs_sb_version_has_v3inode()

Source kernel commit: cf28e17c9186c83e7e8702f844bc40b6e782ce6c

All callers to xfs_dinode_good_version() and XFS_DINODE_SIZE() in
both the kernel and userspace have a xfs_mount structure available
which means they can use mount features checks instead looking
directly are the superblock.

Convert these functions to take a mount and use a xfs_has_v3inodes()
check and move it out of the libxfs/xfs_format.h file as it really
doesn't have anything to do with the definition of the on-disk
format.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: introduce xfs_sb_is_v5 helper
Dave Chinner [Mon, 31 Jan 2022 22:27:45 +0000 (17:27 -0500)] 
xfs: introduce xfs_sb_is_v5 helper

Source kernel commit: d6837c1aab42e70141fd3875ba05eb69ffb220f0

Rather than open coding XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5
checks everywhere, add a simple wrapper to encapsulate this and make
the code easier to read.

This allows us to remove the xfs_sb_version_has_v3inode() wrapper
which is only used in xfs_format.h now and is just a version number
check.

There are a couple of places where we should be checking the mount
feature bits rather than the superblock version (e.g. remount), so
those are converted to use xfs_has_crc(mp) instead.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: remove unused xfs_sb_version_has wrappers
Dave Chinner [Mon, 31 Jan 2022 22:27:45 +0000 (17:27 -0500)] 
xfs: remove unused xfs_sb_version_has wrappers

Source kernel commit: 2beb7b50ddd429f47b6cabd186b3102d2a6aa505

The vast majority of these wrappers are now unused. Remove them
leaving just the small subset of wrappers that are used to either
add feature bits or make the mount features field setup code
simpler.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs_{copy,db,logprint,repair}: replace xfs_sb_version checks with feature flag checks
Darrick J. Wong [Mon, 31 Jan 2022 22:27:44 +0000 (17:27 -0500)] 
xfs_{copy,db,logprint,repair}: replace xfs_sb_version checks with feature flag checks

Convert the xfs_sb_version_hasfoo() to checks against mp->m_features.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: replace xfs_sb_version checks with feature flag checks
Darrick J. Wong [Mon, 31 Jan 2022 22:27:44 +0000 (17:27 -0500)] 
libxfs: replace xfs_sb_version checks with feature flag checks

Convert the xfs_sb_version_hasfoo() to checks against mp->m_features.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[sandeen: drop one hunk that wasn't really a conversion]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxlog: replace xfs_sb_version checks with feature flag checks
Darrick J. Wong [Mon, 31 Jan 2022 22:27:44 +0000 (17:27 -0500)] 
libxlog: replace xfs_sb_version checks with feature flag checks

Convert the xfs_sb_version_hasfoo() to checks against mp->m_features.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[sandeen: drop hunk to libxfs/init.c that's not a straight replace]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: convert xfs_sb_version_has checks to use mount features
Dave Chinner [Mon, 31 Jan 2022 22:27:44 +0000 (17:27 -0500)] 
xfs: convert xfs_sb_version_has checks to use mount features

Source kernel commit: ebd9027d088b3a4e49d294f79e6cadb7b7a88b28

This is a conversion of the remaining xfs_sb_version_has..(sbp)
checks to use xfs_has_..(mp) feature checks.

This was largely done with a vim replacement macro that did:

:0,$s/xfs_sb_version_has\(.*\)&\(.*\)->m_sb/xfs_has_\1\2/g<CR>

A couple of other variants were also used, and the rest touched up
by hand.

$ size -t fs/xfs/built-in.a
text    data     bss     dec     hex filename
before  1127533  311352     484 1439369  15f689 (TOTALS)
after   1125360  311352     484 1437196  15ee0c (TOTALS)

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: open code sb verifier feature checks
Dave Chinner [Mon, 31 Jan 2022 22:27:44 +0000 (17:27 -0500)] 
xfs: open code sb verifier feature checks

Source kernel commit: fe08cc5044486096bfb5ce9d3db4e915e53281ea

The superblock verifiers are one of the last places that use the sb
version functions to do feature checks. This are all quite simple
uses, and there aren't many of them so open code them all.

Also, move the good version number check into xfs_sb.c instead of it
being an inline function in xfs_format.h

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: convert xfs_fs_geometry to use mount feature checks
Dave Chinner [Mon, 31 Jan 2022 22:27:44 +0000 (17:27 -0500)] 
xfs: convert xfs_fs_geometry to use mount feature checks

Source kernel commit: 03288b19093b9bcff72f0d5f90c578daf053f759

Reporting filesystem features to userspace is currently superblock
based. Now we have a general mount-based feature infrastructure,
switch to using the xfs_mount rather than the superblock directly.

This reduces the size of the function by over 300 bytes.

$ size -t fs/xfs/built-in.a
text    data     bss     dec     hex filename
before  1127855  311352     484 1439691  15f7cb (TOTALS)
after   1127535  311352     484 1439371  15f68b (TOTALS)

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: replace XFS_FORCED_SHUTDOWN with xfs_is_shutdown
Dave Chinner [Mon, 31 Jan 2022 22:27:19 +0000 (17:27 -0500)] 
xfs: replace XFS_FORCED_SHUTDOWN with xfs_is_shutdown

Source kernel commit: 75c8c50fa16a23f8ac89ea74834ae8ddd1558d75

Remove the shouty macro and instead use the inline function that
matches other state/feature check wrapper naming. This conversion
was done with sed.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: convert remaining mount flags to state flags
Dave Chinner [Mon, 31 Jan 2022 22:26:19 +0000 (17:26 -0500)] 
xfs: convert remaining mount flags to state flags

Source kernel commit: 2e973b2cd4cdb993be94cca4c33f532f1ed05316

The remaining mount flags kept in m_flags are actually runtime state
flags. These change dynamically, so they really should be updated
atomically so we don't potentially lose an update due to racing
modifications.

Convert these remaining flags to be stored in m_opstate and use
atomic bitops to set and clear the flags. This also adds a couple of
simple wrappers for common state checks - read only and shutdown.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: convert mount flags to features
Dave Chinner [Mon, 31 Jan 2022 22:22:11 +0000 (17:22 -0500)] 
xfs: convert mount flags to features

Source kernel commit: 0560f31a09e523090d1ab2bfe21c69d028c2bdf2

Replace m_flags feature checks with xfs_has_<feature>() calls and
rework the setup code to set flags in m_features.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[sandeen: add small_inums to userspace unsupported features]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: replace xfs_sb_version checks with feature flag checks
Dave Chinner [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: replace xfs_sb_version checks with feature flag checks

Source kernel commit: 38c26bfd90e1999650d5ef40f90d721f05916643

Convert the xfs_sb_version_hasfoo() to checks against
mp->m_features. Checks of the superblock itself during disk
operations (e.g. in the read/write verifiers and the to/from disk
formatters) are not converted - they operate purely on the
superblock state. Everything else should use the mount features.

Large parts of this conversion were done with sed with commands like
this:

for f in `git grep -l xfs_sb_version_has fs/xfs/*.c`; do
sed -i -e 's/xfs_sb_version_has\(.*\)(&\(.*\)->m_sb)/xfs_has_\1(\2)/' $f
done

With manual cleanups for things like "xfs_has_extflgbit" and other
little inconsistencies in naming.

The result is ia lot less typing to check features and an XFS binary
size reduced by a bit over 3kB:

$ size -t fs/xfs/built-in.a
text       data     bss     dec     hex filenam
before  1130866  311352     484 1442702  16038e (TOTALS)
after   1127727  311352     484 1439563  15f74b (TOTALS)

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: reflect sb features in xfs_mount
Dave Chinner [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: reflect sb features in xfs_mount

Source kernel commit: a1d86e8dec8c1325d301c9d5594bb794bc428fc3

Currently on-disk feature checks require decoding the superblock
fileds and so can be non-trivial. We have almost 400 hundred
individual feature checks in the XFS code, so this is a significant
amount of code. To reduce runtime check overhead, pre-process all
the version flags into a features field in the xfs_mount at mount
time so we can convert all the feature checks to a simple flag
check.

There is also a need to convert the dynamic feature flags to update
the m_features field. This is required for attr, attr2 and quota
features. New xfs_mount based wrappers are added for this.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: rework attr2 feature and mount options
Dave Chinner [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: rework attr2 feature and mount options

Source kernel commit: e23b55d537c9be60ae918fa6c3be0d699986f346

The attr2 feature is somewhat unique in that it has both a superblock
feature bit to enable it and mount options to enable and disable it.

Back when it was first introduced in 2005, attr2 was disabled unless
either the attr2 superblock feature bit was set, or the attr2 mount
option was set. If the superblock feature bit was not set but the
mount option was set, then when the first attr2 format inode fork
was created, it would set the superblock feature bit. This is as it
should be - the superblock feature bit indicated the presence of the
attr2 on disk format.

The noattr2 mount option, however, did not affect the superblock
feature bit. If noattr2 was specified, the on-disk superblock
feature bit was ignored and the code always just created attr1
format inode forks.  If neither of the attr2 or noattr2 mounts
option were specified, then the behaviour was determined by the
superblock feature bit.

This was all pretty sane.

Fast foward 3 years, and we are dealing with fallout from the
botched sb_features2 addition and having to deal with feature
mismatches between the sb_features2 and sb_bad_features2 fields. The
attr2 feature bit was one of these flags. The reconciliation was
done well after mount option parsing and, unfortunately, the feature
reconciliation had a bug where it ignored the noattr2 mount option.

For reasons lost to the mists of time, it was decided that resolving
this issue in commit 7c12f296500e ("[XFS] Fix up noattr2 so that it
will properly update the versionnum and features2 fields.") required
noattr2 to clear the superblock attr2 feature bit.  This greatly
complicated the attr2 behaviour and broke rules about feature bits
needing to be set when those specific features are present in the
filesystem.

By complicated, I mean that it introduced problems due to feature
bit interactions with log recovery. All of the superblock feature
bit checks are done prior to log recovery, but if we crash after
removing a feature bit, then on the next mount we see the feature
bit in the unrecovered superblock, only to have it go away after the
log has been replayed.  This means our mount time feature processing
could be all wrong.

Hence you can mount with noattr2, crash shortly afterwards, and
mount again without attr2 or noattr2 and still have attr2 enabled
because the second mount sees attr2 still enabled in the superblock
before recovery runs and removes the feature bit. It's just a mess.

Further, this is all legacy code as the v5 format requires attr2 to
be enabled at all times and it cannot be disabled.  i.e. the noattr2
mount option returns an error when used on v5 format filesystems.

To straighten this all out, this patch reverts the attr2/noattr2
mount option behaviour back to the original behaviour. There is no
reason for disabling attr2 these days, so we will only do this when
the noattr2 mount option is set. This will not remove the superblock
feature bit. The superblock bit will provide the default behaviour
and only track whether attr2 is present on disk or not. The attr2
mount option will enable the creation of attr2 format inode forks,
and if the superblock feature bit is not set it will be added when
the first attr2 inode fork is created.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: rename xfs_has_attr()
Dave Chinner [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: rename xfs_has_attr()

Source kernel commit: 51b495eba84dee8c1df4abfc26fc134ea190e28f

xfs_has_attr() is poorly named. It has global scope as it is defined
in a header file, but it has no namespace scope that tells us what
it is checking has attributes. It's not even clear what "has_attr"
means, because what it is actually doing is an attribute fork lookup
to see if the attribute exists.

Upcoming patches use this "xfs_has_<foo>" namespace for global
filesystem features, which conflicts with this function.

Rename xfs_has_attr() to xfs_attr_lookup() and make it a static
function, freeing up the "xfs_has_" namespace for global scope
usage.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: sb verifier doesn't handle uncached sb buffer
Dave Chinner [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: sb verifier doesn't handle uncached sb buffer

Source kernel commit: 8cf07f3dd56195316be97758cb8b4e1d7183ea84

The verifier checks explicitly for bp->b_bn == XFS_SB_DADDR to match
the primary superblock buffer, but the primary superblock is an
uncached buffer and so bp->b_bn is always -1ULL. Hence this never
matches and the CRC error reporting is wholly dependent on the
mount superblock already being populated so CRC feature checks pass
and allow CRC errors to be reported.

Fix this so that the primary superblock CRC error reporting is not
dependent on already having read the superblock into memory.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: resolve fork names in trace output
Darrick J. Wong [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: resolve fork names in trace output

Source kernel commit: f93f85f77aa80f3e4d5bada01248c98da32933c5

Emit whichfork values as text strings in the ftrace output.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: constify btree function parameters that are not modified
Darrick J. Wong [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: constify btree function parameters that are not modified

Source kernel commit: 32816fd7920b32c24e1720ce387482fb430959fc

Constify the rest of the btree functions that take structure and union
pointers and are not supposed to modify them.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: make the start pointer passed to btree update_lastrec functions const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: make the start pointer passed to btree update_lastrec functions const

Source kernel commit: 60e265f7f85a3d91c368f9284dc6501fa1f41e50

This btree function is called when updating a record in the rightmost
block of a btree so that we can update the AGF's longest free extent
length field.  Neither parameter is supposed to be updated, so mark them
both const.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: make the start pointer passed to btree alloc_block functions const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: make the start pointer passed to btree alloc_block functions const

Source kernel commit: deb06b9ab6dfa167c280a68d5acb2f12e007073f

The @start pointer passed to each per-AG btree type's ->alloc_block
function isn't supposed to be modified, since it's a hint about the
location of the btree block being split that is to be fed to the
allocator, so mark the parameter const.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: make the pointer passed to btree set_root functions const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: make the pointer passed to btree set_root functions const

Source kernel commit: b5a6e5fe0e6840bc90e51cf522d6c5a880cde567

The pointer passed to each per-AG btree type's ->set_root function isn't
supposed to be modified (that function sets an external pointer to the
root block) so mark them const.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: mark the record passed into xchk_btree functions as const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:48 +0000 (15:25 -0500)] 
xfs: mark the record passed into xchk_btree functions as const

Source kernel commit: 22ece4e836beff1df528ee09cf21ca5fab7235f5

xchk_btree calls a user-supplied function to validate each btree record
that it finds.  Those functions are not supposed to change the record
data, so mark the parameter const.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: make the keys and records passed to btree inorder functions const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: make the keys and records passed to btree inorder functions const

Source kernel commit: 8e38dc88a67b3c7475cbe8a132d03542717c1e27

The inorder functions are simple predicates, which means that they don't
modify the parameters.  Mark them all const.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: mark the record passed into btree init_key functions as const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: mark the record passed into btree init_key functions as const

Source kernel commit: 23825cd148764ce133ee92375da395140d6ccb15

These functions initialize a key from a record, but they aren't supposed
to modify the record.  Mark it const.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: make the record pointer passed to query_range functions const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: make the record pointer passed to query_range functions const

Source kernel commit: 159eb69dba8baf6d5b58b69936920fb311324c82

The query_range functions are supposed to call a caller-supplied
function on each record found in the dataset.  These functions don't
own the memory storing the record, so don't let them change the record.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: make the key parameters to all btree query range functions const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: make the key parameters to all btree query range functions const

Source kernel commit: 04dcb47482a9d9e27feba48ca92613edced42ef9

Range query functions are not supposed to modify the query keys that are
being passed in, so mark them all const.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: make the key parameters to all btree key comparison functions const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: make the key parameters to all btree key comparison functions const

Source kernel commit: d29d5577774d7d032da1343dba80be7423e307f9

The btree key comparison functions are not allowed to change the keys
that are passed in, so mark them const.  We'll need this for the next
patch, which adds const to the btree range query functions.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: make xfs_rtalloc_query_range input parameters const
Darrick J. Wong [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: make xfs_rtalloc_query_range input parameters const

Source kernel commit: c02f6529864a4f5f91d216d324bac4ba75415d19

In commit 8ad560d2565e, we changed xfs_rtalloc_query_range to constrain
the range of bits in the realtime bitmap file that would actually be
searched.  In commit a3a374bf1889, we changed the range again
(incorrectly), leading to the fix in commit d88850bd5516, which finally
corrected the range check code.  Unfortunately, the author never noticed
that the function modifies its input parameters, which is a totaly no-no
since none of the other range query functions change their input
parameters.

So, fix this function yet again to stash the upper end of the query
range (i.e. the high key) in a local variable and hope this is the last
time I have to fix my own function.  While we're at it, mark the key
inputs const so nobody makes this mistake again. :(

Fixes: 8ad560d2565e ("xfs: strengthen rtalloc query range checks")
Not-fixed-by: a3a374bf1889 ("xfs: fix off-by-one error in xfs_rtalloc_query_range")
Not-fixed-by: d88850bd5516 ("xfs: fix high key handling in the rt allocator's query_range function")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: Rename __xfs_attr_rmtval_remove
Allison Henderson [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: Rename __xfs_attr_rmtval_remove

Source kernel commit: 5e68b4c7fb6414c4a48b6d2988312e3b1f31978e

Now that xfs_attr_rmtval_remove is gone, rename __xfs_attr_rmtval_remove
to xfs_attr_rmtval_remove

Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: add attr state machine tracepoints
Allison Henderson [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: add attr state machine tracepoints

Source kernel commit: df0826312a23e495faa91eee0d6ac31bca35dc09

This is a quick patch to add a new xfs_attr_*_return tracepoints.  We
use these to track when ever a new state is set or -EAGAIN is returned

Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: allow setting and clearing of log incompat feature flags
Darrick J. Wong [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: allow setting and clearing of log incompat feature flags

Source kernel commit: 908ce71e54f8265fa909200410d6c50ab9a2d302

Log incompat feature flags in the superblock exist for one purpose: to
protect the contents of a dirty log from replay on a kernel that isn't
prepared to handle those dirty contents.  This means that they can be
cleared if (a) we know the log is clean and (b) we know that there
aren't any other threads in the system that might be setting or relying
upon a log incompat flag.

Therefore, clear the log incompat flags when we've finished recovering
the log, when we're unmounting cleanly, remounting read-only, or
freezing; and provide a function so that subsequent patches can start
using this.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: replace kmem_alloc_large() with kvmalloc()
Dave Chinner [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: replace kmem_alloc_large() with kvmalloc()

Source kernel commit: d634525db63e9e946c3229fb93c8d9b763afbaf3

There is no reason for this wrapper existing anymore. All the places
that use KM_NOFS allocation are within transaction contexts and
hence covered by memalloc_nofs_save/restore contexts. Hence we don't
need any special handling of vmalloc for large IOs anymore and
so special casing this code isn't necessary.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: remove the active vs running quota differentiation
Christoph Hellwig [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: remove the active vs running quota differentiation

Source kernel commit: 149e53afc851713a70b6a06ebfaf2ebf25975454

These only made a difference when quotaoff supported disabling quota
accounting on a mounted file system, so we can switch everyone to use
a single set of flags and helpers now. Note that the *QUOTA_ON naming
for the helpers is kept as it was the much more commonly used one.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: remove support for disabling quota accounting on a mounted file system
Christoph Hellwig [Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)] 
xfs: remove support for disabling quota accounting on a mounted file system

Source kernel commit: 40b52225e58cd3adf9358146b4b39dccfbfe5892

Disabling quota accounting is hairy, racy code with all kinds of pitfalls.
And it has a very strange mind set, as quota accounting (unlike
enforcement) really is a propery of the on-disk format.  There is no good
use case for supporting this.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs_{copy,db,logprint,repair}: pass xfs_mount pointers instead of xfs_sb pointers
Darrick J. Wong [Mon, 31 Jan 2022 20:25:41 +0000 (15:25 -0500)] 
xfs_{copy,db,logprint,repair}: pass xfs_mount pointers instead of xfs_sb pointers

Where possible, convert these four programs to pass a pointer to a
struct xfs_mount instead of the struct xfs_sb inside the mount.  This
will make it easier to convert some of the code to the new
xfs_has_FEATURE predicates later on.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfsprogs: fix static build problems caused by liburcu
Theodore Ts'o [Mon, 31 Jan 2022 20:24:54 +0000 (15:24 -0500)] 
xfsprogs: fix static build problems caused by liburcu

The liburcu library has a dependency on pthreads.  Hence, in order for
static builds of xfsprogs to work, $(LIBPTHREAD) needs to appear
*after* $(LUBURCU) in LLDLIBS.  Otherwise, static links of xfs_* will
fail due to undefined references of pthread_create, pthread_exit,
et. al.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfsprogs: Release v5.14.2 v5.14.2
Eric Sandeen [Mon, 6 Dec 2021 21:41:57 +0000 (16:41 -0500)] 
xfsprogs: Release v5.14.2

Update all the necessary files for a 5.14.2 release.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: hide the drainbamaged fallthrough macro from xfslibs
Darrick J. Wong [Mon, 6 Dec 2021 19:26:04 +0000 (14:26 -0500)] 
libxfs: hide the drainbamaged fallthrough macro from xfslibs

Back in mid-2021, Kees and Gustavo rammed into the kernel a bunch of
static checker "improvements" that redefined '/* fallthrough */'
comments for switch statements as a macro that virtualizes either that
same comment, a do-while loop, or a compiler __attribute__.  This was
necessary to work around the poor decision-making of the clang, gcc, and
C language standard authors, who collectively came up with four mutually
incompatible ways to document a lack of branching in a code flow.

Having received ZERO HELP porting this to userspace, Eric and I
foolishly dumped that crap into linux.h, which was a poor decision
because we keep forgetting that linux.h is exported as a userspace
header.  This has now caused downstream regressions in Debian[1] and
will probably cause more problems in the other distros.

Move it to platform_defs.h since that's not shipped publicly and leave a
warning to anyone else who dare modify linux.h.

[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1000974

Fixes: df9c7d8d ("xfs: Fix fall-through warnings for Clang")
Cc: 1000974@bugs.debian.org, gustavoars@kernel.org, keescook@chromium.org
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
[sandeen: add comment to top of linux.h  per Dave's suggestion]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfsprogs: Release v5.14.1 v5.14.1
Eric Sandeen [Thu, 2 Dec 2021 22:02:13 +0000 (17:02 -0500)] 
xfsprogs: Release v5.14.1

Update all the necessary files for a 5.14.1 release.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibxfs: fix atomic64_t poorly for 32-bit architectures
Darrick J. Wong [Thu, 2 Dec 2021 20:24:33 +0000 (15:24 -0500)] 
libxfs: fix atomic64_t poorly for 32-bit architectures

In commit de555f66, we converted the atomic64_t implementation to use
the liburcu uatomic_* functions.  Regrettably, nobody tried to build
xfsprogs on a 32-bit architecture (hint: maintainers don't scale well
anymore) so nobody noticed that the build fails due to the unknown
symbol _uatomic_link_error.  This is what happens when liburcu doesn't
know how to perform atomic updates to a variable of a certain size, due
to some horrid macro magic in urcu.h.

Rather than a strict revert to non-atomic updates for these platforms or
(which would introduce a landmine) or roll everything back for the sake
of older platforms, I went with providing a custom atomic64_t
implementation that uses a single pthread mutex.  This enables us to
work around the fact that the kernel atomic64_t API doesn't require a
special initializer function, and is probably good enough since there
are only a handful of atomic64_t counters in the kernel.

Clean up the type declarations of a couple of variables in libxlog to
match the kernel usage, though that's probably overkill.

Eventually we'll want to decide if we're deprecating 32-bit, but this
fixes them in the mean time.

[sandeen: make the custom atomic64_add() take an int64_t]

Fixes: de555f66 ("atomic: convert to uatomic")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agolibfrog: fix crc32c self test code on cross builds
Darrick J. Wong [Thu, 2 Dec 2021 20:24:32 +0000 (15:24 -0500)] 
libfrog: fix crc32c self test code on cross builds

Helmut Grohne reported that the crc32c self test program fails to cross
build on 5.14.0 if the build host doesn't have liburcu installed.  We
don't need userspace RCU functionality to test crc32 on the build host,
so twiddle the header files to include only the two header files that we
actually need.

Note: Build-time testing of crc32c is useful for upstream developers so
that we can check that we haven't broken the checksum code, but we
really ought to be testing this in mkfs and repair on the user's system
so that they don't end up with garbage filesystems.  A future patch will
introduce that.

Reported-by: Helmut Grohne <helmut@subdivi.de>
Cc: Bastian Germann <bage@debian.org>
Suggested-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfsprogs: Release v5.14.0 v5.14.0
Eric Sandeen [Fri, 19 Nov 2021 15:59:45 +0000 (10:59 -0500)] 
xfsprogs: Release v5.14.0

Update all the necessary files for a 5.14.0 release.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agodebian: Add changelog entry for 5.14.0-rc1-1
Bastian Germann [Fri, 19 Nov 2021 03:05:11 +0000 (22:05 -0500)] 
debian: Add changelog entry for 5.14.0-rc1-1

This holds all package changes since v5.13.0.
Add Closes tags that will autoclose related bugs.

Signed-off-by: Bastian Germann <bage@debian.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agodebian: Fix FTBFS
Boian Bonev [Fri, 19 Nov 2021 03:05:11 +0000 (22:05 -0500)] 
debian: Fix FTBFS

With newer autotools install-sh is regenerated by libtoolize.
Copy the package's version after autogen.

Link: https://bugs.debian.org/997656
Signed-off-by: Boian Bonev <bbonev@ipacct.com>
Signed-off-by: Bastian Germann <bage@debian.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agodebian: Pass --build and --host to configure
Bastian Germann [Fri, 19 Nov 2021 03:05:11 +0000 (22:05 -0500)] 
debian: Pass --build and --host to configure

xfsprogs fails to cross build because it fails to pass --host to configure.
Thus it selects the build architecture as host architecture and fails
configure, because the requested libraries are only installed for the host
architecture.

Link: https://bugs.debian.org/794158
Reported-by: Helmut Grohne <helmut@subdivi.de>
Signed-off-by: Bastian Germann <bage@debian.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agodebian: Update Uploaders list
Bastian Germann [Fri, 19 Nov 2021 03:05:11 +0000 (22:05 -0500)] 
debian: Update Uploaders list

Set Bastian's debian.org email address.

Signed-off-by: Bastian Germann <bage@debian.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfsprogs: Release v5.14.0-rc1 v5.14.0-rc1
Eric Sandeen [Fri, 12 Nov 2021 20:38:42 +0000 (15:38 -0500)] 
xfsprogs: Release v5.14.0-rc1

Update all the necessary files for a 5.14.0-rc1 release.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agomkfs: warn about V4 deprecation when creating new V4 filesystems
Darrick J. Wong [Fri, 12 Nov 2021 20:27:59 +0000 (15:27 -0500)] 
mkfs: warn about V4 deprecation when creating new V4 filesystems

The V4 filesystem format is deprecated in the upstream Linux kernel.  In
September 2025 it will be turned off by default in the kernel and five
years after that, support will be removed entirely.  Warn people
formatting new filesystems with the old format, particularly since V4 is
not the default.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: sync xfs_btree_split macros with userspace libxfs
Darrick J. Wong [Fri, 12 Nov 2021 20:20:04 +0000 (15:20 -0500)] 
xfs: sync xfs_btree_split macros with userspace libxfs

Source kernel commit: 4a6b35b3b3f28df81fea931dc77c4c229cbdb5b2

Sync this one last bit of discrepancy between kernel and userspace
libxfs.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: #ifdef out perag code for userspace
Eric Sandeen [Fri, 12 Nov 2021 20:17:14 +0000 (15:17 -0500)] 
xfs: #ifdef out perag code for userspace

Source kernel commit: 29f11fce211c7fcf32713457c031e71785fb6088

The xfs_perag structure and initialization is unused in userspace,
so #ifdef it out with __KERNEL__ to facilitate the xfsprogs sync
and build.

Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs_db: convert the agresv command to use for_each_perag libxfs-5.14-sync
Darrick J. Wong [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs_db: convert the agresv command to use for_each_perag

Convert the AG iteration loop for this debugger command to use
for_each_perag, since it's the only place in userspace that obvious
wants it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: logging the on disk inode LSN can make it go backwards
Dave Chinner [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: logging the on disk inode LSN can make it go backwards

Source kernel commit: 32baa63d82ee3f5ab3bd51bae6bf7d1c15aed8c7

When we log an inode, we format the "log inode" core and set an LSN
in that inode core. We do that via xfs_inode_item_format_core(),
which calls:

xfs_inode_to_log_dinode(ip, dic, ip->i_itemp->ili_item.li_lsn);

to format the log inode. It writes the LSN from the inode item into
the log inode, and if recovery decides the inode item needs to be
replayed, it recovers the log inode LSN field and writes it into the
on disk inode LSN field.

Now this might seem like a reasonable thing to do, but it is wrong
on multiple levels. Firstly, if the item is not yet in the AIL,
item->li_lsn is zero. i.e. the first time the inode it is logged and
formatted, the LSN we write into the log inode will be zero. If we
only log it once, recovery will run and can write this zero LSN into
the inode.

This means that the next time the inode is logged and log recovery
runs, it will *always* replay changes to the inode regardless of
whether the inode is newer on disk than the version in the log and
that violates the entire purpose of recording the LSN in the inode
at writeback time (i.e. to stop it going backwards in time on disk
during recovery).

Secondly, if we commit the CIL to the journal so the inode item
moves to the AIL, and then relog the inode, the LSN that gets
stamped into the log inode will be the LSN of the inode's current
location in the AIL, not it's age on disk. And it's not the LSN that
will be associated with the current change. That means when log
recovery replays this inode item, the LSN that ends up on disk is
the LSN for the previous changes in the log, not the current
changes being replayed. IOWs, after recovery the LSN on disk is not
in sync with the LSN of the modifications that were replayed into
the inode. This, again, violates the recovery ordering semantics
that on-disk writeback LSNs provide.

Hence the inode LSN in the log dinode is -always- invalid.

Thirdly, recovery actually has the LSN of the log transaction it is
replaying right at hand - it uses it to determine if it should
replay the inode by comparing it to the on-disk inode's LSN. But it
doesn't use that LSN to stamp the LSN into the inode which will be
written back when the transaction is fully replayed. It uses the one
in the log dinode, which we know is always going to be incorrect.

Looking back at the change history, the inode logging was broken by
back in 2016 by a stupid idiot who thought he knew how this code
worked. i.e. me. That commit replaced an in memory di_lsn field that
was updated only at inode writeback time from the inode item.li_lsn
value - and hence always contained the same LSN that appeared in the
on-disk inode - with a read of the inode item LSN at inode format
time. CLearly these are not the same thing.

Before 93f958f9c41f, the log recovery behaviour was irrelevant,
because the LSN in the log inode always matched the on-disk LSN at
the time the inode was logged, hence recovery of the transaction
would never make the on-disk LSN in the inode go backwards or get
out of sync.

A symptom of the problem is this, caught from a failure of
generic/482. Before log recovery, the inode has been allocated but
never used:

xfs_db> inode 393388
xfs_db> p
core.magic = 0x494e
core.mode = 0
....
v3.crc = 0x99126961 (correct)
v3.change_count = 0
v3.lsn = 0
v3.flags2 = 0
v3.cowextsize = 0
v3.crtime.sec = Thu Jan  1 10:00:00 1970
v3.crtime.nsec = 0

After log recovery:

xfs_db> p
core.magic = 0x494e
core.mode = 020444
....
v3.crc = 0x23e68f23 (correct)
v3.change_count = 2
v3.lsn = 0
v3.flags2 = 0
v3.cowextsize = 0
v3.crtime.sec = Thu Jul 22 17:03:03 2021
v3.crtime.nsec = 751000000
...

You can see that the LSN of the on-disk inode is 0, even though it
clearly has been written to disk. I point out this inode, because
the generic/482 failure occurred because several adjacent inodes in
this specific inode cluster were not replayed correctly and still
appeared to be zero on disk when all the other metadata (inobt,
finobt, directories, etc) indicated they should be allocated and
written back.

The fix for this is two-fold. The first is that we need to either
revert the LSN changes in 93f958f9c41f or stop logging the inode LSN
altogether. If we do the former, log recovery does not need to
change but we add 8 bytes of memory per inode to store what is
largely a write-only inode field. If we do the latter, log recovery
needs to stamp the on-disk inode in the same manner that inode
writeback does.

I prefer the latter, because we shouldn't really be trying to log
and replay changes to the on disk LSN as the on-disk value is the
canonical source of the on-disk version of the inode. It also
matches the way we recover buffer items - we create a buf_log_item
that carries the current recovery transaction LSN that gets stamped
into the buffer by the write verifier when it gets written back
when the transaction is fully recovered.

However, this might break log recovery on older kernels even more,
so I'm going to simply ignore the logged value in recovery and stamp
the on-disk inode with the LSN of the transaction being recovered
that will trigger writeback on transaction recovery completion. This
will ensure that the on-disk inode LSN always reflects the LSN of
the last change that was written to disk, regardless of whether it
comes from log recovery or runtime writeback.

Fixes: 93f958f9c41f ("xfs: cull unnecessary icdinode fields")
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: correct the narrative around misaligned rtinherit/extszinherit dirs
Darrick J. Wong [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: correct the narrative around misaligned rtinherit/extszinherit dirs

Source kernel commit: 83193e5ebb0164d612aa620ceab7d3746e80e2a4

While auditing the realtime growfs code, I realized that the GROWFSRT
ioctl (and by extension xfs_growfs) has always allowed sysadmins to
change the realtime extent size when adding a realtime section to the
filesystem.  Since we also have always allowed sysadmins to set
RTINHERIT and EXTSZINHERIT on directories even if there is no realtime
device, this invalidates the premise laid out in the comments added in

In other words, this is not a case of inadequate metadata validation.
This is a case of nearly forgotten (and apparently untested) but
supported functionality.  Update the comments to reflect what we've
learned, and remove the log message about correcting the misalignment.

Fixes: 603f000b15f2 ("xfs: validate extsz hints against rt extent size when rtinherit is set")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: check for sparse inode clusters that cross new EOAG when shrinking
Darrick J. Wong [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: check for sparse inode clusters that cross new EOAG when shrinking

Source kernel commit: da062d16a897c0759ae907e786bc0bea950c0c9d

While running xfs/168, I noticed occasional write verifier shutdowns
involving inodes at the very end of the filesystem.  Existing inode
btree validation code checks that all inode clusters are fully contained
within the filesystem.

However, due to inadequate checking in the fs shrink code, it's possible
that there could be a sparse inode cluster at the end of the filesystem
where the upper inodes of the cluster are marked as holes and the
corresponding blocks are free.  In this case, the last blocks in the AG
are listed in the bnobt.  This enables the shrink to proceed but results
in a filesystem that trips the inode verifiers.  Fix this by disallowing
the shrink.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: Fix multiple fall-through warnings for Clang
Gustavo A. R. Silva [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: Fix multiple fall-through warnings for Clang

Source kernel commit: 5937e00017f1d1dd4551e723ebfa306671f27843

In preparation to enable -Wimplicit-fallthrough for Clang, fix
the following warnings by replacing /* fallthrough */ comments,
and its variants, with the new pseudo-keyword macro fallthrough:

fs/xfs/libxfs/xfs_attr.c:487:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
fs/xfs/libxfs/xfs_attr.c:500:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
fs/xfs/libxfs/xfs_attr.c:532:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
fs/xfs/libxfs/xfs_attr.c:594:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
fs/xfs/libxfs/xfs_attr.c:607:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
fs/xfs/libxfs/xfs_attr.c:1410:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
fs/xfs/libxfs/xfs_attr.c:1445:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
fs/xfs/libxfs/xfs_attr.c:1473:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]

Notice that Clang doesn't recognize /* fallthrough */ comments as
implicit fall-through markings, so in order to globally enable
-Wimplicit-fallthrough for Clang, these comments need to be
replaced with fallthrough; in the whole codebase.

Link: https://github.com/KSPP/linux/issues/115
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: Initialize error in xfs_attr_remove_iter
Allison Henderson [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: Initialize error in xfs_attr_remove_iter

Source kernel commit: d3a3340b6af28ab79a66687973fb0287d976d490

A recent bug report generated a warning that a code path in
xfs_attr_remove_iter could potentially return error uninitialized in the
case of XFS_DAS_RM_SHRINK state.  Fix this by initializing error.

Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Bill O'Donnell <bodonnel@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: fix endianness issue in xfs_ag_shrink_space
Darrick J. Wong [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: fix endianness issue in xfs_ag_shrink_space

Source kernel commit: a8f3522c9a1f4a31e93b17f2b5310a2b615f5581

The AGI buffer is in big-endian format, so we must convert the
endianness to CPU format to do any comparisons.

Fixes: 46141dc891f7 ("xfs: introduce xfs_ag_shrink_space()")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: xfs_log_force_lsn isn't passed a LSN
Dave Chinner [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: xfs_log_force_lsn isn't passed a LSN

Source kernel commit: 5f9b4b0de8dc2fb8eb655463b438001c111570fe

In doing an investigation into AIL push stalls, I was looking at the
log force code to see if an async CIL push could be done instead.
This lead me to xfs_log_force_lsn() and looking at how it works.

xfs_log_force_lsn() is only called from inode synchronisation
contexts such as fsync(), and it takes the ip->i_itemp->ili_last_lsn
value as the LSN to sync the log to. This gets passed to
xlog_cil_force_lsn() via xfs_log_force_lsn() to flush the CIL to the
journal, and then used by xfs_log_force_lsn() to flush the iclogs to
the journal.

The problem is that ip->i_itemp->ili_last_lsn does not store a
log sequence number. What it stores is passed to it from the
->iop_committing method, which is called by xfs_log_commit_cil().
The value this passes to the iop_committing method is the CIL
context sequence number that the item was committed to.

As it turns out, xlog_cil_force_lsn() converts the sequence to an
actual commit LSN for the related context and returns that to
xfs_log_force_lsn(). xfs_log_force_lsn() overwrites it's "lsn"
variable that contained a sequence with an actual LSN and then uses
that to sync the iclogs.

This caused me some confusion for a while, even though I originally
wrote all this code a decade ago. ->iop_committing is only used by
a couple of log item types, and only inode items use the sequence
number it is passed.

Let's clean up the API, CIL structures and inode log item to call it
a sequence number, and make it clear that the high level code is
using CIL sequence numbers and not on-disk LSNs for integrity
synchronisation purposes.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: log stripe roundoff is a property of the log
Dave Chinner [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: log stripe roundoff is a property of the log

Source kernel commit: a6a65fef5ef8d0a6a0ce514eb66b2f3dfa777b48

We don't need to look at the xfs_mount and superblock every time we
need to do an iclog roundoff calculation. The property is fixed for
the life of the log, so store the roundoff in the log at mount time
and use that everywhere.

On a debug build:

$ size fs/xfs/xfs_log.o.*
text    data     bss     dec     hex filename
27360     560       8   27928    6d18 fs/xfs/xfs_log.o.orig
27219     560       8   27787    6c8b fs/xfs/xfs_log.o.patched

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: perag may be null in xfs_imap()
Dave Chinner [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: perag may be null in xfs_imap()

Source kernel commit: 90e2c1c20ac672756a2835b5a92a606dd48a4aa3

Dan Carpenter's static checker reported:

The patch 7b13c5155182: "xfs: use perag for ialloc btree cursors"
from Jun 2, 2021, leads to the following Smatch complaint:

fs/xfs/libxfs/xfs_ialloc.c:2403 xfs_imap()
error: we previously assumed 'pag' could be null (see line 2294)

And it's right. Fix it.

Fixes: 7b13c5155182 ("xfs: use perag for ialloc btree cursors")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: Make attr name schemes consistent
Allison Henderson [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: Make attr name schemes consistent

Source kernel commit: 816c8e39b7ea0875640312c9ed3be0d5a68d7183

This patch renames the following functions to make the nameing scheme more consistent:
xfs_attr_shortform_remove -> xfs_attr_sf_removename
xfs_attr_node_remove_name -> xfs_attr_node_removename
xfs_attr_set_fmt -> xfs_attr_sf_addname

Suggested-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: Fix default ASSERT in xfs_attr_set_iter
Allison Henderson [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: Fix default ASSERT in xfs_attr_set_iter

Source kernel commit: 4a4957c16dc674d1306a3b43d6b07ed93a7b7a14

This ASSERT checks for the state value of RM_SHRINK in the set path
which should never happen.  Change to ASSERT(0);

Suggested-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: drop the AGI being passed to xfs_check_agi_freecount
Dave Chinner [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: drop the AGI being passed to xfs_check_agi_freecount

Source kernel commit: 9ba0889e2272294bfbb5589b1b180ad2e782b2a4

Stephen Rothwell reported this compiler warning from linux-next:

fs/xfs/libxfs/xfs_ialloc.c: In function 'xfs_difree_finobt':
fs/xfs/libxfs/xfs_ialloc.c:2032:20: warning: unused variable 'agi' [-Wunused-variable]
2032 |  struct xfs_agi   *agi = agbp->b_addr;

Which is fallout from agno -> perag conversions that were done in
this function. xfs_check_agi_freecount() is the only user of "agi"
in xfs_difree_finobt() now, and it only uses the agi to get the
current free inode count. We hold that in the perag structure, so
there's not need to directly reference the raw AGI to get this
information.

The btree cursor being passed to xfs_check_agi_freecount() has a
reference to the perag being operated on, so use that directly in
xfs_check_agi_freecount() rather than passing an AGI.

Fixes: 7b13c5155182 ("xfs: use perag for ialloc btree cursors")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: fix radix tree tag signs
Darrick J. Wong [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: fix radix tree tag signs

Source kernel commit: 919a4ddb68413056ecb7c71d9d5465bb54c8032b

Radix tree tags are supposed to be unsigned ints, so fix the callers.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: mark xfs_bmap_set_attrforkoff static
Christoph Hellwig [Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)] 
xfs: mark xfs_bmap_set_attrforkoff static

Source kernel commit: 5a981e4ea8ff8062e7c7ea8fc4a1565e4820a08b

xfs_bmap_set_attrforkoff is only used inside of xfs_bmap.c, so mark it
static.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: Remove redundant assignment to busy
Jiapeng Chong [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: Remove redundant assignment to busy

Source kernel commit: 9673261c32dc2f30863b803374b726a72d16b07c

Variable busy is set to false, but this value is never read as it is
overwritten or not used later on, hence it is a redundant assignment
and can be removed.

Clean up the following clang-analyzer warning:

fs/xfs/libxfs/xfs_alloc.c:1679:2: warning: Value stored to 'busy' is
never read [clang-analyzer-deadcode.DeadStores].

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: sort variable alphabetically to avoid repeated declaration
Shaokun Zhang [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: sort variable alphabetically to avoid repeated declaration

Source kernel commit: 5f7fd75086203a8a4dd3e518976e52bcf24e8b22

Variable 'xfs_agf_buf_ops', 'xfs_agi_buf_ops', 'xfs_dquot_buf_ops' and
'xfs_symlink_buf_ops' are declared twice, so sort these variables
alphabetically and remove the repeated declaration.

Cc: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: remove xfs_perag_t
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: remove xfs_perag_t

Source kernel commit: 509201163fca3d4d906bd50a5320115d42818748

Almost unused, gets rid of another typedef.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: use perag through unlink processing
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: use perag through unlink processing

Source kernel commit: f40aadb2bb64fe0a3d9b59957e70796d629cdee2

Unlinked lists are held in the perag, and freeing of inodes needs to
be passed a perag, too, so look up the perag early in the unlink
processing and use it throughout.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: clean up and simplify xfs_dialloc()
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: clean up and simplify xfs_dialloc()

Source kernel commit: 8237fbf53d6fd2a3a248fc2a8608e047ef22316c

Because it's a mess.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: inode allocation can use a single perag instance
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: inode allocation can use a single perag instance

Source kernel commit: 309161f6603ce1a53b76a42817cde2a9bcd17e82

Now that we've internalised the two-phase inode allocation, we can
now easily make the AG selection and allocation atomic from the
perspective of a single perag context. This will ensure AGs going
offline/away cannot occur between the selection and allocation
steps.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: get rid of xfs_dir_ialloc()
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: get rid of xfs_dir_ialloc()

Source kernel commit: b652afd937033911944d7f681f2031b006961f1d

This is just a simple wrapper around the per-ag inode allocation
that doesn't need to exist. The internal mechanism to select and
allocate within an AG does not need to be exposed outside
xfs_ialloc.c, and it being exposed simply makes it harder to follow
the code and simplify it.

This is simplified by internalising xf_dialloc_select_ag() and
xfs_dialloc_ag() into a single xfs_dialloc() function and then
xfs_dir_ialloc() can go away.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: collapse AG selection for inode allocation
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: collapse AG selection for inode allocation

Source kernel commit: 89b1f55a2951bb89b7ae9f8cb3fd11513ff3f219

xfs_dialloc_select_ag() does a lot of repetitive work. It first
calls xfs_ialloc_ag_select() to select the AG to start allocation
attempts in, which can do up to two entire loops across the perags
that inodes can be allocated in. This is simply checking if there is
spce available to allocate inodes in an AG, and it returns when it
finds the first candidate AG.

xfs_dialloc_select_ag() then does it's own iterative walk across
all the perags locking the AGIs and trying to allocate inodes from
the locked AG. It also doesn't limit the search to mp->m_maxagi,
so it will walk all AGs whether they can allocate inodes or not.

Hence if we are really low on inodes, we could do almost 3 entire
walks across the whole perag range before we find an allocation
group we can allocate inodes in or report ENOSPC.

Because xfs_ialloc_ag_select() returns on the first candidate AG it
finds, we can simply do these checks directly in
xfs_dialloc_select_ag() before we lock and try to allocate inodes.
This reduces the inode allocation pass down to 2 perag sweeps at
most - one for aligned inode cluster allocation and if we can't
allocate full, aligned inode clusters anywhere we'll do another pass
trying to do sparse inode cluster allocation.

This also removes a big chunk of duplicate code.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: simplify xfs_dialloc_select_ag() return values
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: simplify xfs_dialloc_select_ag() return values

Source kernel commit: 4268547305c91b35ae7871374078de788a822ed1

The only caller of xfs_dialloc_select_ag() will always return
-ENOSPC to it's caller if the agbp returned from
xfs_dialloc_select_ag() is NULL. IOWs, failure to find a candidate
AGI we can allocate inodes from is always an ENOSPC condition, so
move this logic up into xfs_dialloc_select_ag() so we can simplify
the return logic in this function.

xfs_dialloc_select_ag() now only ever returns 0 with a locked
agbp, or an error with no agbp.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: remove agno from btree cursor
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: remove agno from btree cursor

Source kernel commit: 50f02fe3338d3fee6b298a1b262a4c562e7d84e0

Now that everything passes a perag, the agno is not needed anymore.
Convert all the users to use pag->pag_agno instead and remove the
agno from the cursor. This was largely done as an automated search
and replace.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: use perag for ialloc btree cursors
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: use perag for ialloc btree cursors

Source kernel commit: 7b13c515518264df0cb90d84fdab907a627c0fa9

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: convert allocbt cursors to use perags
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: convert allocbt cursors to use perags

Source kernel commit: 289d38d22cd88960cb648dc480c50de5102519bb

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: convert refcount btree cursor to use perags
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: convert refcount btree cursor to use perags

Source kernel commit: a81a06211fb43d80ee746e7a40a32ed812002f8e

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: convert rmap btree cursor to using a perag
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: convert rmap btree cursor to using a perag

Source kernel commit: fa9c3c197329fdab0efc48a8944d2c4a21c6a74f

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: add a perag to the btree cursor
Dave Chinner [Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)] 
xfs: add a perag to the btree cursor

Source kernel commit: be9fb17d88f08af648a89784d30dbac83d893154

Which will eventually completely replace the agno in it.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: pass perags around in fsmap data dev functions
Dave Chinner [Fri, 15 Oct 2021 20:28:25 +0000 (16:28 -0400)] 
xfs: pass perags around in fsmap data dev functions

Source kernel commit: 58d43a7e3263766ade4974c86118e6b5737ea259

Needs a [from, to] ranged AG walk, and the perag to be stuffed into
the info structure for callouts to use.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
2 years agoxfs: push perags through the ag reservation callouts
Dave Chinner [Fri, 15 Oct 2021 20:28:25 +0000 (16:28 -0400)] 
xfs: push perags through the ag reservation callouts

Source kernel commit: 30933120ad79f4549d6e364df7eda474cc0d9c65

We currently pass an agno from the AG reservation functions to the
individual feature accounting functions, which in future may have to
do perag lookups to access per-AG state. Instead, pre-emptively
plumb the perag through from the highest AG reservation layer to the
feature callouts so they won't have to look it up again.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>