5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2016, 2020 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
36 # Verify that 'zfs set sharenfs' and 'zfs share' shares a given dataset.
39 # 1. Invoke 'zfs set sharenfs'.
40 # 2. Verify that the file system is shared.
41 # 3. Invoke 'zfs share'.
42 # 4. Verify that the file system is shared.
43 # 5. Verify that a shared filesystem cannot be shared again.
44 # 6. Verify that share -a succeeds.
47 verify_runnable "global"
50 "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \
51 "$TESTDIR2" "$TESTPOOL/$TESTFS-clone" \
52 "$TESTDIR" "$TESTPOOL/$TESTFS"
57 while (( i < ${#fs[*]} )); do
58 log_must zfs set sharenfs=off ${fs[((i+1))]}
64 if mounted $TESTPOOL/$TESTFS-clone; then
65 log_must zfs unmount $TESTDIR2
68 datasetexists $TESTPOOL/$TESTFS-clone && \
69 log_must zfs destroy -f $TESTPOOL/$TESTFS-clone
71 if snapexists "$TESTPOOL/$TESTFS@snapshot"; then
72 log_must zfs destroy -f $TESTPOOL/$TESTFS@snapshot
82 # Given a mountpoint and file system this routine will attempt
83 # share the mountpoint and then verify it has been shared.
85 function test_share # mntp filesystem
91 log_fail "File system $filesystem is already shared."
93 log_must zfs set sharenfs=on $filesystem
95 log_fail "File system $filesystem is not shared (set sharenfs)."
98 # Verify 'zfs share' works as well.
100 log_must zfs unshare $filesystem
102 log_fail "File system $filesystem is still shared."
104 log_must zfs share $filesystem
106 log_fail "file system $filesystem is not shared (zfs share)."
108 log_note "Sharing a shared file system fails."
109 log_mustnot zfs share $filesystem
112 log_assert "Verify that 'zfs share' succeeds as root."
115 log_must zfs snapshot $TESTPOOL/$TESTFS@snapshot
116 log_must zfs clone $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS-clone
117 log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS-clone
120 while (( i < ${#fs[*]} )); do
121 test_share ${fs[i]} ${fs[((i + 1))]}
126 log_note "Verify 'zfs share -a' succeeds."
129 # Unshare each of the file systems.
132 while (( i < ${#fs[*]} )); do
139 # Try a zfs share -a and verify all file systems are shared.
141 log_must zfs share -a
144 # We need to unset __ZFS_POOL_EXCLUDE so that we include all file systems
145 # in the os-specific zfs exports file. This will be reset by the next test.
147 unset __ZFS_POOL_EXCLUDE
150 while (( i < ${#fs[*]} )); do
151 is_shared ${fs[i]} || \
152 log_fail "File system ${fs[i]} is not shared (share -a)"
154 is_exported ${fs[i]} || \
155 log_fail "File system ${fs[i]} is not exported (share -a)"
160 log_pass "'zfs share [ -a ] <filesystem>' succeeds as root."