mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
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:
@@ -181,11 +181,12 @@ tests = ['cache_001_pos', 'cache_002_neg', 'canmount_001_pos',
|
||||
'zfs_set_002_neg', 'zfs_set_003_neg', 'property_alias_001_pos']
|
||||
|
||||
# DISABLED: Tests need to be updated for Linux share behavior
|
||||
#[tests/functional/cli_root/zfs_share]
|
||||
#tests = ['zfs_share_001_pos', 'zfs_share_002_pos', 'zfs_share_003_pos',
|
||||
# 'zfs_share_004_pos', 'zfs_share_005_pos', 'zfs_share_006_pos',
|
||||
# 'zfs_share_007_neg', 'zfs_share_008_neg', 'zfs_share_009_neg',
|
||||
# 'zfs_share_010_neg', 'zfs_share_011_pos']
|
||||
# zfs_share_005_pos - needs investigation, probably unsupported NFS share format
|
||||
[tests/functional/cli_root/zfs_share]
|
||||
tests = ['zfs_share_001_pos', 'zfs_share_002_pos', 'zfs_share_003_pos',
|
||||
'zfs_share_004_pos', 'zfs_share_006_pos',
|
||||
'zfs_share_007_neg', 'zfs_share_008_neg', 'zfs_share_009_neg',
|
||||
'zfs_share_010_neg', 'zfs_share_011_pos']
|
||||
|
||||
[tests/functional/cli_root/zfs_snapshot]
|
||||
tests = ['zfs_snapshot_001_neg', 'zfs_snapshot_002_neg',
|
||||
@@ -203,9 +204,11 @@ tests = ['zfs_unmount_001_pos', 'zfs_unmount_002_pos', 'zfs_unmount_003_pos',
|
||||
'zfs_unmount_007_neg', 'zfs_unmount_008_neg']
|
||||
|
||||
# DISABLED: Tests need to be updated for Linux unshare behavior
|
||||
#[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_002_pos - zfs set sharenfs=off won't unshare if it was already off
|
||||
# zfs_unshare_006_pos - some distros come with Samba "user shares" disabled
|
||||
[tests/functional/cli_root/zfs_unshare]
|
||||
tests = ['zfs_unshare_001_pos', 'zfs_unshare_003_pos',
|
||||
'zfs_unshare_004_neg', 'zfs_unshare_005_neg']
|
||||
|
||||
[tests/functional/cli_root/zfs_upgrade]
|
||||
tests = ['zfs_upgrade_001_pos', 'zfs_upgrade_002_pos', 'zfs_upgrade_003_pos',
|
||||
|
||||
@@ -67,6 +67,7 @@ export MOUNT="@MOUNT@"
|
||||
export MPSTAT="@MPSTAT@"
|
||||
export MV="@MV@"
|
||||
export NAWK="@AWK@"
|
||||
export NET="@NET@"
|
||||
export NEWFS="@NEWFS@"
|
||||
export NPROC="@NPROC@"
|
||||
export PAGESIZE="@PAGESIZE@"
|
||||
|
||||
@@ -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,7 +1099,36 @@ 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 shared, 1 otherwise.
|
||||
#
|
||||
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.
|
||||
#
|
||||
@@ -1103,12 +1136,24 @@ function not_shared
|
||||
{
|
||||
typeset fs=$1
|
||||
|
||||
if is_linux; then
|
||||
log_unsupported "Currently unsupported by the test framework"
|
||||
is_shared $fs
|
||||
if (($? == 0)); then
|
||||
return 1
|
||||
fi
|
||||
|
||||
is_shared $fs
|
||||
return 0
|
||||
}
|
||||
|
||||
#
|
||||
# Given a dataset determine if it is not shared via SMB.
|
||||
#
|
||||
# Returns 0 if not shared, 1 otherwise.
|
||||
#
|
||||
function not_shared_smb
|
||||
{
|
||||
typeset fs=$1
|
||||
|
||||
is_shared_smb $fs
|
||||
if (($? == 0)); then
|
||||
return 1
|
||||
fi
|
||||
@@ -1123,12 +1168,7 @@ function unshare_fs #fs
|
||||
{
|
||||
typeset fs=$1
|
||||
|
||||
if is_linux; then
|
||||
log_unsupported "Currently unsupported by the test framework"
|
||||
return 1
|
||||
fi
|
||||
|
||||
is_shared $fs
|
||||
is_shared $fs || is_shared_smb $fs
|
||||
if (($? == 0)); then
|
||||
log_must $ZFS unshare $fs
|
||||
fi
|
||||
@@ -1136,6 +1176,78 @@ function unshare_fs #fs
|
||||
return 0
|
||||
}
|
||||
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+88
@@ -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."
|
||||
Reference in New Issue
Block a user