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. $STF_SUITE/include/libtest.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_share_006_pos
34#
35# DESCRIPTION:
36# Verify that a dataset could not be shared but filesystems are shared.
37#
38# STRATEGY:
39# 1. Create a dataset and file system
40# 2. Set the sharenfs property on the dataset
41# 3. Verify that the dataset is unable be shared.
42# 4. Add a new file system to the dataset.
43# 5. Verify that the newly added file system be shared.
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2005-07-04)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55verify_runnable "global"
56
57function cleanup
58{
59	log_must $ZFS set sharenfs=off $TESTPOOL/$TESTCTR
60	if mounted $TESTDIR2; then
61		log_must $ZFS unmount $TESTDIR2
62	fi
63
64	datasetexists $TESTPOOL/$TESTCTR/$TESTFS2 && \
65		log_must $ZFS destroy $TESTPOOL/$TESTCTR/$TESTFS2
66
67	typeset fs=""
68	for fs in $mntp $TESTDIR1 $TESTDIR2
69	do
70		log_must unshare_fs $fs
71	done
72}
73
74#
75# Main test routine.
76#
77# Given a mountpoint and a dataset, this routine will set the
78# sharenfs property on the dataset and verify that dataset
79# is unable to be shared but the existing contained file systems
80# could be shared.
81#
82function test_ctr_share # mntp ctr
83{
84	typeset mntp=$1
85	typeset ctr=$2
86
87	not_shared $mntp || \
88	    log_fail "Mountpoint: $mntp is already shared."
89
90	log_must $ZFS set sharenfs=on $ctr
91
92	not_shared $mntp || \
93		log_fail "File system $mntp is shared (set sharenfs)."
94
95	#
96	# Add a new file system to the dataset and verify it is shared.
97	#
98	typeset mntp2=$TESTDIR2
99	log_must $ZFS create $ctr/$TESTFS2
100	log_must $ZFS set mountpoint=$mntp2 $ctr/$TESTFS2
101
102	is_shared $mntp2 || \
103	    log_fail "File system $mntp2 was not shared (set sharenfs)."
104}
105
106log_assert "Verify that a dataset could not be shared, " \
107	"but its sub-filesystems could be shared."
108log_onexit cleanup
109
110typeset mntp=$(get_prop mountpoint $TESTPOOL/$TESTCTR)
111test_ctr_share $mntp $TESTPOOL/$TESTCTR
112
113log_pass "A dataset could not be shared, " \
114	"but its sub-filesystems could be shared as expect."
115