]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/log
thirdparty/xfsprogs-dev.git
5 years agoxfs: use ->t_firstblock in attrfork add
Brian Foster [Fri, 5 Oct 2018 02:36:08 +0000 (21:36 -0500)] 
xfs: use ->t_firstblock in attrfork add

Source kernel commit: 825d75cd8c1b53883dd8c2fe1d8833c371b08074

Note that this codepath is a user of struct xfs_da_args. Switch it
over to ->t_firstblock in preparation to remove
xfs_da_args.firstblock.

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: remove firstblock param from xfs dir ops
Brian Foster [Fri, 5 Oct 2018 02:36:08 +0000 (21:36 -0500)] 
xfs: remove firstblock param from xfs dir ops

Source kernel commit: 381eee69f862d38bef468e91517e37fc53f60885

All callers of the xfs_dir_*() functions pass ->t_firstblock as the
firstblock parameter. Drop the parameter and access ->t_firstblock
directly.

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 firstblock field to xfs_trans
Brian Foster [Fri, 5 Oct 2018 02:35:54 +0000 (21:35 -0500)] 
xfs: add firstblock field to xfs_trans

Source kernel commit: bba59c5e4b38e160c6be25b2f4fe36ebc84f53df

A firstblock var is typically allocated and initialized along with
xfs_defer_ops structures and passed around independent from the
associated transaction. To facilitate combining the two, add an
optional ->t_firstblock field to xfs_trans that can be used in place
of an on-stack variable.

The firstblock value follows the lifetime of the transaction, so
initialize it on allocation and when a transaction rolls.

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: allow null firstblock in xfs_bmapi_write() when tp is null
Brian Foster [Thu, 4 Oct 2018 19:40:01 +0000 (14:40 -0500)] 
xfs: allow null firstblock in xfs_bmapi_write() when tp is null

Source kernel commit: 3ae2d89174e4ba581093320afb48421ca95191d2

xfs_bmapi_write() always expects a valid firstblock pointer. It
immediately dereferences the pointer to help determine how to
initialize the bma.minleft field. The remaining accesses are
related to modifying btree format forks, which is only relevant for
!COW fork callers.

The reflink code passes a NULL transaction to xfs_bmapi_write() in a
couple places that do COW fork unwritten conversion. The purpose of
the firstblock field is to track the first block allocation in the
current transaction, so technically firstblock should not be
required for these callers either.

Tweak xfs_bmapi_write() to initialize the bma correctly without
accessing the firstblock pointer if no transaction is provided in
the first place. Update the reflink callers to pass NULL instead of
otherwise unused firstblock references.

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: refactor dfops init to attach to transaction
Brian Foster [Thu, 4 Oct 2018 19:39:01 +0000 (14:39 -0500)] 
xfs: refactor dfops init to attach to transaction

Source kernel commit: bcd2c9f33559764e0d306e226a8aa88bc2e1e6fb

Most callers of xfs_defer_init() immediately attach the dfops
structure to a transaction. Add a transaction parameter to eliminate
much of this boilerplate code. This also helps self-document the
fact that many codepaths now expect a dfops pointer implicitly via
xfs_trans->t_dfops.

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: use ->t_dfops in reflink cow recover path
Brian Foster [Thu, 4 Oct 2018 19:38:01 +0000 (14:38 -0500)] 
xfs: use ->t_dfops in reflink cow recover path

Source kernel commit: d5669ed58175f85d2c13e914c5c4e2bd3647d893

Use ->t_dfops of the leftover COW reservation cleanup transaction.

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: remove unused btree cursor bc_private.a.dfops field
Brian Foster [Thu, 4 Oct 2018 19:37:01 +0000 (14:37 -0500)] 
xfs: remove unused btree cursor bc_private.a.dfops field

Source kernel commit: ed7ef8e55c6f24ae4347b5bda89e00af475ebc89

The xfs_btree_cur.bc_private.a.dfops field is only ever initialized
by the refcountbt cursor init function. The only caller of that
function with a non-NULL dfops is from deferred completion context,
which already has attached to ->t_dfops.

In addition to that, the only actual reference of a.dfops is the
cursor duplication function, which means the field is effectively
unused.

Remove the dfops field from the bc_private.a union. Any future users
can acquire the dfops from the transaction. This patch 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: remove xfs_btree_cur bmbt dfops field
Brian Foster [Thu, 4 Oct 2018 19:36:01 +0000 (14:36 -0500)] 
xfs: remove xfs_btree_cur bmbt dfops field

