From c2e3c1997a3a1e5ca6907edcf4ca70bcbcb4a65e Mon Sep 17 00:00:00 2001 From: Pavel Snajdr Date: Sun, 6 Oct 2019 20:33:33 +0200 Subject: [PATCH] tests: add basic overlayfs tests --- configure.ac | 1 + tests/runfiles/linux.run | 4 + .../tests/functional/overlayfs/Makefile.am | 6 ++ .../tests/functional/overlayfs/cleanup.ksh | 34 ++++++++ .../functional/overlayfs/overlayfs_basic.ksh | 66 +++++++++++++++ .../overlayfs/overlayfs_layered.ksh | 82 +++++++++++++++++++ .../tests/functional/overlayfs/setup.ksh | 43 ++++++++++ 7 files changed, 236 insertions(+) create mode 100644 tests/zfs-tests/tests/functional/overlayfs/Makefile.am create mode 100755 tests/zfs-tests/tests/functional/overlayfs/cleanup.ksh create mode 100755 tests/zfs-tests/tests/functional/overlayfs/overlayfs_basic.ksh create mode 100755 tests/zfs-tests/tests/functional/overlayfs/overlayfs_layered.ksh create mode 100755 tests/zfs-tests/tests/functional/overlayfs/setup.ksh diff --git a/configure.ac b/configure.ac index 86abbce94959..4c53b0e47f74 100644 --- a/configure.ac +++ b/configure.ac @@ -324,6 +324,7 @@ AC_CONFIG_FILES([ tests/zfs-tests/tests/functional/no_space/Makefile tests/zfs-tests/tests/functional/nopwrite/Makefile tests/zfs-tests/tests/functional/online_offline/Makefile + tests/zfs-tests/tests/functional/overlayfs/Makefile tests/zfs-tests/tests/functional/pool_names/Makefile tests/zfs-tests/tests/functional/pool_checkpoint/Makefile tests/zfs-tests/tests/functional/poolversion/Makefile diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 352cfba13a5f..2450d5207ffe 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -701,6 +701,10 @@ tests = ['online_offline_001_pos', 'online_offline_002_neg', 'online_offline_003_neg'] tags = ['functional', 'online_offline'] +[tests/functional/overlayfs] +tests = ['overlayfs_basic', 'overlayfs_layered'] +tags = ['functional', 'overlayfs'] + [tests/functional/pool_checkpoint] tests = ['checkpoint_after_rewind', 'checkpoint_big_rewind', 'checkpoint_capacity', 'checkpoint_conf_change', 'checkpoint_discard', diff --git a/tests/zfs-tests/tests/functional/overlayfs/Makefile.am b/tests/zfs-tests/tests/functional/overlayfs/Makefile.am new file mode 100644 index 000000000000..f38457131e27 --- /dev/null +++ b/tests/zfs-tests/tests/functional/overlayfs/Makefile.am @@ -0,0 +1,6 @@ +pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/overlayfs +dist_pkgdata_SCRIPTS = \ + setup.ksh \ + cleanup.ksh \ + overlayfs_basic.ksh \ + overlayfs_layered.ksh diff --git a/tests/zfs-tests/tests/functional/overlayfs/cleanup.ksh b/tests/zfs-tests/tests/functional/overlayfs/cleanup.ksh new file mode 100755 index 000000000000..3166bd6ec16e --- /dev/null +++ b/tests/zfs-tests/tests/functional/overlayfs/cleanup.ksh @@ -0,0 +1,34 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +default_cleanup diff --git a/tests/zfs-tests/tests/functional/overlayfs/overlayfs_basic.ksh b/tests/zfs-tests/tests/functional/overlayfs/overlayfs_basic.ksh new file mode 100755 index 000000000000..8369228ccaca --- /dev/null +++ b/tests/zfs-tests/tests/functional/overlayfs/overlayfs_basic.ksh @@ -0,0 +1,66 @@ +#!/bin/ksh -p +# SPDX-License-Identifier: CDDL-1.0 OR MPL-2.0 + +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright (C) 2019 Pavel Snajdr lower/testfile +echo "upper" > upper/testfile + +# Basic overlayfs mount +log_must mount -t overlay \ + -o lowerdir=lower/,upperdir=upper/,workdir=work/ \ + none overlay/ + +# Does presented overlay have all the files we expect? +log_must stat overlay/{a, b, c, d, testfile} + +# We'd expect content of the upper test file +log_must grep upper overlay/testfile + +echo "new" > overlay/testfile + +# We'd expect content of the upper test file changed now +log_must grep new upper/testfile + +log_assert "ZFS supports being upper/lower/mnt of overlayfs as expected." diff --git a/tests/zfs-tests/tests/functional/overlayfs/overlayfs_layered.ksh b/tests/zfs-tests/tests/functional/overlayfs/overlayfs_layered.ksh new file mode 100755 index 000000000000..06b8cbae97db --- /dev/null +++ b/tests/zfs-tests/tests/functional/overlayfs/overlayfs_layered.ksh @@ -0,0 +1,82 @@ +#!/bin/ksh -p +# SPDX-License-Identifier: CDDL-1.0 OR MPL-2.0 + +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright (C) 2019 Pavel Snajdr lower/testfile +echo "mid" > middle/testfile +echo "upper" > upper/testfile + +# 1st level overlayfs mount +log_must mount -t overlay \ + -o lowerdir=lower/,upperdir=middle/,workdir=work1/ \ + -o ro \ + none merge1/ + +# 2st level overlayfs mount +log_must mount -t overlay \ + -o lowerdir=merge1/,upperdir=upper/,workdir=work2/ \ + none merge2/ + +# Does presented overlay have all the files we expect? +log_must stat merge2/{dira,dirb}/{a,b,c,d,e,f} merge2/testfile + +# We'd expect content of the upper test file +log_must grep upper merge2/testfile + +echo "new" > merge2/testfile +echo "now" > merge1/testfile + +# We'd expect content of the lower test file not changed +log_must grep orig lower/testfile + +# We'd expect content of the upper test file changed to now +log_must grep now middle/testfile + +# We'd expect content of the upper test file changed to new +log_must grep new upper/testfile + +log_assert "ZFS supports multi-layered overlayfs as expected." diff --git a/tests/zfs-tests/tests/functional/overlayfs/setup.ksh b/tests/zfs-tests/tests/functional/overlayfs/setup.ksh new file mode 100755 index 000000000000..9738d569cdb7 --- /dev/null +++ b/tests/zfs-tests/tests/functional/overlayfs/setup.ksh @@ -0,0 +1,43 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +if ! is_linux ; then + log_unsupported "overlayfs is linux-only" +elif ! grep overlay /proc/filesystems; then + log_unsupported "kernel built without overlayfs or module not loaded" +elif ! renameat2 -C ; then + log_unsupported "renameat2 not supported on this (pre-3.15) linux kernel" +fi + +DISK=${DISKS%% *} +default_setup $DISK