generic/551: Adjust the size argument for aio-dio-write-verify
[xfstests-dev.git] / common / rc
index 238ffef9d959e5309abcb73724c687e62d7877b5..6943f19f130c520c65ab00e0458d90ab1f321744 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -910,6 +910,17 @@ _free_memory_bytes()
     free -b | grep ^Mem | awk '{print $4}'
 }
 
+_available_memory_bytes()
+{
+       nf=`free -b | grep ^Mem | awk '{print NF}'`
+       if [[ nf -lt 7 ]]; then
+               # Doesn't have available field. Fallback.
+               _free_memory_bytes
+       else
+               free -b | grep ^Mem | awk '{print $7}'
+       fi
+}
+
 # Create fs of certain size on scratch device
 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
 _scratch_mkfs_sized()
@@ -1978,13 +1989,14 @@ _require_timestamp_range()
 _filesystem_timestamp_range()
 {
        local device=${1:-$TEST_DEV}
+       local fstyp=${2:-$FSTYP}
        u32max=$(((1<<32)-1))
        s32min=-$((1<<31))
        s32max=$(((1<<31)-1))
        s64max=$(((1<<63)-1))
        s64min=$((1<<63))
 
-       case $FSTYP in
+       case $fstyp in
        ext2)
                echo "$s32min $s32max"
                ;;
@@ -2005,6 +2017,13 @@ _filesystem_timestamp_range()
        btrfs)
                echo "$s64min $s64max"
                ;;
+       overlay)
+               if [ ! -z $OVL_BASE_FSTYP -a $OVL_BASE_FSTYP != "overlay" ]; then
+                       _filesystem_timestamp_range $OVL_BASE_TEST_DEV $OVL_BASE_FSTYP
+               else
+                       echo "-1 -1"
+               fi
+               ;;
        *)
                echo "-1 -1"
                ;;
@@ -3159,7 +3178,7 @@ _require_norecovery()
 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
 # any dev we want.
-_require_metadata_journaling()
+_has_metadata_journaling()
 {
        if [ -z $1 ]; then
                local dev=$TEST_DEV
@@ -3169,32 +3188,52 @@ _require_metadata_journaling()
 
        case "$FSTYP" in
        ext2|vfat|msdos|udf)
-               _notrun "$FSTYP does not support metadata journaling"
+               echo "$FSTYP does not support metadata journaling"
+               return 1
                ;;
        ext4)
                # ext4 could be mkfs'd without a journal...
                _require_dumpe2fs
-               $DUMPE2FS_PROG -h $dev 2>&1 | grep -q has_journal || \
-                       _notrun "$FSTYP on $dev not configured with metadata journaling"
+               $DUMPE2FS_PROG -h $dev 2>&1 | grep -q has_journal || {
+                       echo "$FSTYP on $dev not configured with metadata journaling"
+                       return 1
+               }
                # ext4 might not load a journal
-               _exclude_scratch_mount_option "noload"
+               if _normalize_mount_options | grep -qw "noload"; then
+                       echo "mount option \"noload\" not allowed in this test"
+                       return 1
+               fi
                ;;
        overlay)
                # metadata journaling check is based on base filesystem configurations
                # and  because -overlay option saves those configurations to OVL_BASE_*,
                # adding restore/override the configurations before/after the check.
                if [ ! -z $OVL_BASE_FSTYP -a $OVL_BASE_FSTYP != "overlay" ]; then
+                       local ret
+
                        _overlay_config_restore
-                       _require_metadata_journaling
+                       _has_metadata_journaling
+                       ret=$?
                        _overlay_config_override
+                       return $ret
                else
-                       _notrun "No metadata journaling support for legacy overlay setup"
+                       echo "No metadata journaling support for legacy overlay setup"
+                       return 1
                fi
                ;;
        *)
                # by default we pass; if you need to, add your fs above!
                ;;
        esac
+       return 0
+}
+
+_require_metadata_journaling()
+{
+       local msg=$(_has_metadata_journaling $@)
+       if [ -n "$msg" ]; then
+               _notrun "$msg"
+       fi
 }
 
 _count_extents()
@@ -3202,6 +3241,15 @@ _count_extents()
        $XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
 }
 
+# Similar to _count_extents() but if any extent is shared multiples times in
+# the file (reflinked to different file offsets), it is accounted as 1 extent
+# instead of N extents.
+_count_exclusive_extents()
+{
+       $XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep -v hole | \
+               cut -d ' ' -f 3 | sort | uniq | wc -l
+}
+
 _count_holes()
 {
        $XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
@@ -3597,7 +3645,9 @@ _check_dmesg()
                _dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
                return 1
        else
-               rm -f $seqres.dmesg
+               if [ "$KEEP_DMESG" != "yes" ]; then
+                       rm -f $seqres.dmesg
+               fi
                return 0
        fi
 }