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 <dinatale2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Turbo Fredriksson <turbo@bayour.com>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #3238 
Closes #5367
This commit is contained in:
LOLi
2016-11-29 20:22:38 +01:00
committed by Brian Behlendorf
parent 251cb8dfac
commit 2f71caf2d9
17 changed files with 289 additions and 48 deletions
@@ -68,7 +68,7 @@ do
log_fail "get sharenfs failed. ($option != ${shareopts[i]})"
fi
$SHARE | $GREP $option > /dev/null 2>&1
showshares_nfs | $GREP $option > /dev/null 2>&1
if (( $? != 0 )); then
log_fail "The '$option' option was not found in share output."
fi
@@ -59,7 +59,7 @@ do
log_note "Setting sharenfs=${badopts[i]} $i "
log_mustnot $ZFS set sharenfs="${badopts[i]}" $TESTPOOL/$TESTFS
$SHARE | $GREP $option > /dev/null 2>&1
showshares_nfs | $GREP $option > /dev/null 2>&1
if (( $? == 0 )); then
log_fail "An invalid setting '$option' was propagated."
fi
@@ -59,7 +59,7 @@ if [[ $sharenfs_val == off ]]; then
log_must $ZFS set sharenfs=on $fs
fi
$SHARE | $GREP $mpt >/dev/null 2>&1
showshares_nfs | $GREP $mpt >/dev/null 2>&1
if (( $? != 0 )); then
log_must $ZFS share $fs
fi
@@ -6,4 +6,5 @@ dist_pkgdata_SCRIPTS = \
zfs_unshare_002_pos.ksh \
zfs_unshare_003_pos.ksh \
zfs_unshare_004_neg.ksh \
zfs_unshare_005_neg.ksh
zfs_unshare_005_neg.ksh \
zfs_unshare_006_pos.ksh
@@ -88,7 +88,7 @@ function test_unshare # <mntp> <filesystem>
if [[ $prop_value == "off" ]]; then
not_shared $mntp ||
log_must $UNSHARE -F nfs $mntp
log_must eval "unshare_nfs $mntp"
log_must $ZFS set sharenfs=on $filesystem
is_shared $mntp || \
log_fail "'$ZFS set sharenfs=on' fails to make" \
@@ -45,7 +45,7 @@ function cleanup
typeset -i i=0
while (( i < ${#mntp_fs[*]} )); do
is_shared ${mntp_fs[i]} && \
log_must $UNSHARE -F nfs ${mntp_fs[i]}
log_must eval "unshare_nfs ${mntp_fs[i]}"
((i = i + 2))
done
@@ -86,7 +86,7 @@ function test_legacy_unshare # <mntp> <filesystem>
log_fail "'zfs set sharenfs=off' fails to make ZFS " \
"filesystem $filesystem unshared."
log_must $SHARE -F nfs $mntp
log_must eval "share_nfs $mntp"
is_shared $mntp || \
log_fail "'share' command fails to share ZFS file system."
#
@@ -150,7 +150,7 @@ done
#
i=0
while (( i < ${#mntp_fs[*]} )); do
$SHARE -F nfs ${mntp_fs[i]}
share_nfs ${mntp_fs[i]}
is_shared ${mntp_fs[i]} || \
log_fail "'$SHARE' shares ZFS filesystem failed."
@@ -68,7 +68,7 @@ function test_snap_unshare # <mntp> <filesystem>
prop_value=$(get_prop "sharenfs" $filesystem)
if [[ $prop_value == "off" ]]; then
is_shared $mntp || $UNSHARE -F nfs $mntp
is_shared $mntp || unshare_nfs $mntp
log_must $ZFS set sharenfs=on $filesystem
fi
@@ -0,0 +1,88 @@
#!/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.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# Verify that 'zfs unshare [nfs|smb] -a' unshares only filesystems shared by the
# specified protocol.
#
# STRATEGY:
# 1. Share filesystems with different protocols.
# 2. Invoke 'zfs unshare nfs -a' to unshare filesystems.
# 3. Verify that only nfs filesystems are unshared.
# 4. Share all filesystems again.
# 5. Invoke 'zfs unshare smb -a' and verify only smb filesystems are unshared.
#
verify_runnable "global"
function cleanup
{
log_must $ZFS unshare -a
log_must $ZFS destroy -f $TESTPOOL/$TESTFS/shared1
log_must $ZFS destroy -f $TESTPOOL/$TESTFS/shared2
log_must $ZFS destroy -f $TESTPOOL/$TESTFS/shared3
}
log_assert "Verify '$ZFS unshare [nfs|smb] -a' only works on the specified "\
"protocol."
log_onexit cleanup
# 1. Share filesystems with different protocols.
log_must $ZFS create $TESTPOOL/$TESTFS/shared1
log_must $ZFS create $TESTPOOL/$TESTFS/shared2
log_must $ZFS create $TESTPOOL/$TESTFS/shared3
log_must $ZFS set mountpoint=$TESTDIR/1 $TESTPOOL/$TESTFS/shared1
log_must $ZFS set mountpoint=$TESTDIR/2 $TESTPOOL/$TESTFS/shared2
log_must $ZFS set mountpoint=$TESTDIR/3 $TESTPOOL/$TESTFS/shared3
log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS/shared1
log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS/shared2
log_must $ZFS set sharesmb=on $TESTPOOL/$TESTFS/shared2
log_must $ZFS set sharesmb=on $TESTPOOL/$TESTFS/shared3
log_must $ZFS share -a
# 2. Invoke 'zfs unshare nfs -a' to unshare filesystems.
log_must $ZFS unshare nfs -a
# 3. Verify that only nfs filesystems are unshared.
log_must eval "not_shared $TESTPOOL/$TESTFS/shared1"
log_must eval "not_shared $TESTPOOL/$TESTFS/shared2"
log_must eval "is_shared_smb $TESTPOOL/$TESTFS/shared2"
log_must eval "is_shared_smb $TESTPOOL/$TESTFS/shared3"
# 4. Share all filesystems again.
log_must $ZFS share -a
# 5. Invoke 'zfs unshare smb -a' and verify only smb filesystems are unshared.
log_must $ZFS unshare smb -a
log_must eval "is_shared $TESTPOOL/$TESTFS/shared1"
log_must eval "is_shared $TESTPOOL/$TESTFS/shared2"
log_must eval "not_shared_smb $TESTPOOL/$TESTFS/shared2"
log_must eval "not_shared_smb $TESTPOOL/$TESTFS/shared3"
log_pass "'$ZFS unshare [nfs|smb] -a' only works on the specified protocol."