91dc9605f2c4c86407928cf5233a0b58de5db6fe
[xfstests-dev.git] / tests / xfs / 180
1 #! /bin/bash
2 # FSQA Test No. 180
3 #
4 # Test for NULL files problem
5 # test inode size is on disk after sync
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 seqres=$RESULT_DIR/$seq
29 seqres=$RESULT_DIR/$seq
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 # Do we have enough space on disk?  10G
56 _require_fs_space $SCRATCH_MNT 10485760
57
58 _check_files()
59 {
60         # check file size and contents
61         i=1;
62         while [ $i -lt 1000 ]
63         do
64                 file=$SCRATCH_MNT/$i
65                 # if file is missing then sync failed
66                 if [ -e $file ]
67                 then
68                         # if file size is not 10MB then sync failed
69                         if [ `ls -l $file | tr -s ' ' | cut -d ' ' -f 5` -eq 10485760 ]
70                         then
71                                 # if file has non-zero size but no extents then it's contents will be NULLs, bad.
72                                 if xfs_bmap $file | grep 'no extents' > /dev/null
73                                 then
74                                         echo corrupt file $file - non-zero size but no extents
75                                 else
76                                         rm -f $file
77                                 fi
78                         else
79                                 echo file $file has incorrect size - sync failed
80                         fi
81                 else
82                         echo file $file missing - sync failed
83                 fi
84                 let i=$i+1
85         done
86 }
87
88 # create files and sync them
89 i=1;
90 while [ $i -lt 1000 ]
91 do
92         file=$SCRATCH_MNT/$i
93         xfs_io -f -c "pwrite -b 64k -S 0xff 0 10m" $file > /dev/null
94         if [ $? -ne 0 ]
95         then
96                 echo error creating/writing file $file
97                 exit
98         fi
99         let i=$i+1
100 done
101
102 # sync, then shutdown immediately after, then remount and test
103 sync
104 src/godown $SCRATCH_MNT
105 umount $SCRATCH_MNT
106 _scratch_mount
107 umount $SCRATCH_MNT
108 if [ ! _check_scratch_fs ]
109 then
110         echo error detected in filesystem
111         exit
112 fi
113 _scratch_mount
114 _check_files
115
116 status=0
117 exit