1d583b39bSJohn Wren Kennedy#!/bin/ksh -p
2d583b39bSJohn Wren Kennedy#
3d583b39bSJohn Wren Kennedy# CDDL HEADER START
4d583b39bSJohn Wren Kennedy#
5d583b39bSJohn Wren Kennedy# The contents of this file are subject to the terms of the
6d583b39bSJohn Wren Kennedy# Common Development and Distribution License (the "License").
7d583b39bSJohn Wren Kennedy# You may not use this file except in compliance with the License.
8d583b39bSJohn Wren Kennedy#
9d583b39bSJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d583b39bSJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11d583b39bSJohn Wren Kennedy# See the License for the specific language governing permissions
12d583b39bSJohn Wren Kennedy# and limitations under the License.
13d583b39bSJohn Wren Kennedy#
14d583b39bSJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15d583b39bSJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16d583b39bSJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17d583b39bSJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18d583b39bSJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19d583b39bSJohn Wren Kennedy#
20d583b39bSJohn Wren Kennedy# CDDL HEADER END
21d583b39bSJohn Wren Kennedy#
22d583b39bSJohn Wren Kennedy
23d583b39bSJohn Wren Kennedy#
24d583b39bSJohn Wren Kennedy# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25d583b39bSJohn Wren Kennedy# Use is subject to license terms.
26d583b39bSJohn Wren Kennedy#
27d583b39bSJohn Wren Kennedy
28*1d32ba66SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2016 by Delphix. All rights reserved.
30*1d32ba66SJohn Wren Kennedy#
31*1d32ba66SJohn Wren Kennedy
32d583b39bSJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
33d583b39bSJohn Wren Kennedy
34d583b39bSJohn Wren Kennedy#
35d583b39bSJohn Wren Kennedy# DESCRIPTION:
36d583b39bSJohn Wren Kennedy# Verify that zfs unmount and destroy in a snapshot directory will not cause error.
37d583b39bSJohn Wren Kennedy#
38d583b39bSJohn Wren Kennedy# STRATEGY:
39d583b39bSJohn Wren Kennedy# 1. Create a file in a zfs filesystem, snapshot it and change directory to snapshot directory
40d583b39bSJohn Wren Kennedy# 2. Verify that 'zfs unmount -a'  will fail and 'zfs unmount -fa' will succeed
41d583b39bSJohn Wren Kennedy# 3. Verify 'ls' and 'cd /' will succeed
42d583b39bSJohn Wren Kennedy# 4. 'zfs mount -a' and change directory to snapshot directory again
43d583b39bSJohn Wren Kennedy# 5. Verify that zfs destroy snapshot will succeed
44d583b39bSJohn Wren Kennedy# 6. Verify 'ls' and 'cd /' will succeed
45d583b39bSJohn Wren Kennedy# 7. Create zfs filesystem, create a file, snapshot it and change to snapshot directory
46d583b39bSJohn Wren Kennedy# 8. Verify that zpool destroy the pool will succeed
47d583b39bSJohn Wren Kennedy# 9. Verify 'ls' 'cd /' 'zpool list' and etc will succeed
48d583b39bSJohn Wren Kennedy#
49d583b39bSJohn Wren Kennedy
50d583b39bSJohn Wren Kennedyverify_runnable "both"
51d583b39bSJohn Wren Kennedy
52d583b39bSJohn Wren Kennedyfunction cleanup
53d583b39bSJohn Wren Kennedy{
54d583b39bSJohn Wren Kennedy	DISK=${DISKS%% *}
55d583b39bSJohn Wren Kennedy
56d583b39bSJohn Wren Kennedy	for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
57d583b39bSJohn Wren Kennedy		typeset snap=$fs@$TESTSNAP
58d583b39bSJohn Wren Kennedy		if snapexists $snap; then
59*1d32ba66SJohn Wren Kennedy			log_must zfs destroy $snap
60d583b39bSJohn Wren Kennedy		fi
61d583b39bSJohn Wren Kennedy	done
62d583b39bSJohn Wren Kennedy
63d583b39bSJohn Wren Kennedy	if ! poolexists $TESTPOOL && is_global_zone; then
64*1d32ba66SJohn Wren Kennedy		log_must zpool create $TESTPOOL $DISK
65d583b39bSJohn Wren Kennedy	fi
66d583b39bSJohn Wren Kennedy
67d583b39bSJohn Wren Kennedy	if ! datasetexists $TESTPOOL/$TESTFS; then
68*1d32ba66SJohn Wren Kennedy		log_must zfs create $TESTPOOL/$TESTFS
69*1d32ba66SJohn Wren Kennedy		log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
70d583b39bSJohn Wren Kennedy	fi
71d583b39bSJohn Wren Kennedy}
72d583b39bSJohn Wren Kennedy
73d583b39bSJohn Wren Kennedyfunction restore_dataset
74d583b39bSJohn Wren Kennedy{
75d583b39bSJohn Wren Kennedy	if ! datasetexists $TESTPOOL/$TESTFS ; then
76*1d32ba66SJohn Wren Kennedy		log_must zfs create $TESTPOOL/$TESTFS
77*1d32ba66SJohn Wren Kennedy		log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
78d583b39bSJohn Wren Kennedy		log_must cd $TESTDIR
79*1d32ba66SJohn Wren Kennedy		echo hello > world
80*1d32ba66SJohn Wren Kennedy		log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP
81d583b39bSJohn Wren Kennedy		log_must cd .zfs/snapshot/$TESTSNAP
82d583b39bSJohn Wren Kennedy	fi
83d583b39bSJohn Wren Kennedy}
84d583b39bSJohn Wren Kennedy
85d583b39bSJohn Wren Kennedy
86d583b39bSJohn Wren Kennedylog_assert "zfs fource unmount and destroy in snapshot directory will not cause error."
87d583b39bSJohn Wren Kennedylog_onexit cleanup
88d583b39bSJohn Wren Kennedy
89d583b39bSJohn Wren Kennedyfor fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
90d583b39bSJohn Wren Kennedy	typeset snap=$fs@$TESTSNAP
91d583b39bSJohn Wren Kennedy	typeset mtpt=$(get_prop mountpoint $fs)
92d583b39bSJohn Wren Kennedy
93d583b39bSJohn Wren Kennedy	log_must cd $mtpt
94*1d32ba66SJohn Wren Kennedy	echo hello > world
95*1d32ba66SJohn Wren Kennedy	log_must zfs snapshot $snap
96d583b39bSJohn Wren Kennedy	log_must cd .zfs/snapshot/$TESTSNAP
97d583b39bSJohn Wren Kennedy
98*1d32ba66SJohn Wren Kennedy	log_mustnot zfs unmount -a
99*1d32ba66SJohn Wren Kennedy	log_must zfs unmount -fa
100*1d32ba66SJohn Wren Kennedy	log_mustnot ls
101d583b39bSJohn Wren Kennedy	log_must cd /
102d583b39bSJohn Wren Kennedy
103*1d32ba66SJohn Wren Kennedy	log_must zfs mount -a
104d583b39bSJohn Wren Kennedy	log_must cd $mtpt
105d583b39bSJohn Wren Kennedy	log_must cd .zfs/snapshot/$TESTSNAP
106d583b39bSJohn Wren Kennedy
107d583b39bSJohn Wren Kennedy	if is_global_zone || [[ $fs != $TESTPOOL ]] ; then
108*1d32ba66SJohn Wren Kennedy		log_must zfs destroy -rf $fs
109*1d32ba66SJohn Wren Kennedy		log_mustnot ls
110d583b39bSJohn Wren Kennedy		log_must cd /
111d583b39bSJohn Wren Kennedy	fi
112d583b39bSJohn Wren Kennedy
113d583b39bSJohn Wren Kennedy	restore_dataset
114d583b39bSJohn Wren Kennedydone
115d583b39bSJohn Wren Kennedy
116d583b39bSJohn Wren Kennedyif is_global_zone ; then
117*1d32ba66SJohn Wren Kennedy	log_must zpool destroy -f $TESTPOOL
118*1d32ba66SJohn Wren Kennedy	log_mustnot ls
119d583b39bSJohn Wren Kennedy	log_must cd /
120d583b39bSJohn Wren Kennedyfi
121d583b39bSJohn Wren Kennedy
122*1d32ba66SJohn Wren Kennedylog_must eval zfs list > /dev/null 2>&1
123*1d32ba66SJohn Wren Kennedylog_must eval zpool list > /dev/null 2>&1
124*1d32ba66SJohn Wren Kennedylog_must eval zpool status > /dev/null 2>&1
125*1d32ba66SJohn Wren Kennedyzpool iostat > /dev/null 2>&1
126d583b39bSJohn Wren Kennedy
127d583b39bSJohn Wren Kennedylog_pass "zfs fource unmount and destroy in snapshot directory will not cause error."
128