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