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