]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/log
thirdparty/xfsprogs-dev.git
7 years agoplatform: remove use of off64_t
Felix Janda [Tue, 1 Nov 2016 01:39:20 +0000 (12:39 +1100)] 
platform: remove use of off64_t

Since we force transparent LFS it can be replaced by off_t.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs.h: require transparent LFS for all users
Felix Janda [Tue, 1 Nov 2016 01:38:42 +0000 (12:38 +1100)] 
xfs.h: require transparent LFS for all users

Since our interfaces depend on the consistent use of a 64bit offset
type, force downstreams to use transparent LFS (_FILE_OFFSET_BITS=64),
so that it becomes impossible for them to use 32bit interfaces.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfsprogs: replace statvfs64 by equivalent statvfs
Felix Janda [Tue, 1 Nov 2016 01:38:40 +0000 (12:38 +1100)] 
xfsprogs: replace statvfs64 by equivalent statvfs

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agofsr: remove workaround for statvfs on Mac OS X
Felix Janda [Tue, 1 Nov 2016 01:38:39 +0000 (12:38 +1100)] 
fsr: remove workaround for statvfs on Mac OS X

It can be removed since fsr is no longer built on Mac OS X.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoMakefile: disable fsr for Mac OS X
Felix Janda [Tue, 1 Nov 2016 01:38:37 +0000 (12:38 +1100)] 
Makefile: disable fsr for Mac OS X

Since its kernel does not support XFS anyway this utility is not
useful, and with its removal the portability framework can be
simplified.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs_io: replace posix_fadvise64 by equivalent posix_fadvise
Felix Janda [Tue, 1 Nov 2016 01:38:36 +0000 (12:38 +1100)] 
xfs_io: replace posix_fadvise64 by equivalent posix_fadvise

also fixes a compile failure on FreeBSD

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfsprogs: replace sendfile64 by equivalent sendfile
Felix Janda [Tue, 1 Nov 2016 01:38:34 +0000 (12:38 +1100)] 
xfsprogs: replace sendfile64 by equivalent sendfile

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfsprogs: replace pread64/pwrite64 by equivalent pread/pwrite
Felix Janda [Tue, 1 Nov 2016 01:38:33 +0000 (12:38 +1100)] 
xfsprogs: replace pread64/pwrite64 by equivalent pread/pwrite

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfsprogs: replace lseek64 by equivalent lseek
Felix Janda [Tue, 1 Nov 2016 01:38:29 +0000 (12:38 +1100)] 
xfsprogs: replace lseek64 by equivalent lseek

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfsprogs: replace ftruncate64 by equivalent ftruncate
Felix Janda [Tue, 1 Nov 2016 01:38:27 +0000 (12:38 +1100)] 
xfsprogs: replace ftruncate64 by equivalent ftruncate

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfsprogs: replace [fl]stat64 by equivalent [fl]stat
Felix Janda [Tue, 1 Nov 2016 01:38:25 +0000 (12:38 +1100)] 
xfsprogs: replace [fl]stat64 by equivalent [fl]stat

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoconfigure: remove unecessary definitions of _FILE_OFFSET_BITS
Felix Janda [Mon, 31 Oct 2016 23:41:40 +0000 (10:41 +1100)] 
configure: remove unecessary definitions of _FILE_OFFSET_BITS

now that we use AC_SYS_LARGEFILE, there is no need to explicitly
define _FILE_OFFSET_BITS.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoconfigure: error out when LFS does not work
Felix Janda [Mon, 31 Oct 2016 23:40:40 +0000 (10:40 +1100)] 
configure: error out when LFS does not work

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoconfigure: use AC_SYS_LARGEFILE
Felix Janda [Mon, 31 Oct 2016 23:39:40 +0000 (10:39 +1100)] 
configure: use AC_SYS_LARGEFILE

The autoconf macro AC_SYS_LARGEFILE defines _FILE_OFFSET_BITS=64
where necessary to ensure that off_t and all interfaces using off_t
are 64bit, even on 32bit systems.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs_io: Fix initial -m option
Andreas Gruenbacher [Mon, 31 Oct 2016 23:38:40 +0000 (10:38 +1100)] 
xfs_io: Fix initial -m option

Like "open -m mode", the initial -m option requires a mode argument.

Document these options correctly as well.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs_io: add command line option -i to start an idle thread
Amir Goldstein [Mon, 31 Oct 2016 23:38:19 +0000 (10:38 +1100)] 
xfs_io: add command line option -i to start an idle thread

xfs_io -i will start by spawning an idle thread.

The purpose of this idle thread is to test io from a multi threaded
process. With single threaded process, the file table is not shared
and file structs are not reference counted. Spawning an idle thread
can help detecting file struct reference leaks.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfsprogs: Update FSF address in COPYING file
Grozdan [Mon, 31 Oct 2016 23:38:09 +0000 (10:38 +1100)] 
xfsprogs: Update FSF address in COPYING file

The FSF address in doc/COPYING needs an update. This was caught and
reported by the openSUSE build service while building the xfsprogs
package. The new address is taken directly from FSF's license files
put on their site

Signed-off-by: Grozdan Nikolov <neutrino8@gmail.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
--

7 years agomkfs.xfs: format reflink enabled filesystems
Darrick J. Wong [Tue, 25 Oct 2016 22:14:36 +0000 (15:14 -0700)] 
mkfs.xfs: format reflink enabled filesystems

