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_001_pos 33# 34# DESCRIPTION: 35# 'zfs promote' can promote a clone filesystem to no longer be dependent 36# on its "origin" snapshot. 37# 38# STRATEGY: 39# 1. Create a snapshot and a clone of the snapshot 40# 2. Promote the clone filesystem 41# 3. Verify the promoted filesystem become independent 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; then 58 log_must $ZFS promote $fs 59 fi 60 snapexists $snap && \ 61 log_must $ZFS destroy -rR $snap 62 63 typeset data 64 for data in $file0 $file1; do 65 [[ -e $data ]] && $RM -f $data 66 done 67} 68 69function testing_verify 70{ 71 typeset ds=$1 72 typeset ds_file=$2 73 typeset snap_file=$3 74 typeset c_ds=$4 75 typeset c_file=$5 76 typeset csnap_file=$6 77 typeset origin_prop="" 78 79 80 snapexists $ds@$TESTSNAP && \ 81 log_fail "zfs promote cannot promote $ds@$TESTSNAP." 82 ! snapexists $c_ds@$TESTSNAP && \ 83 log_fail "The $c_ds@$TESTSNAP after zfs promote doesn't exist." 84 85 origin_prop=$(get_prop origin $ds) 86 [[ "$origin_prop" != "$c_ds@$TESTSNAP" ]] && \ 87 log_fail "The dependency of $ds is not correct." 88 origin_prop=$(get_prop origin $c_ds) 89 [[ "$origin_prop" != "-" ]] && \ 90 log_fail "The dependency of $c_ds is not correct." 91 92 if [[ -e $snap_file ]] || [[ ! -e $csnap_file ]]; then 93 log_fail "Data file $snap_file cannot be correctly promoted." 94 fi 95 if [[ ! -e $ds_file ]] || [[ ! -e $c_file ]]; then 96 log_fail "There exists data file losing after zfs promote." 97 fi 98 99 log_mustnot $ZFS destroy -r $c_ds 100} 101 102log_assert "'zfs promote' can promote a clone filesystem." 103log_onexit cleanup 104 105fs=$TESTPOOL/$TESTFS 106file0=$TESTDIR/$TESTFILE0 107file1=$TESTDIR/$TESTFILE1 108snap=$fs@$TESTSNAP 109snapfile=$TESTDIR/$(get_snapdir_name)/$TESTSNAP/$TESTFILE0 110clone=$TESTPOOL/$TESTCLONE 111cfile=/$clone/$CLONEFILE 112csnap=$clone@$TESTSNAP 113csnapfile=/$clone/$(get_snapdir_name)/$TESTSNAP/$TESTFILE0 114 115# setup for promte testing 116log_must $MKFILE $FILESIZE $file0 117log_must $ZFS snapshot $snap 118log_must $MKFILE $FILESIZE $file1 119log_must $RM -f $file0 120log_must $ZFS clone $snap $clone 121log_must $MKFILE $FILESIZE $cfile 122 123log_must $ZFS promote $clone 124# verify the 'promote' operation 125testing_verify $fs $file1 $snapfile $clone $cfile $csnapfile 126 127log_note "Verify 'zfs promote' can change back the dependency relationship." 128log_must $ZFS promote $fs 129#verify the result 130testing_verify $clone $cfile $csnapfile $fs $file1 $snapfile 131 132log_pass "'zfs promote' reverses the clone parent-child dependency relationship"\ 133 "as expected." 134 135