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