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