Create the refcount btree at mkfs time and set the feature flag.

v2: Turn on the reflink feature when calculating the minimum log size.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: use thread pools to sort rmap data
Darrick J. Wong [Tue, 25 Oct 2016 22:14:36 +0000 (15:14 -0700)] 
xfs_repair: use thread pools to sort rmap data

Since each slab is a collection of independent mini-slabs, we can
fire up a bunch of threads to sort the mini-slabs in parallel.
This speeds up the sorting phase of the rmapbt rebuilding if we
have a large number of mini slabs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: check for mergeable refcount records
Darrick J. Wong [Tue, 25 Oct 2016 22:14:36 +0000 (15:14 -0700)] 
xfs_repair: check for mergeable refcount records

Make sure there aren't adjacent refcount records that could be merged;
this is a sign that the refcount tree algorithms aren't working
correctly.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: use range query when while checking rmaps
Darrick J. Wong [Tue, 25 Oct 2016 22:14:35 +0000 (15:14 -0700)] 
xfs_repair: use range query when while checking rmaps

For shared extents, we ought to use a range query on the rmapbt to
find the corresponding rmap.  However, most of the time the observed
rmap will be an exact match for the rmapbt rmap, in which case we
could have used the (much faster) regular lookup.  Therefore, try the
regular lookup first and resort to the range lookup if that doesn't
get us what we want.  This can cut the run time of the rmap check of
xfs_repair in half.

Theoretically, the only reason why an observed rmap wouldn't be an
exact match for an rmapbt rmap is because we modified some file on
account of a metadata error.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: check the CoW extent size hint
Darrick J. Wong [Tue, 25 Oct 2016 22:14:35 +0000 (15:14 -0700)] 
xfs_repair: check the CoW extent size hint

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: complain about copy-on-write leftovers
Darrick J. Wong [Tue, 25 Oct 2016 22:14:35 +0000 (15:14 -0700)] 
xfs_repair: complain about copy-on-write leftovers

Complain about leftover CoW allocations that are hanging off the
refcount btree.  These are cleaned out at mount time, but we could be
louder about flagging down evidence of trouble.

Since these extents aren't "owned" by anything, we'll free them up by
reconstructing the free space btrees.

v2: When we're processing rmap records, we inadvertently forgot to
handle the CoW owner, so the leftover CoW staging blocks got marked as
file data.  These blocks will just get freed later, so mark them
"CoW".  When we process the refcountbt, complain about leftovers if
the type is unknown or "CoW".

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: rebuild the refcount btree
Darrick J. Wong [Tue, 25 Oct 2016 22:14:35 +0000 (15:14 -0700)] 
xfs_repair: rebuild the refcount btree

Rebuild the refcount btree with the reference count data we assembled
during phase 4.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: check the refcount btree against our observed reference counts when -n
Darrick J. Wong [Tue, 25 Oct 2016 22:14:35 +0000 (15:14 -0700)] 
xfs_repair: check the refcount btree against our observed reference counts when -n

Check the observed reference counts against whatever's in the refcount
btree for discrepancies.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: fix inode reflink flags
Darrick J. Wong [Tue, 25 Oct 2016 22:14:35 +0000 (15:14 -0700)] 
xfs_repair: fix inode reflink flags

While we're computing reference counts, record which inodes actually
share blocks with other files and fix the flags as necessary.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: record reflink inode state
Darrick J. Wong [Tue, 25 Oct 2016 22:14:34 +0000 (15:14 -0700)] 
xfs_repair: record reflink inode state

Record the state of the per-inode reflink flag, so that we can
compare against the rmap data and update the flags accordingly.
Clear the (reflink) state if we clear the inode.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: process reverse-mapping data into refcount data
Darrick J. Wong [Tue, 25 Oct 2016 22:14:34 +0000 (15:14 -0700)] 
xfs_repair: process reverse-mapping data into refcount data

Take all the reverse-mapping data we've acquired and use it to generate
reference count data.  This data is used in phase 5 to rebuild the
refcount btree.

v2: Update to reflect separation of rmap_irec flags.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: handle multiple owners of data blocks
Darrick J. Wong [Tue, 25 Oct 2016 22:14:34 +0000 (15:14 -0700)] 
xfs_repair: handle multiple owners of data blocks

If reflink is enabled, don't freak out if there are multiple owners of
a given block; that's just a sign that each of those owners are
reflink files.

v2: owner and offset are unsigned types, so use those for inorder
comparison.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_repair: check the existing refcount btree
Darrick J. Wong [Tue, 25 Oct 2016 22:14:34 +0000 (15:14 -0700)] 
xfs_repair: check the existing refcount btree

Spot-check the refcount btree for obvious errors, and mark the
refcount btree blocks as such.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_repair: fix get_agino_buf to avoid corrupting inodes
Darrick J. Wong [Tue, 25 Oct 2016 22:14:34 +0000 (15:14 -0700)] 
xfs_repair: fix get_agino_buf to avoid corrupting inodes

The inode buffering code tries to read inodes in units of chunks,
which are the larger of 8K or 1 FSB.  Each chunk gets its own xfs_buf,
which means that get_agino_buf must calculate the disk address of the
chunk and feed that to libxfs_readbuf in order to find the inode data
correctly.  The current code simply grabs the chunk for the start
inode and indexes from that, which corrupts memory because the start
inode and the target inode could be in different inode chunks.  That
causes the assert in rmap.c to blow when we clear the reflink flag.

