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# 32*f38cb554SJohn Wren Kennedy# Simple function to get the source of the specified property. 33*f38cb554SJohn Wren Kennedy# If unable to get the property then exits. 34*f38cb554SJohn Wren Kennedy# 35*f38cb554SJohn Wren Kennedyfunction get_prop_src # property dataset 36*f38cb554SJohn Wren Kennedy{ 37*f38cb554SJohn Wren Kennedy typeset prop_val 38*f38cb554SJohn Wren Kennedy typeset prop=$1 39*f38cb554SJohn Wren Kennedy typeset dataset=$2 40*f38cb554SJohn Wren Kennedy 41*f38cb554SJohn Wren Kennedy prop_val=`$ZFS get -H -o source $prop $dataset` 42*f38cb554SJohn Wren Kennedy 43*f38cb554SJohn Wren Kennedy if [[ $? -ne 0 ]]; then 44*f38cb554SJohn Wren Kennedy log_fail "Unable to determine the source of $prop " \ 45*f38cb554SJohn Wren Kennedy "property for dataset $dataset" 46*f38cb554SJohn Wren Kennedy else 47*f38cb554SJohn Wren Kennedy echo $prop_val 48*f38cb554SJohn Wren Kennedy fi 49*f38cb554SJohn Wren Kennedy} 50*f38cb554SJohn Wren Kennedy 51*f38cb554SJohn Wren Kennedy# 52*f38cb554SJohn Wren Kennedy# Function to check the 'source' of a property. The source can 53*f38cb554SJohn Wren Kennedy# either be "default", "local", or "inherited from <parent dataset>". 54*f38cb554SJohn Wren Kennedy# 55*f38cb554SJohn Wren Kennedy# The 'expected src' argument must be either "default", "local", or 56*f38cb554SJohn Wren Kennedy# a dataset name. 57*f38cb554SJohn Wren Kennedy# 58*f38cb554SJohn Wren Kennedy# Returns 0 on success, 1 on failure. 59*f38cb554SJohn Wren Kennedy# 60*f38cb554SJohn Wren Kennedyfunction verify_prop_src # child_dataset property expected_src 61*f38cb554SJohn Wren Kennedy{ 62*f38cb554SJohn Wren Kennedy typeset target=$1 63*f38cb554SJohn Wren Kennedy typeset prop=$2 64*f38cb554SJohn Wren Kennedy typeset expected=$3 65*f38cb554SJohn Wren Kennedy 66*f38cb554SJohn Wren Kennedy prop_src=`get_prop_src $prop $target` 67*f38cb554SJohn Wren Kennedy 68*f38cb554SJohn Wren Kennedy # 69*f38cb554SJohn Wren Kennedy # Rather than just checking if $prop_src == $expected 70*f38cb554SJohn Wren Kennedy # we first determine what value $expected should have. 71*f38cb554SJohn Wren Kennedy # This allows us to catch the case where a property 72*f38cb554SJohn Wren Kennedy # has a source of "local" but we expected it to be 73*f38cb554SJohn Wren Kennedy # "default" 74*f38cb554SJohn Wren Kennedy # 75*f38cb554SJohn Wren Kennedy if [[ $expected == "default" ]]; then 76*f38cb554SJohn Wren Kennedy if [[ $prop_src != $expected ]]; then 77*f38cb554SJohn Wren Kennedy log_note "Property $prop of $target has source"\ 78*f38cb554SJohn Wren Kennedy " $prop_src rather than $expected" 79*f38cb554SJohn Wren Kennedy return 1 80*f38cb554SJohn Wren Kennedy fi 81*f38cb554SJohn Wren Kennedy elif [[ $expected == "local" ]]; then 82*f38cb554SJohn Wren Kennedy if [[ $prop_src != $expected ]]; then 83*f38cb554SJohn Wren Kennedy log_note "Property $prop of $target has source"\ 84*f38cb554SJohn Wren Kennedy " $prop_src rather than $expected" 85*f38cb554SJohn Wren Kennedy return 1 86*f38cb554SJohn Wren Kennedy fi 87*f38cb554SJohn Wren Kennedy elif [[ $prop_src != "inherited from $expected" ]]; then 88*f38cb554SJohn Wren Kennedy log_note "Property $prop of $expected has source $prop_src"\ 89*f38cb554SJohn Wren Kennedy " rather than 'inherited from $expected'" 90*f38cb554SJohn Wren Kennedy return 1 91*f38cb554SJohn Wren Kennedy fi 92*f38cb554SJohn Wren Kennedy 93*f38cb554SJohn Wren Kennedy return 0 94*f38cb554SJohn Wren Kennedy} 95*f38cb554SJohn Wren Kennedy 96*f38cb554SJohn Wren Kennedy# 97*f38cb554SJohn Wren Kennedy# Simple function to set a property to a 98*f38cb554SJohn Wren Kennedy# specified value and verify it has changed 99*f38cb554SJohn Wren Kennedy# correctly. 100*f38cb554SJohn Wren Kennedy# 101*f38cb554SJohn Wren Kennedyfunction set_n_verify_prop #property value dataset 102*f38cb554SJohn Wren Kennedy{ 103*f38cb554SJohn Wren Kennedy typeset prop=$1 104*f38cb554SJohn Wren Kennedy typeset prop_val=$2 105*f38cb554SJohn Wren Kennedy typeset dataset=$3 106*f38cb554SJohn Wren Kennedy 107*f38cb554SJohn Wren Kennedy $ZFS set $prop=$prop_val $dataset 108*f38cb554SJohn Wren Kennedy check_val=`get_prop $prop $dataset` 109*f38cb554SJohn Wren Kennedy 110*f38cb554SJohn Wren Kennedy if [[ $check_val != $prop_val ]]; then 111*f38cb554SJohn Wren Kennedy log_fail "Property $prop of $dataset has value $check_val"\ 112*f38cb554SJohn Wren Kennedy " rather than $prop_val" 113*f38cb554SJohn Wren Kennedy fi 114*f38cb554SJohn Wren Kennedy} 115