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 https://opensource.org/licenses/CDDL-1.0. 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# 29# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg 34 35# 36# DESCRIPTION: 37# 'zpool destroy -f <pool>' can forcely destroy the specified pool. 38# 39# STRATEGY: 40# 1. Create a storage pool 41# 2. Create some datasets within the pool 42# 3. Change directory to any mountpoint of these datasets, 43# Verify 'zpool destroy' without '-f' will fail. 44# 4. 'zpool destroy -f' the pool 45# 5. Verify the pool is destroyed successfully 46# 47 48verify_runnable "global" 49 50function cleanup 51{ 52 [[ -n $cwd ]] && log_must cd $cwd 53 54 if [[ -d $TESTDIR ]]; then 55 ismounted $TESTDIR && log_must umount $TESTDIR 56 log_must rm -rf $TESTDIR 57 fi 58 59 typeset -i i=0 60 while (( $i < ${#datasets[*]} )); do 61 datasetexists ${datasets[i]} && \ 62 destroy_dataset ${datasets[i]} 63 (( i = i + 1 )) 64 done 65 66 poolexists $TESTPOOL && destroy_pool $TESTPOOL 67} 68 69set -A datasets "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR/$TESTFS1" \ 70 "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" \ 71 72log_assert "'zpool destroy -f <pool>' can forcely destroy the specified pool" 73 74log_onexit cleanup 75 76create_pool $TESTPOOL $DISK0 77log_must zfs create $TESTPOOL/$TESTFS 78log_must mkdir -p $TESTDIR 79log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 80log_must zfs create $TESTPOOL/$TESTCTR 81log_must zfs create $TESTPOOL/$TESTCTR/$TESTFS1 82log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL 83 84typeset -i i=0 85while (( $i < ${#datasets[*]} )); do 86 datasetexists "${datasets[i]}" || \ 87 log_fail "Create datasets fail." 88 ((i = i + 1)) 89done 90 91log_note "'zpool destroy' without '-f' will fail " \ 92 "while pool is busy." 93 94for dir in $TESTDIR /$TESTPOOL/$TESTCTR /$TESTPOOL/$TESTCTR/$TESTFS1 ; do 95 log_must cd $dir 96 log_mustnot zpool destroy $TESTPOOL 97 98 # Need mount here, otherwise some dataset may be unmounted. 99 log_must zfs mount -a 100 101 i=0 102 while (( i < ${#datasets[*]} )); do 103 datasetexists "${datasets[i]}" || \ 104 log_fail "Dataset ${datasets[i]} removed unexpected." 105 ((i = i + 1)) 106 done 107done 108 109# 4. 'zpool destroy -f' the pool (unsupported behavior in Linux) 110if is_linux; then 111 log_must cd $cwd 112fi 113 114destroy_pool $TESTPOOL 115log_mustnot poolexists "$TESTPOOL" 116 117log_pass "'zpool destroy -f <pool>' success." 118