]> www.infradead.org Git - users/hch/xfsprogs.git/log
users/hch/xfsprogs.git
5 years agoxfs_repair: check plausibility of root dir pointer before trashing it
Darrick J. Wong [Thu, 27 Feb 2020 20:05:47 +0000 (15:05 -0500)]
xfs_repair: check plausibility of root dir pointer before trashing it

If sb_rootino doesn't point to where we think mkfs should have allocated
the root directory, check to see if the alleged root directory actually
looks like a root directory.  If so, we'll let it live because someone
could have changed sunit since formatting time, and that changes the
root directory inode estimate.

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_repair: use libxfs function to calculate root inode location
Darrick J. Wong [Thu, 27 Feb 2020 20:05:00 +0000 (15:05 -0500)]
xfs_repair: use libxfs function to calculate root inode location

Use libxfs_ialloc_calc_rootino to compute the location of the root
inode, and improve the function comments while we're at it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.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_repair: refactor fixed inode location checks
Darrick J. Wong [Thu, 27 Feb 2020 20:04:29 +0000 (15:04 -0500)]
xfs_repair: refactor fixed inode location checks

Refactor the checking and resetting of fixed-location inodes (root,
rbmino, rsumino) into a helper function.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.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_repair: enforce that inode btree chunks can't point to AG headers
Darrick J. Wong [Thu, 27 Feb 2020 19:50:01 +0000 (14:50 -0500)]
xfs_repair: enforce that inode btree chunks can't point to AG headers

xfs_repair has a very old check that evidently excuses the AG 0 inode
btrees pointing to blocks that are already marked XR_E_INUSE_FS* (e.g.
AG headers).  mkfs never formats filesystems that way and it looks like
an error, so purge the check.  After this, we always complain if inodes
overlap with AG headers because that should never happen.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
[sandeen: removed unused switch cases that fall through to default]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agomkfs: check root inode location
Darrick J. Wong [Thu, 27 Feb 2020 19:49:55 +0000 (14:49 -0500)]
mkfs: check root inode location

Make sure the root inode gets created where repair thinks it should be
created.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.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_repair: replace verify_inum with libxfs inode validators
Darrick J. Wong [Thu, 27 Feb 2020 19:22:19 +0000 (14:22 -0500)]
xfs_repair: replace verify_inum with libxfs inode validators

Repair uses the verify_inum function to validate inode numbers that it
finds in the superblock and in directories.  libxfs now has validator
functions to cover that kind of thing, so remove verify_inum().  As a
side bonus, this means that we will flag directories that point to the
quota/realtime metadata inodes.

