aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPrakash Surya <[email protected]>2018-09-21 10:54:49 -0700
committerBrian Behlendorf <[email protected]>2018-10-03 10:17:58 -0700
commit54eb2c410ec8ef9f75c62e3d0e8f53ac8bdb5eea (patch)
tree46079a0f3b6bb968501419a2961bc340e2729201 /tests
parent1bf490ba930e7f46a82689fda2618d0f30365fec (diff)
Verify 'zfs destroy' will unshare the dataset
This change adds a new test case to the zfs-test suite to verify that when 'zfs destroy' is used on a shared dataset, the dataset will be unshared after the destroy operation completes. Reviewed by: loli10K <[email protected]> Reviewed by: George Wilson <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Prakash Surya <[email protected]> Closes #7941
Diffstat (limited to 'tests')
-rw-r--r--tests/runfiles/linux.run3
-rw-r--r--tests/zfs-tests/include/libtest.shlib48
-rw-r--r--tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile.am3
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_007_pos.ksh72
4 files changed, 104 insertions, 22 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
index 32bc9c328..92964139b 100644
--- a/tests/runfiles/linux.run
+++ b/tests/runfiles/linux.run
@@ -282,7 +282,8 @@ tags = ['functional', 'cli_root', 'zfs_unmount']
[tests/functional/cli_root/zfs_unshare]
tests = ['zfs_unshare_001_pos', 'zfs_unshare_002_pos', 'zfs_unshare_003_pos',
- 'zfs_unshare_004_neg', 'zfs_unshare_005_neg', 'zfs_unshare_006_pos']
+ 'zfs_unshare_004_neg', 'zfs_unshare_005_neg', 'zfs_unshare_006_pos',
+ 'zfs_unshare_007_pos']
tags = ['functional', 'cli_root', 'zfs_unshare']
[tests/functional/cli_root/zfs_upgrade]
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib
index 608f4f29b..28ee345c8 100644
--- a/tests/zfs-tests/include/libtest.shlib
+++ b/tests/zfs-tests/include/libtest.shlib
@@ -1230,30 +1230,11 @@ function datasetnonexists
return 0
}
-#
-# Given a mountpoint, or a dataset name, determine if it is shared via NFS.
-#
-# Returns 0 if shared, 1 otherwise.
-#
-function is_shared
+function is_shared_impl
{
typeset fs=$1
typeset mtpt
- if [[ $fs != "/"* ]] ; then
- if datasetnonexists "$fs" ; then
- return 1
- else
- mtpt=$(get_prop mountpoint "$fs")
- case $mtpt in
- none|legacy|-) return 1
- ;;
- *) fs=$mtpt
- ;;
- esac
- fi
- fi
-
if is_linux; then
for mtpt in `share | awk '{print $1}'` ; do
if [[ $mtpt == $fs ]] ; then
@@ -1278,6 +1259,33 @@ function is_shared
}
#
+# Given a mountpoint, or a dataset name, determine if it is shared via NFS.
+#
+# Returns 0 if shared, 1 otherwise.
+#
+function is_shared
+{
+ typeset fs=$1
+ typeset mtpt
+
+ if [[ $fs != "/"* ]] ; then
+ if datasetnonexists "$fs" ; then
+ return 1
+ else
+ mtpt=$(get_prop mountpoint "$fs")
+ case $mtpt in
+ none|legacy|-) return 1
+ ;;
+ *) fs=$mtpt
+ ;;
+ esac
+ fi
+ fi
+
+ is_shared_impl "$fs"
+}
+
+#
# Given a dataset name determine if it is shared via SMB.
#
# Returns 0 if shared, 1 otherwise.
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile.am
index e1d2e6b8a..0845f1e2f 100644
--- a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile.am
+++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile.am
@@ -7,4 +7,5 @@ dist_pkgdata_SCRIPTS = \
zfs_unshare_003_pos.ksh \
zfs_unshare_004_neg.ksh \
zfs_unshare_005_neg.ksh \
- zfs_unshare_006_pos.ksh
+ zfs_unshare_006_pos.ksh \
+ zfs_unshare_007_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_007_pos.ksh
new file mode 100755
index 000000000..0749dc1b8
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_007_pos.ksh
@@ -0,0 +1,72 @@
+#!/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 2016, loli10K. All rights reserved.
+# Copyright (c) 2018 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zfs destroy' on a shared dataset, will unshare it.
+#
+# STRATEGY:
+# 1. Create and share a dataset with sharenfs.
+# 2. Verify the dataset is shared.
+# 3. Invoke 'zfs destroy' on the dataset.
+# 4. Verify the dataset is not shared.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+ if datasetexists "$TESTPOOL/$TESTFS/shared1"; then
+ log_must zfs destroy -f $TESTPOOL/$TESTFS/shared1
+ fi
+}
+
+log_assert "Verify 'zfs destroy' will unshare the dataset"
+log_onexit cleanup
+
+# 1. Create and share a dataset with sharenfs.
+log_must zfs create \
+ -o sharenfs=on -o mountpoint=$TESTDIR/1 $TESTPOOL/$TESTFS/shared1
+
+#
+# 2. Verify the datasets is shared.
+#
+# The "non-impl" variant of "is_shared" requires the dataset to exist.
+# Thus, we can only use the "impl" variant in step 4, below. To be
+# consistent with step 4, we also use the "impl" variant here.
+#
+log_must eval "is_shared_impl $TESTDIR/1"
+
+# 3. Invoke 'zfs destroy' on the dataset.
+log_must zfs destroy -f $TESTPOOL/$TESTFS/shared1
+
+# 4. Verify the dataset is not shared.
+log_mustnot eval "is_shared_impl $TESTDIR/1"
+
+log_pass "'zfs destroy' will unshare the dataset."