summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Moeller <[email protected]>2020-02-21 18:59:20 -0500
committerGitHub <[email protected]>2020-02-21 15:59:20 -0800
commitb7dbbf6aa782b10e2645b3cf748406443ccd7052 (patch)
treeeff59625df3e60c3da943c5a88ea28e32a276bce
parentf5f438194df6419573eb699f9ef0c8b0e1aeaf12 (diff)
ZTS: Refactor is_shared, fix impl on FreeBSD
FreeBSD doesn't have a `share` command. It does have showmount. Split the separate platform impls out of is_shared_impl. Dispatch to the correct platform impl function from is_shared. Eliminate the use of is_shared_impl from tests. is_shared works. Reviewed-by: John Kennedy <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #10037
-rw-r--r--tests/zfs-tests/include/commands.cfg1
-rw-r--r--tests/zfs-tests/include/libtest.shlib37
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_007_pos.ksh8
3 files changed, 29 insertions, 17 deletions
diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg
index 65945212d..71b05dda0 100644
--- a/tests/zfs-tests/include/commands.cfg
+++ b/tests/zfs-tests/include/commands.cfg
@@ -127,6 +127,7 @@ export SYSTEM_FILES_FREEBSD='chflags
rmextattr
setextattr
sha256
+ showmount
swapctl
sysctl
uncompress'
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib
index d13abc4d6..e95d2edb8 100644
--- a/tests/zfs-tests/include/libtest.shlib
+++ b/tests/zfs-tests/include/libtest.shlib
@@ -1324,19 +1324,17 @@ function datasetnonexists
return 0
}
-function is_shared_impl
+function is_shared_freebsd
{
typeset fs=$1
- typeset mtpt
- if is_linux; then
- for mtpt in `share | awk '{print $1}'` ; do
- if [[ $mtpt == $fs ]] ; then
- return 0
- fi
- done
- return 1
- fi
+ showmount -E | grep -qx $fs
+}
+
+function is_shared_illumos
+{
+ typeset fs=$1
+ typeset mtpt
for mtpt in `share | awk '{print $2}'` ; do
if [[ $mtpt == $fs ]] ; then
@@ -1352,6 +1350,19 @@ function is_shared_impl
return 1
}
+function is_shared_linux
+{
+ typeset fs=$1
+ typeset mtpt
+
+ for mtpt in `share | awk '{print $1}'` ; do
+ if [[ $mtpt == $fs ]] ; then
+ return 0
+ fi
+ done
+ return 1
+}
+
#
# Given a mountpoint, or a dataset name, determine if it is shared via NFS.
#
@@ -1376,7 +1387,11 @@ function is_shared
fi
fi
- is_shared_impl "$fs"
+ case $(uname) in
+ FreeBSD) is_shared_freebsd "$fs" ;;
+ Linux) is_shared_linux "$fs" ;;
+ *) is_shared_illumos "$fs" ;;
+ esac
}
#
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
index 0749dc1b8..a5b29a896 100755
--- 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
@@ -57,16 +57,12 @@ log_must zfs create \
#
# 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"
+log_must is_shared $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_mustnot is_shared $TESTDIR/1
log_pass "'zfs destroy' will unshare the dataset."