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