1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License (the "License"). 6# You may not use this file except in compliance with the License. 7# 8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9# or http://www.opensolaris.org/os/licensing. 10# See the License for the specific language governing permissions 11# and limitations under the License. 12# 13# When distributing Covered Code, include this CDDL HEADER in each 14# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15# If applicable, add the following below this CDDL HEADER, with the 16# fields enclosed by brackets "[]" replaced with your own identifying 17# information: Portions Copyright [yyyy] [name of copyright owner] 18# 19# CDDL HEADER END 20# 21 22# 23# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26 27# 28# Copyright (c) 2012, 2018 by Delphix. All rights reserved. 29# 30 31. $STF_SUITE/include/libtest.shlib 32. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg 33 34# 35# Create or recover a set of test environment which include ctr, vol, fs, 36# snap & clone. It looks like the following. 37# 38# pool 39# |ctr 40# | |fs 41# | | |fssnap 42# | |vol 43# | |volsnap 44# |fsclone 45# |volclone 46# 47# $1 indicate which dependent dataset need be created. Such as 'snap', 'clone'. 48# 49function setup_testenv #[dtst] 50{ 51 typeset dtst=$1 52 53 if ! datasetexists $CTR; then 54 log_must zfs create $CTR 55 fi 56 if ! datasetexists $FS; then 57 log_must zfs create $FS 58 fi 59 # Volume test is only available on global zone 60 if ! datasetexists $VOL && is_global_zone; then 61 log_must zfs create -V $VOLSIZE $VOL 62 block_device_wait 63 64 log_must new_fs $ZVOL_DEVDIR/$VOL 65 66 if [[ ! -d $TESTDIR1 ]]; then 67 log_must mkdir $TESTDIR1 68 fi 69 log_must mount $ZVOL_DEVDIR/$VOL $TESTDIR1 70 fi 71 72 if [[ $dtst == snap || $dtst == clone ]]; then 73 if ! datasetexists $FSSNAP; then 74 log_must zfs snapshot $FSSNAP 75 fi 76 if ! datasetexists $VOLSNAP && is_global_zone; then 77 log_must zfs snapshot $VOLSNAP 78 fi 79 fi 80 81 if [[ $dtst == clone ]]; then 82 if ! datasetexists $FSCLONE; then 83 log_must zfs clone $FSSNAP $FSCLONE 84 fi 85 if ! datasetexists $VOLCLONE && is_global_zone; then 86 log_must zfs clone $VOLSNAP $VOLCLONE 87 block_device_wait 88 fi 89 fi 90} 91 92# Clean up the testing environment 93# 94function cleanup_testenv 95{ 96 if is_global_zone && ismounted "$TESTDIR1" "$NEWFS_DEFAULT_FS" ; then 97 log_must umount -f $TESTDIR1 98 fi 99 if [[ -d $TESTDIR1 ]]; then 100 log_must rm -rf $TESTDIR1 101 fi 102 103 pkill mkbusy 104 105 if datasetexists $CTR; then 106 log_must zfs destroy -Rf $CTR 107 fi 108} 109 110# 111# Delete volume and related datasets from list, if the test cases was 112# running in local zone. Then check them are existed or non-exists. 113# 114# $1 function name 115# $2-n datasets name 116# 117function check_dataset 118{ 119 typeset funname=$1 120 typeset newlist="" 121 typeset dtst 122 shift 123 124 for dtst in "$@"; do 125 # Volume and related stuff are unavailable in local zone 126 if ! is_global_zone; then 127 if [[ $dtst == $VOL || $dtst == $VOLSNAP || \ 128 $dtst == $VOLCLONE ]] 129 then 130 continue 131 fi 132 fi 133 newlist="$newlist $dtst" 134 done 135 136 if (( ${#newlist} != 0 )); then 137 # Run each item in $newlist individually so on failure, the 138 # problematic dataset is listed in the logs. 139 for i in $newlist; do 140 log_must $funname $i 141 done 142 fi 143} 144 145# Use zdb to see if a livelist exists for a given clone 146# $1 clone name 147function check_livelist_exists 148{ 149 zdb -vvvvv $TESTPOOL/$1 | grep "Livelist" || \ 150 log_fail "zdb could not find Livelist" 151} 152 153# Check that a livelist has been removed, waiting for deferred destroy entries 154# to be cleared from zdb. 155function check_livelist_gone 156{ 157 log_must zpool wait -t free $TESTPOOL 158 zpool sync 159 zdb -vvvvv $TESTPOOL | grep "Livelist" && \ 160 log_fail "zdb found Livelist after the clone is deleted." 161} 162 163# Create a clone in the testpool based on $TESTFS@snap. Verify that the clone 164# was created and that it includes a livelist 165# $1 fs name 166# $2 snap name 167# $3 clone name 168function clone_dataset 169{ 170 log_must zfs clone $TESTPOOL/$1@$2 $TESTPOOL/$3 171 datasetexists $TESTPOOL/$3 || \ 172 log_fail "zfs clone $TESTPOOL/$3 fail." 173 check_livelist_exists $3 174} 175