1#!/bin/ksh -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 https://opensource.org/licenses/CDDL-1.0. 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 28# 29# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg 33. $STF_SUITE/include/libtest.shlib 34 35# 36# DESCRIPTION: 37# 'zfs promote' can deal with multi-level clones. 38# 39# STRATEGY: 40# 1. Create multiple snapshots and multi-level clones 41# 2. Promote a clone filesystem 42# 3. Verify the dataset dependency relationships are correct after promotion. 43# 44 45verify_runnable "both" 46 47function cleanup 48{ 49 if snapexists ${c1snap[1]}; then 50 log_must zfs promote $clone 51 fi 52 53 typeset ds 54 typeset data 55 for ds in ${snap[*]}; do 56 snapexists $ds && destroy_dataset $ds -rR 57 done 58 for data in ${file[*]}; do 59 [[ -e $data ]] && rm -f $data 60 done 61} 62 63log_assert "'zfs promote' can deal with multi-level clone." 64log_onexit cleanup 65 66fs=$TESTPOOL/$TESTFS 67clone=$TESTPOOL/$TESTCLONE 68clone1=$TESTPOOL/$TESTCLONE1 69 70# Define some arrays here to use loop to reduce code amount 71 72# Array which stores the origin snapshots created in the origin filesystem 73set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3" 74# Array which stores the snapshots existing in the first clone 75set -A csnap "${clone}@$TESTSNAP3" "${clone}@$TESTSNAP4" "${clone}@$TESTSNAP5" 76# Array which stores the snapshots existing in the second clone after promote operation 77set -A c1snap "${clone1}@$TESTSNAP3" "${clone1}@$TESTSNAP4" "${clone1}@$TESTSNAP5" 78# The data will inject into the origin filesystem 79set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \ 80 "$TESTDIR/$TESTFILE3" 81cdir=/$TESTPOOL/$TESTCLONE 82# The data will inject into the first clone 83set -A cfile "${cdir}/$CLONEFILE" "${cdir}/$CLONEFILE1" "${cdir}/$CLONEFILE2" 84c1snapdir=/$TESTPOOL/$TESTCLONE1/.zfs/snapshot 85# The data which will exist in the snapshot of the second clone filesystem after promote 86set -A c1snapfile "${c1snapdir}/$TESTSNAP3/$CLONEFILE" \ 87 "${c1snapdir}/$TESTSNAP4/$CLONEFILE1" \ 88 "${c1snapdir}/$TESTSNAP5/$CLONEFILE2" 89 90# setup for promote testing 91typeset -i i=0 92while (( i < 4 )); do 93 log_must mkfile $FILESIZE ${file[i]} 94 (( i>0 )) && log_must rm -f ${file[((i-1))]} 95 log_must zfs snapshot ${snap[i]} 96 97 (( i = i + 1 )) 98done 99log_must zfs clone ${snap[2]} $clone 100 101log_must rm -f /$clone/$TESTFILE2 102i=0 103while (( i < 3 )); do 104 log_must mkfile $FILESIZE ${cfile[i]} 105 (( i>0 )) && log_must rm -f ${cfile[(( i-1 ))]} 106 log_must zfs snapshot ${csnap[i]} 107 108 (( i = i + 1 )) 109done 110 111log_must zfs clone ${csnap[1]} $clone1 112log_must mkfile $FILESIZE /$clone1/$CLONEFILE2 113log_must rm -f /$clone1/$CLONEFILE1 114log_must zfs snapshot ${c1snap[2]} 115 116log_must zfs promote $clone1 117 118# verify the 'promote' operation 119for ds in ${snap[*]} ${csnap[2]} ${c1snap[*]}; do 120 ! snapexists $ds && \ 121 log_fail "The snapshot $ds disappear after zfs promote." 122done 123for data in ${c1snapfile[*]}; do 124 [[ ! -e $data ]] && \ 125 log_fail "The data file $data loses after zfs promote." 126done 127 128origin_prop=$(get_prop origin $fs) 129[[ "$origin_prop" != "-" ]] && \ 130 log_fail "The dependency is not correct for $fs after zfs promote." 131origin_prop=$(get_prop origin $clone) 132[[ "$origin_prop" != "${c1snap[1]}" ]] && \ 133 log_fail "The dependency is not correct for $clone after zfs promote." 134origin_prop=$(get_prop origin $clone1) 135[[ "$origin_prop" != "${snap[2]}" ]] && \ 136 log_fail "The dependency is not correct for $clone1 after zfs promote." 137 138log_pass "'zfs promote' deal with multi-level clones as expected." 139 140