This fixes a regression found by fuzzing u3.sfdir3.hdr.parent.i4 to
lastbit (aka making a directory's .. point to the user quota inode) in
xfs/384.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: don't corrupt a attr fork da3 node when clearing forw/back
Darrick J. Wong [Thu, 27 Feb 2020 19:22:19 +0000 (14:22 -0500)]
xfs_repair: don't corrupt a attr fork da3 node when clearing forw/back

In process_longform_attr, we enforce that the root block of the
attribute index must have both forw or back pointers set to zero.
Unfortunately, the code that nulls out the pointers is not aware that
the root block could be in da3 node format.

This leads to corruption of da3 root node blocks because the functions
that convert attr3 leaf headers to and from the ondisk structures
perform some interpretation of firstused on what they think is an attr1
leaf block.

Found by using xfs/402 to fuzz hdr.info.hdr.forw.

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_repair: refactor attr root block pointer check
Darrick J. Wong [Thu, 27 Feb 2020 19:22:19 +0000 (14:22 -0500)]
xfs_repair: refactor attr root block pointer check

In process_longform_attr, replace the agcount check with a call to the
fsblock verification function in libxfs.  Now we can also catch blocks
that point to static FS metadata.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
[sandeen: update error message]
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agolibfrog: remove libxfs.h dependencies in fsgeom.c and linux.c
Darrick J. Wong [Thu, 27 Feb 2020 19:22:19 +0000 (14:22 -0500)]
libfrog: remove libxfs.h dependencies in fsgeom.c and linux.c

libfrog isn't supposed to depend on libxfs, so don't include the header
file in the libfrog source code.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agolibxfs: re-sort libxfs_api_defs.h defines
Darrick J. Wong [Thu, 27 Feb 2020 19:21:45 +0000 (14:21 -0500)]
libxfs: re-sort libxfs_api_defs.h defines

Re-fix the sorting in this file.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs_repair: fix bad next_unlinked field
Eric Sandeen [Thu, 27 Feb 2020 19:21:45 +0000 (14:21 -0500)]
xfs_repair: fix bad next_unlinked field

As of xfsprogs-4.17 we started testing whether the di_next_unlinked field
on an inode is valid in the inode verifiers. However, this field is never
tested or repaired during inode processing.

So if, for example, we had a completely zeroed-out inode, we'd detect and
fix the broken magic and version, but the invalid di_next_unlinked field
would not be touched, fail the write verifier, and prevent the inode from
being properly repaired or even written out.

Fix this by checking the di_next_unlinked inode field for validity and
clearing it if it is invalid.

Reported-by: John Jore <john@jore.no>
Fixes: 2949b4677 ("xfs: don't accept inode buffers with suspicious unlinked chains")
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 agolibxfs: remove duplicate attr function declarations
Darrick J. Wong [Thu, 30 Jan 2020 18:41:12 +0000 (13:41 -0500)]
libxfs: remove duplicate attr function declarations

Remove these function declarations since they're in libxfs/xfs_attr.h
and are therefore redundant.

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: fix integer over/underflow handling in timespec_from_string
Darrick J. Wong [Thu, 30 Jan 2020 18:41:06 +0000 (13:41 -0500)]
xfs_io: fix integer over/underflow handling in timespec_from_string

When we're filling out the struct timespec, make sure we detect when the
string value cannot be represented by a (potentially 32-bit) seconds
field in struct timespec.

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_repair: fix totally broken unit conversion in directory invalidation
Darrick J. Wong [Thu, 30 Jan 2020 18:41:01 +0000 (13:41 -0500)]
xfs_repair: fix totally broken unit conversion in directory invalidation

Your humble author forgot that xfs_dablk_t has the same units as
xfs_fileoff_t, and totally screwed up the directory buffer invalidation
loop in dir_binval.  Not only is there an off-by-one error in the loop
conditional, but the unit conversions are wrong.

The pre-5.5 xfs_da_get_buf implementation mostly hides the off-by-one
error because dir_binval turns on "don't complain if no mapping" mode,
but on dirblocksize > fsblocksize filesystems the incorrect units can
cause us to miss invalidating some blocks, which can lead to other
buffer cache errors later.

Fixes: f9c559f4e4fb4 ("xfs_repair: invalidate dirty dir buffers when we zap a directory")
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: fix pwrite/pread length truncation on 32-bit systems
Darrick J. Wong [Thu, 30 Jan 2020 18:40:54 +0000 (13:40 -0500)]
xfs_io: fix pwrite/pread length truncation on 32-bit systems

The pwrite and pread commands in xfs_io accept an operation length that
can be any quantity that fits in a long long int; and loops to handle
the cases where the operation length is larger than the IO buffer.

Weirdly, the do_ functions contain code to shorten the operation to the
IO buffer size but the @count parameter is size_t, which means that for
a large argument on a 32-bit system, we rip off the upper bits of the
length, turning your 8GB write into a 0 byte write, which does nothing.

This was found by running generic/175 and observing that the 8G test
file it creates has zero length after the operation:

wrote 0/8589934592 bytes at offset 0
0.000000 bytes, 0 ops; 0.0001 sec (0.000000 bytes/sec and 0.0000 ops/sec)

Fix this by pushing long long count all the way through the call stack.

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: fix copy_file_range length argument overflow
Darrick J. Wong [Thu, 30 Jan 2020 18:40:50 +0000 (13:40 -0500)]
xfs_io: fix copy_file_range length argument overflow

Don't let the length argument overflow size_t.  This is mostly a problem
on 32-bit platforms.

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_db: dump per-AG reservations
Darrick J. Wong [Thu, 30 Jan 2020 18:40:46 +0000 (13:40 -0500)]
xfs_db: dump per-AG reservations

Add a new 'agresv' command to print the size and free blocks count of an
AG along with the size and usage of the per-AG reservation.  This
command can be used to aid in diagnosing why a particular filesystem
fails the mount time per-AG space reservation, and to figure out how
much space needs to be freed from a given AG to fix the problem.

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 agoman: document some missing xfs_db commands
Darrick J. Wong [Thu, 30 Jan 2020 18:39:33 +0000 (13:39 -0500)]
man: document some missing xfs_db commands

The 'attr_set', 'attr_remove', and 'logformat' commands in xfs_db were
not documented.  Add sections about them to the manpage.

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 agoman: reformat xfs_quota commands in the manpage for testing
Darrick J. Wong [Thu, 30 Jan 2020 18:39:18 +0000 (13:39 -0500)]
man: reformat xfs_quota commands in the manpage for testing

Reformat the xfs_quota commands listed in the xfs_quota.8 manpage so
that we can implement a fstest that checks that each command actually
has a section in the manpage.

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 agoman: document the xfs_db btheight command
Darrick J. Wong [Thu, 30 Jan 2020 18:39:07 +0000 (13:39 -0500)]
man: document the xfs_db btheight command

Document the btheight command in xfs_db.

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 agoman: list xfs_io lsattr inode flag letters
Darrick J. Wong [Thu, 30 Jan 2020 18:36:17 +0000 (13:36 -0500)]
man: list xfs_io lsattr inode flag letters

The section of the xfs_io manpage for the 'chattr' command says to refer
to xfsctl(3) for information on the flags.  The inode flag information
was moved to ioctl_xfs_fssetxattr(2) ages ago, and it never actually
mapped the inode flag letters to inode flag bits, so fix the link and
add such a mapping to the xfs_io manpage.

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 agoxfsprogs: do not redeclare globals provided by libraries
Eric Sandeen [Thu, 30 Jan 2020 18:34:17 +0000 (13:34 -0500)]
xfsprogs: do not redeclare globals provided by libraries

In each of these cases, db, logprint, and mdrestore are redeclaring
as a global variable something which was already provided by a
library they link with.

gcc now defaults to -fno-common and trips over these global variables
which are declared in utilities as well as in libxfs and libxlog, and
it causes the build to fail.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-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_repair: don't search for libxfs.h in system headers
Eric Sandeen [Thu, 30 Jan 2020 16:43:59 +0000 (11:43 -0500)]
xfs_repair: don't search for libxfs.h in system headers

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-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 agolibxfs: move header includes closer to kernelspace
Eric Sandeen [Thu, 30 Jan 2020 16:43:39 +0000 (11:43 -0500)]
libxfs: move header includes closer to kernelspace

Aid application of future kernel patches which change #includes;
not all headers exist in userspace so this is not a 1:1 match, but
it brings userspace files a bit closer to kernelspace by adding all
#includes which do match, and putting them in the same order.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-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 agoxfsprogs: alphabetize libxfs_api_defs.h
Eric Sandeen [Thu, 30 Jan 2020 16:43:33 +0000 (11:43 -0500)]
xfsprogs: alphabetize libxfs_api_defs.h

Rather than randomly choosing locations for new #defines in the
future, alphabetize the file now for consistency.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfsprogs: Release v5.5.0-rc0 libxfs-5.5-sync v5.5.0-rc0
Eric Sandeen [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfsprogs: Release v5.5.0-rc0

Update all the necessary files for a 5.5.0-rc0 prerelease.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: Make the symbol 'xfs_rtalloc_log_count' static
Chen Wandun [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: Make the symbol 'xfs_rtalloc_log_count' static

Source kernel commit: 5084bf6b2006fcd46f1e44e3c51b687507b362e2

Fix the following sparse warning:

fs/xfs/libxfs/xfs_trans_resv.c:206:1: warning: symbol 'xfs_rtalloc_log_count' was not declared. Should it be static?

Fixes: b1de6fc7520f ("xfs: fix log reservation overflows when allocating large rt extents")
Signed-off-by: Chen Wandun <chenwandun@huawei.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 commit sunit/swidth updates to disk if that would cause repair failures
Darrick J. Wong [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: don't commit sunit/swidth updates to disk if that would cause repair failures

Source kernel commit: 13eaec4b2adf2657b8167b67e27c97cc7314d923

Alex Lyakas reported[1] that mounting an xfs filesystem with new sunit
and swidth values could cause xfs_repair to fail loudly.  The problem
here is that repair calculates the where mkfs should have allocated the
root inode, based on the superblock geometry.  The allocation decisions
depend on sunit, which means that we really can't go updating sunit if
it would lead to a subsequent repair failure on an otherwise correct
filesystem.

Port from xfs_repair some code that computes the location of the root
inode and teach mount to skip the ondisk update if it would cause
problems for repair.  Along the way we'll update the documentation,
provide a function for computing the minimum AGFL size instead of
open-coding it, and cut down some indenting in the mount code.

Note that we allow the mount to proceed (and new allocations will
reflect this new geometry) because we've never screened this kind of
thing before.  We'll have to wait for a new future incompat feature to
enforce correct behavior, alas.

Note that the geometry reporting always uses the superblock values, not
the incore ones, so that is what xfs_info and xfs_growfs will report.

[1] https://lore.kernel.org/linux-xfs/20191125130744.GA44777@bfoster/T/#m00f9594b511e076e2fcdd489d78bc30216d72a7d

Reported-by: Alex Lyakas <alex@zadara.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: refactor agfl length computation function
Darrick J. Wong [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: refactor agfl length computation function

Source kernel commit: 1cac233cfe71f21e069705a4930c18e48d897be6

Refactor xfs_alloc_min_freelist to accept a NULL @pag argument, in which
case it returns the largest possible minimum length.  This will be used
in an upcoming patch to compute the length of the AGFL at mkfs time.

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 agolibxfs: resync with the userspace libxfs
Darrick J. Wong [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
libxfs: resync with the userspace libxfs

Source kernel commit: af952aeb4a8717fe4c7a872d9699fcfa85aa9e1c

Prepare to resync the userspace libxfs with the kernel libxfs.  There
were a few things I missed -- a couple of static inline directory
functions that have to be exported for xfs_repair; a couple of directory
naming functions that make porting much easier if they're /not/ static
inline; and a u16 usage that should have been uint16_t.

None of these things are bugs in their own right; this just makes
porting xfsprogs easier.

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: fix log reservation overflows when allocating large rt extents
Darrick J. Wong [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: fix log reservation overflows when allocating large rt extents

Source kernel commit: b1de6fc7520fe12949c070af0e8c0e4044cd3420

Omar Sandoval reported that a 4G fallocate on the realtime device causes
filesystem shutdowns due to a log reservation overflow that happens when
we log the rtbitmap updates.  Factor rtbitmap/rtsummary updates into the
the tr_write and tr_itruncate log reservation calculation.

"The following reproducer results in a transaction log overrun warning
for me:

mkfs.xfs -f -r rtdev=/dev/vdc -d rtinherit=1 -m reflink=0 /dev/vdb
mount -o rtdev=/dev/vdc /dev/vdb /mnt
fallocate -l 4G /mnt/foo

Reported-by: Omar Sandoval <osandov@osandov.com>
Tested-by: Omar Sandoval <osandov@osandov.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: stabilize insert range start boundary to avoid COW writeback race
Brian Foster [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: stabilize insert range start boundary to avoid COW writeback race

Source kernel commit: d0c2204135a0cdbc607c94c481cf1ccb2f659aa7

generic/522 (fsx) occasionally fails with a file corruption due to
an insert range operation. The primary characteristic of the
corruption is a misplaced insert range operation that differs from
the requested target offset. The reason for this behavior is a race
between the extent shift sequence of an insert range and a COW
writeback completion that causes a front merge with the first extent
in the shift.

The shift preparation function flushes and unmaps from the target
offset of the operation to the end of the file to ensure no
modifications can be made and page cache is invalidated before file
data is shifted. An insert range operation then splits the extent at
the target offset, if necessary, and begins to shift the start
offset of each extent starting from the end of the file to the start
offset. The shift sequence operates at extent level and so depends
on the preparation sequence to guarantee no changes can be made to
the target range during the shift. If the block immediately prior to
the target offset was dirty and shared, however, it can undergo
writeback and move from the COW fork to the data fork at any point
during the shift. If the block is contiguous with the block at the
start offset of the insert range, it can front merge and alter the
start offset of the extent. Once the shift sequence reaches the
target offset, it shifts based on the latest start offset and
silently changes the target offset of the operation and corrupts the
file.

To address this problem, update the shift preparation code to
stabilize the start boundary along with the full range of the
insert. Also update the existing corruption check to fail if any
extent is shifted with a start offset behind the target offset of
the insert range. This prevents insert from racing with COW
writeback completion and fails loudly in the event of an unexpected
extent shift.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: don't check for AG deadlock for realtime files in bunmapi
Omar Sandoval [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: don't check for AG deadlock for realtime files in bunmapi

Source kernel commit: 69ffe5960df16938bccfe1b65382af0b3de51265

Commit 5b094d6dac04 ("xfs: fix multi-AG deadlock in xfs_bunmapi") added
a check in __xfs_bunmapi() to stop early if we would touch multiple AGs
in the wrong order. However, this check isn't applicable for realtime
files. In most cases, it just makes us do unnecessary commits. However,
without the fix from the previous commit ("xfs: fix realtime file data
space leak"), if the last and second-to-last extents also happen to have
different "AG numbers", then the break actually causes __xfs_bunmapi()
to return without making any progress, which sends
xfs_itruncate_extents_flags() into an infinite loop.

Fixes: 5b094d6dac04 ("xfs: fix multi-AG deadlock in xfs_bunmapi")
Signed-off-by: Omar Sandoval <osandov@fb.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 realtime file data space leak
Omar Sandoval [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: fix realtime file data space leak

Source kernel commit: 0c4da70c83d41a8461fdf50a3f7b292ecb04e378

Realtime files in XFS allocate extents in rextsize units. However, the
written/unwritten state of those extents is still tracked in blocksize
units. Therefore, a realtime file can be split up into written and
unwritten extents that are not necessarily aligned to the realtime
extent size. __xfs_bunmapi() has some logic to handle these various
corner cases. Consider how it handles the following case:

1. The last extent is unwritten.
2. The last extent is smaller than the realtime extent size.
3. startblock of the last extent is not aligned to the realtime extent
size, but startblock + blockcount is.

In this case, __xfs_bunmapi() calls xfs_bmap_add_extent_unwritten_real()
to set the second-to-last extent to unwritten. This should merge the
last and second-to-last extents, so __xfs_bunmapi() moves on to the
second-to-last extent.

However, if the size of the last and second-to-last extents combined is
greater than MAXEXTLEN, xfs_bmap_add_extent_unwritten_real() does not
merge the two extents. When that happens, __xfs_bunmapi() skips past the
last extent without unmapping it, thus leaking the space.

Fix it by only unwriting the minimum amount needed to align the last
extent to the realtime extent size, which is guaranteed to merge with
the last extent.

Signed-off-by: Omar Sandoval <osandov@fb.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 mappedbno argument to xfs_da_get_buf
Christoph Hellwig [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: remove the mappedbno argument to xfs_da_get_buf

Source kernel commit: 2911edb653b9c64e0aad461f308cae8ce030eb7b

Use the xfs_da_get_buf_daddr function directly for the two callers
that pass a mapped disk address, and then remove the mappedbno argument.

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 the mappedbno argument to xfs_da_read_buf
Christoph Hellwig [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: remove the mappedbno argument to xfs_da_read_buf

Source kernel commit: cd2c9f1b544b8f5e1ca1874032fd669d74946a6d

Move the code for reading an already mapped block into
xfs_da3_node_read_mapped, which is the only caller ever passing a block
number in the mappedbno argument and replace the mappedbno argument with
the simple xfs_dabuf_get flags.

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: split xfs_da3_node_read
Christoph Hellwig [Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)]
xfs: split xfs_da3_node_read

Source kernel commit: 02c57f0a8b07f5c8a393530ff29b2f6fbe17c825

Split xfs_da3_node_read into one variant that always looks up the daddr
and doesn't accept holes, and one that already has a daddr at hand.
This is in preparation of splitting up xfs_da_read_buf in a similar way.

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 the mappedbno argument to xfs_dir3_leafn_read
Christoph Hellwig [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: remove the mappedbno argument to xfs_dir3_leafn_read

Source kernel commit: f3fcb314d16cdcffb6c521564b86b453869300da

This argument is always hard coded to -1, so remove it.

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 the mappedbno argument to xfs_dir3_leaf_read
Christoph Hellwig [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: remove the mappedbno argument to xfs_dir3_leaf_read

Source kernel commit: c943c0b2e5c310e2f70e64055666732782f00254

This argument is always hard coded to -1, so remove it.

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 the mappedbno argument to xfs_attr3_leaf_read
Christoph Hellwig [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: remove the mappedbno argument to xfs_attr3_leaf_read

Source kernel commit: dfb8759408a9dd8a31a222ed0987bad3e83b50a0

This argument is always hard coded to -1, so remove it.

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 the mappedbno argument to xfs_da_reada_buf
Christoph Hellwig [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: remove the mappedbno argument to xfs_da_reada_buf

Source kernel commit: 06566fda428e6420aa993e32845b165936fb50d6

Replace the mappedbno argument with the simple flags for xfs_da_reada_buf
and xfs_dir3_data_readahead.

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: improve the xfs_dabuf_map calling conventions
Christoph Hellwig [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: improve the xfs_dabuf_map calling conventions

Source kernel commit: 199e9ba4e4a9927f5addb644c1a1e1002e68cc30

Use a flags argument with the XFS_DABUF_MAP_HOLE_OK flag to signal that
a hole is okay and not corruption, and return 0 with *nmap set to 0 to
signal that case in the return value instead of a nameless -1 return
code.

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: refactor xfs_dabuf_map
Christoph Hellwig [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: refactor xfs_dabuf_map

Source kernel commit: 45feef8f50b94d56d6a433ad5baf5cdf58e3db98

Merge xfs_buf_map_from_irec and xfs_da_map_covers_blocks into a single
loop in the caller.

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 mappedbno handling in xfs_da_{get,read}_buf
Christoph Hellwig [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: simplify mappedbno handling in xfs_da_{get,read}_buf

Source kernel commit: fa0d44ec7faab82da468aa7ab4f0c2614cadf7e7

Shortcut the creation of xfs_bmbt_irec and xfs_buf_map for the case
where the callers passed an already mapped xfs_daddr_t.  This is in
preparation for splitting these cases out entirely later.  Also reject
the mappedbno case for xfs_da_reada_buf as no callers currently uses
it and it will be removed soon.

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 kmem_zone_free() wrapper
Carlos Maiolino [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: Remove kmem_zone_free() wrapper

Source kernel commit: 377bcd5f3b7f46f50fdad1fed639c07f8c9f68cb

We can remove it now, without needing to rework the KM_ flags.

Use kmem_cache_free() directly.

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: fix attr leaf header freemap.size underflow
Brian Foster [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: fix attr leaf header freemap.size underflow

Source kernel commit: 2a2b5932db67586bacc560cc065d62faece5b996

The leaf format xattr addition helper xfs_attr3_leaf_add_work()
adjusts the block freemap in a couple places. The first update drops
the size of the freemap that the caller had already selected to
place the xattr name/value data. Before the function returns, it
also checks whether the entries array has encroached on a freemap
range by virtue of the new entry addition. This is necessary because
the entries array grows from the start of the block (but end of the
block header) towards the end of the block while the name/value data
grows from the end of the block in the opposite direction. If the
associated freemap is already empty, however, size is zero and the
subtraction underflows the field and causes corruption.

This is reproduced rarely by generic/070. The observed behavior is
that a smaller sized freemap is aligned to the end of the entries
list, several subsequent xattr additions land in larger freemaps and
the entries list expands into the smaller freemap until it is fully
consumed and then underflows. Note that it is not otherwise a
corruption for the entries array to consume an empty freemap because
the nameval list (i.e. the firstused pointer in the xattr header)
starts beyond the end of the corrupted freemap.

Update the freemap size modification to account for the fact that
the freemap entry can be empty and thus stale.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: remove duplicated include from xfs_dir2_data.c
YueHaibing [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: remove duplicated include from xfs_dir2_data.c

Source kernel commit: eb0d21637f893b545a320595e8b3ebef5b819433

Remove duplicated include.

Signed-off-by: YueHaibing <yuehaibing@huawei.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 structure members & simple typedefs
Eric Sandeen [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: remove unused structure members & simple typedefs

Source kernel commit: a55cefccaaa825169f8649fd3b2a78b15893e7a9

Remove some unused typedef'd simple types, and some unused
structure members.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: remove unused typedef definitions
Eric Sandeen [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: remove unused typedef definitions

Source kernel commit: 35dab307c8e912306cf38d974d3c7f7adc090bce

Remove some typdefs for type_t's that are no longer referred to
by their typedef'd types.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: remove the xfs_qoff_logitem_t typedef
Pavel Reichl [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: remove the xfs_qoff_logitem_t typedef

Source kernel commit: d0bdfb106907e4a3ef4f25f6d27e392abf41f3a0

Signed-off-by: Pavel Reichl <preichl@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: fix a comment]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: remove the xfs_disk_dquot_t and xfs_dquot_t
Pavel Reichl [Wed, 22 Jan 2020 16:29:45 +0000 (11:29 -0500)]
xfs: remove the xfs_disk_dquot_t and xfs_dquot_t

Source kernel commit: aefe69a45d84901c702f87672ec1e93de1d03f73

Signed-off-by: Pavel Reichl <preichl@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: fix some of the comments]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: avoid time_t in user api
Arnd Bergmann [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: avoid time_t in user api

Source kernel commit: e8777b27ca8a6946bd69ad6a0f282e519c895e4b

The ioctl definitions for XFS_IOC_SWAPEXT, XFS_IOC_FSBULKSTAT and
XFS_IOC_FSBULKSTAT_SINGLE are part of libxfs and based on time_t.

The definition for time_t differs between current kernels and coming
32-bit libc variants that define it as 64-bit. For most ioctls, that
means the kernel has to be able to handle two different command codes
based on the different structure sizes.

The same solution could be applied for XFS_IOC_SWAPEXT, but it would
not work for XFS_IOC_FSBULKSTAT and XFS_IOC_FSBULKSTAT_SINGLE because
the structure with the time_t is passed through an indirect pointer,
and the command number itself is based on struct xfs_fsop_bulkreq,
which does not differ based on time_t.

This means any solution that can be applied requires a change of the
ABI definition in the xfs_fs.h header file, as well as doing the same
change in any user application that contains a copy of this header.

The usual solution would be to define a replacement structure and
use conditional compilation for the ioctl command codes to use
one or the other, such as

#define XFS_IOC_FSBULKSTAT_OLD _IOWR('X', 101, struct xfs_fsop_bulkreq)
#define XFS_IOC_FSBULKSTAT_NEW _IOWR('X', 129, struct xfs_fsop_bulkreq)
#define XFS_IOC_FSBULKSTAT ((sizeof(time_t) == sizeof(__kernel_long_t)) ? \
XFS_IOC_FSBULKSTAT_OLD : XFS_IOC_FSBULKSTAT_NEW)

After this, the kernel would be able to implement both
XFS_IOC_FSBULKSTAT_OLD and XFS_IOC_FSBULKSTAT_NEW handlers on
32-bit architectures with the correct ABI for either definition
of time_t.

However, as long as two observations are true, a much simpler solution
can be used:

1. xfsprogs is the only user space project that has a copy of this header
2. xfsprogs already has a replacement for all three affected ioctl commands,
based on the xfs_bulkstat structure to pass 64-bit timestamps
regardless of the architecture

Based on those assumptions, changing xfs_bstime to use __kernel_long_t
instead of time_t in both the kernel and in xfsprogs preserves the current
ABI for any libc definition of time_t and solves the problem of passing
64-bit timestamps to 32-bit user space.

If either of the two assumptions is invalid, more discussion is needed
for coming up with a way to fix as much of the affected user space
code as possible.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
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: Fix deadlock between AGI and AGF when target_ip exists in xfs_rename()
kaixuxia [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: Fix deadlock between AGI and AGF when target_ip exists in xfs_rename()

Source kernel commit: 93597ae8dac0149b5c00b787cba6bf7ba213e666

When target_ip exists in xfs_rename(), the xfs_dir_replace() call may
need to hold the AGF lock to allocate more blocks, and then invoking
the xfs_droplink() call to hold AGI lock to drop target_ip onto the
unlinked list, so we get the lock order AGF->AGI. This would break the
ordering constraint on AGI and AGF locking - inode allocation locks
the AGI, then can allocate a new extent for new inodes, locking the
AGF after the AGI.

In this patch we check whether the replace operation need more
blocks firstly. If so, acquire the agi lock firstly to preserve
locking order(AGI/AGF). Actually, the locking order problem only
occurs when we are locking the AGI/AGF of the same AG. For multiple
AGs the AGI lock will be released after the transaction committed.

Signed-off-by: kaixuxia <kaixuxia@tencent.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: reword the comment]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: don't reset the "inode core" in xfs_iread
Christoph Hellwig [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: don't reset the "inode core" in xfs_iread

Source kernel commit: 048a35d2f0b4cfeb24cbb7fe59e78124d8e7dc73

We have the exact same memset in xfs_inode_alloc, which is always called
just before xfs_iread.

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: merge the projid fields in struct xfs_icdinode
Christoph Hellwig [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: merge the projid fields in struct xfs_icdinode

Source kernel commit: de7a866fd41b227b0aa6e9cbeb0dae221c12f542

There is no point in splitting the fields like this in an purely
in-memory structure.

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: use a struct timespec64 for the in-core crtime
Christoph Hellwig [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: use a struct timespec64 for the in-core crtime

Source kernel commit: 8d2d878db897d7501aaa2f72e10bb28295bb5498

struct xfs_icdinode is purely an in-memory data structure, so don't use
a log on-disk structure for it.  This simplifies the code a bit, and
also reduces our include hell slightly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: fix a minor indenting problem in xfs_trans_ichgtime]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: devirtualize ->m_dirnameops
Christoph Hellwig [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: devirtualize ->m_dirnameops

Source kernel commit: d8d11fc703a22bbe3939e08b08396fa6b816719a

Instead of causing a relatively expensive indirect call for each
hashing and comparism of a file name in a directory just use an
inline function and a simple branch on the ASCII CI bit.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: fix unused variable warning]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
5 years agoxfs: convert open coded corruption check to use XFS_IS_CORRUPT
Darrick J. Wong [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: convert open coded corruption check to use XFS_IS_CORRUPT

Source kernel commit: a71895c5dad1ab8cf30622e208d148298ab602e5

Convert the last of the open coded corruption check and report idioms to
use the XFS_IS_CORRUPT macro.

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: kill the XFS_WANT_CORRUPT_* macros
Darrick J. Wong [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: kill the XFS_WANT_CORRUPT_* macros

Source kernel commit: f9e0370648b9f9908ec97f44459a1152aecbbf45

The XFS_WANT_CORRUPT_* macros conceal subtle side effects such as the
creation of local variables and redirections of the code flow.  This is
pretty ugly, so replace them with explicit XFS_IS_CORRUPT tests that
remove both of those ugly points.  The change was performed with the
following coccinelle script:

@@
expression mp, test;
identifier label;
@@

- XFS_WANT_CORRUPTED_GOTO(mp, test, label);
+ if (XFS_IS_CORRUPT(mp, !test)) { error = -EFSCORRUPTED; goto label; }

@@
expression mp, test;
@@

- XFS_WANT_CORRUPTED_RETURN(mp, test);
+ if (XFS_IS_CORRUPT(mp, !test)) return -EFSCORRUPTED;

@@
expression mp, lval, rval;
@@

- XFS_IS_CORRUPT(mp, !(lval == rval))
+ XFS_IS_CORRUPT(mp, lval != rval)

@@
expression mp, e1, e2;
@@

- XFS_IS_CORRUPT(mp, !(e1 && e2))
+ XFS_IS_CORRUPT(mp, !e1 || !e2)

@@
expression e1, e2;
@@

- !(e1 == e2)
+ e1 != e2

@@
expression e1, e2, e3, e4, e5, e6;
@@

- !(e1 == e2 && e3 == e4) || e5 != e6
+ e1 != e2 || e3 != e4 || e5 != e6

@@
expression e1, e2, e3, e4, e5, e6;
@@

- !(e1 == e2 || (e3 <= e4 && e5 <= e6))
+ e1 != e2 && (e3 > e4 || e5 > e6)

@@
expression mp, e1, e2;
@@

- XFS_IS_CORRUPT(mp, !(e1 <= e2))
+ XFS_IS_CORRUPT(mp, e1 > e2)

@@
expression mp, e1, e2;
@@

- XFS_IS_CORRUPT(mp, !(e1 < e2))
+ XFS_IS_CORRUPT(mp, e1 >= e2)

@@
expression mp, e1;
@@

- XFS_IS_CORRUPT(mp, !!e1)
+ XFS_IS_CORRUPT(mp, e1)

@@
expression mp, e1, e2;
@@

- XFS_IS_CORRUPT(mp, !(e1 || e2))
+ XFS_IS_CORRUPT(mp, !e1 && !e2)

@@
expression mp, e1, e2, e3, e4;
@@

- XFS_IS_CORRUPT(mp, !(e1 == e2) && !(e3 == e4))
+ XFS_IS_CORRUPT(mp, e1 != e2 && e3 != e4)

@@
expression mp, e1, e2, e3, e4;
@@

- XFS_IS_CORRUPT(mp, !(e1 <= e2) || !(e3 >= e4))
+ XFS_IS_CORRUPT(mp, e1 > e2 || e3 < e4)

@@
expression mp, e1, e2, e3, e4;
@@

- XFS_IS_CORRUPT(mp, !(e1 == e2) && !(e3 <= e4))
+ XFS_IS_CORRUPT(mp, e1 != e2 && e3 > e4)

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: actually check xfs_btree_check_block return in xfs_btree_islastblock
Darrick J. Wong [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: actually check xfs_btree_check_block return in xfs_btree_islastblock

Source kernel commit: 27d9ee577dccec94fb0fc1a14728de64db342f86

Coverity points out that xfs_btree_islastblock doesn't check the return
value of xfs_btree_check_block.  Since the question "Does the cursor
point to the last block in this level?" only makes sense if the caller
previously performed a lookup or seek operation, the block should
already have been checked.

Therefore, check the return value in an ASSERT and turn the whole thing
into a static inline predicate.

Coverity-id: 114069
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: always pass a valid hdr to xfs_dir3_leaf_check_int
Christoph Hellwig [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: always pass a valid hdr to xfs_dir3_leaf_check_int

Source kernel commit: 23220fe260c4b307da1c1fa82a944c50bf0742e4

Move the code for extracting the incore header to the only caller that
didn't already do that.

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: merge xfs_dir2_data_freescan and xfs_dir2_data_freescan_int
Christoph Hellwig [Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)]
xfs: merge xfs_dir2_data_freescan and xfs_dir2_data_freescan_int

Source kernel commit: ae42976de7f1022e6d83f5560debc072929921a9

There is no real need for xfs_dir2_data_freescan wrapper, so rename
xfs_dir2_data_freescan_int to xfs_dir2_data_freescan and let the
callers dereference the mount pointer from the inode.

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 the now unused dir ops infrastructure
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: remove the now unused dir ops infrastructure

Source kernel commit: 957ee13e204a5ffe814139aa89e62eece4b969fd

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: devirtualize ->data_get_ftype and ->data_put_ftype
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: devirtualize ->data_get_ftype and ->data_put_ftype

Source kernel commit: 59b8b465058ec203493c0436f243263051e08f5a

Replace the ->data_get_ftype and ->data_put_ftype dir ops methods with
directly called xfs_dir2_data_get_ftype and xfs_dir2_data_put_ftype
helpers that takes care of the differences between the directory format
with and without the file type field.

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: devirtualize ->data_bestfree_p
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: devirtualize ->data_bestfree_p

Source kernel commit: 1848b607a9ad084db0180118304b9af2be68384e

Replace the ->data_bestfree_p dir ops method with a directly called
xfs_dir2_data_bestfree_p helper that takes care of the differences
between the v4 and v5 on-disk format.

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: cleanup xfs_dir2_data_entsize
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: cleanup xfs_dir2_data_entsize

Source kernel commit: 711c7dbf5fdafdbb2fb906b38cefb113bfdd4a79

Remove the XFS_DIR2_DATA_ENTSIZE and XFS_DIR3_DATA_ENTSIZE and open
code them in their only caller, which now becomes so simple that
we can turn it into an inline function.

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: move the dir2 data block fixed offsets to struct xfs_da_geometry
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: move the dir2 data block fixed offsets to struct xfs_da_geometry

Source kernel commit: d73e1cee8add0d18d5401b81db2351b9e8af899a

Move the data block fixed offsets towards our structure for dir/attr
geometry parameters.

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: devirtualize ->data_entry_tag_p
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: devirtualize ->data_entry_tag_p

Source kernel commit: 7e8ae7bd1c5d806316e6b6403ac2dd0be7a1f82b

Replace the ->data_entry_tag_p dir ops method with a directly called
xfs_dir2_data_entry_tag_p helper that takes care of the differences
between the directory format with and without the file type field.

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: devirtualize ->data_entsize
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: devirtualize ->data_entsize

Source kernel commit: fdbb8c5b805c19bc2764aa1b91952e75e4c1c086

Replace the ->data_entsize dir ops method with a directly called
xfs_dir2_data_entsize helper that takes care of the differences between
the directory format with and without the file type field.

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: replace xfs_dir3_data_endp with xfs_dir3_data_end_offset
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: replace xfs_dir3_data_endp with xfs_dir3_data_end_offset

Source kernel commit: 5c072127d31d3a605a3048dc5d3fdfc0cdd47212

All the callers really want an offset into the buffer, so adopt
the helper to return that instead.

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 the now unused ->data_entry_p method
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: remove the now unused ->data_entry_p method

Source kernel commit: 9eedae10899af882f3d34dc49c89d3220cd145f6

Now that all users use the data_entry_offset field this method is
unused and can be removed.

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_repair: stop using ->data_entry_p()
Eric Sandeen [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs_repair: stop using ->data_entry_p()

The ->data_entry_p() op went away in v5.5 kernelspace, so rework
xfs_repair to use ->data_entry_offset instead, in preparation
for the v5.5 libxfs backport.

This could later be cleaned up to use offsets as was done
in kernel commit 8073af5153c for example.

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: cleanup __xfs_dir3_data_check
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: cleanup __xfs_dir3_data_check

Source kernel commit: 48a71399e7477043ee25573b3df2505787fcf0c4

Use an offset as the main means for iteration, and only do pointer
arithmetics to find the data/unused entries.

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: cleanup xfs_dir2_data_freescan_int
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: cleanup xfs_dir2_data_freescan_int

Source kernel commit: 62479f573459827edacb296dac4ad7ca714ab71c

Use an offset as the main means for iteration, and only do pointer
arithmetics to find the data/unused entries.

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: cleanup xfs_dir2_block_to_sf
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: cleanup xfs_dir2_block_to_sf

Source kernel commit: 8073af5153ce25fd936e5c190d6ccf30b9cae89d

Use an offset as the main means for iteration, and only do pointer
arithmetics to find the data/unused entries.

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 the ->data_unused_p method
Christoph Hellwig [Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)]
xfs: remove the ->data_unused_p method

Source kernel commit: ee641d5af5e638d53d9bcde459836b1cb90f12e2

Replace the two users of the ->data_unused_p dir ops method with a
direct calculation using ->data_entry_offset, and clean them up a bit.
xfs_dir2_sf_to_block already had an offset variable containing the
value of ->data_entry_offset, which we are now reusing to make it
clear that the initial freespace entry is at the same place that
we later fill in the 1 entry, and in xfs_dir3_data_init the function
is cleaned up a bit to keep the initialization of fields of a given
structure close to each other, and to avoid a local variable.

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 the ->data_dot_entry_p and ->data_dotdot_entry_p methods
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: remove the ->data_dot_entry_p and ->data_dotdot_entry_p methods

Source kernel commit: da3ca0df8bd146bf1c83db1b9763189976175e87

The only user of the ->data_dot_entry_p and ->data_dotdot_entry_p
methods is the xfs_dir2_sf_to_block function that builds block format
directorys from a short form directory.  It already uses pointer
arithmetics with a offset variable to do so for the real entries in
the directory, so switch the generation of the . and .. entries to
the same scheme, and clean up some of the later pointer arithmetics
to use bp->b_addr directly as well and avoid some casts.

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 the data_dotdot_offset field in struct xfs_dir_ops
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: remove the data_dotdot_offset field in struct xfs_dir_ops

Source kernel commit: 2eb68a5d3619b80dec745f71df8af5f80cda16f8

The data_dotdot_offset value is always equal to data_entry_offset plus
the fixed size of the "." entry.  Right now calculating that fixed size
requires an indirect call, but by the end of this series it will be
an inline function that can be constant folded.

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 the data_dot_offset field in struct xfs_dir_ops
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: remove the data_dot_offset field in struct xfs_dir_ops

Source kernel commit: 1682310474b2f223951ee46f21e34eb462cf71c2

The data_dot_offset value is always equal to data_entry_offset given
that "." is always the first entry in the directory.

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 the unused ->data_first_entry_p method
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: remove the unused ->data_first_entry_p method

Source kernel commit: c81484e2b97f27683b5bdc3aee266d4685a48f8b

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: devirtualize ->sf_get_ftype and ->sf_put_ftype
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: devirtualize ->sf_get_ftype and ->sf_put_ftype

Source kernel commit: 4501ed2a3a863ae5d43629b98f6a4d7f6147c4df

Replace the ->sf_get_ftype and ->sf_put_ftype dir ops methods with
directly called xfs_dir2_sf_get_ftype and xfs_dir2_sf_put_ftype helpers
that takes care of the differences between the directory format with and
without the file type field.

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: devirtualize ->sf_get_ino and ->sf_put_ino
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: devirtualize ->sf_get_ino and ->sf_put_ino

Source kernel commit: 93b1e96a42006813e58e5052718f7b24a9312258

Replace the ->sf_get_ino and ->sf_put_ino dir ops methods with directly
called xfs_dir2_sf_get_ino and xfs_dir2_sf_put_ino helpers that take care
of the difference between the directory format with and without the file
type field.  Also move xfs_dir2_sf_get_parent_ino and
xfs_dir2_sf_put_parent_ino to xfs_dir2_sf.c with the rest of the
low-level short form entry handling and use XFS_MAXINUMBER istead of
opencoded constants.

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: devirtualize ->sf_entsize and ->sf_nextentry
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: devirtualize ->sf_entsize and ->sf_nextentry

Source kernel commit: 50f6bb6b7aea8177110e55355c455f18912a7a73

Just check for file-type enabled directories directly.

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: devirtualize ->sf_get_parent_ino and ->sf_put_parent_ino
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: devirtualize ->sf_get_parent_ino and ->sf_put_parent_ino

Source kernel commit: 84915e1bdddf9de3edf79a2813982b886e76658f

The parent inode handling is the same for all directory format variants,
just use direct calls instead of going through a pointless indirect
call.

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: devirtualize ->db_to_fdb and ->db_to_fdindex
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: devirtualize ->db_to_fdb and ->db_to_fdindex

Source kernel commit: 3d92c93b7065be28eda33f92681d2f1121fbf8bf

Now that the max bests value is in struct xfs_da_geometry both instances
of ->db_to_fdb and ->db_to_fdindex are identical.  Replace them with
local xfs_dir2_db_to_fdb and xfs_dir2_db_to_fdindex functions in
xfs_dir2_node.c.

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: move the max dir2 free bests count to struct xfs_da_geometry
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: move the max dir2 free bests count to struct xfs_da_geometry

Source kernel commit: 5893e4feb0eac11aab7b93ff9fe7e6e58bcec5ec

Move the max free bests count towards our structure for dir/attr
geometry parameters.

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: move the dir2 free header size to struct xfs_da_geometry
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: move the dir2 free header size to struct xfs_da_geometry

Source kernel commit: ed1d612fbe6ba95a4d16b56bbfb1f90d48a42149

Move the free header size towards our structure for dir/attr geometry
parameters.

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: add a bests pointer to struct xfs_dir3_icfree_hdr
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: add a bests pointer to struct xfs_dir3_icfree_hdr

Source kernel commit: a84f3d5cb04f7dff1bf6904f0a05bc8df16137fb

All but two callers of the ->free_bests_p dir operation already have a
struct xfs_dir3_icfree_hdr from a previous call to
xfs_dir2_free_hdr_from_disk at hand.  Add a pointer to the bests to
struct xfs_dir3_icfree_hdr to clean up this pattern.  To optimize this
pattern, pass the struct xfs_dir3_icfree_hdr to xfs_dir2_free_log_bests
instead of recalculating the pointer there.

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: make the xfs_dir3_icfree_hdr available to xfs_dir2_node_addname_int
Christoph Hellwig [Wed, 22 Jan 2020 16:29:42 +0000 (11:29 -0500)]
xfs: make the xfs_dir3_icfree_hdr available to xfs_dir2_node_addname_int

Source kernel commit: 195b0a44ab73f0275683e7a0b1985751ea2ef6ae

Return the xfs_dir3_icfree_hdr used by the helpers called from
xfs_dir2_node_addname_int to the main function to prepare for the
next round of changes where we'll use the ichdr in xfs_dir3_icfree_hdr
to avoid extra operations to find the bests pointers.

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: devirtualize ->free_hdr_to_disk
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: devirtualize ->free_hdr_to_disk

Source kernel commit: 200dada70008a1204ddd3d95250d23d6477e20e6

Replace the ->free_hdr_to_disk dir ops method with a directly called
xfs_dir2_free_hdr_to_disk helper that takes care of the differences
between the v4 and v5 on-disk format.

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: devirtualize ->free_hdr_from_disk
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: devirtualize ->free_hdr_from_disk

Source kernel commit: 5ba30919a6fcf0d3d52507082ea67fab32c8bb29

Replace the ->free_hdr_from_disk dir ops method with a directly called
xfs_dir_free_hdr_from_disk helper that takes care of the differences
between the v4 and v5 on-disk format.

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: move the max dir2 leaf entries count to struct xfs_da_geometry
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: move the max dir2 leaf entries count to struct xfs_da_geometry

Source kernel commit: 478c7835cb8ee28e73e732642866995f8555df7e

Move the max leaf entries count towards our structure for dir/attr
geometry parameters.

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: move the dir2 leaf header size to struct xfs_da_geometry
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: move the dir2 leaf header size to struct xfs_da_geometry

Source kernel commit: 545910bcc875377160b7b669e790865602a006f3

Move the leaf header size towards our structure for dir/attr geometry
parameters.

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: add an entries pointer to struct xfs_dir3_icleaf_hdr
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: add an entries pointer to struct xfs_dir3_icleaf_hdr

Source kernel commit: 787b0893ad1e315ea014dc3f0e01a5bc9236c623

All callers of the ->node_tree_p dir operation already have a struct
xfs_dir3_icleaf_hdr from a previous call to xfs_da_leaf_hdr_from_disk at
hand, or just need slight changes to the calling conventions to do so.
Add a pointer to the entries to struct xfs_dir3_icleaf_hdr to clean up
this pattern.  To make this possible the xfs_dir3_leaf_log_ents function
grow a new argument to pass the xfs_dir3_icleaf_hdr that call callers
already have, and xfs_dir2_leaf_lookup_int returns the
xfs_dir3_icleaf_hdr to the callers so that they can later use it.

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: devirtualize ->leaf_hdr_to_disk
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: devirtualize ->leaf_hdr_to_disk

Source kernel commit: 163fbbb3568b6acf762449b8aa7713c764cf860a

Replace the ->leaf_hdr_to_disk dir ops method with a directly called
xfs_dir_leaf_hdr_to_disk helper that takes care of the differences
between the v4 and v5 on-disk format.

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: devirtualize ->leaf_hdr_from_disk
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: devirtualize ->leaf_hdr_from_disk

Source kernel commit: 518425560a8b6ec7516505846c1b79623b467148

Replace the ->leaf_hdr_from_disk dir ops method with a directly called
xfs_dir2_leaf_hdr_from_disk helper that takes care of the differences
between the v4 and v5 on-disk format.

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: move the node header size to struct xfs_da_geometry
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: move the node header size to struct xfs_da_geometry

Source kernel commit: 3b34441309f364bba59a6ee5d1aa32206456142f

Move the node header size field to struct xfs_da_geometry, and remove
the now unused non-directory dir ops infrastructure.

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: add a btree entries pointer to struct xfs_da3_icnode_hdr
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: add a btree entries pointer to struct xfs_da3_icnode_hdr

Source kernel commit: 51908ca75feb5b2dd4f0d0146f9c92775520812c

All but two callers of the ->node_tree_p dir operation already have a
xfs_da3_icnode_hdr from a previous call to xfs_da3_node_hdr_from_disk at
hand.  Add a pointer to the btree entries to struct xfs_da3_icnode_hdr
to clean up this pattern.  The two remaining callers now expand the
whole header as well, but that isn't very expensive and not in a super
hot path anyway.

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: devirtualize ->node_hdr_to_disk
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: devirtualize ->node_hdr_to_disk

Source kernel commit: e1c8af1e02c7893f2d056aa44c4daf59fe0881ed

Replace the ->node_hdr_to_disk dir ops method with a directly called
xfs_da_node_hdr_to_disk helper that takes care of the v4 vs v5
difference.

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: devirtualize ->node_hdr_from_disk
Christoph Hellwig [Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)]
xfs: devirtualize ->node_hdr_from_disk

Source kernel commit: f475dc4dc7cc98ad653135db174084a55076b1ba

Replace the ->node_hdr_from_disk dir ops method with a directly called
xfs_da_node_hdr_from_disk helper that takes care of the v4 vs v5
difference.

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>