overlay/029: fix test failure with nfs_export feature enabled
[xfstests-dev.git] / tests / overlay / 057
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 057
6 #
7 # Test absolute redirect is followed even if ancestor is opaque
8 #
9 # Typically, when following absolute redirect, if an opauqe dentry is
10 # found, lookup in further lower directories is stopped. But if a
11 # child dentry has another absolute redirect, then lookup in further
12 # lower layers should continue.
13 #
14 # Say, following is example setup.
15 # upper:  /redirect (redirect=/a/b/c)
16 # lower1: /a/[b]/c       ([b] is opaque) (c has absolute redirect=/a/b/d/)
17 # lower0: /a/b/d/foo
18 #
19 # "redirect" directory in upper should merge with lower1:/a/b/c/ and
20 # lower0:/a/b/d/, despite lower1:/a/b/ being opaque.
21 #
22 seq=`basename $0`
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
25
26 here=`pwd`
27 tmp=/tmp/$$
28 status=1        # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
30
31 _cleanup()
32 {
33         cd /
34         rm -f $tmp.*
35 }
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40
41 # remove previous $seqres.full before test
42 rm -f $seqres.full
43
44 # real QA test starts here
45 _supported_fs overlay
46 _supported_os Linux
47 # We use non-default scratch underlying overlay dirs, we need to check
48 # them explicity after test.
49 _require_scratch_nocheck
50 _require_scratch_overlay_features redirect_dir
51
52 # remove all files from previous tests
53 _scratch_mkfs
54
55 # Create test directories
56 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
57 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
58 upperdir=$OVL_BASE_SCRATCH_MNT/upper
59 workdir=$OVL_BASE_SCRATCH_MNT/workdir
60 workdir2=$OVL_BASE_SCRATCH_MNT/workdir2
61
62 mkdir -p $lowerdir $lowerdir2 $upperdir $workdir $workdir2
63 mkdir -p $lowerdir/origin
64 touch $lowerdir/origin/foo
65 _overlay_scratch_mount_dirs $lowerdir $lowerdir2 $workdir2 -o redirect_dir=on
66
67 # Create opaque parent with absolute redirect child in middle layer
68 mkdir $SCRATCH_MNT/pure
69 mv $SCRATCH_MNT/origin $SCRATCH_MNT/pure/redirect
70 $UMOUNT_PROG $SCRATCH_MNT
71 _overlay_scratch_mount_dirs $lowerdir2:$lowerdir $upperdir $workdir -o redirect_dir=on
72 mv $SCRATCH_MNT/pure/redirect $SCRATCH_MNT/redirect
73 # List content of renamed merge dir before mount cycle
74 ls $SCRATCH_MNT/redirect/
75
76 # Verify that redirects are followed by listing content of renamed merge dir
77 # after mount cycle
78 $UMOUNT_PROG $SCRATCH_MNT
79 _overlay_scratch_mount_dirs $lowerdir2:$lowerdir $upperdir $workdir -o redirect_dir=on
80 ls $SCRATCH_MNT/redirect/
81
82 # check overlayfs
83 _overlay_check_scratch_dirs "$lowerdir2:$lowerdir" $upperdir $workdir -o redirect_dir=on
84
85 # success, all done
86 status=0
87 exit