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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: user_property_002_pos
34#
35# DESCRIPTION:
36#	User defined property are always inherited from its parent dataset
37#	directly.
38#
39# STRATEGY:
40#	1. Create pool, fs, volume, fsclone & volclone.
41#	2. Get random user property name and set to the pool
42#	3. Verify all dataset user property inherit from pool.
43#	4. Set intermediate dataset and verify its children will inherit user
44#	   property from it directly.
45#
46# TESTABILITY: explicit
47#
48# TEST_AUTOMATION_LEVEL: automated
49#
50# CODING_STATUS: COMPLETED (2006-09-04)
51#
52# __stc_assertion_end
53#
54################################################################################
55
56verify_runnable "both"
57
58function cleanup
59{
60	datasetexists $new_vol && log_must $ZFS rename $new_vol $vol
61
62	typeset dtst
63	for dtst in $new_fsclone $new_volclone $fsclone $volclone \
64	    $fssnap $volsnap; do
65	    	if datasetexists $dtst; then
66			log_must $ZFS destroy -f $dtst
67		fi
68	done
69
70	cleanup_user_prop $pool
71}
72
73#
74# Verify options datasets (3-n) inherit from the inherited dataset $2.
75#
76# $1 user property
77# $2 inherited dataset
78# $3-n datasets
79#
80function inherit_check
81{
82	typeset prop=$1
83	typeset inherited_dtst=$2
84	shift 2
85	[[ -z $@ ]] && return 1
86
87	typeset inherited_value=$(get_prop $prop $inherited_dtst)
88	for dtst in $@; do
89		typeset value=$(get_prop $prop $dtst)
90		typeset source=$(get_source $prop $dtst)
91		if [[ "$value" != "$inherited_value" || \
92		      "$source" != "inherited from $inherited_dtst" ]]
93		then
94			return 1
95		fi
96
97		shift
98	done
99
100	return 0
101}
102
103log_assert "User defined property inherited from its parent."
104log_onexit cleanup
105
106pool=$TESTPOOL; fs=$pool/$TESTFS; vol=$pool/$TESTVOL
107fssnap=$fs@snap; volsnap=$vol@snap;
108log_must $ZFS snapshot $fssnap
109log_must $ZFS snapshot $volsnap
110fsclone=$pool/fsclone; volclone=$pool/volclone
111log_must $ZFS clone $fssnap $fsclone
112log_must $ZFS clone $volsnap $volclone
113
114prop_name=$(valid_user_property 10)
115value=$(user_property_value 16)
116log_must eval "$ZFS set $prop_name='$value' $pool"
117log_must eval "check_user_prop $pool $prop_name '$value'"
118log_must inherit_check $prop_name $pool $fs $vol $fsclone $volclone
119
120new_fsclone=$fs/fsclone; new_volclone=$fs/volclone
121log_must $ZFS rename $fsclone $new_fsclone
122log_must $ZFS rename $volclone $new_volclone
123log_must inherit_check $prop_name $pool $fs $new_fsclone $new_volclone
124
125log_note "Set intermediate dataset will change the inherited relationship."
126new_value=$(user_property_value 16)
127log_must eval "$ZFS set $prop_name='$new_value' $fs"
128log_must eval "check_user_prop $fs $prop_name '$new_value'"
129log_must inherit_check $prop_name $fs $new_fsclone $new_volclone
130
131log_pass "User defined property inherited from its parent passed."
132