]> www.infradead.org Git - users/hch/xfsprogs.git/log
users/hch/xfsprogs.git
5 years agoxfs: more lockdep whackamole with kmem_alloc* 5.8-sync
Darrick J. Wong [Fri, 10 Jul 2020 06:34:16 +0000 (08:34 +0200)]
xfs: more lockdep whackamole with kmem_alloc*

Source kernel commit: 6dcde60efd946e38fac8d276a6ca47492103e856

Dave Airlie reported the following lockdep complaint:

>  ======================================================
>  WARNING: possible circular locking dependency detected
>  5.7.0-0.rc5.20200515git1ae7efb38854.1.fc33.x86_64 #1 Not tainted
>  ------------------------------------------------------
>  kswapd0/159 is trying to acquire lock:
>  ffff9b38d01a4470 (&xfs_nondir_ilock_class){++++}-{3:3},
>  at: xfs_ilock+0xde/0x2c0 [xfs]
>
>  but task is already holding lock:
>  ffffffffbbb8bd00 (fs_reclaim){+.+.}-{0:0}, at:
>  __fs_reclaim_acquire+0x5/0x30
>
>  which lock already depends on the new lock.
>
>
>  the existing dependency chain (in reverse order) is:
>
>  -> #1 (fs_reclaim){+.+.}-{0:0}:
>         fs_reclaim_acquire+0x34/0x40
>         __kmalloc+0x4f/0x270
>         kmem_alloc+0x93/0x1d0 [xfs]
>         kmem_alloc_large+0x4c/0x130 [xfs]
>         xfs_attr_copy_value+0x74/0xa0 [xfs]
>         xfs_attr_get+0x9d/0xc0 [xfs]
>         xfs_get_acl+0xb6/0x200 [xfs]
>         get_acl+0x81/0x160
>         posix_acl_xattr_get+0x3f/0xd0
>         vfs_getxattr+0x148/0x170
>         getxattr+0xa7/0x240
>         path_getxattr+0x52/0x80
>         do_syscall_64+0x5c/0xa0
>         entry_SYSCALL_64_after_hwframe+0x49/0xb3
>
>  -> #0 (&xfs_nondir_ilock_class){++++}-{3:3}:
>         __lock_acquire+0x1257/0x20d0
>         lock_acquire+0xb0/0x310
>         down_write_nested+0x49/0x120
>         xfs_ilock+0xde/0x2c0 [xfs]
>         xfs_reclaim_inode+0x3f/0x400 [xfs]
>         xfs_reclaim_inodes_ag+0x20b/0x410 [xfs]
>         xfs_reclaim_inodes_nr+0x31/0x40 [xfs]
>         super_cache_scan+0x190/0x1e0
>         do_shrink_slab+0x184/0x420
>         shrink_slab+0x182/0x290
>         shrink_node+0x174/0x680
>         balance_pgdat+0x2d0/0x5f0
>         kswapd+0x21f/0x510
>         kthread+0x131/0x150
>         ret_from_fork+0x3a/0x50
>
>  other info that might help us debug this:
>
>   Possible unsafe locking scenario:
>
>         CPU0                    CPU1
>         ----                    ----
>    lock(fs_reclaim);
>                                 lock(&xfs_nondir_ilock_class);
>                                 lock(fs_reclaim);
>    lock(&xfs_nondir_ilock_class);
>
>   *** DEADLOCK ***
>
>  4 locks held by kswapd0/159:
>   #0: ffffffffbbb8bd00 (fs_reclaim){+.+.}-{0:0}, at:
>  __fs_reclaim_acquire+0x5/0x30
>   #1: ffffffffbbb7cef8 (shrinker_rwsem){++++}-{3:3}, at:
>  shrink_slab+0x115/0x290
>   #2: ffff9b39f07a50e8
>  (&type->s_umount_key#56){++++}-{3:3}, at: super_cache_scan+0x38/0x1e0
>   #3: ffff9b39f077f258
>  (&pag->pag_ici_reclaim_lock){+.+.}-{3:3}, at:
>  xfs_reclaim_inodes_ag+0x82/0x410 [xfs]

This is a known false positive because inodes cannot simultaneously be
getting reclaimed and the target of a getxattr operation, but lockdep
doesn't know that.  We can (selectively) shut up lockdep until either
it gets smarter or we change inode reclaim not to require the ILOCK by
applying a stupid GFP_NOLOCKDEP bandaid.

Reported-by: Dave Airlie <airlied@gmail.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Tested-by: Dave Airlie <airlied@gmail.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: force writes to delalloc regions to unwritten
Darrick J. Wong [Fri, 10 Jul 2020 06:34:10 +0000 (08:34 +0200)]
xfs: force writes to delalloc regions to unwritten

Source kernel commit: a5949d3faedf492fa7863b914da408047ab46eb0

When writing to a delalloc region in the data fork, commit the new
allocations (of the da reservation) as unwritten so that the mappings
are only marked written once writeback completes successfully.  This
fixes the problem of stale data exposure if the system goes down during
targeted writeback of a specific region of a file, as tested by
generic/042.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: always return -ENOSPC on project quota reservation failure
Eric Sandeen [Fri, 10 Jul 2020 06:34:00 +0000 (08:34 +0200)]
xfs: always return -ENOSPC on project quota reservation failure

Source kernel commit: dcf1ccc99e6db06a3a3cc9f72161f7d084a38d40

XFS project quota treats project hierarchies as "mini filesysems" and
so rather than -EDQUOT, the intent is to return -ENOSPC when a quota
reservation fails, but this behavior is not consistent.

The only place we make a decision between -EDQUOT and -ENOSPC
returns based on quota type is in xfs_trans_dqresv().

This behavior is currently controlled by whether or not the
XFS_QMOPT_ENOSPC flag gets passed into the quota reservation.  However,
its use is not consistent; paths such as xfs_create() and xfs_symlink()
don't set the flag, so a reservation failure will return -EDQUOT for
project quota reservation failures rather than -ENOSPC for these sorts
of operations, even for project quota:

# mkdir mnt/project
# xfs_quota -x -c "project -s -p mnt/project 42" mnt
# xfs_quota -x -c 'limit -p isoft=2 ihard=3 42' mnt
# touch mnt/project/file{1,2,3}
touch: cannot touch ‘mnt/project/file3’: Disk quota exceeded

We can make this consistent by not requiring the flag to be set at the
top of the callchain; instead we can simply test whether we are
reserving a project quota with XFS_QM_ISPDQ in xfs_trans_dqresv and if
so, return -ENOSPC for that failure.  This removes the need for the
XFS_QMOPT_ENOSPC altogether and simplifies the code a fair bit.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: cleanup xfs_idestroy_fork
Christoph Hellwig [Fri, 10 Jul 2020 06:31:37 +0000 (08:31 +0200)]
xfs: cleanup xfs_idestroy_fork

Source kernel commit: ef8385128d4b31a382d496b1c433697993bd0bfb

Move freeing the dynamically allocated attr and COW fork, as well
as zeroing the pointers where actually needed into the callers, and
just pass the xfs_ifork structure to xfs_idestroy_fork.  Also simplify
the kmem_free calls by not checking for NULL first.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: move the fork format fields into struct xfs_ifork
Christoph Hellwig [Fri, 10 Jul 2020 06:17:49 +0000 (08:17 +0200)]
xfs: move the fork format fields into struct xfs_ifork

Source kernel commit: f7e67b20ecbbcb9180c888a5c4fde267935e075f

Both the data and attr fork have a format that is stored in the legacy
idinode.  Move it into the xfs_ifork structure instead, where it uses
up padding.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: move the per-fork nextents fields into struct xfs_ifork
Christoph Hellwig [Thu, 9 Jul 2020 19:21:56 +0000 (21:21 +0200)]
xfs: move the per-fork nextents fields into struct xfs_ifork

Source kernel commit: daf83964a3681cf1f1f255ad6095c0b60cba7dca

There are there are three extents counters per inode, one for each of
the forks.  Two are in the legacy icdinode and one is directly in
struct xfs_inode.  Switch to a single counter in the xfs_ifork structure
where it uses up padding at the end of the structure.  This simplifies
various bits of code that just wants the number of extents counter and
can now directly dereference it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: remove the XFS_DFORK_Q macro
Christoph Hellwig [Thu, 9 Jul 2020 19:14:23 +0000 (21:14 +0200)]
xfs: remove the XFS_DFORK_Q macro

Source kernel commit: 09c38edd54c16657093a73a3169342f9f9080bb3

Just checking di_forkoff directly is a little easier to follow.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: remove the NULL fork handling in xfs_bmapi_read
Christoph Hellwig [Thu, 9 Jul 2020 19:14:13 +0000 (21:14 +0200)]
xfs: remove the NULL fork handling in xfs_bmapi_read

Source kernel commit: 4b516ff4e772993a99fc9bf36503d23ce5bd5ba9

Now that we fully verify the inode forks before they are added to the
inode cache, the crash reported in

https://bugzilla.kernel.org/show_bug.cgi?id=204031

can't happen anymore, as we'll never let an inode that has inconsistent
nextents counts vs the presence of an in-core attr fork leak into the
inactivate code path.  So remove the work around to try to handle the
case, and just return an error and warn if the fork is not present.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: remove the special COW fork handling in xfs_bmapi_read
Christoph Hellwig [Thu, 9 Jul 2020 19:14:08 +0000 (21:14 +0200)]
xfs: remove the special COW fork handling in xfs_bmapi_read

Source kernel commit: 1a1c57b2826f8b408feb733d3321490591a6e4c9

We don't call xfs_bmapi_read for the COW fork anymore, so remove the
special casing.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: improve local fork verification
Christoph Hellwig [Thu, 9 Jul 2020 19:11:23 +0000 (21:11 +0200)]
xfs: improve local fork verification

Source kernel commit: 0f45a1b20cd8f9cfc985a1f91a1e7a86e5e14dd6

Call the data/attr local fork verifiers as soon as we are ready for them.
This keeps them close to the code setting up the forks, and avoids a
few branches later on.  Also open code xfs_inode_verify_forks in the
only remaining caller.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: refactor xfs_inode_verify_forks
Christoph Hellwig [Thu, 9 Jul 2020 19:09:30 +0000 (21:09 +0200)]
xfs: refactor xfs_inode_verify_forks

Source kernel commit: 7c7ba2186305d6bee5eb5b8fb95a61d8de14de4f

The split between xfs_inode_verify_forks and the two helpers
implementing the actual functionality is a little strange.  Reshuffle
it so that xfs_inode_verify_forks verifies if the data and attr forks
are actually in local format and only call the low-level helpers if
that is the case.  Handle the actual error reporting in the low-level
handlers to streamline the caller.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: remove xfs_ifork_ops
Christoph Hellwig [Thu, 9 Jul 2020 19:04:14 +0000 (21:04 +0200)]
xfs: remove xfs_ifork_ops

Source kernel commit: 1934c8bd81bee4c239478b03a59addf5fe8e2785

xfs_ifork_ops add up to two indirect calls per inode read and flush,
despite just having a single instance in the kernel.  In xfsprogs
phase6 in xfs_repair overrides the verify_dir method to deal with inodes
that do not have a valid parent, but that can be fixed pretty easily
by ensuring they always have a valid looking parent.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: remove xfs_iread
Christoph Hellwig [Thu, 9 Jul 2020 18:49:25 +0000 (20:49 +0200)]
xfs: remove xfs_iread

Source kernel commit: bb8a66af4fff1cecb7631c68af761ea8e1a41ac2

There is not much point in the xfs_iread function, as it has a single
caller and not a whole lot of code.  Move it into the only caller,
and trim down the overdocumentation to just documenting the important
"why" instead of a lot of redundant "what".

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: don't reset i_delayed_blks in xfs_iread
Christoph Hellwig [Thu, 9 Jul 2020 18:48:23 +0000 (20:48 +0200)]
xfs: don't reset i_delayed_blks in xfs_iread

Source kernel commit: 7f0290123506e2b248fe06fa7cdc17c1b5b603b5

i_delayed_blks is set to 0 in xfs_inode_alloc and can't have anything
assigned to it until the inode is visible to the VFS.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: call xfs_dinode_verify from xfs_inode_from_disk
Christoph Hellwig [Thu, 9 Jul 2020 18:48:15 +0000 (20:48 +0200)]
xfs: call xfs_dinode_verify from xfs_inode_from_disk

Source kernel commit: 2d6051d4965308c3367bf5a2468dff969872a96e

Keep the code dealing with the dinode together, and also ensure we verify
the dinode in the owner change log recovery case as well.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: handle unallocated inodes in xfs_inode_from_disk
Christoph Hellwig [Thu, 9 Jul 2020 18:48:10 +0000 (20:48 +0200)]
xfs: handle unallocated inodes in xfs_inode_from_disk

Source kernel commit: 0bce8173fdcf203c92a4d57dc7d3bb642ed478a1

Handle inodes with a 0 di_mode in xfs_inode_from_disk, instead of partially
duplicating inode reading in xfs_iread.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: split xfs_iformat_fork
Christoph Hellwig [Thu, 9 Jul 2020 18:48:01 +0000 (20:48 +0200)]
xfs: split xfs_iformat_fork

Source kernel commit: 9229d18e801bdbdf79d963d8c944980fc77b5d6b

xfs_iformat_fork is a weird catchall.  Split it into one helper for
the data fork and one for the attr fork, and then call both helper
as well as the COW fork initialization from xfs_inode_from_disk.  Order
the COW fork initialization after the attr fork initialization given
that it can't fail to simplify the error handling.

Note that the newly split helpers are moved down the file in
xfs_inode_fork.c to avoid the need for forward declarations.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: call xfs_iformat_fork from xfs_inode_from_disk
Christoph Hellwig [Thu, 9 Jul 2020 18:47:02 +0000 (20:47 +0200)]
xfs: call xfs_iformat_fork from xfs_inode_from_disk

Source kernel commit: cb7d58594412fff106cde550dd9e0a7999cc2a0c

We always need to fill out the fork structures when reading the inode,
so call xfs_iformat_fork from the tail of xfs_inode_from_disk.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: xfs_bmapi_read doesn't take a fork id as the last argument
Christoph Hellwig [Thu, 9 Jul 2020 18:44:58 +0000 (20:44 +0200)]
xfs: xfs_bmapi_read doesn't take a fork id as the last argument

Source kernel commit: b90c2a9c8b4422bb9398b50fe3d6163e46dcddec

The last argument to xfs_bmapi_raad contains XFS_BMAPI_* flags, not the
fork.  Given that XFS_DATA_FORK evaluates to 0 no real harm is done,
but let's fix this anyway.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: fix the warning message in xfs_validate_sb_common()
Kaixu Xia [Thu, 9 Jul 2020 18:44:50 +0000 (20:44 +0200)]
xfs: fix the warning message in xfs_validate_sb_common()

Source kernel commit: 14506f7a91d8f4d13fc07126ac8d14c6519f00e3

Fix this error message to complain about project and group quota flag
bits instead of "PUOTA" and "QUOTA".

Signed-off-by: Kaixu Xia <kaixuxia@tencent.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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: use ordered buffers to initialize dquot buffers during quotacheck
Darrick J. Wong [Fri, 10 Jul 2020 06:37:43 +0000 (08:37 +0200)]
xfs: use ordered buffers to initialize dquot buffers during quotacheck

Source kernel commit: 78bba5c812cc651cee51b64b786be926ab7fe2a9

While QAing the new xfs_repair quotacheck code, I uncovered a quota
corruption bug resulting from a bad interaction between dquot buffer
initialization and quotacheck.  The bug can be reproduced with the
following sequence:

User quota on /opt (/dev/sdf)
Inodes
User ID      Used   Soft   Hard Warn/Grace
---------- ---------------------------------
root            3      0      0  00 [------]
nobody          1      0      0  00 [------]

User quota on /opt (/dev/sdf)
Inodes
User ID      Used   Soft   Hard Warn/Grace
---------- ---------------------------------
root            1      0      0  00 [------]
nobody          1      0      0  00 [------]

Notice how the initial quotacheck set the root dquot icount to 3
(rootino, rbmino, rsumino), but after shutdown -> remount -> recovery,
xfs_quota reports that the root dquot has only 1 icount.  We haven't
deleted anything from the filesystem, which means that quota is now
under-counting.  This behavior is not limited to icount or the root
dquot, but this is the shortest reproducer.

I traced the cause of this discrepancy to the way that we handle ondisk
dquot updates during quotacheck vs. regular fs activity.  Normally, when
we allocate a disk block for a dquot, we log the buffer as a regular
(dquot) buffer.  Subsequent updates to the dquots backed by that block
are done via separate dquot log item updates, which means that they
depend on the logged buffer update being written to disk before the
dquot items.  Because individual dquots have their own LSN fields, that
initial dquot buffer must always be recovered.

However, the story changes for quotacheck, which can cause dquot block
allocations but persists the final dquot counter values via a delwri
list.  Because recovery doesn't gate dquot buffer replay on an LSN, this
means that the initial dquot buffer can be replayed over the (newer)
contents that were delwritten at the end of quotacheck.  In effect, this
re-initializes the dquot counters after they've been updated.  If the
log does not contain any other dquot items to recover, the obsolete
dquot contents will not be corrected by log recovery.

Because quotacheck uses a transaction to log the setting of the CHKD
flags in the superblock, we skip quotacheck during the second mount
call, which allows the incorrect icount to remain.

Fix this by changing the ondisk dquot initialization function to use
ordered buffers to write out fresh dquot blocks if it detects that we're
running quotacheck.  If the system goes down before quotacheck can
complete, the CHKD flags will not be set in the superblock and the next
mount will run quotacheck again, which can fix uninitialized dquot
buffers.  This requires amending the defer code to maintaine ordered
buffer state across defer rolls for the sake of the dquot allocation
code.

For regular operations we preserve the current behavior since the dquot
items require properly initialized ondisk dquot records.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: don't fail verifier on empty attr3 leaf block
Brian Foster [Thu, 9 Jul 2020 18:44:36 +0000 (20:44 +0200)]
xfs: don't fail verifier on empty attr3 leaf block

Source kernel commit: f28cef9e4daca11337cb9f144cdebedaab69d78c

The attr fork can transition from shortform to leaf format while
empty if the first xattr doesn't fit in shortform. While this empty
leaf block state is intended to be transient, it is technically not
due to the transactional implementation of the xattr set operation.

We historically have a couple of bandaids to work around this
problem. The first is to hold the buffer after the format conversion
to prevent premature writeback of the empty leaf buffer and the
second is to bypass the xattr count check in the verifier during
recovery. The latter assumes that the xattr set is also in the log
and will be recovered into the buffer soon after the empty leaf
buffer is reconstructed. This is not guaranteed, however.

If the filesystem crashes after the format conversion but before the
xattr set that induced it, only the format conversion may exist in
the log. When recovered, this creates a latent corrupted state on
the inode as any subsequent attempts to read the buffer fail due to
verifier failure. This includes further attempts to set xattrs on
the inode or attempts to destroy the attr fork, which prevents the
inode from ever being removed from the unlinked list.

To avoid this condition, accept that an empty attr leaf block is a
valid state and remove the count check from the verifier. This means
that on rare occasions an attr fork might exist in an unexpected
state, but is otherwise consistent and functional. Note that we
retain the logic to avoid racing with metadata writeback to reduce
the window where this can occur.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: Use the correct style for SPDX License Identifier
Nishad Kamdar [Thu, 9 Jul 2020 18:44:30 +0000 (20:44 +0200)]
xfs: Use the correct style for SPDX License Identifier

Source kernel commit: 508578f2f5601816ea29bec5cda00ea7d95a856d

This patch corrects the SPDX License Identifier style in header files
related to XFS File System support. For C header files
Documentation/process/license-rules.rst mandates C-like comments.
(opposed to C source files where C++ style should be used).

Changes made by using a script provided by Joe Perches here:
https://lkml.org/lkml/2019/2/7/46.

Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Nishad Kamdar <nishadkamdar@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: Replace zero-length array with flexible-array
Gustavo A. R. Silva [Thu, 9 Jul 2020 18:44:18 +0000 (20:44 +0200)]
xfs: Replace zero-length array with flexible-array

Source kernel commit: ee4064e56cd81cd3126805159122f53cf4f12ae6

The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:

struct foo {
int stuff;
struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by
this change:

"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]

sizeof(flexible-array-member) triggers a warning because flexible array
members have incomplete type[1]. There are some instances of code in
which the sizeof operator is being incorrectly/erroneously applied to
zero-length arrays and the result is zero. Such instances may be hiding
some bugs. So, this work (flexible-array member conversions) will also
help to get completely rid of those sorts of issues.

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: remove unused iget_flags param from xfs_imap_to_bp()
Brian Foster [Thu, 9 Jul 2020 18:38:39 +0000 (20:38 +0200)]
xfs: remove unused iget_flags param from xfs_imap_to_bp()

Source kernel commit: c199507993ede3f63d0deae7e2cbc2f5462c6452

iget_flags is unused in xfs_imap_to_bp(). Remove the parameter and
fix up the callers.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: random buffer write failure errortag
Brian Foster [Thu, 9 Jul 2020 18:38:29 +0000 (20:38 +0200)]
xfs: random buffer write failure errortag

Source kernel commit: 7376d74547344598008d00419eae0caa5f50f4f0

Introduce an error tag to randomly fail async buffer writes. This is
primarily to facilitate testing of the XFS error configuration
mechanism.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: remove unnecessary shutdown check from xfs_iflush()
Brian Foster [Thu, 9 Jul 2020 18:38:23 +0000 (20:38 +0200)]
xfs: remove unnecessary shutdown check from xfs_iflush()

Source kernel commit: 15fab3b9be2255be70ba1c598a11622fa03c9d5e

The shutdown check in xfs_iflush() duplicates checks down in the
buffer code. If the fs is shut down, xfs_trans_read_buf_map() always
returns an error and falls into the same error path. Remove the
unnecessary check along with the warning in xfs_imap_to_bp()
that generates excessive noise in the log if the fs is shut down.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs: spell out the parameter name for ->cancel_item
Christoph Hellwig [Thu, 9 Jul 2020 18:38:16 +0000 (20:38 +0200)]
xfs: spell out the parameter name for ->cancel_item

Source kernel commit: 2f88f1efd02ddf76cb5973abc42474c4dac2b03a

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: use a xfs_btree_cur for the ->finish_cleanup state
Christoph Hellwig [Thu, 9 Jul 2020 18:35:08 +0000 (20:35 +0200)]
xfs: use a xfs_btree_cur for the ->finish_cleanup state

Source kernel commit: 3ec1b26c04d4910f37cdaad26d14b403c0240e30

Given how XFS is all based around btrees it doesn't make much sense
to offer a totally generic state when we can just use the btree cursor.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: turn dfp_done into a xfs_log_item
Christoph Hellwig [Thu, 9 Jul 2020 18:32:54 +0000 (20:32 +0200)]
xfs: turn dfp_done into a xfs_log_item

Source kernel commit: f09d167c20332ad1298ff82a6f538b4c7ea3fe1b

All defer op instance place their own extension of the log item into
the dfp_done field.  Replace that with a xfs_log_item to improve type
safety and make the code easier to follow.

Also use the opportunity to improve the ->finish_item calling conventions
to place the done log item as the higher level structure before the
list_entry used for the individual items.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: refactor xfs_defer_finish_noroll
Christoph Hellwig [Thu, 9 Jul 2020 18:32:07 +0000 (20:32 +0200)]
xfs: refactor xfs_defer_finish_noroll

Source kernel commit: bb47d79750f1a68a75d4c7defc2da934ba31de14

Split out a helper that operates on a single xfs_defer_pending structure
to untangle the code.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: turn dfp_intent into a xfs_log_item
Christoph Hellwig [Thu, 9 Jul 2020 18:29:33 +0000 (20:29 +0200)]
xfs: turn dfp_intent into a xfs_log_item

Source kernel commit: 13a8333339072b8654c1d2c75550ee9f41ee15de

All defer op instance place their own extension of the log item into
the dfp_intent field.  Replace that with a xfs_log_item to improve type
safety and make the code easier to follow.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: merge the ->diff_items defer op into ->create_intent
Christoph Hellwig [Thu, 9 Jul 2020 18:25:32 +0000 (20:25 +0200)]
xfs: merge the ->diff_items defer op into ->create_intent

Source kernel commit: d367a868e46b025a8ced8e00ef2b3a3c2f3bf732

This avoids a per-item indirect call, and also simplifies the interface
a bit.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: merge the ->log_item defer op into ->create_intent
Christoph Hellwig [Thu, 9 Jul 2020 18:22:10 +0000 (20:22 +0200)]
xfs: merge the ->log_item defer op into ->create_intent

Source kernel commit: c1f09188e8de0ae65433cb9c8ace4feb66359bcc

These are aways called together, and my merging them we reduce the amount
of indirect calls, improve type safety and in general clean up the code
a bit.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: factor out a xfs_defer_create_intent helper
Christoph Hellwig [Thu, 9 Jul 2020 18:22:00 +0000 (20:22 +0200)]
xfs: factor out a xfs_defer_create_intent helper

Source kernel commit: e046e949486ec92d83b2ccdf0e7e9144f74ef028

Create a helper that encapsulates the whole logic to create a defer
intent.  This reorders some of the work that was done, but none of
that has an affect on the operation as only fields that don't directly
interact are affected.

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: Christoph Hellwig <hch@lst.de>
5 years agoxfs: remove the xfs_inode_log_item_t typedef
Christoph Hellwig [Thu, 9 Jul 2020 18:19:58 +0000 (20:19 +0200)]
xfs: remove the xfs_inode_log_item_t typedef

Source kernel commit: fd9cbe51215198ccffa64169c98eae35b0916088

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: Christoph Hellwig <hch@lst.de>
5 years agorepair: simplify bmap_next_offset
Christoph Hellwig [Fri, 10 Jul 2020 06:28:59 +0000 (08:28 +0200)]
repair: simplify bmap_next_offset

The tp argument is always NULL, and the whichfork argument is always
XFS_DATA_FORK, so simplify and cleanup the function based on those
assumptions.

Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agoxfs_db: directly operate on the dinode in process_inode
Christoph Hellwig [Fri, 10 Jul 2020 06:00:22 +0000 (08:00 +0200)]
xfs_db: directly operate on the dinode in process_inode

Rewrite process_inode to operate directly on the dinode instead of
converting it to an in-core inode using xfs_inode_from_disk, which will
change significantly to match the latest kernel version.

As we don't support v1 inodes any more this doesn't change behavior.

Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agolibxfs: remove the ifork_ops argument to libxfs_iget
Christoph Hellwig [Thu, 9 Jul 2020 19:07:05 +0000 (21:07 +0200)]
libxfs: remove the ifork_ops argument to libxfs_iget

We always use xfs_default_ifork_ops now, so hard code that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
5 years agorepair: ensure inodes always have a valid parent in phase 6
Brian Foster [Thu, 9 Jul 2020 18:57:24 +0000 (20:57 +0200)]
repair: ensure inodes always have a valid parent in phase 6

XXX: needs signoff from Brian

5 years agometadump: remove redundant bracket and show right SYNOPSIS for-next
Kaixu Xia [Tue, 26 May 2020 18:42:40 +0000 (14:42 -0400)]
metadump: remove redundant bracket and show right SYNOPSIS

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Shorten a conditional to a single line.

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

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

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

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

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

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

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

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

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

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

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

XFS_BUF_TO_AGFL_BNO has been renamed to open coded xfs_buf_to_agfl_bno.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Source kernel commit: f8e566c0f5e1fd8de33ccec6eb1ff815cd4b0dc3

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

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

Source kernel commit: 6471e9c5e7a109a952be8e3e80b8d9e262af239d

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

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

Source kernel commit: e9e2eae89ddb658ea332295153fdca78c12c1e0d

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

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

Source kernel commit: b81b79f4eda2ea98ae5695c0b6eb384c8d90b74d

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

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

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

Source kernel commit: 59d677127cf1543b2978aca3be8c8395f3a17973

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

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

Source kernel commit: 56e98164ffea2a9ee577e5e4f368c6d5182ed8eb

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

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

Source kernel commit: c29ce8f48e219d10644f402ec5d738cadf20666e

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

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

Source kernel commit: e6eb33d905c287eb07ee1c69d38871276db154dd

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

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

Source kernel commit: 60e3d7070749554227fbb636a69a4282ab930f86

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

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

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

Source kernel commit: 349e1c0380dbb7f552e4ea61b479c293eb076b3f

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

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

Source kernel commit: e06536a692e032470130af5b2136b519595809da

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

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

Source kernel commit: 77ca1eed5a7d2bf0905562eb1a15aac76bc19fe4

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

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

Source kernel commit: faf8ee8476c19b30fd16079ad616b2b0f56eaff4

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

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

Source kernel commit: c4aa10d041968f55f00fe8ca768b6f45f4066a69

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

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

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

Source kernel commit: 68422d90dad4fe98f99d6e414aeec9a58d5185d5

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

Based on code extracted from a patchset by Darrick Wong.

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

Source kernel commit: 352890735e52343b1690f6d5d32224e2aa88a56a

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

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

Source kernel commit: 8ef547976a18e3d672194d8c944c19b345ef6bfc

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

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

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

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

Source kernel commit: 92219c292af8ddfb64d75bdffcbdd9baf80ac0aa

bc_private.b -> bc_ino conversion via script:

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

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

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

Source kernel commit: 576af7322807601d5ef366597645a69471570e10

bc_private.a -> bc_ag conversion via script:

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

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

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

Source kernel commit: 7cace18ab576ef65d16498d3a9e2170fff5f5c93

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

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

Source kernel commit: 1b2c1a63b678d63e9c98314d44413f5af79c9c80

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

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

Source kernel commit: a10c21ed5d5241d11cf1d5a4556730840572900b

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

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

Source kernel commit: 6fb5aac73310d030be13eb3481fdb7c7cc7c0f00

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

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

Source kernel commit: 1cb5deb5bc095c070c09a4540c45f9c9ba24be43

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

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

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

Source kernel commit: ce99494c9699df58b31d0a839e957f86cd58c755

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

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

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

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

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

Source kernel commit: e83cf875d67a6cb9ddfaa8b45d2fa93d12b5c66f

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

Source kernel commit: 8d57c21600a514d7a9237327c2496ae159bab5bb

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

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

Source kernel commit: a71e4228e6f2a4fe6519d8ed081d0a164967fa31

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

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

Source kernel commit: 3e6e8afd3abb745871ee215738a899a495c54a66

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

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

Source kernel commit: 9798f615ad2be48466a01c44ad2257ba64ab03bd

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

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

Source kernel commit: 370c782b98436bb3f9d14a7394ab126cdbeac233

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

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

Source kernel commit: 4b97510859b22e0db5edf104096af1132daeea9a

There is just a single user left, so remove it.

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

Source kernel commit: 183606d82446110e23987d4b693f3d3fc300bd82

struct xfs_agfl is a header in front of the AGFL entries that exists
for CRC enabled file systems.  For not CRC enabled file systems the AGFL
is simply a list of agbno.  Make the CRC case similar to that by just
using the list behind the new header.  This indirectly solves a problem
with modern gcc versions that warn about taking addresses of packed
structures (and we have to pack the AGFL given that gcc rounds up
structure sizes).  Also replace the helper macro to get from a buffer
with an inline function in xfs_alloc.h to make the code easier to
read.

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

Source kernel commit: e3a19cdea84a42d44ef42ff8b5459c903992bbf2

The attrlist cursor only exists as part of an attr list context, so
embedd the structure instead of pointing to it.  Also give it a proper
xfs_ prefix and remove the obsolete typedef.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>