xfstests: test ext4 statfs
[xfstests-dev.git] / 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 # creator
24 owner=sandeen@redhat.com
25
26 seq=`basename $0`
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36     cd /
37     rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common.rc
42 . ./common.filter
43
44 # real QA test starts here
45
46 # Modify as appropriate.
47 _supported_fs ext2 ext3 ext4
48 _supported_os Linux
49 _require_scratch
50
51 rm -f $seq.full
52
53 _scratch_mkfs >> $seq.full 2>&1
54
55 # Get the honest truth about block counts straight from metadata on disk
56 TOTAL_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
57                 | awk '/Block count:/{print $3}'`
58
59 FREE_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
60                 | awk '/Free blocks:/{print $3}'`
61
62 # nb: kernels today don't count journal blocks  as overhead, but should.
63 # For most filesystems this will still be within tolerance.
64 # Overhead is all the blocks (already) used by the fs itself:
65 OVERHEAD=$(($TOTAL_BLOCKS-$FREE_BLOCKS))
66
67 #  bsddf|minixdf
68 #         Set the behaviour  for  the  statfs  system  call.  The  minixdf
69 #         behaviour is to return in the f_blocks field the total number of
70 #         blocks of the filesystem, while the bsddf  behaviour  (which  is
71 #         the default) is to subtract the overhead blocks used by the ext2
72 #         filesystem and not available for file storage.
73
74 # stat -f output looks like this; we get f_blocks from that, which
75 # varies depending on the df mount options used below:
76
77 #   File: "/mnt/test"
78 #    ID: affc5f2b2f57652 Namelen: 255     Type: ext2/ext3
79 # Block size: 4096       Fundamental block size: 4096
80 # Blocks: Total: 5162741    Free: 5118725    Available: 4856465
81 # Inodes: Total: 1313760    Free: 1313749
82
83 _scratch_mount "-o minixdf"
84 MINIX_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
85 umount $SCRATCH_MNT
86
87 _scratch_mount "-o bsddf"
88 BSD_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
89 umount $SCRATCH_MNT
90
91 # Echo data to $seq.full for analysis
92 echo "Overhead is $OVERHEAD blocks out of $TOTAL_BLOCKS ($FREE_BLOCKS free)" >> $seq.full
93 echo "MINIX free blocks $MINIX_F_BLOCKS" >> $seq.full
94 echo "BSD free blocks $BSD_F_BLOCKS" >> $seq.full
95
96 # minix should be exactly equal (hence tolerance of 0)
97 _within_tolerance "minix f_blocks" $MINIX_F_BLOCKS $TOTAL_BLOCKS 0 -v
98 # bsd should be within ... we'll say 1% for some slop
99 _within_tolerance "bsd f_blocks" $BSD_F_BLOCKS $(($TOTAL_BLOCKS-$OVERHEAD)) 1% -v
100
101 # success, all done
102 status=0
103 exit