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# 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 log_must zfs destroy ${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 76typeset cwd="" 77 78create_pool "$TESTPOOL" "$DISK" 79log_must zfs create $TESTPOOL/$TESTFS 80log_must mkdir -p $TESTDIR 81log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 82log_must zfs create $TESTPOOL/$TESTCTR 83log_must zfs create $TESTPOOL/$TESTCTR/$TESTFS1 84log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL 85 86typeset -i i=0 87while (( $i < ${#datasets[*]} )); do 88 datasetexists "${datasets[i]}" || \ 89 log_fail "Create datasets fail." 90 ((i = i + 1)) 91done 92 93cwd=$PWD 94log_note "'zpool destroy' without '-f' will fail " \ 95 "while pool is busy." 96 97for dir in $TESTDIR /$TESTPOOL/$TESTCTR /$TESTPOOL/$TESTCTR/$TESTFS1 ; do 98 log_must cd $dir 99 log_mustnot zpool destroy $TESTPOOL 100 101 # Need mount here, otherwise some dataset may be unmounted. 102 log_must zfs mount -a 103 104 i=0 105 while (( i < ${#datasets[*]} )); do 106 datasetexists "${datasets[i]}" || \ 107 log_fail "Dataset ${datasets[i]} removed unexpected." 108 ((i = i + 1)) 109 done 110done 111 112destroy_pool $TESTPOOL 113log_mustnot poolexists "$TESTPOOL" 114 115log_pass "'zpool destroy -f <pool>' success." 116