diff options
author | George Wilson <[email protected]> | 2020-07-13 11:19:18 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-13 09:19:18 -0700 |
commit | c15d36c674bcfb10975fc835978d4a49d159bf0b (patch) | |
tree | 4d4aeadaf69fe83875229d7c7bee8a7fa1b8480e /tests/zfs-tests | |
parent | e59a377a8fdbf4e66864d1654c0055fdff5f12f4 (diff) |
Remove dependency on sharetab file and refactor sharing logic
== Motivation and Context
The current implementation of 'sharenfs' and 'sharesmb' relies on
the use of the sharetab file. The use of this file is os-specific
and not required by linux or freebsd. Currently the code must
maintain updates to this file which adds complexity and presents
a significant performance impact when sharing many datasets. In
addition, concurrently running 'zfs sharenfs' command results in
missing entries in the sharetab file leading to unexpected failures.
== Description
This change removes the sharetab logic from the linux and freebsd
implementation of 'sharenfs' and 'sharesmb'. It still preserves an
os-specific library which contains the logic required for sharing
NFS or SMB. The following entry points exist in the vastly simplified
libshare library:
- sa_enable_share -- shares a dataset but may not commit the change
- sa_disable_share -- unshares a dataset but may not commit the change
- sa_is_shared -- determine if a dataset is shared
- sa_commit_share -- notify NFS/SMB subsystem to commit the shares
- sa_validate_shareopts -- determine if sharing options are valid
The sa_commit_share entry point is provided as a performance enhancement
and is not required. The sa_enable_share/sa_disable_share may commit
the share as part of the implementation. Libshare provides a framework
for both NFS and SMB but some operating systems may not fully support
these protocols or all features of the protocol.
NFS Operation:
For linux, libshare updates /etc/exports.d/zfs.exports to add
and remove shares and then commits the changes by invoking
'exportfs -r'. This file, is automatically read by the kernel NFS
implementation which makes for better integration with the NFS systemd
service. For FreeBSD, libshare updates /etc/zfs/exports to add and
remove shares and then commits the changes by sending a SIGHUP to
mountd.
SMB Operation:
For linux, libshare adds and removes files in /var/lib/samba/usershares
by calling the 'net' command directly. There is no need to commit the
changes. FreeBSD does not support SMB.
== Performance Results
To test sharing performance we created a pool with an increasing number
of datasets and invoked various zfs actions that would enable and
disable sharing. The performance testing was limited to NFS sharing.
The following tests were performed on an 8 vCPU system with 128GB and
a pool comprised of 4 50GB SSDs:
Scale testing:
- Share all filesystems in parallel -- zfs sharenfs=on <dataset> &
- Unshare all filesystems in parallel -- zfs sharenfs=off <dataset> &
Functional testing:
- share each filesystem serially -- zfs share -a
- unshare each filesystem serially -- zfs unshare -a
- reset sharenfs property and unshare -- zfs inherit -r sharenfs <pool>
For 'zfs sharenfs=on' scale testing we saw an average reduction in time
of 89.43% and for 'zfs sharenfs=off' we saw an average reduction in time
of 83.36%.
Functional testing also shows a huge improvement:
- zfs share -- 97.97% reduction in time
- zfs unshare -- 96.47% reduction in time
- zfs inhert -r sharenfs -- 99.01% reduction in time
Reviewed-by: Matt Ahrens <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Bryant G. Ly <[email protected]>
Signed-off-by: George Wilson <[email protected]>
External-Issue: DLPX-68690
Closes #1603
Closes #7692
Closes #7943
Closes #10300
Diffstat (limited to 'tests/zfs-tests')
5 files changed, 334 insertions, 10 deletions
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 5e07cda4d..1618c92bd 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -21,7 +21,7 @@ # # Copyright (c) 2009, Sun Microsystems Inc. All rights reserved. -# Copyright (c) 2012, 2018, Delphix. All rights reserved. +# Copyright (c) 2012, 2020, Delphix. All rights reserved. # Copyright (c) 2017, Tim Chase. All rights reserved. # Copyright (c) 2017, Nexenta Systems Inc. All rights reserved. # Copyright (c) 2017, Lawrence Livermore National Security LLC. @@ -1373,6 +1373,80 @@ function is_shared esac } +function is_exported_illumos +{ + typeset fs=$1 + typeset mtpt + + for mtpt in `awk '{print $1}' /etc/dfs/sharetab` ; do + if [[ $mtpt == $fs ]] ; then + return 0 + fi + done + + return 1 +} + +function is_exported_freebsd +{ + typeset fs=$1 + typeset mtpt + + for mtpt in `awk '{print $1}' /etc/zfs/exports` ; do + if [[ $mtpt == $fs ]] ; then + return 0 + fi + done + + return 1 +} + +function is_exported_linux +{ + typeset fs=$1 + typeset mtpt + + for mtpt in `awk '{print $1}' /etc/exports.d/zfs.exports` ; do + if [[ $mtpt == $fs ]] ; then + return 0 + fi + done + + return 1 +} + +# +# Given a mountpoint, or a dataset name, determine if it is exported via +# the os-specific NFS exports file. +# +# Returns 0 if exported, 1 otherwise. +# +function is_exported +{ + typeset fs=$1 + typeset mtpt + + if [[ $fs != "/"* ]] ; then + if datasetnonexists "$fs" ; then + return 1 + else + mtpt=$(get_prop mountpoint "$fs") + case $mtpt in + none|legacy|-) return 1 + ;; + *) fs=$mtpt + ;; + esac + fi + fi + + case $(uname) in + FreeBSD) is_exported_freebsd "$fs" ;; + Linux) is_exported_linux "$fs" ;; + *) is_exported_illumos "$fs" ;; + esac +} + # # Given a dataset name determine if it is shared via SMB. # @@ -1397,7 +1471,7 @@ function is_shared_smb done return 1 else - log_unsupported "Currently unsupported by the test framework" + log_note "Currently unsupported by the test framework" return 1 fi } @@ -1445,7 +1519,7 @@ function unshare_fs #fs is_shared $fs || is_shared_smb $fs if (($? == 0)); then - log_must zfs unshare $fs + zfs unshare $fs || log_fail "zfs unshare $fs failed" fi return 0 @@ -1523,6 +1597,21 @@ function showshares_smb return 0 } +function check_nfs +{ + if is_linux; then + share -s + elif is_freebsd; then + showmount -e + else + log_unsupported "Unknown platform" + fi + + if [[ $? -ne 0 ]]; then + log_unsupported "The NFS utilities are not installed" + fi +} + # # Check NFS server status and trigger it online. # @@ -1535,7 +1624,7 @@ function setup_nfs_server return fi - if is_linux || is_freebsd; then + if is_linux; then # # Re-synchronize /var/lib/nfs/etab with /etc/exports and # /etc/exports.d./* to provide a clean test environment. @@ -1544,6 +1633,11 @@ function setup_nfs_server log_note "NFS server must be started prior to running ZTS." return + elif is_freebsd; then + kill -s HUP $(cat /var/run/mountd.pid) + + log_note "NFS server must be started prior to running ZTS." + return fi typeset nfs_fmri="svc:/network/nfs/server:default" @@ -4078,3 +4172,23 @@ function get_arcstat # stat ;; esac } + +# +# Given an array of pids, wait until all processes +# have completed and check their return status. +# +function wait_for_children #children +{ + rv=0 + children=("$@") + for child in "${children[@]}" + do + child_exit=0 + wait ${child} || child_exit=$? + if [ $child_exit -ne 0 ]; then + echo "child ${child} failed with ${child_exit}" + rv=1 + fi + done + return $rv +} diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile.am index e20014656..8628b17c4 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile.am @@ -12,7 +12,8 @@ dist_pkgdata_SCRIPTS = \ zfs_share_008_neg.ksh \ zfs_share_009_neg.ksh \ zfs_share_010_neg.ksh \ - zfs_share_011_pos.ksh + zfs_share_011_pos.ksh \ + zfs_share_concurrent_shares.ksh dist_pkgdata_DATA = \ zfs_share.cfg diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/setup.ksh index 29f38e802..1601087f7 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_share/setup.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_share/setup.ksh @@ -27,10 +27,7 @@ . $STF_SUITE/include/libtest.shlib -share -s -if [ $? -ne 0 ]; then - log_unsupported "The NFS utilities are not installed" -fi +check_nfs # Make sure NFS server is running before testing. setup_nfs_server diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh index a2c06e0b3..fefeb1b1c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh @@ -26,7 +26,7 @@ # # -# Copyright (c) 2016 by Delphix. All rights reserved. +# Copyright (c) 2016, 2020 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib @@ -71,6 +71,8 @@ function cleanup if snapexists "$TESTPOOL/$TESTFS@snapshot"; then log_must zfs destroy -f $TESTPOOL/$TESTFS@snapshot fi + + log_must zfs share -a } @@ -138,11 +140,20 @@ done # log_must zfs share -a +# +# We need to unset __ZFS_POOL_EXCLUDE so that we include all file systems +# in the os-specific zfs exports file. This will be reset by the next test. +# +unset __ZFS_POOL_EXCLUDE + i=0 while (( i < ${#fs[*]} )); do is_shared ${fs[i]} || \ log_fail "File system ${fs[i]} is not shared (share -a)" + is_exported ${fs[i]} || \ + log_fail "File system ${fs[i]} is not exported (share -a)" + ((i = i + 2)) done diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_concurrent_shares.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_concurrent_shares.ksh new file mode 100755 index 000000000..bc45820a1 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_concurrent_shares.ksh @@ -0,0 +1,201 @@ +#!/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 (c) 2020 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +# +# DESCRIPTION: +# Verify that 'zfs set sharenfs=on', 'zfs share', and 'zfs unshare' can +# run concurrently. The test creates 300 filesystem and 300 threads. +# Each thread will run through the test strategy in parallel. +# +# STRATEGY: +# 1. Verify that the file system is not shared. +# 2. Enable the 'sharenfs' property +# 3. Invoke 'zfs unshare' and verify filesystem is no longer shared +# 4. Invoke 'zfs share'. +# 4. Verify that the file system is shared. +# 5. Verify that a shared filesystem cannot be shared again. +# 6. Verify that share -a succeeds. +# + +verify_runnable "global" + +function cleanup +{ + wait + for fs in $(seq 0 100) + do + log_must zfs set sharenfs=off $TESTPOOL/$TESTFS1/$fs + log_must zfs set sharenfs=off $TESTPOOL/$TESTFS2/$fs + log_must zfs set sharenfs=off $TESTPOOL/$TESTFS3/$fs + unshare_fs $TESTPOOL/$TESTFS1/$fs + unshare_fs $TESTPOOL/$TESTFS2/$fs + unshare_fs $TESTPOOL/$TESTFS3/$fs + + if mounted $TESTPOOL/$TESTFS1/$fs; then + log_must zfs unmount $TESTPOOL/$TESTFS1/$fs + fi + if mounted $TESTPOOL/$TESTFS2/$fs; then + log_must zfs unmount $TESTPOOL/$TESTFS2/$fs + fi + if mounted $TESTPOOL/$TESTFS3/$fs; then + log_must zfs unmount $TESTPOOL/$TESTFS3/$fs + fi + + datasetexists $TESTPOOL/$TESTFS1/$fs && \ + log_must zfs destroy -f $TESTPOOL/$TESTFS1/$fs + datasetexists $TESTPOOL/$TESTFS2/$fs && \ + log_must zfs destroy -f $TESTPOOL/$TESTFS2/$fs + datasetexists $TESTPOOL/$TESTFS3/$fs && \ + log_must zfs destroy -f $TESTPOOL/$TESTFS3/$fs + done + + log_must zfs share -a +} + +function create_filesystems +{ + for fs in $(seq 0 100) + do + log_must zfs create -p $TESTPOOL/$TESTFS1/$fs + log_must zfs create -p $TESTPOOL/$TESTFS2/$fs + log_must zfs create -p $TESTPOOL/$TESTFS3/$fs + done +} + +# +# Main test routine. +# +# Given a file system this routine will attempt +# share the mountpoint and then verify it has been shared. +# +function test_share # filesystem +{ + typeset filesystem=$1 + typeset mntp=$(get_prop mountpoint $filesystem) + + not_shared $mntp || \ + log_fail "File system $filesystem is already shared." + + zfs set sharenfs=on $filesystem || \ + log_fail "zfs set sharenfs=on $filesystem failed." + is_shared $mntp || \ + log_fail "File system $filesystem is not shared (set sharenfs)." + + # + # Verify 'zfs share' works as well. + # + zfs unshare $filesystem || \ + log_fail "zfs unshare $filesystem failed." + is_shared $mntp && \ + log_fail "File system $filesystem is still shared." + + zfs share $filesystem || \ + log_fail "zfs share $filesystem failed." + is_shared $mntp || \ + log_fail "file system $filesystem is not shared (zfs share)." + + #log_note "Sharing a shared file system fails." + zfs share $filesystem && \ + log_fail "zfs share $filesystem did not fail" + return 0 +} + +# +# Set the main process id so that we know to capture +# failures from child processes and allow the parent process +# to report the failure. +# +set_main_pid $$ +log_assert "Verify that 'zfs share' succeeds as root." +log_onexit cleanup + +create_filesystems + +child_pids=() +for fs in $(seq 0 100) +do + test_share $TESTPOOL/$TESTFS1/$fs & + child_pids+=($!) + log_note "$TESTPOOL/$TESTFS1/$fs ==> $!" + test_share $TESTPOOL/$TESTFS2/$fs & + child_pids+=($!) + log_note "$TESTPOOL/$TESTFS2/$fs ==> $!" + test_share $TESTPOOL/$TESTFS3/$fs & + child_pids+=($!) + log_note "$TESTPOOL/$TESTFS3/$fs ==> $!" +done +wait_for_children "${child_pids[@]}" || + log_fail "multithreaded share test failed" + +log_note "Verify 'zfs share -a' succeeds." + +# +# Unshare each of the file systems. +# +child_pids=() +for fs in $(seq 0 100) +do + unshare_fs $TESTPOOL/$TESTFS1/$fs & + child_pids+=($!) + unshare_fs $TESTPOOL/$TESTFS2/$fs & + child_pids+=($!) + unshare_fs $TESTPOOL/$TESTFS3/$fs & + child_pids+=($!) +done +wait_for_children "${child_pids[@]}" || + log_fail "multithreaded unshare failed" + +# +# Try a zfs share -a and verify all file systems are shared. +# +log_must zfs share -a + +# +# We need to unset __ZFS_POOL_EXCLUDE so that we include all file systems +# in the os-specific zfs exports file. This will be reset by the next test. +# +unset __ZFS_POOL_EXCLUDE + +for fs in $(seq 0 100) +do + is_shared $TESTPOOL/$TESTFS1/$fs || \ + log_fail "File system $TESTPOOL/$TESTFS1/$fs is not shared" + is_shared $TESTPOOL/$TESTFS2/$fs || \ + log_fail "File system $TESTPOOL/$TESTFS2/$fs is not shared" + is_shared $TESTPOOL/$TESTFS3/$fs || \ + log_fail "File system $TESTPOOL/$TESTFS3/$fs is not shared" + + is_exported $TESTPOOL/$TESTFS1/$fs || \ + log_fail "File system $TESTPOOL/$TESTFS1/$fs is not exported" + is_exported $TESTPOOL/$TESTFS2/$fs || \ + log_fail "File system $TESTPOOL/$TESTFS2/$fs is not exported" + is_exported $TESTPOOL/$TESTFS3/$fs || \ + log_fail "File system $TESTPOOL/$TESTFS3/$fs is not exported" +done + +log_pass "'zfs share [ -a ] <filesystem>' succeeds as root." |