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