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