overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / xfs / 004
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 004
6 #
7 # exercise xfs_db bug #789674 and other freesp functionality
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=0
16
17 _cleanup()
18 {
19         _scratch_unmount
20         rm -f $tmp.*
21         exit $status
22 }
23 trap "_cleanup" 0 1 2 3 15
24
25 _populate_scratch()
26 {
27         echo "=== mkfs output ===" >>$seqres.full
28         _scratch_mkfs_xfs | tee -a $seqres.full | _filter_mkfs 2>$tmp.mkfs
29         . $tmp.mkfs
30         _scratch_mount
31         dd if=/dev/zero of=$SCRATCH_MNT/foo count=200 bs=4096 >/dev/null 2>&1 &
32         dd if=/dev/zero of=$SCRATCH_MNT/goo count=400 bs=4096 >/dev/null 2>&1 &
33         dd if=/dev/zero of=$SCRATCH_MNT/moo count=800 bs=4096 >/dev/null 2>&1 &
34         wait
35         _scratch_unmount                        # flush everything
36         _scratch_mount                          # and then remount
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # real QA test starts here
44 _supported_fs xfs
45 _supported_os Linux
46
47 _require_scratch
48 _require_no_large_scratch_dev
49
50 rm -f $seqres.full
51
52 _populate_scratch
53
54 eval `$DF_PROG -P --block-size=512 $SCRATCH_MNT 2>&1 \
55         | tail -1 | $AWK_PROG '{ printf "blocks=%u used=%u avail=%u\n", $3, $4, $5 }'`
56 echo "df gave: blocks=$blocks used=$used avail=$avail" >>$seqres.full
57 echo "blocksize from mkfs is '$dbsize'" >>$seqres.full
58
59 _scratch_xfs_db -r -c "freesp -s"  >$tmp.xfs_db
60 echo "xfs_db for $SCRATCH_DEV" >>$seqres.full
61 cat $tmp.xfs_db >>$seqres.full
62
63 eval `$XFS_IO_PROG -x -c resblks $SCRATCH_MNT 2>&1 \
64         | $AWK_PROG '/available/ { printf "resblks=%u\n", $5 }'`
65 echo "resblks gave: resblks=$resblks" >>$seqres.full
66
67 # check the 'blocks' field from freesp command is OK
68 perl -ne '
69         BEGIN   { $avail ='$avail' * 512 + ('$resblks' * '$dbsize');
70                   $answer="(no xfs_db free blocks line?)" }
71         /free blocks (\d+)$/    || next;
72         $freesp = $1 * '$dbsize';
73         if ($freesp >= $avail) {
74                 $answer = "yes";
75         } else {
76                 $answer = "no ($freesp < $avail)";
77         }
78         END     { print "$answer\n" }
79         ' <$tmp.xfs_db >$tmp.ans
80 ans="`cat $tmp.ans`"
81 echo "Checking blocks column same as df: $ans"
82 if [ "$ans" != yes ]
83 then
84         echo "Error: $SCRATCH_DEV: freesp mismatch: $ans"
85         echo "xfs_db output ..."
86         cat $tmp.xfs_db
87         status=1
88 fi
89
90 # check the 'pct' field from freesp command is good
91 perl -ne '
92             BEGIN       { $percent = 0; }
93             /free/      && next;        # skip over free extent size number
94             if (/\s+(\d+\.\d+)$/) {
95                 $percent += $1;
96             }
97             END { $percent += 0.5; print int($percent), "\n" }  # round up
98 ' <$tmp.xfs_db >$tmp.ans
99 ans="`cat $tmp.ans`"
100 echo "Checking percent column yields 100: $ans"
101 if [ "$ans" != 100 ]
102 then
103         echo "Error: $SCRATCH_DEV: pct mismatch: $ans (expected 100)"
104         echo "xfs_db output ..."
105         cat $tmp.xfs_db
106         status=1
107 fi
108
109 exit