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