Source kernel commit: 42b394a92562b464e9ef81954ca93930c037a51b

All assignments of xfs_btree_cur.bc_private.b.dfops originate from
->t_dfops. Replace accesses of the former with the latter and remove
the unnecessary field. This patch 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: remove dfops param from internal bmap extent helpers
Brian Foster [Thu, 4 Oct 2018 19:35:01 +0000 (14:35 -0500)] 
xfs: remove dfops param from internal bmap extent helpers

Source kernel commit: 81ba8f3e947c3c53beb535c7f29fe402429cae37

All callers of the various bmap extent helpers now use ->t_dfops.
Remove the unnecessary dfops params and access ->t_dfops directly.
This patch 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: use ->t_dfops for collapse/insert range operations
Brian Foster [Thu, 4 Oct 2018 19:34:01 +0000 (14:34 -0500)] 
xfs: use ->t_dfops for collapse/insert range operations

Source kernel commit: f4a9cf97faf4adb27e4e105beda420bb5253c502

Use ->t_dfops for the collapse and insert range transactions. These
are the only callers of the respective bmap helpers, so replace the
unnecessary dfops parameters with direct accesses to ->t_dfops.

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: remove struct xfs_bmalloca dfops field
Brian Foster [Thu, 4 Oct 2018 19:33:01 +0000 (14:33 -0500)] 
xfs: remove struct xfs_bmalloca dfops field

Source kernel commit: 3e3673e3029c1dedf75a1688a5203d9550adf490

Now that bma.dfops is only assigned from ->t_dfops, replace all
accesses to the former with the latter and remove the unnecessary
field. This patch 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: remove xfs_bmapi_remap() dfops param
Brian Foster [Thu, 4 Oct 2018 19:32:01 +0000 (14:32 -0500)] 
xfs: remove xfs_bmapi_remap() dfops param

Source kernel commit: ff3edf255da7a1ceb0fb2cb7f195fc27edd0091d

All xfs_bmapi_remap() callers already use ->t_dfops. Note that
deferred completion context unconditionally sets ->t_dfops if it
hasn't already been set by the caller. Remove the unnecessary
parameter and access ->t_dfops directly.

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: remove xfs_bunmapi() dfops param
Brian Foster [Thu, 4 Oct 2018 19:31:01 +0000 (14:31 -0500)] 
xfs: remove xfs_bunmapi() dfops param

Source kernel commit: ccd9d91148780a5e979ac00bce67c2155fb6378f

Now that all xfs_bunmapi() callers use ->t_dfops, remove the
unnecessary parameter and access ->t_dfops directly. This patch 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: remove xfs_bmapi_write() dfops param
Brian Foster [Thu, 4 Oct 2018 19:30:01 +0000 (14:30 -0500)] 
xfs: remove xfs_bmapi_write() dfops param

Source kernel commit: 6e702a5dcbe1d38cf479931dd2e2a3da884143f0

Now that all callers use ->t_dfops, the xfs_bmapi_write() dfops
parameter is no longer necessary. Remove it and access ->t_dfops
directly. This patch 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: replace xfs_da_args->dfops accesses with ->t_dfops and remove
Brian Foster [Thu, 4 Oct 2018 19:29:01 +0000 (14:29 -0500)] 
xfs: replace xfs_da_args->dfops accesses with ->t_dfops and remove

Source kernel commit: 32a9b7c65cfc7d9283055fc9d61e6393ee2aa984

Now that xfs_da_args->dfops is always assigned from a ->t_dfops
pointer (or one that is immediately attached), replace all
downstream accesses of the former with the latter and remove the
field from struct xfs_da_args.

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: use ->t_dfops in extent split tx and remove param
Brian Foster [Thu, 4 Oct 2018 19:28:01 +0000 (14:28 -0500)] 
xfs: use ->t_dfops in extent split tx and remove param

Source kernel commit: d76e6ce8ed6943941c0c964d8ae43fdaefdcbb5a

Attach the local dfops to ->t_dfops of the extent split transaction.
Since this is the only caller of xfs_bmap_split_extent_at(), remove
the dfops parameter as well.

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: remove dfops param in attr fork add path
Brian Foster [Thu, 4 Oct 2018 19:27:01 +0000 (14:27 -0500)] 
xfs: remove dfops param in attr fork add path

Source kernel commit: 0bd6207f836446f9d472f342a0ba3c21fe5e986f

