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