Add xfsdump support for the security extended attributes namespace.
[xfstests-dev.git] / 042
1 #! /bin/sh
2 # XFS QA Test No. 042
3 #
4 # xfs_fsr QA tests
5 # create a large fragmented file and check that xfs_fsr doesn't corrupt
6 # it or the other contents of the filesystem
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
10
11 # This program is free software; you can redistribute it and/or modify it
12 # under the terms of version 2 of the GNU General Public License as
13 # published by the Free Software Foundation.
14
15 # This program is distributed in the hope that it would be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
19 # Further, this software is distributed without any warranty that it is
20 # free of the rightful claim of any third person regarding infringement
21 # or the like.  Any license provided herein, whether implied or
22 # otherwise, applies only to this software file.  Patent licenses, if
23 # any, provided herein do not apply to combinations of this program with
24 # other software, or any other product whatsoever.
25
26 # You should have received a copy of the GNU General Public License along
27 # with this program; if not, write the Free Software Foundation, Inc., 59
28 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
29
30 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
31 # Mountain View, CA  94043, or:
32
33 # http://www.sgi.com 
34
35 # For further information regarding this notice, see: 
36
37 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #-----------------------------------------------------------------------
39 #
40 set +x
41 # creator
42 owner=ajag@sgi.com
43
44 seq=`basename $0`
45 echo "QA output created by $seq"
46
47 here=`pwd`
48 tmp=/tmp/$$
49 status=1        # failure is the default!
50
51 _cleanup()
52 {
53     umount $SCRATCH_MNT
54     rm -f $tmp.*
55 }
56 trap "_cleanup ; exit \$status" 0 1 2 3 15
57
58 # get standard environment, filters and checks
59 . ./common.rc
60 . ./common.filter
61
62 # real QA test starts here
63
64 _require_scratch
65
66 _cull_files()
67 {
68     perl -e "\$manifest=\"$tmp.manifest\";" -e '
69         open MANIFEST, $manifest;
70         @in = <MANIFEST>;
71         close MANIFEST;
72         open MANIFEST, ">$manifest";
73         for ($i = 0; $i < @in; $i++) {
74             if (($i+1) % 2 == 0) {
75                 # remove every second file
76                 chomp($s = $in[$i]);
77                 if (unlink($s) != 1) {
78                     print "_cull_files: could not delete \"$s\"\n";
79                     exit(1);
80                 }
81             }
82             else {
83                 print MANIFEST $in[$i];
84             }
85         }
86         close MANIFEST;
87         exit(0);'
88 }
89
90 # create a large contiguous file using dd
91 # use fill2fs to fill the filesystem up with 4k sized files
92 # fill any remaining space using dd
93 # delete every second 4k file - remaining free space should be fragmented
94 # use fill2 to generate a very large file - run it until it fails producing a truncated file
95 # delete the dd-generated file
96 # run xfs_fsr on the filesystem
97 # check checksums for remaining files
98 # create 3 minimum sized (16Mb) allocation groups
99 # xfs_repair is going to need three to verify the superblock
100
101 rm -f $seq.full
102 _do_die_on_error=message_only
103
104 echo -n "Make a 48 megabyte filesystem on SCRATCH_DEV and mount... "
105 _do "_scratch_mkfs_xfs -dsize=48m,agcount=3"
106 _do "_scratch_mount"
107 echo "done"
108
109 echo -n "Reserve 16 1Mb unfragmented regions... "
110 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
111 do
112     _do "dd if=/dev/zero of=$SCRATCH_MNT/hole$i bs=4096 count=256"
113     _do "dd if=/dev/zero of=$SCRATCH_MNT/space$i bs=4096 count=1"
114     _do "xfs_bmap -v $SCRATCH_MNT/hole$i"
115 done
116 echo "done" 
117
118 # set up filesystem
119 echo -n "Fill filesystem with 4k files, generate manifest... "
120 fill_options="--verbose --seed=0 --filesize=4096 --stddev=0 --sync=1000000"
121 _do "src/fill2fs $fill_options --dir=$SCRATCH_MNT/fill --list=- > $tmp.manifest"
122 echo "done"
123 # flush the filesystem - make sure there is no space "lost" to pre-allocation
124 _do "umount $SCRATCH_MNT"
125 _do "_scratch_mount"
126 echo -n "Use up any further available space using dd... "
127 _do "dd if=/dev/zero of=$SCRATCH_MNT/pad bs=4096"
128 echo "done"
129
130 # create fragmented file
131 _do "Delete every second file" "_cull_files"
132 echo -n "Create one very large file... "
133 _do "src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
134 echo "done"
135 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
136 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum1"
137 _do "Remove other files" "rm -rf $SCRATCH_MNT/{pad,hole*}"
138
139 # defragment
140 _do "Run xfs_fsr on filesystem" "xfs_fsr -v $SCRATCH_DEV"
141 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
142 _do "Check 4k files" "src/fill2fs_check $tmp.manifest"
143
144 # check
145 echo -n "Check large file... "
146 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
147 if ! _do "diff $tmp.sum1 $tmp.sum2"; then
148     echo "fail"
149     echo "File is corrupt/missing after fsr. Test failed see $seq.full"
150     status=1; exit
151 fi
152 echo "done"
153 _do "Checking filesystem" "_check_scratch_fs"
154
155 # success, all done
156 echo "xfs_fsr tests passed."
157 status=0 ; exit