common/rc: not run swapfile test for DAX
[xfstests-dev.git] / common / rc
index 4d3397d681d3b6ef5f60f69b73aecab1300c945a..e53d1569eef732d8db9f0b45e0a3c636e1a253d7 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -1931,6 +1931,50 @@ _require_dm_target()
        fi
 }
 
+_zone_type()
+{
+       local target=$1
+       if [ -z $target ]; then
+               echo "Usage: _zone_type <device>"
+               exit 1
+       fi
+       local sdev=`_short_dev $target`
+
+       if [ -e /sys/block/${sdev}/queue/zoned ]; then
+               cat /sys/block/${sdev}/queue/zoned
+       else
+               echo none
+       fi
+}
+
+_require_zoned_device()
+{
+       local target=$1
+       if [ -z $target ]; then
+               echo "Usage: _require_zoned_device <device>"
+               exit 1
+       fi
+
+       local type=`_zone_type ${target}`
+       if [ "${type}" = "none" ]; then
+               _notrun "this test require zoned block device"
+       fi
+}
+
+_require_non_zoned_device()
+{
+       local target=$1
+       if [ -z $target ]; then
+               echo "Usage: _require_non_zoned_device <device>"
+               exit 1
+       fi
+
+       local type=`_zone_type ${target}`
+       if [ "${type}" != "none" ]; then
+               _notrun "this test require non-zoned block device"
+       fi
+}
+
 # this test requires the ext4 kernel support crc feature on scratch device
 #
 _require_scratch_ext4_crc()
@@ -2124,7 +2168,7 @@ _filesystem_timestamp_range()
                echo "0 $u32max"
                ;;
        xfs)
-               echo "$s32min $s32max"
+               _xfs_timestamp_range "$device"
                ;;
        btrfs)
                echo "$s64min $s64max"
@@ -2185,6 +2229,40 @@ _require_user()
     [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
 }
 
+# check for a chown support
+#
+_require_chown()
+{
+       local rnd_uid=4242
+       local file="$TEST_DIR/chown_testfile"
+
+       rm -f $file
+       touch $file
+       chown ${rnd_uid}:${rnd_uid} $file >/dev/null 2>&1 \
+               || _notrun "chown is not supported ${FSTYP}"
+}
+
+
+# check for a chmod support
+# Since chmod sometimes fails silently actual functionality test is done
+#
+_require_chmod()
+{
+       local file="$TEST_DIR/chmod_testfile"
+
+       rm -f $file
+       touch $file
+
+       # get original file mode
+       local mode=`stat --format="0%a" $file`
+       # flip the user's read bit
+       let mode^=0400
+       chmod `printf '%o' "$mode"` $file
+       # check that the chmod actually flipped the bit
+       [ `stat --format="0%a" $file` == `printf '0%o' "$mode"` ] \
+               || _notrun "chmod is not supported ${FSTYP}"
+}
+
 # check for a group on the machine, fsgqa as default
 #
 _require_group()
@@ -2421,7 +2499,15 @@ _format_swapfile() {
        # Swap files must be nocow on Btrfs.
        $CHATTR_PROG +C "$fname" > /dev/null 2>&1
        _pwrite_byte 0x61 0 "$sz" "$fname" >> $seqres.full
-       $MKSWAP_PROG "$fname" >> $seqres.full
+       # Ignore permission complaints on filesystems that don't support perms
+       $MKSWAP_PROG "$fname" 2> >(grep -v 'insecure permission' >&2) >> $seqres.full
+}
+
+_swapon_file() {
+       local fname="$1"
+
+       # Ignore permission complaints on filesystems that don't support perms
+       swapon "$fname" 2> >(grep -v "insecure permissions" >&2)
 }
 
 # Check that the filesystem supports swapfiles
@@ -2448,13 +2534,18 @@ _require_scratch_swapfile()
        # Minimum size for mkswap is 10 pages
        _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
 
-       # ext* and xfs have supported all variants of swap files since their
+       # ext* has supported all variants of swap files since their
        # introduction, so swapon should not fail.
        case "$FSTYP" in
-       ext2|ext3|ext4|xfs)
+       ext2|ext3|ext4)
                if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
-                       _scratch_unmount
-                       _fail "swapon failed for $FSTYP"
+                       if _check_s_dax "$SCRATCH_MNT/swap" 1 >/dev/null; then
+                               _scratch_unmount
+                               _notrun "swapfiles are not supported"
+                       else
+                               _scratch_unmount
+                               _fail "swapon failed for $FSTYP"
+                       fi
                fi
                ;;
        *)
@@ -3318,6 +3409,7 @@ _check_s_dax()
 {
        local target=$1
        local exp_s_dax=$2
+       local ret=0
 
        local attributes=$($XFS_IO_PROG -c 'statx -r' $target | awk '/stat.attributes / { print $3 }')
 
@@ -3338,10 +3430,17 @@ _check_s_dax()
        fi
 
        if [ $exp_s_dax -eq 0 ]; then
-               (( attributes & 0x00200000 )) && echo "$target has unexpected S_DAX flag"
+               if (( attributes & 0x00200000 )); then
+                       echo "$target has unexpected S_DAX flag"
+                       ret=1
+               fi
        else
-               (( attributes & 0x00200000 )) || echo "$target doesn't have expected S_DAX flag"
+               if ! (( attributes & 0x00200000 )); then
+                       echo "$target doesn't have expected S_DAX flag"
+                       ret=2
+               fi
        fi
+       return $ret
 }
 
 _check_xflag()
@@ -3433,7 +3532,7 @@ _has_metadata_journaling()
        fi
 
        case "$FSTYP" in
-       ext2|vfat|msdos|udf|exfat)
+       ext2|vfat|msdos|udf|exfat|tmpfs)
                echo "$FSTYP does not support metadata journaling"
                return 1
                ;;