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