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_promote_004_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_promote_004_pos 36# 37# DESCRIPTION: 38# 'zfs promote' can deal with multi-level clones. 39# 40# STRATEGY: 41# 1. Create multiple snapshots and multi-level clones 42# 2. Promote a clone filesystem 43# 3. Verify the dataset dependency relationships are correct after promotion. 44# 45# TESTABILITY: explicit 46# 47# TEST_AUTOMATION_LEVEL: automated 48# 49# CODING_STATUS: COMPLETED (2006-05-16) 50# 51# __stc_assertion_end 52# 53################################################################################ 54 55verify_runnable "both" 56 57function cleanup 58{ 59 if snapexists ${c1snap[1]}; then 60 log_must $ZFS promote $clone 61 fi 62 63 typeset ds 64 typeset data 65 for ds in ${snap[*]}; do 66 snapexists $ds && \ 67 log_must $ZFS destroy -rR $ds 68 done 69 for data in ${file[*]}; do 70 [[ -e $data ]] && $RM -f $data 71 done 72} 73 74log_assert "'zfs promote' can deal with multi-level clone." 75log_onexit cleanup 76 77fs=$TESTPOOL/$TESTFS 78clone=$TESTPOOL/$TESTCLONE 79clone1=$TESTPOOL/$TESTCLONE1 80 81# Define some arrays here to use loop to reduce code amount 82 83# Array which stores the origin snapshots created in the origin filesystem 84set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3" 85# Array which stores the snapshots existing in the first clone 86set -A csnap "${clone}@$TESTSNAP3" "${clone}@$TESTSNAP4" "${clone}@$TESTSNAP5" 87# Array which stores the snapshots existing in the second clone after promote operation 88set -A c1snap "${clone1}@$TESTSNAP3" "${clone1}@$TESTSNAP4" "${clone1}@$TESTSNAP5" 89# The data will inject into the origin filesystem 90set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \ 91 "$TESTDIR/$TESTFILE3" 92cdir=/$TESTPOOL/$TESTCLONE 93# The data will inject into the first clone 94set -A cfile "${cdir}/$CLONEFILE" "${cdir}/$CLONEFILE1" "${cdir}/$CLONEFILE2" 95c1snapdir=/$TESTPOOL/$TESTCLONE1/$(get_snapdir_name) 96# The data which will exist in the snapshot of the second clone filesystem after promote 97set -A c1snapfile "${c1snapdir}/$TESTSNAP3/$CLONEFILE" \ 98 "${c1snapdir}/$TESTSNAP4/$CLONEFILE1" \ 99 "${c1snapdir}/$TESTSNAP5/$CLONEFILE2" 100 101# setup for promote testing 102typeset -i i=0 103while (( i < 4 )); do 104 log_must $MKFILE $FILESIZE ${file[i]} 105 (( i>0 )) && log_must $RM -f ${file[((i-1))]} 106 log_must $ZFS snapshot ${snap[i]} 107 108 (( i = i + 1 )) 109done 110log_must $ZFS clone ${snap[2]} $clone 111 112log_must $RM -f /$clone/$TESTFILE2 113i=0 114while (( i < 3 )); do 115 log_must $MKFILE $FILESIZE ${cfile[i]} 116 (( i>0 )) && log_must $RM -f ${cfile[(( i-1 ))]} 117 log_must $ZFS snapshot ${csnap[i]} 118 119 (( i = i + 1 )) 120done 121 122log_must $ZFS clone ${csnap[1]} $clone1 123log_must $MKFILE $FILESIZE /$clone1/$CLONEFILE2 124log_must $RM -f /$clone1/$CLONEFILE1 125log_must $ZFS snapshot ${c1snap[2]} 126 127log_must $ZFS promote $clone1 128 129# verify the 'promote' operation 130for ds in ${snap[*]} ${csnap[2]} ${c1snap[*]}; do 131 ! snapexists $ds && \ 132 log_fail "The snapshot $ds disappear after zfs promote." 133done 134for data in ${c1snapfile[*]}; do 135 [[ ! -e $data ]] && \ 136 log_fail "The data file $data loses after zfs promote." 137done 138 139origin_prop=$(get_prop origin $fs) 140[[ "$origin_prop" != "-" ]] && \ 141 log_fail "The dependency is not correct for $fs after zfs promote." 142origin_prop=$(get_prop origin $clone) 143[[ "$origin_prop" != "${c1snap[1]}" ]] && \ 144 log_fail "The dependency is not correct for $clone after zfs promote." 145origin_prop=$(get_prop origin $clone1) 146[[ "$origin_prop" != "${snap[2]}" ]] && \ 147 log_fail "The dependency is not correct for $clone1 after zfs promote." 148 149log_pass "'zfs promote' deal with multi-level clones as expected." 150 151