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