]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/log
thirdparty/xfsprogs-dev.git
5 years agoxfs_io: Remove redundant setting/check for lsattr/stat command
Xiao Yang [Thu, 30 Jul 2020 01:02:15 +0000 (21:02 -0400)] 
xfs_io: Remove redundant setting/check for lsattr/stat command

lsattr/stat command can check exclusive options by argmax = 1
so the related setting/check is redundant.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: Make -D and -R options incompatible explicitly
Xiao Yang [Thu, 30 Jul 2020 00:45:36 +0000 (20:45 -0400)] 
xfs_io: Make -D and -R options incompatible explicitly

-D and -R options are mutually exclusive actually but many commands
can accept them at the same time and process them differently(e.g.
chattr alway chooses -D option or cowextsize accepts the last one
specified), so make these commands have the consistent behavior that
don't accept them concurrently.

1) Make them incompatible by setting argmax to 1 if commands can accept
   single option(i.e. lsattr, lsproj).
2) Make them incompatible by adding check if commands can accept multiple
   options(i.e. chattr, chproj, extsize, cowextsize).

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: skip mount time quotacheck if our quotacheck was ok
Darrick J. Wong [Thu, 30 Jul 2020 00:15:27 +0000 (20:15 -0400)] 
xfs_repair: skip mount time quotacheck if our quotacheck was ok

If we verified that the incore quota counts match the ondisk quota
contents, we can leave the CHKD flags set so that the next mount doesn't
have to repeat the quotacheck.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: check quota values if quota was loaded
Darrick J. Wong [Thu, 30 Jul 2020 00:15:27 +0000 (20:15 -0400)] 
xfs_repair: check quota values if quota was loaded

If the filesystem looks like it had up to date quota information, check
it against what's in the filesystem and report if we find discrepancies.
This closes one of the major gaps in corruptions that are detected by
xfs_check vs. xfs_repair.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: fix clearing of quota CHKD flags
Darrick J. Wong [Thu, 30 Jul 2020 00:15:27 +0000 (20:15 -0400)] 
xfs_repair: fix clearing of quota CHKD flags

XFS_ALL_QUOTA_CHKD, being a OR of [UGP]QUOTA_CHKD, is a bitset of the
possible *incore* quota checked flags.  This means that it cannot be
used in a comparison with the *ondisk* quota checked flags because V4
filesystems set OQUOTA_CHKD, not the [GU]QUOTA_CHKD flags (which are V5
flags).

If you have a V4 filesystem with user quotas disabled but either group
or project quotas enabled, xfs_repair will /not/ claim that the quota
info will be regenerated on the next mount like it does in any other
situation.  This is because the ondisk qflags field has OQUOTA_CHKD set
but repair fails to notice.

Worse, if you have a V4 filesystem with user and group quotas enabled
and mild corruption, repair will claim that the quota info will be
regenerated.  If you then mount the fs with only group quotas enabled,
quotacheck will not run to correct the data because repair failed to
clear OQUOTA_CHKD properly.

These are fairly benign and unlikely scenarios, but when we add
quotacheck capabilities to xfs_repair, it will complain about the
incorrect quota counts, which causes regressions in xfs/278.

Fixes: 342aef1ec0ec ("xfsprogs: Remove incore use of XFS_OQUOTA_ENFD and XFS_OQUOTA_CHKD")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: alphabetize HFILES and CFILES
Darrick J. Wong [Thu, 30 Jul 2020 00:15:27 +0000 (20:15 -0400)] 
xfs_repair: alphabetize HFILES and CFILES

Convert the definitions of HFILES and CFILES to lists that can be sorted
easily (in vim, anyway), then fix the alphabetization of the makefile
targets.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfsprogs: Release v5.7.0 v5.7.0
Eric Sandeen [Fri, 24 Jul 2020 18:33:08 +0000 (14:33 -0400)] 
xfsprogs: Release v5.7.0

Update all the necessary files for a 5.7.0 release.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: Document '-q' option for sendfile command
Xiao Yang [Fri, 24 Jul 2020 18:32:00 +0000 (14:32 -0400)] 
xfs_io: Document '-q' option for sendfile command

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfsprogs: Release v5.7.0-rc1 v5.7.0-rc1
Eric Sandeen [Wed, 15 Jul 2020 20:08:04 +0000 (16:08 -0400)] 
xfsprogs: Release v5.7.0-rc1

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

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: Document '-q' option for pread/pwrite command
Xiao Yang [Wed, 15 Jul 2020 19:43:19 +0000 (15:43 -0400)] 
xfs_io: Document '-q' option for pread/pwrite command

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_copy: flush target devices before exiting
Darrick J. Wong [Wed, 15 Jul 2020 19:40:53 +0000 (15:40 -0400)] 
xfs_copy: flush target devices before exiting

Flush the devices we're copying to before exiting, so that we can report
any write errors.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: try to fill the AGFL before we fix the freelist
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: try to fill the AGFL before we fix the freelist

In commit 9851fd79bfb1, we added a slight amount of slack to the free
space btrees being reconstructed so that the initial fix_freelist call
(which is run against a totally empty AGFL) would never have to split
either free space btree in order to populate the free list.

The new btree bulk loading code in xfs_repair can re-create this
situation because it can set the slack values to zero if the filesystem
is very full.  However, these days repair has the infrastructure needed
to ensure that overestimations of the btree block counts end up on the
AGFL or get freed back into the filesystem at the end of phase 5.

