Skip to contentSkip to conversation

xfstests: mount cycle overlay base fs

PATCH In review Amir Goldstein 2 participants 8 messages Jan 27, 2017 – Feb 7, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover xfstests: mount cycle overlay base fs

Eryu,

The main motivation for this work was to help catch overlayfs bugs related to leaking objects in underlying (base) fs.
Along the way, it also addresses the config of fake TEST/SCRATCH_DEV to refer to directories.

I split the patches to 2 main changes:
1) convert old config with config of already mounted test/scratch base fs (backward compat with old config is maintained)
2) (optional) configure blockdev of base fs for mount cycling base fs

I tested -g quick with all 3 configuraions:
- old (*_DEV)
- new (only *_BASE_MNT)
- new (*_BASE_MNT and *_BASE_DEV)

v2:
- Test and scratch base dirs each have thier own base fs
- Support mount cycles of base fs for scratch tests

v1:
- Both test and scratch base dirs on a single base fs

Amir Goldstein (3):
overlay: configure base fs mount point for running tests
overlay: use SCRATCH_BASE_DIR instead of SCRATCH_DEV
overlay: mount/unmount base fs before/after running tests

 common/config     | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-
 common/rc         | 62 +++++++++++++++++++++++++++++++++++++++++++++++--------
 tests/overlay/001 |  7 +++----
 tests/overlay/002 |  2 +-
 tests/overlay/003 |  5 +++--
 tests/overlay/004 |  7 ++++---
 tests/overlay/005 | 30 +++++++++++++--------------
 tests/overlay/006 |  8 +++----
 tests/overlay/008 |  4 ++--
 tests/overlay/009 |  2 +-
 tests/overlay/010 | 10 ++++-----
 tests/overlay/011 |  4 ++--
 tests/overlay/012 |  4 ++--
 tests/overlay/013 |  4 ++--
 tests/overlay/014 | 19 +++++++++--------
 tests/overlay/015 |  2 +-
 tests/overlay/016 |  2 +-
 tests/overlay/017 |  2 +-
 tests/overlay/018 |  2 +-
 tests/overlay/019 |  2 +-
 tests/overlay/020 |  2 +-
 tests/overlay/021 |  6 +++---
 22 files changed, 171 insertions(+), 71 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/3 overlay: configure base fs mount point for running tests

Instead of setting the vars TEST/SCRATCH_DEV to overlay base dirs, allow setting the vars SCRATCH/TEST_BASE_MNT, to configure where the base fs is mounted and where overlay dirs will be created. For example:

-export TEST_DEV=/mnt/base/test/ovl
-export SCRATCH_DEV=/mnt/base/scratch/ovl
+export TEST_BASE_MNT=/mnt/base/test
+export SCRATCH_BASE_MNT=/mnt/base/scratch
export TEST_DIR=/mnt/test
export SCRATCH_MNT=/mnt/scratch
export FSTYP=overlay

The new canonical vars SCRATCH/TEST_BASE_DIR are defined to refer to overlay base dir explicitly, whether it was set by old or new config method. Tests should always use these canonical vars and not the fake SCRATCH/TEST_DEV vars when referring to overlay based dir.

An upcoming change is going to support mount/umount of base fs.

---
 common/config | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 common/rc     | 20 +++++++++++---------
 2 files changed, 62 insertions(+), 10 deletions(-)
common/config +51 -1
index 0706aca..db5721c 100644
@@ -35,6 +35,8 @@
 # RMT_TAPE_DEV -    the remote tape device for the xfsdump tests
 # RMT_IRIXTAPE_DEV- the IRIX remote tape device for the xfsdump tests
 # RMT_TAPE_USER -   remote user for tape device
+# TEST_BASE_MNT -   mount point for base fs of overlay test dirs
+# SCRATCH_BASE_MNT- mount point for base fs of overlay scratch dirs
 #
 # - These can be added to $HOST_CONFIG_DIR (witch default to ./config)
 #   below or a separate local configuration file can be used (using
@@ -77,6 +79,9 @@ export XFS_MKFS_OPTIONS=${XFS_MKFS_OPTIONS:=-bsize=4096}
 export TIME_FACTOR=${TIME_FACTOR:=1}
 export LOAD_FACTOR=${LOAD_FACTOR:=1}
 export DEBUGFS_MNT=${DEBUGFS_MNT:="/sys/kernel/debug"}
+# directory inside TEST/SCRATCH_BASE_MNT where overlay dirs are created
+export OVERLAY_BASE_DIR=${OVERLAY_BASE_DIR:="ovl"}
+# directories created inside TEST/SCRATCH_BASE_DIR
 export OVERLAY_UPPER_DIR=${OVERLAY_UPPER_DIR:="upper"}
 export OVERLAY_LOWER_DIR=${OVERLAY_LOWER_DIR:="lower"}
 export OVERLAY_WORK_DIR=${OVERLAY_WORK_DIR:="work"}
@@ -443,7 +448,7 @@ _check_device()
 	echo $dev | grep -qE ":|//" > /dev/null 2>&1
 	network_dev=$?
 	if [ "$FSTYP" == "overlay" ]; then
-		if [ ! -d "$dev" ]; then
+		if [ -z "$TEST_BASE_MNT" -a ! -d "$dev" ]; then
 			_fatal "common/config: $name ($dev) is not a directory for overlay"
 		fi
 	elif [ ! -b "$dev" -a "$network_dev" != "0" ]; then
@@ -451,6 +456,46 @@ _check_device()
 	fi
 }
 
+# Set SCRATCH/TEST_BASE_DIR either from legacy TEST/SCRATCH_DEV
+# Or by deriving them from base fs if SCRATCH/TEST_BASE_MNT are defined.
+# Tests should always use SCRATCH/TEST_BASE_DIR when referering to
+# overlay base dir explicitly.
+_config_overlay()
+{
+	# There are 2 options for testing overlayfs:
+	#
+	# 1. (legacy) set SCRATCH/TEST_DEV to existing directories
+	#    on an already mounted fs.
+	#
+	[ -z "$TEST_DEV" ] || export TEST_BASE_DIR="$TEST_DEV"
+	[ -z "$SCRATCH_DEV" ] || export SCRATCH_BASE_DIR="$SCRATCH_DEV"
+
+	# 2. set SCRATCH/TEST_BASE_MNT to configure base fs.
+	#    SCRATCH/TEST_DEV are derived from SCRATCH/TEST_BASE_MNT
+	#    and therein, overlay fs directories will be created.
+	[ -n "$TEST_BASE_MNT" ] || return
+
+	if [ ! -d "$TEST_BASE_MNT" ]; then
+		echo "common/config: Error: \$TEST_BASE_MNT ($TEST_BASE_MNT) is not a directory"
+		exit 1
+	fi
+
+	export TEST_BASE_DIR="$TEST_BASE_MNT/$OVERLAY_BASE_DIR"
+	# Set TEST_DEV to base dir to satisfy common helpers
+	export TEST_DEV="$TEST_BASE_DIR"
+
+	[ -n "$SCRATCH_BASE_MNT" ] || return
+
+	if [ ! -d "$SCRATCH_BASE_MNT" ]; then
+		echo "common/config: Error: \$SCRATCH_BASE_MNT ($SCRATCH_BASE_MNT) is not a directory"
+		exit 1
+	fi
+
+	export SCRATCH_BASE_DIR="$SCRATCH_BASE_MNT/$OVERLAY_BASE_DIR"
+	# Set SCRATCH_DEV to base dir to satisfy common helpers
+	export SCRATCH_DEV="$SCRATCH_BASE_DIR"
+}
+
 # Parse config section options. This function will parse all the configuration
 # within a single section which name is passed as an argument. For section
 # name format see comments in get_config_sections().
