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