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