]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/log
thirdparty/xfsprogs-dev.git
5 years agoxfs: pack holes in xfs_defer_ops and xfs_trans
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: pack holes in xfs_defer_ops and xfs_trans

Source kernel commit: 44fd294681de73990da656294e3dacaa7878f577

Both structures have holes due to member alignment. Move dop_low to
the end of xfs_defer ops to sanitize the cache line alignment and
move t_flags to save 8 bytes in xfs_trans.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bill O'Donnell <billodo@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: reset dfops to initial state after finish
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: reset dfops to initial state after finish

Source kernel commit: 509308b413c9e4e3140b4bc524522255d126787e

xfs_defer_init() is currently used in two particular situations. The
first and most obvious case is raw initialization of an
xfs_defer_ops struct. The other case is partial reinit of
xfs_defer_ops on reuse due to iteration.

Most instances of the first case will be replaced by a single init
of a dfops embedded in the transaction. Init calls are still
technically required for the second case because the dfops may have
low space mode enabled or have joined items that need to be reset
before the dfops should be reused.

Since the current dfops usage expects either a final transaction
be reused, we can shift some of the init logic into
xfs_defer_finish() such that the latter returns with a reinitialized
dfops. This eliminates the second dependency noted above such that a
dfops is immediately ready for reuse after an xfs_defer_finish()
without the need to change any calling code.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: remove unused deferred ops committed field
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: remove unused deferred ops committed field

Source kernel commit: 83200bfac6082a46cc962366478d050052e50450

dop_committed is set when deferred item processing rolls the
transaction at least once, but is only ever accessed in tracepoints.
The transaction roll/commit events are already available via
independent tracepoints, so remove the otherwise unused field.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bill O'Donnell <billodo@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: make deferred processing safe for embedded dfops
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: make deferred processing safe for embedded dfops

Source kernel commit: 03f4e4b26cd5f6eed728f82d90039a19d1b51ce3

xfs_defer_finish() has a couple quirks that are not safe with
respect to the upcoming internal dfops functionality. First,
xfs_defer_finish() attaches the passed in dfops structure to
->t_dfops and caches and restores the original value. Second, it
continues to use the initial dfops reference before and after the
transaction roll.

These behaviors assume that dop is an independent memory allocation
from the transaction itself, which may not always be true once
transactions begin to use an embedded dfops structure. In the latter
model, dfops processing creates a new xfs_defer_ops structure with
each transaction and the associated state is migrated across to the
new transaction.

Fix up xfs_defer_finish() to handle the possibility of the current
dfops changing after a transaction roll. Since ->t_dfops is used
unconditionally in this path, it is no longer necessary to
attach/restore ->t_dfops and pass it explicitly down to
xfs_defer_trans_roll(). Update dop in the latter function and the
caller to ensure that it always refers to the current dfops
structure.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bill O'Donnell <billodo@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 transaction leak on remote attr set/remove failure
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: fix transaction leak on remote attr set/remove failure

Source kernel commit: dcbd44f79986e55691600b969c14db004d741883

The xattr remote value set/remove handlers both clear args.trans in
the error path without having cancelled the transaction. This leaks
the transaction, causes warnings around returning to userspace with
locks held and leads to system lockups or other general problems.

