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# Verify "-d <n>" can work with other options
38#
39# STRATEGY:
40# 1. Create pool, filesystem, dataset, volume, snapshot, and bookmark.
41# 2. Getting an -d option, other options and properties random combination.
42# 3. Using the combination as the parameters of 'zfs get' to check the
43# command line return value.
44#
45
46verify_runnable "both"
47
48set -A options " " "-r" "-H" "-p" "-rHp" "-o name" \
49	"-s local,default,temporary,inherited,none" \
50	"-o name -s local,default,temporary,inherited,none" \
51	"-rHp -o name -s local,default,temporary,inherited,none"
52
53set -A props type used available creation volsize referenced compressratio \
54	mounted origin recordsize quota reservation mountpoint sharenfs \
55	checksum compression atime devices exec readonly setuid snapdir \
56	aclinherit canmount primarycache secondarycache \
57	usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \
58	userquota@root groupquota@root userused@root groupused@root
59if is_freebsd; then
60	set -A props ${props[*]} jailed aclmode
61else
62	set -A props ${props[*]} zoned acltype
63fi
64
65zfs upgrade -v > /dev/null 2>&1
66if [[ $? -eq 0 ]]; then
67	set -A props ${props[*]} version
68fi
69
70set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
71	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP
72
73set -A bookmark_props creation
74set -A bookmark $TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK
75
76log_assert "Verify '-d <n>' can work with other options"
77log_onexit cleanup
78
79# Create volume and filesystem's snapshot
80create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
81create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
82
83# Create filesystem and volume's bookmark
84create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK
85create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK
86
87typeset -i opt_numb=16
88typeset -i prop_numb=16
89typeset -i i=0
90typeset -i item=0
91typeset -i depth_item=0
92
93for dst in ${dataset[@]}; do
94	(( i=0 ))
95	while (( i < opt_numb )); do
96		(( item = $RANDOM % ${#options[@]} ))
97		(( depth_item = $RANDOM % ${#depth_options[@]} ))
98		for prop in $(gen_option_str "${props[*]}" "" "," $prop_numb)
99		do
100			log_must eval "zfs get -${depth_options[depth_item]} ${options[item]} $prop $dst > /dev/null 2>&1"
101		done
102		(( i += 1 ))
103	done
104done
105
106for dst in ${bookmark[@]}; do
107	(( i=0 ))
108	while (( i < opt_numb )); do
109		(( item = $RANDOM % ${#options[@]} ))
110		(( depth_item = $RANDOM % ${#depth_options[@]} ))
111		log_must eval "zfs get -${depth_options[depth_item]} ${options[item]} $bookmark_props $dst > /dev/null 2>&1"
112		(( i += 1 ))
113	done
114done
115
116log_pass "Verify '-d <n>' can work with other options"
117
118