Linux "xfs_io" Command Line Options and Examples
debug the I/O path of an XFS filesystem

xfs_io is a debugging tool like xfs_db(8), but is aimed at examining the regular file I/O paths rather than the raw XFS volume itself. These code paths include not only the obvious read/write/mmap interfaces for manipulating files, but also cover all of the XFS extensions (such as space preallocation, additional inode flags, etc)..


Usage:

xfs_io [ -adfimrRstxT ] [ -c cmd ] ... [ -p prog ] file
    xfs_io -V






Command Line Options:

-c
cmd xfs_io commands may be run interactively (the default) or as arguments on the command line. Multiple
xfs_io -c ...
-p
prog Set the program name for prompts and some error messages, the default value is xfs_io.
xfs_io -p ...
-f
Create file if it does not already exist.
xfs_io -f ...
-r
initially. This is required if file is immutable or append-only.
xfs_io -r ...
-V
The other open(2) options described below are also available from the command line.CONCEPTSxfs_io maintains a number of open files and memory mappings. Files can be initially opened on the commandline (optionally), and additional files can also be opened later.xfs_io commands can be broken up into three groups. Some commands are aimed at doing regular file I/O - read,write, sync, space preallocation, etc.The second set of commands exist for manipulating memory mapped regions of a file - mapping, accessing, stor‐ing, unmapping, flushing, etc.The remaining commands are for the navigation and display of data structures relating to the open files, map‐pings, and the filesystems where they reside.Many commands have extensive online help. Use the help command for more details on any command.FILE I/O COMMANDSfile [ N ]Display a list of all open files and (optionally) switch to an alternate current open file.open [[ -acdfrstRT ] path ]Closes the current file, and opens the file specified by path instead. Without any arguments, displaysstatistics about the current file - see the stat command.
xfs_io -V ...
-a
opens append-only (O_APPEND).
xfs_io -a ...
-d
opens for direct I/O (O_DIRECT).
xfs_io -d ...
-s
opens for synchronous I/O (O_SYNC).
xfs_io -s ...
-t
truncates on open (O_TRUNC).
xfs_io -t ...
-n
opens in non-blocking mode if possible (O_NONBLOCK).
xfs_io -n ...
-R
o See the open command.close Closes the current open file, marking the next open file as current (if one exists).c See the close command.pread [ -b bsize ] [ -v ] [ -FBR [ -Z seed ] ] [ -V vectors ] offset lengthReads a range of bytes in a specified blocksize from the given offset.
xfs_io -R ...
-F
read the buffers in a forwards sequential direction.
xfs_io -F ...
-B
read the buffers in a reserve sequential direction.
xfs_io -B ...
-Z
specify the random number seed used for random reads.
xfs_io -Z ...
-i
allows an input file to be specified as the source of the data to be written.
xfs_io -i ...
-w
call fdatasync(2) once all writes are complete (included in timing results)
xfs_io -w ...
-W
call fsync(2) once all writes are complete (included in timing results)
xfs_io -W ...
-b
wait for IO in the given range to finish before writing (SYNC_FILE_RANGE_WAIT_BEFORE).
xfs_io -b ...
-k
fcollapse offset lengthCall fallocate with FALLOC_FL_COLLAPSE_RANGE flag as described in the fallocate(2) manual page to de-allocates blocks and eliminates the hole created in this process by shifting data blocks into the hole.finsert offset lengthCall fallocate with FALLOC_FL_INSERT_RANGE flag as described in the fallocate(2) manual page to createthe hole by shifting data blocks.fpunch offset lengthPunches (de-allocates) blocks in the file by calling fallocate with the FALLOC_FL_PUNCH_HOLE flag asdescribed in the fallocate(2) manual page.funshare offset lengthCall fallocate with FALLOC_FL_UNSHARE_RANGE flag as described in the fallocate(2) manual page tounshare all shared blocks within the range.fzero offset lengthCall fallocate with FALLOC_FL_ZERO_RANGE flag as described in the fallocate(2) manual page to allocateand zero blocks within the range.zero offset lengthCall xfsctl with XFS_IOC_ZERO_RANGE as described in the xfsctl(3) manual page to allocate and zeroblocks within the range.truncate offsetTruncates the current file at the given offset using ftruncate(2).sendfile -i srcfile | -f N [ offset length ]On platforms which support it, allows a direct in-kernel copy between two file descriptors. The currentopen file is the target, the source must be specified as another open file (-f) or by path (-i).readdir [ -v ] [ -o offset ] [ -l length ]Read a range of directory entries from a given offset of a directory.
xfs_io -k ...
-v
verbose mode - dump dirent content as defined in readdir(3)
xfs_io -v ...
-o
specify starting offset
xfs_io -o ...
-l
seek -a | -d | -h [ -r ] [ -s ] offsetOn platforms that support the lseek(2) SEEK_DATA and SEEK_HOLE options, display the offsets of thespecified segments.
xfs_io -l ...
-h
Display the hole segment starting at the specified offset.
xfs_io -h ...
-C
Print timing statistics in a condensed format.
xfs_io -C ...
-q
dedupe [ -C ] [ -q ] src_file src_offset dst_offset lengthOn filesystems that support the XFS_IOC_FILE_EXTENT_SAME or BTRFS_IOC_FILE_EXTENT_SAME ioctls, maplength bytes at offset dst_offset in the open file to the same physical blocks that are mapped at off‐set src_offset in the file src_file , but only if the contents of both ranges are identical. This isknown as block-based deduplication. If a program writes into a reflinked block range of either file,the dirty blocks will be cloned, written to, and remapped ("copy on write") in the affected file, leav‐ing the other file(s) unchanged.
xfs_io -q ...