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