xfs/049: umount -d fails when kernel wins teardown race
[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 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36
37 # don't put fs images in /tmp
38 imgs=$TEST_DIR/$$
39
40 _cleanup()
41 {
42         cd /
43         umount $SCRATCH_MNT 2>/dev/null
44         umount $imgs.loop 2>/dev/null
45         [ -d $imgs.loop ] && rmdir $imgs.loop
46         umount $imgs.source_dir 2>/dev/null
47         [ -d $imgs.source_dir ] && rm -rf $imgs.source_dir
48         rm -f $imgs.* $tmp.* /var/tmp/xfs_copy.log.*
49 }
50 trap "_cleanup; exit \$status" 0 1 2 3 15
51
52 _filter_copy()
53 {
54         sed -e "s,$1,<DEVIMAGE>,g" -e "s,$2,<FSIMAGE1>,g" \
55             -e "s,$3,<DEVIMAGE>,g" -e "s,$4,<FSIMAGE2>,g"
56 }
57
58 _filter_path()
59 {
60         sed -e "s,$1,<MNTPATH>,g" | LC_COLLATE=POSIX sort
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=$imgs.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 none none
84
85         echo mounting new image on loopback
86         rmdir $target_dir 2>/dev/null
87         mkdir $target_dir
88
89         mount -t xfs -o loop $target $target_dir 2>/dev/null
90         if [ $? -ne 0 ]; then
91                 echo retrying mount with nouuid option
92                 mount -t xfs -o loop -o nouuid $target $target_dir
93                 if [ $? -ne 0 ]; then
94                         echo mount failed - evil!
95                         return
96                 fi
97         fi
98
99         echo comparing new image files to old
100         diff -Naur $source_dir $target_dir
101
102         echo comparing new image directories to old
103         find $source_dir | _filter_path $source_dir > $tmp.manifest1
104         find $target_dir | _filter_path $target_dir > $tmp.manifest2
105         [ -s $tmp.manifest1 ] || echo no directory output
106         diff -u $tmp.manifest1 $tmp.manifest2
107
108         echo comparing new image geometry to old
109         xfs_info $source_dir \
110                 | _filter_copy $source $source_dir '/dev/loop.' '#' \
111                 | tr -s ' ' \
112                 > $tmp.geometry1
113         xfs_info $target_dir \
114                 | _filter_copy $target $target_dir '/dev/loop.' '#' \
115                 | tr -s ' ' \
116                 > $tmp.geometry2
117         [ -s $tmp.geometry1 ] || echo no geometry output
118         diff -u $tmp.geometry1 $tmp.geometry2
119
120         echo unmounting and removing new image
121         umount $source_dir
122         umount $target_dir > /dev/null 2>&1
123         rm -f $target
124 }
125
126 # real QA test starts here
127 _supported_fs xfs
128 _supported_os Linux
129 _require_test
130
131 [ "$USE_EXTERNAL" = yes ] && _notrun "Cannot xfs_copy with external devices"
132 [ -n "$XFS_COPY_PROG" ] || _notrun "xfs_copy binary not yet installed"
133
134 _require_scratch
135 _require_loop
136
137 rm -f $seqres.full
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_XFS_PROG} -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