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