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