xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/property_alias_001_pos.ksh (revision 37e2cd25d56b334a2403f2540a0b0a1e6a40bcd1)
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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2016, 2017 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
34
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
45verify_runnable "both"
46
47function set_and_check #<dataset><set_prop_name><set_value><check_prop_name>
48{
49	typeset ds=$1
50	typeset setprop=$2
51	typeset setval=$3
52	typeset chkprop=$4
53	typeset getval
54
55	log_must zfs set $setprop=$setval $ds
56	if [[ $setval == "gzip-6" ]]; then
57		setval="gzip"
58	fi
59	getval=$(get_prop $chkprop $ds)
60
61	case $setprop in
62		reservation|reserv )
63			if [[ $setval == "none" ]]; then
64				 [[ $getval != "0" ]] && \
65					log_fail "Setting the property $setprop" \
66						"with value $setval fails."
67                        elif [[ $getval != $setval ]]; then
68				log_fail "Setting the property $setprop with" \
69					"with $setval fails."
70			fi
71                        ;;
72                 * )
73                        [[ $getval != $setval ]] && \
74				log_fail "Setting the property $setprop with value \
75					$setval fails."
76                        ;;
77         esac
78}
79
80log_assert "Properties with aliases also work with those aliases."
81
82set -A ro_prop "available" "avail" "referenced" "refer"
83set -A rw_prop "readonly" "rdonly" "compression" "compress" "reservation" "reserv"
84set -A chk_prop "rdonly" "readonly" "compress" "compression" "reserv" "reservation"
85set -A size "512" "1024" "2048" "4096" "8192" "16384" "32768" "65536" "131072"
86
87pool=$TESTPOOL
88fs=$TESTPOOL/$TESTFS
89vol=$TESTPOOL/$TESTVOL
90typeset -l avail_space=$(get_prop avail $pool)
91typeset -l reservsize
92typeset -i i=0
93
94for ds in $pool $fs $vol; do
95	for propname in ${ro_prop[*]}; do
96		zfs get -pH -o value $propname $ds >/dev/null 2>&1
97		(( $? != 0 )) && \
98			log_fail "Get the property $proname of $ds failed."
99	done
100	i=0
101	while (( i < ${#rw_prop[*]} )); do
102		case ${rw_prop[i]} in
103		readonly|rdonly )
104			for val in "on" "off"; do
105				set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]}
106			done
107			;;
108		compression|compress )
109			for val in $(get_compress_opts zfs_set); do
110				set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]}
111			done
112			;;
113		reservation|reserv )
114			(( reservsize = $avail_space % (( $RANDOM + 1 )) ))
115			for val in "0" "$reservsize" "none"; do
116				set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]}
117			done
118			;;
119		esac
120
121		(( i = i + 1 ))
122	done
123	if [[ $ds == $vol ]]; then
124		for propname in "volblocksize" "volblock" ; do
125			zfs get -pH -o value $propname $ds >/dev/null 2>&1
126			(( $? != 0 )) && \
127				log_fail "Get the property $propname of $ds failed."
128		done
129	fi
130done
131
132for ds in $pool $fs; do
133	for propname in "recordsize" "recsize"; do
134		for val in ${size[*]}; do
135			if [[ $propname == "recordsize" ]]; then
136				set_and_check $ds $propname $val "recsize"
137			else
138				set_and_check $ds $propname $val "recordsize"
139			fi
140		done
141	done
142done
143
144log_pass "The alias of a property works as expected."
145