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