diff mbox series

[2/2] overlay: Test invalidate of readdir cache

Message ID 20210421092317.68716-3-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show
Series Test overlayfs readdir cache | expand

Commit Message

Amir Goldstein April 21, 2021, 9:23 a.m. UTC
This is a regression test for kernel commit 65cd913ec9d9
("ovl: invalidate readdir cache on changes to dir with origin")

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 tests/overlay/077     | 105 ++++++++++++++++++++++++++++++++++++++++++
 tests/overlay/077.out |   2 +
 tests/overlay/group   |   1 +
 3 files changed, 108 insertions(+)
 create mode 100755 tests/overlay/077
 create mode 100644 tests/overlay/077.out

Comments

Amir Goldstein April 21, 2021, 9:33 a.m. UTC | #1
On Wed, Apr 21, 2021 at 12:23 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> This is a regression test for kernel commit 65cd913ec9d9
> ("ovl: invalidate readdir cache on changes to dir with origin")
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  tests/overlay/077     | 105 ++++++++++++++++++++++++++++++++++++++++++
>  tests/overlay/077.out |   2 +
>  tests/overlay/group   |   1 +
>  3 files changed, 108 insertions(+)
>  create mode 100755 tests/overlay/077
>  create mode 100644 tests/overlay/077.out
>
> diff --git a/tests/overlay/077 b/tests/overlay/077
> new file mode 100755
> index 00000000..e254aec1
> --- /dev/null
> +++ b/tests/overlay/077
> @@ -0,0 +1,105 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2021 CTERA Networks. All Rights Reserved.
> +#
> +# FS QA Test 077
> +#
> +# Test invalidate of readdir cache
> +#
> +# This is a regression test for kernel commit 65cd913ec9d9
> +# ("ovl: invalidate readdir cache on changes to dir with origin")
> +#
> +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.*
> +}
> +
> +# create test directory and test file, mount overlayfs and remove
> +# testfile to create a whiteout in upper dir.
> +create_whiteout()
> +{
> +       local lower=$1
> +       local upper=$2
> +       local work=$3
> +       local file=$4
> +
> +       mkdir -p $lower/testdir
> +       touch $lower/testdir/$file
> +
> +       _overlay_scratch_mount_dirs $lower $upper $work
> +
> +       rm -f $SCRATCH_MNT/testdir/$file
> +
> +       $UMOUNT_PROG $SCRATCH_MNT
> +}
> +

Oops. Unused leftover.
A former merge dir does not need to actually have whiteouts for this test...

Thanks,
Amir.
Amir Goldstein April 22, 2021, 6:23 a.m. UTC | #2
On Wed, Apr 21, 2021 at 12:33 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Wed, Apr 21, 2021 at 12:23 PM Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > This is a regression test for kernel commit 65cd913ec9d9
> > ("ovl: invalidate readdir cache on changes to dir with origin")
> >
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > ---
> >  tests/overlay/077     | 105 ++++++++++++++++++++++++++++++++++++++++++
> >  tests/overlay/077.out |   2 +
> >  tests/overlay/group   |   1 +
> >  3 files changed, 108 insertions(+)
> >  create mode 100755 tests/overlay/077
> >  create mode 100644 tests/overlay/077.out
> >
> > diff --git a/tests/overlay/077 b/tests/overlay/077
> > new file mode 100755
> > index 00000000..e254aec1
> > --- /dev/null
> > +++ b/tests/overlay/077
> > @@ -0,0 +1,105 @@
> > +#! /bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +# Copyright (C) 2021 CTERA Networks. All Rights Reserved.
> > +#
> > +# FS QA Test 077
> > +#
> > +# Test invalidate of readdir cache
> > +#
> > +# This is a regression test for kernel commit 65cd913ec9d9
> > +# ("ovl: invalidate readdir cache on changes to dir with origin")
> > +#
> > +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.*
> > +}
> > +
> > +# create test directory and test file, mount overlayfs and remove
> > +# testfile to create a whiteout in upper dir.
> > +create_whiteout()
> > +{
> > +       local lower=$1
> > +       local upper=$2
> > +       local work=$3
> > +       local file=$4
> > +
> > +       mkdir -p $lower/testdir
> > +       touch $lower/testdir/$file
> > +
> > +       _overlay_scratch_mount_dirs $lower $upper $work
> > +
> > +       rm -f $SCRATCH_MNT/testdir/$file
> > +
> > +       $UMOUNT_PROG $SCRATCH_MNT
> > +}
> > +
>
> Oops. Unused leftover.
> A former merge dir does not need to actually have whiteouts for this test...
>

