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_unmount_all_001_pos.ksh	1.3	07/07/31 SMI"
30#
31
32. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib
33. $STF_SUITE/tests/cli_root/zfs_unmount/zfs_unmount.kshlib
34
35################################################################################
36#
37# __stc_assertion_start
38#
39# ID: zfs_unmount_all_001_pos
40#
41# DESCRIPTION:
42#       Verify that 'zfs unmount -a[f]' succeeds as root.
43#
44# STRATEGY:
45#       1. Create a group of pools with specified vdev.
46#       2. Create zfs filesystems within the given pools.
47#       3. Mount all the filesystems.
48#       4. Verify that 'zfs unmount -a[f]' command succeed,
49#	   and all available ZFS filesystems are unmounted.
50#	5. Verify that 'zfs mount' is identical with 'df -F zfs'
51#
52# TESTABILITY: explicit
53#
54# TEST_AUTOMATION_LEVEL: automated
55#
56# CODING_STATUS: COMPLETED (2005-07-12)
57#
58# __stc_assertion_end
59#
60################################################################################
61
62verify_runnable "both"
63
64set -A fs "$TESTFS" "$TESTFS1"
65set -A ctr "" "$TESTCTR" "$TESTCTR1" "$TESTCTR/$TESTCTR1"
66set -A vol "$TESTVOL" "$TESTVOL1"
67
68function setup_all
69{
70	typeset -i i=0
71	typeset -i j=0
72	typeset path
73
74	while (( i < ${#ctr[*]} )); do
75
76		path=${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID}/$TESTPOOL
77		if [[ -n ${ctr[i]} ]]; then
78			path=$path/${ctr[i]}
79
80			setup_filesystem "$DISKS" "$TESTPOOL" \
81				"${ctr[i]}" "$path" \
82				"ctr"
83		fi
84
85		if is_global_zone ; then
86			j=0
87			while (( j < ${#vol[*]} )); do
88				setup_filesystem "$DISKS" "$TESTPOOL" \
89				"${ctr[i]}/${vol[j]}" \
90					"$path/${vol[j]}" \
91					"vol"
92				((j = j + 1))
93			done
94		fi
95		j=0
96		while (( j < ${#fs[*]} )); do
97			setup_filesystem "$DISKS" "$TESTPOOL" \
98				"${ctr[i]}/${fs[j]}" \
99				"$path/${fs[j]}"
100			((j = j + 1))
101		done
102
103		((i = i + 1))
104	done
105
106	return 0
107}
108
109function cleanup_all
110{
111	typeset -i i=0
112	typeset -i j=0
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_must unmounted "$path/${vol[j]}"
159				((j = j + 1))
160			done
161		fi
162
163		j=0
164		while (( j < ${#fs[*]} )); do
165			log_must unmounted "$path/${fs[j]}"
166			((j = j + 1))
167		done
168
169		log_must unmounted "$path"
170
171		((i = i + 1))
172	done
173
174	return 0
175}
176
177
178log_assert "Verify that 'zfs $unmountall' succeeds as root, " \
179	"and all available ZFS filesystems are unmounted."
180
181log_onexit cleanup_all
182
183log_must setup_all
184
185typeset opt
186for opt in "-a" "-fa"; do
187	log_must $ZFS $mountall
188
189	if [[ $opt == "-fa" ]]; then
190		mntpnt=$(get_prop mountpoint ${TESTPOOL}/${TESTCTR}/${TESTFS})
191		cd $mntpnt
192		log_mustnot $ZFS unmount -a
193	fi
194
195	log_must $ZFS unmount $opt
196
197	if [[ $opt == "-fa" ]]; then
198		cd  /tmp
199	fi
200
201	log_must verify_all
202	log_note "Verify that 'zfs $mountcmd' will display " \
203	"all ZFS filesystems currently mounted."
204	log_must verify_mount_display
205
206done
207
208log_pass "'zfs mount -[f]a' succeeds as root, " \
209	"and all available ZFS filesystems are unmounted."
210