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