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 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
33. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
34
35#
36# DESCRIPTION:
37# Setting the valid option and properties, 'zfs get' should return the
38# correct property value.
39#
40# STRATEGY:
41# 1. Create pool, filesystem, volume, snapshot, and bookmark.
42# 2. Setting valid parameter, 'zfs get' should succeed.
43# 3. Compare the output property name with the original input property.
44#
45
46verify_runnable "both"
47
48typeset options=("" "-p" "-r" "-H")
49
50typeset -i i=${#options[*]}
51typeset -i j=0
52while ((j<${#depth_options[*]}));
53do
54	options[$i]=-"${depth_options[$j]}"
55	((j+=1))
56	((i+=1))
57done
58
59typeset zfs_props=("type" used available creation volsize referenced \
60    compressratio mounted origin recordsize quota reservation mountpoint \
61    sharenfs checksum compression atime devices exec readonly setuid \
62    snapdir aclinherit canmount primarycache secondarycache version \
63    usedbychildren usedbydataset usedbyrefreservation usedbysnapshots)
64if is_freebsd; then
65	typeset zfs_props_os=(jailed aclmode)
66else
67	typeset zfs_props_os=(zoned acltype)
68fi
69typeset userquota_props=(userquota@root groupquota@root userused@root \
70    groupused@root)
71typeset all_props=("${zfs_props[@]}" \
72    "${zfs_props_os[@]}" \
73    "${userquota_props[@]}")
74typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
75	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP)
76
77typeset bookmark_props=(creation)
78typeset bookmark=($TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK)
79
80#
81# According to dataset and option, checking if 'zfs get' return correct
82# property information.
83#
84# $1 dataset
85# $2 properties which are expected to output into $TESTDIR/$TESTFILE0
86# $3 option
87#
88function check_return_value
89{
90	typeset dst=$1
91	typeset props=$2
92	typeset opt=$3
93	typeset -i found=0
94	typeset p
95
96	for p in $props; do
97		found=0
98
99		while read line; do
100			typeset item
101			item=$(echo $line | awk '{print $2}' 2>&1)
102
103			if [[ $item == $p ]]; then
104				((found += 1))
105				break
106			fi
107		done < $TESTDIR/$TESTFILE0
108
109		if ((found == 0)); then
110			log_fail "'zfs get $opt $props $dst' return " \
111			    "error message.'$p' haven't been found."
112		fi
113	done
114
115	log_note "SUCCESS: 'zfs get $opt $prop $dst'."
116}
117
118log_assert "Setting the valid options and properties 'zfs get' should return " \
119    "the correct property value."
120log_onexit cleanup
121
122# Create filesystem and volume's snapshot
123create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
124create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
125
126# Create filesystem and volume's bookmark
127create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK
128create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK
129
130typeset -i i=0
131while ((i < ${#dataset[@]})); do
132	for opt in "${options[@]}"; do
133		for prop in ${all_props[@]}; do
134			eval "zfs get $opt $prop ${dataset[i]} > \
135			    $TESTDIR/$TESTFILE0"
136			ret=$?
137			if [[ $ret != 0 ]]; then
138				log_fail "zfs get returned: $ret"
139			fi
140			check_return_value ${dataset[i]} "$prop" "$opt"
141		done
142	done
143	((i += 1))
144done
145
146i=0
147while ((i < ${#bookmark[@]})); do
148	for opt in "${options[@]}"; do
149		for prop in ${bookmark_props[@]}; do
150			eval "zfs get $opt $prop ${bookmark[i]} > \
151			    $TESTDIR/$TESTFILE0"
152			ret=$?
153			if [[ $ret != 0 ]]; then
154				log_fail "zfs get returned: $ret"
155			fi
156			check_return_value ${bookmark[i]} "$prop" "$opt"
157		done
158	done
159	((i += 1))
160done
161
162log_pass "Setting the valid options to dataset, it should succeed and return " \
163    "valid value. 'zfs get' pass."
164