12fae26bdSAlan Somers#!/usr/local/bin/ksh93 -p
22fae26bdSAlan Somers#
32fae26bdSAlan Somers# CDDL HEADER START
42fae26bdSAlan Somers#
52fae26bdSAlan Somers# The contents of this file are subject to the terms of the
62fae26bdSAlan Somers# Common Development and Distribution License (the "License").
72fae26bdSAlan Somers# You may not use this file except in compliance with the License.
82fae26bdSAlan Somers#
92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing.
112fae26bdSAlan Somers# See the License for the specific language governing permissions
122fae26bdSAlan Somers# and limitations under the License.
132fae26bdSAlan Somers#
142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each
152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the
172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying
182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner]
192fae26bdSAlan Somers#
202fae26bdSAlan Somers# CDDL HEADER END
212fae26bdSAlan Somers#
222fae26bdSAlan Somers
232fae26bdSAlan Somers#
242fae26bdSAlan Somers# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
252fae26bdSAlan Somers# Use is subject to license terms.
262fae26bdSAlan Somers. $STF_SUITE/include/libtest.kshlib
272fae26bdSAlan Somers
282fae26bdSAlan Somers################################################################################
292fae26bdSAlan Somers#
302fae26bdSAlan Somers# __stc_assertion_start
312fae26bdSAlan Somers#
322fae26bdSAlan Somers# ID: zfs_promote_001_pos
332fae26bdSAlan Somers#
342fae26bdSAlan Somers# DESCRIPTION:
352fae26bdSAlan Somers#	'zfs promote' can promote a clone filesystem to no longer be dependent
362fae26bdSAlan Somers#	on its "origin" snapshot.
372fae26bdSAlan Somers#
382fae26bdSAlan Somers# STRATEGY:
392fae26bdSAlan Somers#	1. Create a snapshot and a clone of the snapshot
402fae26bdSAlan Somers#	2. Promote the clone filesystem
412fae26bdSAlan Somers#	3. Verify the promoted filesystem become independent
422fae26bdSAlan Somers#
432fae26bdSAlan Somers# TESTABILITY: explicit
442fae26bdSAlan Somers#
452fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
462fae26bdSAlan Somers#
472fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2006-05-16)
482fae26bdSAlan Somers#
492fae26bdSAlan Somers# __stc_assertion_end
502fae26bdSAlan Somers#
512fae26bdSAlan Somers################################################################################
522fae26bdSAlan Somers
532fae26bdSAlan Somersverify_runnable "both"
542fae26bdSAlan Somers
552fae26bdSAlan Somersfunction cleanup
562fae26bdSAlan Somers{
572fae26bdSAlan Somers	if snapexists $csnap; then
582fae26bdSAlan Somers		log_must $ZFS promote $fs
592fae26bdSAlan Somers	fi
602fae26bdSAlan Somers	snapexists $snap && \
612fae26bdSAlan Somers		log_must $ZFS destroy -rR $snap
622fae26bdSAlan Somers
632fae26bdSAlan Somers	typeset data
642fae26bdSAlan Somers	for data in $file0 $file1; do
652fae26bdSAlan Somers		[[ -e $data ]] && $RM -f $data
662fae26bdSAlan Somers	done
672fae26bdSAlan Somers}
682fae26bdSAlan Somers
692fae26bdSAlan Somersfunction testing_verify
702fae26bdSAlan Somers{
712fae26bdSAlan Somers	typeset ds=$1
722fae26bdSAlan Somers	typeset ds_file=$2
732fae26bdSAlan Somers	typeset snap_file=$3
742fae26bdSAlan Somers	typeset c_ds=$4
752fae26bdSAlan Somers	typeset c_file=$5
762fae26bdSAlan Somers	typeset csnap_file=$6
772fae26bdSAlan Somers	typeset origin_prop=""
782fae26bdSAlan Somers
792fae26bdSAlan Somers
802fae26bdSAlan Somers	snapexists $ds@$TESTSNAP && \
812fae26bdSAlan Somers		log_fail "zfs promote cannot promote $ds@$TESTSNAP."
822fae26bdSAlan Somers	! snapexists $c_ds@$TESTSNAP && \
832fae26bdSAlan Somers		log_fail "The $c_ds@$TESTSNAP after zfs promote doesn't exist."
842fae26bdSAlan Somers
852fae26bdSAlan Somers	origin_prop=$(get_prop origin $ds)
862fae26bdSAlan Somers	[[ "$origin_prop" != "$c_ds@$TESTSNAP" ]] && \
872fae26bdSAlan Somers		log_fail "The dependency of $ds is not correct."
882fae26bdSAlan Somers	origin_prop=$(get_prop origin $c_ds)
892fae26bdSAlan Somers	[[ "$origin_prop" != "-" ]] && \
902fae26bdSAlan Somers		log_fail "The dependency of $c_ds is not correct."
912fae26bdSAlan Somers
922fae26bdSAlan Somers	if [[ -e $snap_file ]] || [[ ! -e $csnap_file ]]; then
932fae26bdSAlan Somers		log_fail "Data file $snap_file cannot be correctly promoted."
942fae26bdSAlan Somers	fi
952fae26bdSAlan Somers	if [[ ! -e $ds_file ]] || [[ ! -e $c_file ]]; then
962fae26bdSAlan Somers        	log_fail "There exists data file losing after zfs promote."
972fae26bdSAlan Somers	fi
982fae26bdSAlan Somers
992fae26bdSAlan Somers	log_mustnot $ZFS destroy -r $c_ds
1002fae26bdSAlan Somers}
1012fae26bdSAlan Somers
1022fae26bdSAlan Somerslog_assert "'zfs promote' can promote a clone filesystem."
1032fae26bdSAlan Somerslog_onexit cleanup
1042fae26bdSAlan Somers
1052fae26bdSAlan Somersfs=$TESTPOOL/$TESTFS
1062fae26bdSAlan Somersfile0=$TESTDIR/$TESTFILE0
1072fae26bdSAlan Somersfile1=$TESTDIR/$TESTFILE1
1082fae26bdSAlan Somerssnap=$fs@$TESTSNAP
1092fae26bdSAlan Somerssnapfile=$TESTDIR/$(get_snapdir_name)/$TESTSNAP/$TESTFILE0
1102fae26bdSAlan Somersclone=$TESTPOOL/$TESTCLONE
1112fae26bdSAlan Somerscfile=/$clone/$CLONEFILE
1122fae26bdSAlan Somerscsnap=$clone@$TESTSNAP
1132fae26bdSAlan Somerscsnapfile=/$clone/$(get_snapdir_name)/$TESTSNAP/$TESTFILE0
1142fae26bdSAlan Somers
1152fae26bdSAlan Somers# setup for promte testing
1162fae26bdSAlan Somerslog_must $MKFILE $FILESIZE $file0
1172fae26bdSAlan Somerslog_must $ZFS snapshot $snap
1182fae26bdSAlan Somerslog_must $MKFILE $FILESIZE $file1
1192fae26bdSAlan Somerslog_must $RM -f $file0
1202fae26bdSAlan Somerslog_must $ZFS clone $snap $clone
1212fae26bdSAlan Somerslog_must $MKFILE $FILESIZE $cfile
1222fae26bdSAlan Somers
1232fae26bdSAlan Somerslog_must $ZFS promote $clone
1242fae26bdSAlan Somers# verify the 'promote' operation
1252fae26bdSAlan Somerstesting_verify $fs $file1 $snapfile $clone $cfile $csnapfile
1262fae26bdSAlan Somers
1272fae26bdSAlan Somerslog_note "Verify 'zfs promote' can change back the dependency relationship."
1282fae26bdSAlan Somerslog_must $ZFS promote $fs
1292fae26bdSAlan Somers#verify the result
1302fae26bdSAlan Somerstesting_verify $clone $cfile $csnapfile $fs $file1 $snapfile
1312fae26bdSAlan Somers
1322fae26bdSAlan Somerslog_pass "'zfs promote' reverses the clone parent-child dependency relationship"\
1332fae26bdSAlan Somers	"as expected."
1342fae26bdSAlan Somers
135