]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/log
thirdparty/xfsprogs-dev.git
5 years agoxfsprogs: Release v4.18.0-rc0 v4.18.0-rc0
Eric Sandeen [Thu, 5 Jul 2018 20:27:56 +0000 (15:27 -0500)] 
xfsprogs: Release v4.18.0-rc0

Update all the necessary files for a 4.18.0-rc0 release.
This is primarily only a libxfs sync with linux-4.18

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: fix fdblocks accounting w/ RMAPBT per-AG reservation
Darrick J. Wong [Thu, 5 Jul 2018 20:16:04 +0000 (15:16 -0500)] 
xfs: fix fdblocks accounting w/ RMAPBT per-AG reservation

Source kernel commit: d8cb5e42378918e00eda58792f3ab86dd1e7d214

In __xfs_ag_resv_init we incorrectly calculate the amount by which to
decrease fdblocks when reserving blocks for the rmapbt.  Because rmapbt
allocations do not decrease fdblocks, we must decrease fdblocks by the
entire size of the requested reservation in order to achieve our goal of
always having enough free blocks to satisfy an rmapbt expansion.

This is in contrast to the refcountbt/finobt, which /do/ subtract from
fdblocks whenever they allocate a block.  For this allocation type we
preserve the existing behavior where we decrease fdblocks only by the
requested reservation minus the size of the existing tree.

This fixes the problem where the available block counts reported by
statfs change across a remount if there had been an rmapbt size change
since mount time.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: fix off-by-one error in xfs_rtalloc_query_range
Darrick J. Wong [Thu, 5 Jul 2018 20:16:04 +0000 (15:16 -0500)] 
xfs: fix off-by-one error in xfs_rtalloc_query_range

Source kernel commit: a3a374bf1889b1b401b25e6aada3ca4151a99d15

In commit 8ad560d2565e6 ("xfs: strengthen rtalloc query range checks")
we strengthened the input parameter checks in the rtbitmap range query
function, but introduced an off-by-one error in the process.  The call
to xfs_rtfind_forw deals with the high key being rextents, but we clamp
the high key to rextents - 1.  This causes the returned results to stop
one block short of the end of the rtdev, which is incorrect.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: don't allow insert-range to shift extents past the maximum offset
Darrick J. Wong [Thu, 5 Jul 2018 20:16:04 +0000 (15:16 -0500)] 
xfs: don't allow insert-range to shift extents past the maximum offset

Source kernel commit: f62cb48e43195f66c7a40bbfcf11531fc1ff8999

Zorro Lang reports that generic/485 blows an assert on a filesystem with
512 byte blocks.  The test tries to fallocate a post-eof extent at the
maximum file size and calls insert range to shift the extents right by
two blocks.  On a 512b block filesystem this causes startoff to overflow
the 54-bit startoff field, leading to the assert.

Therefore, always check the rightmost extent to see if it would overflow
prior to invoking the insert range machinery.

Reported-by: zlang@redhat.com
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=200137
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: More robust inode extent count validation
Dave Chinner [Thu, 5 Jul 2018 20:16:04 +0000 (15:16 -0500)] 
xfs: More robust inode extent count validation

Source kernel commit: 23fcb3340d033d9f081e21e6c12c2db7eaa541d3

When the inode is in extent format, it can't have more extents that
fit in the inode fork. We don't currenty check this, and so this
corruption goes unnoticed by the inode verifiers. This can lead to
crashes operating on invalid in-memory structures.

Attempts to access such a inode will now error out in the verifier
rather than allowing modification operations to proceed.

Reported-by: Wen Xu <wen.xu@gatech.edu>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: fix a typedef, add some braces and breaks to shut up compiler warnings]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: update incore per-AG inode count
Darrick J. Wong [Thu, 28 Jun 2018 20:11:59 +0000 (15:11 -0500)] 
xfs: update incore per-AG inode count

Source kernel commit: 89e9b5c0915aaeaf673a14e794c559768eda5534

For whatever reason we never actually update pagi_count (the in-core
perag inode count) when we allocate or free inode chunks.  Online scrub
is going to use it, so we need to fix the accounting.

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: replace do_mod with native operations
Dave Chinner [Thu, 28 Jun 2018 20:11:59 +0000 (15:11 -0500)] 
xfs: replace do_mod with native operations

Source kernel commit: 0703a8e1c17e2cba742eafe640be3b60f77352c4

do_mod() is a hold-over from when we have different sizes for file
offsets and and other internal values for 40 bit XFS filesystems.
Hence depending on build flags variables passed to do_mod() could
change size. We no longer support those small format filesystems and
hence everything is of fixed size theses days, even on 32 bit
platforms.