(Also fix some minor errors in the debugging printfs.)

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoman: document the inode cowextsize flags & fields
Darrick J. Wong [Tue, 25 Oct 2016 22:14:34 +0000 (15:14 -0700)] 
man: document the inode cowextsize flags & fields

Document the new copy-on-write extent size fields and inode flags
available in struct fsxattr.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_logprint: support bmap redo items
Darrick J. Wong [Tue, 25 Oct 2016 22:14:33 +0000 (15:14 -0700)] 
xfs_logprint: support bmap redo items

Print block mapping update redo items.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_logprint: support refcount redo items
Darrick J. Wong [Tue, 25 Oct 2016 22:14:33 +0000 (15:14 -0700)] 
xfs_logprint: support refcount redo items

Print reference count update redo items.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_logprint: support cowextsize reporting in log contents
Darrick J. Wong [Tue, 25 Oct 2016 22:14:33 +0000 (15:14 -0700)] 
xfs_logprint: support cowextsize reporting in log contents

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_io: try to unshare copy-on-write blocks via fallocate
Darrick J. Wong [Tue, 25 Oct 2016 22:14:33 +0000 (15:14 -0700)] 
xfs_io: try to unshare copy-on-write blocks via fallocate

Wire up the "unshare" flag to the xfs_io fallocate command.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_io: provide long-format help for falloc
Darrick J. Wong [Tue, 25 Oct 2016 22:14:33 +0000 (15:14 -0700)] 
xfs_io: provide long-format help for falloc

Provide long-format help for falloc so that users can learn about
the command.

Note for xfstest writers: If you need to check that a particular
fallocate mode works (-c/-i/-p/-u) on a given filesystem, you should
call _require_xfs_io_command with the falloc subcommand directly, (i.e.
_require_xfs_io_command funshare) because the subcommands are
special-cased to actually try the command.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_io: support injecting the 'per-AG reservation critically low' error
Darrick J. Wong [Tue, 25 Oct 2016 22:14:33 +0000 (15:14 -0700)] 
xfs_io: support injecting the 'per-AG reservation critically low' error

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_io: add refcount+bmap error injection types
Darrick J. Wong [Tue, 25 Oct 2016 22:14:33 +0000 (15:14 -0700)] 
xfs_io: add refcount+bmap error injection types

Add refcount and bmap deferred finish to the types of errors we can
inject.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_io: get and set the CoW extent size hint
Darrick J. Wong [Tue, 25 Oct 2016 22:14:32 +0000 (15:14 -0700)] 
xfs_io: get and set the CoW extent size hint

Enable administrators to get or set the CoW extent size hint.
Report the hint when we run stat.  This also requires some
autoconf magic to detect whether or not fsx_cowextsize exists.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: Use the internal fsxattr override to guarantee that the cowextsize
field always exists inside of whatever struct fsxattr is.

7 years agolibxfs: add autoconf mechanism to override system header fsxattr
Darrick J. Wong [Tue, 25 Oct 2016 22:14:32 +0000 (15:14 -0700)] 
libxfs: add autoconf mechanism to override system header fsxattr

By default, libxfs will use the kernel/system headers to define struct
fsxattr.  Unfortunately, this creates a problem for developers who are
writing new features but building xfsprogs on a stable system, because
the stable kernel's headers don't reflect the new feature.  In this
case, we want to be able to use the internal fsxattr definition while
the kernel headers catch up, so provide some configure magic to allow
further patches to force the use of the internal definition.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: Remove the user-visible configure option but leave the fsxattr
override ability so that subsequent patches can trigger it if
necessary.

7 years agoxfs_io: bmap should support querying CoW fork, shared blocks
Darrick J. Wong [Tue, 25 Oct 2016 22:14:32 +0000 (15:14 -0700)] 
xfs_io: bmap should support querying CoW fork, shared blocks

Teach the bmap command to report shared and delayed allocation
extents, and to be able to query the CoW fork.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_growfs: report the presence of the reflink feature
Darrick J. Wong [Tue, 25 Oct 2016 22:14:32 +0000 (15:14 -0700)] 
xfs_growfs: report the presence of the reflink feature

Report the presence of the reflink feature in xfs_info.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_db: print one array element per line
Darrick J. Wong [Tue, 25 Oct 2016 22:14:32 +0000 (15:14 -0700)] 
xfs_db: print one array element per line

Print one array element per line so that the debugger output isn't
a gigantic pile of screen snow.

Before (inobt):

xfs_db> p recs
recs[1-55] = [startino,holemask,count,freecount,free]
1:[128,0,64,0,0] 2:[4288,0xff,32,0,0xffffffff] 3:[4352,0,64,0,0]
4:[4416,0,64,10,0x1f0003e000000000] 5:[4480,0,64,17,0xc00e1803c2007840]

After:

xfs_db> p recs
recs[1-55] = [startino,holemask,count,freecount,free]
1:[128,0,64,0,0]
2:[4288,0xff,32,0,0xffffffff]
3:[4352,0,64,0,0]
4:[4416,0,64,10,0x1f0003e000000000]
5:[4480,0,64,17,0xc00e1803c2007840]

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_db: deal with the CoW extent size hint
Darrick J. Wong [Tue, 25 Oct 2016 22:14:32 +0000 (15:14 -0700)] 
xfs_db: deal with the CoW extent size hint

