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 https://opensource.org/licenses/CDDL-1.0. 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 2008 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/snapshot/snapshot.cfg 34 35# 36# DESCRIPTION: 37# Verify 'snapshot -r' can create snapshot for promoted clone, and vice 38# versa, a clone filesystem from the snapshot created by 'snapshot -r' 39# can be correctly promoted. 40# 41# STRATEGY: 42# 1. Create a dataset tree 43# 2. snapshot a filesystem and clone the snapshot 44# 3. promote the clone 45# 4. snapshot -r the dataset tree 46# 5. verify that the snapshot of cloned filesystem is created correctly 47# 6. clone a snapshot from the snapshot tree 48# 7. promote the clone 49# 8. verify that the clone is promoted correctly. 50# 51 52verify_runnable "both" 53 54function cleanup 55{ 56 if datasetexists $clone1; then 57 log_must zfs promote $ctrfs 58 destroy_dataset $clone1 59 fi 60 61 snapexists $snapctr && destroy_dataset $snapctr -r 62 63 if snapexists $clone@$TESTSNAP1; then 64 log_must zfs promote $ctrfs 65 destroy_dataset $ctrfs@$TESTSNAP1 -rR 66 fi 67} 68 69log_assert "Verify that 'snapshot -r' can work with 'zfs promote'." 70log_onexit cleanup 71 72ctr=$TESTPOOL/$TESTCTR 73ctrfs=$ctr/$TESTFS1 74clone=$ctr/$TESTCLONE 75clone1=$ctr/$TESTCLONE1 76snappool=$SNAPPOOL 77snapfs=$SNAPFS 78snapctr=$ctr@$TESTSNAP 79snapctrclone=$clone@$TESTSNAP 80snapctrclone1=$clone1@$TESTSNAP 81snapctrfs=$SNAPCTR 82 83#preparation for testing 84log_must zfs snapshot $ctrfs@$TESTSNAP1 85log_must zfs clone $ctrfs@$TESTSNAP1 $clone 86log_must zfs promote $clone 87 88log_must zfs snapshot -r $snapctr 89 90! snapexists $snapctrclone && \ 91 log_fail "'snapshot -r' fails to create $snapctrclone for $ctr/$TESTCLONE." 92 93log_must zfs clone $snapctrfs $clone1 94log_must zfs promote $clone1 95 96#verify the origin value is correct. 97orig_value=$(get_prop origin $ctrfs) 98if ! snapexists $snapctrclone1 || [[ "$orig_value" != "$snapctrclone1" ]]; then 99 log_fail "'zfs promote' fails to promote $clone which is cloned from \ 100 $snapctrfs." 101fi 102 103log_pass "'snapshot -r' can work with 'zfs promote' as expected." 104