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#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/tests/rsend/rsend.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: rsend_008_pos
34#
35# DESCRIPTION:
36#	Changes made by 'zfs promote' can be properly received.
37#
38# STRATEGY:
39#	1. Separately promote pool clone, filesystem clone and volume clone.
40#	2. Recursively backup all the POOL and restore in POOL2
41#	3. Verify all the datesets and property be properly received.
42#
43# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2007-08-27)
48#
49# __stc_assertion_end
50#
51################################################################################
52
53verify_runnable "both"
54
55#		Origin			Clone
56#
57set -A	dtst	"$POOL"			"$POOL/pclone"		\
58		"$POOL/$FS/fs1/fs2"	"$POOL/$FS/fs1/fclone"
59if is_global_zone ; then
60	typeset -i n=${#dtst[@]}
61	dtst[((n))]="$POOL/$FS/vol"; 	dtst[((n+1))]="$POOL/$FS/vclone"
62fi
63
64function cleanup
65{
66	typeset origin
67	typeset -i i=0
68	while ((i < ${#dtst[@]})); do
69		origin=$(get_prop origin ${dtst[$i]})
70
71		if [[ $origin != "-" ]]; then
72			log_must $ZFS promote ${dtst[$i]}
73		fi
74
75		((i += 2))
76	done
77
78	origin=$(get_prop origin $POOL2)
79	if [[ $origin != "-" ]]; then
80		log_must $ZFS promote $POOL2
81	fi
82	log_must cleanup_pool $POOL2
83}
84
85log_assert "Changes made by 'zfs promote' can be properly received."
86log_onexit cleanup
87
88typeset -i i=0
89while ((i < ${#dtst[@]})); do
90	log_must $ZFS promote ${dtst[((i+1))]}
91
92	((i += 2))
93done
94
95#
96# Verify zfs send -R should succeed
97#
98log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
99log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
100
101dstds=$(get_dst_ds $POOL $POOL2)
102#
103# Define all the POOL/POOL2 datasets pair
104#
105set -A pair 	"$POOL" 		"$dstds" 		\
106		"$POOL/$FS" 		"$dstds/$FS" 		\
107		"$POOL/$FS/fs1"		"$dstds/$FS/fs1"	\
108		"$POOL/$FS/fs1/fs2"	"$dstds/$FS/fs1/fs2"	\
109		"$POOL/pclone"		"$dstds/pclone"		\
110		"$POOL/$FS/fs1/fclone"	"$dstds/$FS/fs1/fclone"
111
112if is_global_zone ; then
113	typeset -i n=${#pair[@]}
114	pair[((n))]="$POOL/vol"; 	pair[((n+1))]="$dstds/vol"
115	pair[((n+2))]="$POOL/$FS/vol"	pair[((n+3))]="$dstds/$FS/vol"
116fi
117
118#
119# Verify all the sub-datasets can be properly received.
120#
121log_must cmp_ds_subs $POOL $dstds
122typeset -i i=0
123while ((i < ${#pair[@]})); do
124	log_must cmp_ds_cont ${pair[$i]} ${pair[((i+1))]}
125	log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
126
127	((i += 2))
128done
129
130# Verify the original filesystem can be promoted
131log_must $ZFS promote $dstds
132if is_global_zone ; then
133	log_must $ZFS promote $dstds/$FS/vol
134fi
135log_must $ZFS promote $dstds/$FS/fs1/fs2
136
137log_pass "Changes made by 'zfs promote' can be properly received."
138