file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
# mount the filesystem, create the file, unmount it
- _scratch_mount 2>&1 >$tmp_dir/mnt.err
+ _try_scratch_mount 2>&1 >$tmp_dir/mnt.err
local status=$?
if [ $status -ne 0 ]; then
echo "mount failed"
{
local mkfs_cmd="`_scratch_mkfs_xfs_opts`"
local mkfs_filter="sed -e '/less than device physical sector/d' \
- -e '/switching to logical sector/d'"
- local tmp=`mktemp`
+ -e '/switching to logical sector/d' \
+ -e '/Default configuration/d'"
+ local tmp=`mktemp -u`
local mkfs_status
_scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
# output mkfs stdout and stderr
cat $tmp.mkfsstd
cat $tmp.mkfserr >&2
- rm -f $tmp*
+ rm -f $tmp.mkfserr $tmp.mkfsstd
return $mkfs_status
}
DBOPTS=" "
USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
+ OPTIND=1
while getopts "b:fi:l:stvV" c; do
case $c in
s) OPTS=$OPTS"-s ";;
_require_xfs_crc()
{
_scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
- _scratch_mount >/dev/null 2>&1 \
+ _try_scratch_mount >/dev/null 2>&1 \
|| _notrun "Kernel doesn't support crc feature"
_scratch_unmount
}
_require_scratch_xfs_crc()
{
_scratch_mkfs_xfs >/dev/null 2>&1
- _scratch_mount >/dev/null 2>&1 \
+ _try_scratch_mount >/dev/null 2>&1 \
|| _notrun "Kernel doesn't support crc feature"
xfs_info $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
_scratch_unmount
_require_xfs_finobt()
{
_scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
- _scratch_mount >/dev/null 2>&1 \
+ _try_scratch_mount >/dev/null 2>&1 \
|| _notrun "Kernel doesn't support finobt feature"
_scratch_unmount
}
_scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
|| _notrun "mkfs.xfs does not support sparse inodes"
_scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
- _scratch_mount >/dev/null 2>&1 \
+ _try_scratch_mount >/dev/null 2>&1 \
|| _notrun "kernel does not support sparse inodes"
_scratch_unmount
}
_notrun "xfs_db $command support is missing"
}
+# Does the filesystem mounted from a particular device support scrub?
+_supports_xfs_scrub()
+{
+ local mountpoint="$1"
+ local device="$2"
+
+ if [ -z "$device" ] || [ -z "$mountpoint" ]; then
+ echo "Usage: _supports_xfs_scrub mountpoint device"
+ return 1
+ fi
+
+ if [ ! -b "$device" ] || [ ! -e "$mountpoint" ]; then
+ return 1
+ fi
+
+ test "$FSTYP" = "xfs" || return 1
+ test -x "$XFS_SCRUB_PROG" || return 1
+
+ # Probe for kernel support...
+ $XFS_IO_PROG -c 'help scrub' 2>&1 | grep -q 'types are:.*probe' || return 1
+ $XFS_IO_PROG -c "scrub probe" "$mountpoint" 2>&1 | grep -q "Inappropriate ioctl" && return 1
+
+ # Scrub can't run on norecovery mounts
+ _fs_options "$device" | grep -q "norecovery" && return 1
+
+ return 0
+}
+
# run xfs_check and friends on a FS.
_check_xfs_filesystem()
{
type=`_fs_type $device`
ok=1
- if [ "$type" = "xfs" ]; then
- if [ -n "$TEST_XFS_SCRUB" ] && [ -x "$XFS_SCRUB_PROG" ]; then
- "$XFS_SCRUB_PROG" $scrubflag -v -d -n $device >>$seqres.full
- if [ $? -ne 0 ]; then
- _log_err "filesystem on $device failed scrub"
- ok=0
- fi
+ # Run online scrub if we can.
+ mntpt="$(_is_dev_mounted $device)"
+ if [ -n "$mntpt" ] && _supports_xfs_scrub "$mntpt" "$device"; then
+ "$XFS_SCRUB_PROG" $scrubflag -v -d -n $mntpt > $tmp.scrub 2>&1
+ if [ $? -ne 0 ]; then
+ _log_err "_check_xfs_filesystem: filesystem on $device failed scrub"
+ echo "*** xfs_scrub $scrubflag -v -d -n output ***" >> $seqres.full
+ cat $tmp.scrub >> $seqres.full
+ echo "*** end xfs_scrub output" >> $serqres.full
+ ok=0
fi
+ rm -f $tmp.scrub
+ fi
+
+ if [ "$type" = "xfs" ]; then
# mounted ...
mountpoint=`_umount_or_remount_ro $device`
fi
# option (-t) to avoid indexing the free space trees doesn't make it pass on
# large filesystems. Avoid it.
if [ "$LARGE_SCRATCH_DEV" != yes ]; then
- _xfs_check $extra_log_options $device 2>&1 |\
- _fix_malloc >$tmp.fs_check
+ _xfs_check $extra_log_options $device 2>&1 > $tmp.fs_check
fi
if [ -s $tmp.fs_check ]; then
_log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (c)"
if [ $? -ne 0 ]; then
_log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (r)"
echo "*** xfs_repair -n output ***" >>$seqres.full
- cat $tmp.repair | _fix_malloc >>$seqres.full
+ cat $tmp.repair >>$seqres.full
echo "*** end xfs_repair output" >>$seqres.full
ok=0
if [ $? -ne 0 ]; then
_log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild)"
echo "*** xfs_repair output ***" >>$seqres.full
- cat $tmp.repair | _fix_malloc >>$seqres.full
+ cat $tmp.repair >>$seqres.full
echo "*** end xfs_repair output" >>$seqres.full
ok=0
if [ $? -ne 0 ]; then
_log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild-reverify)"
echo "*** xfs_repair -n output ***" >>$seqres.full
- cat $tmp.repair | _fix_malloc >>$seqres.full
+ cat $tmp.repair >>$seqres.full
echo "*** end xfs_repair output" >>$seqres.full
ok=0
TEST_RT="$TEST_RTDEV"
_check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
-
- # check for ipath consistency
- if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
- # errors go to stderr
- xfs_check_ipaths $TEST_DIR >/dev/null
- xfs_repair_ipaths -n $TEST_DIR >/dev/null
- fi
+ return $?
}
_require_xfs_test_rmapbt()
_scratch_xfs_db -x -c "uuid generate" >/dev/null 2>&1
- _scratch_mount >/dev/null 2>&1 \
+ _try_scratch_mount >/dev/null 2>&1 \
|| _notrun "Kernel doesn't support meta_uuid feature"
_scratch_unmount
}
|| _notrun "need case-insensitive naming support in mkfs.xfs"
}
-# xfs generates WARNINGs on purpose when applications mix buffered/mmap IO with
-# direct IO on the same file. This is a helper for _check_dmesg() to filter out
-# such warnings.
-_filter_xfs_dmesg()
-{
- local warn1="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_dio_aio_write.*"
- local warn2="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_dio_aio_read.*"
- local warn3="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_read_iter.*"
- local warn4="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_aio_read.*"
- local warn5="WARNING:.*fs/iomap\.c:.*iomap_dio_rw.*"
- local warn6="WARNING:.*fs/xfs/xfs_aops\.c:.*__xfs_get_blocks.*"
- sed -e "s#$warn1#Intentional warnings in xfs_file_dio_aio_write#" \
- -e "s#$warn2#Intentional warnings in xfs_file_dio_aio_read#" \
- -e "s#$warn3#Intentional warnings in xfs_file_read_iter#" \
- -e "s#$warn4#Intentional warnings in xfs_file_aio_read#" \
- -e "s#$warn5#Intentional warnings in iomap_dio_rw#" \
- -e "s#$warn6#Intentional warnings in __xfs_get_blocks#"
+# XFS_DEBUG requirements
+_require_xfs_debug()
+{
+ if grep -q "debug 0" /proc/fs/xfs/stat; then
+ _notrun "Require XFS built with CONFIG_XFS_DEBUG"
+ fi
+}
+_require_no_xfs_debug()
+{
+ if grep -q "debug 1" /proc/fs/xfs/stat; then
+ _notrun "Require XFS built without CONFIG_XFS_DEBUG"
+ fi
+}
+
+# Require that assertions will not crash the system.
+#
+# Assertions would always crash the system if XFS assert fatal was enabled
+# (CONFIG_XFS_ASSERT_FATAL=y). If a test is designed to trigger an assertion,
+# skip the test on a CONFIG_XFS_ASSERT_FATAL built XFS by default. Note:
+# CONFIG_XFS_ASSERT_FATAL can be disabled by setting bug_on_assert to zero if
+# we want test to run.
+_require_no_xfs_bug_on_assert()
+{
+ if [ -f /sys/fs/xfs/debug/bug_on_assert ]; then
+ grep -q "1" /sys/fs/xfs/debug/bug_on_assert && \
+ _notrun "test requires XFS bug_on_assert to be off, turn it off to run the test"
+ else
+ # Note: Prior to the creation of CONFIG_XFS_ASSERT_FATAL (and
+ # the sysfs knob bug_on_assert), assertions would always crash
+ # the system if XFS debug was enabled (CONFIG_XFS_DEBUG=y). If
+ # a test is designed to trigger an assertion and the test
+ # designer does not want to hang fstests, skip the test.
+ _require_no_xfs_debug
+ fi
+}
+
+# Get a metadata field
+# The first arg is the field name
+# The rest of the arguments are xfs_db commands to find the metadata.
+_scratch_xfs_get_metadata_field()
+{
+ local key="$1"
+ shift
+
+ local grep_key="$(echo "${key}" | tr '[]()' '....')"
+ local cmds=()
+ local arg
+ for arg in "$@"; do
+ cmds+=("-c" "${arg}")
+ done
+ _scratch_xfs_db "${cmds[@]}" -c "print ${key}" | grep "^${grep_key}" | \
+ sed -e 's/^.* = //g'
+}
+
+# Set a metadata field
+# The first arg is the field name
+# The second arg is the new value
+# The rest of the arguments are xfs_db commands to find the metadata.
+_scratch_xfs_set_metadata_field()
+{
+ local key="$1"
+ local value="$2"
+ shift; shift
+
+ local cmds=()
+ local arg
+ for arg in "$@"; do
+ cmds+=("-c" "${arg}")
+ done
+
+ local wr_cmd="write"
+ _scratch_xfs_db -x -c "help write" | egrep -q "(-c|-d)" && value="-- ${value}"
+ _scratch_xfs_db -x -c "help write" | egrep -q "(-d)" && wr_cmd="${wr_cmd} -d"
+ _scratch_xfs_db -x "${cmds[@]}" -c "${wr_cmd} ${key} ${value}"
+}
+
+_scratch_xfs_get_sb_field()
+{
+ _scratch_xfs_get_metadata_field "$1" "sb 0"
+}
+
+_scratch_xfs_set_sb_field()
+{
+ _scratch_xfs_set_metadata_field "$1" "$2" "sb 0"
+}
+
+# Before xfsprogs commit 4222d000ed("db: write via array indexing doesn't
+# work"), xfs_db command to write a specific AGFL index doesn't work. It's a
+# bug in a diagnostic tool that is only used by XFS developers as a test
+# infrastructure, so it's fine to treat it as a infrastructure dependency as
+# all other _require rules.
+_require_xfs_db_write_array()
+{
+ local supported=0
+
+ _require_test
+ touch $TEST_DIR/$seq.img
+ $MKFS_XFS_PROG -d file,name=$TEST_DIR/$seq.img,size=512m >/dev/null 2>&1
+ $XFS_DB_PROG -x -c "agfl 0" -c "write bno[32] 78" $TEST_DIR/$seq.img \
+ >/dev/null 2>&1
+ $XFS_DB_PROG -x -c "agfl 0" -c "print bno[32]" $TEST_DIR/$seq.img \
+ | grep -q "bno\[32\] = 78" && supported=1
+ rm -f $TEST_DIR/$seq.img
+ [ $supported -eq 0 ] && _notrun "xfs_db write can't support array"
}