common/xfs: refactor commands to select a particular xfs backing device
[xfstests-dev.git] / tests / xfs / 004
index bbc1aee31e0109d29165a06a8f9fb36d9c7abbce..d3fb9c958cf496bc73e131e3ed9b62347c9706e1 100755 (executable)
@@ -1,27 +1,11 @@
 #! /bin/bash
-# FS QA Test No. 004
-#
-# exercise xfs_db bug #789674 and other freesp functionality
-#
-#-----------------------------------------------------------------------
+# SPDX-License-Identifier: GPL-2.0
 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+# FS QA Test No. 004
 #
-#-----------------------------------------------------------------------
+# exercise xfs_db bug #789674 and other freesp functionality
 #
-
 seq=`basename $0`
 seqres=$RESULT_DIR/$seq
 echo "QA output created by $seq"
@@ -44,6 +28,10 @@ _populate_scratch()
        _scratch_mkfs_xfs | tee -a $seqres.full | _filter_mkfs 2>$tmp.mkfs
        . $tmp.mkfs
        _scratch_mount
+       # This test looks at specific behaviors of the xfs_db freesp command,
+       # which reports on the contents of the free space btrees for the data
+       # device.  Don't let anything get created on the realtime volume.
+       _xfs_force_bdev data $SCRATCH_MNT
        dd if=/dev/zero of=$SCRATCH_MNT/foo count=200 bs=4096 >/dev/null 2>&1 &
        dd if=/dev/zero of=$SCRATCH_MNT/goo count=400 bs=4096 >/dev/null 2>&1 &
        dd if=/dev/zero of=$SCRATCH_MNT/moo count=800 bs=4096 >/dev/null 2>&1 &
@@ -58,7 +46,6 @@ _populate_scratch()
 
 # real QA test starts here
 _supported_fs xfs
-_supported_os IRIX Linux
 
 _require_scratch
 _require_no_large_scratch_dev
@@ -67,9 +54,7 @@ rm -f $seqres.full
 
 _populate_scratch
 
-[ "$HOSTOS" = "Linux" ] && DF_PROG="$DF_PROG -P --block-size=512"
-
-eval `$DF_PROG $SCRATCH_MNT 2>&1 \
+eval `$DF_PROG -P --block-size=512 $SCRATCH_MNT 2>&1 \
        | tail -1 | $AWK_PROG '{ printf "blocks=%u used=%u avail=%u\n", $3, $4, $5 }'`
 echo "df gave: blocks=$blocks used=$used avail=$avail" >>$seqres.full
 echo "blocksize from mkfs is '$dbsize'" >>$seqres.full
@@ -83,18 +68,15 @@ eval `$XFS_IO_PROG -x -c resblks $SCRATCH_MNT 2>&1 \
 echo "resblks gave: resblks=$resblks" >>$seqres.full
 
 # check the 'blocks' field from freesp command is OK
-#  - starting with Linux 4.10-rc the bmbt split reservation moved to be per-AG
 perl -ne '
        BEGIN   { $avail ='$avail' * 512 + ('$resblks' * '$dbsize');
                  $answer="(no xfs_db free blocks line?)" }
        /free blocks (\d+)$/    || next;
        $freesp = $1 * '$dbsize';
-       if ($freesp == $avail + ('$agcount') * '$dbsize' * 8) {
-               $answer = "yes";
-       } elsif ($freesp == $avail + (('$agcount' + 1) * '$dbsize' * 4)) {
+       if ($freesp >= $avail) {
                $answer = "yes";
        } else {
-               $answer = "no ($freesp != $avail)";
+               $answer = "no ($freesp < $avail)";
        }
        END     { print "$answer\n" }
        ' <$tmp.xfs_db >$tmp.ans