run test on scratch dir
[xfstests-dev.git] / 042
1 #! /bin/sh
2 # FS 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 #
12 set +x
13 # creator
14 owner=ajag@sgi.com
15
16 seq=`basename $0`
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22
23 _cleanup()
24 {
25     umount $SCRATCH_MNT
26     rm -f $tmp.*
27 }
28 trap "_cleanup ; exit \$status" 0 1 2 3 15
29
30 # get standard environment, filters and checks
31 . ./common.rc
32 . ./common.filter
33
34 # real QA test starts here
35 _supported_fs xfs
36 _supported_os IRIX Linux
37
38 _require_scratch
39
40 _cull_files()
41 {
42     perl -e "\$manifest=\"$tmp.manifest\";" -e '
43         open MANIFEST, $manifest;
44         @in = <MANIFEST>;
45         close MANIFEST;
46         open MANIFEST, ">$manifest";
47         for ($i = 0; $i < @in; $i++) {
48             if (($i+1) % 2 == 0) {
49                 # remove every second file
50                 chomp($s = $in[$i]);
51                 if (unlink($s) != 1) {
52                     print "_cull_files: could not delete \"$s\"\n";
53                     exit(1);
54                 }
55             }
56             else {
57                 print MANIFEST $in[$i];
58             }
59         }
60         close MANIFEST;
61         exit(0);'
62 }
63
64 # create a large contiguous file using dd
65 # use fill2fs to fill the filesystem up with 4k sized files
66 # fill any remaining space using dd
67 # delete every second 4k file - remaining free space should be fragmented
68 # use fill2 to generate a very large file - run it until it fails producing a truncated file
69 # delete the dd-generated file
70 # run xfs_fsr on the filesystem
71 # check checksums for remaining files
72 # create 3 minimum sized (16Mb) allocation groups
73 # xfs_repair is going to need three to verify the superblock
74
75 rm -f $seq.full
76 _do_die_on_error=message_only
77
78 echo -n "Make a 48 megabyte filesystem on SCRATCH_DEV and mount... "
79 _do "_scratch_mkfs_xfs -dsize=48m,agcount=3"
80 _do "_scratch_mount"
81 echo "done"
82
83 echo -n "Reserve 16 1Mb unfragmented regions... "
84 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
85 do
86     _do "dd if=/dev/zero of=$SCRATCH_MNT/hole$i bs=4096 count=256"
87     _do "dd if=/dev/zero of=$SCRATCH_MNT/space$i bs=4096 count=1"
88     _do "xfs_bmap -v $SCRATCH_MNT/hole$i"
89 done
90 echo "done" 
91
92 # set up filesystem
93 echo -n "Fill filesystem with 4k files, generate manifest... "
94 fill_options="--verbose --seed=0 --filesize=4096 --stddev=0 --sync=1000000"
95 _do "src/fill2fs $fill_options --dir=$SCRATCH_MNT/fill --list=- > $tmp.manifest"
96 echo "done"
97 # flush the filesystem - make sure there is no space "lost" to pre-allocation
98 _do "umount $SCRATCH_MNT"
99 _do "_scratch_mount"
100 echo -n "Use up any further available space using dd... "
101 _do "dd if=/dev/zero of=$SCRATCH_MNT/pad bs=4096"
102 echo "done"
103
104 # create fragmented file
105 _do "Delete every second file" "_cull_files"
106 echo -n "Create one very large file... "
107 _do "src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
108 echo "done"
109 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
110 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum1"
111 _do "Remove other files" "rm -rf $SCRATCH_MNT/{pad,hole*}"
112
113 # defragment
114 _do "Run xfs_fsr on filesystem" "$XFS_FSR_PROG -v $SCRATCH_DEV"
115 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
116 _do "Check 4k files" "src/fill2fs_check $tmp.manifest"
117
118 # check
119 echo -n "Check large file... "
120 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
121 if ! _do "diff $tmp.sum1 $tmp.sum2"; then
122     echo "fail"
123     echo "File is corrupt/missing after fsr. Test failed see $seq.full"
124     status=1; exit
125 fi
126 echo "done"
127 _do "Checking filesystem" "_check_scratch_fs"
128
129 # success, all done
130 echo "xfs_fsr tests passed."
131 status=0 ; exit