Fix this problem by reserving extra blocks in the bnobt reservation, and
checking that there are enough overages in the bnobt/cntbt fakeroots to
populate the AGFL with the minimum number of blocks it needs to handle a
split in the bno/cnt/rmap btrees.

Note that we reserve blocks for the new bnobt/cntbt/AGFL at the very end
of the reservation steps in phase 5, so the extra allocation should not
cause repair to fail if it can't find blocks for btrees.

Fixes: 9851fd79bfb1 ("repair: AGFL rebuild fails if btree split required")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: simplify free space btree calculations in init_freespace_cursors
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: simplify free space btree calculations in init_freespace_cursors

Add a summary variable to the bulkload structure so that we can track
the number of blocks that have been reserved for a particular (btree)
bulkload operation.  Doing so enables us to simplify the logic in
init_freespace_cursors that deals with figuring out how many more blocks
we need to fill the bnobt/cntbt properly.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: complain about ag header crc errors
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: complain about ag header crc errors

Repair doesn't complain about crc errors in the AG headers, and it
should.  Otherwise, this gives the admin the wrong impression about the
state of the filesystem after a nomodify check.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: use bitmap to track blocks lost during btree construction
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: use bitmap to track blocks lost during btree construction

Use the incore bitmap structure to track blocks that were lost
during btree construction.  This makes it somewhat more efficient.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: remove old btree rebuild support code
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: remove old btree rebuild support code

This code isn't needed anymore, so get rid of it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: rebuild refcount btrees with bulk loader
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: rebuild refcount btrees with bulk loader

Use the btree bulk loading functions to rebuild the refcount btrees
and drop the open-coded implementation.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: rebuild reverse mapping btrees with bulk loader
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: rebuild reverse mapping btrees with bulk loader

Use the btree bulk loading functions to rebuild the reverse mapping
btrees and drop the open-coded implementation.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
[sandeen: adjust for prior inclusion of "fix rebuilding btree block..."]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: rebuild inode btrees with bulk loader
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: rebuild inode btrees with bulk loader

Use the btree bulk loading functions to rebuild the inode btrees
and drop the open-coded implementation.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: rebuild free space btrees with bulk loader
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: rebuild free space btrees with bulk loader

Use the btree bulk loading functions to rebuild the free space btrees
and drop the open-coded implementation.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
[sandeen: move phase5_func changes into this patch]
[sandeen: adjust for prior inclusion of "fix rebuilding btree block..."]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: create a new class of btree rebuild cursors
Darrick J. Wong [Fri, 10 Jul 2020 19:35:46 +0000 (15:35 -0400)] 
xfs_repair: create a new class of btree rebuild cursors

Create some new support structures and functions to assist phase5 in
using the btree bulk loader to reconstruct metadata btrees.  This is the
first step in removing the open-coded AG btree rebuilding code.

Note: The code in this patch will not be used anywhere until the next
patch, so warnings about unused symbols are expected.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
[for all but the slack_node change from 0 to 2:]
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: inject lost blocks back into the fs no matter the owner
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: inject lost blocks back into the fs no matter the owner

In repair phase 5, inject_lost_blocks takes the blocks that we allocated
but didn't use for constructing the new AG btrees and puts them back in
the filesystem by adding them to the free space.  The only btree that
can overestimate like that are the free space btrees, but in principle,
any of the btrees can do that.  If the others did, the rmap record owner
for those blocks won't necessarily be OWNER_AG, and if it isn't, repair
will fail.

Get rid of this logic bomb so that we can use it for /any/ block count
overestimation, and then we can use it to clean up after all
reconstruction of any btree type.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: remove gratuitous code block in phase5
Eric Sandeen [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: remove gratuitous code block in phase5

A commit back in 2008 removed a "for" loop ahead of this code block, but
left the indented code block in place. Remove it for clarity and reflow
comments & lines as needed.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: make container for btree bulkload root and block reservation
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: make container for btree bulkload root and block reservation

Create appropriate data structures to manage the fake btree root and
block reservation lists needed to stage a btree bulkload operation.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: rename the agfl index loop variable in build_agf_agfl
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: rename the agfl index loop variable in build_agf_agfl

The variable 'i' is used to index the AGFL block list, so change the
name to make it clearer what this is to be used for.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: drop lostblocks from build_agf_agfl
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: drop lostblocks from build_agf_agfl

We don't do anything with this parameter, so get rid of it.

Fixes: ef4332b8 ("xfs_repair: add freesp btree block overflow to the free space")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: complain about any nonzero inprogress value, not just 1
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: complain about any nonzero inprogress value, not just 1

Complain about the primary superblock having any non-zero sb_inprogress
value, not just 1.  This brings repair's behavior into alignment with
xfs_check and the kernel.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: complain about extents in unknown state
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: complain about extents in unknown state

During phase 4, if we find any extents that are unaccounted for, report
the entire extent, not just the first block.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: complain about free space only seen by one btree
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: complain about free space only seen by one btree

During the free space btree walk, scan_allocbt claims in a comment that
we'll catch FREE1 blocks (i.e. blocks that were seen by only one free
space btree) later.  This never happens, with the result that xfs_repair
in dry-run mode can return 0 on a filesystem with corrupt free space
btrees.

Found by fuzzing xfs/358 with numrecs = middlebit (or sub).

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: mark entire free space btree record as free1
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: mark entire free space btree record as free1