Now that the attribute fork add tx carries dfops along with the
transaction, it is unnecessary to pass it down the stack. Remove the
dfops parameter and access ->t_dfops directly where necessary. This
patch 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: use ->t_dfops for attr set/remove operations
Brian Foster [Thu, 4 Oct 2018 19:26:01 +0000 (14:26 -0500)] 
xfs: use ->t_dfops for attr set/remove operations

Source kernel commit: 40d03ac6aa2bebe05190462734690472310167e4

Attach the local dfops to the transaction allocated for xattr add
and remove operations. Add an earlier initialization in
xfs_attr_remove() to ensure the structure is valid if it remains
unused at transaction commit time.

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: remove dfops param from high level dirname calls
Brian Foster [Thu, 4 Oct 2018 19:25:01 +0000 (14:25 -0500)] 
xfs: remove dfops param from high level dirname calls

Source kernel commit: c9cfdb381172174ade2445e7b468f1be550b1a44

All callers of the directory create, rename and remove interfaces
already associate the dfops with the transaction. Drop the dfops
parameters in these calls in preparation for further cleanups in the
layers below. This patch 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: remove dfops parameter from ifree call stack
Brian Foster [Thu, 4 Oct 2018 19:24:01 +0000 (14:24 -0500)] 
xfs: remove dfops parameter from ifree call stack

Source kernel commit: 0e0417f3e54668cec9f677850130e6fbb64edcf2

The inode free callchain starting in xfs_inactive_ifree() already
associates its dfops with the transaction. It still passes the dfops
on the stack down through xfs_difree_inobt(), however.

Clean up the call stack and reference dfops directly from the
transaction. This patch 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: rename xfs_trans ->t_agfl_dfops to ->t_dfops
Brian Foster [Thu, 4 Oct 2018 19:23:01 +0000 (14:23 -0500)] 
xfs: rename xfs_trans ->t_agfl_dfops to ->t_dfops

Source kernel commit: 6aa6718439ac6907b3c34cbe7ac2c71408f84f6e

The ->t_agfl_dfops field is currently used to defer agfl block frees
from associated transaction contexts. While all known problematic
contexts have already been updated to use ->t_agfl_dfops, the
broader goal is defer agfl frees from all callers that already use a
deferred operations structure. Further, the transaction field
facilitates a good amount of code clean up where the transaction and
dfops have historically been passed down through the stack
separately.

Rename the field to something more generic to prepare to use it as
such throughout XFS. This patch 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: remove the now unused XFS_BMAPI_IGSTATE flag
Christoph Hellwig [Thu, 4 Oct 2018 19:22:01 +0000 (14:22 -0500)] 
xfs: remove the now unused XFS_BMAPI_IGSTATE flag

Source kernel commit: c3a2f9fff1bbe3cfc2070b2e9f1f0ad0d5ccda91

Signed-off-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 agolibxfs: track transaction block reservation usage like the kernel
Darrick J. Wong [Thu, 4 Oct 2018 19:21:01 +0000 (14:21 -0500)] 
libxfs: track transaction block reservation usage like the kernel

Currently, block reservations in userspace transactions are not carried
over across transaction rolls.  This will lead to ENOSPC failures inside
libxfs code which checks for reservation overruns in an upcoming patch
that borrows the bmbt repair code from the kernel because it makes
extensive use of transaction rolling.

Therefore, port t_blk_res_used from the kernel so that block
reservations work the same way in userspace.

[sandeen: tweaks to backport before libxfs updates]
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 agolibxfs: fix xfs_trans_alloc reservation abuse
Darrick J. Wong [Thu, 4 Oct 2018 19:19:01 +0000 (14:19 -0500)] 
libxfs: fix xfs_trans_alloc reservation abuse

Various xfsprogs tools have been abusing the transaction reservation
system by allocating the transaction with zero reservation.  This has
always worked in the past because userspace transactions do not require
reservations.  However, once we merge deferred ops into the transaction
structure, we will need to use a permanent reservation type to set up
any transaction that can roll.  tr_itruncate has all we need, so use
that as the reservation dummy.

[sandeen: tweaks to backport before libxfs updates]
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 block reservation in mk_rsumino
Darrick J. Wong [Thu, 4 Oct 2018 19:18:01 +0000 (14:18 -0500)] 
xfs_repair: fix block reservation in mk_rsumino