Display the CoW extent hint size when dumping inodes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_db: metadump should copy the refcount btree too
Darrick J. Wong [Tue, 25 Oct 2016 22:14:32 +0000 (15:14 -0700)] 
xfs_db: metadump should copy the refcount btree too

Teach metadump to copy the refcount btree.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_db: add support for checking the refcount btree
Darrick J. Wong [Tue, 25 Oct 2016 22:14:31 +0000 (15:14 -0700)] 
xfs_db: add support for checking the refcount btree

Do some basic checks of the refcount btree.  xfs_repair will have to
check that the reference counts match the various bmbt mappings.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agoxfs_db: dump refcount btree data
Darrick J. Wong [Tue, 25 Oct 2016 22:14:31 +0000 (15:14 -0700)] 
xfs_db: dump refcount btree data

Add the ability to walk and dump the refcount btree in xfs_db.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agolibxfs: add fsxattr flags and fields for cowextsize
Darrick J. Wong [Tue, 25 Oct 2016 22:14:31 +0000 (15:14 -0700)] 
libxfs: add fsxattr flags and fields for cowextsize

Add the cowextsize field and flag to each platform's struct fsxattr
definitions.  We can compile these definitions into the xfsprogs
utilities if we don't pick them up from the system headers, such as on
kernels prior to 4.9.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agolibxfs: free the CoW fork from an inode
Darrick J. Wong [Tue, 25 Oct 2016 22:14:31 +0000 (15:14 -0700)] 
libxfs: free the CoW fork from an inode

Clean up the CoW fork, should there ever be one.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agolibxfs: plumb in bmap deferred op log items
Darrick J. Wong [Tue, 25 Oct 2016 22:14:31 +0000 (15:14 -0700)] 
libxfs: plumb in bmap deferred op log items

Add a deferred op handler for block mapping actions.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agolibxfs: plumb in refcount deferred op log items
Darrick J. Wong [Tue, 25 Oct 2016 22:14:31 +0000 (15:14 -0700)] 
libxfs: plumb in refcount deferred op log items

Add a deferred op handler for refcount update actions.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agolibxfs: add xfs_refcount.h to the standard include list
Darrick J. Wong [Tue, 25 Oct 2016 22:14:30 +0000 (15:14 -0700)] 
libxfs: add xfs_refcount.h to the standard include list

Pick up the definitions in xfs_refcount.h for all compilation units.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
7 years agolibxfs: initialize the in-core mount context for refcount btrees
Darrick J. Wong [Tue, 25 Oct 2016 22:14:30 +0000 (15:14 -0700)] 
libxfs: initialize the in-core mount context for refcount btrees

Initialize the refcount btree maxlevel field of the mount context.
This helps us to detect overly tall trees.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_buflock: handling parsing errors more gracefully
Darrick J. Wong [Tue, 25 Oct 2016 22:14:30 +0000 (15:14 -0700)] 
xfs_buflock: handling parsing errors more gracefully

Skip ftrace output lines that don't parse.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs_logprint: fix up the RUI printing code to reflect new format
Darrick J. Wong [Tue, 25 Oct 2016 22:14:30 +0000 (15:14 -0700)] 
xfs_logprint: fix up the RUI printing code to reflect new format

We changed the RUI format to use a variable length array, so update
the logprint code to reflect that.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: defer should abort intent items if the trans roll fails libxfs-4.9-sync
Darrick J. Wong [Tue, 25 Oct 2016 02:00:12 +0000 (13:00 +1100)] 
xfs: defer should abort intent items if the trans roll fails

Source kernel commit: b77428b12b55437b28deae738d9ce8b2e0663b55

If the deferred ops transaction roll fails, we need to abort the intent
items if we haven't already logged a done item for it, regardless of
whether or not the deferred ops has had a transaction committed.  Dave
found this while running generic/388.

Move the tracepoint to make it easier to track object lifetimes.

Reported-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs: remove xfs_bunmapi_cow
Christoph Hellwig [Tue, 25 Oct 2016 01:59:49 +0000 (12:59 +1100)] 
xfs: remove xfs_bunmapi_cow

Source kernel commit: 64e6428ddd00f864e3ca105f914a2b6920c2bc41

Since no one uses it anymore.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs: refactor xfs_bunmapi_cow
Christoph Hellwig [Tue, 25 Oct 2016 01:59:46 +0000 (12:59 +1100)] 
xfs: refactor xfs_bunmapi_cow

Source kernel commit: fa5c836ca8eb5bad6316ddfc066acbc4e2485356

Split out two helpers for deleting delayed or real extents from the COW fork.
This allows to call them directly from xfs_reflink_cow_end_io once that
function is refactored to iterate the extent tree.  It will also allow
to reuse the delalloc deletion from xfs_bunmapi in the future.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs: add xfs_trim_extent
Darrick J. Wong [Tue, 25 Oct 2016 01:47:36 +0000 (12:47 +1100)] 
xfs: add xfs_trim_extent

Source kernel commit: 0a0af28cad9a43d90f13c2047bd8ee3d4cffb7f3

This helpers allows to trim an extent to a subset of it's original range
while making sure the block numbers in it remain valid,

