aboutsummaryrefslogtreecommitdiff
path: root/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh
blob: e5f786e0ae28e66b42b154ac4c17594fcb535971 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or https://opensource.org/licenses/CDDL-1.0.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# Copyright (c) 2016 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
# Verify that 'zfs unshare [-a] <filesystem|mountpoint>' is aware of legacy share.
#
# STRATEGY:
# 1. Set 'zfs set sharenfs=off'
# 2. Use 'share' to share given filesystem
# 3. Verify that 'zfs unshare <filesystem|mountpoint>' is aware of legacy share
# 4. Verify that 'zfs unshare -a' is aware of legacy share.
#

verify_runnable "global"

if is_linux; then
	log_unsupported "zfs set sharenfs=off won't unshare if already off"
fi

function cleanup
{
	typeset -i i=0
	while (( i < ${#mntp_fs[*]} )); do
		is_shared ${mntp_fs[i]} && \
			log_must eval "unshare_nfs ${mntp_fs[i]}"

		((i = i + 2))
	done

	if mounted $TESTPOOL/$TESTCLONE; then
		log_must zfs unmount $TESTDIR2
	fi

	[[ -d $TESTDIR2 ]] && \
		log_must rm -rf $TESTDIR2

	datasetexists "$TESTPOOL/$TESTCLONE" && \
		destroy_dataset $TESTPOOL/$TESTCLONE -f

	snapexists "$TESTPOOL/$TESTFS2@snapshot" && \
		destroy_dataset $TESTPOOL/$TESTFS2@snapshot -f

	datasetexists "$TESTPOOL/$TESTFS2" && \
		destroy_dataset $TESTPOOL/$TESTFS2 -f
}

#
# Main test routine.
#
# Given a mountpoint and file system this routine will attempt
# to verify 'zfs unshare' is aware of legacy share.
#
function test_legacy_unshare # <mntp> <filesystem>
{
        typeset mntp=$1
        typeset filesystem=$2

	log_must zfs set sharenfs=off $filesystem
	not_shared $mntp || \
	    log_fail "'zfs set sharenfs=off' fails to make ZFS " \
	    "filesystem $filesystem unshared."

	log_must share_nfs $mntp
	is_shared $mntp || \
	    log_fail "'share' command fails to share ZFS file system."
	#
	# Verify 'zfs unshare <filesystem>' is aware of legacy share.
	#
	log_mustnot zfs unshare $filesystem
	is_shared $mntp || \
	    log_fail "'zfs unshare <filesystem>' fails to be aware" \
	    "of legacy share."

	#
	# Verify 'zfs unshare <filesystem>' is aware of legacy share.
	#
	log_mustnot zfs unshare $mntp
	is_shared $mntp || \
	    log_fail "'zfs unshare <mountpoint>' fails to be aware" \
	    "of legacy share."
}


set -A mntp_fs \
    "$TESTDIR" "$TESTPOOL/$TESTFS" \
    "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \
    "$TESTDIR2" "$TESTPOOL/$TESTCLONE"

log_assert "Verify that 'zfs unshare [-a]' is aware of legacy share."
log_onexit cleanup

log_must zfs create $TESTPOOL/$TESTFS2
log_must zfs snapshot $TESTPOOL/$TESTFS2@snapshot
log_must zfs clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE
log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE

#
# Invoke 'test_legacy_unshare' routine to verify.
#
typeset -i i=0
while (( i < ${#mntp_fs[*]} )); do
	test_legacy_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]}

	((i = i + 2))
done


log_note "Verify 'zfs unshare -a' is aware of legacy share."

#
# set the 'sharenfs' property to 'off' for each filesystem
#
i=0
while (( i < ${#mntp_fs[*]} )); do
        log_must zfs set sharenfs=off ${mntp_fs[((i + 1))]}
        not_shared ${mntp_fs[i]} || \
                log_fail "'zfs set sharenfs=off' unshares file system failed."

        ((i = i + 2))
done

#
# Share each of the file systems via legacy share.
#
i=0
while (( i < ${#mntp_fs[*]} )); do
        share_nfs ${mntp_fs[i]}
        is_shared ${mntp_fs[i]} || \
                log_fail "'share' shares ZFS filesystem failed."

        ((i = i + 2))
done

#
# Verify that 'zfs unshare -a' is aware of legacy share
#
log_must zfs unshare -a

#
# verify ZFS filesystems are still shared
#
i=0
while (( i < ${#mntp_fs[*]} )); do
        is_shared ${mntp_fs[i]} || \
            log_fail "'zfs  unshare -a' fails to be aware of legacy share."

        ((i = i + 2))
done

log_pass "'zfs unshare [-a]' succeeds to be aware of legacy share."