update for version 2 logs
[xfstests-dev.git] / 073
1 #! /bin/sh
2 # XFS QA Test No. 073
3 #
4 # Test xfs_copy
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
8
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of version 2 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, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write the Free Software Foundation, Inc., 59
26 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
27
28 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
29 # Mountain View, CA  94043, or:
30
31 # http://www.sgi.com 
32
33 # For further information regarding this notice, see: 
34
35 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #-----------------------------------------------------------------------
37 #
38 # creator
39 owner=nathans@sgi.com
40
41 seq=`basename $0`
42 echo "QA output created by $seq"
43
44 here=`pwd`
45 tmp=/tmp/$$
46 status=1        # failure is the default!
47 _cleanup()
48 {
49         umount $SCRATCH_MNT 2>/dev/null
50         umount $tmp.loop 2>/dev/null
51         [ -d $tmp.loop ] && rmdir $tmp.loop
52         [ -d $tmp.source_dir ] && rmdir $tmp.source_dir
53         rm -f $tmp.* /var/tmp/xfs_copy.log.*
54 }
55 trap "_cleanup; exit \$status" 0 1 2 3 15
56
57 _filter_copy()
58 {
59         sed -e "s,$1,<FSIMAGE1>,g" -e "s,$2,<FSIMAGE2>,g"
60 }
61
62 _populate_scratch()
63 {
64         POSIXLY_CORRECT=yes \
65                 dd if=/dev/zero of=$SCRATCH_MNT/big+attr count=1000 bs=4096
66         [ "$FAST_POPULATE" = true ] && return
67         echo $SCRATCH_MNT/big+attr | $here/src/fill2attr
68         $here/src/fill2fs --bytes=1048576 --filesize=4096 --stddev=0 --force \
69                 --dir=$SCRATCH_MNT/fill --list=- > $tmp.manifest
70 }
71
72 _verify_copy()
73 {
74         target=$1
75         target_dir=$tmp.loop
76         source=$2
77         source_dir=$3
78
79         [ $source = $SCRATCH_DEV ] && _scratch_mount
80
81         echo checking new image
82         _check_filesystem $target
83
84         echo mounting new image on loopback
85         rmdir $target_dir 2>/dev/null
86         mkdir $target_dir
87         mount -t xfs -o loop $target $target_dir 2>/dev/null
88         if [ $? -ne 0 ]; then
89                 echo retrying mount with nouuid option
90                 mount -t xfs -o loop -o nouuid $target $target_dir
91                 if [ $? -ne 0 ]; then
92                         echo mount failed - evil!
93                         return
94                 fi
95         fi
96
97         echo comparing new image files to old
98         diff -Naur $source_dir $target_dir
99
100         echo comparing new image directories to old
101         find $source_dir \
102                 | _filter_copy $source_dir '#' \
103                 | LC_COLLATE=POSIX sort \
104                 > $tmp.manifest1
105         find $target_dir \
106                 | _filter_copy $target_dir '#' \
107                 | LC_COLLATE=POSIX sort \
108                 > $tmp.manifest2
109         [ -s $tmp.manifest1 ] || echo no directory output
110         diff -u $tmp.manifest1 $tmp.manifest2
111
112         echo comparing new image geometry to old
113         xfs_info $source_dir \
114                 | _filter_copy $source_dir '#' \
115                 | tr -s ' ' \
116                 > $tmp.geometry1
117         xfs_info $target_dir \
118                 | _filter_copy $target_dir '#' \
119                 | tr -s ' ' \
120                 > $tmp.geometry2
121         [ -s $tmp.geometry1 ] || echo no geometry output
122         diff -u $tmp.geometry1 $tmp.geometry2
123
124         echo unmounting and removing new image
125         umount $source $target
126         rm -f $target
127 }
128
129 # get standard environment, filters and checks
130 . ./common.rc
131 . ./common.filter
132
133 [ "$USE_EXTERNAL" = yes ] && _notrun "Cannot xfs_copy with external devices"
134 [ -x /usr/sbin/xfs_copy ] || _notrun "xfs_copy binary not yet installed"
135
136 # real QA test starts here
137 _require_scratch
138 _require_loop
139
140 _scratch_mkfs_xfs -dsize=41m | _filter_mkfs 2>/dev/null
141 _scratch_mount 2>/dev/null || _fail "initial scratch mount failed"
142
143 echo
144 echo === populating scratch device
145 _populate_scratch
146 umount $SCRATCH_MNT 2>/dev/null
147
148 echo
149 echo === copying scratch device to single target
150 xfs_copy $SCRATCH_DEV $tmp.image | _filter_copy $tmp.image
151 _verify_copy $tmp.image $SCRATCH_DEV $SCRATCH_MNT
152
153 echo
154 echo === copying scratch device to single target, duplicate UUID
155 xfs_copy -d $SCRATCH_DEV $tmp.image | _filter_copy $tmp.image
156 _verify_copy $tmp.image $SCRATCH_DEV $SCRATCH_MNT
157
158 echo 
159 echo === copying scratch device to single target, large ro device
160 /sbin/mkfs.xfs -dfile,name=$tmp.source,size=100g | _filter_mkfs 2>/dev/null
161 rmdir $tmp.source_dir 2>/dev/null
162 mkdir $tmp.source_dir
163 mount -t xfs -o loop $tmp.source $tmp.source_dir
164 cp -a $here $tmp.source_dir
165 mount -t xfs -o remount,ro $tmp.source $tmp.source_dir
166 xfs_copy $tmp.source $tmp.image | _filter_copy $tmp.image
167 _verify_copy $tmp.image $tmp.source $tmp.source_dir
168
169 echo
170 echo === copying scratch device to multiple targets
171 xfs_copy -L$tmp.log -b $SCRATCH_DEV $tmp.image1 $tmp.image2 \
172         | _filter_copy $tmp.image1 $tmp.image2
173 _verify_copy $tmp.image1 $SCRATCH_DEV $SCRATCH_MNT
174 _verify_copy $tmp.image2 $SCRATCH_DEV $SCRATCH_MNT
175
176 # success, all done
177 status=0
178 exit