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. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
34
35# DESCRIPTION:
36#       Verify that 'zfs mount -a' succeeds as root.
37#
38# STRATEGY:
39#       1. Create a group of pools with specified vdev.
40#       2. Create zfs filesystems within the given pools.
41#       3. Unmount all the filesystems.
42#       4. Verify that 'zfs mount -a' command succeed,
43#	   and all available ZFS filesystems are mounted.
44#	5. Verify that 'zfs mount' is identical with 'df -F zfs'
45#
46
47verify_runnable "both"
48
49set -A fs "$TESTFS" "$TESTFS1"
50set -A ctr "" "$TESTCTR" "$TESTCTR/$TESTCTR1" "$TESTCTR1"
51set -A vol "$TESTVOL" "$TESTVOL1"
52
53function setup_all
54{
55	typeset -i i=0
56	typeset -i j=0
57	typeset path
58
59	while (( i < ${#ctr[*]} )); do
60
61		path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
62		if [[ -n ${ctr[i]} ]]; then
63			path=$path/${ctr[i]}
64
65			setup_filesystem "$DISKS" "$TESTPOOL" \
66				"${ctr[i]}" "$path" \
67				"ctr"
68		fi
69
70		if is_global_zone ; then
71			j=0
72			while (( j < ${#vol[*]} )); do
73				setup_filesystem "$DISKS" "$TESTPOOL" \
74					"${ctr[i]}/${vol[j]}" \
75					"$path/${vol[j]}" \
76					"vol"
77				((j = j + 1))
78			done
79		fi
80
81		j=0
82		while (( j < ${#fs[*]} )); do
83			setup_filesystem "$DISKS" "$TESTPOOL" \
84				"${ctr[i]}/${fs[j]}" \
85				"$path/${fs[j]}"
86			((j = j + 1))
87		done
88
89		((i = i + 1))
90	done
91
92	return 0
93}
94
95function cleanup_all
96{
97	typeset -i i=0
98	typeset -i j=0
99	typeset path
100
101	((i = ${#ctr[*]} - 1))
102
103	while (( i >= 0 )); do
104		if is_global_zone ; then
105			j=0
106			while (( j < ${#vol[*]} )); do
107				cleanup_filesystem "$TESTPOOL" \
108					"${ctr[i]}/${vol[j]}"
109				((j = j + 1))
110			done
111		fi
112
113		j=0
114		while (( j < ${#fs[*]} )); do
115			cleanup_filesystem "$TESTPOOL" \
116				"${ctr[i]}/${fs[j]}"
117			((j = j + 1))
118		done
119
120		[[ -n ${ctr[i]} ]] && \
121			cleanup_filesystem "$TESTPOOL" "${ctr[i]}"
122
123		((i = i - 1))
124	done
125
126	[[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
127		rm -rf ${TEST_BASE_DIR%%/}/testroot$$
128}
129
130#
131# This function takes a single true/false argument. If true it will verify that
132# all file systems are mounted. If false it will verify that they are not
133# mounted.
134#
135function verify_all
136{
137	typeset -i i=0
138	typeset -i j=0
139	typeset path
140	typeset logfunc
141
142	if $1; then
143		logfunc=log_must
144	else
145		logfunc=log_mustnot
146	fi
147
148	while (( i < ${#ctr[*]} )); do
149
150		path=$TESTPOOL
151		[[ -n ${ctr[i]} ]] && \
152			path=$path/${ctr[i]}
153
154		if is_global_zone ; then
155			j=0
156			while (( j < ${#vol[*]} )); do
157				log_mustnot mounted "$path/${vol[j]}"
158				((j = j + 1))
159			done
160		fi
161
162		j=0
163		while (( j < ${#fs[*]} )); do
164			$logfunc mounted "$path/${fs[j]}"
165			((j = j + 1))
166		done
167
168		$logfunc mounted "$path"
169
170		((i = i + 1))
171	done
172
173	return 0
174}
175
176
177log_assert "Verify that 'zfs $mountall' succeeds as root, " \
178	"and all available ZFS filesystems are mounted."
179
180log_onexit cleanup_all
181
182log_must setup_all
183
184export __ZFS_POOL_RESTRICT="$TESTPOOL"
185log_must zfs $unmountall
186unset __ZFS_POOL_RESTRICT
187
188verify_all false
189
190export __ZFS_POOL_RESTRICT="$TESTPOOL"
191log_must zfs $mountall
192unset __ZFS_POOL_RESTRICT
193
194verify_all true
195
196log_note "Verify that 'zfs $mountcmd' will display " \
197	"all ZFS filesystems currently mounted."
198
199verify_mount_display
200
201log_pass "'zfs $mountall' succeeds as root, " \
202	"and all available ZFS filesystems are mounted."
203