In scan_allocbt, we iterate each free space btree record (of both bnobt
and cntbt) in the hopes of pushing all the free space from UNKNOWN to
FREE1 to FREE.  Unfortunately, the first time we see a free space record
we only set the first block of that record to FREE1, which means that
the second time we see the record, the first block will get set to FREE,
but the rest of the free space will only make it to FREE1.  This is
incorrect state, so we need to fix that.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: remove verify_aginum
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: remove verify_aginum

Replace this homegrown inode pointer verification function with the
libxfs checking helper.  This one is a little tricky because this
function (unlike all of its verify_* siblings) returned 1 for bad and 0
for good, so we must invert the checking logic.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: remove verify_dfsbno
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: remove verify_dfsbno

Replace this homegrown helper with its libxfs equivalent.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: refactor verify_dfsbno_range
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: refactor verify_dfsbno_range

Refactor this function to use libxfs type checking helpers.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: convert to libxfs_verify_agbno
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: convert to libxfs_verify_agbno

Convert the homegrown verify_agbno callers to use the libxfs function,
as needed.  In some places we drop the "bno != 0" checks because those
conditionals are checking btree roots; btree roots should never be
zero if the corresponding feature bit is set; and repair skips the if
clause entirely if the feature bit is disabled.

In effect, this strengthens repair to validate that AG btree pointers
neither point to the AG headers nor past the end of the AG.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: complain about bad interior btree pointers
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: complain about bad interior btree pointers

Actually complain about garbage btree node pointers, don't just silently
ignore them.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: tag inobt vs finobt errors properly
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: tag inobt vs finobt errors properly

Amend the generic inode btree block scanner function to tag correctly
which tree it's complaining about.  Previously, dubious finobt headers
would be attributed to the "inode btree", which is at best ambiguous
and misleading at worst.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: fix rmapbt record order check
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: fix rmapbt record order check

The rmapbt record order checks here don't quite work properly.  For
non-shared filesystems, we fail to check that the startblock of the nth
record comes entirely after the previous record.

However, for filesystems with shared blocks (reflink) we correctly check
that the startblock/owner/offset of the nth record comes after the
previous one.

Therefore, make the reflink fs checks use "laststartblock" to preserve
that functionality while making the non-reflink fs checks use
"lastblock" to fix the problem outlined above.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: check for out-of-order inobt records
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: check for out-of-order inobt records

Make sure that the inode btree records are in order.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: fix bnobt and refcountbt record order checks
Darrick J. Wong [Fri, 10 Jul 2020 19:35:45 +0000 (15:35 -0400)] 
xfs_repair: fix bnobt and refcountbt record order checks

The bnobt and refcountbt scanners attempt to check that records are in
the correct order.  However, the lastblock variable in both functions
ought to be set to the end of the previous record (instead of the start)
because otherwise we fail to catch overlapping records, which are not
allowed in either btree type.

Found by running xfs/410 with recs[1].blockcount = middlebit.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: check for AG btree records that would wrap around
Darrick J. Wong [Fri, 10 Jul 2020 19:35:44 +0000 (15:35 -0400)] 
xfs_repair: check for AG btree records that would wrap around

For AG btree types, make sure that each record's length is not so huge
that integer wraparound would happen.

Found via xfs/358 fuzzing recs[1].blockcount = ones.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: warn when we would have rebuilt a directory
Darrick J. Wong [Fri, 10 Jul 2020 19:35:36 +0000 (15:35 -0400)] 
xfs_repair: warn when we would have rebuilt a directory

longform_dir2_entry_check should warn the user when we would have
rebuilt a directory had -n not been given on the command line.  The
missing warning results in repair returning 0 (all clean) when in fact
there were things that it would have fixed.

Found by running xfs/496 against lents[0].hashval = middlebit.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: fix missing dir buffer corruption checks
Darrick J. Wong [Fri, 10 Jul 2020 19:34:36 +0000 (15:34 -0400)] 
xfs_repair: fix missing dir buffer corruption checks

The da_read_buf() function operates in "salvage" mode, which means that
if the verifiers fail, it will return a buffer with b_error set.  The
callers of da_read_buf, however, do not adequately check for verifier
errors, which means that repair can fail to flag a corrupt filesystem.

Fix the callers to do this properly.  The dabtree block walker and the
dabtree path checker functions to complain any time the da node / leafn
verifiers fail.  Fix the directory block walking functions to complain
about EFSCORRUPTED, since they already dealt with EFSBADCRC.

Found by running xfs/496 against lhdr.stale = middlebit.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_quota: fix unsigned int id comparisons
Darrick J. Wong [Fri, 10 Jul 2020 19:33:36 +0000 (15:33 -0400)] 
xfs_quota: fix unsigned int id comparisons

Fix compiler warnings about unsigned int comparisons by replacing them
with an explicit check for the one possible invalid value (-1U).
id_from_string sets exitcode to nonzero when it sees this value, so the
call sites don't have to do that.

Coverity-id: 146385514638561463857
Fixes: 67a73d6139d0 ("xfs_quota: refactor code to generate id from name")
Fixes: 36dc471cc9bb ("xfs_quota: allow individual timer extension")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: fix rebuilding btree block less than minrecs
Gao Xiang [Fri, 10 Jul 2020 19:32:36 +0000 (15:32 -0400)] 
xfs_repair: fix rebuilding btree block less than minrecs

