overlay/075: fix wrong invocation of t_immutable
[xfstests-dev.git] / tests / overlay / 049
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test 049
6 #
7 # Test multiple redirects to the same lower dir.
8 #
9 # Multiple redirects to the same lower dir will falsely return the same
10 # st_ino/st_dev for two different upper dirs and will cause 'diff' to
11 # falsely report that content of directories is the same when it is not.
12 #
13 # This test checks that overlayfs detects and fails lookup of a multiply
14 # redirected dir.
15 #
16 # The check for multiply redirected dir was a by-product of kernel
17 # commit 31747eda41ef ("ovl: hash directory inodes for fsnotify")
18 #
19 seq=`basename $0`
20 seqres=$RESULT_DIR/$seq
21 echo "QA output created by $seq"
22
23 here=`pwd`
24 tmp=/tmp/$$
25 status=1        # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
27
28 _cleanup()
29 {
30         cd /
31         rm -f $tmp.*
32 }
33
34 # Rename lower dir to create a redirected upper dir and
35 # touch lower file to create copy up with origin xattr
36 create_redirect()
37 {
38         local redirect=$1
39
40         mkdir -p $lowerdir/origin
41         touch $lowerdir/origin/file
42
43         _scratch_mount -o redirect_dir=on
44         touch $SCRATCH_MNT/origin/file
45         mv $SCRATCH_MNT/origin $SCRATCH_MNT/$redirect
46
47         $UMOUNT_PROG $SCRATCH_MNT
48 }
49
50 # get standard environment, filters and checks
51 . ./common/rc
52 . ./common/filter
53
54 rm -f $seqres.full
55
56 # real QA test starts here
57 _supported_fs overlay
58 _require_scratch_nocheck
59 _require_scratch_feature redirect_dir
60
61 # remove all files from previous runs
62 _scratch_mkfs
63
64 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
65 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
66
67 # Create redirected dir with copied up file
68 create_redirect redirect1
69 # Duplicate the redirected dir and copied up file
70 cp -a $upperdir/redirect1 $upperdir/redirect2
71
72 # Diverge the content of the two copies of file
73 # and the content of two copies of redirected dir
74 echo right >> $upperdir/redirect1/file
75 touch $upperdir/redirect1/right
76 echo wrong >> $upperdir/redirect2/file
77 touch $upperdir/redirect2/wrong
78
79 _scratch_mount -o redirect_dir=on
80
81 # If both copies of file/dir use the same st_dev/st_ino in overlay
82 # diff won't detect that their content differs
83 diff -q $SCRATCH_MNT/redirect1/file $SCRATCH_MNT/redirect2/file &>/dev/null && \
84         echo "diff on files inside duplicate redirect parent doesn't know right from wrong!"
85
86 diff -q $SCRATCH_MNT/redirect1 $SCRATCH_MNT/redirect2 &> /dev/null && \
87         echo "diff on duplicate redirect dirs doesn't know right from wrong!"
88
89 # success, all done
90 echo "Silence is golden"
91 status=0
92 exit