]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/log
thirdparty/xfsprogs-dev.git
6 years agoxfs: introduce the xfs_iext_cursor abstraction
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: introduce the xfs_iext_cursor abstraction

Source kernel commit: b2b1712a640824e7c131bfdd2585d57bf8ccb39a

Add a new xfs_iext_cursor structure to hide the direct extent map
index manipulations. In addition to the existing lookup/get/insert/
remove and update routines new primitives to get the first and last
extent cursor, as well as moving up and down by one extent are
provided.  Also new are convenience to increment/decrement the
cursor and retreive the new extent, as well as to peek into the
previous/next extent without updating the cursor and last but not
least a macro to iterate over all extents in a fork.

[darrick: rename for_each_iext to for_each_xfs_iext]

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>
[sandeen: use cursor in xfs_repair code as well]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: iterate over extents in xfs_bmap_extents_to_btree
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: iterate over extents in xfs_bmap_extents_to_btree

Source kernel commit: 906abed501bf5a2103946deb7a4a40b31c56f027

This actually makes the function very slightly less efficient for now as we
detour through the expanded irect format between the in-core extent format
and the on-disk one instead of just endian swapping them.  But with the
incore extent btree the in-core one will use a different format and the
representation will be entirely hidden.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: iterate over extents in xfs_iextents_copy
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: iterate over extents in xfs_iextents_copy

Source kernel commit: 71565f4b92048321ba3078877dd1a1149a23550d

This actually makes the function very slightly less efficient for now as we
detour through the expanded irect format between the in-core extent format
and the on-disk one instead of just endian swapping them.  But with the
incore extent btree the in-core one will use a different format and the
representation will be entirely hidden.  It also happens to make the
function a whole more readable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: pass an on-disk extent to xfs_bmbt_validate_extent
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: pass an on-disk extent to xfs_bmbt_validate_extent

Source kernel commit: f36bc228e1b94d9994915cba67588104ebe763ae

This prepares for getting rid of the current in-memory extent format.
At the end of the series we will change the calling convention again
to pass the xfs_bmbt_irec structure once it is available everywhere.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: treat idx as a cursor in xfs_bmap_collapse_extents
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: treat idx as a cursor in xfs_bmap_collapse_extents

Source kernel commit: 42630361003461edd7607c1d459ab9d66ef97813

Stop poking before and after the index and just increment or decrement
it while doing our operations on it to prepare for a new extent list
implementation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: treat idx as a cursor in xfs_bmap_del_extent_*
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: treat idx as a cursor in xfs_bmap_del_extent_*

Source kernel commit: 657fcb23362c9e8a72593b3e4755135f003a7a74

Stop poking before and after the index and just increment or decrement
it while doing our operations on it to prepare for a new extent list
implementation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: treat idx as a cursor in xfs_bmap_add_extent_unwritten_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: treat idx as a cursor in xfs_bmap_add_extent_unwritten_real

Source kernel commit: a681847796df31c036810bce97003f687e1db5f4

Stop poking before and after the index and just increment or decrement
it while doing our operations on it to prepare for a new extent list
implementation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: treat idx as a cursor in xfs_bmap_add_extent_hole_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: treat idx as a cursor in xfs_bmap_add_extent_hole_real

Source kernel commit: 1d2e0089e16642928c76f032c1dbd0eb6da22935

Stop poking before and after the index and just increment or decrement
it while doing our operations on it to prepare for a new extent list
implementation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: treat idx as a cursor in xfs_bmap_add_extent_hole_delay
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: treat idx as a cursor in xfs_bmap_add_extent_hole_delay

Source kernel commit: 41d196f439509fd8b09364ca1ba48194cccc6d6e

Stop poking before and after the index and just increment or decrement
it while doing our operations on it to prepare for a new extent list
implementation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: treat idx as a cursor in xfs_bmap_add_extent_delay_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: treat idx as a cursor in xfs_bmap_add_extent_delay_real

Source kernel commit: 0d045540ed57e68b9ddcf5c325279a7e5ede7bbf

Stop poking before and after the index and just increment or decrement
it while doing our operations on it to prepare for a new extent list
implementation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: remove a duplicate assignment in xfs_bmap_add_extent_delay_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: remove a duplicate assignment in xfs_bmap_add_extent_delay_real

Source kernel commit: bf99971c8200fcb3e16d880194f5d559aca09576

Reported-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: don't create overlapping extents in xfs_bmap_add_extent_delay_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: don't create overlapping extents in xfs_bmap_add_extent_delay_real

Source kernel commit: 1bfd7618cbf2de630c845f60f5370671c2cd1c5d