In the future xfs_trim_extent and xfs_bmapi_trim_map should probably be
merged in some form.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
[hch: split from a previous patch from Darrick, moved around and added
support for "raw" delayed extents"]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agolibxfs: clean up _calc_dquots_per_chunk
Darrick J. Wong [Tue, 25 Oct 2016 01:47:36 +0000 (12:47 +1100)] 
libxfs: clean up _calc_dquots_per_chunk

Source kernel commit: 58d789678546d46d7bbd809dd7dab417c0f23655

The function xfs_calc_dquots_per_chunk takes a parameter in units
of basic blocks.  The kernel seems to get the units wrong, but
userspace got 'fixed' by commenting out the unnecessary conversion.
Fix both.

cc: <stable@vger.kernel.org>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs: remove pointless error goto in xfs_bmap_remap_alloc
Eric Sandeen [Tue, 25 Oct 2016 01:47:14 +0000 (12:47 +1100)] 
xfs: remove pointless error goto in xfs_bmap_remap_alloc

Source kernel commit: fe23759eaf2f6540de20c1623f066aad967ff9c9

The commit:

f65306ea xfs: map an inode's offset to an exact physical block

added a pointless error0: target; remove it.

Addresses-Coverity-Id: 1373865
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs: add some 'static' annotations
Eric Biggers [Tue, 25 Oct 2016 01:47:14 +0000 (12:47 +1100)] 
xfs: add some 'static' annotations

Source kernel commit: f1b8243c55ca6fd2a3898e2f586b8cfcfff684bb

sparse reported that several variables and a function were not
forward-declared anywhere and therefore should be 'static'.

Found with sparse by running 'make C=2 CF=-D__CHECK_ENDIAN__ fs/xfs/'

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs: remove redundant assignment of ifp
Colin Ian King [Tue, 25 Oct 2016 01:47:14 +0000 (12:47 +1100)] 
xfs: remove redundant assignment of ifp

Source kernel commit: 1d55a4bfd080ff4c6c96acfccfb7cdd2615ed6c2

Remove redundant ifp = ifp statement, it does nothing. Found with
static analysis by CoverityScan.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs: rework refcount cow recovery error handling
Darrick J. Wong [Tue, 25 Oct 2016 01:47:13 +0000 (12:47 +1100)] 
xfs: rework refcount cow recovery error handling

Source kernel commit: 6f97077ff6ef28e0f3b361b6ba9c95a222ef384b

The error handling in xfs_refcount_recover_cow_leftovers is confused
and can potentially leak memory, so rework it to release resources
correctly on error.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
7 years agoxfs: implement swapext for rmap filesystems
Darrick J. Wong [Tue, 25 Oct 2016 01:47:13 +0000 (12:47 +1100)] 
xfs: implement swapext for rmap filesystems

Source kernel commit: 1f08af52e7c981e9877796a2d90b0e0f08666945

Implement swapext for filesystems that have reverse mapping.  Back in
the reflink patches, we augmented the bmap code with a 'REMAP' flag
that updates only the bmbt and doesn't touch the allocator and
implemented log redo items for those two operations.  Now we can
rewrite extent swapping as a (looong) series of remap operations.

This is far less efficient than the fork swapping method implemented
in the past, so we only switch this on for rmap.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: recognize the reflink feature bit
Darrick J. Wong [Tue, 25 Oct 2016 01:46:51 +0000 (12:46 +1100)] 
xfs: recognize the reflink feature bit

Source kernel commit: e54b5bf9d7aeb92d92c7f5115035e6a851d0f0c5

Add the reflink feature flag to the set of recognized feature flags.
This enables users to write to reflink filesystems.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: simulate per-AG reservations being critically low
Darrick J. Wong [Tue, 25 Oct 2016 01:46:51 +0000 (12:46 +1100)] 
xfs: simulate per-AG reservations being critically low

Source kernel commit: a35eb41519ab8db90e87d375ee9362d6e080ca4c

Create an error injection point that enables us to simulate being
critically low on per-AG block reservations.  This should enable us to
simulate this specific ENOSPC condition so that we can test falling back
to a regular file copy.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: don't mix reflink and DAX mode for now
Darrick J. Wong [Tue, 25 Oct 2016 01:46:51 +0000 (12:46 +1100)] 
xfs: don't mix reflink and DAX mode for now

Source kernel commit: 4f435ebe7d0422af61cdcddbbcc659888645a1e1

Since we don't have a strategy for handling both DAX and reflink,
for now we'll just prohibit both being set at the same time.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: check for invalid inode reflink flags
Darrick J. Wong [Tue, 25 Oct 2016 01:46:51 +0000 (12:46 +1100)] 
xfs: check for invalid inode reflink flags

Source kernel commit: c8e156ac336d82f67d7adc014404a2251e9dad09

We don't support sharing blocks on the realtime device.  Flag inodes
with the reflink or cowextsize flags set when the reflink feature is
disabled.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: convert unwritten status of reverse mappings for shared files
Darrick J. Wong [Tue, 25 Oct 2016 01:46:51 +0000 (12:46 +1100)] 
xfs: convert unwritten status of reverse mappings for shared files

Source kernel commit: 3f165b334e51477d2b33ac1c81b39927514daab7

Provide a function to convert an unwritten extent to a real one and
vice versa when shared extents are possible.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: use interval query for rmap alloc operations on shared files
Darrick J. Wong [Tue, 25 Oct 2016 01:46:22 +0000 (12:46 +1100)] 
xfs: use interval query for rmap alloc operations on shared files

Source kernel commit: ceeb9c832eeca5c1c2efc54a38f67283ccb60288

When it's possible for reverse mappings to overlap (data fork extents
of files on reflink filesystems), use the interval query function to
find the left neighbor of an extent we're trying to add; and be
careful to use the lookup functions to update the neighbors and/or
add new extents.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: add shared rmap map/unmap/convert log item types
Darrick J. Wong [Tue, 25 Oct 2016 01:43:48 +0000 (12:43 +1100)] 
xfs: add shared rmap map/unmap/convert log item types

