xfstests: convert tests to use new results directory
[xfstests-dev.git] / tests / xfs / 073
1 #! /bin/bash
2 # FS QA Test No. 073
3 #
4 # Test xfs_copy
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2003,2008 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38
39 # don't put fs images in /tmp
40 imgs=$TEST_DIR/$$
41
42 _cleanup()
43 {
44         cd /
45         umount $SCRATCH_MNT 2>/dev/null
46         umount -d $imgs.loop 2>/dev/null
47         [ -d $imgs.loop ] && rmdir $imgs.loop
48         umount -d $imgs.source_dir 2>/dev/null
49         [ -d $imgs.source_dir ] && rm -rf $imgs.source_dir
50         rm -f $imgs.* $tmp.* /var/tmp/xfs_copy.log.*
51 }
52 trap "_cleanup; exit \$status" 0 1 2 3 15
53
54 _filter_copy()
55 {
56         sed -e "s,$1,<DEVIMAGE>,g" -e "s,$2,<FSIMAGE1>,g" \
57             -e "s,$3,<DEVIMAGE>,g" -e "s,$4,<FSIMAGE2>,g"
58 }
59
60 _filter_path()
61 {
62         sed -e "s,$1,<MNTPATH>,g" | LC_COLLATE=POSIX sort
63 }
64
65 _populate_scratch()
66 {
67         POSIXLY_CORRECT=yes \
68                 dd if=/dev/zero of=$SCRATCH_MNT/big+attr count=1000 bs=4096
69         [ "$FAST_POPULATE" = true ] && return
70         echo $SCRATCH_MNT/big+attr | $here/src/fill2attr
71         $here/src/fill2fs --bytes=1048576 --filesize=4096 --stddev=0 --force \
72                 --dir=$SCRATCH_MNT/fill --list=- > $tmp.manifest
73 }
74
75 _verify_copy()
76 {
77         target=$1
78         target_dir=$imgs.loop
79         source=$2
80         source_dir=$3
81
82         [ $source = $SCRATCH_DEV ] && _scratch_mount
83
84         echo checking new image
85         _check_xfs_filesystem $target none none
86
87         echo mounting new image on loopback
88         rmdir $target_dir 2>/dev/null
89         mkdir $target_dir
90
91         mount -t xfs -o loop $target $target_dir 2>/dev/null
92         if [ $? -ne 0 ]; then
93                 echo retrying mount with nouuid option
94                 mount -t xfs -o loop -o nouuid $target $target_dir
95                 if [ $? -ne 0 ]; then
96                         echo mount failed - evil!
97                         return
98                 fi
99         fi
100
101         echo comparing new image files to old
102         diff -Naur $source_dir $target_dir
103
104         echo comparing new image directories to old
105         find $source_dir | _filter_path $source_dir > $tmp.manifest1
106         find $target_dir | _filter_path $target_dir > $tmp.manifest2
107         [ -s $tmp.manifest1 ] || echo no directory output
108         diff -u $tmp.manifest1 $tmp.manifest2
109
110         echo comparing new image geometry to old
111         xfs_info $source_dir \
112                 | _filter_copy $source $source_dir '/dev/loop.' '#' \
113                 | tr -s ' ' \
114                 > $tmp.geometry1
115         xfs_info $target_dir \
116                 | _filter_copy $target $target_dir '/dev/loop.' '#' \
117                 | tr -s ' ' \
118                 > $tmp.geometry2
119         [ -s $tmp.geometry1 ] || echo no geometry output
120         diff -u $tmp.geometry1 $tmp.geometry2
121
122         echo unmounting and removing new image
123         umount $source_dir
124         umount -d $target_dir > /dev/null 2>&1
125         rm -f $target
126 }
127
128
129 # real QA test starts here
130 _supported_fs xfs
131 _supported_os Linux
132
133 [ "$USE_EXTERNAL" = yes ] && _notrun "Cannot xfs_copy with external devices"
134 [ -n "$XFS_COPY_PROG" ] || _notrun "xfs_copy binary not yet installed"
135
136 _require_scratch
137 _require_loop
138
139 _scratch_mkfs_xfs -dsize=41m,agcount=2 | _filter_mkfs 2>/dev/null
140 _scratch_mount 2>/dev/null || _fail "initial scratch mount failed"
141
142 echo
143 echo === populating scratch device
144 _populate_scratch
145 umount $SCRATCH_MNT 2>/dev/null
146
147 echo
148 echo === copying scratch device to single target
149 $XFS_COPY_PROG $SCRATCH_DEV $imgs.image | _filter_copy '#' $imgs.image '#' '#'
150 _verify_copy $imgs.image $SCRATCH_DEV $SCRATCH_MNT
151
152 echo
153 echo === copying scratch device to single target, duplicate UUID
154 $XFS_COPY_PROG -d $SCRATCH_DEV $imgs.image | _filter_copy '#' $imgs.image '#' '#'
155 _verify_copy $imgs.image $SCRATCH_DEV $SCRATCH_MNT
156
157 echo 
158 echo === copying scratch device to single target, large ro device
159 ${MKFS_PROG}.xfs -dfile,name=$imgs.source,size=100g | _filter_mkfs 2>/dev/null
160 rmdir $imgs.source_dir 2>/dev/null
161 mkdir $imgs.source_dir
162
163 mount -t xfs -o loop $imgs.source $imgs.source_dir
164 loop2=`mount | grep $imgs.source | grep -o -e 'loop=.*[^),]' | grep -o -e '/.*$'`
165 cp -a $here $imgs.source_dir
166 mount -t xfs -o remount,ro $imgs.source $imgs.source_dir
167 $XFS_COPY_PROG $imgs.source $imgs.image | _filter_copy '#' $imgs.image '#' '#'
168 _verify_copy $imgs.image $imgs.source $imgs.source_dir
169
170 # HACK WARNING:
171 #
172 # We're done with the nested loop mount, now we have to clean
173 # up the pieces that mount is incapable of doing.
174 losetup -d $loop2 > /dev/null 2>&1
175
176 echo
177 echo === copying scratch device to multiple targets
178 $XFS_COPY_PROG -L$imgs.log -b $SCRATCH_DEV $imgs.image1 $imgs.image2 \
179         | _filter_copy '#' $imgs.image1 '#' $imgs.image2
180 _verify_copy $imgs.image1 $SCRATCH_DEV $SCRATCH_MNT
181 _verify_copy $imgs.image2 $SCRATCH_DEV $SCRATCH_MNT
182
183 # success, all done
184 status=0
185 exit