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