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 2009 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/tests/functional/rsend/rsend.kshlib
33
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 datasets and properties were properly received.
42#
43
44verify_runnable "both"
45
46# See issue: https://github.com/openzfs/zfs/issues/6066
47log_unsupported "Occasionally hangs"
48
49#		Origin			Clone
50#
51set -A	dtst	"$POOL"			"$POOL/pclone"		\
52		"$POOL/$FS/fs1/fs2"	"$POOL/$FS/fs1/fclone"
53if is_global_zone ; then
54	typeset -i n=${#dtst[@]}
55	dtst[((n))]="$POOL/$FS/vol"; 	dtst[((n+1))]="$POOL/$FS/vclone"
56fi
57
58function cleanup
59{
60	typeset origin
61	typeset -i i=0
62	while ((i < ${#dtst[@]})); do
63		origin=$(get_prop origin ${dtst[$i]})
64
65		if [[ $origin != "-" ]]; then
66			log_must zfs promote ${dtst[$i]}
67		fi
68
69		((i += 2))
70	done
71
72	origin=$(get_prop origin $POOL2)
73	if [[ $origin != "-" ]]; then
74		log_must zfs promote $POOL2
75	fi
76	log_must cleanup_pool $POOL2
77}
78
79log_assert "Changes made by 'zfs promote' can be properly received."
80log_onexit cleanup
81
82typeset -i i=0
83while ((i < ${#dtst[@]})); do
84	log_must zfs promote ${dtst[((i+1))]}
85
86	((i += 2))
87done
88
89#
90# Verify zfs send -R should succeed
91#
92log_must eval "zfs send -R $POOL@final > $BACKDIR/pool-final-R"
93log_must eval "zfs receive -d -F $POOL2 < $BACKDIR/pool-final-R"
94
95dstds=$(get_dst_ds $POOL $POOL2)
96#
97# Define all the POOL/POOL2 datasets pair
98#
99set -A pair 	"$POOL" 		"$dstds" 		\
100		"$POOL/$FS" 		"$dstds/$FS" 		\
101		"$POOL/$FS/fs1"		"$dstds/$FS/fs1"	\
102		"$POOL/$FS/fs1/fs2"	"$dstds/$FS/fs1/fs2"	\
103		"$POOL/pclone"		"$dstds/pclone"		\
104		"$POOL/$FS/fs1/fclone"	"$dstds/$FS/fs1/fclone"
105
106if is_global_zone ; then
107	typeset -i n=${#pair[@]}
108	pair[((n))]="$POOL/vol"; 	pair[((n+1))]="$dstds/vol"
109	pair[((n+2))]="$POOL/$FS/vol"	pair[((n+3))]="$dstds/$FS/vol"
110fi
111
112#
113# Verify all the sub-datasets can be properly received.
114#
115log_must cmp_ds_subs $POOL $dstds
116typeset -i i=0
117while ((i < ${#pair[@]})); do
118	log_must cmp_ds_cont ${pair[$i]} ${pair[((i+1))]}
119	log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
120
121	((i += 2))
122done
123
124# Verify the original filesystem can be promoted
125log_must zfs promote $dstds
126if is_global_zone ; then
127	log_must zfs promote $dstds/$FS/vol
128fi
129log_must zfs promote $dstds/$FS/fs1/fs2
130
131log_pass "Changes made by 'zfs promote' can be properly received."
132