Keep userspace packaging in sync; update srcdiff to grok moved dmapi source.
[xfstests-dev.git] / 073
1 #! /bin/sh
2 # FS 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         cd /
50         umount $SCRATCH_MNT 2>/dev/null
51         umount $tmp.loop 2>/dev/null
52         [ -d $tmp.loop ] && rmdir $tmp.loop
53         [ -d $tmp.source_dir ] && rmdir $tmp.source_dir
54         rm -f $tmp.* /var/tmp/xfs_copy.log.*
55 }
56 trap "_cleanup; exit \$status" 0 1 2 3 15
57
58 _filter_copy()
59 {
60         sed -e "s,$1,<FSIMAGE1>,g" -e "s,$2,<FSIMAGE2>,g"
61 }
62
63 _populate_scratch()
64 {
65         POSIXLY_CORRECT=yes \
66                 dd if=/dev/zero of=$SCRATCH_MNT/big+attr count=1000 bs=4096
67         [ "$FAST_POPULATE" = true ] && return
68         echo $SCRATCH_MNT/big+attr | $here/src/fill2attr
69         $here/src/fill2fs --bytes=1048576 --filesize=4096 --stddev=0 --force \
70                 --dir=$SCRATCH_MNT/fill --list=- > $tmp.manifest
71 }
72
73 _verify_copy()
74 {
75         target=$1
76         target_dir=$tmp.loop
77         source=$2
78         source_dir=$3
79
80         [ $source = $SCRATCH_DEV ] && _scratch_mount
81
82         echo checking new image
83         _check_xfs_filesystem $target
84
85         echo mounting new image on loopback
86         rmdir $target_dir 2>/dev/null
87         mkdir $target_dir
88         mount -t xfs -o loop $target $target_dir 2>/dev/null
89         if [ $? -ne 0 ]; then
90                 echo retrying mount with nouuid option
91                 mount -t xfs -o loop -o nouuid $target $target_dir
92                 if [ $? -ne 0 ]; then
93                         echo mount failed - evil!
94                         return
95                 fi
96         fi
97
98         echo comparing new image files to old
99         diff -Naur $source_dir $target_dir
100
101         echo comparing new image directories to old
102         find $source_dir \
103                 | _filter_copy $source_dir '#' \
104                 | LC_COLLATE=POSIX sort \
105                 > $tmp.manifest1
106         find $target_dir \
107                 | _filter_copy $target_dir '#' \
108                 | LC_COLLATE=POSIX sort \
109                 > $tmp.manifest2
110         [ -s $tmp.manifest1 ] || echo no directory output
111         diff -u $tmp.manifest1 $tmp.manifest2
112
113         echo comparing new image geometry to old
114         xfs_info $source_dir \
115                 | _filter_copy $source_dir '#' \
116                 | tr -s ' ' \
117                 > $tmp.geometry1
118         xfs_info $target_dir \
119                 | _filter_copy $target_dir '#' \
120                 | tr -s ' ' \
121                 > $tmp.geometry2
122         [ -s $tmp.geometry1 ] || echo no geometry output
123         diff -u $tmp.geometry1 $tmp.geometry2
124
125         echo unmounting and removing new image
126         umount $source $target
127         rm -f $target
128 }
129
130 # get standard environment, filters and checks
131 . ./common.rc
132 . ./common.filter
133
134
135 # real QA test starts here
136 _supported_fs xfs
137 _supported_os Linux
138
139 [ "$USE_EXTERNAL" = yes ] && _notrun "Cannot xfs_copy with external devices"
140 [ -x /usr/sbin/xfs_copy ] || _notrun "xfs_copy binary not yet installed"
141
142 _require_scratch
143 _require_loop
144
145 _scratch_mkfs_xfs -dsize=41m | _filter_mkfs 2>/dev/null
146 _scratch_mount 2>/dev/null || _fail "initial scratch mount failed"
147
148 echo
149 echo === populating scratch device
150 _populate_scratch
151 umount $SCRATCH_MNT 2>/dev/null
152
153 echo
154 echo === copying scratch device to single target
155 xfs_copy $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, duplicate UUID
160 xfs_copy -d $SCRATCH_DEV $tmp.image | _filter_copy $tmp.image
161 _verify_copy $tmp.image $SCRATCH_DEV $SCRATCH_MNT
162
163 echo 
164 echo === copying scratch device to single target, large ro device
165 /sbin/mkfs.xfs -dfile,name=$tmp.source,size=100g | _filter_mkfs 2>/dev/null
166 rmdir $tmp.source_dir 2>/dev/null
167 mkdir $tmp.source_dir
168 mount -t xfs -o loop $tmp.source $tmp.source_dir
169 cp -a $here $tmp.source_dir
170 mount -t xfs -o remount,ro $tmp.source $tmp.source_dir
171 xfs_copy $tmp.source $tmp.image | _filter_copy $tmp.image
172 _verify_copy $tmp.image $tmp.source $tmp.source_dir
173
174 echo
175 echo === copying scratch device to multiple targets
176 xfs_copy -L$tmp.log -b $SCRATCH_DEV $tmp.image1 $tmp.image2 \
177         | _filter_copy $tmp.image1 $tmp.image2
178 _verify_copy $tmp.image1 $SCRATCH_DEV $SCRATCH_MNT
179 _verify_copy $tmp.image2 $SCRATCH_DEV $SCRATCH_MNT
180
181 # success, all done
182 status=0
183 exit