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