4 # Test metadata only copy up functionality.
6 #-----------------------------------------------------------------------
7 # Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
30 status=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
43 # remove previous $seqres.full before test
46 # real QA test starts here
49 # We use non-default scratch underlying overlay dirs, we need to check
50 # them explicity after test.
51 _require_scratch_nocheck
52 _require_scratch_overlay_features index redirect_dir metacopy
54 # remove all files from previous tests
59 lowerlink="lowerfile-link"
63 # Number of blocks allocated by filesystem on lower. Will be queried later.
69 # Check metacopy xattr
72 local target=$1 exist=$2
76 out_f=$($GETFATTR_PROG --absolute-names --only-values -n \
77 $OVL_XATTR_METACOPY $target 2>&1 | _filter_scratch)
79 if [ "$exist" == "y" ];then
80 [ "$out_f" == "" ] && return
81 echo "Metacopy xattr does not exist on ${target}. stdout=$out_f"
85 if [ "$out_f" == "" ];then
86 echo "Metacopy xattr exists on ${target} unexpectedly."
90 target_f=`echo $target | _filter_scratch`
91 msg="$target_f: trusted.overlay.metacopy: No such attribute"
93 [ "$out_f" == "$msg" ] && return
95 echo "Error while checking xattr on ${target}. stdout=$out"
98 # Check redirect xattr
104 value=$($GETFATTR_PROG --absolute-names --only-values -n \
105 $OVL_XATTR_REDIRECT $target)
107 [[ "$value" == "$expect" ]] || echo "Redirect xattr incorrect. Expected=\"$expect\", actual=\"$value\""
113 local target=$1 expected_size=$2 actual_size
115 actual_size=$(stat -c "%s" $target)
117 [ "$actual_size" == "$expected_size" ] || echo "Expected file size $expected_size but actual size is $actual_size"
122 local target=$1 expected_blocks=$2 nr_blocks
124 nr_blocks=$(stat -c "%b" $target)
126 [ "$nr_blocks" == "$expected_blocks" ] || echo "Expected $expected_blocks blocks but actual number of blocks is ${nr_blocks}."
129 check_file_contents()
131 local target=$1 expected=$2
132 local actual target_f
134 target_f=`echo $target | _filter_scratch`
138 [ "$actual" == "$expected" ] || echo "Expected file $target_f contents to be \"$expected\" but actual contents are \"$actual\""
141 check_file_size_contents()
143 local target=$1 expected_size=$2 expected_content=$3
145 check_file_size $target $expected_size
146 check_file_contents $target $expected_content
153 _overlay_scratch_mount_dirs "$_lowerdir" $upperdir $workdir -o redirect_dir=on,index=on,metacopy=on
158 $UMOUNT_PROG $SCRATCH_MNT
161 # Assumes it is called with overlay mounted.
164 local _lowerdir=$1 _target=$2 _size=$3 _blocks=$4 _data="$5"
167 echo "check properties of metadata copied up file"
168 check_file_size_contents $SCRATCH_MNT/$_target $_size "$_data"
169 check_file_blocks $SCRATCH_MNT/$_target $_blocks
171 # Do a mount cycle and check size and contents again.
172 echo "Unmount and Mount again"
174 mount_overlay $_lowerdir
175 echo "check properties of metadata copied up file"
176 check_file_size_contents $SCRATCH_MNT/$_target $_size "$_data"
177 check_file_blocks $SCRATCH_MNT/$_target $_blocks
179 # Make sure copied up file is a metacopy file.
181 check_metacopy $upperdir/$_target "y"
182 check_file_size_contents $upperdir/$_target $_size ""
183 [ -n "$_redirect" ] && check_redirect $upperdir/$_target "$_redirect"
185 # Trigger data copy up and check absence of metacopy xattr.
186 mount_overlay $_lowerdir
187 $XFS_IO_PROG -c "open -a $SCRATCH_MNT/$_target"
188 echo "check properties of data copied up file"
189 check_file_size_contents $SCRATCH_MNT/$_target $_size "$_data"
191 check_metacopy $upperdir/$_target "n"
192 check_file_size_contents $upperdir/$_target $_size "$_data"
198 mkdir -p $lowerdir $lowerdir2 $upperdir $workdir $workdir2
199 mkdir -p $upperdir/$udirname
200 echo "$lowerdata" > $lowerdir/$lowername
201 chmod 600 $lowerdir/$lowername
202 # Create a file of size lowersize.
203 $XFS_IO_PROG -c "falloc 0 $lowersize" $lowerdir/$lowername
204 $XFS_IO_PROG -c "fsync" $lowerdir/$lowername
206 # Query number of lower
207 lowerblocks=$(stat -c "%b" $lowerdir/$lowername)
212 ln $lowerdir/$lowername $lowerdir/$lowerlink
220 _overlay_scratch_mount_dirs $lowerdir $lowerdir2 $workdir2 -o redirect_dir=on,index=on,metacopy=on
222 chmod 400 $SCRATCH_MNT/$lowername
226 # Create test directories
227 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
228 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
229 upperdir=$OVL_BASE_SCRATCH_MNT/upper
230 workdir=$OVL_BASE_SCRATCH_MNT/workdir
231 workdir2=$OVL_BASE_SCRATCH_MNT/workdir2
234 echo "== Check Simple Metacopy =="
236 mount_overlay $lowerdir
237 chmod 400 $SCRATCH_MNT/$lowername
238 test_common $lowerdir $lowername $lowersize $lowerblocks "$lowerdata"
240 # Test midlayer metacopy
241 echo -e "\n== Check Midlayer Metacopy =="
243 mount_overlay "$lowerdir2:$lowerdir"
244 chmod 400 $SCRATCH_MNT/$lowername
245 test_common "$lowerdir2:$lowerdir" $lowername $lowersize $lowerblocks \
248 # Test Rename Redirect
249 echo -e "\n== Check Rename Redirect =="
251 mount_overlay $lowerdir
252 mv $SCRATCH_MNT/$lowername $SCRATCH_MNT/$ufile
253 test_common $lowerdir $ufile $lowersize $lowerblocks "$lowerdata" "$lowername"
255 # Test midlayer rename redirect
256 echo -e "\n== Check Midlayer Rename Redirect =="
258 mount_overlay "$lowerdir2:$lowerdir"
259 mv $SCRATCH_MNT/$lowername $SCRATCH_MNT/$ufile
260 test_common "$lowerdir2:$lowerdir" $ufile $lowersize $lowerblocks "$lowerdata" \
264 echo -e "\n== Check Link Redirect =="
266 mount_overlay $lowerdir
267 ln $SCRATCH_MNT/$lowername $SCRATCH_MNT/$udirname/$ufile
268 test_common $lowerdir $udirname/$ufile $lowersize $lowerblocks "$lowerdata" \
271 # Test midlayer link redirect
272 echo -e "\n== Check Midlayer Link Redirect =="
274 mount_overlay "$lowerdir2:$lowerdir"
275 ln $SCRATCH_MNT/$lowername $SCRATCH_MNT/$udirname/$ufile
276 test_common "$lowerdir2:$lowerdir" $udirname/$ufile $lowersize $lowerblocks \
277 "$lowerdata" "/$lowername"
279 # Test lower link file gets absolute redirect upon rename
280 echo -e "\n== Check Lower Link Rename Absolute Redirect =="
283 mount_overlay $lowerdir
284 mv $SCRATCH_MNT/$lowerlink $SCRATCH_MNT/$ufile
285 test_common $lowerdir $ufile $lowersize $lowerblocks "$lowerdata" "/$lowerlink"