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 2007 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/zfs_destroy/zfs_destroy.cfg 34 35# 36# DESCRIPTION: 37# Verify 'zfs destroy -f' succeeds as root. 38# 39# STRATEGY: 40# 1. Create filesystem in the storage pool 41# 2. Set mountpoint for the filesystem and make it busy 42# 3. Verify that 'zfs destroy' fails to destroy the filesystem 43# 4. Verify 'zfs destroy -f' succeeds to destroy the filesystem. 44# 45 46verify_runnable "both" 47 48function cleanup 49{ 50 cd $olddir 51 52 datasetexists $clone && \ 53 log_must zfs destroy -f $clone 54 55 snapexists $snap && \ 56 log_must zfs destroy -f $snap 57 58 for fs in $fs1 $fs2; do 59 datasetexists $fs && \ 60 log_must zfs destroy -f $fs 61 done 62 63 for dir in $TESTDIR1 $TESTDIR2; do 64 [[ -d $dir ]] && \ 65 log_must rm -rf $dir 66 done 67} 68 69log_assert "Verify that 'zfs destroy -f' succeeds as root. " 70 71log_onexit cleanup 72 73# 74# Preparations for testing 75# 76olddir=$PWD 77 78for dir in $TESTDIR1 $TESTDIR2; do 79 [[ ! -d $dir ]] && \ 80 log_must mkdir -p $dir 81done 82 83fs1=$TESTPOOL/$TESTFS1 84mntp1=$TESTDIR1 85fs2=$TESTPOOL/$TESTFS2 86snap=$TESTPOOL/$TESTFS2@snap 87clone=$TESTPOOL/$TESTCLONE 88mntp2=$TESTDIR2 89 90# 91# Create filesystem and clone in the storage pool, mount them and 92# make the mountpoint busy 93# 94for fs in $fs1 $fs2; do 95 log_must zfs create $fs 96done 97 98log_must zfs snapshot $snap 99log_must zfs clone $snap $clone 100 101log_must zfs set mountpoint=$mntp1 $fs1 102log_must zfs set mountpoint=$mntp2 $clone 103 104for arg in "$fs1 $mntp1" "$clone $mntp2"; do 105 fs=`echo $arg | awk '{print $1}'` 106 mntp=`echo $arg | awk '{print $2}'` 107 108 log_note "Verify that 'zfs destroy' fails to" \ 109 "destroy filesystem when it is busy." 110 cd $mntp 111 log_mustnot zfs destroy $fs 112 113 log_must zfs destroy -f $fs 114 datasetexists $fs && \ 115 log_fail "'zfs destroy -f' fails to destroy busy filesystem." 116 117 cd $olddir 118done 119 120log_pass "'zfs destroy -f' succeeds as root." 121