In production, we found that sometimes xfs_repair phase 5
rebuilds freespace node block with pointers less than minrecs
and if we trigger xfs_repair again it would report such
the following message:

bad btree nrecs (39, min=40, max=80) in btbno block 0/7882

The background is that xfs_repair starts to rebuild AGFL
after the freespace btree is settled in phase 5 so we may
need to leave necessary room in advance for each btree
leaves in order to avoid freespace btree split and then
result in AGFL rebuild fails. The old mathematics uses
ceil(num_extents / maxrecs) to decide the number of node
blocks. That would be fine without leaving extra space
since minrecs = maxrecs / 2 but if some slack was decreased
from maxrecs, the result would be larger than what is
expected and cause num_recs_pb less than minrecs, i.e:

num_extents = 79, adj_maxrecs = 80 - 2 (slack) = 78

so we'd get

num_blocks = ceil(79 / 78) = 2,
num_recs_pb = 79 / 2 = 39, which is less than
minrecs = 80 / 2 = 40

OTOH, btree bulk loading code behaves in a different way.
As in xfs_btree_bload_level_geometry it wrote

num_blocks = floor(num_extents / maxrecs)

which will never go below minrecs. And when it goes above
maxrecs, just increment num_blocks and recalculate so we
can get the reasonable results.

Later, btree bulk loader will replace the current repair code.
But we may still want to look for a backportable solution
for stable versions. Hence, keep the same logic to avoid
the freespace as well as rmap btree minrecs underflow for now.

Cc: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: Eric Sandeen <sandeen@sandeen.net>
Fixes: 9851fd79bfb1 ("repair: AGFL rebuild fails if btree split required")
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agometadump: remove redundant bracket and show right SYNOPSIS
Kaixu Xia [Tue, 26 May 2020 18:42:40 +0000 (14:42 -0400)] 
metadump: remove redundant bracket and show right SYNOPSIS

The bracket is meaningless, so remove it and show right SYNOPSIS.

Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agomkfs: simplify the configured sector sizes setting in validate_sectorsize
Kaixu Xia [Tue, 26 May 2020 18:42:30 +0000 (14:42 -0400)] 
mkfs: simplify the configured sector sizes setting in validate_sectorsize

There are two places that set the configured sector sizes in
validate_sectorsize, actually we can simplify them and combine into one
if statement. Use the default value structure to set the topology sectors
when probing fails.

Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_quota: allow individual timer extension
Eric Sandeen [Tue, 26 May 2020 18:36:26 +0000 (14:36 -0400)] 
xfs_quota: allow individual timer extension

The only grace period which can be set via xfs_quota today is for id 0,
i.e. the default grace period for all users.  However, setting an
individual grace period is useful; for example:

 Alice has a soft quota of 100 inodes, and a hard quota of 200 inodes
 Alice uses 150 inodes, and enters a short grace period
 Alice really needs to use those 150 inodes past the grace period
 The administrator extends Alice's grace period until next Monday

vfs quota users such as ext4 can do this today, with setquota -T

xfs_quota can now accept an optional user id or name (symmetric with
how warn limits are specified), in which case that user's grace period
is extended to expire the given amount of time from now().

To maintain compatibility with old command lines, if none of
[-d|id|name] are specified, default limits are set as before.

(kernelspace requires updates to enable all this as well.)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_quota: refactor code to generate id from name
Eric Sandeen [Tue, 26 May 2020 18:36:04 +0000 (14:36 -0400)] 
xfs_quota: refactor code to generate id from name

There's boilerplate for setting limits and warnings, where we have
a case statement for each of the 3 quota types, and from there call
3 different functions to configure each of the 3 types, each of which
calls its own version of id to string function...

Refactor this so that the main function can call a generic id to string
conversion routine, and then call a common action.  This save a lot of
LOC.

I was looking at allowing xfs to bump out individual grace periods like
setquota can do, and this refactoring allows us to add new actions like
that without copying all the boilerplate again.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: fix progress reporting
Eric Sandeen [Tue, 26 May 2020 18:36:04 +0000 (14:36 -0400)] 
xfs_repair: fix progress reporting

The Fixes: commit tried to avoid a segfault in case the progress timer
went off before the first message type had been set up, but this
had the net effect of short-circuiting the pthread start routine,
and so the timer didn't get set up at all and we lost all fine-grained
progress reporting.

The initial problem occurred when log zeroing took more time than the
timer interval.

So, make a new log zeroing progress item and initialize it when we first
set up the timer thread, to be sure that if the timer goes off while we
are still zeroing the log, it will be initialized and correct.

(We can't offer fine-grained status on log zeroing, so it'll go from
zero to $LOGBLOCKS with nothing in between, but it's unlikely that log
zeroing will take so long that this really matters.)

Reported-by: Leonardo Vaz <lvaz@redhat.com>
Fixes: 7f2d6b811755 ("xfs_repair: avoid segfault if reporting progre...")
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Donald Douwsma <ddouwsma@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agodebian: replace libreadline with libedit
Darrick J. Wong [Tue, 26 May 2020 18:36:03 +0000 (14:36 -0400)] 
debian: replace libreadline with libedit

Now that upstream has dropped libreadline support entirely, switch the
debian package over to libedit.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_db: fix rdbmap_boundscheck
Darrick J. Wong [Tue, 26 May 2020 18:36:03 +0000 (14:36 -0400)] 
xfs_db: fix rdbmap_boundscheck

