common/xfs: Fix _require_scratch_xfs_shrink bug
[xfstests-dev.git] / common / xfs
index 0ec5b03ccc487a5315a5b305951441f12d0ae99d..c5e3942721dbc1cd0b63462b73aa47c568e2ec40 100644 (file)
@@ -194,6 +194,31 @@ _xfs_get_file_block_size()
        $XFS_INFO_PROG "$path" | grep realtime | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g'
 }
 
+# Set or clear the realtime status of every supplied path.  The first argument
+# is either 'data' or 'realtime'.  All other arguments should be paths to
+# existing directories or empty regular files.
+#
+# For each directory, each file subsequently created will target the given
+# device for file data allocations.  For each empty regular file, each
+# subsequent file data allocation will be on the given device.
+_xfs_force_bdev()
+{
+       local device="$1"
+       shift
+       local chattr_arg=""
+
+       case "$device" in
+       "data")         chattr_arg="-t";;
+       "realtime")     chattr_arg="+t";;
+       *)
+               echo "${device}: Don't know what device this is?"
+               return 1
+               ;;
+       esac
+
+       $XFS_IO_PROG -c "chattr $chattr_arg" "$@"
+}
+
 _xfs_get_fsxattr()
 {
        local field="$1"
@@ -478,7 +503,7 @@ _xfs_metadump() {
        $XFS_METADUMP_PROG $options "$device" "$metadump"
        res=$?
        [ "$compressopt" = "compress" ] && [ -n "$DUMP_COMPRESSOR" ] &&
-               $DUMP_COMPRESSOR "$metadump" &> /dev/null
+               $DUMP_COMPRESSOR -f "$metadump" &> /dev/null
        return $res
 }
 
@@ -795,7 +820,8 @@ _require_scratch_xfs_shrink()
        . $tmp.mkfs
        _scratch_mount
        # here just to check if kernel supports, no need do more extra work
-       local errmsg=$($XFS_GROWFS_PROG -D$((dblocks-1)) "$SCRATCH_MNT" 2>&1)
+       local errmsg
+       errmsg=$($XFS_GROWFS_PROG -D$((dblocks-1)) "$SCRATCH_MNT" 2>&1)
        if [ "$?" -ne 0 ]; then
                echo "$errmsg" | grep 'XFS_IOC_FSGROWFSDATA xfsctl failed: Invalid argument' > /dev/null && \
                        _notrun "kernel does not support shrinking"