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