But it would be better for test coverage if the merge dir had copied up
files on first readdir (making it "impure").

And I will also add the "upper impure" test case in V2 posting.

Thanks,
Amir.
diff mbox series

Patch

diff --git a/tests/overlay/077 b/tests/overlay/077
new file mode 100755
index 00000000..e254aec1
--- /dev/null
+++ b/tests/overlay/077
@@ -0,0 +1,105 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021 CTERA Networks. All Rights Reserved.
+#
+# FS QA Test 077
+#
+# Test invalidate of readdir cache
+#
+# This is a regression test for kernel commit 65cd913ec9d9
+# ("ovl: invalidate readdir cache on changes to dir with origin")
+#
+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.*
+}
+
+# create test directory and test file, mount overlayfs and remove
+# testfile to create a whiteout in upper dir.
+create_whiteout()
+{
+	local lower=$1
+	local upper=$2
+	local work=$3
+	local file=$4
+
+	mkdir -p $lower/testdir
+	touch $lower/testdir/$file
+
+	_overlay_scratch_mount_dirs $lower $upper $work
+
+	rm -f $SCRATCH_MNT/testdir/$file
+
+	$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
+_require_scratch_nocheck
+
+# remove all files from previous runs
+_scratch_mkfs
+
+# Create test area with a merge dir, a "former" merge dir and
+# a pure upper dir
+lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
+upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
+
+mkdir -p $lowerdir/merge $lowerdir/former $upperdir/pure
+touch $lowerdir/merge/{a,b,c}
+
+_scratch_mount
+
+touch $SCRATCH_MNT/pure/{a,b,c}
+touch $SCRATCH_MNT/former/{a,b,c}
+
+# Remove the lower directory and mount overlay again to create
+# a "former merge dir"
+$UMOUNT_PROG $SCRATCH_MNT
+rm -rf $lowerdir/former
+_scratch_mount
+
+# Check readdir cache invalidate on pure upper dir
+echo "Create file in pure upper dir:" >> $seqres.full
+$here/src/t_dir_offset2 $SCRATCH_MNT/pure A 2>&1 >> $seqres.full || \
+	echo "Missing created file in pure upper dir (see $seqres.full for details)"
+echo "Remove files in pure upper dir:" >> $seqres.full
+$here/src/t_dir_offset2 $SCRATCH_MNT/pure -u 2>&1 >> $seqres.full || \
+	echo "Found unlinked files in pure upper dir (see $seqres.full for details)"
+
+# Check readdir cache invalidate on merge dir
+echo "Create file in merge dir:" >> $seqres.full
+$here/src/t_dir_offset2 $SCRATCH_MNT/merge A 2>&1 >> $seqres.full || \
+	echo "Missing created file in merge dir (see $seqres.full for details)"
+echo "Remove files in merge dir:" >> $seqres.full
+$here/src/t_dir_offset2 $SCRATCH_MNT/merge -u 2>&1 >> $seqres.full || \
+	echo "Found unlinked files in merge dir (see $seqres.full for details)"
+
+# Check readdir cache invalidate on former merge dir
+echo "Create file in former merge dir:" >> $seqres.full
+$here/src/t_dir_offset2 $SCRATCH_MNT/former A 2>&1 >> $seqres.full || \
+	echo "Missing created file in former merge dir (see $seqres.full for details)"
+echo "Remove files in former merge dir:" >> $seqres.full
+$here/src/t_dir_offset2 $SCRATCH_MNT/former -u 2>&1 >> $seqres.full || \
+	echo "Found unlinked files in former merge dir (see $seqres.full for details)"
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/overlay/077.out b/tests/overlay/077.out
new file mode 100644
index 00000000..11538276
--- /dev/null
+++ b/tests/overlay/077.out
@@ -0,0 +1,2 @@ 
+QA output created by 077
+Silence is golden
diff --git a/tests/overlay/group b/tests/overlay/group
index ddc355e5..a8f98789 100644
--- a/tests/overlay/group
+++ b/tests/overlay/group
@@ -79,6 +79,7 @@ 
 074 auto quick exportfs dangerous
 075 auto quick perms
 076 auto quick perms dangerous
+077 auto quick whiteout dir
 100 auto quick union samefs
 101 auto quick union nonsamefs
 102 auto quick union nonsamefs xino