2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
7 # Test multiple redirects to the same lower dir.
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.
13 # This test checks that overlayfs detects and fails lookup of a multiply
16 # The check for multiply redirected dir was a by-product of kernel
17 # commit 31747eda41ef ("ovl: hash directory inodes for fsnotify")
20 seqres=$RESULT_DIR/$seq
21 echo "QA output created by $seq"
25 status=1 # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
34 # Rename lower dir to create a redirected upper dir and
35 # touch lower file to create copy up with origin xattr
40 mkdir -p $lowerdir/origin
41 touch $lowerdir/origin/file
43 _scratch_mount -o redirect_dir=on
44 touch $SCRATCH_MNT/origin/file
45 mv $SCRATCH_MNT/origin $SCRATCH_MNT/$redirect
47 $UMOUNT_PROG $SCRATCH_MNT
50 # get standard environment, filters and checks
56 # real QA test starts here
58 _require_scratch_nocheck
59 _require_scratch_feature redirect_dir
61 # remove all files from previous runs
64 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
65 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
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
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
79 _scratch_mount -o redirect_dir=on
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!"
86 diff -q $SCRATCH_MNT/redirect1 $SCRATCH_MNT/redirect2 &> /dev/null && \
87 echo "diff on duplicate redirect dirs doesn't know right from wrong!"
90 echo "Silence is golden"