diff mbox series

[v2,1/4] overlay: add helper for mounting rdonly overlay

Message ID d1be127cafcbbc7b25798d220e8c568bb7972a7c.1688979643.git.alexl@redhat.com (mailing list archive)
State New, archived
Headers show
Series overlayfs: Test data-only upperdirs and fs-verity | expand

Commit Message

Alexander Larsson July 10, 2023, 9:07 a.m. UTC
From: Amir Goldstein <amir73il@gmail.com>

Allow passing empty upperdir to _overlay_mount_dirs().

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Alexander Larsson <alexl@redhat.com>
---
 common/overlay | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/common/overlay b/common/overlay
index 20cafeb1..452b3b09 100644
--- a/common/overlay
+++ b/common/overlay
@@ -17,15 +17,19 @@  if [ -n "$OVL_BASE_FSTYP" ];then
 fi
 
 # helper function to do the actual overlayfs mount operation
+# accepts "-" as upperdir for non-upper overlayfs
 _overlay_mount_dirs()
 {
 	local lowerdir=$1
 	local upperdir=$2
 	local workdir=$3
 	shift 3
+	local diropts="-olowerdir=$lowerdir"
 
-	$MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \
-		    -o workdir=$workdir `_common_dev_mount_options $*`
+	[ -n "$upperdir" ] && [ "$upperdir" != "-" ] && \
+		diropts+=",upperdir=$upperdir,workdir=$workdir"
+
+	$MOUNT_PROG -t overlay $diropts `_common_dev_mount_options $*`
 }
 
 # Mount with same options/mnt/dev of scratch mount, but optionally