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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zfs_unmount_009_pos.ksh	1.2	09/05/19 SMI"
28#
29
30. $STF_SUITE/include/libtest.kshlib
31
32###############################################################################
33#
34# __stc_assertion_start
35#
36# ID: zfs_unmount_009_pos
37#
38# DESCRIPTION:
39# Verify that zfs unmount and destroy in a snapshot directory will not cause error.
40#
41# STRATEGY:
42# 1. Create a file in a zfs filesystem, snapshot it and change directory to snapshot directory
43# 2. Verify that 'zfs unmount -a'  will fail and 'zfs unmount -fa' will succeed
44# 3. Verify 'ls' and 'cd /' will succeed
45# 4. 'zfs mount -a' and change directory to snapshot directory again
46# 5. Verify that zfs destroy snapshot will succeed
47# 6. Verify 'ls' and 'cd /' will succeed
48# 7. Create zfs filesystem, create a file, snapshot it and change to snapshot directory
49# 8. Verify that zpool destroy the pool will succeed
50# 9. Verify 'ls' 'cd /' 'zpool list' and etc will succeed
51#
52# TESTABILITY: explicit
53#
54# TEST_AUTOMATION_LEVEL: automated
55#
56# CODING_STATUS: COMPLETED (2008-07-29)
57#
58# __stc_assertion_end
59#
60################################################################################
61
62verify_runnable "both"
63
64function cleanup
65{
66	DISK=${DISKS%% *}
67
68	for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
69		typeset snap=$fs@$TESTSNAP
70		if snapexists $snap; then
71			log_must $ZFS destroy $snap
72		fi
73	done
74
75	if ! poolexists $TESTPOOL && is_global_zone; then
76		log_must $ZPOOL create $TESTPOOL $DISK
77	fi
78
79	if ! datasetexists $TESTPOOL/$TESTFS; then
80		log_must $ZFS create $TESTPOOL/$TESTFS
81		log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
82	fi
83}
84
85function restore_dataset
86{
87	if ! datasetexists $TESTPOOL/$TESTFS ; then
88		log_must $ZFS create $TESTPOOL/$TESTFS
89		log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
90		log_must cd $TESTDIR
91		$ECHO hello > world
92		log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
93		log_must cd $(get_snapdir_name)/$TESTSNAP
94	fi
95}
96
97
98log_assert "zfs fource unmount and destroy in snapshot directory will not cause error."
99log_onexit cleanup
100
101for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
102	typeset snap=$fs@$TESTSNAP
103	typeset mtpt=$(get_prop mountpoint $fs)
104
105	log_must cd $mtpt
106	$ECHO hello > world
107	log_must $ZFS snapshot $snap
108	log_must cd $(get_snapdir_name)/$TESTSNAP
109
110	log_mustnot $ZFS unmount -a
111	log_must $ZFS unmount -fa
112	log_mustnot $LS
113	log_must cd /
114
115	log_must $ZFS mount -a
116	log_must cd $mtpt
117	log_must cd $(get_snapdir_name)/$TESTSNAP
118
119	if is_global_zone || [[ $fs != $TESTPOOL ]] ; then
120		log_must $ZFS destroy -rf $fs
121		log_mustnot $LS
122		log_must cd /
123	fi
124
125	restore_dataset
126done
127
128if is_global_zone ; then
129	log_must $ZPOOL destroy -f $TESTPOOL
130	log_mustnot $LS
131	log_must cd /
132fi
133
134log_must eval $ZFS list > /dev/null 2>&1
135log_must eval $ZPOOL list > /dev/null 2>&1
136log_must eval $ZPOOL status > /dev/null 2>&1
137$ZPOOL iostat > /dev/null 2>&1
138
139log_pass "zfs fource unmount and destroy in snapshot directory will not cause error."
140