generic/077: fall back to /usr if /lib/modules doesn't exist
[xfstests-dev.git] / tests / shared / 289
1 #! /bin/bash
2 # FS QA Test No. 289
3 #
4 # Test overhead & df output for extN filesystems
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2012 Red Hat, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35     cd /
36     rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # real QA test starts here
44
45 # Modify as appropriate.
46 _supported_fs ext2 ext3 ext4
47 _supported_os Linux
48 _require_scratch
49
50 rm -f $seqres.full
51
52 _scratch_mkfs >> $seqres.full 2>&1
53
54 # Get the honest truth about block counts straight from metadata on disk
55 TOTAL_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
56                 | awk '/Block count:/{print $3}'`
57
58 FREE_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
59                 | awk '/Free blocks:/{print $3}'`
60
61 # ext3 doesn't count journal blocks as overhead, ext4 does.
62 if [ $FSTYP = "ext3" ]; then
63         JOURNAL_SIZE=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
64                 | awk '/Journal size:/{print $3}' | _filter_size_to_bytes`
65         BLOCK_SIZE=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
66                 | awk '/Block size:/{print $3}'`
67         JOURNAL_BLOCKS=$(($JOURNAL_SIZE/$BLOCK_SIZE))
68 else
69         JOURNAL_BLOCKS=0
70 fi
71
72 OVERHEAD=$(($TOTAL_BLOCKS-$FREE_BLOCKS-$JOURNAL_BLOCKS))
73
74 #  bsddf|minixdf
75 #         Set the behaviour  for  the  statfs  system  call.  The  minixdf
76 #         behaviour is to return in the f_blocks field the total number of
77 #         blocks of the filesystem, while the bsddf  behaviour  (which  is
78 #         the default) is to subtract the overhead blocks used by the ext2
79 #         filesystem and not available for file storage.
80
81 # stat -f output looks like this; we get f_blocks from that, which
82 # varies depending on the df mount options used below:
83
84 #   File: "/mnt/test"
85 #    ID: affc5f2b2f57652 Namelen: 255     Type: ext2/ext3
86 # Block size: 4096       Fundamental block size: 4096
87 # Blocks: Total: 5162741    Free: 5118725    Available: 4856465
88 # Inodes: Total: 1313760    Free: 1313749
89
90 _scratch_mount "-o minixdf"
91 MINIX_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
92 umount $SCRATCH_MNT
93
94 _scratch_mount "-o bsddf"
95 BSD_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
96 umount $SCRATCH_MNT
97
98 # Echo data to $seqres.full for analysis
99 echo "Overhead is $OVERHEAD blocks out of $TOTAL_BLOCKS ($FREE_BLOCKS free)" >> $seqres.full
100 echo "MINIX free blocks $MINIX_F_BLOCKS" >> $seqres.full
101 echo "BSD free blocks $BSD_F_BLOCKS" >> $seqres.full
102
103 # minix should be exactly equal (hence tolerance of 0)
104 _within_tolerance "minix f_blocks" $MINIX_F_BLOCKS $TOTAL_BLOCKS 0 -v
105 # bsd should be within ... we'll say 1% for some slop
106 _within_tolerance "bsd f_blocks" $BSD_F_BLOCKS $(($TOTAL_BLOCKS-$OVERHEAD)) 1% -v
107
108 # success, all done
109 status=0
110 exit