diff mbox series

[v2,2/4] overlay: prepare for new lowerdir+,datadir+ tests

Message ID 20231204185859.3731975-3-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show
Series Overlayfs tests for 6.7-rc1 | expand

Commit Message

Amir Goldstein Dec. 4, 2023, 6:58 p.m. UTC
In preparation to forking tests for new lowerdir+,datadir+ mount options,
prepare a helper to test kernel support and pass datadirs into mount
helpers in overlay/079 test.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 common/overlay    | 15 +++++++++++++++
 tests/overlay/079 | 36 +++++++++++++++++++++---------------
 2 files changed, 36 insertions(+), 15 deletions(-)

Comments

Zorro Lang Dec. 6, 2023, 8:37 a.m. UTC | #1
On Mon, Dec 04, 2023 at 08:58:57PM +0200, Amir Goldstein wrote:
> In preparation to forking tests for new lowerdir+,datadir+ mount options,
> prepare a helper to test kernel support and pass datadirs into mount
> helpers in overlay/079 test.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  common/overlay    | 15 +++++++++++++++
>  tests/overlay/079 | 36 +++++++++++++++++++++---------------
>  2 files changed, 36 insertions(+), 15 deletions(-)
> 
> diff --git a/common/overlay b/common/overlay
> index 8f275228..ea1eb7b1 100644
> --- a/common/overlay
> +++ b/common/overlay
> @@ -247,6 +247,21 @@ _require_scratch_overlay_lowerdata_layers()
>  	_scratch_unmount
>  }
>  
> +# Check kernel support for lowerdir+=<lowerdir>,datadir+=<lowerdatadir> format
> +_require_scratch_overlay_lowerdir_add_layers()
> +{
> +	local lowerdir="$OVL_BASE_SCRATCH_MNT/$OVL_UPPER"
> +	local datadir="$OVL_BASE_SCRATCH_MNT/$OVL_LOWER"
> +
> +	_scratch_mkfs > /dev/null 2>&1
> +	$MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
> +		-o"lowerdir+=$lowerdir,datadir+=$datadir" \
> +		-o"redirect_dir=follow,metacopy=on" > /dev/null 2>&1 || \
> +	        _notrun "overlay lowerdir+,datadir+ not supported on ${SCRATCH_DEV}"

Hi Amir,

I found overlay cases don't use helpers in common/overlay recently, always
use raw $MOUNT_PROG directly (not only in this patchset). Although overlay
supports new mount format, can we improve the mount helpers in common/overlay
to support that? It would be to good to use common helpers to do common
operation.

Anyway, that can be changed in another patch, if it takes too much time or
you don't want to do it at here. What do you think?

Thanks,
Zorro

> +
> +	_scratch_unmount
> +}
> +
>  # Helper function to check underlying dirs of overlay filesystem
>  _overlay_fsck_dirs()
>  {
> diff --git a/tests/overlay/079 b/tests/overlay/079
> index 77f94598..078ee816 100755
> --- a/tests/overlay/079
> +++ b/tests/overlay/079
> @@ -139,16 +139,21 @@ check_file_size_contents()
>  
>  mount_overlay()
>  {
> -	local _lowerdir=$1
> +	local _lowerdir=$1 _datadir2=$2 _datadir=$3
>  
> -	_overlay_scratch_mount_dirs "$_lowerdir" $upperdir $workdir -o redirect_dir=on,index=on,metacopy=on
> +	$MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
> +		-o"lowerdir=$_lowerdir::$_datadir2::$_datadir" \
> +		-o"upperdir=$upperdir,workdir=$workdir" \
> +		-o redirect_dir=on,metacopy=on
>  }
>  
>  mount_ro_overlay()
>  {
> -	local _lowerdir=$1
> +	local _lowerdir=$1 _datadir2=$2 _datadir=$3
>  
> -	_overlay_scratch_mount_dirs "$_lowerdir" "-" "-" -o ro,redirect_dir=follow,metacopy=on
> +	$MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
> +		-o"lowerdir=$_lowerdir::$_datadir2::$_datadir" \
> +		-o redirect_dir=follow,metacopy=on
>  }
>  
>  umount_overlay()
> @@ -160,14 +165,14 @@ test_no_access()
>  {
>  	local _target=$1
>  
> -	mount_ro_overlay "$lowerdir::$datadir2::$datadir"
> +	mount_ro_overlay "$lowerdir" "$datadir2" "$datadir"
>  
>  	stat $SCRATCH_MNT/$_target >> $seqres.full 2>&1 || \
>  		echo "No access to lowerdata layer $_target"
>  
>  	echo "Unmount and Mount rw"
>  	umount_overlay
> -	mount_overlay "$lowerdir::$datadir2::$datadir"
> +	mount_overlay "$lowerdir" "$datadir2" "$datadir"
>  	stat $SCRATCH_MNT/$_target >> $seqres.full 2>&1 || \
>  		echo "No access to lowerdata layer $_target"
>  	umount_overlay
> @@ -175,11 +180,12 @@ test_no_access()
>  
>  test_common()
>  {
> -	local _lowerdirs=$1 _target=$2 _size=$3 _blocks=$4 _data="$5"
> -	local _redirect=$6
> +	local _lowerdir=$1 _datadir2=$2 _datadir=$3
> +	local _target=$4 _size=$5 _blocks=$6 _data="$7"
> +	local _redirect=$8
>  
>  	echo "Mount ro"
> -	mount_ro_overlay $_lowerdirs
> +	mount_ro_overlay $_lowerdir $_datadir2 $_datadir
>  
>  	# Check redirect xattr to lowerdata
>  	[ -n "$_redirect" ] && check_redirect $lowerdir/$_target "$_redirect"
> @@ -191,7 +197,7 @@ test_common()
>  	# Do a mount cycle and check size and contents again.
>  	echo "Unmount and Mount rw"
>  	umount_overlay
> -	mount_overlay $_lowerdirs
> +	mount_overlay $_lowerdir $_datadir2 $_datadir
>  	echo "check properties of metadata copied up file $_target"
>  	check_file_size_contents $SCRATCH_MNT/$_target $_size "$_data"
>  	check_file_blocks $SCRATCH_MNT/$_target $_blocks
> @@ -203,7 +209,7 @@ test_common()
>  	check_file_size_contents $upperdir/$_target $_size ""
>  
>  	# Trigger data copy up and check absence of metacopy xattr.
> -	mount_overlay $_lowerdirs
> +	mount_overlay $_lowerdir $_datadir2 $_datadir
>  	$XFS_IO_PROG -c "falloc 0 1" $SCRATCH_MNT/$_target >> $seqres.full
>  	echo "check properties of data copied up file $_target"
>  	check_file_size_contents $SCRATCH_MNT/$_target $_size "$_data"
> @@ -216,7 +222,7 @@ test_lazy()
>  {
>  	local _target=$1
>  
> -	mount_overlay "$lowerdir::$datadir2::$datadir"
> +	mount_overlay "$lowerdir" "$datadir2" "$datadir"
>  
>  	# Metadata should be valid
>  	check_file_size $SCRATCH_MNT/$_target $datasize
> @@ -305,12 +311,12 @@ test_no_access "$sharedname"
>  
>  echo -e "\n== Check follow to lowerdata layer with absolute redirect =="
>  prepare_midlayer "/subdir/$dataname"
> -test_common "$lowerdir::$datadir2::$datadir" "$dataname" $datasize $datablocks \
> +test_common "$lowerdir" "$datadir2" "$datadir" "$dataname" $datasize $datablocks \
>  		"$datacontent" "/subdir/$dataname"
> -test_common "$lowerdir::$datadir2::$datadir" "$dataname2" $datasize $datablocks \
> +test_common "$lowerdir" "$datadir2" "$datadir" "$dataname2" $datasize $datablocks \
>  		"$datacontent2" "/subdir/$dataname.2"
>  # Shared file should be picked from upper datadir
> -test_common "$lowerdir::$datadir2::$datadir" "$sharedname" $datasize $datablocks \
> +test_common "$lowerdir" "$datadir2" "$datadir" "$sharedname" $datasize $datablocks \
>  		"$datacontent2" "/subdir/$dataname.shared"
>  
>  echo -e "\n== Check lazy follow to lowerdata layer =="
> -- 
> 2.34.1
>
Amir Goldstein Dec. 6, 2023, 10:29 a.m. UTC | #2
On Wed, Dec 6, 2023 at 10:37 AM Zorro Lang <zlang@redhat.com> wrote:
>
> On Mon, Dec 04, 2023 at 08:58:57PM +0200, Amir Goldstein wrote:
> > In preparation to forking tests for new lowerdir+,datadir+ mount options,
> > prepare a helper to test kernel support and pass datadirs into mount
> > helpers in overlay/079 test.
> >
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > ---
> >  common/overlay    | 15 +++++++++++++++
> >  tests/overlay/079 | 36 +++++++++++++++++++++---------------
> >  2 files changed, 36 insertions(+), 15 deletions(-)
> >
> > diff --git a/common/overlay b/common/overlay
> > index 8f275228..ea1eb7b1 100644
> > --- a/common/overlay
> > +++ b/common/overlay
> > @@ -247,6 +247,21 @@ _require_scratch_overlay_lowerdata_layers()
> >       _scratch_unmount
> >  }
> >
> > +# Check kernel support for lowerdir+=<lowerdir>,datadir+=<lowerdatadir> format
> > +_require_scratch_overlay_lowerdir_add_layers()
> > +{
> > +     local lowerdir="$OVL_BASE_SCRATCH_MNT/$OVL_UPPER"
> > +     local datadir="$OVL_BASE_SCRATCH_MNT/$OVL_LOWER"
> > +
> > +     _scratch_mkfs > /dev/null 2>&1
> > +     $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
> > +             -o"lowerdir+=$lowerdir,datadir+=$datadir" \
> > +             -o"redirect_dir=follow,metacopy=on" > /dev/null 2>&1 || \
> > +             _notrun "overlay lowerdir+,datadir+ not supported on ${SCRATCH_DEV}"
>
> Hi Amir,
>
> I found overlay cases don't use helpers in common/overlay recently, always
> use raw $MOUNT_PROG directly (not only in this patchset). Although overlay
> supports new mount format, can we improve the mount helpers in common/overlay
> to support that? It would be to good to use common helpers to do common
> operation.
>
> Anyway, that can be changed in another patch, if it takes too much time or
> you don't want to do it at here. What do you think?

I agree. I wouldn't improve the existing helpers to support the new
lowerdir+,datadir+ options as positional argument like in
_overlay_scratch_mount_dirs(), but there is an opportunity to reduce
dedupe of this common line with a helper:

# Mount with mnt/dev of scratch mount and custom mount options
_overlay_scratch_mount_opts()
{
        $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
}

I will work on this cleanup and post a patch when I get to it.
No need to block this series for the cleanup.

Thanks,
Amir.
Zorro Lang Dec. 6, 2023, 1:35 p.m. UTC | #3
On Wed, Dec 06, 2023 at 12:29:54PM +0200, Amir Goldstein wrote:
> On Wed, Dec 6, 2023 at 10:37 AM Zorro Lang <zlang@redhat.com> wrote:
> >
> > On Mon, Dec 04, 2023 at 08:58:57PM +0200, Amir Goldstein wrote:
> > > In preparation to forking tests for new lowerdir+,datadir+ mount options,
> > > prepare a helper to test kernel support and pass datadirs into mount
> > > helpers in overlay/079 test.
> > >
> > > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > > ---
> > >  common/overlay    | 15 +++++++++++++++
> > >  tests/overlay/079 | 36 +++++++++++++++++++++---------------
> > >  2 files changed, 36 insertions(+), 15 deletions(-)
> > >
> > > diff --git a/common/overlay b/common/overlay
> > > index 8f275228..ea1eb7b1 100644
> > > --- a/common/overlay
> > > +++ b/common/overlay
> > > @@ -247,6 +247,21 @@ _require_scratch_overlay_lowerdata_layers()
> > >       _scratch_unmount
> > >  }
> > >
> > > +# Check kernel support for lowerdir+=<lowerdir>,datadir+=<lowerdatadir> format
> > > +_require_scratch_overlay_lowerdir_add_layers()
> > > +{
> > > +     local lowerdir="$OVL_BASE_SCRATCH_MNT/$OVL_UPPER"
> > > +     local datadir="$OVL_BASE_SCRATCH_MNT/$OVL_LOWER"
> > > +
> > > +     _scratch_mkfs > /dev/null 2>&1
> > > +     $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
> > > +             -o"lowerdir+=$lowerdir,datadir+=$datadir" \
> > > +             -o"redirect_dir=follow,metacopy=on" > /dev/null 2>&1 || \
> > > +             _notrun "overlay lowerdir+,datadir+ not supported on ${SCRATCH_DEV}"
> >
> > Hi Amir,
> >
> > I found overlay cases don't use helpers in common/overlay recently, always
> > use raw $MOUNT_PROG directly (not only in this patchset). Although overlay
> > supports new mount format, can we improve the mount helpers in common/overlay
> > to support that? It would be to good to use common helpers to do common
> > operation.
> >
> > Anyway, that can be changed in another patch, if it takes too much time or
> > you don't want to do it at here. What do you think?
> 
> I agree. I wouldn't improve the existing helpers to support the new
> lowerdir+,datadir+ options as positional argument like in
> _overlay_scratch_mount_dirs(), but there is an opportunity to reduce
> dedupe of this common line with a helper:
> 
> # Mount with mnt/dev of scratch mount and custom mount options
> _overlay_scratch_mount_opts()
> {
>         $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
> }
> 
> I will work on this cleanup and post a patch when I get to it.
> No need to block this series for the cleanup.

Agree, thanks for doing this!

> 
> Thanks,
> Amir.
>
diff mbox series

Patch

diff --git a/common/overlay b/common/overlay
index 8f275228..ea1eb7b1 100644
--- a/common/overlay
+++ b/common/overlay
@@ -247,6 +247,21 @@  _require_scratch_overlay_lowerdata_layers()
 	_scratch_unmount
 }
 
+# Check kernel support for lowerdir+=<lowerdir>,datadir+=<lowerdatadir> format
+_require_scratch_overlay_lowerdir_add_layers()
+{
+	local lowerdir="$OVL_BASE_SCRATCH_MNT/$OVL_UPPER"
+	local datadir="$OVL_BASE_SCRATCH_MNT/$OVL_LOWER"
+
+	_scratch_mkfs > /dev/null 2>&1
+	$MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
+		-o"lowerdir+=$lowerdir,datadir+=$datadir" \
+		-o"redirect_dir=follow,metacopy=on" > /dev/null 2>&1 || \
+	        _notrun "overlay lowerdir+,datadir+ not supported on ${SCRATCH_DEV}"
+
+	_scratch_unmount
+}
+
 # Helper function to check underlying dirs of overlay filesystem
 _overlay_fsck_dirs()
 {
diff --git a/tests/overlay/079 b/tests/overlay/079
index 77f94598..078ee816 100755
--- a/tests/overlay/079
+++ b/tests/overlay/079
@@ -139,16 +139,21 @@  check_file_size_contents()
 
 mount_overlay()
 {
-	local _lowerdir=$1
+	local _lowerdir=$1 _datadir2=$2 _datadir=$3
 
-	_overlay_scratch_mount_dirs "$_lowerdir" $upperdir $workdir -o redirect_dir=on,index=on,metacopy=on
+	$MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
+		-o"lowerdir=$_lowerdir::$_datadir2::$_datadir" \
+		-o"upperdir=$upperdir,workdir=$workdir" \
+		-o redirect_dir=on,metacopy=on
 }
 
 mount_ro_overlay()
 {
-	local _lowerdir=$1
+	local _lowerdir=$1 _datadir2=$2 _datadir=$3
 
-	_overlay_scratch_mount_dirs "$_lowerdir" "-" "-" -o ro,redirect_dir=follow,metacopy=on
+	$MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
+		-o"lowerdir=$_lowerdir::$_datadir2::$_datadir" \
+		-o redirect_dir=follow,metacopy=on
 }
 
 umount_overlay()
@@ -160,14 +165,14 @@  test_no_access()
 {
 	local _target=$1
 
-	mount_ro_overlay "$lowerdir::$datadir2::$datadir"
+	mount_ro_overlay "$lowerdir" "$datadir2" "$datadir"
 
 	stat $SCRATCH_MNT/$_target >> $seqres.full 2>&1 || \
 		echo "No access to lowerdata layer $_target"
 
 	echo "Unmount and Mount rw"
 	umount_overlay
-	mount_overlay "$lowerdir::$datadir2::$datadir"
+	mount_overlay "$lowerdir" "$datadir2" "$datadir"
 	stat $SCRATCH_MNT/$_target >> $seqres.full 2>&1 || \
 		echo "No access to lowerdata layer $_target"
 	umount_overlay
@@ -175,11 +180,12 @@  test_no_access()
 
 test_common()
 {
-	local _lowerdirs=$1 _target=$2 _size=$3 _blocks=$4 _data="$5"
-	local _redirect=$6
+	local _lowerdir=$1 _datadir2=$2 _datadir=$3
+	local _target=$4 _size=$5 _blocks=$6 _data="$7"
+	local _redirect=$8
 
 	echo "Mount ro"
-	mount_ro_overlay $_lowerdirs
+	mount_ro_overlay $_lowerdir $_datadir2 $_datadir
 
 	# Check redirect xattr to lowerdata
 	[ -n "$_redirect" ] && check_redirect $lowerdir/$_target "$_redirect"
@@ -191,7 +197,7 @@  test_common()
 	# Do a mount cycle and check size and contents again.
 	echo "Unmount and Mount rw"
 	umount_overlay
-	mount_overlay $_lowerdirs
+	mount_overlay $_lowerdir $_datadir2 $_datadir
 	echo "check properties of metadata copied up file $_target"
 	check_file_size_contents $SCRATCH_MNT/$_target $_size "$_data"
 	check_file_blocks $SCRATCH_MNT/$_target $_blocks
@@ -203,7 +209,7 @@  test_common()
 	check_file_size_contents $upperdir/$_target $_size ""
 
 	# Trigger data copy up and check absence of metacopy xattr.
-	mount_overlay $_lowerdirs
+	mount_overlay $_lowerdir $_datadir2 $_datadir
 	$XFS_IO_PROG -c "falloc 0 1" $SCRATCH_MNT/$_target >> $seqres.full
 	echo "check properties of data copied up file $_target"
 	check_file_size_contents $SCRATCH_MNT/$_target $_size "$_data"
@@ -216,7 +222,7 @@  test_lazy()
 {
 	local _target=$1
 
-	mount_overlay "$lowerdir::$datadir2::$datadir"
+	mount_overlay "$lowerdir" "$datadir2" "$datadir"
 
 	# Metadata should be valid
 	check_file_size $SCRATCH_MNT/$_target $datasize
@@ -305,12 +311,12 @@  test_no_access "$sharedname"
 
 echo -e "\n== Check follow to lowerdata layer with absolute redirect =="
 prepare_midlayer "/subdir/$dataname"
-test_common "$lowerdir::$datadir2::$datadir" "$dataname" $datasize $datablocks \
+test_common "$lowerdir" "$datadir2" "$datadir" "$dataname" $datasize $datablocks \
 		"$datacontent" "/subdir/$dataname"
-test_common "$lowerdir::$datadir2::$datadir" "$dataname2" $datasize $datablocks \
+test_common "$lowerdir" "$datadir2" "$datadir" "$dataname2" $datasize $datablocks \
 		"$datacontent2" "/subdir/$dataname.2"
 # Shared file should be picked from upper datadir
-test_common "$lowerdir::$datadir2::$datadir" "$sharedname" $datasize $datablocks \
+test_common "$lowerdir" "$datadir2" "$datadir" "$sharedname" $datasize $datablocks \
 		"$datacontent2" "/subdir/$dataname.shared"
 
 echo -e "\n== Check lazy follow to lowerdata layer =="