]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/log
thirdparty/xfsprogs-dev.git
7 years agoxfs: verify dirblocklog correctly
Darrick J. Wong [Thu, 16 Feb 2017 03:03:54 +0000 (21:03 -0600)] 
xfs: verify dirblocklog correctly

Source kernel commit: 83d230eb5c638949350f4761acdfc0af5cb1bc00

sb_dirblklog is added to sb_blocklog to compute the directory block size
in bytes.  Therefore, we must compare the sum of both those values
against XFS_MAX_BLOCKSIZE_LOG, not just dirblklog.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: fix COW writeback race
Christoph Hellwig [Thu, 16 Feb 2017 03:03:54 +0000 (21:03 -0600)] 
xfs: fix COW writeback race

Source kernel commit: d2b3964a0780d2d2994eba57f950d6c9fe489ed8

Due to the way how xfs_iomap_write_allocate tries to convert the whole
found extents from delalloc to real space we can run into a race
condition with multiple threads doing writes to this same extent.
For the non-COW case that is harmless as the only thing that can happen
is that we call xfs_bmapi_write on an extent that has already been
converted to a real allocation.  For COW writes where we move the extent
from the COW to the data fork after I/O completion the race is, however,
not quite as harmless.  In the worst case we are now calling
xfs_bmapi_write on a region that contains hole in the COW work, which
will trip up an assert in debug builds or lead to file system corruption
in non-debug builds.  This seems to be reproducible with workloads of
small O_DSYNC write, although so far I've not managed to come up with
a with an isolated reproducer.

The fix for the issue is relatively simple:  tell xfs_bmapi_write
that we are only asked to convert delayed allocations and skip holes
in that case.

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>
7 years agoxfs: fix xfs_mode_to_ftype() prototype
Arnd Bergmann [Thu, 16 Feb 2017 03:03:54 +0000 (21:03 -0600)] 
xfs: fix xfs_mode_to_ftype() prototype

Source kernel commit: fd29f7af75b7adf250beccffa63746c6a88e2b74

A harmless warning just got introduced:

fs/xfs/libxfs/xfs_dir2.h:40:8: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers]

Removing the 'const' modifier avoids the warning and has no
other effect.

Fixes: 1fc4d33fed12 ("xfs: replace xfs_mode_to_ftype table with switch statement")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_repair: Fix uninit var in process_leaf_attr_level
Eric Sandeen [Thu, 26 Jan 2017 02:37:23 +0000 (20:37 -0600)] 
xfs_repair: Fix uninit var in process_leaf_attr_level

My unreviewed maintainer adjustment on the way in gets a
brown paper bag.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agotools/find-api-violations: fix fs -> fsr in the directory list
Darrick J. Wong [Thu, 26 Jan 2017 02:02:43 +0000 (20:02 -0600)] 
tools/find-api-violations: fix fs -> fsr in the directory list

Fix a stupid typo in the original commit.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_db: Interpret inode's di_format field as unsigned
chandan [Thu, 26 Jan 2017 02:02:43 +0000 (20:02 -0600)] 
xfs_db: Interpret inode's di_format field as unsigned

On a ppc64 big endian system, xfs_db would print the following,

xfs_db> p
core.magic = 0x494e
core.mode = 0100600
core.version = 3
core.format = -253

This is due to fp_dinode_fmt() interpretting the di_format field as
signed. This commit fixes the bug by passing BVUNSIGNED (instead of
BVSIGNED) as the argument to getbitval(). With this commit applied, we
now get,

xfs_db> p
core.magic = 0x494e
core.mode = 0100600
core.version = 3
core.format = 3 (btree)

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_repair: trash dirattr btrees that cycle to the root
Darrick J. Wong [Thu, 26 Jan 2017 02:02:43 +0000 (20:02 -0600)] 
xfs_repair: trash dirattr btrees that cycle to the root

If xfs_repair detects a dir/attr btree that cycles back to the root, the
tree should be cleared and/or rebuilt instead of simply aborting the
repair program.

[sandeen: move check outside main loop]

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>
7 years agoxfs_repair: zero shared_vn
Darrick J. Wong [Thu, 26 Jan 2017 02:02:43 +0000 (20:02 -0600)] 
xfs_repair: zero shared_vn

Since shared_vn always has to be zero, zero it at the start of repair.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_repair: strengthen geometry checks
Darrick J. Wong [Thu, 26 Jan 2017 02:02:43 +0000 (20:02 -0600)] 
xfs_repair: strengthen geometry checks

In xfs_repair, the inodelog, sectlog, and dirblklog values are read
directly into the xfs_mount structure without any sanity checking by the
verifier.  This results in xfs_repair segfaulting when those fields have
ridiculously high values because the pointer arithmetic runs us off the
end of the metadata buffers.  Therefore, reject the superblock if these
values are garbage and try to find one of the other ones.  Clean up the
dblocks checking to use the relevant macros.

The superblock field fuzzer (xfs/1301) triggers all these segfaults.

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>
7 years agoxfs_db: fix the 'source' command when passed as a -c option
Darrick J. Wong [Thu, 26 Jan 2017 02:02:43 +0000 (20:02 -0600)] 
xfs_db: fix the 'source' command when passed as a -c option

The 'source' command is supposed to read commands out of a file and
execute them.  This works great when done from an interactive command
line, but it doesn't work at all when invoked from the command line
because we never actually do anything with the opened file.

So don't load stdin into the input stack when we're only executing
command line options, and use that to decide if source_f is executing
from the command line so that we can actually run the input loop.  We'll
use this for the per-field fuzzing xfstests.

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>
7 years agolibxfs: sanitize agcount on load
Eric Sandeen [Thu, 26 Jan 2017 02:02:43 +0000 (20:02 -0600)] 
libxfs: sanitize agcount on load

Before we get into libxfs_initialize_perag and try to blindly
allocate a perag struct for every (possibly corrupted number of)
AGs, see if we can read the last one.  If not, assume it's corrupt,
and load only the first AG.

Do this only for an arbitrarily high-ish agcount, so that normal-ish
geometry on a possibly truncated file or device will still do
its best to make all readable AGs available.

Set xfs_db's exitcode to 1 if this happens.

Also teach metadump to detect this and exit appropriately if
truncated, as it resets exitcode to 0 for its own purposes internally.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_io: add DAX and CoW extent-size flags to chattr manpage
Eryu Guan [Thu, 26 Jan 2017 02:02:42 +0000 (20:02 -0600)] 
xfs_io: add DAX and CoW extent-size flags to chattr manpage

Manpage is not updated after adding set/clear DAX and CoW
extent-size flags support to xfs_io.

Signed-off-by: Eryu Guan <eguan@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_io: fix missing syncfs command
Amir Goldstein [Thu, 26 Jan 2017 02:02:42 +0000 (20:02 -0600)] 
xfs_io: fix missing syncfs command

