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 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27# ident "@(#)zfs_get_004_pos.ksh 1.3 07/02/06 SMI" 28# 29 30. $STF_SUITE/include/libtest.kshlib 31 32################################################################################# 33# 34# __stc_assertion_start 35# 36# ID: zfs_get_004_pos 37# 38# DESCRIPTION: 39# Verify 'zfs get all' can get all properties for all datasets in the system 40# 41# STRATEGY: 42# 1. Create datasets for testing 43# 2. Issue 'zfs get all' command 44# 3. Verify the command gets all available properties of all datasets 45# 46# TESTABILITY: explicit 47# 48# TEST_AUTOMATION_LEVEL: automated 49# 50# CODING_STATUS: COMPLETED (2006-08-31) 51# 52# __stc_assertion_end 53# 54################################################################################ 55 56verify_runnable "both" 57 58#check 'zfs get all' supportability with the installed OS version 59$ZFS get all >/dev/null 2>&1 60(( $? != 0 )) && log_unsupported "ZFS get all option is unsupported." 61 62 63function cleanup 64{ 65 [[ -e $propfile ]] && $RM -f $propfile 66 67 datasetexists $clone && \ 68 log_must $ZFS destroy $clone 69 for snap in $fssnap $volsnap ; do 70 snapexists $snap && \ 71 log_must $ZFS destroy $snap 72 done 73 74 if [[ -n $globalzone ]] ; then 75 for pool in $TESTPOOL1 $TESTPOOL2 $TESTPOOL3; do 76 poolexists $pool && \ 77 log_must $ZPOOL destroy -f $pool 78 done 79 for file in `$LS $TESTDIR1/poolfile*`; do 80 $RM -f $file 81 done 82 else 83 for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS3; do 84 datasetexists $fs && \ 85 log_must $ZFS destroy -rf $fs 86 done 87 fi 88} 89 90log_assert "Verify the functions of 'zfs get all' work." 91log_onexit cleanup 92 93typeset globalzone="" 94 95if is_global_zone ; then 96 globalzone="true" 97fi 98 99set -A opts "" "-r" "-H" "-p" "-rHp" "-o name" \ 100 "-s local,default,temporary,inherited,none" \ 101 "-o name -s local,default,temporary,inherited,none" \ 102 "-rHp -o name -s local,default,temporary,inherited,none" 103set -A usrprops "a:b=c" "d_1:1_e=0f" "123:456=789" 104 105fs=$TESTPOOL/$TESTFS 106fssnap=$fs@$TESTSNAP 107clone=$TESTPOOL/$TESTCLONE 108volsnap=$TESTPOOL/$TESTVOL@$TESTSNAP 109 110#set user defined properties for $TESTPOOL 111for usrprop in ${usrprops[@]}; do 112 log_must $ZFS set $usrprop $TESTPOOL 113done 114# create snapshot and clone in $TESTPOOL 115log_must $ZFS snapshot $fssnap 116log_must $ZFS clone $fssnap $clone 117log_must $ZFS snapshot $volsnap 118 119# collect datasets which can be set user defined properties 120usrpropds="$clone $fs" 121 122# collect all datasets which we are creating 123allds="$fs $clone $fssnap $volsnap" 124 125#create pool and datasets to guarantee testing under multiple pools and datasets. 126file=$TESTDIR1/poolfile 127typeset -i FILESIZE=104857600 #100M 128(( DFILESIZE = FILESIZE * 2 )) # double of FILESIZE 129typeset -i VOLSIZE=10485760 #10M 130availspace=$(get_prop available $TESTPOOL) 131typeset -i i=0 132 133# make sure 'availspace' is larger then twice of FILESIZE to create a new pool. 134# If any, we only totally create 3 pools for multple datasets testing to limit 135# testing time 136while (( availspace > DFILESIZE )) && (( i < 3 )) ; do 137 (( i += 1 )) 138 139 if [[ -n $globalzone ]] ; then 140 log_must create_vdevs ${file}$i 141 eval pool=\$TESTPOOL$i 142 log_must $ZPOOL create $pool ${file}$i 143 else 144 eval pool=$TESTPOOL/\$TESTFS$i 145 log_must $ZFS create $pool 146 fi 147 148 #set user defined properties for testing 149 for usrprop in ${usrprops[@]}; do 150 log_must $ZFS set $usrprop $pool 151 done 152 153 #create datasets in pool 154 log_must $ZFS create $pool/$TESTFS 155 log_must $ZFS snapshot $pool/$TESTFS@$TESTSNAP 156 log_must $ZFS clone $pool/$TESTFS@$TESTSNAP $pool/$TESTCLONE 157 158 if [[ -n $globalzone ]] ; then 159 log_must $ZFS create -V $VOLSIZE $pool/$TESTVOL 160 else 161 log_must $ZFS create $pool/$TESTVOL 162 fi 163 164 ds=`$ZFS list -H -r -o name -t filesystem,volume $pool` 165 usrpropds="$usrpropds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL" 166 allds="$allds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL \ 167 $pool/$TESTFS@$TESTSNAP" 168 169 availspace=$(get_prop available $TESTPOOL) 170done 171 172#the expected number of property for each type of dataset in this testing 173typeset -i fspropnum=27 174typeset -i snappropnum=8 175typeset -i volpropnum=15 176propfile=$TMPDIR/allpropfile.${TESTCASE_ID} 177 178typeset -i i=0 179typeset -i propnum=0 180typeset -i failflag=0 181while (( i < ${#opts[*]} )); do 182 [[ -e $propfile ]] && $RM -f $propfile 183 log_must eval "$ZFS get ${opts[i]} all >$propfile" 184 185 for ds in $allds; do 186 $GREP $ds $propfile >/dev/null 2>&1 187 (( $? != 0 )) && \ 188 log_fail "There is no property for" \ 189 "dataset $ds in 'get all' output." 190 191 propnum=`$CAT $propfile | $AWK '{print $1}' | \ 192 $GREP "${ds}$" | $WC -l` 193 ds_type=`$ZFS get -H -o value type $ds` 194 case $ds_type in 195 filesystem ) 196 (( propnum < fspropnum )) && \ 197 (( failflag += 1 )) 198 ;; 199 snapshot ) 200 (( propnum < snappropnum )) && \ 201 (( failflag += 1 )) 202 ;; 203 volume ) 204 (( propnum < volpropnum )) && \ 205 (( failflag += 1 )) 206 ;; 207 esac 208 209 (( failflag != 0 )) && \ 210 log_fail " 'zfs get all' fails to get out " \ 211 "all properties for dataset $ds." 212 213 (( propnum = 0 )) 214 (( failflag = 0 )) 215 done 216 217 (( i += 1 )) 218done 219 220log_note "'zfs get' can get particular property for all datasets with that property." 221 222function do_particular_prop_test #<property> <suitable datasets> 223{ 224 typeset props="$1" 225 typeset ds="$2" 226 227 for prop in ${commprops[*]}; do 228 ds=`$ZFS get -H -o name $prop` 229 230 [[ "$ds" != "$allds" ]] && \ 231 log_fail "The result datasets are $ds, but all suitable" \ 232 "datasets are $allds for the property $prop" 233 done 234} 235 236# Here, we do a testing for user defined properties and the most common properties 237# for all datasets. 238commprop="type creation used referenced compressratio" 239usrprop="a:b d_1:1_e 123:456" 240 241do_particular_prop_test "$commprop" "$allds" 242do_particular_prop_test "$usrprop" "$usrpropds" 243 244log_pass "'zfs get all' works as expected." 245