fd9fcd9291502943fbebfff2ba771078bbc03919
[xfstests-dev.git] / tests / generic / 048
1 #! /bin/bash
2 # FSQA Test No. 048
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 "exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # real QA test starts here
40 _supported_fs generic
41 _supported_os Linux
42
43 _require_scratch
44 _require_scratch_shutdown
45 _require_xfs_io_command "fiemap"
46 _scratch_mkfs >/dev/null 2>&1
47 _require_metadata_journaling $SCRATCH_DEV
48 _scratch_mount
49
50 # Do we have enough space on disk?  10G
51 _require_fs_space $SCRATCH_MNT 10485760
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 sync failed
61                 if [ -e $file ]
62                 then
63                         # if file size is not 10MB then sync failed
64                         if [ `ls -l $file | tr -s ' ' | cut -d ' ' -f 5` -eq 10485760 ]
65                         then
66                                 # if file has non-zero size but no extents then it's contents will be NULLs, bad.
67                                 num_extents=`_count_extents $file`
68                                 if [ $num_extents -eq 0 ]; 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 - sync failed
75                         fi
76                 else
77                         echo file $file missing - sync failed
78                 fi
79                 let i=$i+1
80         done
81 }
82
83 # create files and sync them
84 i=1;
85 while [ $i -lt 1000 ]
86 do
87         file=$SCRATCH_MNT/$i
88         $XFS_IO_PROG -f -c "pwrite -b 64k -S 0xff 0 10m" $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 # sync, then shutdown immediately after, then remount and test
98 sync
99 _scratch_shutdown
100 _scratch_unmount
101 _scratch_mount
102 _scratch_unmount
103 if [ ! _check_scratch_fs ]
104 then
105         echo error detected in filesystem
106         exit
107 fi
108 _scratch_mount
109 _check_files
110
111 status=0
112 exit