fstests: remove old electric fence support
[xfstests-dev.git] / common / xfs
index 95dde603cf99930239c38d956db4ad158a051ca0..92223513d561c634cf5068afdaea1c3105c46269 100644 (file)
@@ -18,7 +18,7 @@ _setup_large_xfs_fs()
        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"
@@ -119,6 +119,7 @@ _xfs_check()
        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 ";;
@@ -223,7 +224,7 @@ _require_xfs_mkfs_crc()
 _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
 }
@@ -233,7 +234,7 @@ _require_xfs_crc()
 _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
@@ -252,7 +253,7 @@ _require_xfs_mkfs_finobt()
 _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
 }
@@ -280,7 +281,7 @@ _require_xfs_sparse_inodes()
        _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
 }
@@ -304,9 +305,13 @@ _supports_xfs_scrub()
        local mountpoint="$1"
        local device="$2"
 
-       if [ ! -b "$device" ] || [ ! -e "$mountpoint" ]; then
+       if [ -z "$device" ] || [ -z "$mountpoint" ]; then
                echo "Usage: _supports_xfs_scrub mountpoint device"
-               exit 1
+               return 1
+       fi
+
+       if [ ! -b "$device" ] || [ ! -e "$mountpoint" ]; then
+               return 1
        fi
 
        test "$FSTYP" = "xfs" || return 1
@@ -314,7 +319,7 @@ _supports_xfs_scrub()
 
        # 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 0" "$mountpoint" 2>&1 | grep -q "Inappropriate ioctl" && 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
@@ -355,13 +360,17 @@ _check_xfs_filesystem()
        ok=1
 
        # Run online scrub if we can.
-       mntpt="$(_is_mounted $device)"
+       mntpt="$(_is_dev_mounted $device)"
        if [ -n "$mntpt" ] && _supports_xfs_scrub "$mntpt" "$device"; then
-               "$XFS_SCRUB_PROG" $scrubflag -v -d -n $device >>$seqres.full 2>&1
+               "$XFS_SCRUB_PROG" $scrubflag -v -d -n $mntpt > $tmp.scrub 2>&1
                if [ $? -ne 0 ]; then
-                       _log_err "filesystem on $device failed scrub"
+                       _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
@@ -384,8 +393,7 @@ _check_xfs_filesystem()
        # 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)"
@@ -400,7 +408,7 @@ _check_xfs_filesystem()
        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
@@ -413,7 +421,7 @@ _check_xfs_filesystem()
                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
@@ -424,7 +432,7 @@ _check_xfs_filesystem()
                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
@@ -462,13 +470,7 @@ _check_xfs_test_fs()
                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()
@@ -601,7 +603,7 @@ _require_meta_uuid()
 
        _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
 }
@@ -626,3 +628,95 @@ _require_no_xfs_debug()
                _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"
+}