Fixes commit c7dd81c7cd ("xfs_io: add sync and syncfs commands")

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_logprint: handle log operation split of inode item correctly
Hou Tao [Thu, 26 Jan 2017 02:02:42 +0000 (20:02 -0600)] 
xfs_logprint: handle log operation split of inode item correctly

If an inode log item has 4 log operations, and the 4th operation
(attr fork op) is splitted to the next log record due to the size
limitation of log record, xfs_logprint doesn't check whether or not
the 4th operation is in the current log record and print invalid data.

xfs_logprint also needs to calculate the count of splitted log
operations correctly instead of just returning 1.

The following is a diff of the output before and after the patch
is applied:

  =====================================================================
  cycle: 120  version: 2      lsn: 120,11014  tail_lsn: 120,427
  length of Log Record: 32256 prev offset: 10984      num ops: 243
  ......
  h_size: 32768
  ---------------------------------------------------------------------
  Oper (0): tid: 2db4353b  len: 0  clientid: TRANS  flags: START
  ......
  ---------------------------------------------------------------------
  Oper (240): tid: 2db4353b  len: 56  clientid: TRANS  flags: none
  INODE: #regs: 4   ino: 0x200a4bf  flags: 0x45   dsize: 64
          blkno: 10506832  len: 16  boff: 7936
  Oper (241): tid: 2db4353b  len: 96  clientid: TRANS  flags: none
  INODE CORE
  ......
  Oper (242): tid: 2db4353b  len: 64  clientid: TRANS  flags: none
  EXTENTS inode data
 -Oper (243): tid: 150000  len: 83886080  clientid: ERROR  flags: none
 -LOCAL attr data
  =====================================================================
  cycle: 120  version: 2      lsn: 120,11078  tail_lsn: 120,427
  length of Log Record: 3584  prev offset: 11014      num ops: 44
  ......
  h_size: 32768
  ---------------------------------------------------------------------
  Oper (0): tid: 2db4353b  len: 52  clientid: TRANS  flags: none
 +Left over region from split log item
  ---------------------------------------------------------------------
  Oper (1): tid: 2db4353b  len: 56  clientid: TRANS  flags: none
  INODE: #regs: 3   ino: 0x100047b  flags: 0x5   dsize: 64
  ......
  ---------------------------------------------------------------------

Signed-off-by: Hou Tao <houtao1@huawei.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfsprogs: remove irix support
Christoph Hellwig [Thu, 26 Jan 2017 02:02:42 +0000 (20:02 -0600)] 
xfsprogs: remove irix support

The port of the opensource xfsprogs to IRIX always was secondary to the
"real" tools in the IRIX tree.  IRIX has effectively been EOLed, and
dropping support for it will allow cleaning up various things in the XFS
tree where IRIX was oddly different from the other ports.  E.g. that the
xfsctl function needs a path and a fd, something we could replace with
just documenting to use ioctl in the future, or various ifdefs in the
headers shared with the kernel for structures provided by native headers
in IRIX.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: sanity check inode di_mode
Amir Goldstein [Thu, 26 Jan 2017 02:02:42 +0000 (20:02 -0600)] 
xfs: sanity check inode di_mode

Source kernel commit: a324cbf10a3c67aaa10c9f47f7b5801562925bc2

Check for invalid file type in xfs_dinode_verify()
and fail to load the inode structure from disk.

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.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>
7 years agoxfs: replace xfs_mode_to_ftype table with switch statement
Amir Goldstein [Thu, 26 Jan 2017 02:02:41 +0000 (20:02 -0600)] 
xfs: replace xfs_mode_to_ftype table with switch statement

Source kernel commit: 1fc4d33fed124fb182e8e6c214e973a29389ae83

The size of the xfs_mode_to_ftype[] conversion table
was too small to handle an invalid value of mode=S_IFMT.

Instead of fixing the table size, replace the conversion table
with a conversion helper that uses a switch statement.

Suggested-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: add missing include dependencies to xfs_dir2.h
Amir Goldstein [Thu, 26 Jan 2017 02:02:41 +0000 (20:02 -0600)] 
xfs: add missing include dependencies to xfs_dir2.h

Source kernel commit: b597dd5373a1ccc08218665dc8417433b1c09550

xfs_dir2.h dereferences some data types in inline functions
and fails to include those type definitions, e.g.:
xfs_dir2_data_aoff_t, struct xfs_da_geometry.

Signed-off-by: Amir Goldstein <amir73il@gmail.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>
7 years agoxfs: sanity check directory inode di_size
Amir Goldstein [Thu, 26 Jan 2017 02:02:41 +0000 (20:02 -0600)] 
xfs: sanity check directory inode di_size

Source kernel commit: 3c6f46eacd876bd723a9bad3c6882714c052fd8e

This changes fixes an assertion hit when fuzzing on-disk
i_mode values.

The easy case to fix is when changing an empty file
i_mode to S_IFDIR. In this case, xfs_dinode_verify()
detects an illegal zero size for directory and fails
to load the inode structure from disk.

For the case of non empty file whose i_mode is changed
to S_IFDIR, the ASSERT() statement in xfs_dir2_isblock()
is replaced with return -EFSCORRUPTED, to avoid interacting
with corrupted jusk also when XFS_DEBUG is disabled.

Suggested-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_repair: update the manual content about xfs_repair exit status
Zirong Lang [Thu, 12 Jan 2017 20:12:42 +0000 (14:12 -0600)] 
xfs_repair: update the manual content about xfs_repair exit status

The man 8 xfs_repair said "xfs_repair run without the -n option will
always return a status code of 0". That's not correct.

xfs_repair will return 2 if it finds a fs log which needs to be
replayed or cleared, 1 if runtime error is encountered, and 0 for
all other cases.

[ sandeen: editing for clarity ]

Signed-off-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_repair.8: document dirty log conditions
Darrick J. Wong [Thu, 12 Jan 2017 20:12:42 +0000 (14:12 -0600)] 
xfs_repair.8: document dirty log conditions

Add a section describing what is a dirty log, why xfs_repair won't touch
such things, and what one can do to clear the condition and check the
filesystem.

[ sandeen: light editing, minor man-page-ification ]

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>
7 years agolibxfs-apply: minor improvements
Eric Sandeen [Thu, 12 Jan 2017 20:12:42 +0000 (14:12 -0600)] 
libxfs-apply: minor improvements

Three quick improvements to libxfs-apply:

- Skip already-cross-merged commits, based on the
  "Source XXX commit" line in the commitlog.

- Be clearer about which patch failed if it does

- Clean up guilt better after a failed application

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agobuild: add tar.xz target
Eric Sandeen [Thu, 12 Jan 2017 20:12:42 +0000 (14:12 -0600)] 
build: add tar.xz target

kup generates .xz files, and fedora RPMs now use that.
It'd be nice to have a handy target to generate .xz
files locally, so hack that in.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoUpdate licenses in COPYING file
Eric Sandeen [Thu, 12 Jan 2017 20:12:42 +0000 (14:12 -0600)] 
Update licenses in COPYING file

