1*f38cb554SJohn Wren Kennedy# 2*f38cb554SJohn Wren Kennedy# CDDL HEADER START 3*f38cb554SJohn Wren Kennedy# 4*f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the 5*f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License"). 6*f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License. 7*f38cb554SJohn Wren Kennedy# 8*f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 10*f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions 11*f38cb554SJohn Wren Kennedy# and limitations under the License. 12*f38cb554SJohn Wren Kennedy# 13*f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 14*f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 16*f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 17*f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 18*f38cb554SJohn Wren Kennedy# 19*f38cb554SJohn Wren Kennedy# CDDL HEADER END 20*f38cb554SJohn Wren Kennedy# 21*f38cb554SJohn Wren Kennedy 22*f38cb554SJohn Wren Kennedy# 23*f38cb554SJohn Wren Kennedy# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24*f38cb554SJohn Wren Kennedy# Use is subject to license terms. 25*f38cb554SJohn Wren Kennedy# 26*f38cb554SJohn Wren Kennedy 27*f38cb554SJohn Wren Kennedy# 28*f38cb554SJohn Wren Kennedy# Copyright (c) 2013 by Delphix. All rights reserved. 29*f38cb554SJohn Wren Kennedy# 30*f38cb554SJohn Wren Kennedy 31*f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 32*f38cb554SJohn Wren Kennedy 33*f38cb554SJohn Wren Kennedyexport USEDTEST=$TESTPOOL/$TESTFS/usedtest-snapused 34*f38cb554SJohn Wren Kennedy 35*f38cb554SJohn Wren Kennedyfunction _check_used # dataset 36*f38cb554SJohn Wren Kennedy{ 37*f38cb554SJohn Wren Kennedy typeset dataset=$1 38*f38cb554SJohn Wren Kennedy 39*f38cb554SJohn Wren Kennedy if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then 40*f38cb554SJohn Wren Kennedy return 41*f38cb554SJohn Wren Kennedy fi 42*f38cb554SJohn Wren Kennedy 43*f38cb554SJohn Wren Kennedy used=$(get_prop used $dataset) 44*f38cb554SJohn Wren Kennedy usedbychildren=$(get_prop usedbychildren $dataset) 45*f38cb554SJohn Wren Kennedy usedbydataset=$(get_prop usedbydataset $dataset) 46*f38cb554SJohn Wren Kennedy usedbyrefreservation=$(get_prop usedbyrefreservation $dataset) 47*f38cb554SJohn Wren Kennedy usedbysnapshots=$(get_prop usedbysnapshots $dataset) 48*f38cb554SJohn Wren Kennedy ((used_sum = usedbychildren + usedbydataset + \ 49*f38cb554SJohn Wren Kennedy usedbyrefreservation + usedbysnapshots)) 50*f38cb554SJohn Wren Kennedy if ((used != used_sum)); then 51*f38cb554SJohn Wren Kennedy log_fail "$dataset: used($used) is not the sum($used_sum) of usedby*" 52*f38cb554SJohn Wren Kennedy fi 53*f38cb554SJohn Wren Kennedy} 54*f38cb554SJohn Wren Kennedy 55*f38cb554SJohn Wren Kennedyfunction check_used # dataset 56*f38cb554SJohn Wren Kennedy{ 57*f38cb554SJohn Wren Kennedy typeset dataset=$1 58*f38cb554SJohn Wren Kennedy for child in $($ZFS list -rH -t filesystem,volume -o name $dataset) 59*f38cb554SJohn Wren Kennedy do 60*f38cb554SJohn Wren Kennedy _check_used $child 61*f38cb554SJohn Wren Kennedy done 62*f38cb554SJohn Wren Kennedy} 63*f38cb554SJohn Wren Kennedy 64*f38cb554SJohn Wren Kennedyfunction check_usedbychildren # dataset 65*f38cb554SJohn Wren Kennedy{ 66*f38cb554SJohn Wren Kennedy typeset dataset=$1 67*f38cb554SJohn Wren Kennedy typeset -i usedbychildren_sum=0 68*f38cb554SJohn Wren Kennedy typeset -i parent_usedbychildren=0 69*f38cb554SJohn Wren Kennedy for child in $($ZFS list -rH -t filesystem,volume -o name $dataset) 70*f38cb554SJohn Wren Kennedy do 71*f38cb554SJohn Wren Kennedy if [[ "$(get_prop type $child)" == "snapshot" ]]; then 72*f38cb554SJohn Wren Kennedy continue 73*f38cb554SJohn Wren Kennedy fi 74*f38cb554SJohn Wren Kennedy 75*f38cb554SJohn Wren Kennedy # parent 76*f38cb554SJohn Wren Kennedy if [[ "$child" == "$dataset" ]]; then 77*f38cb554SJohn Wren Kennedy parent_usedbychildren=$(get_prop usedbychildren $child) 78*f38cb554SJohn Wren Kennedy else #child 79*f38cb554SJohn Wren Kennedy reservation=$(get_prop reservation $child) 80*f38cb554SJohn Wren Kennedy used=$(get_prop used $child) 81*f38cb554SJohn Wren Kennedy if ((reservation > used)); then 82*f38cb554SJohn Wren Kennedy ((usedbychildren_sum += reservation)) 83*f38cb554SJohn Wren Kennedy else 84*f38cb554SJohn Wren Kennedy ((usedbychildren_sum += used)) 85*f38cb554SJohn Wren Kennedy fi 86*f38cb554SJohn Wren Kennedy fi 87*f38cb554SJohn Wren Kennedy done 88*f38cb554SJohn Wren Kennedy 89*f38cb554SJohn Wren Kennedy if ((parent_usedbychildren != usedbychildren_sum)); then 90*f38cb554SJohn Wren Kennedy log_fail "$dataset: usedbychildren($parent_usedbychildren) is not the sum($usedbychildren_sum) of used by children" 91*f38cb554SJohn Wren Kennedy fi 92*f38cb554SJohn Wren Kennedy} 93*f38cb554SJohn Wren Kennedy 94*f38cb554SJohn Wren Kennedyfunction _check_usedbydataset # dataset 95*f38cb554SJohn Wren Kennedy{ 96*f38cb554SJohn Wren Kennedy typeset dataset=$1 97*f38cb554SJohn Wren Kennedy if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then 98*f38cb554SJohn Wren Kennedy return 99*f38cb554SJohn Wren Kennedy fi 100*f38cb554SJohn Wren Kennedy 101*f38cb554SJohn Wren Kennedy usedbydataset=$(get_prop usedbydataset $dataset) 102*f38cb554SJohn Wren Kennedy referenced=$(get_prop referenced $dataset) 103*f38cb554SJohn Wren Kennedy 104*f38cb554SJohn Wren Kennedy is_cloned=$(get_prop is:cloned $dataset) 105*f38cb554SJohn Wren Kennedy 106*f38cb554SJohn Wren Kennedy if [[ "$is_cloned" == "yes" ]]; then 107*f38cb554SJohn Wren Kennedy if ((usedbydataset > referenced)); then 108*f38cb554SJohn Wren Kennedy log_fail "$dataset(cloned): usedbydataset($usedbydataset) is more than referenced($referenced)" 109*f38cb554SJohn Wren Kennedy fi 110*f38cb554SJohn Wren Kennedy else 111*f38cb554SJohn Wren Kennedy # 112*f38cb554SJohn Wren Kennedy # if non-clones, should usedbydataset == referenced 113*f38cb554SJohn Wren Kennedy # 114*f38cb554SJohn Wren Kennedy if ((usedbydataset != referenced)); then 115*f38cb554SJohn Wren Kennedy log_fail "$dataset: usedbydataset($usedbydataset) is not equal to referenced($referenced)" 116*f38cb554SJohn Wren Kennedy fi 117*f38cb554SJohn Wren Kennedy fi 118*f38cb554SJohn Wren Kennedy} 119*f38cb554SJohn Wren Kennedy 120*f38cb554SJohn Wren Kennedyfunction check_usedbydataset # dataset 121*f38cb554SJohn Wren Kennedy{ 122*f38cb554SJohn Wren Kennedy typeset dataset=$1 123*f38cb554SJohn Wren Kennedy for child in $($ZFS list -rH -t filesystem,volume -o name $dataset) 124*f38cb554SJohn Wren Kennedy do 125*f38cb554SJohn Wren Kennedy _check_usedbydataset $child 126*f38cb554SJohn Wren Kennedy done 127*f38cb554SJohn Wren Kennedy} 128*f38cb554SJohn Wren Kennedy 129*f38cb554SJohn Wren Kennedyfunction _check_usedbyrefreservation # dataset 130*f38cb554SJohn Wren Kennedy{ 131*f38cb554SJohn Wren Kennedy typeset dataset=$1 132*f38cb554SJohn Wren Kennedy if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then 133*f38cb554SJohn Wren Kennedy return 134*f38cb554SJohn Wren Kennedy fi 135*f38cb554SJohn Wren Kennedy 136*f38cb554SJohn Wren Kennedy usedbyrefreservation=$(get_prop usedbyrefreservation $dataset) 137*f38cb554SJohn Wren Kennedy referenced=$(get_prop referenced $dataset) 138*f38cb554SJohn Wren Kennedy refreservation=$(get_prop refreservation $dataset) 139*f38cb554SJohn Wren Kennedy ((diff_ref = refreservation - referenced)) 140*f38cb554SJohn Wren Kennedy if ((usedbyrefreservation > refreservation || \ 141*f38cb554SJohn Wren Kennedy usedbyrefreservation < diff_ref)); then 142*f38cb554SJohn Wren Kennedy log_fail "$dataset: usedbyrefreservation($usedbyrefreservation) checking is not ok" 143*f38cb554SJohn Wren Kennedy fi 144*f38cb554SJohn Wren Kennedy} 145*f38cb554SJohn Wren Kennedy 146*f38cb554SJohn Wren Kennedyfunction check_usedbyrefreservation # dataset 147*f38cb554SJohn Wren Kennedy{ 148*f38cb554SJohn Wren Kennedy typeset dataset=$1 149*f38cb554SJohn Wren Kennedy for child in $($ZFS list -rH -t filesystem,volume -o name $dataset) 150*f38cb554SJohn Wren Kennedy do 151*f38cb554SJohn Wren Kennedy _check_usedbyrefreservation $child 152*f38cb554SJohn Wren Kennedy done 153*f38cb554SJohn Wren Kennedy} 154*f38cb554SJohn Wren Kennedy 155*f38cb554SJohn Wren Kennedyfunction check_usedbysnapshots # dataset 156*f38cb554SJohn Wren Kennedy{ 157*f38cb554SJohn Wren Kennedy typeset dataset=$1 158*f38cb554SJohn Wren Kennedy typeset -i usedbysnapshots_sum=0 159*f38cb554SJohn Wren Kennedy typeset -i parent_usedbysnapshots=0 160*f38cb554SJohn Wren Kennedy for child in $($ZFS list -rH -t filesystem,volume,snapshot -o name $dataset) 161*f38cb554SJohn Wren Kennedy do 162*f38cb554SJohn Wren Kennedy # parent 163*f38cb554SJohn Wren Kennedy if [[ "$child" == "$dataset" ]]; then 164*f38cb554SJohn Wren Kennedy parent_usedbysnapshots=$(get_prop usedbysnapshots $child) 165*f38cb554SJohn Wren Kennedy continue 166*f38cb554SJohn Wren Kennedy fi 167*f38cb554SJohn Wren Kennedy 168*f38cb554SJohn Wren Kennedy if [[ "$(get_prop type $child)" != "snapshot" ]]; then 169*f38cb554SJohn Wren Kennedy continue 170*f38cb554SJohn Wren Kennedy fi 171*f38cb554SJohn Wren Kennedy 172*f38cb554SJohn Wren Kennedy if [[ "$child" != "$dataset@"* ]]; then 173*f38cb554SJohn Wren Kennedy continue 174*f38cb554SJohn Wren Kennedy fi 175*f38cb554SJohn Wren Kennedy 176*f38cb554SJohn Wren Kennedy # snapshot 177*f38cb554SJohn Wren Kennedy used=$(get_prop used $child) 178*f38cb554SJohn Wren Kennedy ((usedbysnapshots_sum += used)) 179*f38cb554SJohn Wren Kennedy done 180*f38cb554SJohn Wren Kennedy 181*f38cb554SJohn Wren Kennedy if ((parent_usedbysnapshots < usedbysnapshots_sum)); then 182*f38cb554SJohn Wren Kennedy log_fail "$dataset: usedbysnapshots($parent_usedbysnapshots) is not more than or equal to" \ 183*f38cb554SJohn Wren Kennedy "the sum($usedbysnapshots_sum) of used of snapshots" 184*f38cb554SJohn Wren Kennedy fi 185*f38cb554SJohn Wren Kennedy} 186