This change makes test 041 function correctly other blocks sizes, not just 4096.
[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 #
10 # creator
11 owner=nathans@sgi.com
12
13 seq=`basename $0`
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 _cleanup()
20 {
21         cd /
22         umount $SCRATCH_MNT 2>/dev/null
23         umount $tmp.loop 2>/dev/null
24         [ -d $tmp.loop ] && rmdir $tmp.loop
25         [ -d $tmp.source_dir ] && rmdir $tmp.source_dir
26         rm -f $tmp.* /var/tmp/xfs_copy.log.*
27 }
28 trap "_cleanup; exit \$status" 0 1 2 3 15
29
30 _filter_copy()
31 {
32         sed -e "s,$1,<DEVIMAGE>,g" -e "s,$2,<FSIMAGE1>,g" \
33             -e "s,$3,<DEVIMAGE>,g" -e "s,$4,<FSIMAGE2>,g"
34 }
35
36 _filter_path()
37 {
38         sed -e "s,$1,<MNTPATH>,g" | LC_COLLATE=POSIX sort
39 }
40
41 _populate_scratch()
42 {
43         POSIXLY_CORRECT=yes \
44                 dd if=/dev/zero of=$SCRATCH_MNT/big+attr count=1000 bs=4096
45         [ "$FAST_POPULATE" = true ] && return
46         echo $SCRATCH_MNT/big+attr | $here/src/fill2attr
47         $here/src/fill2fs --bytes=1048576 --filesize=4096 --stddev=0 --force \
48                 --dir=$SCRATCH_MNT/fill --list=- > $tmp.manifest
49 }
50
51 _verify_copy()
52 {
53         target=$1
54         target_dir=$tmp.loop
55         source=$2
56         source_dir=$3
57
58         [ $source = $SCRATCH_DEV ] && _scratch_mount
59
60         echo checking new image
61         _check_xfs_filesystem $target none none
62
63         echo mounting new image on loopback
64         rmdir $target_dir 2>/dev/null
65         mkdir $target_dir
66         mount -t xfs -o loop $target $target_dir 2>/dev/null
67         if [ $? -ne 0 ]; then
68                 echo retrying mount with nouuid option
69                 mount -t xfs -o loop -o nouuid $target $target_dir
70                 if [ $? -ne 0 ]; then
71                         echo mount failed - evil!
72                         return
73                 fi
74         fi
75
76         echo comparing new image files to old
77         diff -Naur $source_dir $target_dir
78
79         echo comparing new image directories to old
80         find $source_dir | _filter_path $source_dir > $tmp.manifest1
81         find $target_dir | _filter_path $target_dir > $tmp.manifest2
82         [ -s $tmp.manifest1 ] || echo no directory output
83         diff -u $tmp.manifest1 $tmp.manifest2
84
85         echo comparing new image geometry to old
86         xfs_info $source_dir \
87                 | _filter_copy $source $source_dir '/dev/loop.' '#' \
88                 | tr -s ' ' \
89                 > $tmp.geometry1
90         xfs_info $target_dir \
91                 | _filter_copy $target $target_dir '/dev/loop.' '#' \
92                 | tr -s ' ' \
93                 > $tmp.geometry2
94         [ -s $tmp.geometry1 ] || echo no geometry output
95         diff -u $tmp.geometry1 $tmp.geometry2
96
97         echo unmounting and removing new image
98         umount $source $target
99         rm -f $target
100 }
101
102 # get standard environment, filters and checks
103 . ./common.rc
104 . ./common.filter
105
106
107 # real QA test starts here
108 _supported_fs xfs
109 _supported_os Linux
110
111 [ "$USE_EXTERNAL" = yes ] && _notrun "Cannot xfs_copy with external devices"
112 [ -x /usr/sbin/xfs_copy ] || _notrun "xfs_copy binary not yet installed"
113
114 _require_scratch
115 _require_loop
116
117 MKFS_OPTIONS="" #ignore external MKFS_OPTIONS
118 _scratch_mkfs_xfs -dsize=41m,agcount=2 | _filter_mkfs 2>/dev/null
119 _scratch_mount 2>/dev/null || _fail "initial scratch mount failed"
120
121 echo
122 echo === populating scratch device
123 _populate_scratch
124 umount $SCRATCH_MNT 2>/dev/null
125
126 echo
127 echo === copying scratch device to single target
128 xfs_copy $SCRATCH_DEV $tmp.image | _filter_copy '#' $tmp.image '#' '#'
129 _verify_copy $tmp.image $SCRATCH_DEV $SCRATCH_MNT
130
131 echo
132 echo === copying scratch device to single target, duplicate UUID
133 xfs_copy -d $SCRATCH_DEV $tmp.image | _filter_copy '#' $tmp.image '#' '#'
134 _verify_copy $tmp.image $SCRATCH_DEV $SCRATCH_MNT
135
136 echo 
137 echo === copying scratch device to single target, large ro device
138 /sbin/mkfs.xfs -dfile,name=$tmp.source,size=100g | _filter_mkfs 2>/dev/null
139 rmdir $tmp.source_dir 2>/dev/null
140 mkdir $tmp.source_dir
141 mount -t xfs -o loop $tmp.source $tmp.source_dir
142 cp -a $here $tmp.source_dir
143 mount -t xfs -o remount,ro $tmp.source $tmp.source_dir
144 xfs_copy $tmp.source $tmp.image | _filter_copy '#' $tmp.image '#' '#'
145 _verify_copy $tmp.image $tmp.source $tmp.source_dir
146
147 echo
148 echo === copying scratch device to multiple targets
149 xfs_copy -L$tmp.log -b $SCRATCH_DEV $tmp.image1 $tmp.image2 \
150         | _filter_copy '#' $tmp.image1 '#' $tmp.image2
151 _verify_copy $tmp.image1 $SCRATCH_DEV $SCRATCH_MNT
152 _verify_copy $tmp.image2 $SCRATCH_DEV $SCRATCH_MNT
153
154 # success, all done
155 status=0
156 exit