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_012_pos
34#
35# DESCRIPTION:
36#	zfs send -R will backup all the filesystem properties correctly.
37#
38# STRATEGY:
39#	1. Setting properties for all the filesystem and volumes randomly
40#	2. Backup all the data from POOL by send -R
41#	3. Restore all the data in POOL2
42#	4. Verify all the perperties in two pools are same
43#
44# TESTABILITY: explicit
45#
46# TEST_AUTOMATION_LEVEL: automated
47#
48# CODING_STATUS: COMPLETED (2007-08-27)
49#
50# __stc_assertion_end
51#
52################################################################################
53
54verify_runnable "global"
55
56function rand_set_prop
57{
58	typeset dtst=$1
59	typeset prop=$2
60	shift 2
61	typeset value=$(random_get $@)
62
63	log_must eval "$ZFS set $prop='$value' $dtst"
64}
65
66function edited_prop
67{
68	typeset behaviour=$1
69	typeset ds=$2
70	typeset backfile=$TESTDIR/edited_prop_$ds
71
72	case $behaviour in
73		"get")
74			typeset props=$($ZFS inherit 2>&1 | \
75				$AWK '$2=="YES" {print $1}' | \
76				$EGREP -v "^vol|\.\.\.$")
77			for item in $props ; do
78				$ZFS get -H -o property,value $item $ds >> \
79					$backfile
80				if (($? != 0)); then
81					log_fail "zfs get -H -o property,value"\
82						"$item $ds > $backfile"
83				fi
84			done
85			;;
86		"set")
87			if [[ ! -f $backfile ]] ; then
88				log_fail "$ds need backup properties firstly."
89			fi
90
91			typeset prop value
92			while read prop value ; do
93				eval $ZFS set $prop='$value' $ds
94				if (($? != 0)); then
95					log_fail "$ZFS set $prop=$value $ds"
96				fi
97			done < $backfile
98			;;
99		*)
100			log_fail "Unrecognized behaviour: $behaviour"
101	esac
102}
103
104function cleanup
105{
106	log_must cleanup_pool $POOL
107	log_must cleanup_pool $POOL2
108
109	log_must edited_prop "set" $POOL
110	log_must edited_prop "set" $POOL2
111
112	typeset prop
113	for prop in $(fs_inherit_prop) ; do
114		log_must $ZFS inherit $prop $POOL
115		log_must $ZFS inherit $prop $POOL2
116	done
117
118	#if is_shared $POOL; then
119	#	log_must $ZFS set sharenfs=off $POOL
120	#fi
121	log_must setup_test_model $POOL
122
123	if [[ -d $TESTDIR ]]; then
124		log_must $RM -rf $TESTDIR/*
125	fi
126}
127
128log_assert "Verify zfs send -R will backup all the filesystem properties " \
129	"correctly."
130log_onexit cleanup
131
132log_must edited_prop "get" $POOL
133log_must edited_prop "get" $POOL2
134
135for fs in "$POOL" "$POOL/pclone" "$POOL/$FS" "$POOL/$FS/fs1" \
136	"$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do
137	rand_set_prop $fs aclinherit "discard" "noallow" "secure" "passthrough"
138	rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256"
139	rand_set_prop $fs aclmode "discard" "groupmask" "passthrough"
140	rand_set_prop $fs atime "on" "off"
141	rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256"
142	rand_set_prop $fs compression "on" "off" "lzjb" "gzip" \
143		"gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6"   \
144		"gzip-7" "gzip-8" "gzip-9"
145	rand_set_prop $fs copies "1" "2" "3"
146	rand_set_prop $fs devices "on" "off"
147	rand_set_prop $fs exec "on" "off"
148	rand_set_prop $fs quota "512M" "1024M"
149	rand_set_prop $fs recordsize "512" "2K" "8K" "32K" "128K"
150	rand_set_prop $fs setuid "on" "off"
151	rand_set_prop $fs snapdir "hidden" "visible"
152	rand_set_prop $fs xattr "on" "off"
153	rand_set_prop $fs user:prop "aaa" "bbb" "23421" "()-+?"
154done
155
156for vol in "$POOL/vol" "$POOL/$FS/vol" ; do
157	rand_set_prop $vol checksum "on" "off" "fletcher2" "fletcher4" "sha256"
158	rand_set_prop $vol compression "on" "off" "lzjb" "gzip" \
159		"gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6"   \
160		"gzip-7" "gzip-8" "gzip-9"
161	rand_set_prop $vol readonly "on" "off"
162	rand_set_prop $vol copies "1" "2" "3"
163	rand_set_prop $vol user:prop "aaa" "bbb" "23421" "()-+?"
164done
165
166
167# Verify inherited property can be received
168rand_set_prop $POOL sharenfs "on" "off" "rw"
169
170#
171# Duplicate POOL2 for testing
172#
173log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
174log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
175
176#
177# Define all the POOL/POOL2 datasets pair
178#
179set -A pair 	"$POOL" 		"$POOL2" 		\
180		"$POOL/$FS" 		"$POOL2/$FS" 		\
181		"$POOL/$FS/fs1"		"$POOL2/$FS/fs1"	\
182		"$POOL/$FS/fs1/fs2"	"$POOL2/$FS/fs1/fs2"	\
183		"$POOL/pclone"		"$POOL2/pclone"		\
184		"$POOL/$FS/fs1/fclone"	"$POOL2/$FS/fs1/fclone" \
185		"$POOL/vol"		"$POOL2/vol" 		\
186		"$POOL/$FS/vol"		"$POOL2/$FS/vol"
187
188typeset -i i=0
189while ((i < ${#pair[@]})); do
190	log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
191
192	((i += 2))
193done
194
195
196$ZPOOL upgrade -v | $GREP "Snapshot properties" > /dev/null 2>&1
197if (( $? == 0 )) ; then
198	i=0
199	while ((i < ${#pair[@]})); do
200		log_must cmp_ds_prop ${pair[$i]}@final ${pair[((i+1))]}@final
201		((i += 2))
202	done
203fi
204
205log_pass "Verify zfs send -R will backup all the filesystem properties " \
206	"correctly."
207