aboutsummaryrefslogtreecommitdiffstats
path: root/tests/zfs-tests/include/libtest.shlib
diff options
context:
space:
mode:
authorLOLi <[email protected]>2016-11-29 20:22:38 +0100
committerBrian Behlendorf <[email protected]>2016-11-29 12:22:38 -0700
commit2f71caf2d926249920d1b9162550c56715cc6461 (patch)
treef970d0355d9a315d16aac3afc138f2af229b1f8f /tests/zfs-tests/include/libtest.shlib
parent251cb8dfacb51b9ad7a0e3da305c0bc5bbc1cb9e (diff)
Allow zfs unshare <protocol> -a
Allow `zfs unshare <protocol> -a` command to share or unshare all datasets of a given protocol, nfs or smb. Additionally, enable most of ZFS Test Suite zfs_share/zfs_unshare test cases. To work around some Illumos-specific functionalities ($SHARE/$UNSHARE) some function wrappers were added around them. Finally, fix and issue in smb_is_share_active() that would leave SMB shares exported when invoking 'zfs unshare -a' Reviewed-by: Giuseppe Di Natale <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Turbo Fredriksson <[email protected]> Signed-off-by: loli10K <[email protected]> Closes #3238 Closes #5367
Diffstat (limited to 'tests/zfs-tests/include/libtest.shlib')
-rw-r--r--tests/zfs-tests/include/libtest.shlib142
1 files changed, 127 insertions, 15 deletions
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib
index 62f371c58..c5fd8b78a 100644
--- a/tests/zfs-tests/include/libtest.shlib
+++ b/tests/zfs-tests/include/libtest.shlib
@@ -1052,7 +1052,7 @@ function datasetnonexists
}
#
-# Given a mountpoint, or a dataset name, determine if it is shared.
+# Given a mountpoint, or a dataset name, determine if it is shared via NFS.
#
# Returns 0 if shared, 1 otherwise.
#
@@ -1061,11 +1061,6 @@ function is_shared
typeset fs=$1
typeset mtpt
- if is_linux; then
- log_unsupported "Currently unsupported by the test framework"
- return 1
- fi
-
if [[ $fs != "/"* ]] ; then
if datasetnonexists "$fs" ; then
return 1
@@ -1080,6 +1075,15 @@ function is_shared
fi
fi
+ if is_linux; then
+ for mtpt in `$SHARE | $AWK '{print $1}'` ; do
+ if [[ $mtpt == $fs ]] ; then
+ return 0
+ fi
+ done
+ return 1
+ fi
+
for mtpt in `$SHARE | $AWK '{print $2}'` ; do
if [[ $mtpt == $fs ]] ; then
return 0
@@ -1095,18 +1099,42 @@ function is_shared
}
#
-# Given a mountpoint, determine if it is not shared.
+# Given a dataset name determine if it is shared via SMB.
#
-# Returns 0 if not shared, 1 otherwise.
+# Returns 0 if shared, 1 otherwise.
#
-function not_shared
+function is_shared_smb
{
typeset fs=$1
+ typeset mtpt
+
+ if datasetnonexists "$fs" ; then
+ return 1
+ else
+ fs=$(echo $fs | sed 's@/@_@g')
+ fi
if is_linux; then
+ for mtpt in `$NET usershare list | $AWK '{print $1}'` ; do
+ if [[ $mtpt == $fs ]] ; then
+ return 0
+ fi
+ done
+ return 1
+ else
log_unsupported "Currently unsupported by the test framework"
return 1
fi
+}
+
+#
+# Given a mountpoint, determine if it is not shared via NFS.
+#
+# Returns 0 if not shared, 1 otherwise.
+#
+function not_shared
+{
+ typeset fs=$1
is_shared $fs
if (($? == 0)); then
@@ -1117,18 +1145,30 @@ function not_shared
}
#
-# Helper function to unshare a mountpoint.
+# Given a dataset determine if it is not shared via SMB.
#
-function unshare_fs #fs
+# Returns 0 if not shared, 1 otherwise.
+#
+function not_shared_smb
{
typeset fs=$1
- if is_linux; then
- log_unsupported "Currently unsupported by the test framework"
+ is_shared_smb $fs
+ if (($? == 0)); then
return 1
fi
- is_shared $fs
+ return 0
+}
+
+#
+# Helper function to unshare a mountpoint.
+#
+function unshare_fs #fs
+{
+ typeset fs=$1
+
+ is_shared $fs || is_shared_smb $fs
if (($? == 0)); then
log_must $ZFS unshare $fs
fi
@@ -1137,6 +1177,78 @@ function unshare_fs #fs
}
#
+# Helper function to share a NFS mountpoint.
+#
+function share_nfs #fs
+{
+ typeset fs=$1
+
+ if is_linux; then
+ is_shared $fs
+ if (($? != 0)); then
+ log_must $SHARE "*:$fs"
+ fi
+ else
+ is_shared $fs
+ if (($? != 0)); then
+ log_must $SHARE -F nfs $fs
+ fi
+ fi
+
+ return 0
+}
+
+#
+# Helper function to unshare a NFS mountpoint.
+#
+function unshare_nfs #fs
+{
+ typeset fs=$1
+
+ if is_linux; then
+ is_shared $fs
+ if (($? == 0)); then
+ log_must $UNSHARE -u "*:$fs"
+ fi
+ else
+ is_shared $fs
+ if (($? == 0)); then
+ log_must $UNSHARE -F nfs $fs
+ fi
+ fi
+
+ return 0
+}
+
+#
+# Helper function to show NFS shares.
+#
+function showshares_nfs
+{
+ if is_linux; then
+ $SHARE -v
+ else
+ $SHARE -F nfs
+ fi
+
+ return 0
+}
+
+#
+# Helper function to show SMB shares.
+#
+function showshares_smb
+{
+ if is_linux; then
+ $NET usershare list
+ else
+ $SHARE -F smb
+ fi
+
+ return 0
+}
+
+#
# Check NFS server status and trigger it online.
#
function setup_nfs_server
@@ -1149,7 +1261,7 @@ function setup_nfs_server
fi
if is_linux; then
- log_unsupported "Currently unsupported by the test framework"
+ log_note "NFS server must started prior to running test framework."
return
fi