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