diff mbox series

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

Message ID 76c983397d13212ff3105ae05fe4240d830440a9.1688634271.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 6, 2023, 9:50 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>
---
 common/overlay | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Amir Goldstein July 6, 2023, 10:07 a.m. UTC | #1
On Thu, Jul 6, 2023 at 12:51 PM <alexl@redhat.com> wrote:
>
> From: Amir Goldstein <amir73il@gmail.com>
>
> Allow passing empty upperdir to _overlay_mount_dirs().
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---

Forgot to say - you need to sign off on patches that you submit
on behalf of someone else, so please reply with SOB on those patches.

>  common/overlay | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> 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
> --
> 2.40.1
>
Alexander Larsson July 6, 2023, 10:24 a.m. UTC | #2
On Thu, Jul 6, 2023 at 11:50 AM <alexl@redhat.com> wrote:
>
> 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 --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
> --
> 2.40.1
>
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