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_unshare_002_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_unshare_002_pos
39#
40# DESCRIPTION:
41# Verify that 'zfs unshare [-a] <filesystem|mountpoint>' is aware of legacy share.
42#
43# STRATEGY:
44# 1. Set 'zfs set sharenfs=off'
45# 2. Use 'share' to share given filesystem
46# 3. Verify that 'zfs unshare <filesystem|mountpoint>' is aware of legacy share
47# 4. Verify that 'zfs unshare -a' is aware of legacy share.
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING_STATUS: COMPLETED (2005-07-28)
54#
55# __stc_assertion_end
56#
57################################################################################
58
59verify_runnable "global"
60
61function cleanup
62{
63	typeset -i i=0
64	while (( i < ${#mntp_fs[*]} )); do
65		is_shared ${mntp_fs[i]} && \
66			log_must $UNSHARE -F nfs ${mntp_fs[i]}
67
68		((i = i + 2))
69	done
70
71	if mounted $TESTPOOL/$TESTCLONE; then
72		log_must $ZFS unmount $TESTDIR2
73	fi
74
75	[[ -d $TESTDIR2 ]] && \
76		log_must $RM -rf $TESTDIR2
77
78	if datasetexists "$TESTPOOL/$TESTCLONE"; then
79		log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE
80	fi
81
82	if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then
83		log_must $ZFS destroy -f $TESTPOOL/$TESTFS2@snapshot
84	fi
85
86	if datasetexists "$TESTPOOL/$TESTFS2"; then
87		log_must $ZFS destroy -f $TESTPOOL/$TESTFS2
88	fi
89}
90
91#
92# Main test routine.
93#
94# Given a mountpoint and file system this routine will attempt
95# to verify 'zfs unshare' is aware of legacy share.
96#
97function test_legacy_unshare # <mntp> <filesystem>
98{
99        typeset mntp=$1
100        typeset filesystem=$2
101
102	log_must $ZFS set sharenfs=off $filesystem
103       	not_shared $mntp || \
104		log_fail "'zfs set sharenfs=off' fails to make ZFS filesystem $filesystem unshared."
105
106	log_must $SHARE -F nfs $mntp
107	is_shared $mntp || \
108		log_fail "'share' command fails to share ZFS file system."
109        #
110       	# Verify 'zfs unshare <filesystem>' is aware of legacy share.
111       	#
112       	log_mustnot $ZFS unshare $filesystem
113	is_shared $mntp || \
114		log_fail "'zfs unshare <filesystem>' fails to be aware" \
115			"of legacy share."
116
117        #
118       	# Verify 'zfs unshare <filesystem>' is aware of legacy share.
119       	#
120       	log_mustnot $ZFS unshare $mntp
121	is_shared $mntp || \
122		log_fail "'zfs unshare <mountpoint>' fails to be aware" \
123			"of legacy share."
124}
125
126
127set -A mntp_fs \
128    "$TESTDIR" 	"$TESTPOOL/$TESTFS" \
129    "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \
130    "$TESTDIR2"	"$TESTPOOL/$TESTCLONE"
131
132log_assert "Verify that 'zfs unshare [-a]' is aware of legacy share."
133log_onexit cleanup
134
135log_must $ZFS create $TESTPOOL/$TESTFS2
136log_must $ZFS snapshot $TESTPOOL/$TESTFS2@snapshot
137log_must $ZFS clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE
138log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE
139
140#
141# Invoke 'test_legacy_unshare' routine to verify.
142#
143typeset -i i=0
144while (( i < ${#mntp_fs[*]} )); do
145	test_legacy_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]}
146
147	((i = i + 2))
148done
149
150
151log_note "Verify '$ZFS unshare -a' is aware of legacy share."
152
153#
154# set the 'sharenfs' property to 'off' for each filesystem
155#
156i=0
157while (( i < ${#mntp_fs[*]} )); do
158        log_must $ZFS set sharenfs=off ${mntp_fs[((i + 1))]}
159        not_shared ${mntp_fs[i]} || \
160                log_fail "'$ZFS set sharenfs=off' unshares file system failed."
161
162        ((i = i + 2))
163done
164
165#
166# Share each of the file systems via legacy share.
167#
168i=0
169while (( i < ${#mntp_fs[*]} )); do
170        $SHARE -F nfs ${mntp_fs[i]}
171        is_shared ${mntp_fs[i]} || \
172                log_fail "'$SHARE' shares ZFS filesystem failed."
173
174        ((i = i + 2))
175done
176
177#
178# Verify that 'zfs unshare -a' is aware of legacy share
179#
180log_must $ZFS unshare -a
181
182#
183# verify ZFS filesystems are still shared
184#
185i=0
186while (( i < ${#mntp_fs[*]} )); do
187        is_shared ${mntp_fs[i]} || \
188            log_fail "'$ZFS  unshare -a' fails to be aware of legacy share."
189
190        ((i = i + 2))
191done
192
193log_pass "'$ZFS unshare [-a]' succeeds to be aware of legacy share."
194
195