added scaly
[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 _scratch_mkfs_xfs -dsize=48m,agcount=3 2>&1 >/dev/null || _fail "mkfs failed"
80 _scratch_mount || _fail "mount failed" 
81
82 echo "done"
83
84 echo -n "Reserve 16 1Mb unfragmented regions... "
85 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
86 do
87     _do "dd if=/dev/zero of=$SCRATCH_MNT/hole$i bs=4096 count=256"
88     _do "dd if=/dev/zero of=$SCRATCH_MNT/space$i bs=4096 count=1"
89     _do "xfs_bmap -v $SCRATCH_MNT/hole$i"
90 done
91 echo "done" 
92
93 # set up filesystem
94 echo -n "Fill filesystem with 4k files, generate manifest... "
95 fill_options="--verbose --seed=0 --filesize=4096 --stddev=0 --sync=1000000"
96 _do "src/fill2fs $fill_options --dir=$SCRATCH_MNT/fill --list=- > $tmp.manifest"
97 echo "done"
98 # flush the filesystem - make sure there is no space "lost" to pre-allocation
99 _do "umount $SCRATCH_MNT"
100 _do "_scratch_mount"
101 echo -n "Use up any further available space using dd... "
102 _do "dd if=/dev/zero of=$SCRATCH_MNT/pad bs=4096"
103 echo "done"
104
105 # create fragmented file
106 _do "Delete every second file" "_cull_files"
107 echo -n "Create one very large file... "
108 _do "src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
109 echo "done"
110 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
111 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum1"
112 _do "Remove other files" "rm -rf $SCRATCH_MNT/{pad,hole*}"
113
114 # defragment
115 _do "Run xfs_fsr on filesystem" "$XFS_FSR_PROG -v $SCRATCH_DEV"
116 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
117 _do "Check 4k files" "src/fill2fs_check $tmp.manifest"
118
119 # check
120 echo -n "Check large file... "
121 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
122 if ! _do "diff $tmp.sum1 $tmp.sum2"; then
123     echo "fail"
124     echo "File is corrupt/missing after fsr. Test failed see $seq.full"
125     status=1; exit
126 fi
127 echo "done"
128 _do "Checking filesystem" "_check_scratch_fs"
129
130 # success, all done
131 echo "xfs_fsr tests passed."
132 status=0 ; exit