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# $FreeBSD$ 24 25# 26# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)zfs_destroy_004_pos.ksh 1.2 07/01/09 SMI" 30# 31. $STF_SUITE/include/libtest.kshlib 32 33################################################################################ 34# 35# __stc_assertion_start 36# 37# ID: zfs_destroy_004_pos 38# 39# DESCRIPTION: 40# Verify 'zfs destroy -f' succeeds as root. 41# 42# STRATEGY: 43# 1. Create filesystem in the storage pool 44# 2. Set mountpoint for the filesystem and make it busy 45# 3. Verify that 'zfs destroy' fails to destroy the filesystem 46# 4. Verify 'zfs destroy -f' succeeds to destroy the filesystem. 47# 48# TESTABILITY: explicit 49# 50# TEST_AUTOMATION_LEVEL: automated 51# 52# CODING_STATUS: COMPLETED (2005-08-02) 53# 54# __stc_assertion_end 55# 56############################################################################### 57 58verify_runnable "both" 59 60function cleanup 61{ 62 cd $olddir 63 64 datasetexists $clone && \ 65 log_must $ZFS destroy -f $clone 66 67 snapexists $snap && \ 68 log_must $ZFS destroy -f $snap 69 70 for fs in $fs1 $fs2; do 71 datasetexists $fs && \ 72 log_must $ZFS destroy -f $fs 73 done 74 75 for dir in $TESTDIR1 $TESTDIR2; do 76 [[ -d $dir ]] && \ 77 log_must $RM -rf $dir 78 done 79} 80 81log_assert "Verify that 'zfs destroy -f' succeeds as root. " 82 83log_onexit cleanup 84 85# 86# Preparations for testing 87# 88olddir=$PWD 89 90for dir in $TESTDIR1 $TESTDIR2; do 91 [[ ! -d $dir ]] && \ 92 log_must $MKDIR -p $dir 93done 94 95fs1=$TESTPOOL/$TESTFS1 96mntp1=$TESTDIR1 97fs2=$TESTPOOL/$TESTFS2 98snap=$TESTPOOL/$TESTFS2@snap 99clone=$TESTPOOL/$TESTCLONE 100mntp2=$TESTDIR2 101 102# 103# Create filesystem and clone in the storage pool, mount them and 104# make the mountpoint busy 105# 106for fs in $fs1 $fs2; do 107 log_must $ZFS create $fs 108done 109 110log_must $ZFS snapshot $snap 111log_must $ZFS clone $snap $clone 112 113log_must $ZFS set mountpoint=$mntp1 $fs1 114log_must $ZFS set mountpoint=$mntp2 $clone 115 116for arg in "$fs1 $mntp1" "$clone $mntp2"; do 117 fs=`$ECHO $arg | $AWK '{print $1}'` 118 mntp=`$ECHO $arg | $AWK '{print $2}'` 119 120 log_note "Verify that 'zfs destroy' fails to" \ 121 "destroy filesystem when it is busy." 122 cd $mntp 123 log_mustnot $ZFS destroy $fs 124 125 log_must $ZFS destroy -f $fs 126 datasetexists $fs && \ 127 log_fail "'zfs destroy -f' fails to destroy busy filesystem." 128 129 cd $olddir 130done 131 132log_pass "'zfs destroy -f' succeeds as root." 133