reflink: ensure that we can handle reflinking a lot of extents
[xfstests-dev.git] / tests / generic / 049
1 #! /bin/bash
2 # FSQA Test No. 049
3 #
4 # Test for NULL files problem
5 # test inode size is on disk after sync - expose log replay bug
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 IRIX
42
43 _require_scratch
44 _require_scratch_shutdown
45 _require_fiemap
46 _scratch_mkfs >/dev/null 2>&1
47 _scratch_mount
48
49 _check_files()
50 {
51         # check file size and contents
52         i=1;
53         while [ $i -lt 1000 ]
54         do
55                 file=$SCRATCH_MNT/$i
56                 # if file is missing then sync failed
57                 if [ -e $file ]
58                 then
59                         # if file size is not 32KB then sync failed
60                         if [ `ls -l $file | tr -s ' ' | cut -d ' ' -f 5` -eq 32768 ]
61                         then
62                                 # if file has non-zero size but no extents then it's contents will be NULLs, bad.
63                                 num_extents=`_count_extents $file`
64                                 if [ $num_extents -eq 0 ]; then
65                                         echo corrupt file $file - non-zero size but no extents
66                                 else
67                                         rm -f $file
68                                 fi
69                         else
70                                 echo file $file has incorrect size - sync failed
71                         fi
72                 else
73                         echo file $file missing - sync failed
74                 fi
75                 let i=$i+1
76         done
77 }
78
79 # create files and sync them
80 i=1;
81 while [ $i -lt 1000 ]
82 do
83         file=$SCRATCH_MNT/$i
84         xfs_io -f -c "pwrite -b 32k -S 0xff 0 32k" $file > /dev/null
85         if [ $? -ne 0 ]
86         then
87                 echo error creating/writing file $file
88                 exit
89         fi
90         let i=$i+1
91 done
92
93 # sync, then shutdown immediately after, then remount and test
94 sync
95 src/godown $SCRATCH_MNT
96 _scratch_unmount
97 _scratch_mount
98 _scratch_unmount
99 if [ ! _check_scratch_fs ]
100 then
101         echo error detected in filesystem
102         exit
103 fi
104 _scratch_mount
105 _check_files
106
107 status=0
108 exit