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