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