fix XFSQA 145 / test_hole
[xfstests-dev.git] / 073
1 #! /bin/sh
2 # FS QA Test No. 073
3 #
4 # Test xfs_copy
5 #
6 # HACK WARNING:
7 #
8 # Due to the severe brokenness of mount's handling of loopback devices, we
9 # hardcode the loop devices we use for this test. This enables us to clean up
10 # the pieces when we remount the loop device because mount loses all trace of
11 # the fact this is a loop device. Hence to enable us to unmount the hosting
12 # filesystem, we need to manually tear down the relevant loop device. If
13 # mount ever gets fixed then this hack can be removed.
14 #
15 #-----------------------------------------------------------------------
16 # Copyright (c) 2000-2003,2008 Silicon Graphics, Inc.  All Rights Reserved.
17 #-----------------------------------------------------------------------
18 #
19 # creator
20 owner=nathans@sgi.com
21
22 seq=`basename $0`
23 echo "QA output created by $seq"
24
25 here=`pwd`
26 tmp=/tmp/$$
27 status=1        # failure is the default!
28
29 # get standard environment, filters and checks
30 . ./common.rc
31 . ./common.filter
32
33 # don't put fs images in /tmp
34 imgs=$TEST_DIR/$$
35
36 _cleanup()
37 {
38         cd /
39         umount $SCRATCH_MNT 2>/dev/null
40         umount $imgs.loop 2>/dev/null
41         [ -d $imgs.loop ] && rmdir $imgs.loop
42         [ -d $imgs.source_dir ] && rm -rf $imgs.source_dir
43         rm -f $imgs.* $tmp.* /var/tmp/xfs_copy.log.*
44 }
45 trap "_cleanup; exit \$status" 0 1 2 3 15
46
47 _filter_copy()
48 {
49         sed -e "s,$1,<DEVIMAGE>,g" -e "s,$2,<FSIMAGE1>,g" \
50             -e "s,$3,<DEVIMAGE>,g" -e "s,$4,<FSIMAGE2>,g"
51 }
52
53 _filter_path()
54 {
55         sed -e "s,$1,<MNTPATH>,g" | LC_COLLATE=POSIX sort
56 }
57
58 _populate_scratch()
59 {
60         POSIXLY_CORRECT=yes \
61                 dd if=/dev/zero of=$SCRATCH_MNT/big+attr count=1000 bs=4096
62         [ "$FAST_POPULATE" = true ] && return
63         echo $SCRATCH_MNT/big+attr | $here/src/fill2attr
64         $here/src/fill2fs --bytes=1048576 --filesize=4096 --stddev=0 --force \
65                 --dir=$SCRATCH_MNT/fill --list=- > $tmp.manifest
66 }
67
68 _verify_copy()
69 {
70         target=$1
71         target_dir=$imgs.loop
72         source=$2
73         source_dir=$3
74
75         [ $source = $SCRATCH_DEV ] && _scratch_mount
76
77         echo checking new image
78         _check_xfs_filesystem $target none none
79
80         echo mounting new image on loopback
81         rmdir $target_dir 2>/dev/null
82         mkdir $target_dir
83
84         mount -t xfs -o loop $target $target_dir 2>/dev/null
85         if [ $? -ne 0 ]; then
86                 echo retrying mount with nouuid option
87                 mount -t xfs -o loop -o nouuid $target $target_dir
88                 if [ $? -ne 0 ]; then
89                         echo mount failed - evil!
90                         return
91                 fi
92         fi
93
94         echo comparing new image files to old
95         diff -Naur $source_dir $target_dir
96
97         echo comparing new image directories to old
98         find $source_dir | _filter_path $source_dir > $tmp.manifest1
99         find $target_dir | _filter_path $target_dir > $tmp.manifest2
100         [ -s $tmp.manifest1 ] || echo no directory output
101         diff -u $tmp.manifest1 $tmp.manifest2
102
103         echo comparing new image geometry to old
104         xfs_info $source_dir \
105                 | _filter_copy $source $source_dir '/dev/loop.' '#' \
106                 | tr -s ' ' \
107                 > $tmp.geometry1
108         xfs_info $target_dir \
109                 | _filter_copy $target $target_dir '/dev/loop.' '#' \
110                 | tr -s ' ' \
111                 > $tmp.geometry2
112         [ -s $tmp.geometry1 ] || echo no geometry output
113         diff -u $tmp.geometry1 $tmp.geometry2
114
115         echo unmounting and removing new image
116         loop=`mount | grep $target | grep -o -e 'loop=.*[^),]' | grep -o -e '/.*$'`
117         umount $source $target
118         losetup -d $loop > /dev/null 2>&1
119         rm -f $target
120 }
121
122
123 # real QA test starts here
124 _supported_fs xfs
125 _supported_os Linux
126
127 [ "$USE_EXTERNAL" = yes ] && _notrun "Cannot xfs_copy with external devices"
128 [ -x /usr/sbin/xfs_copy ] || _notrun "xfs_copy binary not yet installed"
129
130 _require_scratch
131 _require_loop
132
133 _scratch_mkfs_xfs -dsize=41m,agcount=2 | _filter_mkfs 2>/dev/null
134 _scratch_mount 2>/dev/null || _fail "initial scratch mount failed"
135
136 echo
137 echo === populating scratch device
138 _populate_scratch
139 umount $SCRATCH_MNT 2>/dev/null
140
141 echo
142 echo === copying scratch device to single target
143 xfs_copy $SCRATCH_DEV $imgs.image | _filter_copy '#' $imgs.image '#' '#'
144 _verify_copy $imgs.image $SCRATCH_DEV $SCRATCH_MNT
145
146 echo
147 echo === copying scratch device to single target, duplicate UUID
148 xfs_copy -d $SCRATCH_DEV $imgs.image | _filter_copy '#' $imgs.image '#' '#'
149 _verify_copy $imgs.image $SCRATCH_DEV $SCRATCH_MNT
150
151 echo 
152 echo === copying scratch device to single target, large ro device
153 /sbin/mkfs.xfs -dfile,name=$imgs.source,size=100g | _filter_mkfs 2>/dev/null
154 rmdir $imgs.source_dir 2>/dev/null
155 mkdir $imgs.source_dir
156
157 mount -t xfs -o loop $imgs.source $imgs.source_dir
158 loop2=`mount | grep $imgs.source | grep -o -e 'loop=.*[^),]' | grep -o -e '/.*$'`
159 cp -a $here $imgs.source_dir
160 mount -t xfs -o remount,ro $imgs.source $imgs.source_dir
161 xfs_copy $imgs.source $imgs.image | _filter_copy '#' $imgs.image '#' '#'
162 _verify_copy $imgs.image $imgs.source $imgs.source_dir
163
164 # HACK WARNING:
165 #
166 # We're done with the nested loop mount, now we have to clean
167 # up the pieces that mount is incapable of doing.
168 losetup -d $loop2 > /dev/null 2>&1
169
170 echo
171 echo === copying scratch device to multiple targets
172 xfs_copy -L$imgs.log -b $SCRATCH_DEV $imgs.image1 $imgs.image2 \
173         | _filter_copy '#' $imgs.image1 '#' $imgs.image2
174 _verify_copy $imgs.image1 $SCRATCH_DEV $SCRATCH_MNT
175 _verify_copy $imgs.image2 $SCRATCH_DEV $SCRATCH_MNT
176
177 # success, all done
178 status=0
179 exit