Source kernel commit: 0e07c039bac5f6ce7e3bc512ab9efb4aaa76da94

Wire up some rmap log redo item type codes to map, unmap, or convert
shared data block extents.  The actual log item recovery comes in a
later patch.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: increase log reservations for reflink
Darrick J. Wong [Tue, 25 Oct 2016 01:43:48 +0000 (12:43 +1100)] 
xfs: increase log reservations for reflink

Source kernel commit: 80de462e090c2c346ca6ec6344b326e81e8cef84

Increase the log reservations to handle the increased rolling that
happens at the end of copy-on-write operations.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: try other AGs to allocate a BMBT block
Darrick J. Wong [Tue, 25 Oct 2016 01:43:48 +0000 (12:43 +1100)] 
xfs: try other AGs to allocate a BMBT block

Source kernel commit: 90e2056d76adc7894a019f5289d259de58065e13

Prior to the introduction of reflink, allocating a block and mapping
it into a file was performed in a single transaction with a single
block reservation, and the allocator was supposed to find enough
blocks to allocate the extent and any BMBT blocks that might be
necessary (unless we're low on space).

However, due to the way copy on write works, allocation and mapping
have been split into two transactions, which means that we must be
able to handle the case where we allocate an extent for CoW but that
AG runs out of free space before the blocks can be mapped into a file,
and the mapping requires a new BMBT block.  When this happens, look in
one of the other AGs for a BMBT block instead of taking the FS down.

The same applies to the functions that convert a data fork to extents
and later btree format.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: preallocate blocks for worst-case btree expansion
Darrick J. Wong [Tue, 25 Oct 2016 01:43:48 +0000 (12:43 +1100)] 
xfs: preallocate blocks for worst-case btree expansion

Source kernel commit: 84d6961910ea7b3ae8d8338f5b4df25dea68cee9

To gracefully handle the situation where a CoW operation turns a
single refcount extent into a lot of tiny ones and then run out of
space when a tree split has to happen, use the per-AG reserved block
pool to pre-allocate all the space we'll ever need for a maximal
btree.  For a 4K block size, this only costs an overhead of 0.3% of
available disk space.

When reflink is enabled, we have an unfortunate problem with rmap --
since we can share a block billions of times, this means that the
reverse mapping btree can expand basically infinitely.  When an AG is
so full that there are no free blocks with which to expand the rmapbt,
the filesystem will shut down hard.

This is rather annoying to the user, so use the AG reservation code to
reserve a "reasonable" amount of space for rmap.  We'll prevent
reflinks and CoW operations if we think we're getting close to
exhausting an AG's free space rather than shutting down, but this
permanent reservation should be enough for "most" users.  Hopefully.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
[hch@lst.de: ensure that we invalidate the freed btree buffer]
Signed-off-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: create a separate cow extent size hint for the allocator
Darrick J. Wong [Tue, 25 Oct 2016 01:43:42 +0000 (12:43 +1100)] 
xfs: create a separate cow extent size hint for the allocator

Source kernel commit: f7ca35227253dc8244fd908140b06010e67a31e5

Create a per-inode extent size allocator hint for copy-on-write.  This
hint is separate from the existing extent size hint so that CoW can
take advantage of the fragmentation-reducing properties of extent size
hints without disabling delalloc for regular writes.

The extent size hint that's fed to the allocator during a copy on
write operation is the greater of the cowextsize and regular extsize
hint.

During reflink, if we're sharing the entire source file to the entire
destination file and the destination file doesn't already have a
cowextsize hint, propagate the source file's cowextsize hint to the
destination file.

Furthermore, zero the bulkstat buffer prior to setting the fields
so that we don't copy kernel memory contents into userspace.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: teach get_bmapx about shared extents and the CoW fork
Darrick J. Wong [Tue, 25 Oct 2016 01:42:12 +0000 (12:42 +1100)] 
xfs: teach get_bmapx about shared extents and the CoW fork

Source kernel commit: f86f403794b1446b68afb3c233d4c0bc0e93b654

Teach xfs_getbmapx how to report shared extents and CoW fork contents
accurately in the bmap output by querying the refcount btree
appropriately.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: store in-progress CoW allocations in the refcount btree
Darrick J. Wong [Tue, 25 Oct 2016 01:41:50 +0000 (12:41 +1100)] 
xfs: store in-progress CoW allocations in the refcount btree

Source kernel commit: 174edb0e46e520230791a1a894397b7c824cefc4

Due to the way the CoW algorithm in XFS works, there's an interval
during which blocks allocated to handle a CoW can be lost -- if the FS
goes down after the blocks are allocated but before the block
remapping takes place.  This is exacerbated by the cowextsz hint --
allocated reservations can sit around for a while, waiting to get
used.

Since the refcount btree doesn't normally store records with refcount
of 1, we can use it to record these in-progress extents.  In-progress
blocks cannot be shared because they're not user-visible, so there
shouldn't be any conflicts with other programs.  This is a better
solution than holding EFIs during writeback because (a) EFIs can't be
relogged currently, (b) even if they could, EFIs are bound by
available log space, which puts an unnecessary upper bound on how much
CoW we can have in flight, and (c) we already have a mechanism to
track blocks.

At mount time, read the refcount records and free anything we find
with a refcount of 1 because those were in-progress when the FS went
down.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: support removing extents from CoW fork
Darrick J. Wong [Tue, 25 Oct 2016 01:38:27 +0000 (12:38 +1100)] 
xfs: support removing extents from CoW fork

Source kernel commit: 4862cfe825c0087c14452b362e708a35da675f5e

Create a helper method to remove extents from the CoW fork without
any of the side effects (rmapbt/bmbt updates) of the regular extent
deletion routine.  We'll eventually use this to clear out the CoW fork
during ioend processing.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: support allocating delayed extents in CoW fork
Darrick J. Wong [Tue, 25 Oct 2016 01:38:27 +0000 (12:38 +1100)] 
xfs: support allocating delayed extents in CoW fork

Source kernel commit: 60b4984fc3924bff292ec46b95a3e98b34b8e259

Modify xfs_bmap_add_extent_delay_real() so that we can convert delayed
allocation extents in the CoW fork to real allocations, and wire this
up all the way back to xfs_iomap_write_allocate().  In a subsequent
patch, we'll modify the writepage handler to call this.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: support bmapping delalloc extents in the CoW fork
Darrick J. Wong [Tue, 25 Oct 2016 01:37:50 +0000 (12:37 +1100)] 
xfs: support bmapping delalloc extents in the CoW fork

Source kernel commit: be51f8119c2f5e27437d2c4271f6419f3b8e609f

Allow the creation of delayed allocation extents in the CoW fork.  In
a subsequent patch we'll wire up iomap_begin to actually do this via
reflink helper functions.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: introduce the CoW fork
Darrick J. Wong [Tue, 25 Oct 2016 01:37:28 +0000 (12:37 +1100)] 
xfs: introduce the CoW fork

Source kernel commit: 3993baeb3c52f497d243a4a3b5510df97b22596b

Introduce a new in-core fork for storing copy-on-write delalloc
reservations and allocated extents that are in the process of being
written out.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: don't allow reflinked dir/dev/fifo/socket/pipe files
Darrick J. Wong [Tue, 25 Oct 2016 01:37:28 +0000 (12:37 +1100)] 
xfs: don't allow reflinked dir/dev/fifo/socket/pipe files

Source kernel commit: 11715a21bc3035440b853a0334685f1a55ca8c3c

Only non-rt files can be reflinked, so check that when we load an
inode.  Also, don't leak the attr fork if there's a failure.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: add reflink feature flag to geometry
Darrick J. Wong [Tue, 25 Oct 2016 01:37:28 +0000 (12:37 +1100)] 
xfs: add reflink feature flag to geometry

Source kernel commit: f0ec1b8ef11df0a51954df7e3ff3ca4aadb0d34b

Report the reflink feature in the XFS geometry so that xfs_info and
friends know the filesystem has this feature.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: return work remaining at the end of a bunmapi operation
Darrick J. Wong [Tue, 25 Oct 2016 01:37:28 +0000 (12:37 +1100)] 
xfs: return work remaining at the end of a bunmapi operation

Source kernel commit: 4453593be6c54e7581467e80f4a2757be098a3a2

Return the range of file blocks that bunmapi didn't free.  This hint
is used by CoW and reflink to figure out what part of an extent
actually got freed so that it can set up the appropriate atomic
remapping of just the freed range.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: implement deferred bmbt map/unmap operations
Darrick J. Wong [Tue, 25 Oct 2016 01:37:20 +0000 (12:37 +1100)] 
xfs: implement deferred bmbt map/unmap operations

Source kernel commit: 9f3afb57d5f1e7145986132106c6ca91f8136cc2

Implement deferred versions of the inode block map/unmap functions.
These will be used in subsequent patches to make reflink operations
atomic.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: pass bmapi flags through to bmap_del_extent
Darrick J. Wong [Tue, 25 Oct 2016 01:31:59 +0000 (12:31 +1100)] 
xfs: pass bmapi flags through to bmap_del_extent

Source kernel commit: 4847acf868bb426455c8b703c80ed5fc5e2ee556

Pass BMAPI_ flags from bunmapi into bmap_del_extent and extend
BMAPI_REMAP (which means "don't touch the allocator or the quota
accounting") to apply to bunmapi as well.  This will be used to
implement the unmap operation, which will be used by swapext.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: map an inode's offset to an exact physical block
Darrick J. Wong [Tue, 25 Oct 2016 01:31:37 +0000 (12:31 +1100)] 
xfs: map an inode's offset to an exact physical block

Source kernel commit: f65306ea5246ef3ff68a6abf85f5a73a04903366

Teach the bmap routine to know how to map a range of file blocks to a
specific range of physical blocks, instead of simply allocating fresh
blocks.  This enables reflink to map a file to blocks that are already
in use.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: log bmap intent items
Darrick J. Wong [Tue, 25 Oct 2016 01:30:19 +0000 (12:30 +1100)] 
xfs: log bmap intent items

Source kernel commit: 77d61fe45e720577a2cc0e9580fbc57d8faa7232

Provide a mechanism for higher levels to create BUI/BUD items, submit
them to the log, and a stub function to deal with recovered BUI items.
These parts will be connected to the rmapbt in a later patch.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: create bmbt update intent log items
Darrick J. Wong [Tue, 25 Oct 2016 01:29:43 +0000 (12:29 +1100)] 
xfs: create bmbt update intent log items

Source kernel commit: 6413a01420c2fbf03b3d059795f541caeb962e86

Create bmbt update intent/done log items to record redo information in
the log.  Because we roll transactions multiple times for reflink
operations, we also have to track the status of the metadata updates
that will be recorded in the post-roll transactions in case we crash
before committing the final transaction.  This mechanism enables log
recovery to finish what was already started.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: introduce reflink utility functions
Darrick J. Wong [Tue, 25 Oct 2016 01:29:22 +0000 (12:29 +1100)] 
xfs: introduce reflink utility functions

Source kernel commit: 350a27a6a65cc5dd2ba1b220e8641993414816d2

These functions will be used by the other reflink functions to find
the maximum length of a range of shared blocks.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.coM>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: reserve AG space for the refcount btree root
Darrick J. Wong [Tue, 25 Oct 2016 01:26:50 +0000 (12:26 +1100)] 
xfs: reserve AG space for the refcount btree root

Source kernel commit: d0e853f3600cd2a3f7c4a067dc38155c77c51df9

Reduce the max AG usable space size so that we always have space for
the refcount btree root.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: adjust refcount when unmapping file blocks
Darrick J. Wong [Tue, 25 Oct 2016 01:26:48 +0000 (12:26 +1100)] 
xfs: adjust refcount when unmapping file blocks

Source kernel commit: 62aab20f08758b1b171a73a54e0c72dd12beb980

When we're unmapping blocks from a reflinked file, decrease the
refcount of the affected blocks and free the extents that are no
longer in use.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: connect refcount adjust functions to upper layers
Darrick J. Wong [Tue, 25 Oct 2016 01:24:46 +0000 (12:24 +1100)] 
xfs: connect refcount adjust functions to upper layers

Source kernel commit: 33ba6129208475ec3aeffe6e9dad9f9afe022405

Plumb in the upper level interface to schedule and finish deferred
refcount operations via the deferred ops mechanism.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: adjust refcount of an extent of blocks in refcount btree
Darrick J. Wong [Tue, 25 Oct 2016 01:24:45 +0000 (12:24 +1100)] 
xfs: adjust refcount of an extent of blocks in refcount btree

Source kernel commit: 3172725814f9a689d6e8b3c7979b66403abf5dae

Provide functions to adjust the reference counts for an extent of
physical blocks stored in the refcount btree.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: log refcount intent items
Darrick J. Wong [Tue, 25 Oct 2016 01:20:28 +0000 (12:20 +1100)] 
xfs: log refcount intent items

Source kernel commit: f997ee2137175f5b2bd7ced52acf1ca51f04f420

Provide a mechanism for higher levels to create CUI/CUD items, submit
them to the log, and a stub function to deal with recovered CUI items.
These parts will be connected to the refcountbt in a later patch.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: create refcount update intent log items
Darrick J. Wong [Tue, 25 Oct 2016 01:20:28 +0000 (12:20 +1100)] 
xfs: create refcount update intent log items

Source kernel commit: baf4bcacb715cebd412b2f4bb69989ef24496523

Create refcount update intent/done log items to record redo
information in the log.  Because we need to roll transactions between
updating the bmbt mapping and updating the reverse mapping, we also
have to track the status of the metadata updates that will be recorded
in the post-roll transactions, just in case we crash before committing
the final transaction.  This mechanism enables log recovery to finish
what was already started.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: add refcount btree operations
Darrick J. Wong [Tue, 25 Oct 2016 01:20:26 +0000 (12:20 +1100)] 
xfs: add refcount btree operations

Source kernel commit: bdf28630b72154e5766cbad5874576b6f22e7237

Implement the generic btree operations required to manipulate refcount
btree blocks.  The implementation is similar to the bmapbt, though it
will only allocate and free blocks from the AG.

Since the refcount root and level fields are separate from the
existing roots and levels array, they need a separate logging flag.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
[hch: fix logging of AGF refcount btree fields]
Signed-off-by: Christoph Hellwig <hch@lst.de>
7 years agoxfs: account for the refcount btree in the alloc/free log reservation
Darrick J. Wong [Tue, 25 Oct 2016 01:01:06 +0000 (12:01 +1100)] 
xfs: account for the refcount btree in the alloc/free log reservation

Source kernel commit: f310bd2ecd37b17bf0042c9d1595329057970eb6

Every time we allocate or free a data extent, we might need to split
the refcount btree.  Reserve some blocks in the transaction to handle
this possibility.  Even though the deferred refcount code can roll a
transaction to avoid overloading the transaction, we can still exceed
the reservation.

Certain pathological workloads (1k blocks, no cowextsize hint, random
directio writes), cause a perfect storm wherein a refcount adjustment
of a large range of blocks causes full tree splits in two separate
extents in two separate refcount tree blocks; allocating new refcount
tree blocks causes rmap btree splits; and all the allocation activity
causes the freespace btrees to split, blowing the reservation.

(Reproduced by generic/167 over NFS atop XFS)

Signed-off-by: Christoph Hellwig <hch@lst.de>
[darrick.wong@oracle.com: add commit message]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>