diff mbox series

[v5] overlay: test for whiteout inode sharing

Message ID 20200513192338.13584-1-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v5] overlay: test for whiteout inode sharing | expand

Commit Message

Amir Goldstein May 13, 2020, 7:23 p.m. UTC
From: Chengguang Xu <cgxu519@mykernel.net>

This is a test for whiteout inode sharing feature.

[Amir] added check for whiteout sharing support
       and whiteout of lower dir.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---

Chengguang,

I decided to take a stab at Eryu's challenge ;-)

Amir.

 tests/overlay/074     | 117 ++++++++++++++++++++++++++++++++++++++++++
 tests/overlay/074.out |   2 +
 tests/overlay/group   |   1 +
 3 files changed, 120 insertions(+)
 create mode 100755 tests/overlay/074
 create mode 100644 tests/overlay/074.out

Comments

Chengguang Xu May 14, 2020, 7:55 a.m. UTC | #1
---- 在 星期四, 2020-05-14 03:23:38 Amir Goldstein <amir73il@gmail.com> 撰写 ----
 > From: Chengguang Xu <cgxu519@mykernel.net>
 > 
 > This is a test for whiteout inode sharing feature.
 > 
 > [Amir] added check for whiteout sharing support
 >        and whiteout of lower dir.
 > 
 > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
 > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
 > ---
 > 
 > Chengguang,
 > 
 > I decided to take a stab at Eryu's challenge ;-)
 
Thanks for doing this, I've also tested in both sharing/non-sharing ENVs and the case worked as expected. 

Thanks,
cgxu
Eryu Guan May 17, 2020, 4:24 p.m. UTC | #2
On Wed, May 13, 2020 at 10:23:38PM +0300, Amir Goldstein wrote:
> From: Chengguang Xu <cgxu519@mykernel.net>
> 
> This is a test for whiteout inode sharing feature.
> 
> [Amir] added check for whiteout sharing support
>        and whiteout of lower dir.
> 
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
> 
> Chengguang,
> 
> I decided to take a stab at Eryu's challenge ;-)

Great! Thanks for the update!

Eryu
Amir Goldstein May 17, 2020, 4:42 p.m. UTC | #3
On Sun, May 17, 2020 at 7:24 PM Eryu Guan <guan@eryu.me> wrote:
>
> On Wed, May 13, 2020 at 10:23:38PM +0300, Amir Goldstein wrote:
> > From: Chengguang Xu <cgxu519@mykernel.net>
> >
> > This is a test for whiteout inode sharing feature.
> >
> > [Amir] added check for whiteout sharing support
> >        and whiteout of lower dir.
> >
> > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > ---
> >
> > Chengguang,
> >
> > I decided to take a stab at Eryu's challenge ;-)
>
> Great! Thanks for the update!
>

FYI, not sure if and when that was mentioned.
inode sharing feature is now on overlayfs-next.

So are the two file handle fixes for which I posted the test:
"overlay: regression test for two file handle bugs"
(will re-post when I have the final kernel commits)

Thanks,
Amir.
Eryu Guan May 17, 2020, 4:47 p.m. UTC | #4
On Sun, May 17, 2020 at 07:42:32PM +0300, Amir Goldstein wrote:
> On Sun, May 17, 2020 at 7:24 PM Eryu Guan <guan@eryu.me> wrote:
> >
> > On Wed, May 13, 2020 at 10:23:38PM +0300, Amir Goldstein wrote:
> > > From: Chengguang Xu <cgxu519@mykernel.net>
> > >
> > > This is a test for whiteout inode sharing feature.
> > >
> > > [Amir] added check for whiteout sharing support
> > >        and whiteout of lower dir.
> > >
> > > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> > > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > > ---
> > >
> > > Chengguang,
> > >
> > > I decided to take a stab at Eryu's challenge ;-)
> >
> > Great! Thanks for the update!
> >
> 
> FYI, not sure if and when that was mentioned.
> inode sharing feature is now on overlayfs-next.
> 
> So are the two file handle fixes for which I posted the test:
> "overlay: regression test for two file handle bugs"
> (will re-post when I have the final kernel commits)

