mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
overlay: mount/unmount base fs before/after running tests
When TEST/SCRATCH_DEV are configured to the base fs block device, use this information to mount base fs before running tests, unmount it after running tests and cycle on _test_cycle_mount along with the overlay mounts. This helps catching overlayfs bugs related to leaking objects in underlying (base) fs. To preserve expected tests behavior, the semantics are: - _scratch_mkfs mounts the base fs, cleans all files, creates lower/upper dirs and keeps base fs mounted - _scratch_mount mounts base fs (if needed) 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 fixed to use explicit umount $SCRATCH_MNT instead. The overlay test itself, does not support formatting the base fs, so config options like MKFS_OPTIONS and FSCK_OPTIONS are ignored on 'check -overlay'. The config option MOUNT_OPTIONS is used to mount the base scratch fs. The config option TEST_FS_MOUNT_OPTS is used to mount the base test fs. The config option OVERLAY_MOUNT_OPTIONS is used to mount both test and scratch overlay mounts. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Eryu Guan <eguan@redhat.com> Signed-off-by: Eryu Guan <eguan@redhat.com>
This commit is contained in:
committed by
Eryu Guan
parent
bcba40e3df
commit
2ab614524d
@@ -363,24 +363,80 @@ _overlay_mount()
|
||||
$SELINUX_MOUNT_OPTIONS $* $dir $mnt
|
||||
}
|
||||
|
||||
_overlay_base_test_mount()
|
||||
{
|
||||
if [ -z "$OVL_BASE_TEST_DEV" -o -z "$OVL_BASE_TEST_DIR" ] || \
|
||||
_check_mounted_on OVL_BASE_TEST_DEV $OVL_BASE_TEST_DEV \
|
||||
OVL_BASE_TEST_DIR $OVL_BASE_TEST_DIR
|
||||
then
|
||||
# no base fs or already mounted
|
||||
return 0
|
||||
elif [ $? -ne 1 ]
|
||||
then
|
||||
# base fs mounted but not on mount point
|
||||
return 1
|
||||
fi
|
||||
|
||||
_mount $TEST_FS_MOUNT_OPTS \
|
||||
$SELINUX_MOUNT_OPTIONS \
|
||||
$OVL_BASE_TEST_DEV $OVL_BASE_TEST_DIR
|
||||
}
|
||||
|
||||
_overlay_test_mount()
|
||||
{
|
||||
_overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $*
|
||||
_overlay_base_test_mount && \
|
||||
_overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $*
|
||||
}
|
||||
|
||||
_overlay_base_scratch_mount()
|
||||
{
|
||||
if [ -z "$OVL_BASE_SCRATCH_DEV" -o -z "$OVL_BASE_SCRATCH_MNT" ] || \
|
||||
_check_mounted_on OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_DEV \
|
||||
OVL_BASE_SCRATCH_MNT $OVL_BASE_SCRATCH_MNT
|
||||
then
|
||||
# no base fs or already mounted
|
||||
return 0
|
||||
elif [ $? -ne 1 ]
|
||||
then
|
||||
# base fs mounted but not on mount point
|
||||
return 1
|
||||
fi
|
||||
|
||||
_mount $OVL_BASE_MOUNT_OPTIONS \
|
||||
$SELINUX_MOUNT_OPTIONS \
|
||||
$OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_MNT
|
||||
}
|
||||
|
||||
_overlay_base_scratch_unmount()
|
||||
{
|
||||
[ -n "$OVL_BASE_SCRATCH_DEV" -a -n "$OVL_BASE_SCRATCH_MNT" ] || return 0
|
||||
|
||||
$UMOUNT_PROG $OVL_BASE_SCRATCH_MNT
|
||||
}
|
||||
|
||||
_overlay_scratch_mount()
|
||||
{
|
||||
_overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
|
||||
_overlay_base_scratch_mount && \
|
||||
_overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
|
||||
}
|
||||
|
||||
_overlay_base_test_unmount()
|
||||
{
|
||||
[ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0
|
||||
|
||||
$UMOUNT_PROG $OVL_BASE_TEST_DIR
|
||||
}
|
||||
|
||||
_overlay_test_unmount()
|
||||
{
|
||||
$UMOUNT_PROG $TEST_DIR
|
||||
_overlay_base_test_unmount
|
||||
}
|
||||
|
||||
_overlay_scratch_unmount()
|
||||
{
|
||||
$UMOUNT_PROG $SCRATCH_MNT
|
||||
_overlay_base_scratch_unmount
|
||||
}
|
||||
|
||||
_scratch_mount()
|
||||
@@ -687,7 +743,10 @@ _scratch_cleanup_files()
|
||||
overlay)
|
||||
# Avoid rm -rf /* if we messed up
|
||||
[ -n "$OVL_BASE_SCRATCH_MNT" ] || return 1
|
||||
rm -rf $OVL_BASE_SCRATCH_MNT/*
|
||||
_overlay_base_scratch_mount || return 1
|
||||
rm -rf $OVL_BASE_SCRATCH_MNT/* || return 1
|
||||
_overlay_mkdirs $OVL_BASE_SCRATCH_MNT
|
||||
# leave base fs mouted so tests can setup lower/upper dir files
|
||||
;;
|
||||
*)
|
||||
[ -n "$SCRATCH_MNT" ] || return 1
|
||||
@@ -710,7 +769,7 @@ _scratch_mkfs()
|
||||
# $SCRATCH_MNT to avoid EEXIST caused by the leftover files
|
||||
# created in previous runs
|
||||
_scratch_cleanup_files
|
||||
return 0
|
||||
return $?
|
||||
;;
|
||||
tmpfs)
|
||||
# do nothing for tmpfs
|
||||
|
||||
Reference in New Issue
Block a user