1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
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.
8#
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.
13#
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]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zfs_share_003_pos.ksh	1.2	07/01/09 SMI"
28#
29
30. $STF_SUITE/include/libtest.kshlib
31
32#################################################################################
33#
34# __stc_assertion_start
35#
36# ID: zfs_share_003_pos
37#
38# DESCRIPTION:
39# Invoking "zfs share <file system>" with a file system
40# whose sharenfs property is 'off' , will fail with a
41# return code of 1 and issue an error message.
42#
43# STRATEGY:
44# 1. Make sure that the ZFS file system is unshared.
45# 2. Mount the file system using the various combinations
46# - zfs set sharenfs=off <file system>
47# - zfs set sharenfs=none <file system>
48# 3. Verify that share failed with return code of 1.
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2005-07-04)
55#
56# __stc_assertion_end
57#
58################################################################################
59
60verify_runnable "both"
61
62set -A fs \
63    "$TESTDIR" 		"$TESTPOOL/$TESTFS" \
64    "$TESTDIR1" 	"$TESTPOOL/$TESTCTR/$TESTFS1"
65
66function cleanup
67{
68	typeset -i i=0
69	while (( i < ${#fs[*]} )); do
70		log_must $ZFS inherit -r sharenfs ${fs[((i + 1))]}
71		log_must unshare_fs ${fs[i]}
72
73		((i = i + 2))
74	done
75}
76
77
78#
79# Main test routine.
80#
81# Given a mountpoint and file system this routine will attempt
82# to share a legacy mountpoint and then verify the share fails as
83# expected.
84#
85function test_legacy_share # mntp filesystem
86{
87	typeset mntp=$1
88	typeset filesystem=$2
89
90	not_shared $mntp || \
91	    log_fail "File system $filesystem is already shared."
92
93	if is_global_zone ; then
94		log_must $ZFS set sharenfs=off $filesystem
95		not_shared $mntp || \
96		    log_fail "File system $filesystem is still shared (set sharenfs)."
97	fi
98
99	$ZFS share $filesystem
100	ret=$?
101	(( ret == 1)) || \
102	    log_fail "'$ZFS share $filesystem' " \
103		"unexpected return code of $ret."
104
105	not_shared $mntp || \
106	    log_fail "file system $filesystem is shared (zfs share)."
107}
108
109log_assert "Verify that '$ZFS share' with a file system " \
110        "whose sharenfs property is 'off'  " \
111        "will fail with return code 1."
112log_onexit cleanup
113
114typeset -i i=0
115while (( i < ${#fs[*]} )); do
116	test_legacy_share ${fs[i]} ${fs[((i + 1))]}
117
118	((i = i + 2))
119done
120
121log_pass "Verify that '$ZFS share' with a file system " \
122        "whose sharenfs property is 'off' fails."
123