The functions mk_rsumino and rtinit both allocate transactions to create
the realtime summary inode.  In order to allocate and map blocks to the
rtsummary file, these transactions require a block reservation.
However, despite the comments in mk_rsumino about lifting the code from
mkfs, it doesn't actually copy the same reservation calculation that
mkfs uses in rtinit().  Practically speaking this has no effect since
userspace doesn't care about transaction block reservations, but fix
this logic bomb anyway.

[sandeen: tweaks to backport before libxfs updates]
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 agolibxfs: fix libxfs_trans_alloc callsite problems
Darrick J. Wong [Thu, 4 Oct 2018 19:17:01 +0000 (14:17 -0500)] 
libxfs: fix libxfs_trans_alloc callsite problems

Fix some incorrect libxfs_trans_alloc callers to check return values
correctly.

[sandeen: tweaks to backport before libxfs updates]
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 agolibxfs: port kernel transaction code
Darrick J. Wong [Thu, 4 Oct 2018 19:16:01 +0000 (14:16 -0500)] 
libxfs: port kernel transaction code

Restructure the userspace transaction code to resemble the kernel code
more closely.  This will make deferred operations behave the same (with
respect to transaction lifetimes) as the kernel.

[sandeen: tweaks to backport before libxfs updates]
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.18.0 v4.18.0
Eric Sandeen [Fri, 24 Aug 2018 19:47:25 +0000 (14:47 -0500)] 
xfsprogs: Release v4.18.0

Update all the necessary files for a 4.18.0 release.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agolibxfs: fix spdx tag in xfs_cksum.h
Darrick J. Wong [Fri, 24 Aug 2018 19:45:22 +0000 (14:45 -0500)] 
libxfs: fix spdx tag in xfs_cksum.h

Change the SPDX tag style to match the kernel.

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.18.0-rc1 v4.18.0-rc1
Eric Sandeen [Wed, 1 Aug 2018 22:06:45 +0000 (17:06 -0500)] 
xfsprogs: Release v4.18.0-rc1

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

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agomisc: remove COPYING from doc/ Makefile
Eric Sandeen [Wed, 1 Aug 2018 22:06:45 +0000 (17:06 -0500)] 
misc: remove COPYING from doc/ Makefile

COPYING is gone now, so make doc-install breaks.

Fixes: 959ef98 ("xfsprogs: convert to SPDX license tags")
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 agomkfs: avoid divide-by-zero when hardware reports optimal i/o size as 0
Jeff Mahoney [Wed, 1 Aug 2018 22:06:45 +0000 (17:06 -0500)] 
mkfs: avoid divide-by-zero when hardware reports optimal i/o size as 0

Commit 051b4e37f5e (mkfs: factor AG alignment) factored out the
AG alignment code into a separate function.  It got rid of
redundant checks for dswidth != 0 since calc_stripe_factors was
supposed to guarantee that if dsunit is non-zero dswidth will be
as well.  Unfortunately, there's hardware out there that reports its
optimal i/o size as larger than the maximum i/o size, which the kernel
treats as broken and zeros out the optimal i/o size.

To resolve this we can check the topology before consuming it, and
ignore the bad stripe geometry.

Fixes: 051b4e37f5e (mkfs: factor AG alignment)
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
[sandeen: remove guessing heuristic, just warn and ignore bad data.]
Reviewed-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: add debian initramfs hook to package
Darrick J. Wong [Wed, 1 Aug 2018 22:06:45 +0000 (17:06 -0500)] 
xfs: add debian initramfs hook to package

In Debian bug 904086, the reporter complained that xfs_repair wasn't
present in the initramfs, which prevented him from using shutdown -F to
force a filesystem fsck after a reboot.  Add a hook to put the xfs
utilities in the initramfs if xfs is the root filesystem.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agomisc: clean up MIN/MAX in the utilities
Darrick J. Wong [Wed, 1 Aug 2018 22:06:45 +0000 (17:06 -0500)] 
misc: clean up MIN/MAX in the utilities

Get rid of the MIN/MAX macros and just use the native min/max macros
directly in the XFS code, just like we did for libxfs.

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 agomisc: use xfs_agfl_walk where appropriate
Darrick J. Wong [Wed, 1 Aug 2018 22:06:45 +0000 (17:06 -0500)] 
misc: use xfs_agfl_walk where appropriate

Use the xfs_agfl_walk function to iterate every block in the AGFL,
instead of open-coding it db and repair.

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: clear_dinode should simply clear, not check contents
Eric Sandeen [Wed, 1 Aug 2018 22:06:45 +0000 (17:06 -0500)] 
xfs_repair: clear_dinode should simply clear, not check contents