@@ -525,6 +570,11 @@ get_next_config() {
 		export RESULT_BASE="$here/results/"
 	fi
 
+	# Maybe derive TEST_DEV from TEST_BASE_MNT
+	if [ "$FSTYP" == "overlay" ]; then
+		_config_overlay
+	fi
+
 	#  Mandatory Config values.
 	MC=""
 	[ -z "$EMAIL" ]          && MC="$MC EMAIL"
common/rc +11 -9
index 862bc04..f5ab869 100644
@@ -257,7 +257,7 @@ _scratch_mount_options()
 	_scratch_options mount
 
 	if [ "$FSTYP" == "overlay" ]; then
-		echo `_overlay_mount_options $SCRATCH_DEV`
+		echo `_overlay_mount_options $SCRATCH_BASE_DIR`
 		return 0
 	fi
 	echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
@@ -322,12 +322,12 @@ _overlay_mount()
 
 _overlay_test_mount()
 {
-	_overlay_mount $TEST_DEV $TEST_DIR $*
+	_overlay_mount $TEST_BASE_DIR $TEST_DIR $*
 }
 
 _overlay_scratch_mount()
 {
-	_overlay_mount $SCRATCH_DEV $SCRATCH_MNT $*
+	_overlay_mount $SCRATCH_BASE_DIR $SCRATCH_MNT $*
 }
 
 _overlay_test_unmount()
@@ -641,10 +641,12 @@ _scratch_cleanup_files()
 {
 	case $FSTYP in
 	overlay)
-		# $SCRATCH_DEV is a valid directory in overlay case
-		rm -rf $SCRATCH_DEV/*
+		# Avoid rm -rf /* if we messed up
+		[ -n "$SCRATCH_BASE_DIR" ] || return
+		rm -rf $SCRATCH_BASE_DIR/*
 		;;
 	*)
+		[ -n "$SCRATCH_MNT" ] || return
 		_scratch_mount
 		rm -rf $SCRATCH_MNT/*
 		_scratch_unmount
@@ -1343,8 +1345,8 @@ _require_scratch_nocheck()
 		fi
 		;;
 	overlay)
-		if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_DEV" ]; then
-			_notrun "this test requires a valid \$SCRATCH_DEV as ovl base dir"
+		if [ -z "$SCRATCH_BASE_DIR" -o ! -d "$SCRATCH_BASE_DIR" ]; then
+			_notrun "this test requires a valid \$SCRATCH_BASE_DIR as ovl base dir"
 		fi
 		if [ ! -d "$SCRATCH_MNT" ]; then
 			_notrun "this test requires a valid \$SCRATCH_MNT"
@@ -1428,8 +1430,8 @@ _require_test()
 		fi
 		;;
 	overlay)
-		if [ -z "$TEST_DEV" -o ! -d "$TEST_DEV" ]; then
-			_notrun "this test requires a valid \$TEST_DEV as ovl base dir"
+		if [ -z "$TEST_BASE_DIR" -o ! -d "$TEST_BASE_DIR" ]; then
+			_notrun "this test requires a valid \$TEST_BASE_DIR as ovl base dir"
 		fi
 		if [ ! -d "$TEST_DIR" ]; then
 			_notrun "this test requires a valid \$TEST_DIR"
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v2 1/3] overlay: configure base fs mount point for running tests

Review

Quoted 9 lines · Amir Goldstein

Instead of setting the vars TEST/SCRATCH_DEV to overlay base dirs, allow setting the vars SCRATCH/TEST_BASE_MNT, to configure where the base fs is mounted and where overlay dirs will be created. For example:

(quoted diff) +2 -2
-export TEST_DEV=/mnt/base/test/ovl
-export SCRATCH_DEV=/mnt/base/scratch/ovl
+export TEST_BASE_MNT=/mnt/base/test
+export SCRATCH_BASE_MNT=/mnt/base/scratch

[sorry for the late review, I came back from holiday then played with this patchset for a while]

Hmm, I noticed that there're TEST/SCRATCH_BASE_MNT and TEST/SCRATCH_BASE_DIR and OVERLAY_BASE_DIR introduced. They seem a bit complex and can be confusing to users. I'm wondering if they can be simplified somehow? e.g. use TEST/SCRATCH_BASE_MNT only, no ..BASE_DIR vars, no OVERLAY_BASE_DIR (which seems not necessary to me, it only adds another level to the path structure).

And I gave the variables naming a second thought, I think TEST/SCRATCH_BASE_MNT are confusing, they're used only in overlayfs testing, but the names seem to imply they're generic enough and useful in other filesystems testing too. I'd like to name them with little confusion. OTOH, I agree that adding "OVERLAY_" prefix is not good enough either (names too long).

I'm not good at naming variables.., just a random idea in my head, how about using OVL_ prefix? i.e.

OVL_TEST/SCRATCH_BASE_MNT, a bit shorter, and indicates they're only useful in overlayfs testing, but OVL_ prefix introduces inconsistency (with OVERLAY_UPPER_DIR etc., perhaps we can change all OVERLAY_ to OVL_?).

Thanks,
Eryu

Quoted 176 lines

export TEST_DIR=/mnt/test
export SCRATCH_MNT=/mnt/scratch
export FSTYP=overlay

The new canonical vars SCRATCH/TEST_BASE_DIR are defined to refer to overlay base dir explicitly, whether it was set by old or new config method. Tests should always use these canonical vars and not the fake SCRATCH/TEST_DEV vars when referring to overlay based dir.

An upcoming change is going to support mount/umount of base fs.

---
 common/config | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 common/rc     | 20 +++++++++++---------
 2 files changed, 62 insertions(+), 10 deletions(-)
common/config +51 -1
index 0706aca..db5721c 100644
@@ -35,6 +35,8 @@
 # RMT_TAPE_DEV -    the remote tape device for the xfsdump tests
 # RMT_IRIXTAPE_DEV- the IRIX remote tape device for the xfsdump tests
 # RMT_TAPE_USER -   remote user for tape device
+# TEST_BASE_MNT -   mount point for base fs of overlay test dirs
+# SCRATCH_BASE_MNT- mount point for base fs of overlay scratch dirs
 #
 # - These can be added to $HOST_CONFIG_DIR (witch default to ./config)
 #   below or a separate local configuration file can be used (using
@@ -77,6 +79,9 @@ export XFS_MKFS_OPTIONS=${XFS_MKFS_OPTIONS:=-bsize=4096}
 export TIME_FACTOR=${TIME_FACTOR:=1}
 export LOAD_FACTOR=${LOAD_FACTOR:=1}
 export DEBUGFS_MNT=${DEBUGFS_MNT:="/sys/kernel/debug"}
+# directory inside TEST/SCRATCH_BASE_MNT where overlay dirs are created
+export OVERLAY_BASE_DIR=${OVERLAY_BASE_DIR:="ovl"}
+# directories created inside TEST/SCRATCH_BASE_DIR
 export OVERLAY_UPPER_DIR=${OVERLAY_UPPER_DIR:="upper"}
 export OVERLAY_LOWER_DIR=${OVERLAY_LOWER_DIR:="lower"}
 export OVERLAY_WORK_DIR=${OVERLAY_WORK_DIR:="work"}
@@ -443,7 +448,7 @@ _check_device()
 	echo $dev | grep -qE ":|//" > /dev/null 2>&1
 	network_dev=$?
 	if [ "$FSTYP" == "overlay" ]; then
-		if [ ! -d "$dev" ]; then
+		if [ -z "$TEST_BASE_MNT" -a ! -d "$dev" ]; then
 			_fatal "common/config: $name ($dev) is not a directory for overlay"
 		fi
 	elif [ ! -b "$dev" -a "$network_dev" != "0" ]; then
@@ -451,6 +456,46 @@ _check_device()
 	fi
 }
 
+# Set SCRATCH/TEST_BASE_DIR either from legacy TEST/SCRATCH_DEV
+# Or by deriving them from base fs if SCRATCH/TEST_BASE_MNT are defined.
+# Tests should always use SCRATCH/TEST_BASE_DIR when referering to
+# overlay base dir explicitly.
+_config_overlay()
+{
+	# There are 2 options for testing overlayfs:
+	#
+	# 1. (legacy) set SCRATCH/TEST_DEV to existing directories
+	#    on an already mounted fs.
+	#
+	[ -z "$TEST_DEV" ] || export TEST_BASE_DIR="$TEST_DEV"
+	[ -z "$SCRATCH_DEV" ] || export SCRATCH_BASE_DIR="$SCRATCH_DEV"
+
+	# 2. set SCRATCH/TEST_BASE_MNT to configure base fs.
+	#    SCRATCH/TEST_DEV are derived from SCRATCH/TEST_BASE_MNT
+	#    and therein, overlay fs directories will be created.
+	[ -n "$TEST_BASE_MNT" ] || return
+
+	if [ ! -d "$TEST_BASE_MNT" ]; then
+		echo "common/config: Error: \$TEST_BASE_MNT ($TEST_BASE_MNT) is not a directory"
+		exit 1
+	fi
+
+	export TEST_BASE_DIR="$TEST_BASE_MNT/$OVERLAY_BASE_DIR"
+	# Set TEST_DEV to base dir to satisfy common helpers
+	export TEST_DEV="$TEST_BASE_DIR"
+
+	[ -n "$SCRATCH_BASE_MNT" ] || return
+
+	if [ ! -d "$SCRATCH_BASE_MNT" ]; then
+		echo "common/config: Error: \$SCRATCH_BASE_MNT ($SCRATCH_BASE_MNT) is not a directory"
+		exit 1
+	fi
+
+	export SCRATCH_BASE_DIR="$SCRATCH_BASE_MNT/$OVERLAY_BASE_DIR"
+	# Set SCRATCH_DEV to base dir to satisfy common helpers
+	export SCRATCH_DEV="$SCRATCH_BASE_DIR"
+}
+
 # Parse config section options. This function will parse all the configuration
 # within a single section which name is passed as an argument. For section
 # name format see comments in get_config_sections().
@@ -525,6 +570,11 @@ get_next_config() {
 		export RESULT_BASE="$here/results/"
 	fi
 
+	# Maybe derive TEST_DEV from TEST_BASE_MNT
+	if [ "$FSTYP" == "overlay" ]; then
+		_config_overlay
+	fi
+
 	#  Mandatory Config values.
 	MC=""
 	[ -z "$EMAIL" ]          && MC="$MC EMAIL"
common/rc +11 -9
index 862bc04..f5ab869 100644
@@ -257,7 +257,7 @@ _scratch_mount_options()
 	_scratch_options mount
 
 	if [ "$FSTYP" == "overlay" ]; then
-		echo `_overlay_mount_options $SCRATCH_DEV`
+		echo `_overlay_mount_options $SCRATCH_BASE_DIR`
 		return 0
 	fi
 	echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
@@ -322,12 +322,12 @@ _overlay_mount()
 
 _overlay_test_mount()
 {
-	_overlay_mount $TEST_DEV $TEST_DIR $*
+	_overlay_mount $TEST_BASE_DIR $TEST_DIR $*
 }
 
 _overlay_scratch_mount()
 {
-	_overlay_mount $SCRATCH_DEV $SCRATCH_MNT $*
+	_overlay_mount $SCRATCH_BASE_DIR $SCRATCH_MNT $*
 }
 
 _overlay_test_unmount()
@@ -641,10 +641,12 @@ _scratch_cleanup_files()
 {
 	case $FSTYP in
 	overlay)
-		# $SCRATCH_DEV is a valid directory in overlay case
-		rm -rf $SCRATCH_DEV/*
+		# Avoid rm -rf /* if we messed up
+		[ -n "$SCRATCH_BASE_DIR" ] || return
+		rm -rf $SCRATCH_BASE_DIR/*
 		;;
 	*)
+		[ -n "$SCRATCH_MNT" ] || return
 		_scratch_mount
 		rm -rf $SCRATCH_MNT/*
 		_scratch_unmount
@@ -1343,8 +1345,8 @@ _require_scratch_nocheck()
 		fi
 		;;
 	overlay)
-		if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_DEV" ]; then
-			_notrun "this test requires a valid \$SCRATCH_DEV as ovl base dir"
+		if [ -z "$SCRATCH_BASE_DIR" -o ! -d "$SCRATCH_BASE_DIR" ]; then
+			_notrun "this test requires a valid \$SCRATCH_BASE_DIR as ovl base dir"
 		fi
 		if [ ! -d "$SCRATCH_MNT" ]; then
 			_notrun "this test requires a valid \$SCRATCH_MNT"
@@ -1428,8 +1430,8 @@ _require_test()
 		fi
 		;;
 	overlay)
-		if [ -z "$TEST_DEV" -o ! -d "$TEST_DEV" ]; then
-			_notrun "this test requires a valid \$TEST_DEV as ovl base dir"
+		if [ -z "$TEST_BASE_DIR" -o ! -d "$TEST_BASE_DIR" ]; then
+			_notrun "this test requires a valid \$TEST_BASE_DIR as ovl base dir"
 		fi
 		if [ ! -d "$TEST_DIR" ]; then
 			_notrun "this test requires a valid \$TEST_DIR"
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v2 1/3] overlay: configure base fs mount point for running tests

Quoted 14 lines · Eryu Guan

Review

Quoted 9 lines · Amir Goldstein

Instead of setting the vars TEST/SCRATCH_DEV to overlay base dirs, allow setting the vars SCRATCH/TEST_BASE_MNT, to configure where the base fs is mounted and where overlay dirs will be created. For example:

(quoted diff) +2 -2
-export TEST_DEV=/mnt/base/test/ovl
-export SCRATCH_DEV=/mnt/base/scratch/ovl
+export TEST_BASE_MNT=/mnt/base/test
+export SCRATCH_BASE_MNT=/mnt/base/scratch

[sorry for the late review, I came back from holiday then played with this patchset for a while]

Quoted 6 lines

Hmm, I noticed that there're TEST/SCRATCH_BASE_MNT and TEST/SCRATCH_BASE_DIR and OVERLAY_BASE_DIR introduced. They seem a bit complex and can be confusing to users. I'm wondering if they can be simplified somehow? e.g. use TEST/SCRATCH_BASE_MNT only, no ..BASE_DIR vars, no OVERLAY_BASE_DIR (which seems not necessary to me, it only adds another level to the path structure).

I find the extra level necessary.
For example, I use the same BASE_DEV for other tests, so I would like to isolate overlayfs tests under ovl dir.
If we were to support mkfs of BASE_DEV that would have been different but we don't.

However, I will try to get rid of some of the variables to reduce confusion. IMO, _BASE_DIR, which replaces the bogus TEST/SCRATCH_DEV is important for tests that mount their own custom overlays, e.g. overlay/005. I will try to see how this can be simplified or better explained. Please give this another thought as well.

Quoted 8 lines

And I gave the variables naming a second thought, I think TEST/SCRATCH_BASE_MNT are confusing, they're used only in overlayfs testing, but the names seem to imply they're generic enough and useful in other filesystems testing too. I'd like to name them with little confusion. OTOH, I agree that adding "OVERLAY_" prefix is not good enough either (names too long).

Quoted 8 lines

I'm not good at naming variables.., just a random idea in my head, how about using OVL_ prefix? i.e.

OVL_TEST/SCRATCH_BASE_MNT, a bit shorter, and indicates they're only useful in overlayfs testing, but OVL_ prefix introduces inconsistency (with OVERLAY_UPPER_DIR etc., perhaps we can change all OVERLAY_ to OVL_?).

Yes, I considered OVL_ as well. I guess it is the least worse option. No problem to align OVL_UPPER/LOWER_DIR. Will do.

#4 lore raw

PATCH v2 2/3 overlay: use SCRATCH_BASE_DIR instead of SCRATCH_DEV

In reply to Amir Goldstein

Use the new canonical var SCRATCH_BASE_DIR to refer to overlay base dir instead of the old 'fake' SCRATCH_DEV var.

---
 tests/overlay/001 |  7 +++----
 tests/overlay/002 |  2 +-
 tests/overlay/003 |  2 +-
 tests/overlay/004 |  4 ++--
 tests/overlay/005 | 30 +++++++++++++++---------------
 tests/overlay/006 |  8 ++++----
 tests/overlay/008 |  4 ++--
 tests/overlay/009 |  2 +-
 tests/overlay/010 | 10 +++++-----
 tests/overlay/011 |  4 ++--
 tests/overlay/012 |  4 ++--
 tests/overlay/013 |  4 ++--
 tests/overlay/014 | 14 +++++++-------
 tests/overlay/015 |  2 +-
 tests/overlay/016 |  2 +-
 tests/overlay/017 |  2 +-
 tests/overlay/018 |  2 +-
 tests/overlay/019 |  2 +-
 tests/overlay/020 |  2 +-
 tests/overlay/021 |  6 +++---
 20 files changed, 56 insertions(+), 57 deletions(-)
tests/overlay/001 +3 -4
index 7be9ae5..462b83c 100755
@@ -55,12 +55,11 @@ _require_scratch
 _scratch_mkfs
 
 # overlay copy_up doesn't deal with sparse file well, holes will be filled by
-# zeros, so at least (4G + 4G + 8k) free space is needed on $SCRATCH_DEV,
-# where $SCRATCH_DEV is actually a test dir used in overlay testing
-_require_fs_space $SCRATCH_DEV $((4*1024*1024*2 + 8))
+# zeros, so at least (4G + 4G + 8k) free space is needed on $SCRATCH_BASE_DIR
+_require_fs_space $SCRATCH_BASE_DIR $((4*1024*1024*2 + 8))
 
 # Create test files with different sizes in lower dir
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir
 touch $lowerdir/zero_size
 $XFS_IO_PROG -fc "pwrite 0 4k" $lowerdir/less_than_4g >>$seqres.full
tests/overlay/002 +1 -1
index ec7874e..391e755 100755
@@ -59,7 +59,7 @@ _require_scratch
 _scratch_mkfs
 
 # Create our test file.
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir
 touch $lowerdir/foobar
 
tests/overlay/003 +1 -1
index fbc242a..bb59700 100755
@@ -60,7 +60,7 @@ _require_scratch
 _scratch_mkfs
 
 # Create test files dirs in lower dir
-lowerdir=${SCRATCH_DEV}/${OVERLAY_LOWER_DIR}
+lowerdir=${SCRATCH_BASE_DIR}/${OVERLAY_LOWER_DIR}
 mkdir -p $lowerdir
 
 touch ${lowerdir}/test_file
tests/overlay/004 +2 -2
index 4075094..6d78f9f 100755
@@ -53,8 +53,8 @@ _require_user
 _scratch_mkfs
 
 # Create test file in lower dir
-lowerdir=${SCRATCH_DEV}/${OVERLAY_LOWER_DIR}
-upperdir=${SCRATCH_DEV}/${OVERLAY_UPPER_DIR}
+lowerdir=${SCRATCH_BASE_DIR}/${OVERLAY_LOWER_DIR}
+upperdir=${SCRATCH_BASE_DIR}/${OVERLAY_UPPER_DIR}
 mkdir -p $lowerdir
 touch ${lowerdir}/attr_file1
 chmod 000 ${lowerdir}/attr_file1
tests/overlay/005 +15 -15
index baadb69..d037335 100755
@@ -61,31 +61,31 @@ _require_loop
 _scratch_mkfs
 
 # setup loop images fs for overlayfs
-lower_img=${SCRATCH_DEV}/${seq}.$$.img
+lower_img=${SCRATCH_BASE_DIR}/${seq}.$$.img
 $XFS_IO_PROG -f -c "truncate 120m" $lower_img >>$seqres.full 2>&1
 fs_loop_dev=`_create_loop_device $lower_img`
 $MKFS_XFS_PROG -f -n ftype=1 $fs_loop_dev >>$seqres.full 2>&1
 
 # only 20m for upper dir
-upper_img=${SCRATCH_DEV}/$$.${seq}.img
+upper_img=${SCRATCH_BASE_DIR}/$$.${seq}.img
 $XFS_IO_PROG -f -c "truncate 20m" $upper_img >>$seqres.full 2>&1
 upper_loop_dev=`_create_loop_device $upper_img`
 $MKFS_XFS_PROG -f -n ftype=1 $upper_loop_dev >>$seqres.full 2>&1
 
 # mount underlying xfs
-mkdir -p ${SCRATCH_DEV}/lowermnt
-mkdir -p ${SCRATCH_DEV}/uppermnt
-$MOUNT_PROG $fs_loop_dev ${SCRATCH_DEV}/lowermnt
-$MOUNT_PROG $upper_loop_dev ${SCRATCH_DEV}/uppermnt
+mkdir -p ${SCRATCH_BASE_DIR}/lowermnt
+mkdir -p ${SCRATCH_BASE_DIR}/uppermnt
+$MOUNT_PROG $fs_loop_dev ${SCRATCH_BASE_DIR}/lowermnt
+$MOUNT_PROG $upper_loop_dev ${SCRATCH_BASE_DIR}/uppermnt
 
 # prepare dirs
-mkdir -p ${SCRATCH_DEV}/lowermnt/lower
-mkdir -p ${SCRATCH_DEV}/uppermnt/upper
-mkdir -p ${SCRATCH_DEV}/uppermnt/work
+mkdir -p ${SCRATCH_BASE_DIR}/lowermnt/lower
+mkdir -p ${SCRATCH_BASE_DIR}/uppermnt/upper
+mkdir -p ${SCRATCH_BASE_DIR}/uppermnt/work
 
-lowerd=${SCRATCH_DEV}/lowermnt/lower
-upperd=${SCRATCH_DEV}/uppermnt/upper
-workd=${SCRATCH_DEV}/uppermnt/work
+lowerd=${SCRATCH_BASE_DIR}/lowermnt/lower
+upperd=${SCRATCH_BASE_DIR}/uppermnt/upper
+workd=${SCRATCH_BASE_DIR}/uppermnt/work
 
 # Create test file in lower dir, with too big a size for
 # upper dir to copy up.
@@ -93,7 +93,7 @@ $XFS_IO_PROG -f -c "truncate 48m" ${lowerd}/test_file \
 	>>$seqres.full 2>&1
 
 # mount new overlayfs
-_overlay_mount_dirs $lowerd $upperd $workd $SCRATCH_DEV $SCRATCH_MNT
+_overlay_mount_dirs $lowerd $upperd $workd $SCRATCH_BASE_DIR $SCRATCH_MNT
 
 # the open call triggers copy-up and it will fail ENOSPC
 $XFS_IO_PROG -f -c "o" ${SCRATCH_MNT}/test_file \
@@ -103,8 +103,8 @@ $XFS_IO_PROG -f -c "o" ${SCRATCH_MNT}/test_file \
 $UMOUNT_PROG $SCRATCH_MNT
 
 # unmount undelying xfs, this tiggers panic if memleak happens
-$UMOUNT_PROG ${SCRATCH_DEV}/uppermnt
-$UMOUNT_PROG ${SCRATCH_DEV}/lowermnt
+$UMOUNT_PROG ${SCRATCH_BASE_DIR}/uppermnt
+$UMOUNT_PROG ${SCRATCH_BASE_DIR}/lowermnt
 
 # success, all done
 echo "Silence is golden"
tests/overlay/006 +4 -4
index 31f11ef..9450ef9 100755
@@ -57,10 +57,10 @@ echo "Silence is golden"
 _scratch_mkfs
 
 # Create test file/dir before mount
-mkdir $SCRATCH_DEV/$OVERLAY_LOWER_DIR
-mkdir $SCRATCH_DEV/$OVERLAY_UPPER_DIR
-touch $SCRATCH_DEV/$OVERLAY_LOWER_DIR/lowertestfile
-mkdir $SCRATCH_DEV/$OVERLAY_UPPER_DIR/uppertestdir
+mkdir $SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
+mkdir $SCRATCH_BASE_DIR/$OVERLAY_UPPER_DIR
+touch $SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR/lowertestfile
+mkdir $SCRATCH_BASE_DIR/$OVERLAY_UPPER_DIR/uppertestdir
 
 _scratch_mount
 
tests/overlay/008 +2 -2
index cb8667c..9219b41 100755
@@ -56,13 +56,13 @@ _require_user
 _scratch_mkfs
 
 # Create test file on lower dir, and chown to fsgqa user
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir $lowerdir
 touch $lowerdir/testfile
 chown fsgqa:fsgqa $lowerdir/testfile
 
 # chown upperdir to fsgqa user, so new file/dir can be created by the user
-upperdir=$SCRATCH_DEV/$OVERLAY_UPPER_DIR
+upperdir=$SCRATCH_BASE_DIR/$OVERLAY_UPPER_DIR
 mkdir $upperdir
 chown fsgqa:fsgqa $upperdir
 
tests/overlay/009 +1 -1
index de94ca4..efc05ce 100755
@@ -54,7 +54,7 @@ _require_scratch
 _scratch_mkfs
 
 # Create test file in lowerdir
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir
 touch $lowerdir/testfile
 
tests/overlay/010 +5 -5
index a302d74..4aeaa7b 100755
@@ -55,10 +55,10 @@ _scratch_mkfs
 
 # Need two lower dirs in this test, and we mount overlay ourselves,
 # create upper and workdir as well
-lowerdir1=$SCRATCH_DEV/$OVERLAY_LOWER_DIR.1
-lowerdir2=$SCRATCH_DEV/$OVERLAY_LOWER_DIR.2
-upperdir=$SCRATCH_DEV/$OVERLAY_UPPER_DIR
-workdir=$SCRATCH_DEV/$OVERLAY_WORK_DIR
+lowerdir1=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR.1
+lowerdir2=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR.2
+upperdir=$SCRATCH_BASE_DIR/$OVERLAY_UPPER_DIR
+workdir=$SCRATCH_BASE_DIR/$OVERLAY_WORK_DIR
 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir
 
 # One lowerdir contains test dir and test files, the other contains whiteout
@@ -68,7 +68,7 @@ mknod $lowerdir2/testdir/a c 0 0
 
 # Mount overlayfs and remove testdir, which led to kernel crash
 _overlay_mount_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir \
-		    $SCRATCH_DEV $SCRATCH_MNT
+		    $SCRATCH_BASE_DIR $SCRATCH_MNT
 rm -rf $SCRATCH_MNT/testdir
 
 # success, all done
tests/overlay/011 +2 -2
index 4b697b8..4f474d6 100755
@@ -58,8 +58,8 @@ _require_attrs
 _scratch_mkfs
 
 # Create test dir on upper and make it opaque by setting proper xattr
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
-upperdir=$SCRATCH_DEV/$OVERLAY_UPPER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
+upperdir=$SCRATCH_BASE_DIR/$OVERLAY_UPPER_DIR
 mkdir -p $lowerdir/testdir
 mkdir -p $upperdir/testdir
 $SETFATTR_PROG -n "trusted.overlay.opaque" -v "y" $upperdir/testdir
tests/overlay/012 +2 -2
index cfe16f2..339b2af 100755
@@ -55,8 +55,8 @@ _require_scratch
 # remove all files from previous runs
 _scratch_mkfs
 
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
-upperdir=$SCRATCH_DEV/$OVERLAY_UPPER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
+upperdir=$SCRATCH_BASE_DIR/$OVERLAY_UPPER_DIR
 mkdir -p $lowerdir/test
 
 _scratch_mount
tests/overlay/013 +2 -2
index e99e10a..b09a7d1 100755
@@ -54,8 +54,8 @@ _require_test_program "t_truncate_self"
 _scratch_mkfs
 
 # copy test program to lower and upper dir
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
-upperdir=$SCRATCH_DEV/$OVERLAY_UPPER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
+upperdir=$SCRATCH_BASE_DIR/$OVERLAY_UPPER_DIR
 mkdir -p $lowerdir
 mkdir -p $upperdir
 cp $here/src/t_truncate_self $lowerdir/test_lower
tests/overlay/014 +7 -7
index 36d7077..7426c31 100755
@@ -61,16 +61,16 @@ _require_scratch
 _scratch_mkfs
 
 # Create multiple lowerdirs and upperdir, workdir, and testdir on lowerdir
-lowerdir1=$SCRATCH_DEV/lower1
-lowerdir2=$SCRATCH_DEV/lower2
-upperdir=$SCRATCH_DEV/upper
-workdir=$SCRATCH_DEV/workdir
+lowerdir1=$SCRATCH_BASE_DIR/lower1
+lowerdir2=$SCRATCH_BASE_DIR/lower2
+upperdir=$SCRATCH_BASE_DIR/upper
+workdir=$SCRATCH_BASE_DIR/workdir
 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir
 mkdir -p $lowerdir1/testdir/d
 
 # mount overlay with $lowerdir2 as upperdir, and remove & recreate testdir,
 # make testdir on $lowerdir2 opaque
-_overlay_mount_dirs $lowerdir1 $lowerdir2 $workdir $SCRATCH_DEV $SCRATCH_MNT
+_overlay_mount_dirs $lowerdir1 $lowerdir2 $workdir $SCRATCH_BASE_DIR $SCRATCH_MNT
 rm -rf $SCRATCH_MNT/testdir
 mkdir -p $SCRATCH_MNT/testdir/visibledir
 _scratch_unmount
@@ -79,14 +79,14 @@ _scratch_unmount
 # and create a new file in testdir, triggers copyup from lowerdir,
 # copyup should not copy overlayfs private xattr
 _overlay_mount_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir \
-		    $SCRATCH_DEV $SCRATCH_MNT
+		    $SCRATCH_BASE_DIR $SCRATCH_MNT
 touch $SCRATCH_MNT/testdir/visiblefile
 
 # umount and mount overlay again, buggy kernel treats the copied-up dir as
 # opaque, visibledir is not seen in merged dir.
 _scratch_unmount
 _overlay_mount_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir \
-		    $SCRATCH_DEV $SCRATCH_MNT
+		    $SCRATCH_BASE_DIR $SCRATCH_MNT
 ls $SCRATCH_MNT/testdir
 
 # success, all done
tests/overlay/015 +1 -1
index c39caed..e70930b 100755
@@ -57,7 +57,7 @@ _scratch_mkfs
 umask 022
 
 # Create test dir in lower dir and set sgid bit
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir/dir
 chown $qa_user:$qa_group $lowerdir/dir
 chmod 2775 $lowerdir/dir
tests/overlay/016 +1 -1
index cffcde7..bb4366d 100755
@@ -57,7 +57,7 @@ rm -f $seqres.full
 _scratch_mkfs >>$seqres.full 2>&1
 
 # Create our test files.
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir
 echo "This is old news" > $lowerdir/foo
 echo "This is old news" > $lowerdir/bar
tests/overlay/017 +1 -1
index 5330de2..f9c1bfc 100755
@@ -60,7 +60,7 @@ _scratch_mkfs >>$seqres.full 2>&1
 # Not dealing with hardlinks here, because there is more to test
 # then stable inode number.
 # Hardlinks will get a test of their own.
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir
 mkdir $lowerdir/dir
 touch $lowerdir/file
tests/overlay/018 +1 -1
index df631fc..0b73e52 100755
@@ -55,7 +55,7 @@ rm -f $seqres.full
 _scratch_mkfs >>$seqres.full 2>&1
 
 # Create 2 hardlinked files in lower
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir
 echo "patient zero" >> $lowerdir/foo
 ln $lowerdir/foo $lowerdir/bar
tests/overlay/019 +1 -1
index 41ce63b..1a6a4bd 100755
@@ -51,7 +51,7 @@ _require_scratch
 # Remove all files from previous tests
 _scratch_mkfs
 
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir
 
 _scratch_mount
tests/overlay/020 +1 -1
index 4afd40a..189d83c 100755
@@ -55,7 +55,7 @@ _require_scratch
 # Remove all files from previous tests
 _scratch_mkfs
 
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir/dir
 
 _scratch_mount
tests/overlay/021 +3 -3
index c79bb01..4d619c6 100755
@@ -54,13 +54,13 @@ _scratch_mkfs
 
 # overlay copy_up doesn't deal with sparse file well, holes will be filled by
 # zeros, so for the worst case of hitting all the copy up bomb files, we need
-# (64*(16+32+64+128)M) free space on $SCRATCH_DEV.
+# (64*(16+32+64+128)M) free space on $SCRATCH_BASE_DIR.
 # However, triggering more than a total of 16 copy up bombs would require
 # really fast data copy (clone up doesn't take up space at all), so let's be
 # conservative and reserve space for 16 data copy ups per directory.
-_require_fs_space $SCRATCH_DEV $((16*(16+32+64+128)*1024))
+_require_fs_space $SCRATCH_BASE_DIR $((16*(16+32+64+128)*1024))
 
-lowerdir=$SCRATCH_DEV/$OVERLAY_LOWER_DIR
+lowerdir=$SCRATCH_BASE_DIR/$OVERLAY_LOWER_DIR
 mkdir -p $lowerdir
 
 testdir=arena
Signature · 1 line
2.7.4
#5 lore raw

PATCH v2 3/3 overlay: mount/unmount base fs before/after running tests

In reply to Amir Goldstein

Optionally configure TEST/SCRATCH_BASE_DEV, for overlay base fs to be mounted/unmounted before/after running tests. For example:

+export TEST_BASE_DEV=/dev/mapper/base-test
export TEST_BASE_MNT=/mnt/base/test
+export SCRATCH_BASE_DEV=/dev/mapper/base-scratch
export SCRATCH_BASE_MNT=/mnt/base/scratch
export TEST_DIR=/mnt/test
export SCRATCH_MNT=/mnt/scratch
export FSTYP=overlay

With this change, the base fs is mounted before running tests, unmounted after running tests and recycled on _test_cycle_mount along with the overlay mounts.
This helps catching overlayfs bugs related to leaking objects in underlying (base) fs.

The standard way that overlay tests work is:
- _scratch_mkfs
- setup lower/upper dir files
- _scratch_mount (or custom overlay mount)
- (sometimes) _scratch_unmount/_scratch_mount recycle

To preserve expected tests behavior, the semantics are:
- _scratch_mkfs mounts the base fs, cleans the lower/upper dirs and keeps base fs mounted.
- _scratch_mount mounts or recycles base fs and mounts overlay
- _scratch_unmount unmounts overlay and base fs

Tests that use _scratch_unmount to unmount a custom overlay mount and expect to have access to overlay base dir, were converted to use explicit umount $SCRATCH_MNT instead.

---
 common/config     |  6 +++++-
 common/rc         | 42 ++++++++++++++++++++++++++++++++++++++++++
 tests/overlay/003 |  3 ++-
 tests/overlay/004 |  3 ++-
 tests/overlay/014 |  5 +++--
 5 files changed, 54 insertions(+), 5 deletions(-)
common/config +5 -1
index db5721c..f431a8d 100644
@@ -35,7 +35,9 @@
 # RMT_TAPE_DEV -    the remote tape device for the xfsdump tests
 # RMT_IRIXTAPE_DEV- the IRIX remote tape device for the xfsdump tests
 # RMT_TAPE_USER -   remote user for tape device
+# TEST_BASE_DEV -   device for base fs containing overlay test dirs
 # TEST_BASE_MNT -   mount point for base fs of overlay test dirs
+# SCRATCH_BASE_DEV- device for base fs containing overlay scratch dirs
 # SCRATCH_BASE_MNT- mount point for base fs of overlay scratch dirs
 #
 # - These can be added to $HOST_CONFIG_DIR (witch default to ./config)
@@ -470,11 +472,12 @@ _config_overlay()
 	[ -z "$TEST_DEV" ] || export TEST_BASE_DIR="$TEST_DEV"
 	[ -z "$SCRATCH_DEV" ] || export SCRATCH_BASE_DIR="$SCRATCH_DEV"
 
-	# 2. set SCRATCH/TEST_BASE_MNT to configure base fs.
+	# 2. set SCRATCH/TEST_BASE_DEV/MNT to configure base fs.
 	#    SCRATCH/TEST_DEV are derived from SCRATCH/TEST_BASE_MNT
 	#    and therein, overlay fs directories will be created.
 	[ -n "$TEST_BASE_MNT" ] || return
 
+	_check_device TEST_BASE_DEV optional $TEST_BASE_DEV
 	if [ ! -d "$TEST_BASE_MNT" ]; then
 		echo "common/config: Error: \$TEST_BASE_MNT ($TEST_BASE_MNT) is not a directory"
 		exit 1
@@ -486,6 +489,7 @@ _config_overlay()
 
 	[ -n "$SCRATCH_BASE_MNT" ] || return
 
+	_check_device SCRATCH_BASE_DEV optional $SCRATCH_BASE_DEV
 	if [ ! -d "$SCRATCH_BASE_MNT" ]; then
 		echo "common/config: Error: \$SCRATCH_BASE_MNT ($SCRATCH_BASE_MNT) is not a directory"
 		exit 1
common/rc +42 -0

73 lines not on this page · raw message

tests/overlay/003 +2 -1
index bb59700..81aea85 100755
@@ -89,7 +89,8 @@ rm -rf ${SCRATCH_MNT}/*
 # nothing should be listed
 ls ${SCRATCH_MNT}/
 
-_scratch_unmount
+# unmount overlayfs but not base fs
+$UMOUNT_PROG $SCRATCH_MNT
 
 rm -rf $lowerdir
 echo "Silence is golden"
tests/overlay/004 +2 -1
index 6d78f9f..26ac547 100755
@@ -85,7 +85,8 @@ _user_do "chmod g+t ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
 _user_do "chmod u-X ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
 stat -c %a ${SCRATCH_MNT}/attr_file2
 
-_scratch_unmount
+# unmount overlayfs but not base fs
+$UMOUNT_PROG $SCRATCH_MNT
 
 # check mode bits of the file that has been copied up, and
 # the file that should not have been copied up.
tests/overlay/014 +3 -2
index 7426c31..6519432 100755
@@ -73,7 +73,8 @@ mkdir -p $lowerdir1/testdir/d
 _overlay_mount_dirs $lowerdir1 $lowerdir2 $workdir $SCRATCH_BASE_DIR $SCRATCH_MNT
 rm -rf $SCRATCH_MNT/testdir
 mkdir -p $SCRATCH_MNT/testdir/visibledir
-_scratch_unmount
+# unmount overlayfs but not base fs
+$UMOUNT_PROG $SCRATCH_MNT
 
 # mount overlay again, with lowerdir1 and lowerdir2 as multiple lowerdirs,
 # and create a new file in testdir, triggers copyup from lowerdir,
@@ -84,7 +85,7 @@ touch $SCRATCH_MNT/testdir/visiblefile
 
 # umount and mount overlay again, buggy kernel treats the copied-up dir as
 # opaque, visibledir is not seen in merged dir.
-_scratch_unmount
+$UMOUNT_PROG $SCRATCH_MNT
 _overlay_mount_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir \
 		    $SCRATCH_BASE_DIR $SCRATCH_MNT
 ls $SCRATCH_MNT/testdir
Signature · 1 line
2.7.4
#6 lore raw

Re: [PATCH v2 3/3] overlay: mount/unmount base fs before/after running tests

Quoted 23 lines · Amir Goldstein

Optionally configure TEST/SCRATCH_BASE_DEV, for overlay base fs to be mounted/unmounted before/after running tests. For example:

+export TEST_BASE_DEV=/dev/mapper/base-test
export TEST_BASE_MNT=/mnt/base/test
+export SCRATCH_BASE_DEV=/dev/mapper/base-scratch
export SCRATCH_BASE_MNT=/mnt/base/scratch
export TEST_DIR=/mnt/test
export SCRATCH_MNT=/mnt/scratch
export FSTYP=overlay

With this change, the base fs is mounted before running tests, unmounted after running tests and recycled on _test_cycle_mount along with the overlay mounts.
This helps catching overlayfs bugs related to leaking objects in underlying (base) fs.

The standard way that overlay tests work is:
- _scratch_mkfs
- setup lower/upper dir files
- _scratch_mount (or custom overlay mount)
- (sometimes) _scratch_unmount/_scratch_mount recycle

Quoted 5 lines

To preserve expected tests behavior, the semantics are:
- _scratch_mkfs mounts the base fs, cleans the lower/upper dirs and keeps base fs mounted.
- _scratch_mount mounts or recycles base fs and mounts overlay
- _scratch_unmount unmounts overlay and base fs

I think we should do some validation on *_BASE_DEV first, to see if they could be mounted; if they're mounted already, check if they're mounted at the expected place (*_BASE_MNT). Otherwise I see test failures, which are hard to tell which part went wrong just from the failure diff message.

e.g. I tried clearing filesystem signatures (wipefs -a), mounting SCRATCH_BASE_DEV to other random dirs, I saw failures like:

overlay/002 1s ... [failed, exit status 1] - output mismatch (see /root/workspace/xfstests/results//overlay/002.out.bad)
--- tests/overlay/002.out 2016-07-01 23:17:01.029000000 +0800
+++ /root/workspace/xfstests/results//overlay/002.out.bad 2017-02-07 18:47:22.425000000 +0800
@@ -1,3 +1,3 @@
QA output created by 002
-wrote 65536/65536 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+umount: /mnt/ovl/scratch: not mounted
+failed to unmount /mnt/ovl/scratch/ovl
...
(Run 'diff -u tests/overlay/002.out /root/workspace/xfstests/results//overlay/002.out.bad' to see the entire diff)
overlay/003 1s ... - output mismatch (see /root/workspace/xfstests/results//overlay/003.out.bad)
--- tests/overlay/003.out 2016-07-01 23:17:01.029000000 +0800
+++ /root/workspace/xfstests/results//overlay/003.out.bad 2017-02-07 18:47:23.041000000 +0800
@@ -1,2 +1,12 @@
QA output created by 003
+mount: wrong fs type, bad option, bad superblock on /dev/sda6,
+ missing codepage or helper program, or other error
+
+ In some cases useful info is found in syslog - try
+ dmesg | tail or so.
+mount: wrong fs type, bad option, bad superblock on /dev/sda6,
...
(Run 'diff -u tests/overlay/003.out /root/workspace/xfstests/results//overlay/003.out.bad' to see the entire diff)

And since overlayfs configuration is going to be a bit more complex after this patchset, can you please update README to document overlayfs test as well? (Sorry, I forgot to write doc when I introduced overlayfs support..)

Thanks a lot for all your effort!

Eryu

Quoted 181 lines

Tests that use _scratch_unmount to unmount a custom overlay mount and expect to have access to overlay base dir, were converted to use explicit umount $SCRATCH_MNT instead.

---
 common/config     |  6 +++++-
 common/rc         | 42 ++++++++++++++++++++++++++++++++++++++++++
 tests/overlay/003 |  3 ++-
 tests/overlay/004 |  3 ++-
 tests/overlay/014 |  5 +++--
 5 files changed, 54 insertions(+), 5 deletions(-)
common/config +5 -1
index db5721c..f431a8d 100644
@@ -35,7 +35,9 @@
 # RMT_TAPE_DEV -    the remote tape device for the xfsdump tests
 # RMT_IRIXTAPE_DEV- the IRIX remote tape device for the xfsdump tests
 # RMT_TAPE_USER -   remote user for tape device
+# TEST_BASE_DEV -   device for base fs containing overlay test dirs
 # TEST_BASE_MNT -   mount point for base fs of overlay test dirs
+# SCRATCH_BASE_DEV- device for base fs containing overlay scratch dirs
 # SCRATCH_BASE_MNT- mount point for base fs of overlay scratch dirs
 #
 # - These can be added to $HOST_CONFIG_DIR (witch default to ./config)
@@ -470,11 +472,12 @@ _config_overlay()
 	[ -z "$TEST_DEV" ] || export TEST_BASE_DIR="$TEST_DEV"
 	[ -z "$SCRATCH_DEV" ] || export SCRATCH_BASE_DIR="$SCRATCH_DEV"
 
-	# 2. set SCRATCH/TEST_BASE_MNT to configure base fs.
+	# 2. set SCRATCH/TEST_BASE_DEV/MNT to configure base fs.
 	#    SCRATCH/TEST_DEV are derived from SCRATCH/TEST_BASE_MNT
 	#    and therein, overlay fs directories will be created.
 	[ -n "$TEST_BASE_MNT" ] || return
 
+	_check_device TEST_BASE_DEV optional $TEST_BASE_DEV
 	if [ ! -d "$TEST_BASE_MNT" ]; then
 		echo "common/config: Error: \$TEST_BASE_MNT ($TEST_BASE_MNT) is not a directory"
 		exit 1
@@ -486,6 +489,7 @@ _config_overlay()
 
 	[ -n "$SCRATCH_BASE_MNT" ] || return
 
+	_check_device SCRATCH_BASE_DEV optional $SCRATCH_BASE_DEV
 	if [ ! -d "$SCRATCH_BASE_MNT" ]; then
 		echo "common/config: Error: \$SCRATCH_BASE_MNT ($SCRATCH_BASE_MNT) is not a directory"
 		exit 1
common/rc +42 -0
index f5ab869..5033ed4 100644
@@ -320,24 +320,62 @@ _overlay_mount()
 			    $SELINUX_MOUNT_OPTIONS $* $dir $mnt
 }
 
+_overlay_test_base_mount()
+{
+	if [ -n "$TEST_BASE_DEV" -a -n "$TEST_BASE_MNT" ]; then
+		_mount $TEST_BASE_MOUNT_OPTIONS \
+			$SELINUX_MOUNT_OPTIONS \
+			$TEST_BASE_DEV $TEST_BASE_MNT
+	fi
+}
+
 _overlay_test_mount()
 {
+	_overlay_test_base_mount
 	_overlay_mount $TEST_BASE_DIR $TEST_DIR $*
 }
 
+_overlay_scratch_base_mount()
+{
+	if [ -n "$SCRATCH_BASE_DEV" -a -n "$SCRATCH_BASE_MNT" ]; then
+		_mount $SCRATCH_BASE_MOUNT_OPTIONS \
+			$SELINUX_MOUNT_OPTIONS \
+			$SCRATCH_BASE_DEV $SCRATCH_BASE_MNT
+	fi
+}
+
+_overlay_scratch_base_unmount()
+{
+	if [ -n "$SCRATCH_BASE_DEV" -a -n "$SCRATCH_BASE_MNT" ]; then
+		$UMOUNT_PROG $SCRATCH_BASE_MNT
+	fi
+}
+
 _overlay_scratch_mount()
 {
+	# base fs may be mounted after overlay mkfs
+	_overlay_scratch_base_unmount 2>/dev/null
+	_overlay_scratch_base_mount
 	_overlay_mount $SCRATCH_BASE_DIR $SCRATCH_MNT $*
 }
 
+_overlay_test_base_unmount()
+{
+	if [ -n "$TEST_BASE_DEV" -a -n "$TEST_BASE_MNT" ]; then
+		$UMOUNT_PROG $TEST_BASE_MNT
+	fi
+}
+
 _overlay_test_unmount()
 {
 	$UMOUNT_PROG $TEST_DIR
+	_overlay_test_base_unmount
 }
 
 _overlay_scratch_unmount()
 {
 	$UMOUNT_PROG $SCRATCH_MNT
+	_overlay_scratch_base_unmount
 }
 
 _scratch_mount()
@@ -643,7 +681,11 @@ _scratch_cleanup_files()
 	overlay)
 		# Avoid rm -rf /* if we messed up
 		[ -n "$SCRATCH_BASE_DIR" ] || return
+		# overlay 'mkfs' needs to make sure base fs is mounted and clean
+		_overlay_scratch_base_unmount 2>/dev/null
+		_overlay_scratch_base_mount
 		rm -rf $SCRATCH_BASE_DIR/*
+		# leave base fs mouted so tests can setup lower dir
 		;;
 	*)
 		[ -n "$SCRATCH_MNT" ] || return
tests/overlay/003 +2 -1
index bb59700..81aea85 100755
@@ -89,7 +89,8 @@ rm -rf ${SCRATCH_MNT}/*
 # nothing should be listed
 ls ${SCRATCH_MNT}/
 
-_scratch_unmount
+# unmount overlayfs but not base fs
+$UMOUNT_PROG $SCRATCH_MNT
 
 rm -rf $lowerdir
 echo "Silence is golden"
tests/overlay/004 +2 -1
index 6d78f9f..26ac547 100755
@@ -85,7 +85,8 @@ _user_do "chmod g+t ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
 _user_do "chmod u-X ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
 stat -c %a ${SCRATCH_MNT}/attr_file2
 
-_scratch_unmount
+# unmount overlayfs but not base fs
+$UMOUNT_PROG $SCRATCH_MNT
 
 # check mode bits of the file that has been copied up, and
 # the file that should not have been copied up.
tests/overlay/014 +3 -2
index 7426c31..6519432 100755
@@ -73,7 +73,8 @@ mkdir -p $lowerdir1/testdir/d
 _overlay_mount_dirs $lowerdir1 $lowerdir2 $workdir $SCRATCH_BASE_DIR $SCRATCH_MNT
 rm -rf $SCRATCH_MNT/testdir
 mkdir -p $SCRATCH_MNT/testdir/visibledir
-_scratch_unmount
+# unmount overlayfs but not base fs
+$UMOUNT_PROG $SCRATCH_MNT
 
 # mount overlay again, with lowerdir1 and lowerdir2 as multiple lowerdirs,
 # and create a new file in testdir, triggers copyup from lowerdir,
@@ -84,7 +85,7 @@ touch $SCRATCH_MNT/testdir/visiblefile
 
 # umount and mount overlay again, buggy kernel treats the copied-up dir as
 # opaque, visibledir is not seen in merged dir.
-_scratch_unmount
+$UMOUNT_PROG $SCRATCH_MNT
 _overlay_mount_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir \
 		    $SCRATCH_BASE_DIR $SCRATCH_MNT
 ls $SCRATCH_MNT/testdir
Signature · 1 line
2.7.4
#7 lore raw

Re: [PATCH v2 3/3] overlay: mount/unmount base fs before/after running tests

Quoted 24 lines · Eryu Guan
Quoted 23 lines · Amir Goldstein

Optionally configure TEST/SCRATCH_BASE_DEV, for overlay base fs to be mounted/unmounted before/after running tests. For example:

+export TEST_BASE_DEV=/dev/mapper/base-test
export TEST_BASE_MNT=/mnt/base/test
+export SCRATCH_BASE_DEV=/dev/mapper/base-scratch
export SCRATCH_BASE_MNT=/mnt/base/scratch
export TEST_DIR=/mnt/test
export SCRATCH_MNT=/mnt/scratch
export FSTYP=overlay

With this change, the base fs is mounted before running tests, unmounted after running tests and recycled on _test_cycle_mount along with the overlay mounts.
This helps catching overlayfs bugs related to leaking objects in underlying (base) fs.

The standard way that overlay tests work is:
- _scratch_mkfs
- setup lower/upper dir files
- _scratch_mount (or custom overlay mount)
- (sometimes) _scratch_unmount/_scratch_mount recycle

Quoted 12 lines
Quoted 5 lines

To preserve expected tests behavior, the semantics are:
- _scratch_mkfs mounts the base fs, cleans the lower/upper dirs and keeps base fs mounted.
- _scratch_mount mounts or recycles base fs and mounts overlay
- _scratch_unmount unmounts overlay and base fs

I think we should do some validation on *_BASE_DEV first, to see if they could be mounted; if they're mounted already, check if they're mounted at the expected place (*_BASE_MNT). Otherwise I see test failures, which are hard to tell which part went wrong just from the failure diff message.

OK. will add some sanity for OVL_*_BASE_DEV

Quoted 28 lines

e.g. I tried clearing filesystem signatures (wipefs -a), mounting SCRATCH_BASE_DEV to other random dirs, I saw failures like:

overlay/002 1s ... [failed, exit status 1] - output mismatch (see /root/workspace/xfstests/results//overlay/002.out.bad)
--- tests/overlay/002.out 2016-07-01 23:17:01.029000000 +0800
+++ /root/workspace/xfstests/results//overlay/002.out.bad 2017-02-07 18:47:22.425000000 +0800
@@ -1,3 +1,3 @@
QA output created by 002
-wrote 65536/65536 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+umount: /mnt/ovl/scratch: not mounted
+failed to unmount /mnt/ovl/scratch/ovl
...
(Run 'diff -u tests/overlay/002.out /root/workspace/xfstests/results//overlay/002.out.bad' to see the entire diff)
overlay/003 1s ... - output mismatch (see /root/workspace/xfstests/results//overlay/003.out.bad)
--- tests/overlay/003.out 2016-07-01 23:17:01.029000000 +0800
+++ /root/workspace/xfstests/results//overlay/003.out.bad 2017-02-07 18:47:23.041000000 +0800
@@ -1,2 +1,12 @@
QA output created by 003
+mount: wrong fs type, bad option, bad superblock on /dev/sda6,
+ missing codepage or helper program, or other error
+
+ In some cases useful info is found in syslog - try
+ dmesg | tail or so.
+mount: wrong fs type, bad option, bad superblock on /dev/sda6,
...
(Run 'diff -u tests/overlay/003.out /root/workspace/xfstests/results//overlay/003.out.bad' to see the entire diff)

Quoted 4 lines

And since overlayfs configuration is going to be a bit more complex after this patchset, can you please update README to document overlayfs test as well? (Sorry, I forgot to write doc when I introduced overlayfs support..)

Yes, it took me some time reading the code to understand how to configure overlayfs first time I tried :-)
Will do my best to improve README

Quoted 186 lines

Thanks a lot for all your effort!

Eryu

Quoted 181 lines

Tests that use _scratch_unmount to unmount a custom overlay mount and expect to have access to overlay base dir, were converted to use explicit umount $SCRATCH_MNT instead.

---
 common/config     |  6 +++++-
 common/rc         | 42 ++++++++++++++++++++++++++++++++++++++++++
 tests/overlay/003 |  3 ++-
 tests/overlay/004 |  3 ++-
 tests/overlay/014 |  5 +++--
 5 files changed, 54 insertions(+), 5 deletions(-)
common/config +5 -1
index db5721c..f431a8d 100644
@@ -35,7 +35,9 @@
 # RMT_TAPE_DEV -    the remote tape device for the xfsdump tests
 # RMT_IRIXTAPE_DEV- the IRIX remote tape device for the xfsdump tests
 # RMT_TAPE_USER -   remote user for tape device
+# TEST_BASE_DEV -   device for base fs containing overlay test dirs
 # TEST_BASE_MNT -   mount point for base fs of overlay test dirs
+# SCRATCH_BASE_DEV- device for base fs containing overlay scratch dirs
 # SCRATCH_BASE_MNT- mount point for base fs of overlay scratch dirs
 #
 # - These can be added to $HOST_CONFIG_DIR (witch default to ./config)
@@ -470,11 +472,12 @@ _config_overlay()
      [ -z "$TEST_DEV" ] || export TEST_BASE_DIR="$TEST_DEV"
      [ -z "$SCRATCH_DEV" ] || export SCRATCH_BASE_DIR="$SCRATCH_DEV"
 
-     # 2. set SCRATCH/TEST_BASE_MNT to configure base fs.
+     # 2. set SCRATCH/TEST_BASE_DEV/MNT to configure base fs.
      #    SCRATCH/TEST_DEV are derived from SCRATCH/TEST_BASE_MNT
      #    and therein, overlay fs directories will be created.
      [ -n "$TEST_BASE_MNT" ] || return
 
+     _check_device TEST_BASE_DEV optional $TEST_BASE_DEV
      if [ ! -d "$TEST_BASE_MNT" ]; then
              echo "common/config: Error: \$TEST_BASE_MNT ($TEST_BASE_MNT) is not a directory"
              exit 1
@@ -486,6 +489,7 @@ _config_overlay()
 
      [ -n "$SCRATCH_BASE_MNT" ] || return
 
+     _check_device SCRATCH_BASE_DEV optional $SCRATCH_BASE_DEV
      if [ ! -d "$SCRATCH_BASE_MNT" ]; then
              echo "common/config: Error: \$SCRATCH_BASE_MNT ($SCRATCH_BASE_MNT) is not a directory"
              exit 1
common/rc +42 -0
index f5ab869..5033ed4 100644
@@ -320,24 +320,62 @@ _overlay_mount()
                          $SELINUX_MOUNT_OPTIONS $* $dir $mnt
 }
 
+_overlay_test_base_mount()
+{
+     if [ -n "$TEST_BASE_DEV" -a -n "$TEST_BASE_MNT" ]; then
+             _mount $TEST_BASE_MOUNT_OPTIONS \
+                     $SELINUX_MOUNT_OPTIONS \
+                     $TEST_BASE_DEV $TEST_BASE_MNT
+     fi
+}
+
 _overlay_test_mount()
 {
+     _overlay_test_base_mount
      _overlay_mount $TEST_BASE_DIR $TEST_DIR $*
 }
 
+_overlay_scratch_base_mount()
+{
+     if [ -n "$SCRATCH_BASE_DEV" -a -n "$SCRATCH_BASE_MNT" ]; then
+             _mount $SCRATCH_BASE_MOUNT_OPTIONS \
+                     $SELINUX_MOUNT_OPTIONS \
+                     $SCRATCH_BASE_DEV $SCRATCH_BASE_MNT
+     fi
+}
+
+_overlay_scratch_base_unmount()
+{
+     if [ -n "$SCRATCH_BASE_DEV" -a -n "$SCRATCH_BASE_MNT" ]; then
+             $UMOUNT_PROG $SCRATCH_BASE_MNT
+     fi
+}
+
 _overlay_scratch_mount()
 {
+     # base fs may be mounted after overlay mkfs
+     _overlay_scratch_base_unmount 2>/dev/null
+     _overlay_scratch_base_mount
      _overlay_mount $SCRATCH_BASE_DIR $SCRATCH_MNT $*
 }
 
+_overlay_test_base_unmount()
+{
+     if [ -n "$TEST_BASE_DEV" -a -n "$TEST_BASE_MNT" ]; then
+             $UMOUNT_PROG $TEST_BASE_MNT
+     fi
+}
+
 _overlay_test_unmount()
 {
      $UMOUNT_PROG $TEST_DIR
+     _overlay_test_base_unmount
 }
 
 _overlay_scratch_unmount()
 {
      $UMOUNT_PROG $SCRATCH_MNT
+     _overlay_scratch_base_unmount
 }
 
 _scratch_mount()
@@ -643,7 +681,11 @@ _scratch_cleanup_files()
      overlay)
              # Avoid rm -rf /* if we messed up
              [ -n "$SCRATCH_BASE_DIR" ] || return
+             # overlay 'mkfs' needs to make sure base fs is mounted and clean
+             _overlay_scratch_base_unmount 2>/dev/null
+             _overlay_scratch_base_mount
              rm -rf $SCRATCH_BASE_DIR/*
+             # leave base fs mouted so tests can setup lower dir
              ;;
      *)
              [ -n "$SCRATCH_MNT" ] || return
tests/overlay/003 +2 -1
index bb59700..81aea85 100755
@@ -89,7 +89,8 @@ rm -rf ${SCRATCH_MNT}/*
 # nothing should be listed
 ls ${SCRATCH_MNT}/
 
-_scratch_unmount
+# unmount overlayfs but not base fs
+$UMOUNT_PROG $SCRATCH_MNT
 
 rm -rf $lowerdir
 echo "Silence is golden"
tests/overlay/004 +2 -1
index 6d78f9f..26ac547 100755
@@ -85,7 +85,8 @@ _user_do "chmod g+t ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
 _user_do "chmod u-X ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
 stat -c %a ${SCRATCH_MNT}/attr_file2
 
-_scratch_unmount
+# unmount overlayfs but not base fs
+$UMOUNT_PROG $SCRATCH_MNT
 
 # check mode bits of the file that has been copied up, and
 # the file that should not have been copied up.
tests/overlay/014 +3 -3
index 7426c31..6519432 100755
@@ -73,7 +73,8 @@ mkdir -p $lowerdir1/testdir/d
 _overlay_mount_dirs $lowerdir1 $lowerdir2 $workdir $SCRATCH_BASE_DIR $SCRATCH_MNT
 rm -rf $SCRATCH_MNT/testdir
 mkdir -p $SCRATCH_MNT/testdir/visibledir
-_scratch_unmount
+# unmount overlayfs but not base fs
+$UMOUNT_PROG $SCRATCH_MNT
 
 # mount overlay again, with lowerdir1 and lowerdir2 as multiple lowerdirs,
 # and create a new file in testdir, triggers copyup from lowerdir,
@@ -84,7 +85,7 @@ touch $SCRATCH_MNT/testdir/visiblefile
 
 # umount and mount overlay again, buggy kernel treats the copied-up dir as
 # opaque, visibledir is not seen in merged dir.
-_scratch_unmount
+$UMOUNT_PROG $SCRATCH_MNT
 _overlay_mount_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir \
                  $SCRATCH_BASE_DIR $SCRATCH_MNT
 ls $SCRATCH_MNT/testdir
--

2.7.4