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/include/libtest.kshlib
28. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
29
30###############################################################################
31#
32# __stc_assertion_start
33#
34# ID: property_alias_001_pos
35#
36# DESCRIPTION:
37# Verify the properties with aliases also work with those aliases
38#
39# STRATEGY:
40# 1. Create pool, then create filesystem & volume within it.
41# 2. Set or retrieve property via alias with datasets.
42# 3. Verify the result should be successful.
43#
44# TESTABILITY: explicit
45#
46# TEST_AUTOMATION_LEVEL: automated
47#
48# CODING_STATUS: COMPLETED (2006-08-16)
49#
50# __stc_assertion_end
51#
52################################################################################
53
54verify_runnable "both"
55
56function set_and_check #<dataset><set_prop_name><set_value><check_prop_name>
57{
58	typeset ds=$1
59	typeset setprop=$2
60	typeset setval=$3
61	typeset chkprop=$4
62	typeset getval
63
64	log_must $ZFS set $setprop=$setval $ds
65	if [[ $setval == "gzip-6" ]]; then
66		setval="gzip"
67	fi
68	getval=$(get_prop $chkprop $ds)
69
70	case $setprop in
71		reservation|reserv )
72               		if [[ $setval == "none" ]]; then
73				 [[ $getval != "0" ]] && \
74					log_fail "Setting the property $setprop" \
75						"with value $setval fails."
76                        elif [[ $getval != $setval ]]; then
77				log_fail "Setting the property $setprop with" \
78					"with $setval fails."
79			fi
80                        ;;
81                 * )
82                        [[ $getval != $setval ]] && \
83				log_fail "Setting the property $setprop with value \
84					$setval fails."
85                        ;;
86         esac
87}
88
89log_assert "Properties with aliases also work with those aliases."
90
91set -A ro_prop "available" "avail" "referenced" "refer"
92set -A rw_prop "readonly" "rdonly" "compression" "compress" "reservation" "reserv"
93set -A chk_prop "rdonly" "readonly" "compress" "compression" "reserv" "reservation"
94set -A size "512" "1024" "2048" "4096" "8192" "16384" "32768" "65536" "131072"
95
96pool=$TESTPOOL
97fs=$TESTPOOL/$TESTFS
98vol=$TESTPOOL/$TESTVOL
99typeset -l avail_space=$(get_prop avail $pool)
100typeset -l reservsize
101typeset -i i=0
102
103for ds in $pool $fs $vol; do
104	for propname in ${ro_prop[*]}; do
105		$ZFS get -pH -o value $propname $ds >/dev/null 2>&1
106		(( $? != 0 )) && \
107			log_fail "Get the property $proname of $ds failed."
108	done
109	i=0
110	while (( i < ${#rw_prop[*]} )); do
111		case ${rw_prop[i]} in
112		readonly|rdonly )
113			for val in "on" "off"; do
114				set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]}
115			done
116			;;
117		compression|compress )
118			for val in $(get_compress_opts zfs_set); do
119				set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]}
120			done
121			;;
122		reservation|reserv )
123			(( reservsize = $avail_space % $RANDOM ))
124			for val in "0" "$reservsize" "none"; do
125				set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]}
126			done
127			;;
128		esac
129
130		(( i = i + 1 ))
131	done
132	if [[ $ds == $vol ]]; then
133		for propname in "volblocksize" "volblock" ; do
134			$ZFS get -pH -o value $propname $ds >/dev/null 2>&1
135			(( $? != 0 )) && \
136				log_fail "Get the property $propname of $ds failed."
137		done
138	fi
139done
140
141for ds in $pool $fs; do
142	for propname in "recordsize" "recsize"; do
143		for val in ${size[*]}; do
144			if [[ $propname == "recordsize" ]]; then
145				set_and_check $ds $propname $val "recsize"
146			else
147				set_and_check $ds $propname $val "recordsize"
148			fi
149		done
150	done
151done
152
153log_pass "The alias of a property works as expected."
154