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 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26. $STF_SUITE/include/libtest.kshlib 27 28################################################################################ 29# 30# __stc_assertion__start 31# 32# ID: zfs_destroy_003_pos 33# 34# DESCRIPTION: 35# Verify 'zfs destroy [-rR]' succeeds as root. 36# 37# STRATEGY: 38# 1. Create two datasets in the storage pool 39# 2. Create fs,vol,ctr,snapshot and clones of snapshot in the two datasets 40# 3. Create clone in the second dataset for the snapshot in the first dataset 41# 4. Verify 'zfs destroy -r' fails to destroy dataset with clone outside it 42# 5. Verify 'zfs destroy -R' succeeds to destroy dataset with clone outside it 43# 6. Verify 'zfs destroy -r' succeeds to destroy dataset without clone outside it. 44# 45# TESTABILITY: explicit 46# 47# TEST_AUTOMATION_LEVEL: automated 48# 49# CODING_STATUS: COMPLETED (2005-08-02) 50# 51# __stc_assertion_end 52# 53############################################################################### 54 55verify_runnable "both" 56 57function cleanup 58{ 59 for obj in $ctr2 $ctr1 $ctr; do 60 datasetexists $obj && \ 61 log_must $ZFS destroy -Rf $obj 62 done 63 64 for mntp in $TESTDIR1 $TESTDIR2; do 65 [[ -d $mntp ]] && \ 66 log_must $RM -rf $mntp 67 done 68} 69 70log_assert "Verify that 'zfs destroy [-rR]' succeeds as root. " 71 72log_onexit cleanup 73 74# 75# Preparations for testing 76# 77for dir in $TESTDIR1 $TESTDIR2; do 78 [[ ! -d $dir ]] && \ 79 log_must $MKDIR -p $dir 80done 81 82ctr=$TESTPOOL/$TESTCTR 83ctr1=$TESTPOOL/$TESTCTR1 84ctr2=$ctr/$TESTCTR2 85ctr3=$ctr1/$TESTCTR2 86child_fs=$ctr/$TESTFS1 87child_fs1=$ctr1/$TESTFS2 88child_fs_mntp=$TESTDIR1 89child_fs1_mntp=$TESTDIR2 90child_vol=$ctr/$TESTVOL 91child_vol1=$ctr1/$TESTVOL 92child_fs_snap=$child_fs@snap 93child_fs1_snap=$child_fs1@snap 94child_fs_snap_clone=$ctr/$TESTCLONE 95child_fs_snap_clone1=$ctr1/${TESTCLONE}_across_ctr 96child_fs_snap_clone2=$ctr2/$TESTCLONE2 97child_fs1_snap_clone=$ctr1/$TESTCLONE1 98child_fs1_snap_clone1=$ctr/${TESTCLONE1}_across_ctr 99 100# 101# Create two datasets in the storage pool 102# 103log_must $ZFS create $ctr 104log_must $ZFS create $ctr1 105 106# 107# Create children datasets fs,vol,snapshot in the datasets, and 108# clones across two datasets 109# 110log_must $ZFS create $ctr2 111 112for fs in $child_fs $child_fs1; do 113 log_must $ZFS create $fs 114done 115 116log_must $ZFS set mountpoint=$child_fs_mntp $child_fs 117log_must $ZFS set mountpoint=$child_fs1_mntp $child_fs1 118 119for snap in $child_fs_snap $child_fs1_snap; do 120 log_must $ZFS snapshot $snap 121done 122 123if is_global_zone ; then 124 for vol in $child_vol $child_vol1; do 125 log_must $ZFS create -V $VOLSIZE $vol 126 done 127fi 128 129for clone in $child_fs_snap_clone $child_fs_snap_clone1; do 130 log_must $ZFS clone $child_fs_snap $clone 131done 132 133 134for clone in $child_fs1_snap_clone $child_fs1_snap_clone1; do 135 log_must $ZFS clone $child_fs1_snap $clone 136done 137 138log_note "Verify that 'zfs destroy -r' fails to destroy dataset " \ 139 "with clone dependent outside it." 140 141for obj in $child_fs $child_fs1 $ctr $ctr1; do 142 log_mustnot $ZFS destroy -r $obj 143 datasetexists $obj || \ 144 log_fail "'zfs destroy -r' fails to keep clone " \ 145 "dependent outside the hirearchy." 146done 147 148 149log_note "Verify that 'zfs destroy -R' succeeds to destroy dataset " \ 150 "with clone dependent outside it." 151 152log_must $ZFS destroy -R $ctr1 153datasetexists $ctr1 && \ 154 log_fail "'zfs destroy -R' fails to destroy dataset with clone outside it." 155 156log_note "Verify that 'zfs destroy -r' succeeds to destroy dataset " \ 157 "without clone dependent outside it." 158 159log_must $ZFS destroy -r $ctr 160datasetexists $ctr && \ 161 log_fail "'zfs destroy -r' fails to destroy dataset with clone outside it." 162 163log_pass "'zfs destroy [-rR] succeeds as root." 164