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