Two cases in xfs_bmap_add_extent_delay_real currently insert a new
extent before updating the existing one that is being split.  While
this works fine with a simple extent list, a more complex tree can't
easily cope with overlapping extent.  Reshuffle the code a bit to update
the slot of the existing delalloc extent to the new real extent before
inserting the shortened delalloc extent before or after it.  This
avoids the overlapping extents while still allowing to update the
br_startblock field of the delalloc extent with the updated indirect
block reservation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: convert remaining xfs_sb_version_... checks to bool
Dave Chinner [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: convert remaining xfs_sb_version_... checks to bool

Source kernel commit: 5d0eda0307ca20c5c58b1abd2a8ba822e0763b43

Some were missed in the pass that converted the function return
values from int to bool. Update the remaining ones for consistency.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: move error injection tags into their own file
Darrick J. Wong [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: move error injection tags into their own file

Source kernel commit: e9e899a2a8c3c23b3084b048466f417ed92286d3

Move the error injection tag names into a libxfs header so that we can
share it between kernel and userspace.

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>
6 years agoxfs: remove inode log format typedef
Darrick J. Wong [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: remove inode log format typedef

Source kernel commit: 06b1132120d446bbaf844cbbae51f0afd3baacb8

Remove xfs_inode_log_format_t now that xfs_inode_log_format is
explicitly padded and therefore is a real on-disk structure.  This
enables xfs/122 to check the size of the structure.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
[sandeen: same treatment in libxlog & logprint/ ]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: remove the inode log format from the inode log item
Christoph Hellwig [Fri, 17 Nov 2017 04:11:34 +0000 (22:11 -0600)] 
xfs: remove the inode log format from the inode log item

Source kernel commit: 2f251293b09065118d78ae4e883e5639cc22f94e

xfs: remove the inode log format from the inode log item

No need to keep the inode log format around all the time, we can
easily generate it at iop_format time.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
[sandeen: matching change in userspace xfs_trans.h]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: remove redundant assignment to variable bit
Colin Ian King [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: remove redundant assignment to variable bit

Source kernel commit: c06641169e861d6446a220cd7f0d22c6c88da8e1

Variable bit is being assigned a value that is never read, hence
the assignment is redundant and can be removed. Cleans up clang
warning:

fs/xfs/libxfs/xfs_rtbitmap.c:675:3: warning: Value stored to
'bit' is never read

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: compare btree block keys to parent block's keys during scrub
Darrick J. Wong [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: compare btree block keys to parent block's keys during scrub

Source kernel commit: 2fdbec5cbeb93349836d682b1caa5cc72d1b7018

When we're done checking all the records/keys in a btree block, compute
the low and high key of the block and compare them to the associated key
in the parent btree block.

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>
6 years agoxfs: abort dir/attr btree operation if btree is obviously weird
Darrick J. Wong [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: abort dir/attr btree operation if btree is obviously weird

Source kernel commit: 8210f4dda2d7642cb7c882db55e53d899cced401

Abort an dir/attr btree operation if the attr btree has obvious problems
like loops back to the root or pointers don't point down the tree.
Found by fuzzing btree[0].before to zero in xfs/402, which livelocks on
the cycle in the attr btree.

Apply the same checks to xfs_da3_node_lookup_int.

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>
6 years agoxfs: add a new xfs_iext_lookup_extent_before helper
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: add a new xfs_iext_lookup_extent_before helper

Source kernel commit: dc56015faff1bc9e7493c2b28302c423a02237c2

This helper looks up the last extent the covers space before the passed
in block number.  This is useful for truncate and similar operations that
operate backwards over the extent list.  For xfs_bunmapi it also is
a slight optimization as we can return early if there are not extents
at or below the end of the to be truncated range.

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>
6 years agoxfs: merge xfs_bmap_read_extents into xfs_iread_extents
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: merge xfs_bmap_read_extents into xfs_iread_extents

Source kernel commit: 211e95bbab71359e56f3d9adce1b4d6de8e18471

xfs_iread_extents is just a trivial wrapper, there is no good reason
to keep the two separate.

[darrick: minor fixups having left xfs_bmbt_validate_extent intact]

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>
6 years agoxfs: rewrite xfs_bmap_first_unused to make better use of xfs_iext_get_extent
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: rewrite xfs_bmap_first_unused to make better use of xfs_iext_get_extent

Source kernel commit: 29b3e94a9c65224733fe8de49b07b7227f95f821

Look at the return value of xfs_iext_get_extent instead of figuring out
the extent count first and looping up to 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>
6 years agoxfs: don't rely on extent indices in xfs_bmap_insert_extents
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: don't rely on extent indices in xfs_bmap_insert_extents

Source kernel commit: 5936dc543cfd27de74cd34fdc928b5115cec53d1

Rewrite xfs_bmap_insert_extents so that we don't rely on extent indices
except for iterating over them.  Not being able to iterate to the previous
extent or finding the extent that stop_fsb is in are sufficient exit
conditions, and we don't need to do any extent count games given that:

a) we already flushed all delalloc extents past our start offset
before doing the operation
b) xfs_iext_count() includes delalloc extents 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>
6 years agoxfs: don't rely on extent indices in xfs_bmap_collapse_extents
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: don't rely on extent indices in xfs_bmap_collapse_extents

Source kernel commit: 40591bdbccc47661050d98200ab65e77fa2324bd

Rewrite xfs_bmap_collapse_extents so that we don't rely on extent indices
except for iterating over them.  Not being able to iterate to the next
extent is a sufficient exit condition, and we don't need to do any extent
count games given that:

a) we already flushed all delalloc extents past our start offset
before doing the operation
b) xfs_iext_count() includes delalloc extents 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>
6 years agoxfs: update got in xfs_bmap_shift_update_extent
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: update got in xfs_bmap_shift_update_extent

Source kernel commit: 11f75b3bbad57998d1af99391ec3a8e076ab4dd9

This way the caller gets the proper updated extent returned in got.

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>
6 years agoxfs: remove xfs_bmse_shift_one
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: remove xfs_bmse_shift_one

Source kernel commit: bf8062800ad2d1ca22950c28910196bcbda89108

Instead do the actual left and right shift work in the callers, and just
keep a helper to update the bmap and rmap btrees as well as the in-core
extent list.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: split xfs_bmap_shift_extents
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: split xfs_bmap_shift_extents

Source kernel commit: ecfea3f0c8c64ce7375f4be4506996968958bd01

Have a separate helper for insert vs collapse, as this prepares us for
simplifying the code in the next patches.

Also changed the done output argument to a bool intead of int for both
new functions.

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>
6 years agoxfs: remove XFS_BMAP_MAX_SHIFT_EXTENTS
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: remove XFS_BMAP_MAX_SHIFT_EXTENTS

Source kernel commit: 6b18af0dfd1695c1d53a2eeead838a90c27b7cb4

The define was always set to 1, which means looping until we reach is
was dead code from the start.

Also remove an initialization of next_fsb for the done case that doesn't
fit the new code flow - it was never checked by the caller in the done
case to start with.

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>
6 years agoxfs: remove if_rdev
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: remove if_rdev

Source kernel commit: 66f364649d870c7541c30a2f02a32fd4c88684f0

We can simply use the i_rdev field in the Linux inode and just convert
to and from the XFS dev_t when reading or logging/writing the inode.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[sandeen: add i_rdev to our mocked up inode in userspace]
[djwong: use IRIX_DEV macros, assign in i_rdev in libxfs_ialloc]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: remove the never fully implemented UUID fork format
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: remove the never fully implemented UUID fork format

Source kernel commit: 42b67dc6ffbf2701cfc578b3e706d560a80b6674

Remove the dead code dealing with the UUID fork format that was never
implemented in Linux (and neither in IRIX as far as I know).

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>
[sandeen: use __u8 not u8 for now, adapt xfs_logprint]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: remove XFS_BMAP_TRACE_EXLIST
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: remove XFS_BMAP_TRACE_EXLIST

Source kernel commit: e8e0e170e2e17b601b86edb86f58dbf7c599e4b3

Instead of looping over all extents in some debug-only helper just
insert trace points into the loops that already exist in the calling
functions.

Also split the xfs_extlist trace point into one each for reading and
writing extents from disk.

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>
[sandeen: userspace-specific tracepoint macro updates]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: move pre/post-bmap tracing into xfs_iext_update_extent
Christoph Hellwig [Fri, 17 Nov 2017 04:11:33 +0000 (22:11 -0600)] 
xfs: move pre/post-bmap tracing into xfs_iext_update_extent

Source kernel commit: ca5d8e5b7b9030005e38e7c43e08c0cd4eb2a78f

xfs_iext_update_extent already has basically all the information needed
to centralize the bmap pre/post tracing.  We just need to pass inode +
bmap state instead of the inode fork pointer to get all trace annotations.

In addition to covering all the existing trace points this gives us
tracing coverage for the extent shifting operations for free.

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>
6 years agoxfs: remove post-bmap tracing in xfs_bmap_local_to_extents
Christoph Hellwig [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: remove post-bmap tracing in xfs_bmap_local_to_extents

Source kernel commit: d138604fb1a6500064b50e75f220e6cbce785493

Now that we use xfs_iext_insert this is already covered by the tracing
in that 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>
6 years agoxfs: make better use of the 'state' variable in xfs_bmap_del_extent_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: make better use of the 'state' variable in xfs_bmap_del_extent_real

Source kernel commit: 35e62da55f4b2450cbb51c9734d745a799e2a793

We already have all the information about the fork a=D1=95 well as additional
tracing information, so pass that to xfs_iext_remove().

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>
6 years agoxfs: add a xfs_bmap_fork_to_state helper
Christoph Hellwig [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: add a xfs_bmap_fork_to_state helper

Source kernel commit: 060ea65b39409f3b9952dfa6db5fbe4355e6888a

This creates the right initial bmap state from the passed in inode
fork enum.

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>
6 years agoxfs: scrub quota information
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub quota information

Source kernel commit: c2fc338c87a31f557b57f5143602444ba3cf2c3e

Perform some quick sanity testing of the disk quota information.

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>
6 years agoxfs: scrub realtime bitmap/summary
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub realtime bitmap/summary

Source kernel commit: 29b0767b8beb4c5e3fd94656d51413a4fe8d2d74

Perform simple tests of the realtime bitmap and summary.

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>
6 years agoxfs: scrub directory parent pointers
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub directory parent pointers

Source kernel commit: 0f28b25731f76feda1ec71671754a2b7179ee1ef

Scrub parent pointers, sort of.  For directories, we can ride the
'..' entry up to the parent to confirm that there's at most one
dentry that points back to this directory.

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>
6 years agoxfs: scrub symbolic links
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub symbolic links

Source kernel commit: 2a721dbbc8bf4d76581fb073aa0d9554df56da1a

Create the infrastructure to scrub symbolic link data.

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>
6 years agoxfs: scrub extended attributes
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub extended attributes

Source kernel commit: eec0482e0829eab1da1be693e524c889dc4b168c

Scrub the hash tree, keys, and values in an extended attribute structure.
Refactor the attribute code to use the transaction if the caller supplied
one to avoid buffer deadocks.

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>
6 years agoxfs: scrub directory metadata
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub directory metadata

Source kernel commit: a5c46e5e8912d232b959faf511cd9a17cc829f0a

Scrub the hash tree and all the entries in a directory.

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>
6 years agoxfs: scrub inode block mappings
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub inode block mappings

Source kernel commit: 99d9d8d05da26f47aa8412397407f962bcb4713a

Scrub an individual inode's block mappings to make sure they make sense.

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>
6 years agoxfs: scrub inodes
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub inodes

Source kernel commit: 80e4e12688029e42fc6ab4cf7f229b090c61e6a7

Scrub the fields within an inode.

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>
6 years agoxfs: scrub refcount btrees
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub refcount btrees

Source kernel commit: edc09b528628afb50904106f36de182a00e7eb40

Plumb in the pieces necessary to check the refcount btree.  If rmap is
available, check the reference count by performing an interval query
against the rmapbt.

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>
6 years agoxfs: scrub rmap btrees
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub rmap btrees

Source kernel commit: c7e693d9836c003150fef80be40a06e1f2e65d0c

Check the reverse mapping records to make sure that the contents
make sense.

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>
6 years agoxfs: scrub inode btrees
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub inode btrees

Source kernel commit: 3daa664191375db6a4a0cced75183aa3ca96cbda

Check the records of the inode btrees to make sure that the values
make sense given the inode records themselves.

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>
6 years agoxfs: scrub free space btrees
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub free space btrees

Source kernel commit: efa7a99ce1f8615aca7b0ff3122a1ae14e4d1cdc

Check the extent records free space btrees to ensure that the values
look sane.

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>
6 years agoxfs: scrub the AGI
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub the AGI

Source kernel commit: a12890aebb895951720ff884eab1c99a30645b29

Add a forgotten check to the AGI verifier, then wire up the scrub
infrastructure to check the AGI contents.

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>
6 years agoxfs: scrub AGF and AGFL
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub AGF and AGFL

Source kernel commit: ab9d5dc59fe6157b8035c4b605166b868f678ee4

Check the block references in the AGF and AGFL headers to make sure
they make sense.

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>
6 years agoxfs: scrub the secondary superblocks
Darrick J. Wong [Fri, 17 Nov 2017 04:11:32 +0000 (22:11 -0600)] 
xfs: scrub the secondary superblocks

Source kernel commit: 21fb4cb1981ef7e02f35a42b2a5ae619517dfe1b

Ensure that the geometry presented in the backup superblocks matches
the primary superblock so that repair can recover the filesystem if
that primary gets corrupted.

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>
6 years agoxfs: scrub the shape of a metadata btree
Darrick J. Wong [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: scrub the shape of a metadata btree

Source kernel commit: cc3e0948d2686f30f49166660cf85b7e0194f365

Create a function that can check the shape of a btree -- each block
passes basic inspection and all the pointers look ok.  In the next patch
we'll add the ability to check the actual keys and records stored within
the btree.  Add some helper functions so that we report detailed scrub
errors in a uniform manner in dmesg.  These are helper functions for
subsequent patches.

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>
6 years agoxfs: probe the scrub ioctl
Darrick J. Wong [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: probe the scrub ioctl

Source kernel commit: dcb660f9222fd9f607e7e05f4755b39b809ca19f

Create a probe scrubber with id 0.  This will be used by xfs_scrub to
probe the kernel's abilities to scrub (and repair) the metadata.  We do
this by validating the ioctl inputs from userspace, preparing the
filesystem for a scrub (or a repair) operation, and immediately
returning to userspace.  Userspace can use the returned errno and
structure state to decide (in broad terms) if scrub/repair are
supported by the running kernel.

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>
6 years agoxfs: create an ioctl to scrub AG metadata
Darrick J. Wong [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: create an ioctl to scrub AG metadata

Source kernel commit: 36fd6e863cb7329ab2e5687fdae4e4626b840adc

Create an ioctl that can be used to scrub internal filesystem metadata.
The new ioctl takes the metadata type, an (optional) AG number, an
(optional) inode number and generation, and a flags argument.  This will
be used by the upcoming XFS online scrub tool.

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>
6 years agoxfs: create inode pointer verifiers
Darrick J. Wong [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: create inode pointer verifiers

Source kernel commit: 91fb9afc0847926ef6ea7695b8125c8fbe7974d6

Create some helper functions to check that inode pointers point to
somewhere within the filesystem and not at the static AG metadata.
Move xfs_internal_inum and create a directory inode check function.
We will use these functions in scrub and elsewhere.

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>
6 years agoxfs: refactor btree block header checking functions
Darrick J. Wong [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: refactor btree block header checking functions

Source kernel commit: 52c732eee78b47ac2eb828b1c7fa611cd37b0090

Refactor the btree block header checks to have an internal function that
returns the address of the failing check without logging errors.  The
scrubber will call the internal function, while the external version
will maintain the current logging behavior.

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>
6 years agoxfs: refactor btree pointer checks
Darrick J. Wong [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: refactor btree pointer checks

Source kernel commit: f135761a73b18877bdfb44018fe993172c7be203

Refactor the btree pointer checks so that we can call them from the
scrub code without logging errors to dmesg.  Preserve the existing error
reporting for regular operations.

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>
6 years agoxfs: create block pointer check functions
Darrick J. Wong [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: create block pointer check functions

Source kernel commit: 21ec54168b368f1a98097dee00625ec8ec2d47f3

Create some helper functions to check that a block pointer points
within the filesystem (or AG) and doesn't point at static metadata.
We will use this for scrub.

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>
6 years agoxfs: remove xfs_bmbt_get_state
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: remove xfs_bmbt_get_state

Source kernel commit: f0387501652ed39f3bebc72e8a6b5abb405eb2b7

Unused after the big bmap refactor.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: remove all xfs_bmbt_set_* helpers except for xfs_bmbt_set_all
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: remove all xfs_bmbt_set_* helpers except for xfs_bmbt_set_all

Source kernel commit: 9b150709b3190719e5edf5f0ea35245cb8ae0a1a

Unused after the big bmap refactor.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: replace xfs_bmbt_lookup_ge with xfs_bmbt_lookup_first
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: replace xfs_bmbt_lookup_ge with xfs_bmbt_lookup_first

Source kernel commit: b5cfbc2282bcd0dba460d4d4ec07fcfac9981de6

We only use xfs_bmbt_lookup_ge to look up the first bmap record in an
inode, so replace xfs_bmbt_lookup_ge with a special purpose helper that
is a bit more descriptive.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: pass a struct xfs_bmbt_irec to xfs_bmbt_lookup_eq
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: pass a struct xfs_bmbt_irec to xfs_bmbt_lookup_eq

Source kernel commit: e16cf9b03cee4d2797695d4ca691e854c7a24864

Now that we've massaged the callers into the right form we can always
pass the actual extent record instead of the individual fields.

As an additional benefit the btree cursor will now be prepoulated with
the correct extent state instead of having to fix it up later.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: pass a struct xfs_bmbt_irec to xfs_bmbt_update
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: pass a struct xfs_bmbt_irec to xfs_bmbt_update

Source kernel commit: a67d00a55507dc324037f182563e10339945721a

Now that we've massaged the callers into the right form we can always
pass the actual extent record instead of the individual fields.

With that xfs_bmbt_disk_set_allf can go away, and xfs_bmbt_disk_set_all
can be merged into the former implementation of xfs_bmbt_disk_set_allf.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: refactor xfs_bmap_add_extent_unwritten_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: refactor xfs_bmap_add_extent_unwritten_real

Source kernel commit: 79fa6143a939a6b50d1d9dc736336e57d06b849d

Use xfs_iext_get_extent to find, and xfs_iext_update_extent to update
entries in the in-core extent list.  This isolates the function from
the detailed layout of the extent list, and generally makes the code
a lot more readable.

Also get rid of the oldext and newext variables as using the extent
records is a lot more descriptive.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: refactor delalloc accounting in xfs_bmap_add_extent_delay_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: refactor delalloc accounting in xfs_bmap_add_extent_delay_real

Source kernel commit: ca1862b0838604aa048120d87ebbf53cf7c8c8bd

Account for all changes to the delalloc reservation in da_new, and use a
single call xfs_mod_fdblocks to reserve/free blocks, including always
checking for an error.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: refactor xfs_bmap_add_extent_delay_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: refactor xfs_bmap_add_extent_delay_real

Source kernel commit: 4dcb8869871cc102b9431ae78b40bfc39087b90c

Use xfs_iext_get_extent to find, and xfs_iext_update_extent to update
entries in the in-core extent list.  This isolates the function from
the detailed layout of the extent list, and generally makes the code
a lot more readable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: refactor xfs_bmap_add_extent_hole_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: refactor xfs_bmap_add_extent_hole_real

Source kernel commit: 1abb9e55326c19bb41a9a2fd1179ed635e8af38c

Use xfs_iext_update_extent to update entries in the in-core extent list.
This isolates the function from the detailed layout of the extent list,
and generally makes the code a lot more readable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: refactor xfs_bmap_add_extent_hole_delay
Christoph Hellwig [Fri, 17 Nov 2017 04:11:31 +0000 (22:11 -0600)] 
xfs: refactor xfs_bmap_add_extent_hole_delay

Source kernel commit: 3ffc18ecd30ed21dc503fcbfb343c471a9112fb6

Use xfs_iext_get_extent to find, and xfs_iext_update_extent to update
entries in the in-core extent list.  This isolates the function from
the detailed layout of the extent list, and generally makes the code
a lot more readable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: refactor xfs_del_extent_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:30 +0000 (22:11 -0600)] 
xfs: refactor xfs_del_extent_real

Source kernel commit: 48fd52b16d74b937f44f87f942ddaff5e3e3db64

Use xfs_iext_update_extent to update entries in the in-core extent list.
This isolates the function from the detailed layout of the extent list,
and generally makes the code a lot more readable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: use the state defines in xfs_bmap_del_extent_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:30 +0000 (22:11 -0600)] 
xfs: use the state defines in xfs_bmap_del_extent_real

Source kernel commit: 491f6f8abfa7a91d23b969be67ed476817bcefd7

Use the same defines as the other extent add and delete helpers, which
both improves code readability and trace point output.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: use correct state defines in xfs_bmap_del_extent_{cow,delay}
Christoph Hellwig [Fri, 17 Nov 2017 04:11:30 +0000 (22:11 -0600)] 
xfs: use correct state defines in xfs_bmap_del_extent_{cow,delay}

Source kernel commit: 0173c689ff4c0855e24ceb898274af1339b5db48

Use the _FILLING values to match the usage in the xfs_bmap_add_extent_*
helpers.  No change in behavior, just better naming in the code and
tracepoint output.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reported-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: move some more code into xfs_bmap_del_extent_real
Christoph Hellwig [Fri, 17 Nov 2017 04:11:30 +0000 (22:11 -0600)] 
xfs: move some more code into xfs_bmap_del_extent_real

Source kernel commit: 1b24b633aafe4729c468f4144246709cdbda0f35

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: use xfs_bmap_del_extent_delay for the data fork as well
Christoph Hellwig [Fri, 17 Nov 2017 04:10:59 +0000 (22:10 -0600)] 
xfs: use xfs_bmap_del_extent_delay for the data fork as well

Source kernel commit: e1d7553faf3979df83a168ea4732f6f5255972a2

And remove the delalloc code from xfs_bmap_del_extent, which gets renamed
to xfs_bmap_del_extent_real to fit the naming scheme used by the other
xfs_bmap_{add,del}_extent_* routines.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: rename bno to end in __xfs_bunmapi
Christoph Hellwig [Fri, 17 Nov 2017 04:09:59 +0000 (22:09 -0600)] 
xfs: rename bno to end in __xfs_bunmapi

Source kernel commit: 8280f6ed4645549154103da9f037ceb4f7c733b4

Rename the bno variable that's used as the end of the range in
__xfs_bunmapi to end, which better describes it.  Additionally change
the start variable which takes the initial value of bno to be the
function parameter itself.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: don't set XFS_BTCUR_BPRV_WASDEL in xfs_bunmapi
Christoph Hellwig [Fri, 17 Nov 2017 04:08:59 +0000 (22:08 -0600)] 
xfs: don't set XFS_BTCUR_BPRV_WASDEL in xfs_bunmapi

Source kernel commit: b213d69293cf003e6f0c63adfee6fcc70e3afee6

The XFS_BTCUR_BPRV_WASDEL flag is supposed to indicate that we are
converting a delayed allocation to a real one, which isn't the case
in xfs_bunmapi.  Setting it could theoretically lead to misaccounting
here, but it's unlikely that we ever hit it in practice.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: use xfs_iext_get_extent instead of open coding it
Christoph Hellwig [Fri, 17 Nov 2017 04:08:59 +0000 (22:08 -0600)] 
xfs: use xfs_iext_get_extent instead of open coding it

Source kernel commit: e3f0f7563e8a2589e3acc26a41f7a7867a33536d

This avoids exposure to details of the extent list implementation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: fix incorrect extent state in xfs_bmap_add_extent_unwritten_real
Christoph Hellwig [Fri, 17 Nov 2017 04:08:59 +0000 (22:08 -0600)] 
xfs: fix incorrect extent state in xfs_bmap_add_extent_unwritten_real

Source kernel commit: 5e422f5e4fd71d18bc6b851eeb3864477b3d842e

There was one spot in xfs_bmap_add_extent_unwritten_real that didn't use the
passed in new extent state but always converted to normal, leading to wrong
behavior when converting from normal to unwritten.

Only found by code inspection, it seems like this code path to move partial
extent from written to unwritten while merging it with the next extent is
rarely exercised.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_io: Allow partial writes
Goldwyn Rodrigues [Thu, 9 Nov 2017 20:56:29 +0000 (14:56 -0600)] 
xfs_io: Allow partial writes

Partial writes are performed when there is an error midway
while performing the I/O. Perform the write exactly once and
return the number of bytes written so far, until the error.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
[sandeen@sandeen.net: add O to short help]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_io: Add RWF_NOWAIT to pwritev2()
Goldwyn Rodrigues [Thu, 9 Nov 2017 20:56:28 +0000 (14:56 -0600)] 
xfs_io: Add RWF_NOWAIT to pwritev2()

This allows to make pwritev2() calls with RWF_NOWAIT,
which would fail in case the call blocks.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
[sandeen@sandeen.net: combine all optional args in short help]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_io: Add support for pwritev2()
Goldwyn Rodrigues [Thu, 9 Nov 2017 20:56:25 +0000 (14:56 -0600)] 
xfs_io: Add support for pwritev2()

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_io: Disable -V if pwritev is not available
Goldwyn Rodrigues [Thu, 9 Nov 2017 20:54:59 +0000 (14:54 -0600)] 
xfs_io: Disable -V if pwritev is not available

This results in default case which will display the error message
that command is not found. This is required for xfs_io builds which
did not support pwritev and an attempt is made to use -V.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
[sandeen@sandeen.net: restrict default: printf to ifdef'd options]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_repair: always release btree buffers when refcountbt checks fail
Darrick J. Wong [Thu, 9 Nov 2017 17:35:30 +0000 (11:35 -0600)] 
xfs_repair: always release btree buffers when refcountbt checks fail

During phase 4 of repair, we compare the refcount records we've computed
against what's in the refcount btree.  If the btree is corrupt the
libxfs refcount calls will fail, but on our way out of the function we
don't make sure to clear all the btree cursor's buffer pointers.  This
leads to a repair deadlock in xfs/372 when fuzzing ptrs[1] to -1U
because we forgot to release a buffer.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agomisc: fix ubsan warnings
Darrick J. Wong [Thu, 9 Nov 2017 17:35:29 +0000 (11:35 -0600)] 
misc: fix ubsan warnings

Fix all the things ubsan warned about.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agomisc: enable thread sanitizer if the builder wants it
Darrick J. Wong [Thu, 9 Nov 2017 17:35:28 +0000 (11:35 -0600)] 
misc: enable thread sanitizer if the builder wants it

Enable the gcc/clang thread data corruption sanitizer if the builder
requests it and it's available.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agomisc: enable gcc/clang address sanitizer if the builder wants it
Darrick J. Wong [Thu, 9 Nov 2017 17:35:27 +0000 (11:35 -0600)] 
misc: enable gcc/clang address sanitizer if the builder wants it

Enable AddressSanitizer to look for memory usage errors if the builder
asks for it and it's available.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agomisc: enable ubsan if the builder wants it
Darrick J. Wong [Thu, 9 Nov 2017 17:35:26 +0000 (11:35 -0600)] 
misc: enable ubsan if the builder wants it

Enable the undefined behavior sanitizer (ubsan) if the builder requests
it and it's available.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_repair: fix cowextsize field checking and repairing
Darrick J. Wong [Thu, 9 Nov 2017 17:35:26 +0000 (11:35 -0600)] 
xfs_repair: fix cowextsize field checking and repairing

Make sure that we never leave the filesystem with a zero cowextsize hint
while the cowextsize inode flag is set.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_repair: clear DAX flag from non-file inodes
Darrick J. Wong [Thu, 9 Nov 2017 17:35:25 +0000 (11:35 -0600)] 
xfs_repair: clear DAX flag from non-file inodes

The DAX flag should only be set for files and directories.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_repair: fix bag memory overwrite problems
Darrick J. Wong [Thu, 9 Nov 2017 17:35:24 +0000 (11:35 -0600)] 
xfs_repair: fix bag memory overwrite problems

There's an off by one error in the bag_remove code such that we end up
copying memory from beyond the end of the array into the array.  Not a
serious problem since we have counters to prevent us from reading that
garbage, but AddressSanitizer complained so let's fix it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_io: add new error injection knobs to inject command
Darrick J. Wong [Thu, 9 Nov 2017 17:35:23 +0000 (11:35 -0600)] 
xfs_io: add new error injection knobs to inject command

Bring xfs_io's inject command up to date with the newest knobs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfsprogs: explicitly cast troublesome types to match printf format specifiers
Darrick J. Wong [Thu, 9 Nov 2017 17:35:23 +0000 (11:35 -0600)] 
xfsprogs: explicitly cast troublesome types to match printf  format specifiers

Certain system-defined types (__u64, __s64, __nlink_t, __ino64_t,
__off64_t, __blkcnt64_t) don't have a consistent definition across
different architectures, so wherever we use a printf format specifier on
such a variable, we have to typecast the variable or else the compiler
will complain.

IOWs this fixes build warnings on ppc64le.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agodb: increase metadump's default overly long extent discard threshold
Darrick J. Wong [Thu, 9 Nov 2017 17:35:22 +0000 (11:35 -0600)] 
db: increase metadump's default overly long extent discard  threshold

Back in 88b8e1d6d7 ("Make xfs_metadump more robust against bad data"),
metadump grew the ability to ignore a directory extent if it was longer
than 20 blocks.  Presumably this was to protect metadump from dumping
absurdly long extents resulting from bmbt corruption, but it's certainly
possible to create a directory with an extent longer than 20 blocks.
Hilariously, the discards happen with no warning unless the caller
explicitly set -w.

This was raised to 1000 blocks in 7431d134fe8 ("Increase default maximum
extent size for xfs_metadump when copying..."), but it's still possible
to create a directory with an extent longer than 1000 blocks.

Increase the threshold to MAXEXTLEN blocks because it's totally valid
for the filesystem to create extents up to that length.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agobuild: define _DEFAULT_SOURCE with _BSD_SOURCE for preadv
Luis R. Rodriguez [Thu, 9 Nov 2017 17:35:21 +0000 (11:35 -0600)] 
build: define _DEFAULT_SOURCE with _BSD_SOURCE for preadv

_BSD_SOURCE has been deprecated and replaced with _DEFAULT_SOURCE
for feature test macros.  We use this for preadv in the configure
script, but the latest preadv(2) manpage says:

preadv(), pwritev():
since glibc 2.19:
_DEFAULT_SOURCE
Glibc 2.19 and earlier:
_BSD_SOURCE

and the latest feature_test_macros(7) manpage says:

 Since glibc 2.20, this macro is deprecated.  It now has the same
 effect as defining _DEFAULT_SOURCE, but generates a compile-time
 warning (unless _DEFAULT_SOURCE is also defined).  Use
 _DEFAULT_SOURCE instead.  To allow code that requires
 _BSD_SOURCE in glibc 2.19 and earlier and _DEFAULT_SOURCE in
 glibc 2.20 and later to compile without warnings, define both
 _BSD_SOURCE and _DEFAULT_SOURCE.

So add both to our configure test.  They were completely missing
from the actual preadv usage in xfs_io, so add them there too.

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
[sandeen@redhat.com: clarify changelog, add defines to code use too]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfsprogs: add xfs_spaceman to .gitignore
Zirong Lang [Thu, 9 Nov 2017 17:35:20 +0000 (11:35 -0600)] 
xfsprogs: add xfs_spaceman to .gitignore

The new binary xfs_spaceman isn't in .gitignore, so ignore it in
this patch.

Signed-off-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_io: report io error for pwrite -W and -w
Liu Bo [Thu, 9 Nov 2017 17:35:20 +0000 (11:35 -0600)] 
xfs_io: report io error for pwrite -W and -w

When IO error occurs, xfs_io -c "pwrite -W/w" doesn't report errors
while xfs_io -c "pwrite" -c "fsync" does.

This changes "pwrite -W/w" to report errors when it should.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs_metadump: zap stale data in DIR2_LEAF1 dirs
Eric Sandeen [Thu, 9 Nov 2017 17:35:19 +0000 (11:35 -0600)] 
xfs_metadump: zap stale data in DIR2_LEAF1 dirs

xfs_metadump attempts to zero out unused regions of metadata
blocks to prevent data leaks when sharing metadata images.

However, Stefan Ring reported a significant number of leaked
strings when dumping his 1T filesystem.  Based on a reduced
metadata set, I was able to identify "leaf" directories
(with XFS_DIR2_LEAF1_MAGIC magic) as the primary culprit;
the region between the end of the entries array and the start
of the bests array was not getting zeroed out.  This patch
seems to remedy that problem.

Reported-by: Stefan Ring <stefanrin@gmail.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agometadump: update manpage for dirty log/obfuscation issue
Jan Tulak [Thu, 9 Nov 2017 17:35:18 +0000 (11:35 -0600)] 
metadump: update manpage for dirty log/obfuscation issue

This is something that should be documented, as it is not obvious to
everyone.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
[sandeen@redhat.com: edit for clarity]
[darrick.wong@oracle.com: edit for more clarity]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agokill off u_int*_t types
Felix Janda [Thu, 9 Nov 2017 17:34:53 +0000 (11:34 -0600)] 
kill off u_int*_t types

They were only used in two places and can be replaced by uint*_t.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: trim writepage mapping to within eof libxfs-4.14-sync
Brian Foster [Wed, 18 Oct 2017 21:25:45 +0000 (16:25 -0500)] 
xfs: trim writepage mapping to within eof

Source kernel commit: 40214d128e07dd21bb07a8ed6a7fe2f911281ab2

The writeback rework in commit fbcc02561359 ("xfs: Introduce
writeback context for writepages") introduced a subtle change in
behavior with regard to the block mapping used across the
->writepages() sequence. The previous xfs_cluster_write() code would
only flush pages up to EOF at the time of the writepage, thus
ensuring that any pages due to file-extending writes would be
handled on a separate cycle and with a new, updated block mapping.

The updated code establishes a block mapping in xfs_writepage_map()
that could extend beyond EOF if the file has post-eof preallocation.
Because we now use the generic writeback infrastructure and pass the
cached mapping to each writepage call, there is no implicit EOF
limit in place. If eofblocks trimming occurs during ->writepages(),
any post-eof portion of the cached mapping becomes invalid. The
eofblocks code has no means to serialize against writeback because
there are no pages associated with post-eof blocks. Therefore if an
eofblocks trim occurs and is followed by a file-extending buffered
write, not only has the mapping become invalid, but we could end up
writing a page to disk based on the invalid mapping.

Consider the following sequence of events:

- A buffered write creates a delalloc extent and post-eof
speculative preallocation.
- Writeback starts and on the first writepage cycle, the delalloc
extent is converted to real blocks (including the post-eof blocks)
and the mapping is cached.
- The file is closed and xfs_release() trims post-eof blocks. The
cached writeback mapping is now invalid.
- Another buffered write appends the file with a delalloc extent.
- The concurrent writeback cycle picks up the just written page
because the writeback range end is LLONG_MAX. xfs_writepage_map()
attributes it to the (now invalid) cached mapping and writes the
data to an incorrect location on disk (and where the file offset is
still backed by a delalloc extent).

This problem is reproduced by xfstests test generic/464, which
triggers racing writes, appends, open/closes and writeback requests.

To address this problem, trim the mapping used during writeback to
within EOF when the mapping is validated. This ensures the mapping
is revalidated for any pages encountered beyond EOF as of the time
the current mapping was cached or last validated.

Reported-by: Eryu Guan <eguan@redhat.com>
Diagnosed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: handle error if xfs_btree_get_bufs fails
Eric Sandeen [Wed, 18 Oct 2017 18:39:02 +0000 (13:39 -0500)] 
xfs: handle error if xfs_btree_get_bufs fails

Source kernel commit: 93e8befc17f6d6ea92b0aee3741ceac8bca4590f

Jason reported that a corrupted filesystem failed to replay
the log with a metadata block out of bounds warning:

XFS (dm-2): _xfs_buf_find: Block out of range: block 0x80270fff8, EOFS 0x9c40000

_xfs_buf_find() and xfs_btree_get_bufs() return NULL if
that happens, and then when xfs_alloc_fix_freelist() calls
xfs_trans_binval() on that NULL bp, we oops with:

BUG: unable to handle kernel NULL pointer dereference at 00000000000000f8

We don't handle _xfs_buf_find errors very well, every
caller higher up the stack gets to guess at why it failed.
But we should at least handle it somehow, so return
EFSCORRUPTED here.

Reported-by: Jason L Tibbitts III <tibbs@math.uh.edu>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
6 years agoxfs: Fix bool initialization/comparison
Thomas Meyer [Wed, 18 Oct 2017 18:39:02 +0000 (13:39 -0500)] 
xfs: Fix bool initialization/comparison

Source kernel commit: 749f24f33e87c1706d716c283027595b72a034f3

Bool initializations should use true and false. Bool tests don't need
comparisons.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>