mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-24 19:28:53 +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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user