7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_share / zfs_share_003_pos.ksh
blobb99c72ca14e5895f93de39e226a4b861ee19db88
1 #!/bin/ksh -p
3 # CDDL HEADER START
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]
20 # CDDL HEADER END
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
35 # DESCRIPTION:
36 # Invoking "zfs share <file system>" with a file system
37 # whose sharenfs property is 'off' , will fail with a
38 # return code of 1 and issue an error message.
40 # STRATEGY:
41 # 1. Make sure that the ZFS file system is unshared.
42 # 2. Mount the file system using the various combinations
43 # - zfs set sharenfs=off <file system>
44 # - zfs set sharenfs=none <file system>
45 # 3. Verify that share failed with return code of 1.
48 verify_runnable "both"
50 set -A fs \
51 "$TESTDIR" "$TESTPOOL/$TESTFS" \
52 "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1"
54 function cleanup
56 typeset -i i=0
57 while (( i < ${#fs[*]} )); do
58 log_must zfs inherit -r sharenfs ${fs[((i + 1))]}
59 log_must unshare_fs ${fs[i]}
61 ((i = i + 2))
62 done
67 # Main test routine.
69 # Given a mountpoint and file system this routine will attempt
70 # to share a legacy mountpoint and then verify the share fails as
71 # expected.
73 function test_legacy_share # mntp filesystem
75 typeset mntp=$1
76 typeset filesystem=$2
78 not_shared $mntp || \
79 log_fail "File system $filesystem is already shared."
81 if is_global_zone ; then
82 log_must zfs set sharenfs=off $filesystem
83 not_shared $mntp || \
84 log_fail "File system $filesystem is still shared (set sharenfs)."
87 zfs share $filesystem
88 ret=$?
89 (( ret == 1)) || \
90 log_fail "'zfs share $filesystem' " \
91 "unexpected return code of $ret."
93 not_shared $mntp || \
94 log_fail "file system $filesystem is shared (zfs share)."
97 log_assert "Verify that 'zfs share' with a file system " \
98 "whose sharenfs property is 'off' " \
99 "will fail with return code 1."
100 log_onexit cleanup
102 typeset -i i=0
103 while (( i < ${#fs[*]} )); do
104 test_legacy_share ${fs[i]} ${fs[((i + 1))]}
106 ((i = i + 2))
107 done
109 log_pass "Verify that 'zfs share' with a file system " \
110 "whose sharenfs property is 'off' fails."