4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
31 . $STF_SUITE/include/libtest.shlib
33 export USEDTEST=$TESTPOOL/$TESTFS/usedtest-snapused
35 function _check_used # dataset
39 if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then
43 used=$(get_prop used $dataset)
44 usedbychildren=$(get_prop usedbychildren $dataset)
45 usedbydataset=$(get_prop usedbydataset $dataset)
46 usedbyrefreservation=$(get_prop usedbyrefreservation $dataset)
47 usedbysnapshots=$(get_prop usedbysnapshots $dataset)
48 ((used_sum = usedbychildren + usedbydataset + \
49 usedbyrefreservation + usedbysnapshots))
50 if ((used != used_sum)); then
51 log_fail "$dataset: used($used) is not the sum($used_sum) of usedby*"
55 function check_used # dataset
58 for child in $(zfs list -rH -t filesystem,volume -o name $dataset)
64 function check_usedbychildren # dataset
67 typeset -i usedbychildren_sum=0
68 typeset -i parent_usedbychildren=0
69 for child in $(zfs list -rH -t filesystem,volume -o name $dataset)
71 if [[ "$(get_prop type $child)" == "snapshot" ]]; then
76 if [[ "$child" == "$dataset" ]]; then
77 parent_usedbychildren=$(get_prop usedbychildren $child)
79 reservation=$(get_prop reservation $child)
80 used=$(get_prop used $child)
81 if ((reservation > used)); then
82 ((usedbychildren_sum += reservation))
84 ((usedbychildren_sum += used))
89 if ((parent_usedbychildren != usedbychildren_sum)); then
90 log_fail "$dataset: usedbychildren($parent_usedbychildren) is not the sum($usedbychildren_sum) of used by children"
94 function _check_usedbydataset # dataset
97 if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then
101 usedbydataset=$(get_prop usedbydataset $dataset)
102 referenced=$(get_prop referenced $dataset)
104 is_cloned=$(get_prop is:cloned $dataset)
106 if [[ "$is_cloned" == "yes" ]]; then
107 if ((usedbydataset > referenced)); then
108 log_fail "$dataset(cloned): usedbydataset($usedbydataset) is more than referenced($referenced)"
112 # if non-clones, should usedbydataset == referenced
114 if ((usedbydataset != referenced)); then
115 log_fail "$dataset: usedbydataset($usedbydataset) is not equal to referenced($referenced)"
120 function check_usedbydataset # dataset
123 for child in $(zfs list -rH -t filesystem,volume -o name $dataset)
125 _check_usedbydataset $child
129 function _check_usedbyrefreservation # dataset
132 if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then
136 usedbyrefreservation=$(get_prop usedbyrefreservation $dataset)
137 referenced=$(get_prop referenced $dataset)
138 refreservation=$(get_prop refreservation $dataset)
139 ((diff_ref = refreservation - referenced))
140 if ((usedbyrefreservation > refreservation || \
141 usedbyrefreservation < diff_ref)); then
142 log_fail "$dataset: usedbyrefreservation($usedbyrefreservation) checking is not ok"
146 function check_usedbyrefreservation # dataset
149 for child in $(zfs list -rH -t filesystem,volume -o name $dataset)
151 _check_usedbyrefreservation $child
155 function check_usedbysnapshots # dataset
158 typeset -i usedbysnapshots_sum=0
159 typeset -i parent_usedbysnapshots=0
160 for child in $(zfs list -rH -t filesystem,volume,snapshot -o name $dataset)
163 if [[ "$child" == "$dataset" ]]; then
164 parent_usedbysnapshots=$(get_prop usedbysnapshots $child)
168 if [[ "$(get_prop type $child)" != "snapshot" ]]; then
172 if [[ "$child" != "$dataset@"* ]]; then
177 used=$(get_prop used $child)
178 ((usedbysnapshots_sum += used))
181 if ((parent_usedbysnapshots < usedbysnapshots_sum)); then
182 log_fail "$dataset: usedbysnapshots($parent_usedbysnapshots) is not more than or equal to" \
183 "the sum($usedbysnapshots_sum) of used of snapshots"