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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2013 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. Seperatly 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
44 verify_runnable "both"
45
46 # Origin Clone
47 #
48 set -A dtst "$POOL" "$POOL/pclone" \
49 "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone"
50 if is_global_zone ; then
51 typeset -i n=${#dtst[@]}
52 dtst[((n))]="$POOL/$FS/vol"; dtst[((n+1))]="$POOL/$FS/vclone"
53 fi
54
55 function cleanup
56 {
57 typeset origin
58 typeset -i i=0
59 while ((i < ${#dtst[@]})); do
60 origin=$(get_prop origin ${dtst[$i]})
61
62 if [[ $origin != "-" ]]; then
63 log_must $ZFS promote ${dtst[$i]}
64 fi
65
66 ((i += 2))
67 done
68
69 origin=$(get_prop origin $POOL2)
70 if [[ $origin != "-" ]]; then
71 log_must $ZFS promote $POOL2
72 fi
73 log_must cleanup_pool $POOL2
74 }
75
76 log_assert "Changes made by 'zfs promote' can be properly received."
77 log_onexit cleanup
78
79 typeset -i i=0
80 while ((i < ${#dtst[@]})); do
81 log_must $ZFS promote ${dtst[((i+1))]}
82
83 ((i += 2))
84 done
85
86 #
87 # Verify zfs send -R should succeed
88 #
89 log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
90 log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
91
92 dstds=$(get_dst_ds $POOL $POOL2)
93 #
94 # Define all the POOL/POOL2 datasets pair
95 #
96 set -A pair "$POOL" "$dstds" \
97 "$POOL/$FS" "$dstds/$FS" \
98 "$POOL/$FS/fs1" "$dstds/$FS/fs1" \
99 "$POOL/$FS/fs1/fs2" "$dstds/$FS/fs1/fs2" \
100 "$POOL/pclone" "$dstds/pclone" \
101 "$POOL/$FS/fs1/fclone" "$dstds/$FS/fs1/fclone"
102
103 if is_global_zone ; then
104 typeset -i n=${#pair[@]}
105 pair[((n))]="$POOL/vol"; pair[((n+1))]="$dstds/vol"
106 pair[((n+2))]="$POOL/$FS/vol" pair[((n+3))]="$dstds/$FS/vol"
107 fi
108
109 #
110 # Verify all the sub-datasets can be properly received.
111 #
112 log_must cmp_ds_subs $POOL $dstds
113 typeset -i i=0
114 while ((i < ${#pair[@]})); do
115 log_must cmp_ds_cont ${pair[$i]} ${pair[((i+1))]}
116 log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
117
118 ((i += 2))
119 done
120
121 # Verify the original filesystem can be promoted
122 log_must $ZFS promote $dstds
123 if is_global_zone ; then
124 log_must $ZFS promote $dstds/$FS/vol
125 fi
126 log_must $ZFS promote $dstds/$FS/fs1/fs2
127
128 log_pass "Changes made by 'zfs promote' can be properly received."