As such, we can convert all the do_mod() callers to platform
optimised modulus operations as defined by linux/math64.h.
Individual conversions depend on the types of variables being used.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: don't call xfs_da_shrink_inode with NULL bp
Eric Sandeen [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: don't call xfs_da_shrink_inode with NULL bp

Source kernel commit: bb3d48dcf86a97dc25fe9fc2c11938e19cb4399a

xfs_attr3_leaf_create may have errored out before instantiating a buffer,
for example if the blkno is out of range.  In that case there is no work
to do to remove it, and in fact xfs_da_shrink_inode will lead to an oops
if we try.

This also seems to fix a flaw where the original error from
xfs_attr3_leaf_create gets overwritten in the cleanup case, and it
removes a pointless assignment to bp which isn't used after this.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=199969
Reported-by: Xu, Wen <wen.xu@gatech.edu>
Tested-by: Xu, Wen <wen.xu@gatech.edu>
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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: clean up MIN/MAX
Dave Chinner [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: clean up MIN/MAX

Source kernel commit: 9bb54cb56ae8498d35392745f8f050112cec5dcb

Get rid of the MIN/MAX macros and just use the native min/max macros
directly in the XFS code.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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: move various type verifiers to common file
Dave Chinner [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: move various type verifiers to common file

Source kernel commit: 86210fbebae6e60b1158ccd6b47ee7ae1abf5b2c

New verification functions like xfs_verify_fsbno() and
xfs_verify_agino() are spread across multiple files and different
header files. They really don't fit cleanly into the places they've
been put, and have wider scope than the current header includes.

Move the type verifiers to a new file in libxfs (xfs-types.c) and
the prototypes to xfs_types.h where they will be visible to all the
code that uses the types.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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: convert to SPDX license tags
Dave Chinner [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: convert to SPDX license tags

Source kernel commit: 0b61f8a4079d904b1b1d47946cca898313de8c26

Remove the verbose license text from XFS files and replace them
with SPDX tags. This does not change the license of any of the code,
merely refers to the common, up-to-date license files in LICENSES/

This change was mostly scripted. fs/xfs/Makefile and
fs/xfs/libxfs/xfs_fs.h were modified by hand, the rest were detected
and modified by the following command:

for f in `git grep -l "GNU General" fs/xfs/` ; do
echo $f
cat $f | awk -f hdr.awk > $f.new
mv -f $f.new $f
done

And the hdr.awk script that did the modification (including
detecting the difference between GPL-2.0 and GPL-2.0+ licenses)
is as follows:

$ cat hdr.awk
BEGIN {
hdr = 1.0
tag = "GPL-2.0"
str = ""
}

/^ \* This program is free software/ {
hdr = 2.0;
next
}

/any later version./ {
tag = "GPL-2.0+"
next
}

/^ \*\// {
if (hdr > 0.0) {
print "// SPDX-License-Identifier: " tag
print str
print $0
str=""
hdr = 0.0
next
}
print $0
next
}

/^ \* / {
if (hdr > 1.0)
next
if (hdr > 0.0) {
if (str != "")
str = str "\n"
str = str $0
next
}
print $0
next
}

/^ \*/ {
if (hdr > 0.0)
next
print $0
next
}

// {
if (hdr > 0.0) {
if (str != "")
str = str "\n"
str = str $0
next
}
print $0
}

END { }
$

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: validate btree records on retrieval
Dave Chinner [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: validate btree records on retrieval

Source kernel commit: 9e6c08d4a8fc21fc496bf4543e5b2360fc610866

So we don't check the validity of records as we walk the btree. When
there are corrupt records in the free space btree (e.g. zero
startblock/length or beyond EOAG) we just blindly use it and things
go bad from there. That leads to assert failures on debug kernels
like this:

XFS: Assertion failed: fs_is_ok, file: fs/xfs/libxfs/xfs_alloc.c, line: 450
....
Call Trace:
xfs_alloc_fixup_trees+0x368/0x5c0
xfs_alloc_ag_vextent_near+0x79a/0xe20
xfs_alloc_ag_vextent+0x1d3/0x330
xfs_alloc_vextent+0x5e9/0x870

Or crashes like this:

XFS (loop0): xfs_buf_find: daddr 0x7fb28 out of range, EOFS 0x8000
.....
BUG: unable to handle kernel NULL pointer dereference at 00000000000000c8
....
Call Trace:
xfs_bmap_add_extent_hole_real+0x67d/0x930
xfs_bmapi_write+0x934/0xc90
xfs_da_grow_inode_int+0x27e/0x2f0
xfs_dir2_grow_inode+0x55/0x130
xfs_dir2_sf_to_block+0x94/0x5d0
xfs_dir2_sf_addname+0xd0/0x590
xfs_dir_createname+0x168/0x1a0
xfs_rename+0x658/0x9b0

By checking that free space records pulled from the trees are
within the valid range, we catch many of these corruptions before
they can do damage.

This is a generic btree record checking deficiency. We need to
validate the records we fetch from all the different btrees before
we use them to catch corruptions like this.

This patch results in a corrupt record emitting an error message and
returning -EFSCORRUPTED, and the higher layers catch that and abort:

XFS (loop0): Size Freespace BTree record corruption in AG 0 detected!
XFS (loop0): start block 0x0 block count 0x0
XFS (loop0): Internal error xfs_trans_cancel at line 1012 of file fs/xfs/xfs_trans.c.  Caller xfs_create+0x42a/0x670
.....
Call Trace:
dump_stack+0x85/0xcb
xfs_trans_cancel+0x19f/0x1c0
xfs_create+0x42a/0x670
xfs_generic_create+0x1f6/0x2c0
vfs_create+0xf9/0x180
do_mknodat+0x1f9/0x210
do_syscall_64+0x5a/0x180
entry_SYSCALL_64_after_hwframe+0x49/0xbe
.....
XFS (loop0): xfs_do_force_shutdown(0x8) called from line 1013 of file fs/xfs/xfs_trans.c.  Return address = ffffffff81500868
XFS (loop0): Corruption of in-memory data detected.  Shutting down filesystem

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: push corruption -> ESTALE conversion to xfs_nfs_get_inode()
Dave Chinner [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: push corruption -> ESTALE conversion to xfs_nfs_get_inode()

Source kernel commit: 29cad0b3edaffb65f78f61b63cb0c43f87f98865

In xfs_imap_to_bp(), we convert a -EFSCORRUPTED error to -EINVAL if
we are doing an untrusted lookup. This is done because we need
failed filehandle lookups to report -ESTALE to the caller, and it
does this by converting -EINVAL and -ENOENT errors to -ESTALE.

The squashing of EFSCORRUPTED in imap_to_bp makes it impossible for
for xfs_iget(UNTRUSTED) callers to determine the difference between
"inode does not exist" and "corruption detected during lookup". We
realy need that distinction in places calling xfS_iget(UNTRUSTED),
so move the filehandle error case handling all the way out to
xfs_nfs_get_inode() where it is needed.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@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: verify COW extent size hint is valid in inode verifier
Dave Chinner [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: verify COW extent size hint is valid in inode verifier

Source kernel commit: 02a0fda875c89e826c9f9f7e6861a0314d6a6b7d

There are rules for vald extent size hints. We enforce them when
applications set them, but fuzzers violate those rules and that
screws us over. Validate COW extent size hint rules in the inode
verifier to catch this.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@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: verify extent size hint is valid in inode verifier
Dave Chinner [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: verify extent size hint is valid in inode verifier

Source kernel commit: 7d71a671a2d900606d3a62ed5976d3b0feada3a6

There are rules for vald extent size hints. We enforce them when
applications set them, but fuzzers violate those rules and that
screws us over.

This results in alignment assertion failures when setting up
allocations such as this in direct IO:

XFS: Assertion failed: ap->length, file: fs/xfs/libxfs/xfs_bmap.c, line: 3432
....
Call Trace:
xfs_bmap_btalloc+0x415/0x910
xfs_bmapi_write+0x71c/0x12e0
xfs_iomap_write_direct+0x2a9/0x420
xfs_file_iomap_begin+0x4dc/0xa70
iomap_apply+0x43/0x100
iomap_file_buffered_write+0x62/0x90
xfs_file_buffered_aio_write+0xba/0x300
__vfs_write+0xd5/0x150
vfs_write+0xb6/0x180
ksys_write+0x45/0xa0
do_syscall_64+0x5a/0x180
entry_SYSCALL_64_after_hwframe+0x49/0xbe

And from xfs_db:

core.extsize = 10380288

Which is not an integer multiple of the block size, and so violates
Rule #7 for setting extent size hints. Validate extent size hint
rules in the inode verifier to catch this.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@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: catch bad stripe alignment configurations
Dave Chinner [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: catch bad stripe alignment configurations

Source kernel commit: fa4ca9c5574605d1e48b7e617705230a0640b6da

When stripe alignments are invalid, data alignment algorithms in the
allocator may not work correctly. Ensure we catch superblocks with
invalid stripe alignment setups at mount time. These data alignment
mismatches are now detected at mount time like this:

XFS (loop0): SB stripe unit sanity check failed
XFS (loop0): Metadata corruption detected at xfs_sb_read_verify+0xab/0x110, xfs_sb block 0xffffffffffffffff
XFS (loop0): Unmount and run xfs_repair
XFS (loop0): First 128 bytes of corrupted metadata buffer:
0000000091c2de02: 58 46 53 42 00 00 10 00 00 00 00 00 00 00 10 00  XFSB............
0000000023bff869: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000000cdd8c893: 17 32 37 15 ff ca 46 3d 9a 17 d3 33 04 b5 f1 a2  .27...F=...3....
000000009fd2844f: 00 00 00 00 00 00 00 04 00 00 00 00 00 00 06 d0  ................
0000000088e9b0bb: 00 00 00 00 00 00 06 d1 00 00 00 00 00 00 06 d2  ................
00000000ff233a20: 00 00 00 01 00 00 10 00 00 00 00 01 00 00 00 00  ................
000000009db0ac8b: 00 00 03 60 e1 34 02 00 08 00 00 02 00 00 00 00  ...`.4..........
00000000f7022460: 00 00 00 00 00 00 00 00 0c 09 0b 01 0c 00 00 19  ................
XFS (loop0): SB validate failed with error -117.

And the mount fails.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@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: explicitly pass buffer size to xfs_corruption_error
Darrick J. Wong [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: explicitly pass buffer size to xfs_corruption_error

Source kernel commit: 2551a53053de52993be8752731f084fad3cfc4d8

Explicitly pass the buffer length to xfs_corruption_error() instead of
assuming XFS_CORRUPTION_DUMP_LEN so that we avoid dumping off the end
of the buffer.

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: don't assert when on-disk btree pointers are garbage
Darrick J. Wong [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: don't assert when on-disk btree pointers are garbage

Source kernel commit: 85ae01098c1a6a8e3ce908f8808f2d8f8effdbe3

Don't ASSERT when we encounter bad on-disk btree pointers in the debug
check functions.  Log the error to leave breadcrumbs and let the upper
layers deal with it.

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: strengthen btree pointer checks before use
Darrick J. Wong [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: strengthen btree pointer checks before use

Source kernel commit: e63a1008ee08334ea6a9c9edb59b1d2763f5b231

Instead of ASSERTing on null btree pointers in xfs_btree_ptr_to_daddr,
use the new block number verifiers to ensure that the btree pointer
doesn't point to any sensitive areas (AG headers, past-EOFS) and return
-EFSCORRUPTED if this is the case.  Remove the ASSERT because on-disk
corruptions shouldn't trigger ASSERTs.

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: introduce xfs_btree_debug_check_ptr
Darrick J. Wong [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: introduce xfs_btree_debug_check_ptr

Source kernel commit: 4cbae4b816fd61e63abbe8330741e257fa95d4c5

Make xfs_btree_check_ptr a non-debug function and introduce a new _debug
version that only runs when #ifdef DEBUG.   This will enable us to reuse
the checking logic with other parts of the btree code.

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 directory bestfree information in the verifier
Darrick J. Wong [Thu, 28 Jun 2018 20:11:58 +0000 (15:11 -0500)] 
xfs: check directory bestfree information in the verifier

Source kernel commit: e4f45eff86fdbafd8e0ba072fd52422e32e5b5ac

Create a variant of xfs_dir2_data_freefind that is suitable for use in a
verifier.  Because _freefind is called by the verifier, we simply
duplicate the _freefind function, convert the ASSERTs to return
__this_address, and modify the verifier to call our new function.  Once
we've made it impossible for directory blocks with bad bestfree data to
make it into the filesystem we can remove the DEBUG code from the
regular _freefind function.

Underlying argument: corruption of on-disk metadata should return
-EFSCORRUPTED instead of blowing ASSERTs.

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: don't return garbage buffers in xfs_da3_node_read
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: don't return garbage buffers in xfs_da3_node_read

Source kernel commit: 924cade4df49e7c9fddcbae678dbd9dee3b0aeb6

If we're reading a node in a dir/attr btree and the buffer comes off the
disk with a magic number we don't recognize, don't ASSERT and don't set
a garbage buffer type (0 also triggers ASSERTs).  Instead, report the
corruption, release the buffer, and return -EFSCORRUPTED because that's
what the dabtree is -- corrupt.

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: don't ASSERT on short form btree root pointer of zero
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: don't ASSERT on short form btree root pointer of zero

Source kernel commit: 1f5c071d19aef379d0876929a598adcbc7f87986

Don't ASSERT if the short form btree root pointer is zero.  Now that we
use xfs_verify_agbno to check all short form btree pointers, we'll let
that log the error and pass it to the upper layers.

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: btree lookup shouldn't ASSERT on empty btree nodes
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: btree lookup shouldn't ASSERT on empty btree nodes

Source kernel commit: eeee0d6a9bc93eaa211918c203fde263d44fa20e

If a btree lookup encounters an empty btree node or an empty btree leaf
on a multi-level btree, that's evidence of a corrupt on-disk btree.
Therefore, we should return -EFSCORRUPTED to the upper levels, not an
ASSERT failure.

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_alloc_get_rec should return EFSCORRUPTED for obvious bnobt corruption
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: xfs_alloc_get_rec should return EFSCORRUPTED for obvious bnobt corruption

Source kernel commit: a37f7b127ed3dcfab3edc105482891711c1966b3

Return -EFSCORRUPTED when the bnobt/cntbt return obviously corrupt
values, rather than letting them bounce around in the internal code.

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 redundant ASSERT on insufficient bestfree length in _leaf_addname
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: remove redundant ASSERT on insufficient bestfree length in _leaf_addname

Source kernel commit: b3986010cea509842edf15c56ca10c18befdcafb

In xfs_dir2_leaf_addname we ASSERT if the length of the unused space
described by bestfree[0] is less the amount of space we wish to consume.
Immediately after it is a call to xfs_dir2_data_use_free where the
offset parameter is offset of the unused space and the length parameter
is the amount of space we wish to consume.  Both values (and the unused
space pointer) are passed into xfs_dir2_data_check_free, which also
validates that the region of unused space is big enough to cover the
space we wish to consume.  This is effectively the same check that the
ASSERT covers, and since a check failure results in a corruption message
being logged we can remove the ASSERT.

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: don't assert when reporting on-disk corruption while loading btree
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: don't assert when reporting on-disk corruption while loading btree

Source kernel commit: 17ba2cc7b5b9ee6a44baf5e169c8901f1f049ea8

Don't bother ASSERTing when we're already going to log and return the
corruption status.

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: verify AGI unlinked list contains valid blocks
Dave Chinner [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: verify AGI unlinked list contains valid blocks

Source kernel commit: 9f96cc958e8ae9864e6d597a5f3e80b5fca35ae4

The heads of tha AGI unlinked list are only scanned on debug
kernels when the verifier runs. Change that to always scan the heads
and validate that the inode numbers are valid.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: fix error handling in xfs_refcount_insert()
Dave Chinner [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: fix error handling in xfs_refcount_insert()

Source kernel commit: 16858f7c21156e676c98a5f6532f68cacbde3784

generic/475 fired an assert failure just after the filesystem was
shut down:

XFS: Assertion failed: fs_is_ok, file: fs/xfs/libxfs/xfs_refcount.c, line: 182
.....
Call Trace:
xfs_refcount_insert+0x151/0x190
xfs_refcount_adjust_extents.constprop.11+0x9c/0x470
xfs_refcount_adjust.constprop.10+0xb0/0x270
xfs_refcount_finish_one+0x25a/0x420
xfs_trans_log_finish_refcount_update+0x2a/0x40
xfs_refcount_update_finish_item+0x35/0xa0
xfs_defer_finish+0x15e/0x4d0
xfs_reflink_remap_extent+0x1bc/0x610
xfs_reflink_remap_blocks+0x6e/0x280
xfs_reflink_remap_range+0x311/0x530
vfs_clone_file_range+0x119/0x200
....

If xfs_btree_insert() returns an error, the corruption check fires
instead of passing the error back the caller. The corruption check
should be after we've checked for an error, not before, thereby
avoiding assert failures if the filesystem shuts down during a
refcount btree record insert.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: fix xfs_rtalloc_rec units
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: fix xfs_rtalloc_rec units

Source kernel commit: a0e5c435babd8bb61612d2e4e9b098cacdd825f7

All the realtime allocation functions deal with space on the rtdev in
units of realtime extents.  However, struct xfs_rtalloc_rec confusingly
uses the word 'block' in the name, even though they're really extents.

Fix the naming problem and fix all the unit handling problems in the two
existing users.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: strengthen rtalloc query range checks
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: strengthen rtalloc query range checks

Source kernel commit: 8ad560d2565e64b8be0cf5901c1e8fe034ac5599

Strengthen the rtalloc range query checks to make sure that the keys do
not run off the end of the realtime device inappropriately.  Note that
the query range functions require units of rt extents, not blocks,
despite the type name.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: xfs_rtbuf_get should check the bmapi_read results
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: xfs_rtbuf_get should check the bmapi_read results

Source kernel commit: a03f1641c7a6d4e88c6aae0cd3d52305cdb967a0

The xfs_rtbuf_get function should check the block mapping it gets back
from bmapi_read.  If there are no mappings or the mapping isn't a real
extent, we should return -EFSCORRUPTED rather than trying to read a
garbage value.  We also require realtime bitmap blocks to be real,
written allocations.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: xfs_rtword_t should be unsigned, not signed
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: xfs_rtword_t should be unsigned, not signed

Source kernel commit: 2483113f3d7baa303deac115e6764d9489c8316b

xfs_rtword_t is used for bit manipulations in the realtime bitmap file.
Since we're performing bit shifts with this type, we don't want sign
extension and we don't want to be left shifting negative quantities
because that's undefined behavior.

This also shuts up these UBSAN warnings:
UBSAN: Undefined behaviour in fs/xfs/libxfs/xfs_rtbitmap.c:833:48
signed integer overflow:
-2147483648 - 1 cannot be represented in type 'int'

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: repair superblocks
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: repair superblocks

Source kernel commit: d25522f10cfa342a20867086a516c45c87b0877c

If one of the backup superblocks is found to differ seriously from
superblock 0, write out a fresh copy from the in-core sb.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: fix inobt magic number check
Darrick J. Wong [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: fix inobt magic number check

Source kernel commit: 2e050e648ad6c74a2f0a28f645155128be0626ca

In commit a6a781a58befcbd467c ("xfs: have buffer verifier functions
report failing address") the bad magic number return was ported
incorrectly.

Fixes: a6a781a58befcbd467ce843af4eaca3906aa1f08
Reported-by: syzbot+08ab33be0178b76851c8@syzkaller.appspotmail.com
Signed-off-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: implement online get/set fs label
Eric Sandeen [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: implement online get/set fs label

Source kernel commit: f7664b31975bd893190708e76b2c424328f0c49b

The GET ioctl is trivial, just return the current label.

The SET ioctl is more involved:
It transactionally modifies the superblock to write a new filesystem
label to the primary super.

A new variant of xfs_sync_sb then writes the superblock buffer
immediately to disk so that the change is visible from userspace.

It then invalidates any page cache that userspace might have previously
read on the block device so that i.e. blkid can see the change
immediately, and updates all secondary superblocks as userspace relable
does.

Also includes for bisectability:

xfs: use xfs_trans_getsb in xfs_sync_sb_buf

Source kernel commit: 89c2e71123badc1e75316ccd969ee8a5c6fd921a

Use xfs_trans_getsb rather than reaching right in for
mp->m_sb_bp; I think this is more correct, and it facilitates
building this libxfs code in userspace as well.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
[darrick: use dchinner's new xfs_update_secondary_sbs function]
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: factor the ag length extension code into libxfs
Dave Chinner [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: factor the ag length extension code into libxfs

Source kernel commit: 49dd56f26ea7d18d4ca71f43a082dbb92798ebd3

Growfs currently manually codes the extension of the last AG in a
filesytem during the growfs process. Factor that out of the growfs
code and move it into libxfs along with teh rest of the AG header
modification code.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: move growfs core to libxfs
Dave Chinner [Thu, 28 Jun 2018 20:11:57 +0000 (15:11 -0500)] 
xfs: move growfs core to libxfs

Source kernel commit: b16817b66b6c97d2a812d663d26faed40079892a

So it can be shared with userspace (e.g. mkfs) easily.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: implement the metadata repair ioctl flag
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: implement the metadata repair ioctl flag

Source kernel commit: 84d42ea6b6269aee7eb3d91a4425a08b8965fd4a

Plumb in the pieces necessary to make the "scrub" subfunction of
the scrub ioctl actually work.  This means that we make the IFLAG_REPAIR
flag to the scrub ioctl actually do something, and we add an errortag
knob so that xfstests can force the kernel to rebuild a metadata
structure even if there's nothing wrong with it.

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: teach xfs_bmapi_remap to accept some bmapi flags
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: teach xfs_bmapi_remap to accept some bmapi flags

Source kernel commit: 7644bd988d911168c80599bc034bb489dc851dcf

Teach xfs_bmapi_remap how to map in unwritten extent and to skip rmap
updates.  This enables us to rebuild real and unwritten extents from the
rmapbt.

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 xfs_bmapi_remapi work with attribute forks
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: make xfs_bmapi_remapi work with attribute forks

Source kernel commit: 7cf199ba5a70dbc744276efc94442fb4436dac15

Add a new flags argument to xfs_bmapi_remapi so that we can pass BMAPI
flags into the function.  This enables us to pass in BMAPI_ATTRFORK so
that we can remap things into the attribute fork.  Eventually the
online repair code will use this to rebuild attribute forks, so make it
non-static.

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: hoist xfs_scrub_agfl_walk to libxfs as xfs_agfl_walk
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: hoist xfs_scrub_agfl_walk to libxfs as xfs_agfl_walk

Source kernel commit: 9f3a080ef19b1c182a8fb1edbfb707fdb811437c

This function is basically a generic AGFL block iterator, so promote it
to libxfs ahead of online repair wanting to use 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: superblock scrub should use short-lived buffers
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: superblock scrub should use short-lived buffers

Source kernel commit: 689e11c84b15866619e7582486acacaf79d7e3e2

Secondary superblocks are rarely used, so create a helper to read a
given non-primary AG's superblock and ensure that it won't stick around
hogging memory.

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: factor out nodiscard helpers
Brian Foster [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: factor out nodiscard helpers

Source kernel commit: 4e529339af15226a30e0ca044aa2d78ba3518494

The changes to skip discards of speculative preallocation and
unwritten extents introduced several new wrapper functions through
the bunmapi -> extent free codepath to reduce churn in all of the
associated callers. In several cases, these wrappers simply toggle a
single flag to skip or not skip discards for the resulting blocks.

The explicit _nodiscard() wrappers for such an isolated set of
callers is a bit overkill. Kill off these wrappers and replace with
the calls to the underlying functions in the contexts that need to
control discard behavior. Retain the wrappers that preserve the
original calling conventions to serve the original purpose of
reducing code churn.

This is a refactoring patch and does not change behavior.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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 BMAPI_NORMAP flag to perform block remapping without updating rmapbt
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: add BMAPI_NORMAP flag to perform block remapping without updating rmapbt

Source kernel commit: 95eb308caa0ff7c4a0a86053422934737e6e6dc7

Add a new flag, XFS_BMAPI_NORMAP, which will perform file block
remapping without updating the rmapbt.  This will be used by the repair
code to reconstruct bmbts from the rmapbt, in which case we don't want
the rmapbt update.

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 repair helpers for the reference count btree
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: add repair helpers for the reference count btree

Source kernel commit: 08daa3ccf541b8cc59d198daaccefae17fe565ae

Add a couple of functions to the refcount btree and generic btree code
that will be used to repair the refcountbt.

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 repair helpers for the reverse mapping btree
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: add repair helpers for the reverse mapping btree

Source kernel commit: 4d4f86b49fd0d88677ce45c9cc544cdf663bf047

Add a couple of functions to the reverse mapping btree that will be used
to repair the rmapbt.

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: expose various functions to repair code
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: expose various functions to repair code

Source kernel commit: 7f8f1313d91a7db9546de6e5bfeb1a2eebb1fef5

Expose various helpers that the repair code will want to use.

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 helpers to calculate btree size
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: add helpers to calculate btree size

Source kernel commit: 14861c47400b4a1669956d8b027fe4b7855e39f1

Add a bunch of helper functions that calculate the sizes of various
btrees.  These will be used to repair btrees and btree headers.

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: replace XFS_QMOPT_DQALLOC with a simple boolean
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: replace XFS_QMOPT_DQALLOC with a simple boolean

Source kernel commit: 30ab2dcf2c0693e518b1920e6edc4212cba10d10

DQALLOC is only ever used with xfs_qm_dqget*, and the only flag that the
_dqget family of functions cares about is DQALLOC.  Therefore, change
it to a boolean 'can alloc?' flag for the dqget interfaces where that
makes sense.

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: remove unnecessary xfs_qm_dqattach parameter
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: remove unnecessary xfs_qm_dqattach parameter

Source kernel commit: c14cfccabe2af251388e20c1004ac5c6a970ba53

The flags argument is always zero, get rid of it.

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: refactor XFS_QMOPT_DQNEXT out of existence
Darrick J. Wong [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: refactor XFS_QMOPT_DQNEXT out of existence

Source kernel commit: 2e330e76e03dd0caee6804b49e9e49d7c3998867

There's only one caller of DQNEXT and its semantics can be moved into a
separate function, so create the function and get rid of the flag.

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: don't discard on free of unwritten extents
Brian Foster [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: don't discard on free of unwritten extents

Source kernel commit: 84ca484ecf2f8e1dc3afddc895cb9b62c531db49

Unwritten extents by definition have not been written to until they
are converted to normal written extents. If unwritten extents are
freed from a file, it is therefore guaranteed that the blocks have
not been written to since allocation (note that zero range punches
and reallocates blocks).

To cut down on online discards generated from workloads that make
use of preallocation, skip discards of extents if they are in the
unwritten state when the extent is freed.

Note that this optimization does not apply to log recovery, during
which all freed extents are discarded if online discard is enabled.
Also note that it may be possible for a filesystem crash to occur
after write completion of an unwritten extent but before unwritten
conversion such that the extent remains unwritten after log
recovery. Since this pseudo-inconsistency may already be possible
after a crash (consider writing to recently allocated blocks where
the allocation transaction is lost after a crash), this change
shouldn't introduce any fundamental limitations that don't already
exist. In short, on storage stacks where discards are important,
it's good practice to run an occasional fstrim even with online
discard enabled in the filesystem, particularly after a crash.

Signed-off-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>
5 years agoxfs: add bmapi nodiscard flag
Brian Foster [Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)] 
xfs: add bmapi nodiscard flag

Source kernel commit: fcb762f5de2e534ab47b5f034fe484c2b25b4d51

Freed extents are unconditionally discarded when online discard is
enabled. Define XFS_BMAPI_NODISCARD to allow callers to bypass
discards when unnecessary. For example, this will be useful for
eofblocks trimming.

This patch does not change behavior.

Signed-off-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>
5 years agoxfs: get rid of the log item descriptor
Dave Chinner [Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)] 
xfs: get rid of the log item descriptor

Source kernel commit: e6631f85546c8ff8842f62c73be44ff502d4287a

It's just a connector between a transaction and a log item. There's
a 1:1 relationship between a log item descriptor and a log item,
and a 1:1 relationship between a log item descriptor and a
transaction. Both relationships are created and terminated at the
same time, so why do we even have the descriptor?

Replace it with a specific list_head in the log item and a new
log item dirtied flag to replace the XFS_LID_DIRTY flag.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
[darrick: fix up deferred agfl intent finish_item use of LID_DIRTY]
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: adder caller IP to xfs_defer* tracepoints
Dave Chinner [Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)] 
xfs: adder caller IP to xfs_defer* tracepoints

Source kernel commit: e632a5690c734a383a83272a502be79cb2c040e5

So it's clear in the trace where they are being called from.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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>
5 years agoxfs: add missing rmap error return
Darrick J. Wong [Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)] 
xfs: add missing rmap error return

Source kernel commit: 52101dfe56f71d8cb140c2440d95affa25a53746

xfs_rmap_lookup_le_range can return errors, so we need to check for
them and bail out.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: bmap debugging should never panic the system
Darrick J. Wong [Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)] 
xfs: bmap debugging should never panic the system

Source kernel commit: cec572561a748396c783c1ea91a289816d3c4f18

Don't panic() the system if the bmap records are garbage, just call
ASSERT which gives us the same backtrace but enables developers to
control if the system goes down or not.  This makes debugging with
generic/388 much easier because it won't reboot the machine midway
through a run just because btree_read_bufl returns EIO when the fs has
already shut down.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: defer agfl block frees from deferred ops processing context
Brian Foster [Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)] 
xfs: defer agfl block frees from deferred ops processing context

Source kernel commit: 2bc5eba8b6957824631205aeffc75db8dbb5426a

Now that AGFL block frees are deferred when dfops is set in the
transaction, start deferring AGFL block frees from contexts that are
known to push the limits of existing log reservations.

The first such context is deferred operation processing itself. This
primarily targets deferred extent frees (such as file extents and
inode chunks), but in doing so covers all allocation operations that
occur in deferred operation processing context.

Update xfs_defer_finish() to set and reset ->t_agfl_dfops across the
processing sequence. This means that any AGFL block frees due to
allocation events result in the addition of new EFIs to the dfops
rather than being processed immediately. xfs_defer_finish() rolls
the transaction at least once more to process the frees of the AGFL
blocks back to the allocation btrees and returns once the AGFL is
rectified.

Signed-off-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>
5 years agoxfs: defer agfl block frees when dfops is available
Brian Foster [Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)] 
xfs: defer agfl block frees when dfops is available

Source kernel commit: f8f2835a9cf300079835e1adb1d90f85033be04c

The AGFL fixup code executes before every block allocation/free and
rectifies the AGFL based on the current, dynamic allocation
requirements of the fs. The AGFL must hold a minimum number of
blocks to satisfy a worst case split of the free space btrees caused
by the impending allocation operation. The AGFL is also updated to
maintain the implicit requirement for a minimum number of free slots
to satisfy a worst case join of the free space btrees.

Since the AGFL caches individual blocks, AGFL reduction typically
involves multiple, single block frees. We've had reports of
transaction overrun problems during certain workloads that boil down
to AGFL reduction freeing multiple blocks and consuming more space
in the log than was reserved for the transaction.

Since the objective of freeing AGFL blocks is to ensure free AGFL
free slots are available for the upcoming allocation, one way to
address this problem is to release surplus blocks from the AGFL
immediately but defer the free of those blocks (similar to how
file-mapped blocks are unmapped from the file in one transaction and
freed via a deferred operation) until the transaction is rolled.
This turns AGFL reduction into an operation with predictable log
reservation consumption.

Add the capability to defer AGFL block frees when a deferred ops
list is available to the AGFL fixup code. Add a dfops pointer to the
transaction to carry dfops through various contexts to the allocator
context. Deferring AGFL frees is  conditional behavior based on
whether the transaction pointer is populated. The long term
objective is to reuse the transaction pointer to clean up all
unrelated callchains that pass dfops on the stack along with a
transaction and in doing so, consistently defer AGFL blocks from the
allocator.

A bit of customization is required to handle deferred completion
processing because AGFL blocks are accounted against a per-ag
reservation pool and AGFL blocks are not inserted into the extent
busy list when freed (they are inserted when used and released back
to the AGFL). Reuse the majority of the existing deferred extent
free infrastructure and customize it appropriately to handle AGFL
blocks.

Note that this patch only adds infrastructure. It does not change
behavior because no callers have been updated to pass ->t_agfl_dfops
into the allocation code.

Signed-off-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>
5 years agoxfs: create agfl block free helper function
Brian Foster [Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)] 
xfs: create agfl block free helper function

Source kernel commit: 4223f659dd3edd9e561d90488c6ae332a0a05148

Refactor the AGFL block free code into a new helper such that it can
be invoked from deferred context. No functional changes.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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: print specific dqblk that failed verifiers
Eric Sandeen [Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)] 
xfs: print specific dqblk that failed verifiers

Source kernel commit: 72c5c5f6d01c859dfe16c4910a5222ed9393c37c

Rather than printing the top of the buffer that held a corrupted dqblk,
restructure things to print out the specific one that failed by pushing
the calls to the verifier_error function down into the verifier which
iterates over the buffer and detects the error.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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 full xfs_dqblk verifier
Eric Sandeen [Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)] 
xfs: add full xfs_dqblk verifier

Source kernel commit: 7224fa482a6daa0558792e03a209e08d34690a26

Add an xfs_dqblk verifier so that it can check the uuid on V5 filesystems;
it calls the existing xfs_dquot_verify verifier to validate the
xfs_disk_dquot_t contained inside it.  This lets us move the uuid
verification out of the crc verifier, which makes little sense.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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: pass full xfs_dqblk to repair during quotacheck
Eric Sandeen [Thu, 28 Jun 2018 20:11:54 +0000 (15:11 -0500)] 
xfs: pass full xfs_dqblk to repair during quotacheck

Source kernel commit: 48fa1db87f730da1aed2d3df0cc8c33c7c133b4b

It's a bit dicey to pass in the smaller xfs_disk_dquot and then cast it to
something larger; pass in the full xfs_dqblk so we know the caller has sent
us the right thing.  Rename the function to xfs_dqblk_repair for
clarity.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: check type in quota verifier during quotacheck
Eric Sandeen [Thu, 28 Jun 2018 20:11:54 +0000 (15:11 -0500)] 
xfs: check type in quota verifier during quotacheck

Source kernel commit: 57ab324553bbfedc8e732eb570edfac0f5cfe57e

During quotacheck we send in the quota type, so verify that as well.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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 unused flags arg from xfs_dquot_verify
Eric Sandeen [Thu, 28 Jun 2018 20:11:54 +0000 (15:11 -0500)] 
xfs: remove unused flags arg from xfs_dquot_verify

Source kernel commit: e381a0f6c28a3f2a452d5fba9b917f03e5dc4ffb

Long ago the flags argument was used to determine whether to issue warnings
about corruptions, but that's done elsewhere now and the flag is unused
here, so remove it.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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: make xfs_buf_incore out of line
Dave Chinner [Thu, 28 Jun 2018 20:11:54 +0000 (15:11 -0500)] 
xfs: make xfs_buf_incore out of line

Source kernel commit: 8925a3dc4771004b3e697e7159fa87be2aa5dd43

Move xfs_buf_incore out of line and make it the only way to look up
a buffer in the buffer cache from outside the buffer cache. Convert
the external users of _xfs_buf_find() to xfs_buf_incore() and make
_xfs_buf_find() static.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: actually rename xfs_incore -> xfs_buf_incore]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: clear extent size hints when clearing inode core
Darrick J. Wong [Thu, 28 Jun 2018 20:09:21 +0000 (15:09 -0500)] 
xfs_repair: clear extent size hints when clearing inode core

In kernel 4.18 we become more strict about what can be in the extent
size hint fields, even for freed inodes.  Therefore, if repair decides
to clear out an inode core, zero the hint fields and clear the flags so
that the kernel won't trip over the cleared inode if and when it tries
to read the chunk.

Signed-off-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 agoxfsprogs: Release v4.17.0 v4.17.0
Eric Sandeen [Thu, 28 Jun 2018 16:52:21 +0000 (11:52 -0500)] 
xfsprogs: Release v4.17.0

Update all the necessary files for a 4.17.0 release.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfsprogs: Release v4.17.0-rc1 v4.17.0-rc1
Eric Sandeen [Fri, 22 Jun 2018 19:15:45 +0000 (14:15 -0500)] 
xfsprogs: Release v4.17.0-rc1

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

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: clarify -c in bmap documentation
Darrick J. Wong [Fri, 22 Jun 2018 19:15:42 +0000 (14:15 -0500)] 
xfs_io: clarify -c in bmap documentation

The bmap -c parameter displays the cow fork information for a file if
the kernel was built with CONFIG_XFS_DEBUG=y.  Since xfs_bmap doesn't
support it and it doesn't work generally, remove it from the manpages.
However, xfstests relies on the -c command to be documented in the help
screen so leave it there with a warning about its use.

Signed-off-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_bmap: remove -c from manpage
Darrick J. Wong [Fri, 22 Jun 2018 00:46:25 +0000 (19:46 -0500)] 
xfs_bmap: remove -c from manpage

There is no -c switch so remove the documentation.

Signed-off-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_bmap: don't reject -e
Darrick J. Wong [Fri, 22 Jun 2018 00:46:24 +0000 (19:46 -0500)] 
xfs_bmap: don't reject -e

The xfs_io bmap command has an -e switch that prints delalloc extents
without fsync'ing the file first.  The xfs_bmap manpage says it'll pass
-e through, but it doesn't.  Fix the script and fix the weird manpage
discrepancy where it doesn't list -e in the available options but
discusses it anyway.

Fixes: 7536ce44f6 ("xfs_io: bmap should support querying CoW fork, shared blocks")
Signed-off-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_repair: Fix root inode's parent when it's bogus for sf directory
Marco Benatto [Fri, 22 Jun 2018 00:46:24 +0000 (19:46 -0500)] 
xfs_repair: Fix root inode's parent when it's bogus for sf directory

Currently when root inode is in short-form and its parent ino
has an invalid value, process_sf_dir2() ends up not fixing it,
because if verify_inum() fails we never get to the next case which
would fix the root inode's parent pointer.

This behavior triggers the following assert on process_dir2():

   ASSERT((ino != mp->m_sb.sb_rootino && ino != *parent) ||
        (ino == mp->m_sb.sb_rootino &&
        (ino == *parent || need_root_dotdot == 1)));

This patch fixes this behavior by making sure we always properly
handle rootino parent pointer in process_sf_dir2()

Signed-off-by: Marco Benatto <mbenatto@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: fix signed comparison problem in copy_file_range
Darrick J. Wong [Fri, 1 Jun 2018 00:38:54 +0000 (19:38 -0500)] 
xfs_io: fix signed comparison problem in copy_file_range

cvtnum() returns a signed long long, so the type of 'len' should be a
signed type so that a user entering a negative length doesn't produce
some huge positive integer.  The negative len check demands it anyway.

Coverity-id: 1435895
Fixes: 25b4549 ("xfs_io: Make copy_range arguments understand *iB values")
Signed-off-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_db: Don't ASSERT on unrecognized metadata
Carlos Maiolino [Thu, 31 May 2018 19:10:42 +0000 (14:10 -0500)] 
xfs_db: Don't ASSERT on unrecognized metadata

For some types, (for example attr3) if the metadata is not recognized
as the requested type, we can hit an ASSERT when trying to print
the type:

xfs_db: print.c:164: print_flist_1: Assertion `fa->arg & 64' failed.
Aborted (core dumped)

This can happen for corrupted metadata or even just a misdirected
user command; there's no reason to ASSERT.  If we get here, print
something helpful and carry on.

[sandeen: write the commit log]

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agomkfs.xfs: if either sunit or swidth is nonzero, the other must be as well
Eric Sandeen [Thu, 31 May 2018 19:09:55 +0000 (14:09 -0500)] 
mkfs.xfs: if either sunit or swidth is nonzero,  the other must be as well

Don't allow the user to set one but not the other.

Reported-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_db: handle realtime bitmap / summary files as text
Darrick J. Wong [Thu, 31 May 2018 19:09:55 +0000 (14:09 -0500)] 
xfs_db: handle realtime bitmap / summary files as text

Use handle_text to print realtime bitmap / summary file blocks instead
of erroring out.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: Make copy_range arguments understand *iB values
Goldwyn Rodrigues [Thu, 31 May 2018 19:09:55 +0000 (14:09 -0500)] 
xfs_io: Make copy_range arguments understand *iB values

Arguments such as 2MiB or 2M are converted to 2 because copy_range uses
strtoull(). Convert strtoull() to cvtnum().

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: fix null pointer deref when complaining about scrub command
Darrick J. Wong [Thu, 31 May 2018 19:09:55 +0000 (14:09 -0500)] 
xfs_io: fix null pointer deref when complaining about scrub command

Don't increment optind until we've validated that argv[optind] is a
valid scrub/repair subcommand and do not need to complain about
argv[optind].

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: fix libxfs api violations in quota repair code
Eric Sandeen [Thu, 31 May 2018 19:09:55 +0000 (14:09 -0500)] 
xfs_repair: fix libxfs api violations in quota repair code

My "repair quotas" patch forgot about our libxfs API tricks,
fix that.

Fixes: 5857dce ("xfs_repair: check and repair quota metadata")
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_scrub: actually check for errors coming from close()
Darrick J. Wong [Thu, 31 May 2018 19:09:54 +0000 (14:09 -0500)] 
xfs_scrub: actually check for errors coming from close()

Report errors reported by close().

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agofsck: fix more bashisms
Darrick J. Wong [Thu, 31 May 2018 19:09:54 +0000 (14:09 -0500)] 
fsck: fix more bashisms

command -v is a bashism, so we need to get rid of it.  The shell returns
an error code of 127 if it couldn't invoke xfs_repair, so teach
repair2fsck_code to deal with this.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_buflock: record buffer initialization
Darrick J. Wong [Thu, 31 May 2018 19:09:54 +0000 (14:09 -0500)] 
xfs_buflock: record buffer initialization

Buffers are created locked, so we have to factor that into the buffer
state machine that the script utilizes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_buflock: record line number of trace where we locked the buffer
Darrick J. Wong [Thu, 31 May 2018 19:09:54 +0000 (14:09 -0500)] 
xfs_buflock: record line number of trace where we locked the buffer

Enhance the debug output by reporting at which line in the trace output
we locked a particular buffer.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_buflock: ignore if buffer already locked
Darrick J. Wong [Thu, 31 May 2018 19:09:54 +0000 (14:09 -0500)] 
xfs_buflock: ignore if buffer already locked

If the trace data says we ran trylock but we were already locked, don't
record another lock.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: fix integer handling issues
Darrick J. Wong [Thu, 31 May 2018 19:09:54 +0000 (14:09 -0500)] 
xfs_repair: fix integer handling issues

When we shift sb_logblocks to the left we need to ensure that we have
enough storage space to shift correctly.  Cast logblocks to a 64-bit
type so that we don't screw up the check.

Coverity-id: 1435810
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: Allow -P and -L to be given to open for O_PATH and O_NOFOLLOW
David Howells [Thu, 24 May 2018 19:48:41 +0000 (14:48 -0500)] 
xfs_io: Allow -P and -L to be given to open for O_PATH and  O_NOFOLLOW

Allow "open -P" to specify O_PATH so that paths which would otherwise be
unopenable might be opened for stat()'ing.  Such things include files that
would incur an access error or device files for which no corresponding
driver is available.

Allow "-L" to be given in conjunction with O_PATH to specify O_NOFOLLOW
also.

We also have to avoid calling xfsctl() if O_PATH is given as ioctls are
forbidden on such fds.  This means we cannot retrieve the geometry
information on an XFS filesystem, so the record gets cleared instead.  For
the moment, only the xfsctl() calls in the 'open' command are
conditionalised.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: syncfs can fail
Jeff Layton [Thu, 24 May 2018 19:48:39 +0000 (14:48 -0500)] 
xfs_io: syncfs can fail

syncfs can return an error. Report one if it does. Also, ensure that
xfs_io will exit with a non-zero status in that case.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_io: add label command
Eric Sandeen [Thu, 24 May 2018 19:48:33 +0000 (14:48 -0500)] 
xfs_io: add label command

This adds an online get/set/clear label command to xfs_io.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: check and repair quota metadata
Eric Sandeen [Wed, 23 May 2018 21:30:49 +0000 (16:30 -0500)] 
xfs_repair: check and repair quota metadata

Today, quota inodes are not checked at all in xfs_repair.  (This is
a little odd, because xfs_check used to do it in process_quota()).

The kernel has quota inode validation and repair routines, but it is
out of the ordinary for the kernel to be doing metadata repair.  And
now that we have metadata verifiers, this also yields a surprisingly
noisy mount if quota inodes are corrupted, even immediately after an
xfs_repair.

So this patch allows xfs_repair to fix the quota inode metadata.

Quotacheck is still left for the kernel.  After a few more releases,
I'll propose removing the repair calls from quotacheck.

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 agoxfsprogs: be careful about what we stat in platform_check_mount
Eric Sandeen [Wed, 23 May 2018 21:30:49 +0000 (16:30 -0500)] 
xfsprogs: be careful about what we stat in platform_check_mount

After we lost ustat(2) in commit 4e7a824, we ended up with a slightly
bonkers method to determine if our target block device was mounted:
it goes through every entry returned by getmntent and stats the dir
to see if its underlying device matches ours.

Unfortunately that dir might be a hung nfs server and sadness ensues.

So just do a really simple sanity check before we try to stat the
mountpoint: does its device start with a / ?  If not, skip it.

Fixes: 4e7a824 ("libxfs/linux.c: Replace use of ustat by stat")
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_growfs: refactor geometry reporting
Darrick J. Wong [Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)] 
xfs_growfs: refactor geometry reporting

Use the new geometry pretty-printing function.

Signed-off-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_info: call xfs_db for offline filesystems
Darrick J. Wong [Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)] 
xfs_info: call xfs_db for offline filesystems

If the online filesystem geometry query doesn't work, try using xfs_db
to see if we can grab the information offline.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_info: move to xfs_spaceman
Darrick J. Wong [Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)] 
xfs_info: move to xfs_spaceman

Move xfs_info to be under spaceman so that we can remove growfs -N.

Signed-off-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_spaceman: add a superblock info command
Darrick J. Wong [Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)] 
xfs_spaceman: add a superblock info command

Add an 'info' command to pretty-print the superblock geometry.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_spaceman: print a nicer message when file path isn't on xfs
Darrick J. Wong [Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)] 
xfs_spaceman: print a nicer message when file path isn't on xfs

If the file path passed in is not something on an xfs filesystem, print
a nice message about that instead of yelling about ioctls.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_db: add a superblock info command
Darrick J. Wong [Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)] 
xfs_db: add a superblock info command

Add an 'info' command to pretty-print the superblock geometry.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agomkfs: use geometry generation / helper functions
Darrick J. Wong [Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)] 
mkfs: use geometry generation / helper functions

Since libxfs now has a function to fill out the geometry structure
and libfrog has a function to pretty-print the geometry, have mkfs
use the two helpers instead of open-coding it.

Signed-off-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 agolibfrog: refactor fs geometry printing function
Darrick J. Wong [Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)] 
libfrog: refactor fs geometry printing function

Move the fs geometry printing function to libfrog so that mkfs and others
can share.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>