57e4b45aaf4ee9a2ff18aa2d828f2ac2c9a86c39
[xfstests-dev.git] / 179
1 #! /bin/sh
2 #
3 #-----------------------------------------------------------------------
4 # Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 #
19 #-----------------------------------------------------------------------
20 #
21 # FSQA Test No. 179
22 #
23 # Test for NULL files problem
24 # test inode size is on disk after fsync
25 #
26 # creator
27 owner=lachlan@sgi.com
28
29 seq=`basename $0`
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1    # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39     _cleanup_testdir
40 }
41
42 # get standard environment, filters and checks
43 . ./common.rc
44 . ./common.filter
45
46 # real QA test starts here
47 _supported_fs xfs
48 _supported_os Linux IRIX
49
50 _setup_testdir
51 _require_scratch
52 _scratch_mkfs_xfs >/dev/null 2>&1
53 _scratch_mount
54
55 _check_files()
56 {
57         # check file size and contents
58         i=1;
59         while [ $i -lt 1000 ]
60         do
61                 file=$SCRATCH_MNT/$i
62                 # if file is missing then fsync failed
63                 if [ -e $file ]
64                 then
65                         # if file size is not 32KB then fsync failed
66                         if [ `ls -l $file | tr -s ' ' | cut -d ' ' -f 5` -eq 32768 ]
67                         then
68                                 # if file has non-zero size but no extents then it's contents will be NULLs, bad.
69                                 if xfs_bmap $file | grep 'no extents' > /dev/null
70                                 then
71                                         echo corrupt file $file - non-zero size but no extents
72                                 else
73                                         rm -f $file
74                                 fi
75                         else
76                                 echo file $file has incorrect size - fsync failed
77                         fi
78                 else
79                         echo file $file missing - fsync failed
80                 fi
81                 let i=$i+1
82         done
83 }
84
85 # create files and fsync them
86 i=1;
87 while [ $i -lt 1000 ]
88 do
89         file=$SCRATCH_MNT/$i
90         xfs_io -f -c "pwrite -b 32k -S 0xff 0 32k" -c "fsync" $file > /dev/null
91         if [ $? -ne 0 ]
92         then
93                 echo error creating/writing file $file
94                 exit
95         fi
96         let i=$i+1
97 done
98
99 # shutdown immediately after, then remount and test
100 src/godown $SCRATCH_MNT
101 umount $SCRATCH_MNT
102 _scratch_mount
103 umount $SCRATCH_MNT
104 if [ ! _check_scratch_fs ]
105 then
106         echo error detected in filesystem
107         exit
108 fi
109 _scratch_mount
110 _check_files
111
112 status=0
113 exit