Thanks! I noticed this test would oops kernel, so I didn't take it this
time and will wait until the fix goes to mainline kernel.

Thanks,
Eryu
diff mbox series

Patch

diff --git a/tests/overlay/074 b/tests/overlay/074
new file mode 100755
index 00000000..4088c0e7
--- /dev/null
+++ b/tests/overlay/074
@@ -0,0 +1,117 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Chengguang Xu <cgxu519@mykernel.net>.
+# All Rights Reserved.
+#
+# FS QA Test 074
+#
+# Test whiteout inode sharing functionality.
+#
+# A "whiteout" is an object that has special meaning in overlayfs.
+# A whiteout on an upper layer will effectively hide a matching file
+# in the lower layer, making it appear as if the file didn't exist.
+#
+# Whiteout inode sharing means multiple whiteout objects will share
+# one inode in upper layer, without this feature every whiteout object
+# will consume one inode in upper layer.
+
+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.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs overlay
+_supported_os Linux
+_require_scratch
+# Require index dir to test if workdir/work is not in use
+# which implies that whiteout sharing is supported
+_require_scratch_overlay_features index
+
+lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
+upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
+workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
+
+# Make some testing files in lowerdir.
+# Argument:
+# $1: Testing file number
+make_lower_files()
+{
+	mkdir $lowerdir/dir
+	for name in `seq ${1}`; do
+		touch $lowerdir/${name} &>/dev/null
+	done
+}
+
+# Delete all copied-up files in upperdir.
+make_whiteout_files()
+{
+	# whiteout inode sharing implies that workdir/work is not in use
+	# If workdir/work is in use, delete of lower dir will fail and
+	# we won't run the test.
+	rmdir $workdir/work
+	rmdir $SCRATCH_MNT/dir &>/dev/null || \
+		_notrun "overlay does not support whiteout inode sharing"
+	rm $SCRATCH_MNT/* &>/dev/null
+}
+
+# Check link count of whiteout files.
+# Arguments:
+# $1: Testing file number
+# $2: Expected link count
+check_whiteout_files()
+{
+	for name in dir `seq ${1}`; do
+		local real_count=`stat -c %h $upperdir/${name} 2>/dev/null`
+		if [[ ${2} != $real_count ]]; then
+			echo "Expected link count is ${2} but real count is $real_count, file name is ${name}"
+		fi
+	done
+	local tmpfile_count=`ls $workdir/index/\#* 2>/dev/null |wc -l 2>/dev/null`
+	if [[ -n "$tmpfile_count" && $tmpfile_count > 1 ]]; then
+		echo "There are more than one whiteout tmpfile in index dir!"
+		ls -l $workdir/index/\#* 2>/dev/null
+	fi
+}
+
+# Run test case with specific arguments.
+# Arguments:
+# $1: Testing file number
+# $2: Expected link count
+run_test_case()
+{
+	_scratch_mkfs
+	make_lower_files ${1}
+	_scratch_mount -o "index=on"
+	make_whiteout_files
+	check_whiteout_files ${1} ${2}
+	_scratch_unmount
+}
+
+# Test case
+file_count=10
+# +1 for dir +1 for temp whiteout
+link_count=12
+run_test_case $file_count $link_count
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/overlay/074.out b/tests/overlay/074.out
new file mode 100644
index 00000000..380f0657
--- /dev/null
+++ b/tests/overlay/074.out
@@ -0,0 +1,2 @@ 
+QA output created by 074
+Silence is golden
diff --git a/tests/overlay/group b/tests/overlay/group
index 5625a46d..2f21db00 100644
--- a/tests/overlay/group
+++ b/tests/overlay/group
@@ -76,3 +76,4 @@ 
 071 auto quick copyup redirect nested nonsamefs
 072 auto quick copyup hardlink
 073 auto quick exportfs dangerous
+074 auto quick whiteout