linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Eryu Guan <eguan@redhat.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
	linux-unionfs@vger.kernel.org, fstests@vger.kernel.org
Subject: [PATCH 6/6] overlay: deduplicate code in overlay mount helpers
Date: Thu, 28 Sep 2017 14:55:10 +0300	[thread overview]
Message-ID: <1506599710-9751-1-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1506495852-7295-1-git-send-email-amir73il@gmail.com>

factor out helpers _overlay_base_mount() and _overlay_base_umount()
to reduce code duplication.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---

Eryu,

Appologies for the rolling series, but since you said you are looking
into re-factoring mount option handling, I figured you may want to take
this additional cleanup as well.

Beyond reducing code duplication, this change puts the difference in
mount options for base test fs and base scratch fs in wrapper functions
and leaves the common code free of those differences.

Amir.

 common/overlay | 66 ++++++++++++++++++++++++++--------------------------------
 1 file changed, 29 insertions(+), 37 deletions(-)

diff --git a/common/overlay b/common/overlay
index c3bb9ee..79097ba 100644
--- a/common/overlay
+++ b/common/overlay
@@ -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
-- 
2.7.4

  parent reply	other threads:[~2017-09-28 11:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-27  7:04 [PATCH 0/4] fstests: fixes for config option OVERLAY_MOUNT_OPTIONS Amir Goldstein
2017-09-27  7:04 ` [PATCH 1/4] overlay: remove stale implementation of _scratch_mount_options Amir Goldstein
2017-09-27  7:04 ` [PATCH 2/4] overlay: use default overlay mount options _overlay_mount_dirs() Amir Goldstein
2017-09-27  7:50   ` Amir Goldstein
2017-09-27  8:05     ` Eryu Guan
2017-10-12  6:08       ` Eryu Guan
2017-10-11 11:33   ` Eryu Guan
2017-09-27  7:04 ` [PATCH 3/4] overlay: create helper _overlay_scratch_mount_dirs() Amir Goldstein
2017-09-27  7:04 ` [PATCH 4/4] overlay: fix _overlay_config_override of MOUNT_OPTIONS Amir Goldstein
2017-10-11 11:50   ` Eryu Guan
2017-10-11 12:35     ` Amir Goldstein
2017-09-27 10:47 ` [PATCH 5/5] overlay: move _overlay helpers to common/overlay Amir Goldstein
2017-09-28 11:55 ` Amir Goldstein [this message]
2017-09-29  1:44   ` [PATCH 6/6] overlay: deduplicate code in overlay mount helpers Eryu Guan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1506599710-9751-1-git-send-email-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=eguan@redhat.com \
    --cc=fstests@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).