1# vim: filetype=sh
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
27function do_unmount #cmd #opt #mnt #expect
28{
29	typeset cmd=$1
30	typeset opt=$2
31	typeset mnt=$3
32	typeset -i expect=${4-0}
33	typeset -i ret
34	typeset -i wasmounted=1
35
36	mounted $mnt || wasmounted=0
37
38	if (( expect == 0 )) ; then
39		log_must $ZFS $cmd $opt $mnt
40
41		log_must unmounted $mnt
42
43		log_note "Successfully $ZFS $cmd $opt $mnt"
44
45	else
46		log_note "$ZFS $cmd $opt $mnt"
47
48		$ZFS $cmd $opt $mnt
49		ret=$?
50		if (( ret != expect)); then
51			log_fail "'$ZFS $cmd $opt $mnt' " \
52				"unexpected return code of $ret."
53		fi
54
55		if (( wasmounted == 1 )) ; then
56			log_must mounted $mnt
57		else
58			log_must unmounted $mnt
59		fi
60		log_note "Mount status of $mnt not changed."
61	fi
62}
63
64function cleanup
65{
66	[[ -n $cwd ]] && cd $cwd
67
68	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
69	mounted $TESTPOOL/$TESTFS || \
70		log_must $ZFS $mountcmd $TESTPOOL/$TESTFS
71}
72