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