Today clear_inode performs 2 separate tasks - it clears a disk inode
when the calling code detects an inconsistency, and it also validates
allocated-but-free inodes.  This leads to duplicated checks in the
former case, and requires comprehensive validation for the latter case.

Now that we're using xfs_dinode_verify to validate free inodes, there's
no reason to repeat all the checks inside clear_inode.  Drop them all and
simply clear it when told to do so.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-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 agoxfs_repair: notify user if free inodes contain errors
Eric Sandeen [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_repair: notify user if free inodes contain errors

xfs_repair checks allocated but unused (free) inodes in on-disk clusters,
and up until now silently repairs any errors, and as a result does not
alter exit status if errors are found.

The in-kernel verifiers will be noisy about these errors and instruct
the user to run repair, so it's best if repair is explicit about any
fixes it makes.

This shamelessly re-uses xfs_dinode_verify for this purpose.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-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 agoxfs_quota: don't stop the directory tree walk when DEPTH is hit
Kazuya Mio [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_quota: don't stop the directory tree walk when DEPTH is hit

To set/check/clear a project quota, xfs_quota performs a pre-order tree
traversal by using nftw(3).  The documentation states that the -d option
can be used to skip subtrees below a certain level in the directory
hierarchy.  Unfortunately, {check,setup,clear}_project returns -1 when
DEPTH is hit, which stops the directory tree walk immediately.  We only
wanted to skip the subtree, so return 0 instead.

Signed-off-by: Kazuya Mio <k-mio@sx.jp.nec.com>
Reviewed-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 agoxfs_io: Document shutdown -f
Carlos Maiolino [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_io: Document shutdown -f

Add help and manpage information for xfs_io shutdown -f

[sandeen: further text editing]

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfsprogs: remove unused macros
Eric Sandeen [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfsprogs: remove unused macros

A lot of dead macros are lying around xfsprogs; some are just
ancient cruft while others are the result of shifting libxfs
interfaces, but we can remove them.

(I've left a few unused macros in place where they exist with
other macros for symmetry or completeness.)

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_repair: use libxfs extsize/cowextsize validation helpers
Darrick J. Wong [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_repair: use libxfs extsize/cowextsize validation helpers

Now that we've ported the extent size hint verifiers to libxfs, call
them from xfs_repair instead of open-coding the checks.  Tweak the
repair message slightly to reflect the fact that we zero the field and
clear the inode flag if the hint is garbage or is inconsistent with the
inode flags.

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_io: wire up repair ioctl stuff
Darrick J. Wong [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_io: wire up repair ioctl stuff

Wire up the repair ioctl (which is really the scrub ioctl with special
flags) and the force-repair error injection point.

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_scrub: only retry non-permanent repair failures
Darrick J. Wong [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_scrub: only retry non-permanent repair failures

If a repair fails, we want to retry the repair if the error was a
transient one, such as ENOMEM.  For "permanent" ones (shutdown fs,
repair not supported by kernel, readonly fs) there's no point to
retrying them so just error out immediately.

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_scrub: rename NOFIX_COMPLAIN to be less confusing
Darrick J. Wong [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_scrub: rename NOFIX_COMPLAIN to be less confusing

Rename NOFIX_COMPLAIN to COMPLAIN_IF_UNFIXED so that the symbolic name
is less confusing as to what the flag is supposed to mean.

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_scrub: don't error out if an optimize-only repair isn't supported
Darrick J. Wong [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_scrub: don't error out if an optimize-only repair isn't supported

If the kernel told us a metadata object could be optimized, we ask it to
do the optimization and it spits back that it doesn't support
optimizing, don't record this as an error since the fs is still
consistent.

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_scrub: allow developers to force repairs
Darrick J. Wong [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_scrub: allow developers to force repairs

Now that we have an error injection knob in the kernel to simulate
corruptions, enable it in xfs_scrub so that developers can test all
the repair capabilities.

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_scrub: schedule and manage optimizations/repairs to the filesystem
Darrick J. Wong [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_scrub: schedule and manage optimizations/repairs to the filesystem

Teach xfs_scrub to remember scrub requests that failed (or indicated
that optimization is a possibility) as action items.  Depending on the
circumstances, certain items are acted upon immediately (e.g. metadata
that needs to be healthy in order to finish the scan, or files that are
already open) or deferred until later.  Expand the repair phase to
deal with the deferred actions.

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_scrub: destroy workqueues when erroring out
Darrick J. Wong [Wed, 1 Aug 2018 22:06:44 +0000 (17:06 -0500)] 
xfs_scrub: destroy workqueues when erroring out

Fix a couple of code paths that forgot to tear down a workqueue when
erroring out, because if we don't the wq threads keep running even after
we've freed the wq memory.

Found by fuzzing core.nlinkv2=0 in xfs/377, but only because the fs will
shut down when it hits an error destroying the incore (corrupt) inode
after the scrub.

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: move crc32c code out of libxfs
Darrick J. Wong [Wed, 1 Aug 2018 22:06:35 +0000 (17:06 -0500)] 
libfrog: move crc32c code out of libxfs

crc32c code isn't part of the kernel libxfs, nor should it be part of
xfsprogs libxfs.  Put it in libfrog since it's runtime support anyway.

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 agolibxfs: remove crc32 functions
Darrick J. Wong [Wed, 1 Aug 2018 22:06:35 +0000 (17:06 -0500)] 
libxfs: remove crc32 functions

XFS uses crc32c, not crc32.  Remove the unnecessary crc32 code, which
decreases binary size by the 8K crc32 table.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoMerge branch 'libxfs-4.18-sync' into for-next
Eric Sandeen [Fri, 27 Jul 2018 22:10:26 +0000 (17:10 -0500)] 
Merge branch 'libxfs-4.18-sync' into for-next

5 years agoxfs: properly handle free inodes in extent hint validators libxfs-4.18-sync
Eric Sandeen [Fri, 27 Jul 2018 22:03:50 +0000 (17:03 -0500)] 
xfs: properly handle free inodes in extent hint validators

Source kernel commit: d4a34e16555708bab5b67e679a95f055d8ef9882

When inodes are freed in xfs_ifree(), di_flags is cleared (so extent size
hints are removed) but the actual extent size fields are left intact.
This causes the extent hint validators to fail on freed inodes which once
had extent size hints.

This can be observed (for example) by running xfs/229 twice on a
non-crc xfs filesystem, or presumably on V5 with ikeep.

Fixes: 7d71a67 ("xfs: verify extent size hint is valid in inode verifier")
Fixes: 02a0fda ("xfs: verify COW extent size hint is valid in inode verifier")
Signed-off-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>
5 years agoxfs: Initialize variables in xfs_alloc_get_rec before using them
Carlos Maiolino [Fri, 27 Jul 2018 22:03:33 +0000 (17:03 -0500)] 
xfs: Initialize variables in xfs_alloc_get_rec before using them

Source kernel commit: 9991274fddb9fd4413cb166763cf7368f5086419

Make sure we initialize *bno and *len, before jumping to out_bad_rec
label, and risk calling xfs_warn() with uninitialized variables.

Coverity: 100898
Coverity: 1437081
Coverity: 1437129
Coverity: 1437191
Coverity: 1437201
Coverity: 1437212
Coverity: 1437341
Signed-off-by: Carlos Maiolino <cmaiolino@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>
5 years agoGet rid of XFS_BUF_SET_COUNT() macro
Carlos Maiolino [Tue, 24 Jul 2018 04:16:38 +0000 (23:16 -0500)] 
Get rid of XFS_BUF_SET_COUNT() macro

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoGet rid of XFS_BUF_COUNT() macro
Carlos Maiolino [Tue, 24 Jul 2018 04:16:36 +0000 (23:16 -0500)] 
Get rid of XFS_BUF_COUNT() macro

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoGet rid of XFS_BUF_TARGET() macro
Carlos Maiolino [Tue, 24 Jul 2018 04:16:35 +0000 (23:16 -0500)] 
Get rid of XFS_BUF_TARGET() macro

This macro is unused

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoGet rid of XFS_BUF_PTR() macro
Carlos Maiolino [Tue, 24 Jul 2018 04:16:34 +0000 (23:16 -0500)] 
Get rid of XFS_BUF_PTR() macro

[sandeen: I accept the explicit (char *) casting for clarity,
 but removed a few that weren't needed.]

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfsprogs: convert to SPDX license tags
Dave Chinner [Tue, 24 Jul 2018 04:16:32 +0000 (23:16 -0500)] 
xfsprogs: convert to SPDX license tags

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. Makefiles and various scripts
and build files were modified by hand. Files missing license
statements were tagged as GPLv2.0, the rest were detected
and modified by the following command:

for f in `git grep -l "GNU General" |grep [ch]$` ; 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 { }
$

[sandeen: drop libxfs bits inherited from kernel]

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
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>