doc/COPYING was a mess, it included old versions of licenses
and included the GPLv2 licence twice.  Update licenses,
URLs, and elimiate duplicate info.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfsprogs: fix a couple 32-bit build warnings
Eric Sandeen [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
xfsprogs: fix a couple 32-bit build warnings

mremap_f can't turn a long long into a pointer, and
dump_dirent needs proper %llx for u64 printing.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_io: implement 'utimes' command
Deepa Dinamani [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
xfs_io: implement 'utimes' command

Add the utimes command to provide a way to utilize
the futimens C library call. This is the
interface to the utimensat system call, which updates
the mtime and atime of a file.

[ sandeen: minor merge fixups, re-alphabetization ]

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxcmd: add non-iterating user commands
Dave Chinner [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
libxcmd: add non-iterating user commands

Right now command iteration is not directly controllable by the
user; it is controlled entirely by the application command flag
setup. Sometimes we don't want commands to iterate but only operate
on the currently selected object.

For example, the stat command iterates:

$ xfs_io -c "open -r foo" -c "open bar" -c "file" -c "stat" foo
 000  foo            (foreign,non-sync,non-direct,read-write)
 001  foo            (foreign,non-sync,non-direct,read-only)
[002] bar            (foreign,non-sync,non-direct,read-write)
fd.path = "foo"
fd.flags = non-sync,non-direct,read-write
stat.ino = 462399
stat.type = regular file
stat.size = 776508
stat.blocks = 1528
fd.path = "foo"
fd.flags = non-sync,non-direct,read-only
stat.ino = 462399
stat.type = regular file
stat.size = 776508
stat.blocks = 1528
fd.path = "bar"
fd.flags = non-sync,non-direct,read-write
stat.ino = 475227
stat.type = regular file
stat.size = 0
stat.blocks = 0
$

To do this, add a function to supply a "non-iterating" user command
that will execute an iterating-capable command as though it
CMD_FLAG_ONESHOT was set. Add a new command line option to xfs_io to
drive it (-C <command>) and connect it all up. Document it in the
xfs_io man page, too.

The result of "-C stat":

$ xfs_io -c "open -r foo" -c "open bar" -c "file" -C "stat" foo
 000  foo            (foreign,non-sync,non-direct,read-write)
 001  foo            (foreign,non-sync,non-direct,read-only)
[002] bar            (foreign,non-sync,non-direct,read-write)
fd.path = "bar"
fd.flags = non-sync,non-direct,read-write
stat.ino = 475227
stat.type = regular file
stat.size = 0
stat.blocks = 0
$

Is that we only see the stat output for the active open file
which is "bar".

[ sandeen: fix arg in command_loop printf ]

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_io: make various commands one-shot only
Dave Chinner [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
xfs_io: make various commands one-shot only

It makes no sense to iterate the file table for some xfs_io
commands. Some commands are already marked in this way, but lots of
them are not and this leads to bad behaviour. For example, the open
command will run until the process fd table is full and EMFILE is
returned rather than just opening the specified file once.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxcmd: don't check generic library commands
Dave Chinner [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
libxcmd: don't check generic library commands

The generic "help" and "quit" commands have different methods of
skipping user provided command check functions that may prevent them
from running. xfs_quota use CMD_ALL_FSTYPES and xfs_io uses
CMD_FLAG_ONESHOT.  Add a new CMD_FLAG_LIBRARY to indicate commands
that should not be checked against application specific check
functions so they are always present and can be run regardless of
the context in which they are run.

This gets rid of the CMD_ALL_FSTYPES flag, and enables us to remove
the ONESHOT check in xfs_io so we use only app specific flags for
determining if app commands should run or not.

[ sandeen: remove CMD_ALL_FSTYPES definition ]

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxcmd: merge command() and iterate_command()
Dave Chinner [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
libxcmd: merge command() and iterate_command()

Simplify the command loop further by merging the command loop
iteration checks with the command execution function. This removes
all visibility of command iteration from the main command execution
loop, and enables us to factor and clean up the command loop
processing neatly.

[ sandeen: align process_input() args ]

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxcmd: rename args_command to command_iterator
Dave Chinner [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
libxcmd: rename args_command to command_iterator

It is not particularly easy to understand the function of the
args_command abstraction. it's actually a command iterator interface
that allows callers to specify the target of the command and iterate
the command multiple times over different targets. Rename and
document the abstraction to make this functionality clear.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxcmd: check CMD_FLAG_GLOBAL inside args_command()
Dave Chinner [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
libxcmd: check CMD_FLAG_GLOBAL inside args_command()

Rather than having multiple methods of executing commands from the
CLI, use CMD_FLAG_GLOBAL to indicate a one-shot command rather than
an iterative command from args_command(). This simplifies the main
loop processing.

To make it more obvious what this CMD_FLAG_GLOBAL flag does, rename
it to CMD_FLAG_ONESHOT to indicate that the command should only ever
be executed once and not iterated.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_io: fix some documentation problems
Darrick J. Wong [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
xfs_io: fix some documentation problems

Describe the numberless (i.e. "reflink the whole file") behavior
in the xfs_io help system and since the clone/dedupe ioctls were
promoted to the VFS before XFS reflink landed, mention those in
the manpage.

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>
7 years agoxfs_io: fix the minimum arguments to the reflink command
Darrick J. Wong [Thu, 12 Jan 2017 20:12:41 +0000 (14:12 -0600)] 
xfs_io: fix the minimum arguments to the reflink command

The reflink command can reflink the entirety of two files if the
offsets and lengths are not specified... but we forgot to permit
that case.

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>
7 years agoxfs_io: prefix dedupe command error messages consistently
Darrick J. Wong [Thu, 12 Jan 2017 20:12:40 +0000 (14:12 -0600)] 
xfs_io: prefix dedupe command error messages consistently

Prefix the perror output of the dedupe command consistently.  All the
other perror calls reference the ioctl name directly, so we might as
well do that for all the dedupe cases.

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>
7 years agoxfs_io: Improvements to copy_range return code handling
Anna Schumaker [Thu, 12 Jan 2017 20:12:40 +0000 (14:12 -0600)] 
xfs_io: Improvements to copy_range return code handling

If copy_file_range() returns 0, then that means no data was copied.  We
should break out of the loop in this case to prevent looping
indefinitely.

Additionally, if an error is returned by copy_file_range() then we need
to print out the string form to be used by error checking tests in
xfstests.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_io: implement 'set_encpolicy' and 'get_encpolicy' commands
Eric Biggers [Thu, 12 Jan 2017 20:12:40 +0000 (14:12 -0600)] 
xfs_io: implement 'set_encpolicy' and 'get_encpolicy' commands

Add set_encpolicy and get_encpolicy commands to xfs_io so that xfstests
will be able to test filesystem encryption using the actual user API,
not just hacked in with a mount option.  These commands use the common
"fscrypt" API currently implemented by ext4 and f2fs, but it's also
under development for ubifs and planned for xfs.

Note that to get encrypted files to actually work, it's also necessary
to add a key to the kernel keyring.  This patch does not add a command
for this to xfs_io because it's possible to do it using keyctl.  keyctl
can also be used to remove keys, revoke keys, invalidate keys, etc.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_logprint: di_gen is unsigned
Eric Sandeen [Thu, 12 Jan 2017 20:12:40 +0000 (14:12 -0600)] 
xfs_logprint: di_gen is unsigned

di_gen is unsigned:

        __uint32_t      di_gen;         /* generation number */

but we print it as a signed int in logprint, so see oddities like:

 forkoff:24  dmevmask:0x0  dmstate:0  flags:0x0  gen:-628807103

Fix this.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_io.8: remove duplicate .TP commands
Eric Biggers [Thu, 12 Jan 2017 20:12:40 +0000 (14:12 -0600)] 
xfs_io.8: remove duplicate .TP commands

The right margin of the xfs_io man page was being pushed inwards due to
extra .TP commands, making all the text below hard to read.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agobuild: add missing AC_PROG_INSTALL
Jan Engelhardt [Thu, 12 Jan 2017 20:12:40 +0000 (14:12 -0600)] 
build: add missing AC_PROG_INSTALL

$ autoreconf -fi
$ ./configure
configure: error: cannot find install-sh, install.sh, or shtool in . "."/.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agobuild: resolve autoheader warning
Jan Engelhardt [Thu, 12 Jan 2017 20:12:40 +0000 (14:12 -0600)] 
build: resolve autoheader warning

$ autoreconf -fi
[...]
autoheader: warning: missing template: HAVE_UMODE_T
autoheader: Use AC_DEFINE([HAVE_UMODE_T], [], [Description])
autoreconf: /usr/bin/autoheader failed with exit status: 1

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_io: fix building with musl
Ralph Sennhauser [Thu, 12 Jan 2017 20:12:40 +0000 (14:12 -0600)] 
xfs_io: fix building with musl

The fallback in case the libc doesn't have or doesn't advertise the
existence of d_reclen in struct dirent uses d_namlen. Musl neither
advertises d_reclen nor does it have a d_namlen member.

Calculate the value for d_namlen from d_name in the fallback path.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
Reviewed--by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agobuild: Allow compiling xfsprogs in a cross compile environment
Gwendal Grignou [Thu, 12 Jan 2017 20:12:29 +0000 (14:12 -0600)] 
build: Allow compiling xfsprogs in a cross compile environment

Without this patch, we are using the same compiler and options for the host
compiler (BUILD_CC) and the target compiler (CC), and we would get error
messages at compilation:
x86_64-pc-linux-gnu-gcc -O2 -O2 -pipe -march=armv7-a -mtune=cortex-a15 ...
x86_64-pc-linux-gnu-gcc.real: error: unrecognized command line option
'-mfpu=neon'
'-mfloat-abi=hard'
'-clang-syntax'
'-mfpu=neon'
'-mfloat-abi=hard'
'-clang-syntax'

Add BUILD_CC and BUILD_CFLAGS as precious variables to allow setting it up
from the ebuild.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: don't rely on ->total in xfs_alloc_space_available libxfs-4.10-sync
Christoph Hellwig [Wed, 11 Jan 2017 02:09:21 +0000 (20:09 -0600)] 
xfs: don't rely on ->total in xfs_alloc_space_available

Source kernel commit: 12ef830198b0d71668eb9b59f9ba69d32951a48a

->total is a bit of an odd parameter passed down to the low-level
allocator all the way from the high-level callers.  It's supposed to
contain the maximum number of blocks to be allocated for the whole
transaction [1].

But in xfs_iomap_write_allocate we only convert existing delayed
allocations and thus only have a minimal block reservation for the
current transaction, so xfs_alloc_space_available can't use it for
the allocation decisions.  Use the maximum of args->total and the
calculated block requirement to make a decision.  We probably should
get rid of args->total eventually and instead apply ->minleft more
broadly, but that will require some extensive changes all over.

[1] which creates lots of confusion as most callers don't decrement it
once doing a first allocation.  But that's for a separate series.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: adjust allocation length in xfs_alloc_space_available
Christoph Hellwig [Wed, 11 Jan 2017 02:08:21 +0000 (20:08 -0600)] 
xfs: adjust allocation length in xfs_alloc_space_available

Source kernel commit: 54fee133ad59c87ab01dd84ab3e9397134b32acb

We must decide in xfs_alloc_fix_freelist if we can perform an
allocation from a given AG is possible or not based on the available
space, and should not fail the allocation past that point on a
healthy file system.

But currently we have two additional places that second-guess
xfs_alloc_fix_freelist: xfs_alloc_ag_vextent tries to adjust the
maxlen parameter to remove the reservation before doing the
allocation (but ignores the various minium freespace requirements),
and xfs_alloc_fix_minleft tries to fix up the allocated length
after we've found an extent, but ignores the reservations and also
doesn't take the AGFL into account (and thus fails allocations
for not matching minlen in some cases).

Remove all these later fixups and just correct the maxlen argument
inside xfs_alloc_fix_freelist once we have the AGF buffer locked.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: fix bogus minleft manipulations
Christoph Hellwig [Wed, 11 Jan 2017 02:07:48 +0000 (20:07 -0600)] 
xfs: fix bogus minleft manipulations

Source kernel commit: 255c516278175a6dc7037d1406307f35237d8688

We can't just set minleft to 0 when we're low on space - that's exactly
what we need minleft for: to protect space in the AG for btree block
allocations when we are low on free space.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: bump up reserved blocks in xfs_alloc_set_aside
Christoph Hellwig [Wed, 11 Jan 2017 02:07:05 +0000 (20:07 -0600)] 
xfs: bump up reserved blocks in xfs_alloc_set_aside

Source kernel commit: 5149fd327f16e393c1d04fa5325ab072c32472bf

Setting aside 4 blocks globally for bmbt splits isn't all that useful,
as different threads can allocate space in parallel.  Bump it to 4
blocks per AG to allow each thread that is currently doing an
allocation to dip into it separately.  Without that we may no have
enough reserved blocks if there are enough parallel transactions
in an almost out space file system that all run into bmap btree
splits.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: use the actual AG length when reserving blocks
Darrick J. Wong [Wed, 11 Jan 2017 02:06:43 +0000 (20:06 -0600)] 
xfs: use the actual AG length when reserving blocks

Source kernel commit: 20e73b000bcded44a91b79429d8fa743247602ad

We need to use the actual AG length when making per-AG reservations,
since we could otherwise end up reserving more blocks out of the last
AG than there are actual blocks.

Complained-about-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: use GPF_NOFS when allocating btree cursors
Darrick J. Wong [Tue, 10 Jan 2017 02:18:50 +0000 (20:18 -0600)] 
xfs: use GPF_NOFS when allocating btree cursors

Source kernel commit: b24a978c377be5f14e798cb41238e66fe51aab2f

Use NOFS for allocating btree cursors, since they can be called
under the ilock.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: ignore leaf attr ichdr.count in verifier during log replay
Eric Sandeen [Tue, 10 Jan 2017 02:18:50 +0000 (20:18 -0600)] 
xfs: ignore leaf attr ichdr.count in verifier during log replay

Source kernel commit: 2e1d23370e75d7d89350d41b4ab58c7f6a0e26b2

When we create a new attribute, we first create a shortform
attribute, and try to fit the new attribute into it.
If that fails, we copy the (empty) attribute into a leaf attribute,
and do the copy again.  Thus there can be a transient state where
we have an empty leaf attribute.

If we encounter this during log replay, the verifier will fail.
So add a test to ignore this part of the leaf attr verification
during log replay.

Thanks as usual to dchinner for spotting the problem.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: optimise CRC updates
Dave Chinner [Tue, 10 Jan 2017 02:18:50 +0000 (20:18 -0600)] 
xfs: optimise CRC updates

Source kernel commit: cae028df53449905c944603df624ac94bc619661

Nick Piggin reported that the CRC overhead in an fsync heavy
workload was higher than expected on a Power8 machine. Part of this
was to do with the fact that the power8 CRC implementation is not
efficient for CRC lengths of less than 512 bytes, and so the way we
split the CRCs over the CRC field means a lot of the CRCs are
reduced to being less than than optimal size.

To optimise this, change the CRC update mechanism to zero the CRC
field first, and then compute the CRC in one pass over the buffer
and write the result back into the buffer. We can do this safely
because anything writing a CRC has exclusive access to the buffer
the CRC is being calculated over.

We leave the CRC verify code the same - it still splits the CRC
calculation - because we do not want read-only operations modifying
the underlying buffer. This is because read-only operations may not
have an exclusive access to the buffer guaranteed, and so temporary
modifications could leak out to to other processes accessing the
buffer concurrently.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: make xfs btree stats less huge
Dave Chinner [Tue, 10 Jan 2017 02:18:49 +0000 (20:18 -0600)] 
xfs: make xfs btree stats less huge

Source kernel commit: 11ef38afe98cc7ad1a46ef24945232ec1760d5e2

Embedding a switch statement in every btree stats inc/add adds a lot
of code overhead to the core btree infrastructure paths. Stats are
supposed to be small and lightweight, but the btree stats have
become big and bloated as we've added more btrees. It needs fixing
because the reflink code will just add more overhead again.

Convert the v2 btree stats to arrays instead of independent
variables, and instead use the type to index the specific btree
array via an enum. This allows us to use array based indexing
to update the stats, rather than having to derefence variables
specific to the btree type.

If we then wrap the xfsstats structure in a union and place uint32_t
array beside it, and calculate the correct btree stats array base
array index when creating a btree cursor,  we can easily access
entries in the stats structure without having to switch names based
on the btree type.

We then replace with the switch statement with a simple set of stats
wrapper macros, resulting in a significant simplification of the
btree stats code, and:

text    data     bss     dec     hex filename
48905     144       8   49057    bfa1 fs/xfs/libxfs/xfs_btree.o.old
36793     144       8   36945    9051 fs/xfs/libxfs/xfs_btree.o

it reduces the core btree infrastructure code size by close to 25%!

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: don't allow di_size with high bit set
Darrick J. Wong [Tue, 10 Jan 2017 02:18:49 +0000 (20:18 -0600)] 
xfs: don't allow di_size with high bit set

Source kernel commit: ef388e2054feedaeb05399ed654bdb06f385d294

The on-disk field di_size is used to set i_size, which is a signed
integer of loff_t.  If the high bit of di_size is set, we'll end up with
a negative i_size, which will cause all sorts of problems.  Since the
VFS won't let us create a file with such length, we should catch them
here in the verifier too.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: error out if trying to add attrs and anextents > 0
Darrick J. Wong [Tue, 10 Jan 2017 02:18:49 +0000 (20:18 -0600)] 
xfs: error out if trying to add attrs and anextents > 0

Source kernel commit: 0f352f8ee8412bd9d34fb2a6411241da61175c0e

We shouldn't assert if somehow we end up trying to add an attr fork to
an inode that apparently already has attr extents because this is an
indication of on-disk corruption.  Instead, return an error code to
userspace.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: don't crash if reading a directory results in an unexpected hole
Darrick J. Wong [Tue, 10 Jan 2017 02:18:49 +0000 (20:18 -0600)] 
xfs: don't crash if reading a directory results in an unexpected hole

Source kernel commit: 96a3aefb8ffde23180130460b0b2407b328eb727

In xfs_dir3_data_read, we can encounter the situation where err == 0 and
*bpp == NULL if the given bno offset happens to be a hole; this leads to
a crash if we try to set the buffer type after the _da_read_buf call.
Holes can happen due to corrupt or malicious entries in the bmbt data,
so be a little more careful when we're handling buffers.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: complain if we don't get nextents bmap records
Darrick J. Wong [Tue, 10 Jan 2017 02:18:49 +0000 (20:18 -0600)] 
xfs: complain if we don't get nextents bmap records

Source kernel commit: 356a3225222e5bc4df88aef3419fb6424f18ab69

When reading into memory all extents of a btree-format inode fork,
complain if the number of extents we find is not the same as the number
of extents reported in the inode core.  This is needed to stop an IO
action from accessing the garbage areas of the in-core fork.

[dchinner: removed redundant assert]

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: check for bogus values in btree block headers
Darrick J. Wong [Tue, 10 Jan 2017 02:18:49 +0000 (20:18 -0600)] 
xfs: check for bogus values in btree block headers

Source kernel commit: bb3be7e7c1c18e1b141d4cadeb98cc89ecf78099

When we're reading a btree block, make sure that what we retrieved
matches the owner and level; and has a plausible number of records.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: forbid AG btrees with level == 0
Darrick J. Wong [Tue, 10 Jan 2017 02:18:49 +0000 (20:18 -0600)] 
xfs: forbid AG btrees with level == 0

Source kernel commit: d2a047f31e86941fa896e0e3271536d50aba415e

There is no such thing as a zero-level AG btree since even a single-node
zero-records btree has one level.  Btree cursor constructors read
cur_nlevels straight from disk and then access things like
cur_bufs[cur_nlevels - 1] which is /really/ bad if cur_nlevels is zero!
Therefore, strengthen the verifiers to prevent this possibility.

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: several xattr functions can be void
Eric Sandeen [Tue, 10 Jan 2017 02:18:49 +0000 (20:18 -0600)] 
xfs: several xattr functions can be void

Source kernel commit: f7a136aee3c1c3f7daf87197b3b3c361744a2812

There are a handful of xattr functions which now return
nothing but zero.  They can be made void, chased through calling
functions, and error handling etc can be removed.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: handle cow fork in xfs_bmap_trace_exlist
Eric Sandeen [Tue, 10 Jan 2017 02:18:49 +0000 (20:18 -0600)] 
xfs: handle cow fork in xfs_bmap_trace_exlist

Source kernel commit: c44a1f22626c153976289e1cd67bdcdfefc16e1f

By inspection, xfs_bmap_trace_exlist isn't handling cow forks,
and will trace the data fork instead.

Fix this by setting state appropriately if whichfork
== XFS_COW_FORK.

()___()
< @ @ >
 |   |
 {o_o}
  (|)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: pass state not whichfork to trace_xfs_extlist
Eric Sandeen [Tue, 10 Jan 2017 02:18:48 +0000 (20:18 -0600)] 
xfs: pass state not whichfork to trace_xfs_extlist

Source kernel commit: 7710517fc37b1899722707883b54694ea710b3c0

When xfs_bmap_trace_exlist called trace_xfs_extlist,
it sent in the "whichfork" var instead of the bmap "state"
as expected (even though state was already set up for this
purpose).

As a result, the xfs_bmap_class in tracing code used
"whichfork" not state in xfs_iext_state_to_fork(), and got
the wrong ifork pointer.  It all goes downhill from
there, including an ASSERT when ifp_bytes is empty
by the time it reaches xfs_iext_get_ext():

XFS: Assertion failed: idx < ifp->if_bytes / sizeof(xfs_bmbt_rec_t)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: Move AGI buffer type setting to xfs_read_agi
Eric Sandeen [Tue, 10 Jan 2017 02:18:48 +0000 (20:18 -0600)] 
xfs: Move AGI buffer type setting to xfs_read_agi

Source kernel commit: 200237d6746faaeaf7f4ff4abbf13f3917cee60a

We've missed properly setting the buffer type for
an AGI transaction in 3 spots now, so just move it
into xfs_read_agi() and set it if we are in a transaction
to avoid the problem in the future.

This is similar to how it is done in i.e. the dir3
and attr3 read functions.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: track preallocation separately in xfs_bmapi_reserve_delalloc()
Brian Foster [Tue, 10 Jan 2017 02:18:48 +0000 (20:18 -0600)] 
xfs: track preallocation separately in xfs_bmapi_reserve_delalloc()

Source kernel commit: 974ae922efd93b07b6cdf989ae959883f6f05fd8

Speculative preallocation is currently processed entirely by the callers
of xfs_bmapi_reserve_delalloc(). The caller determines how much
preallocation to include, adjusts the extent length and passes down the
resulting request.

While this works fine for post-eof speculative preallocation, it is not
as reliable for COW fork preallocation. COW fork preallocation is
implemented via the cowextszhint, which aligns the start offset as well
as the length of the extent. Further, it is difficult for the caller to
accurately identify when preallocation occurs because the returned
extent could have been merged with neighboring extents in the fork.

To simplify this situation and facilitate further COW fork preallocation
enhancements, update xfs_bmapi_reserve_delalloc() to take a separate
preallocation parameter to incorporate into the allocation request. The
preallocation blocks value is tacked onto the end of the request and
adjusted to accommodate neighboring extents and extent size limits.
Since xfs_bmapi_reserve_delalloc() now knows precisely how much
preallocation was included in the allocation, it can also tag the inodes
appropriately to support preallocation reclaim.

Note that xfs_bmapi_reserve_delalloc() callers are not yet updated to
use the preallocation mechanism. This patch should not change behavior
outside of correctly tagging reflink inodes when start offset
preallocation occurs (which the caller does not handle correctly).

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agofs: xfs: libxfs: constify xfs_nameops structures
Bhumika Goyal [Tue, 10 Jan 2017 02:18:48 +0000 (20:18 -0600)] 
fs: xfs: libxfs: constify xfs_nameops structures

Source kernel commit: cf7841c12d85d1fe0ad33fb8bc5746809a882010

Declare the structure xfs_nameops as const as it is only stored in the
m_dirnameops field of a xfs_mount structure. This field is of type
const struct xfs_nameops *, so xfs_nameops structures having this
property can be declared as const.
Done using Coccinelle:
@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct xfs_nameops i@p = {...};

@ok1@
identifier r1.i;
position p;
struct xfs_mount mp;
@@
mp.m_dirnameops=&i@p

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct xfs_nameops i={...};

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct xfs_nameops i;

File size before:
text    data     bss     dec     hex filename
5302      85       0    5387    150b fs/xfs/libxfs/xfs_dir2.o

File size after:
text    data     bss     dec     hex filename
5318      69       0    5387    150b fs/xfs/libxfs/xfs_dir2.o

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: factor rmap btree size into the indlen calculations
Darrick J. Wong [Tue, 10 Jan 2017 02:18:48 +0000 (20:18 -0600)] 
xfs: factor rmap btree size into the indlen calculations

Source kernel commit: fd26a88093bab6529ea2de819114ca92dbd1d71d

When we're estimating the amount of space it's going to take to satisfy
a delalloc reservation, we need to include the space that we might need
to grow the rmapbt.  This helps us to avoid running out of space later
when _iomap_write_allocate needs more space than we reserved.  Eryu Guan
observed this happening on generic/224 when sunit/swidth were set.

Reported-by: Eryu Guan <eguan@redhat.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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: remove NULLEXTNUM
Christoph Hellwig [Tue, 10 Jan 2017 02:18:47 +0000 (20:18 -0600)] 
xfs: remove NULLEXTNUM

Source kernel commit: 0e8d630ba039d9976d250eedb82c3a423ad15447

We only ever set a field to this constant for an impossible to reach
error case in xfs_bmap_search_extents.  That functions has been removed,
so we can remove the constant as well.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: remove xfs_bmap_search_extents
Christoph Hellwig [Tue, 10 Jan 2017 02:18:47 +0000 (20:18 -0600)] 
xfs: remove xfs_bmap_search_extents

Source kernel commit: 6edc977f775e5ac10655b03607ef091d2b06f2f6

Now that all users are gone.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agorepair: use new extent lookup helpers in bmap_next_offset
Eric Sandeen [Tue, 10 Jan 2017 02:18:47 +0000 (20:18 -0600)] 
repair: use new extent lookup helpers in bmap_next_offset

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: remove prev argument to xfs_bmapi_reserve_delalloc
Christoph Hellwig [Tue, 10 Jan 2017 02:18:47 +0000 (20:18 -0600)] 
xfs: remove prev argument to xfs_bmapi_reserve_delalloc

Source kernel commit: 65c5f419788d623a0410eca1866134f5e4628594

We can easily lookup the previous extent for the cases where we need it,
which saves the callers from looking it up for us later in the series.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: use new extent lookup helpers in __xfs_bunmapi
Christoph Hellwig [Tue, 10 Jan 2017 02:18:47 +0000 (20:18 -0600)] 
xfs: use new extent lookup helpers in __xfs_bunmapi

Source kernel commit: 7efc794561f6bfe34d26c3724289108f6cda3a4d

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: use new extent lookup helpers in xfs_bmapi_write
Christoph Hellwig [Tue, 10 Jan 2017 02:18:47 +0000 (20:18 -0600)] 
xfs: use new extent lookup helpers in xfs_bmapi_write

Source kernel commit: 2d58f6ef79db10257d77ae8cd8e9e8432816c9ac

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: use new extent lookup helpers in xfs_bmapi_read
Christoph Hellwig [Tue, 10 Jan 2017 02:18:47 +0000 (20:18 -0600)] 
xfs: use new extent lookup helpers in xfs_bmapi_read

Source kernel commit: 334f3423d6a6c39483aa0744ea044e105ca0e5ae

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: cleanup xfs_bmap_last_before
Christoph Hellwig [Tue, 10 Jan 2017 02:18:47 +0000 (20:18 -0600)] 
xfs: cleanup xfs_bmap_last_before

Source kernel commit: 86685f7ba5c0fdbcc159ecdbcc530b9b3509a675

Rewrite the function using xfs_iext_lookup_extent and xfs_iext_get_extent,
and massage the flow into something easily understandable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: new inode extent list lookup helpers
Christoph Hellwig [Tue, 10 Jan 2017 02:18:39 +0000 (20:18 -0600)] 
xfs: new inode extent list lookup helpers

Source kernel commit: 93533c7855c3c78c8a900cac65c8d669bb14935d

xfs_iext_lookup_extent looks up a single extent at the passed in offset,
and returns the extent covering the area, or the one behind it in case
of a hole, as well as the index of the returned extent in arguments,
as well as a simple bool as return value that is set to false if no
extent could be found because the offset is behind EOF.  It is a simpler
replacement for xfs_bmap_search_extent that leaves looking up the rarely
needed previous extent to the caller and has a nicer calling convention.

xfs_iext_get_extent is a helper for iterating over the extent list,
it takes an extent index as input, and returns the extent at that index
in it's expanded form in an argument if it exists.  The actual return
value is a bool whether the index is valid or not.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: check minimum block size for CRC filesystems
Darrick J. Wong [Tue, 10 Jan 2017 02:17:39 +0000 (20:17 -0600)] 
xfs: check minimum block size for CRC filesystems

Source kernel commit: bec9d48d7a303a5bb95c05961ff07ec7eeb59058

[dchinner: cleaned up XFS_MIN_CRC_BLOCKSIZE check]

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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: provide helper for counting extents from if_bytes
Eric Sandeen [Tue, 10 Jan 2017 02:16:39 +0000 (20:16 -0600)] 
xfs: provide helper for counting extents from if_bytes

Source kernel commit: 5d829300bee000980a09ac2ccb761cb25867b67c

The open-coded pattern:

ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t)

is all over the xfs code; provide a new helper
xfs_iext_count(ifp) to count the number of inline extents
in an inode fork.

[dchinner: pick up several missed conversions]

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: check return value of _trans_reserve_quota_nblks
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
xfs: check return value of _trans_reserve_quota_nblks

Souce kernel commit: 4fd29ec47212c8cbf98916af519019ccc5e58e49

Check the return value of xfs_trans_reserve_quota_nblks for errors.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxfs: clean up _dir2_data_freescan
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
libxfs: clean up _dir2_data_freescan

Source kernel commit: 523b2e76e3ecb54e0ec8651e32291bdaefc5f866

Refactor the implementations of xfs_dir2_data_freescan into a
routine that takes the raw directory block parameters and
a second function that figures out the raw parameters from the
directory inode.  This enables us to use the exact same code
for both userspace and the kernel, since repair knows exactly
which directory block geometry parameters it needs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxfs: synchronize dinode_verify with userspace
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
libxfs: synchronize dinode_verify with userspace

Source kernel commit: 420fbeb4bff483d89dd8de9242b8fd83e2eb3527

The userspace version of _dinode_verify takes a raw inode number
instead of an inode itself.  Since neither version actually needs
the inode, port the changes to the kernel.  This will also reduce
the libxfs diff noise.

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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: set XFS_DA_OP_OKNOENT in xfs_attr_get
Eric Sandeen [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
xfs: set XFS_DA_OP_OKNOENT in xfs_attr_get

Source kernel commit: c400ee3ed1b13d45adde68e12254dc6ab6977b59

It's entirely possible for userspace to ask for an xattr which
does not exist.

Normally, there is no problem whatsoever when we ask for such
a thing, but when we look at an obfuscated metadump image
on a debug kernel with selinux, we trip over this ASSERT in
xfs_da3_path_shift():

*result = -ENOENT;      /* we're out of our tree */
ASSERT(args->op_flags & XFS_DA_OP_OKNOENT);

It (more or less) only shows up in the above scenario, because
xfs_metadump obfuscates attr names, but chooses names which
keep the same hash value - and xfs_da3_node_lookup_int does:

if (((retval == -ENOENT) || (retval == -ENOATTR)) &&
(blk->hashval == args->hashval)) {
error = xfs_da3_path_shift(state, &state->path, 1, 1,
&retval);

IOWS, we only get down to the xfs_da3_path_shift() ASSERT
if we are looking for an xattr which doesn't exist, but we
find xattrs on disk which have the same hash, and so might be
a hash collision, so we try the path shift.  When *that*
fails to find what we're looking for, we hit the assert about
XFS_DA_OP_OKNOENT.

Simply setting XFS_DA_OP_OKNOENT in xfs_attr_get solves this
rather corner-case problem with no ill side effects.  It's
fine for an attr name lookup to fail.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs: fix btree cursor error cleanups
Brian Foster [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
xfs: fix btree cursor error cleanups

Source kernel commit: f307080a626569f89bc8fbad9f936b307aded877

The btree cursor cleanup function takes an error parameter that
affects how buffers are released from the cursor. All buffers are
released in the event of error. Several callers do not specify the
XFS_BTREE_ERROR flag in the event of error, however. This can cause
buffers to hang around locked or with an elevated hold count and
thus lead to umount hangs in the event of errors.

Fix up the xfs_btree_del_cursor() callers to pass XFS_BTREE_ERROR if
the cursor is being torn down due to error.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxfs: fix line lengths
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
libxfs: fix line lengths

Fix some 80-char line length issues.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: Eric Sandeen <sandeen@sandeen.net>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxfs: remove useless stuff from the kernel
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
libxfs: remove useless stuff from the kernel

Evidently the libxfs-apply script sucked in some fs/xfs/ content from
the kernel patches and an extra redefinition of _bmap_search_extents.
We don't need this, so get rid of it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxfs: return bool from sb_version_hasmetauuid
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
libxfs: return bool from sb_version_hasmetauuid

The kernel's version of this function returns bool, so do so here too.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxfs: fix whitespace to match the kernel
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
libxfs: fix whitespace to match the kernel

Fix some minor whitespace errors so that my automated libxfs diff
scanning will stop reporting this.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxfs: refactor btree crc verifier
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
libxfs: refactor btree crc verifier

In a65d8d293b ("libxfs: validate metadata LSNs against log on v5
superblocks") the hascrc check was modified to use the helper mp
variable in the kernel.  This was left out of the xfsprogs patch, so
change it here too.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxfs: remove unnecessary hascrc test in btree verifiers
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
libxfs: remove unnecessary hascrc test in btree verifiers

xfs_btree_sblock_v5hdr_verify already checks _hascrc, so we can
remove it from the verifier functions.  For whatever reason this
change made it into the kernel but not xfsprogs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_io: fix libxfs naming violation
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
xfs_io: fix libxfs naming violation

All the calls to libxfs code should start with 'libxfs'
per libxfs_api_defs.h.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agolibxfs-apply: port to stgit
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
libxfs-apply: port to stgit

Teach libxfs-apply how to talk to a stgit repository
and fix a minor typo in the guilt hunk of apply_patch.

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>
7 years agotools: create libxfs-diff to compare libxfses
Darrick J. Wong [Tue, 10 Jan 2017 02:16:33 +0000 (20:16 -0600)] 
tools: create libxfs-diff to compare libxfses

Create a script to compare every file in libxfs to the same files
in another libxfs.  This is useful for comparing upstream kernel
and user progs to look for unported changes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfsprogs: Release v4.9.0 v4.9.0
Eric Sandeen [Thu, 5 Jan 2017 22:29:21 +0000 (16:29 -0600)] 
xfsprogs: Release v4.9.0

Update all the necessary files for a 4.9.0 release.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfsprogs: Release v4.9.0-rc1 v4.9.0-rc1
Eric Sandeen [Thu, 22 Dec 2016 22:41:04 +0000 (16:41 -0600)] 
xfsprogs: Release v4.9.0-rc1

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoFix building xfsprogs on 32-bit platforms
Eric Biggers [Thu, 22 Dec 2016 15:31:29 +0000 (09:31 -0600)] 
Fix building xfsprogs on 32-bit platforms

xfslibs now requires that its users enable transparent largefile
support.  This broke building xfsprogs on 32-bit Linux (with glibc)
because _FILE_OFFSET_BITS=64 was not getting defined.  Although the
autoconf macro AC_SYS_LARGEFILE was intended to define it, this didn't
work because AC_SYS_LARGEFILE will only define _FILE_OFFSET_BITS in a
config header, which doesn't work for xfsprogs because not all .c files
include platform_defs.h as their first include.  Also,
platform_defs.h.in is not generated by autoheader and didn't contain a
template for _FILE_OFFSET_BITS.

Therefore, to fix the problem remove the useless autoconf macros and
instead add -D_FILE_OFFSET_BITS=64 to CFLAGS in builddefs.in.  Use
CFLAGS rather than PCFLAGS because this definition could be needed by
platforms other than "linux", and it doesn't hurt to always define it.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Felix Janda <felix.janda@posteo.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_quota: Fix test for wrapped id from GETNEXTQUOTA
Eric Sandeen [Thu, 22 Dec 2016 05:10:54 +0000 (23:10 -0600)] 
xfs_quota: Fix test for wrapped id from GETNEXTQUOTA

dump_file and report_mount can be called with null *oid if
we aren't asking for the GETNEXTQUOTA interface, so we
should only test for the GETNEXTQUOTA wrap if *oid is
non-null.  Otherwise we'll deref a null pointer in the
test.

This only happens for certain invocations of reporting,
which apparently are not covered by any regression tests
at this point, at least on new kernels which contain
GETNEXTQUOTA.

Addresses-Coverity-ID: 1397415
Addresses-Coverity-ID: 1397416
Brown-paper-bag-worn-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_quota: handle wrapped id from GETNEXTQUOTA
Eric Sandeen [Wed, 21 Dec 2016 05:21:19 +0000 (23:21 -0600)] 
xfs_quota: handle wrapped id from GETNEXTQUOTA

The GETNEXTQUOTA interface in the kernel had a bug
(at least in xfs) where if we pass in UINT_MAX as the
ID, it incremented, warpped, and returned 0 for the next
id.  This would cause userspace to start querying
again at zero, and an xfs_quota "report" command would
loop forever.  This occurred if a quota ID near
UINT max existed, and later offsets within the block
wrapped the xfs_dqid_t.

This will also be fixed in the kernel, but we should also
catch this in userspace, and stop the loop if it happens.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_repair: don't indicate dirtiness if FSGEOMETRY fails
Eric Sandeen [Wed, 21 Dec 2016 04:38:06 +0000 (22:38 -0600)] 
xfs_repair: don't indicate dirtiness if FSGEOMETRY fails

Today, pointing repair at an image hosted on a non-xfs
filesystem will result in a XFS_IOC_FSGEOMETRY_V1 failure,
but repair generally proceeds without further problems.

However, calling do_warn() sets fs_is_dirty to 1, so
xfs_repair -n exits with non-zero status, indicating
corruption.  This is incorrect.

Change the message to use do_log so that it does not
incorrectly indicate corruption.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_repair: junk leaf attribute if count == 0
Eric Sandeen [Wed, 21 Dec 2016 04:38:01 +0000 (22:38 -0600)] 
xfs_repair: junk leaf attribute if count == 0

We have recently seen a case where, during log replay, the
attr3 leaf verifier reported corruption when encountering a
leaf attribute with a count of 0 in the header.

We chalked this up to a transient state when a shortform leaf
was created, the attribute didn't fit, and we promoted the
(empty) attribute to the larger leaf form.

I've recently been given a metadump of unknown provenance which actually
contains a leaf attribute with count 0 on disk.  This causes the
verifier to fire every time xfs_repair is run:

 Metadata corruption detected at xfs_attr3_leaf block 0x480988/0x1000

If this 0-count state is detected, we should just junk the leaf, same
as we would do if the count was too high.  With this change, we now
remedy the problem:

 Metadata corruption detected at xfs_attr3_leaf block 0x480988/0x1000
 bad attribute count 0 in attr block 0, inode 12587828
 problem with attribute contents in inode 12587828
 clearing inode 12587828 attributes
 correcting nblocks for inode 12587828, was 2 - counted 1

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_repair: change null check to assertion
Darrick J. Wong [Wed, 21 Dec 2016 04:35:47 +0000 (22:35 -0600)] 
xfs_repair: change null check to assertion

It /should/ be the case that we never run out of records
before we run out of btree blocks, so change the null check
(that was only to appease Coverity) to an assert.

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>
7 years agoxfs_repair: fix some potential null pointer deferences
Darrick J. Wong [Wed, 21 Dec 2016 04:29:01 +0000 (22:29 -0600)] 
xfs_repair: fix some potential null pointer deferences

Fix some potential NULL pointer deferences that Coverity pointed out,
and remove a trivial dead integer check.

Coverity-id: 1375789137579013757911375792
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
7 years agoxfs_repair: fix bogus rmapbt record owner check
Darrick J. Wong [Wed, 21 Dec 2016 04:28:01 +0000 (22:28 -0600)] 
xfs_repair: fix bogus rmapbt record owner check

Make the reverse mapping owner check actually validate inode numbers.

Coverity-id: 1371628
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>