This predicate should check the a rt block number against number of
rtblocks, not the number of AG blocks.  Ooops.

Fixes: 7161cd21b3ed ("xfs_db: bounds-check access to the dbmap array")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_db: don't crash if el_gets returns null
Darrick J. Wong [Tue, 26 May 2020 18:36:03 +0000 (14:36 -0400)] 
xfs_db: don't crash if el_gets returns null

el_gets returns NULL if it fails to read any characters (due to EOF or
errors occurred).  strdup will crash if it is fed a NULL string, so
check the return value to avoid segfaulting.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoscrub: remove xfs_ prefixes from various function
Christoph Hellwig [Tue, 26 May 2020 18:36:03 +0000 (14:36 -0400)] 
scrub: remove xfs_ prefixes from various function

Don't prefix tool private functions.  We'll use the xfs_* namespace for
the shared libxfs functions soon, and want to be able to easily verify
that the callers handle return negative errors for them.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_db: fix crc invalidation segfault
Anthony Iliopoulos [Tue, 26 May 2020 18:35:51 +0000 (14:35 -0400)] 
xfs_db: fix crc invalidation segfault

The nowrite_ops var is declared within nested block scope but used
outside that scope, causing xfs_db to crash while trying to defererence
the verify_write pointer. Fix it by lifting the declaration to the outer
scope, where it is accessed.

Fixes: b64af2c48220c8 ("xfs_db: add crc manipulation commands")
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agolibxfs-apply: use git am instead of patch
Christoph Hellwig [Mon, 11 May 2020 20:48:55 +0000 (16:48 -0400)] 
libxfs-apply: use git am instead of patch

If neither guilt or stgit are used default to git am instead of patch
so that all the commit information is properly propagated.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@sandeen.net>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agometadump: small cleanup for process_inode
Christoph Hellwig [Mon, 11 May 2020 20:48:45 +0000 (16:48 -0400)] 
metadump: small cleanup for process_inode

Shorten a conditional to a single line.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agorepair: cleanup build_agf_agfl
Christoph Hellwig [Mon, 11 May 2020 20:48:40 +0000 (16:48 -0400)] 
repair: cleanup build_agf_agfl

No need to have two variables for the AGFL block number array.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agodb: ensure that create and replace are exclusive in attr_set_f
Christoph Hellwig [Mon, 11 May 2020 20:48:25 +0000 (16:48 -0400)] 
db: ensure that create and replace are exclusive in attr_set_f

Clear the other flag when applying the create or replace option,
as the low-level libxfs can't handle both at the same time.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agodb: validate name and namelen in attr_set_f and attr_remove_f
Christoph Hellwig [Mon, 11 May 2020 19:00:18 +0000 (15:00 -0400)] 
db: validate name and namelen in attr_set_f and attr_remove_f

libxfs has stopped validating these parameters internally, so do it
in the xfs_db commands.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agodb: cleanup attr_set_f and attr_remove_f
Christoph Hellwig [Mon, 11 May 2020 18:59:37 +0000 (14:59 -0400)] 
db: cleanup attr_set_f and attr_remove_f

Don't use local variables for information that is set in the da_args
structure.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agodb: add a comment to agfl_crc_flds
Christoph Hellwig [Sat, 9 May 2020 19:51:59 +0000 (15:51 -0400)] 
db: add a comment to agfl_crc_flds

Explain the bno field that is not actually part of the structure
anymore.