The higher level xfs_attr_[set|remove]() functions already detect
and cancel args.trans when set in the error path. Drop the NULL
assignments from the rmtval handlers and allow the callers to clean
up the transaction correctly.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bill O'Donnell <billodo@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: force summary counter recalc at next mount
Darrick J. Wong [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: force summary counter recalc at next mount

Source kernel commit: f467cad95f5e3814fda408dea76eb962ab19685d

Use the "bad summary count" mount flag from the previous patch to skip
writing the unmount record to force log recovery at the next mount,
which will recalculate the summary counters for us.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: refactor unmount record write
Darrick J. Wong [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: refactor unmount record write

Source kernel commit: 53235f22151ea7229e1251e46e68098bcf74922d

Refactor the writing of the unmount record into a separate helper.  No
functionality changes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: detect and fix bad summary counts at mount
Darrick J. Wong [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: detect and fix bad summary counts at mount

Source kernel commit: 2e9e6481e2a78de3a85083beccfbf6eda2689922

Filippo Giunchedi complained that xfs doesn't even perform basic sanity
checks of the fs summary counters at mount time.  Therefore, recalculate
the summary counters from the AGFs after log recovery if the counts were
bad (or we had to recover the fs).  Enhance the recalculation routine to
fail the mount entirely if the new values are also obviously incorrect.

We use a mount state flag to record the "bad summary count" state so
that the (subsequent) online fsck patches can detect subtlely incorrect
counts and set the flag; clear it userspace asks for a repair; or force
a recalculation at the next mount if nobody fixes it by unmount time.

Reported-by: Filippo Giunchedi <fgiunchedi@wikimedia.org>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: clean up xfs_btree_del_cursor callers
Darrick J. Wong [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: clean up xfs_btree_del_cursor callers

Source kernel commit: ef97ef26d263fb65f0c7446a10cf93201dc0388c

Less trivial cleanups of the error argument to xfs_btree_del_cursor;
these require some minor code refactoring.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: trivial xfs_btree_del_cursor cleanups
Darrick J. Wong [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: trivial xfs_btree_del_cursor cleanups

Source kernel commit: 0b04b6b875b32f2b32263ba46d54d001e05724f9

The error argument to xfs_btree_del_cursor already understands the
"nonzero for error" semantics, so remove pointless error testing in the
callers and pass it directly.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: return from _defer_finish with a clean transaction
Darrick J. Wong [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: return from _defer_finish with a clean transaction

Source kernel commit: 81b549aa626b650bbf00423c084c0fd5581169b9

The following assertion was seen on generic/051:

XFS: Assertion failed: tp->t_firstblock == NULLFSBLOCK, file: fs/xfs/libxfs5
------------[ cut here ]------------
kernel BUG at fs/xfs/xfs_message.c:102!
invalid opcode: 0000 [#1] SMP PTI
CPU: 2 PID: 20757 Comm: fsstress Not tainted 4.18.0-rc4+ #3969
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.1-1 04/01/4
RIP: 0010:assfail+0x23/0x30
Code: c3 66 0f 1f 44 00 00 48 89 f1 41 89 d0 48 c7 c6 88 e0 8c 82 48 89 fa
RSP: 0018:ffff88012dc43c08 EFLAGS: 00010202
RAX: 0000000000000000 RBX: ffff88012dc43ca0 RCX: 0000000000000000
RDX: 00000000ffffffc0 RSI: 000000000000000a RDI: ffffffff828480eb
RBP: ffff88012aa92758 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: f000000000000000 R12: 0000000000000000
R13: ffff88012dc43d48 R14: ffff88013092e7e8 R15: 0000000000000014
FS:  00007f8d689b8e80(0000) GS:ffff88013fd00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f8d689c7000 CR3: 000000012ba6a000 CR4: 00000000000006e0
Call Trace:
xfs_defer_init+0xff/0x160
xfs_reflink_remap_extent+0x31b/0xa00
xfs_reflink_remap_blocks+0xec/0x4a0
xfs_reflink_remap_range+0x3a1/0x650
xfs_file_dedupe_range+0x39/0x50
vfs_dedupe_file_range+0x218/0x260
do_vfs_ioctl+0x262/0x6a0
? __se_sys_newfstat+0x3c/0x60
ksys_ioctl+0x35/0x60
__x64_sys_ioctl+0x11/0x20
do_syscall_64+0x4b/0x190
entry_SYSCALL_64_after_hwframe+0x49/0xbe

The root cause of the assertion failure is that xfs_defer_finish doesn't
roll the transaction after processing all the deferred items.  Therefore
it returns a dirty transaction to the caller, which leaves the caller at
risk of exceeding the transaction reservation if it logs more items.

Brian Foster's patchset to move the defer_ops firstblock into the
transaction requires t_firstblock == NULLFSBLOCK upon defer_ops
initialization, which is how this was noticed at all.

Reported-by: Christoph Hellwig <hch@lst.de>
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: check leaf attribute block freemap in verifier
Darrick J. Wong [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: check leaf attribute block freemap in verifier

Source kernel commit: 65cfcc3897d7715a878b9f59736e7527ca27514f

Check the leaf attribute freemap when we're verifying the block.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.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 agolibxfs: Fix a couple of sparse complaintis
Carlos Maiolino [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
libxfs: Fix a couple of sparse complaintis

Source kernel commit: 5089eafffba2ed444789e5d25c7c0dfd62595713

No significant changes, just silence a couple of sparse errors.

Using cpu_to_be32(NULLAGINO), the NULLAGINO constant will be encoded in
BE as a constant, avoiding a BE -> CPU conversion every iteraction of
the loop, if be32_to_cpu(agi->agi_unlinked[i]) was used instead.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@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: use swap macro in xfs_dir2_leafn_rebalance
Gustavo A. R. Silva [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: use swap macro in xfs_dir2_leafn_rebalance

Source kernel commit: e4e542a683c16945533d700339a0aec261d39f34

Make use of the swap macro and remove unnecessary variable *tmp*. This
makes the code easier to read and maintain. Also, slightly refactor some
code.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.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_attr_leaf: use swap macro in xfs_attr3_leaf_rebalance
Gustavo A. R. Silva [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs_attr_leaf: use swap macro in xfs_attr3_leaf_rebalance

Source kernel commit: 1d5bebbafc73d82e5af003cdd2bf8ee5741cd1df

Make use of the swap macro and remove some unnecessary variables.
This makes the code easier to read and maintain. Also, reduces the
stack usage.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.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 assume a left rmap when allocating a new rmap
Darrick J. Wong [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: don't assume a left rmap when allocating a new rmap

Source kernel commit: fa248de98a6beb9ceaec5059041d65f87ac438b4

The original rmap code assumed that there would always be at least one
rmap in the rmapbt (the AG sb/agf/agi) and so errored out if it didn't
find one.  This assumption isn't true for the rmapbt repair function
(and it won't be true for realtime rmap either), so remove the check and
just deal with the situation.

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

Source kernel commit: 5fdd97944ee5ae0fcdd88227224d0c2c87aa6db9

All but one caller of xfs_defer_init() passes in the ->t_firstblock
of the associated transaction. The one outlier is
xlog_recover_process_intents(), which simply passes a dummy value
because a valid pointer is required. This firstblock variable can
simply be removed.

At this point we could remove the xfs_defer_init() firstblock
parameter and initialize ->t_firstblock directly. Even that is not
necessary, however, because ->t_firstblock is automatically
reinitialized in the new transaction on a transaction roll. Since
xfs_defer_init() should never occur more than once on a particular
transaction (since the corresponding finish will roll it), replace
the reinit from xfs_defer_init() with an assert that verifies the
transaction has a NULLFSBLOCK 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: replace no-op firstblock init with ->t_firstblock
Brian Foster [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: replace no-op firstblock init with ->t_firstblock

Source kernel commit: fb91f4b5d6187996796f4a9989decdf6ead12851

xfs_refcount_recover_cow_leftovers() has no need for a firstblock
variable and so passes an unrelated xfs_fsblock_t to
xfs_defer_init() to avoid declaring one. Replace this no-op
initialization with ->t_firstblock. This will be optimized away by
the removal of the xfs_defer_init() firstblock param.

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_alloc_arg firstblock field
Brian Foster [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: remove xfs_alloc_arg firstblock field

Source kernel commit: 64396ff2c25b2cd8156948a64ae0da5ff962e3f2

The xfs_alloc_arg.firstblock field is used to control the starting
agno for an allocation. The structure already carries a pointer to
the transaction, which carries the current firstblock value.

Remove the field and access ->t_firstblock directly in the
allocation code.

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 private firstblock field
Brian Foster [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: remove xfs_btree_cur private firstblock field

Source kernel commit: cf612de732cb6ef626019ca085406d183f0a055a

The bmbt cursor private structure has a firstblock field that is
used to maintain locking order on bmbt allocations. The field holds
an actual firstblock value (as opposed to a pointer), so it is
initialized on cursor creation, updated on allocation and then the
value is transferred back to the source before the cursor is
destroyed.

This value is always transferred from and back to the ->t_firstblock
field. Since xfs_btree_cur already carries a reference to the
transaction, we can remove this field from xfs_btree_cur and the
associated copying. The bmbt allocations will update the value in
the transaction 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 bmap format helpers firstblock params
Brian Foster [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: remove bmap format helpers firstblock params

Source kernel commit: 280253d213fb735b565532be2836f94cf574260d

The bmap format helpers receive firstblock via ->t_firstblock. Drop
the param and access it 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 bmap extent add helper firstblock params
Brian Foster [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: remove bmap extent add helper firstblock params

Source kernel commit: 92f9da30f57bdb653ee46f26df2d51484b27c7f0

The add extent helpers all receive firstblock via ->t_firstblock.
Drop the parameter and access it 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_bmalloca firstblock field
Brian Foster [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: remove xfs_bmalloca firstblock field

Source kernel commit: 94c07b4dba01481740ce893d05a71578150b8f0b

The xfs_bmalloca.firstblock field carries the firstblock value from
the transaction into the bmap infrastructure. It's initialized in
one place from ->t_firstblock, so drop the field and access
->t_firstblock directly throughout the bmap code.

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_firstblock in bmap extent split
Brian Foster [Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)] 
xfs: use ->t_firstblock in bmap extent split

Source kernel commit: 4b77a088d781b53d263c37e75222439297b410e5

Also remove the unnecessary xfs_bmap_split_extent_at() parameter.

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

Source kernel commit: 333f950c89a17018f812eae13daaa2a404c413c1

The only callers pass ->t_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 xfs_bunmapi() firstblock param
Brian Foster [Fri, 5 Oct 2018 02:36:08 +0000 (21:36 -0500)] 
xfs: remove xfs_bunmapi() firstblock param

Source kernel commit: 2af528425342dc8f696b28693c5e61587cd72b43

All callers pass ->t_firstblock from the current 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 xfs_bmapi_write() firstblock param
Brian Foster [Fri, 5 Oct 2018 02:36:08 +0000 (21:36 -0500)] 
xfs: remove xfs_bmapi_write() firstblock param

Source kernel commit: a7beabeae221db2118a51f6948239d63b84499ca

All callers pass ->t_firstblock from the current 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: use ->t_firstblock in xfs_bmapi_remap()
Brian Foster [Fri, 5 Oct 2018 02:36:08 +0000 (21:36 -0500)] 
xfs: use ->t_firstblock in xfs_bmapi_remap()

Source kernel commit: 580c4ff9484ac3395ad48b1118b269a6d68c9318

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_firstblock for all xfs_bunmapi() callers
Brian Foster [Fri, 5 Oct 2018 02:36:08 +0000 (21:36 -0500)] 
xfs: use ->t_firstblock for all xfs_bunmapi() callers

Source kernel commit: 372837978d90d1c563315192196735c09623a5d6

Convert all xfs_bunmapi() callers to ->t_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: use ->t_firstblock in xattr ops
Brian Foster [Fri, 5 Oct 2018 02:36:08 +0000 (21:36 -0500)] 
xfs: use ->t_firstblock in xattr ops

Source kernel commit: 766139032f95bb41031f6de9c2ee0538bd035229

Similar to the dirops code, the xattr code uses an on-stack
firstblock variable for the various operations. This code rolls the
underlying transaction in various places, however, which means we
cannot simply replace the local firstblock vars with ->t_firstblock.
Doing so (without further changes) would invalidate the memory
pointed to by xfs_da_args.firstblock as soon as the first
transaction rolls.

To avoid this problem, remove xfs_da_args.firstblock and replace all
such accesses with ->t_firstblock at the same time. This ensures
that accesses to the current firstblock always occur through the
current transaction rather than a potentially invalid xfs_da_args
pointer.

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_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>