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