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