fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 073
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2003,2008 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 073
6 #
7 # Test xfs_copy
8 #
9 . ./common/preamble
10 _begin_fstest copy auto
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/attr
15
16 # don't put fs images in /tmp
17 imgs=$TEST_DIR/$$
18
19 # Override the default cleanup function.
20 _cleanup()
21 {
22         cd /
23         _scratch_unmount 2>/dev/null
24         umount $imgs.loop 2>/dev/null
25         [ -d $imgs.loop ] && rmdir $imgs.loop
26         umount $imgs.source_dir 2>/dev/null
27         [ -d $imgs.source_dir ] && rm -rf $imgs.source_dir
28         rm -f $imgs.* $tmp.* /var/tmp/xfs_copy.log.*
29 }
30
31 _filter_copy()
32 {
33         sed -e "s,$1,<DEVIMAGE>,g" -e "s,$2,<FSIMAGE1>,g" \
34             -e "s,$3,<DEVIMAGE>,g" -e "s,$4,<FSIMAGE2>,g"
35 }
36
37 _filter_path()
38 {
39         sed -e "s,$1,<MNTPATH>,g" | LC_COLLATE=POSIX sort
40 }
41
42 _populate_scratch()
43 {
44         POSIXLY_CORRECT=yes \
45                 dd if=/dev/zero of=$SCRATCH_MNT/big+attr count=1000 bs=4096
46         [ "$FAST_POPULATE" = true ] && return
47         echo $SCRATCH_MNT/big+attr | $here/src/fill2attr
48         $here/src/fill2fs --bytes=1048576 --filesize=4096 --stddev=0 --force \
49                 --dir=$SCRATCH_MNT/fill --list=- > $tmp.manifest
50 }
51
52 _verify_copy()
53 {
54         target=$1
55         target_dir=$imgs.loop
56         source=$2
57         source_dir=$3
58
59         [ $source = $SCRATCH_DEV ] && _scratch_mount
60
61         echo checking new image
62         _check_xfs_filesystem $target none none
63
64         echo mounting new image on loopback
65         rmdir $target_dir 2>/dev/null
66         mkdir $target_dir
67
68         mount -t xfs -o loop $target $target_dir 2>/dev/null
69         if [ $? -ne 0 ]; then
70                 echo retrying mount with nouuid option >>$seqres.full
71                 mount -t xfs -o loop -o nouuid $target $target_dir
72                 if [ $? -ne 0 ]; then
73                         echo mount failed - evil!
74                         return
75                 fi
76         fi
77
78         echo comparing new image files to old
79         diff -Naur $source_dir $target_dir
80
81         echo comparing new image directories to old
82         find $source_dir | _filter_path $source_dir > $tmp.manifest1
83         find $target_dir | _filter_path $target_dir > $tmp.manifest2
84         [ -s $tmp.manifest1 ] || echo no directory output
85         diff -u $tmp.manifest1 $tmp.manifest2
86
87         echo comparing new image geometry to old
88         $XFS_INFO_PROG $source_dir \
89                 | _filter_copy $source $source_dir '/dev/loop.' '#' \
90                 | tr -s ' ' \
91                 > $tmp.geometry1
92         $XFS_INFO_PROG $target_dir \
93                 | _filter_copy $target $target_dir '/dev/loop.' '#' \
94                 | tr -s ' ' \
95                 > $tmp.geometry2
96         [ -s $tmp.geometry1 ] || echo no geometry output
97         diff -u $tmp.geometry1 $tmp.geometry2
98
99         echo unmounting and removing new image
100         umount $source_dir
101         umount $target_dir > /dev/null 2>&1
102         rm -f $target
103 }
104
105 # real QA test starts here
106 _supported_fs xfs
107 _require_test
108 _require_attrs
109 _require_xfs_copy
110 _require_scratch
111 _require_loop
112
113 _scratch_mkfs_xfs -dsize=41m,agcount=2 >>$seqres.full 2>&1
114 _scratch_mount
115
116 echo
117 echo === populating scratch device
118 _populate_scratch
119 _scratch_unmount 2>/dev/null
120
121 echo
122 echo === copying scratch device to single target
123 $XFS_COPY_PROG $SCRATCH_DEV $imgs.image | _filter_copy '#' $imgs.image '#' '#'
124 _verify_copy $imgs.image $SCRATCH_DEV $SCRATCH_MNT
125
126 echo
127 echo === copying scratch device to single target, duplicate UUID
128 $XFS_COPY_PROG -d $SCRATCH_DEV $imgs.image | _filter_copy '#' $imgs.image '#' '#'
129 _verify_copy $imgs.image $SCRATCH_DEV $SCRATCH_MNT
130
131 echo 
132 echo === copying scratch device to single target, large ro device
133 ${MKFS_XFS_PROG} -dfile,name=$imgs.source,size=100g \
134         | _filter_mkfs 2>/dev/null
135 rmdir $imgs.source_dir 2>/dev/null
136 mkdir $imgs.source_dir
137
138 mount -t xfs -o loop $imgs.source $imgs.source_dir
139 loop2=`mount | grep $imgs.source | grep -o -e 'loop=.*[^),]' | grep -o -e '/.*$'`
140 cp -a $here $imgs.source_dir
141 mount -t xfs -o remount,ro $imgs.source $imgs.source_dir
142 $XFS_COPY_PROG $imgs.source $imgs.image | _filter_copy '#' $imgs.image '#' '#'
143 _verify_copy $imgs.image $imgs.source $imgs.source_dir
144
145 # HACK WARNING:
146 #
147 # We're done with the nested loop mount, now we have to clean
148 # up the pieces that mount is incapable of doing.
149 losetup -d $loop2 > /dev/null 2>&1
150
151 echo
152 echo === copying scratch device to multiple targets
153 $XFS_COPY_PROG -L$imgs.log -b $SCRATCH_DEV $imgs.image1 $imgs.image2 \
154         | _filter_copy '#' $imgs.image1 '#' $imgs.image2
155 _verify_copy $imgs.image1 $SCRATCH_DEV $SCRATCH_MNT
156 _verify_copy $imgs.image2 $SCRATCH_DEV $SCRATCH_MNT
157
158 # success, all done
159 status=0
160 exit