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