Signed-off-by: Christoph Hellwig <hch@lst.de>
[sandeen: tweak the commentper djwong's suggestion]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agodb: fix a comment in scan_freelist
Christoph Hellwig [Sat, 9 May 2020 17:29:37 +0000 (13:29 -0400)] 
db: fix a comment in scan_freelist

XFS_BUF_TO_AGFL_BNO has been renamed to open coded xfs_buf_to_agfl_bno.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agolibxfs: use tabs instead of spaces in div_u64
Christoph Hellwig [Sat, 9 May 2020 17:29:37 +0000 (13:29 -0400)] 
libxfs: use tabs instead of spaces in div_u64

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_db: bounds-check access to the dbmap array
Darrick J. Wong [Sat, 9 May 2020 17:11:59 +0000 (13:11 -0400)] 
xfs_db: bounds-check access to the dbmap array

Try to check the array boundaries of the dbmap array so that we don't
just segfault.

Found by fuzzing xfs/358 with recs[1].blockcount = ones.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agofind_api_violations: fix sed expression
Darrick J. Wong [Sat, 9 May 2020 17:11:42 +0000 (13:11 -0400)] 
find_api_violations: fix sed expression

Apparently, GNU grep version 3.4 is pickier about requiring '(' to be
escaped inside range expressions.  This causes a regression in xfs/437,
so fix it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
[sandeen: note grep version not OS version]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agolibxcmd: don't crash if el_gets returns null
Darrick J. Wong [Sat, 9 May 2020 17:09:44 +0000 (13:09 -0400)] 
libxcmd: don't crash if el_gets returns null

el_gets returns NULL if it fails to read any characters (due to EOF or
errors occurred).  strdup will crash if it is fed a NULL string, so
check the return value to avoid segfaulting.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: copy_range can take up to 8 arguments
Eric Sandeen [Sat, 9 May 2020 17:09:38 +0000 (13:09 -0400)] 
xfs_io: copy_range can take up to 8 arguments

If we use the "-f N" variant for the source file specification, we will
have up to 8 total arguments.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfsprogs: remove xfs_dir_ops
Christoph Hellwig [Sat, 9 May 2020 17:09:31 +0000 (13:09 -0400)] 
xfsprogs: remove xfs_dir_ops

The xfs_dir_ops infrastructure has been removed a while ago.  Remove
a few always empty members in xfsprogs to finish the cleanup.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfsprogs: remove libreadline support
Christoph Hellwig [Sat, 9 May 2020 17:08:44 +0000 (13:08 -0400)] 
xfsprogs: remove libreadline support

libreadline has been relicensed to GPLv3 and thus incompatible to
xfsprogs many years ago, and all the distros have dropped or are
in the stages of dropping the last GPLv2 version.  As the BSD
licensed libeditline provides the same functionality there is no
need to keep the obsolete libreadline support around.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfsprogs: Release v5.7.0-rc0 libxfs-5.7-sync v5.7.0-rc0
Eric Sandeen [Thu, 7 May 2020 18:10:37 +0000 (14:10 -0400)] 
xfsprogs: Release v5.7.0-rc0

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

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: validate the realtime geometry in xfs_validate_sb_common
Darrick J. Wong [Sat, 2 May 2020 03:33:23 +0000 (23:33 -0400)] 
xfs: validate the realtime geometry in xfs_validate_sb_common

Source kernel commit: f8e566c0f5e1fd8de33ccec6eb1ff815cd4b0dc3

Validate the geometry of the realtime geometry when we mount the
filesystem, so that we don't abruptly shut down the filesystem later on.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: remove the di_version field from struct icdinode
Christoph Hellwig [Sat, 2 May 2020 03:33:22 +0000 (23:33 -0400)] 
xfs: remove the di_version field from struct icdinode

Source kernel commit: 6471e9c5e7a109a952be8e3e80b8d9e262af239d

We know the version is 3 if on a v5 file system.   For earlier file
systems formats we always upgrade the remaining v1 inodes to v2 and
thus only use v2 inodes.  Use the xfs_sb_version_has_large_dinode
helper to check if we deal with small or large dinodes, and thus
remove the need for the di_version field in struct icdinode.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: only check the superblock version for dinode size calculation
Christoph Hellwig [Fri, 1 May 2020 21:37:10 +0000 (17:37 -0400)] 
xfs: only check the superblock version for dinode size calculation

Source kernel commit: e9e2eae89ddb658ea332295153fdca78c12c1e0d

The size of the dinode structure is only dependent on the file system
version, so instead of checking the individual inode version just use
the newly added xfs_sb_version_has_large_dinode helper, and simplify
various calling conventions.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: add a new xfs_sb_version_has_v3inode helper
Christoph Hellwig [Fri, 1 May 2020 21:37:10 +0000 (17:37 -0400)] 
xfs: add a new xfs_sb_version_has_v3inode helper

Source kernel commit: b81b79f4eda2ea98ae5695c0b6eb384c8d90b74d

Add a new wrapper to check if a file system supports the v3 inode format
with a larger dinode core.  Previously we used xfs_sb_version_hascrc for
that, which is technically correct but a little confusing to read.

Also move xfs_dinode_good_version next to xfs_sb_version_has_v3inode
so that we have one place that documents the superblock version to
inode version relationship.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: add support for rmap btree staging cursors
Darrick J. Wong [Fri, 1 May 2020 21:37:10 +0000 (17:37 -0400)] 
xfs: add support for rmap btree staging cursors

Source kernel commit: 59d677127cf1543b2978aca3be8c8395f3a17973

Add support for btree staging cursors for the rmap btrees.  This is
needed both for online repair and also to convert xfs_repair to use
btree bulk loading.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: add support for refcount btree staging cursors
Darrick J. Wong [Fri, 1 May 2020 21:37:10 +0000 (17:37 -0400)] 
xfs: add support for refcount btree staging cursors

Source kernel commit: 56e98164ffea2a9ee577e5e4f368c6d5182ed8eb

Add support for btree staging cursors for the refcount btrees.  This
is needed both for online repair and also to convert xfs_repair to use
btree bulk loading.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: add support for inode btree staging cursors
Darrick J. Wong [Fri, 1 May 2020 21:37:10 +0000 (17:37 -0400)] 
xfs: add support for inode btree staging cursors

Source kernel commit: c29ce8f48e219d10644f402ec5d738cadf20666e

Add support for btree staging cursors for the inode btrees.  This
is needed both for online repair and also to convert xfs_repair to use
btree bulk loading.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: add support for free space btree staging cursors
Darrick J. Wong [Fri, 1 May 2020 21:37:10 +0000 (17:37 -0400)] 
xfs: add support for free space btree staging cursors

Source kernel commit: e6eb33d905c287eb07ee1c69d38871276db154dd

Add support for btree staging cursors for the free space btrees.  This
is needed both for online repair and also to convert xfs_repair to use
btree bulk loading.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: support bulk loading of staged btrees
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: support bulk loading of staged btrees

Source kernel commit: 60e3d7070749554227fbb636a69a4282ab930f86

Add a new btree function that enables us to bulk load a btree cursor.
This will be used by the upcoming online repair patches to generate new
btrees.  This avoids the programmatic inefficiency of calling
xfs_btree_insert in a loop (which generates a lot of log traffic) in
favor of stamping out new btree blocks with ordered buffers, and then
blocks in a single transaction commit.

The design of this new generic code is based off the btree rebuilding
code in xfs_repair's phase 5 code, with the explicit goal of enabling us
to share that code between scrub and repair.  It has the additional
feature of being able to control btree block loading factors.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: introduce fake roots for inode-rooted btrees
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: introduce fake roots for inode-rooted btrees

Source kernel commit: 349e1c0380dbb7f552e4ea61b479c293eb076b3f

Create an in-core fake root for inode-rooted btree types so that callers
can generate a whole new btree using the upcoming btree bulk load
function without making the new tree accessible from the rest of the
filesystem.  It is up to the individual btree type to provide a function
to create a staged cursor (presumably with the appropriate callouts to
update the fakeroot) and then commit the staged root back into the
filesystem.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: introduce fake roots for ag-rooted btrees
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: introduce fake roots for ag-rooted btrees

Source kernel commit: e06536a692e032470130af5b2136b519595809da

Create an in-core fake root for AG-rooted btree types so that callers
can generate a whole new btree using the upcoming btree bulk load
function without making the new tree accessible from the rest of the
filesystem.  It is up to the individual btree type to provide a function
to create a staged cursor (presumably with the appropriate callouts to
update the fakeroot) and then commit the staged root back into the
filesystem.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: fix incorrect test in xfs_alloc_ag_vextent_lastblock
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: fix incorrect test in xfs_alloc_ag_vextent_lastblock

Source kernel commit: 77ca1eed5a7d2bf0905562eb1a15aac76bc19fe4

When I lifted the code in xfs_alloc_ag_vextent_lastblock out of a loop,
I forgot to convert all the accesses to len to be pointer dereferences.

Coverity-id: 1457918
Fixes: 5113f8ec3753ed ("xfs: clean up weird while loop in xfs_alloc_ag_vextent_near")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: xfs_dabuf_map should return ENOMEM when map allocation fails
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: xfs_dabuf_map should return ENOMEM when map allocation fails

Source kernel commit: faf8ee8476c19b30fd16079ad616b2b0f56eaff4

If the xfs_buf_map array allocation in xfs_dabuf_map fails for whatever
reason, we bail out with error code zero.  This will confuse callers, so
make sure that we return ENOMEM.  Allocation failure should never happen
with the small size of the array, but code defensively anyway.

Fixes: 45feef8f50b94d ("xfs: refactor xfs_dabuf_map")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: make the btree ag cursor private union anonymous
Dave Chinner [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: make the btree ag cursor private union anonymous

Source kernel commit: c4aa10d041968f55f00fe8ca768b6f45f4066a69

This is much less widely used than the bc_private union was, so this
is done as a single patch. The named union xfs_btree_cur_private
goes away and is embedded into the struct xfs_btree_cur_ag as an
anonymous union, and the code is modified via this script:

$ sed -i 's/priv\.\([abt|refc]\)/\1/g' fs/xfs/*[ch] fs/xfs/*/*[ch]

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: make the btree cursor union members named structure
Dave Chinner [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: make the btree cursor union members named structure

Source kernel commit: 68422d90dad4fe98f99d6e414aeec9a58d5185d5

we need to name the btree cursor private structures to be able
to pull them out of the deeply nested structure definition they are
in now.

Based on code extracted from a patchset by Darrick Wong.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: make btree cursor private union anonymous
Dave Chinner [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: make btree cursor private union anonymous

Source kernel commit: 352890735e52343b1690f6d5d32224e2aa88a56a

Rename the union and it's internal structures to the new name and
remove the temporary defines that facilitated the change.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: rename btree cursor private btree member flags
Dave Chinner [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: rename btree cursor private btree member flags

Source kernel commit: 8ef547976a18e3d672194d8c944c19b345ef6bfc

BPRV is not longer appropriate because bc_private is going away.
Script:

$ sed -i 's/BTCUR_BPRV/BTCUR_BMBT/g' fs/xfs/*[ch] fs/xfs/*/*[ch]

With manual cleanup to the definitions in fs/xfs/libxfs/xfs_btree.h

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: change "BC_BT" to "BTCUR_BMBT", fix subject line typo]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: convert btree cursor inode-private member names
Dave Chinner [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: convert btree cursor inode-private member names

Source kernel commit: 92219c292af8ddfb64d75bdffcbdd9baf80ac0aa

bc_private.b -> bc_ino conversion via script:

$ sed -i 's/bc_private\.b/bc_ino/g' fs/xfs/*[ch] fs/xfs/*/*[ch]

And then revert the change to the bc_ino #define in
fs/xfs/libxfs/xfs_btree.h manually.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: tweak the subject line slightly]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: convert btree cursor ag-private member name
Dave Chinner [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: convert btree cursor ag-private member name

Source kernel commit: 576af7322807601d5ef366597645a69471570e10

bc_private.a -> bc_ag conversion via script:

`sed -i 's/bc_private\.a/bc_ag/g' fs/xfs/*[ch] fs/xfs/*/*[ch]`

And then revert the change to the bc_ag #define in
fs/xfs/libxfs/xfs_btree.h manually.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: introduce new private btree cursor names
Dave Chinner [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: introduce new private btree cursor names

Source kernel commit: 7cace18ab576ef65d16498d3a9e2170fff5f5c93

Just the defines of the new names - the conversion will be in
scripted commits after this.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: change "bc_bt" to "bc_ino"]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: check owner of dir3 blocks
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: check owner of dir3 blocks

Source kernel commit: 1b2c1a63b678d63e9c98314d44413f5af79c9c80

Check the owner field of dir3 block headers.  If it's corrupt, release
the buffer and return EFSCORRUPTED.  All callers handle this properly.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: check owner of dir3 data blocks
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: check owner of dir3 data blocks

Source kernel commit: a10c21ed5d5241d11cf1d5a4556730840572900b

Check the owner field of dir3 data block headers.  If it's corrupt,
release the buffer and return EFSCORRUPTED.  All callers handle this
properly.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: check owner of dir3 free blocks
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: check owner of dir3 free blocks

Source kernel commit: 6fb5aac73310d030be13eb3481fdb7c7cc7c0f00

Check the owner field of dir3 free block headers and reject the metadata
if there's something wrong with it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: don't ever return a stale pointer from __xfs_dir3_free_read
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: don't ever return a stale pointer from __xfs_dir3_free_read

Source kernel commit: 1cb5deb5bc095c070c09a4540c45f9c9ba24be43

If we decide that a directory free block is corrupt, we must take care
not to leak a buffer pointer to the caller.  After xfs_trans_brelse
returns, the buffer can be freed or reused, which means that we have to
set *bpp back to NULL.

Callers are supposed to notice the nonzero return value and not use the
buffer pointer, but we should code more defensively, even if all current
callers handle this situation correctly.

Fixes: de14c5f541e7 ("xfs: verify free block header fields")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: fix buffer corruption reporting when xfs_dir3_free_header_check fails
Darrick J. Wong [Fri, 1 May 2020 21:37:09 +0000 (17:37 -0400)] 
xfs: fix buffer corruption reporting when xfs_dir3_free_header_check fails

Source kernel commit: ce99494c9699df58b31d0a839e957f86cd58c755

xfs_verifier_error is supposed to be called on a corrupt metadata buffer
from within a buffer verifier function, whereas xfs_buf_mark_corrupt
is the function to be called when a piece of code has read a buffer and
catches something that a read verifier cannot.  The first function sets
b_error anticipating that the low level buffer handling code will see
the nonzero b_error and clear XBF_DONE on the buffer, whereas the second
function does not.

Since xfs_dir3_free_header_check examines fields in the dir free block
header that require more context than can be provided to read verifiers,
we must call xfs_buf_mark_corrupt when it finds a problem.

Switching the calls has a secondary effect that we no longer corrupt the
buffer state by setting b_error and leaving XBF_DONE set.  When /that/
happens, we'll trip over various state assertions (most commonly the
b_error check in xfs_buf_reverify) on a subsequent attempt to read the
buffer.

Fixes: bc1a09b8e334bf5f ("xfs: refactor verifier callers to print address of failing check")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: xfs_buf_corruption_error should take __this_address
Darrick J. Wong [Fri, 1 May 2020 21:37:08 +0000 (17:37 -0400)] 
xfs: xfs_buf_corruption_error should take __this_address

Add a xfs_failaddr_t parameter to this function so that callers can
potentially pass in (and therefore report) the exact point in the code
where we decided that a metadata buffer was corrupt.  This enables us to
wire it up to checking functions that have to run outside of verifiers.

Source kernel commit: e83cf875d67a6cb9ddfaa8b45d2fa93d12b5c66f

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: add a function to deal with corrupt buffers post-verifiers
Darrick J. Wong [Fri, 1 May 2020 21:37:08 +0000 (17:37 -0400)] 
xfs: add a function to deal with corrupt buffers post-verifiers

Source kernel commit: 8d57c21600a514d7a9237327c2496ae159bab5bb

Add a helper function to get rid of buffers that we have decided are
corrupt after the verifiers have run.  This function is intended to
handle metadata checks that can't happen in the verifiers, such as
inter-block relationship checking.  Note that we now mark the buffer
stale so that it will not end up on any LRU and will be purged on
release.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: fix xfs_rmap_has_other_keys usage of ECANCELED
Darrick J. Wong [Fri, 1 May 2020 21:37:08 +0000 (17:37 -0400)] 
xfs: fix xfs_rmap_has_other_keys usage of ECANCELED

Source kernel commit: a71e4228e6f2a4fe6519d8ed081d0a164967fa31

In e7ee96dfb8c26, we converted all ITER_ABORT users to use ECANCELED
instead, but we forgot to teach xfs_rmap_has_other_keys not to return
that magic value to callers.  Fix it now by using ECANCELED both to
abort the iteration and to signal that we found another reverse mapping.
This enables us to drop the separate boolean flag.

Fixes: e7ee96dfb8c26 ("xfs: remove all *_ITER_ABORT values")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: remove XFS_BUF_TO_SBP
Christoph Hellwig [Fri, 1 May 2020 21:37:08 +0000 (17:37 -0400)] 
xfs: remove XFS_BUF_TO_SBP

Source kernel commit: 3e6e8afd3abb745871ee215738a899a495c54a66

Just dereference bp->b_addr directly and make the code a little
simpler and more clear.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: remove XFS_BUF_TO_AGF
Christoph Hellwig [Fri, 1 May 2020 21:37:08 +0000 (17:37 -0400)] 
xfs: remove XFS_BUF_TO_AGF

Source kernel commit: 9798f615ad2be48466a01c44ad2257ba64ab03bd

Just dereference bp->b_addr directly and make the code a little
simpler and more clear.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>