overlay: deduplicate code in overlay mount helpers
authorAmir Goldstein <amir73il@gmail.com>
Thu, 28 Sep 2017 11:55:10 +0000 (14:55 +0300)
committerEryu Guan <eguan@redhat.com>
Tue, 10 Oct 2017 07:44:18 +0000 (15:44 +0800)
factor out helpers _overlay_base_mount() and _overlay_base_umount()
to reduce code duplication.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/overlay

index c3bb9ee2a0aa800685b467f7e2e9a84e726c0b8e..79097bab1a9e2227d070edb99d2b6904c277748a 100644 (file)
@@ -53,23 +53,31 @@ _overlay_mount()
                                $* $dir $mnt
 }
 
-_overlay_base_test_mount()
+_overlay_base_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
+       local devname=$1
+       local mntname=$2
+       local dev=$3
+       local mnt=$4
+       shift 4
+
+       if [ -z "$dev" -o -z "$mnt" ] || \
+               _check_mounted_on $devname $dev $mntname $mnt; then
                # no base fs or already mounted
                return 0
-       elif [ $? -ne 1 ]
-       then
+       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
+       _mount $* $dev $mnt
+}
+
+_overlay_base_test_mount()
+{
+       _overlay_base_mount OVL_BASE_TEST_DEV OVL_BASE_TEST_DIR \
+                       "$OVL_BASE_TEST_DEV" "$OVL_BASE_TEST_DIR" \
+                       $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS
 }
 
 _overlay_test_mount()
@@ -80,28 +88,9 @@ _overlay_test_mount()
 
 _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_base_mount OVL_BASE_SCRATCH_DEV OVL_BASE_SCRATCH_MNT \
+                       "$OVL_BASE_SCRATCH_DEV" "$OVL_BASE_SCRATCH_MNT" \
+                       $OVL_BASE_MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS
 }
 
 _overlay_scratch_mount()
@@ -110,23 +99,26 @@ _overlay_scratch_mount()
                _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
 }
 
-_overlay_base_test_unmount()
+_overlay_base_unmount()
 {
-       [ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0
+       local dev=$1
+       local mnt=$2
+
+       [ -n "$dev" -a -n "$mnt" ] || return 0
 
-       $UMOUNT_PROG $OVL_BASE_TEST_DIR
+       $UMOUNT_PROG $mnt
 }
 
 _overlay_test_unmount()
 {
        $UMOUNT_PROG $TEST_DIR
-       _overlay_base_test_unmount
+       _overlay_base_unmount "$OVL_BASE_TEST_DEV" "$OVL_BASE_TEST_DIR"
 }
 
 _overlay_scratch_unmount()
 {
        $UMOUNT_PROG $SCRATCH_MNT
-       _overlay_base_scratch_unmount
+       _overlay_base_unmount "$OVL_BASE_SCRATCH_DEV" "$OVL_BASE_SCRATCH_MNT"
 }
 
 # Require a specific overlayfs feature