overlay: add a test for multiple redirects to the same lower dir
authorAmir Goldstein <amir73il@gmail.com>
Sun, 28 Jan 2018 09:07:30 +0000 (11:07 +0200)
committerEryu Guan <eguan@redhat.com>
Mon, 29 Jan 2018 10:08:00 +0000 (18:08 +0800)
Multiple redirects to the same lower dir will falsely return the
same st_ino/st_dev for two different upper dirs and will cause
'diff' to falsely report that content of directories is the same
when it is not.

This test checks that overalyfs detects and fails lookup of a
multiply redirected dir.

The check for multiply redirected dir was implemented by kernel
commit titled "ovl: hash directory inodes for fsnotify".

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
tests/overlay/049 [new file with mode: 0755]
tests/overlay/049.out [new file with mode: 0644]
tests/overlay/group

diff --git a/tests/overlay/049 b/tests/overlay/049
new file mode 100755 (executable)
index 0000000..ef00138
--- /dev/null
@@ -0,0 +1,109 @@
+#! /bin/bash
+# FS QA Test 049
+#
+# Test multiple redirects to the same lower dir.
+#
+# Multiple redirects to the same lower dir will falsely return the same
+# st_ino/st_dev for two different upper dirs and will cause 'diff' to
+# falsely report that content of directories is the same when it is not.
+#
+# This test checks that overlayfs detects and fails lookup of a multiply
+# redirected dir.
+#
+# The check for multiply redirected dir was implemented by kernel titled
+# "ovl: hash directory inodes for fsnotify"
+#
+#-----------------------------------------------------------------------
+# Copyright (C) 2018 CTERA Networks. All Rights Reserved.
+# Author: Amir Goldstein <amir73il@gmail.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+}
+
+# Rename lower dir to create a redirected upper dir and
+# touch lower file to create copy up with origin xattr
+create_redirect()
+{
+       local redirect=$1
+
+       mkdir -p $lowerdir/origin
+       touch $lowerdir/origin/file
+
+       _scratch_mount -o redirect_dir=on
+       touch $SCRATCH_MNT/origin/file
+       mv $SCRATCH_MNT/origin $SCRATCH_MNT/$redirect
+
+       $UMOUNT_PROG $SCRATCH_MNT
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs overlay
+_supported_os Linux
+_require_scratch
+_require_scratch_feature redirect_dir
+
+# remove all files from previous runs
+_scratch_mkfs
+
+upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
+lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
+
+# Create redirected dir with copied up file
+create_redirect redirect1
+# Duplicate the redirected dir and copied up file
+cp -a $upperdir/redirect1 $upperdir/redirect2
+
+# Diverge the content of the two copies of file
+# and the content of two copies of redirected dir
+echo right >> $upperdir/redirect1/file
+touch $upperdir/redirect1/right
+echo wrong >> $upperdir/redirect2/file
+touch $upperdir/redirect2/wrong
+
+_scratch_mount -o redirect_dir=on
+
+# If both copies of file/dir use the same st_dev/st_ino in overlay
+# diff won't detect that their content differs
+diff -q $SCRATCH_MNT/redirect1/file $SCRATCH_MNT/redirect2/file &>/dev/null && \
+       echo "diff on files inside duplicate redirect parent doesn't know right from wrong!"
+
+diff -q $SCRATCH_MNT/redirect1 $SCRATCH_MNT/redirect2 &> /dev/null && \
+       echo "diff on duplicate redirect dirs doesn't know right from wrong!"
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/overlay/049.out b/tests/overlay/049.out
new file mode 100644 (file)
index 0000000..c69568a
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 049
+Silence is golden
index edea64aa3230cd550524397373a83d72f494669b..4e138b980d0e99053dc887a836b8b41598fc62c7 100644 (file)
@@ -49,3 +49,4 @@
 044 auto quick copyup hardlink nonsamefs
 047 auto quick copyup hardlink
 048 auto quick copyup hardlink
 044 auto quick copyup hardlink nonsamefs
 047 auto quick copyup hardlink
 048 auto quick copyup hardlink
+049 auto quick copyup redirect