]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/log
thirdparty/xfsprogs-dev.git
5 years agolibxfs: add more bounds checking to sb sanity checks
Bill O'Donnell [Fri, 5 Oct 2018 02:36:11 +0000 (21:36 -0500)] 
libxfs: add more bounds checking to sb sanity checks

Source kernel commit: 8756a5af18191a471e670cc577aea60b652fea4c

Current sb verifier doesn't check bounds on sb_fdblocks and sb_ifree.
Add sanity checks for these parameters.

Signed-off-by: Bill O'Donnell <billodo@redhat.com>
[darrick: port to refactored sb validation predicates]
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: refactor superblock verifiers
Darrick J. Wong [Fri, 5 Oct 2018 02:36:11 +0000 (21:36 -0500)] 
xfs: refactor superblock verifiers

Source kernel commit: eca383fcd63b452cf533505154135da2a1f70227

Split the superblock verifier into the common checks, the read-time
checks, and the write-time check functions.  No functional changes, but
we're setting up to add more write-only checks.

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: remove the xfs_ifork_t typedef
Christoph Hellwig [Fri, 5 Oct 2018 02:36:11 +0000 (21:36 -0500)] 
xfs: remove the xfs_ifork_t typedef

Source kernel commit: 3ba738df25239f877f6a98ce1cc925fa7e924cd3

We only have a few more callers left, so seize the opportunity and kill
it off.

Signed-off-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: simplify xfs_idata_realloc
Christoph Hellwig [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: simplify xfs_idata_realloc

Source kernel commit: 1216b58b353fbf5529454b442cebb3c8f14d93da

Streamline the code and take advantage of the fact that kmem_realloc
through krealloc will be have like a normal allocation if passing in a
NULL old pointer.

Signed-off-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 if_real_bytes
Christoph Hellwig [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: remove if_real_bytes

Source kernel commit: fcacbc3f511338842dd177e2d53d457f9741543b

The field is only used for asserts, and to track if we really need to do
realloc when growing the inode fork data.  But the krealloc function
already performs this check internally, so there is no need to keep track
of the real allocation size.

This will free space in the inode fork for keeping a sequence counter of
changes to the extent list.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: pass transaction lock while setting up agresv on cyclic metadata
Darrick J. Wong [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: pass transaction lock while setting up agresv on cyclic metadata

Source kernel commit: ebcbef3a61a6081ffe20b0b684f18ebbf23f1dfb

Pass a tranaction pointer through to all helpers that calculate the
per-AG block reservation.  Online repair will use this to reinitialize
per-ag reservations while it still holds all the AG headers locked to
the repair transaction.

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: bypass final dfops roll in trans commit path
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: bypass final dfops roll in trans commit path

Source kernel commit: b277c37f43dd387f7430a2186deda0e58c943087

Once xfs_defer_finish() has completed all deferred operations, it
checks the dirty state of the transaction and rolls it once more to
return a clean transaction for the caller. This primarily to cover
the case where repeated xfs_defer_finish() calls are made in a loop
and we need to make sure that the caller starts the next iteration
with a clean transaction. Otherwise we risk transaction reservation
overrun.

This final transaction roll is not required in the transaction
into a separate helper such that we can avoid it in the transaction
until after the last call to xfs_defer_trans_roll(). The reset is
also unnecessary in the transaction commit path because the
transaction is about to complete.

This eliminates unnecessary regrants of transactions where the
associated transaction roll can be replaced by a transaction commit.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@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: drop unnecessary xfs_defer_finish() dfops parameter
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: drop unnecessary xfs_defer_finish() dfops parameter

Source kernel commit: 9e28a242be65b8274742425ca5d146f366205a90

Every caller of xfs_defer_finish() now passes the transaction and
its associated ->t_dfops. The xfs_defer_ops parameter is therefore
no longer necessary and can be removed.

Since most xfs_defer_finish() callers also have to consider
xfs_defer_cancel() on error, update the latter to also receive the
transaction for consistency. The log recovery code contains an
outlier case that cancels a dfops directly without an available
transaction. Retain an internal wrapper to support this outlier case
for the time being.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@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 unnecessary dfops init calls in xattr code
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: remove unnecessary dfops init calls in xattr code

Source kernel commit: d5cca7eb244d276177a57e42494d479742bbba37

Each xfs_defer_init() call in the xattr code uses the internal dfops
reference. In addition, a successful xfs_defer_finish() always
returns with a reset xfs_defer_ops structure.

Given that along with the fact that every xfs_defer_init() call in
the xattr code is followed up by an xfs_defer_finish(), the former
calls are no longer necessary and can be removed.

Note that the xfs_defer_init() call in the remote value copy loop of
xfs_attr_rmtval_set() is not followed by a finish, but the dfops is
unused in this instance.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@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 all boilerplate defer init/finish code
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: remove all boilerplate defer init/finish code

Source kernel commit: c8eac49ef798a7d00240847f63902caa1388241a

At this point, the transaction subsystem completely manages deferred
items internally such that the common and boilerplate
xfs_trans_alloc() -> xfs_defer_init() -> xfs_defer_finish() ->
xfs_trans_commit() sequence can be replaced with a simple
transaction allocation and commit.

Remove all such boilerplate deferred ops code. In doing so, we
change each case over to use the dfops in the transaction and
specifically eliminate:

- The on-stack dfops and associated xfs_defer_init() call, as the
internal dfops is initialized on transaction allocation.
- xfs_bmap_finish() calls that precede a final xfs_trans_commit() of
a transaction.
- xfs_defer_cancel() calls in error handlers that precede a
transaction cancel.

The only deferred ops calls that remain are those that are
non-deterministic with respect to the final commit of the associated
transaction or are open-coded due to special handling.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@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 internal dfops in attr code
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: use internal dfops in attr code

Source kernel commit: 9c6bb0cf7ba318767107328f39aac880344ddd2e

Remove the unnecessary on-stack dfops structure and use the internal
transaction dfops instead. The lower level xattr code already
appropriately accesses ->t_dfops throughout.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@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: support embedded dfops in transaction
Brian Foster [Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)] 
xfs: support embedded dfops in transaction

Source kernel commit: e021a2e5fc520d930f949f303e7307038e258645

The dfops structure used by multi-transaction operations is
typically stored on the stack and carried around by the associated
transaction. The lifecycle of dfops does not quite match that of the
transaction, but they are tightly related in that the former depends
on the latter.

The relationship of these objects is tight enough that we can avoid
the cumbersome boilerplate code required in most cases to manage
them separately by just embedding an xfs_defer_ops in the
transaction itself. This means that a transaction allocation returns
with an initialized dfops, a transaction commit finishes pending
deferred items before the tx commit, a transaction cancel cancels
the dfops before the transaction and a transaction dup operation
transfers the current dfops state to the new transaction.

The dup operation is slightly complicated by the fact that we can no
longer just copy a dfops pointer from the old transaction to the new
transaction. This is solved through a dfops move helper that
transfers the pending items and other dfops state across the
transactions. This also requires that transaction rolling code
always refer to the transaction for the current dfops reference.

Finally, to facilitate incremental conversion to the internal dfops
and continue to support the current external dfops mode of
operation, create the new ->t_dfops_internal field with a layer of
indirection. On allocation, ->t_dfops points to the internal dfops.
This state is overridden by callers who re-init a local dfops on the
transaction. Once ->t_dfops is overridden, the external dfops
reference is maintained as the transaction rolls.

This patch adds the fundamental ability to support an internal
dfops. All codepaths that perform deferred processing continue to
override the internal dfops until they are converted over in
subsequent patches.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@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: 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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

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