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_destroy_001_pos.ksh 1.3 09/08/06 SMI" 28# 29 30. $STF_SUITE/include/libtest.kshlib 31. $STF_SUITE/tests/cli_root/zfs_destroy/zfs_destroy_common.kshlib 32 33################################################################################# 34# 35# __stc_assertion_start 36# 37# ID: zfs_destroy_001_pos 38# 39# DESCRIPTION: 40# 'zfs destroy -r|-rf|-R|-Rf <fs|ctr|vol|snap>' should recursively destroy 41# all children and clones based on options. 42# 43# STRATEGY: 44# 1. Create test environment according to options. There are three test 45# models can be created. Only ctr, fs & vol; with snap; with clone. 46# 2. According to option, make the dataset busy or not. 47# 3. Run 'zfs destroy [-rRf] <dataset>' 48# 4. According to dataset and option, check if get the expected results. 49# 50# TESTABILITY: explicit 51# 52# TEST_AUTOMATION_LEVEL: automated 53# 54# CODING_STATUS: COMPLETED (2005-07-22) 55# 56# __stc_assertion_end 57# 58################################################################################ 59 60verify_runnable "both" 61 62# 63# According to parameters, 1st, create suitable testing environment. 2nd, 64# run 'zfs destroy $opt <dataset>'. 3rd, check the system status. 65# 66# $1 option of 'zfs destroy' 67# $2 dataset will be destroied. 68# 69function test_n_check 70{ 71 typeset opt=$1 72 typeset dtst=$2 73 74 if ! is_global_zone ; then 75 if [[ $dtst == $VOL || $dtst == $VOLSNAP ]]; then 76 log_note "UNSUPPORTED: Volume are unavailable in LZ." 77 return 78 fi 79 fi 80 81 # '-f' has no effect on non-filesystems 82 if [[ $opt == -f ]]; then 83 if [[ $dtst != $FS || $dtst != $CTR ]]; then 84 log_note "UNSUPPORTED: '-f ' is only available for FS." 85 return 86 fi 87 fi 88 89 # Clean the test environment and make it clear. 90 if datasetexists $CTR; then 91 log_must $ZFS destroy -Rf $CTR 92 fi 93 94 # According to option create test compatible environment. 95 case $opt in 96 -r|-rf) setup_testenv snap ;; 97 -R|-Rf) setup_testenv clone ;; 98 -f) setup_testenv ;; 99 *) log_fail "Incorrect option: '$opt'." ;; 100 esac 101 102 # 103 # According to different dataset type, create busy condition when try to 104 # destroy this dataset. 105 # 106 typeset mpt_dir 107 case $dtst in 108 $CTR|$FS) 109 if [[ $opt == *f* ]]; then 110 mpt_dir=$(get_prop mountpoint $FS) 111 make_dir_busy $mpt_dir 112 log_mustnot $ZFS destroy -rR $dtst 113 make_dir_unbusy $mpt_dir 114 fi 115 ;; 116 $VOL) 117 if [[ $opt == *f* ]]; then 118 make_dir_busy $TESTDIR1 119 log_mustnot $ZFS destroy -rR $dtst 120 make_dir_unbusy $TESTDIR1 121 fi 122 ;; 123 $FSSNAP) 124 if [[ $opt == *f* ]]; then 125 mpt_dir=$(snapshot_mountpoint $dtst) 126 init_dir=$PWD 127 make_dir_busy $mpt_dir 128 log_must $ZFS destroy -rR $dtst 129 log_must $ZFS snapshot $dtst 130 make_dir_unbusy $mpt_dir 131 fi 132 ;; 133 $VOLSNAP) 134 if [[ $opt == *f* ]]; then 135 mpt_dir=$TESTDIR1 136 init_dir=$PWD 137 make_dir_busy $mpt_dir 138 log_must $ZFS destroy -rR $dtst 139 log_must $ZFS snapshot $dtst 140 make_dir_unbusy $mpt_dir 141 fi 142 ;; 143 *) log_fail "Unsupported dataset: '$dtst'." 144 esac 145 146 # Firstly, umount ufs filesystem which was created by zfs volume. 147 if is_global_zone; then 148 log_must $UMOUNT -f $TESTDIR1 149 fi 150 # Invoke 'zfs destroy [-rRf] <dataset>' 151 log_must $ZFS destroy $opt $dtst 152 153 case $dtst in 154 $CTR) check_dataset datasetnonexists \ 155 $CTR $FS $VOL $FSSNAP $VOLSNAP 156 if [[ $opt == *R* ]]; then 157 check_dataset datasetnonexists \ 158 $FSCLONE $VOLCLONE 159 fi 160 ;; 161 $FS) check_dataset datasetexists $CTR $VOL 162 check_dataset datasetnonexists $FS 163 if [[ $opt != -f ]]; then 164 check_dataset datasetexists $VOLSNAP 165 check_dataset datasetnonexists $FSSNAP 166 fi 167 if [[ $opt == *R* ]]; then 168 check_dataset datasetexists $VOLCLONE 169 check_dataset datasetnonexists $FSCLONE 170 fi 171 ;; 172 $VOL) check_dataset datasetexists $CTR $FS $FSSNAP 173 check_dataset datasetnonexists $VOL $VOLSNAP 174 if [[ $opt == *R* ]]; then 175 check_dataset datasetexists $FSCLONE 176 check_dataset datasetnonexists $VOLCLONE 177 fi 178 ;; 179 $FSSNAP) 180 check_dataset datasetexists $CTR $FS $VOL $VOLSNAP 181 check_dataset datasetnonexists $FSSNAP 182 if [[ $opt == *R* ]]; then 183 check_dataset datasetexists $VOLCLONE 184 check_dataset datasetnonexists $FSCLONE 185 fi 186 ;; 187 $VOLSNAP) 188 check_dataset datasetexists $CTR $FS $VOL $FSSNAP 189 check_dataset datasetnonexists $VOLSNAP 190 if [[ $opt == *R* ]]; then 191 check_dataset datasetexists $FSCLONE 192 check_dataset datasetnonexists $VOLCLONE 193 fi 194 ;; 195 esac 196 197 log_note "'$ZFS destroy $opt $dtst' passed." 198} 199 200log_assert "'zfs destroy -r|-R|-f|-rf|-Rf <fs|ctr|vol|snap>' should " \ 201 "recursively destroy all children." 202log_onexit cleanup_testenv 203 204typeset dtst="" 205typeset opt="" 206for dtst in $CTR $FS $VOL $FSSNAP $VOLSNAP; do 207 for opt in "-r" "-R" "-f" "-rf" "-Rf"; do 208 log_note "Starting test: $ZFS destroy $opt $dtst" 209 test_n_check $opt $dtst 210 done 211done 212 213log_pass "'zfs destroy -r|-R|-f|-rf|-Rf <fs|ctr|vol|snap>' passed." 214