f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Simple function to get the source of the specified property.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If unable to get the property then exits.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction get_prop_src # property dataset
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset prop_val
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset prop=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset dataset=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy prop_val=`zfs get -H -o source $prop $dataset`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $? -ne 0 ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "Unable to determine the source of $prop " \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "property for dataset $dataset"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy else
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy echo $prop_val
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Function to check the 'source' of a property. The source can
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# either be "default", "local", or "inherited from <parent dataset>".
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The 'expected src' argument must be either "default", "local", or
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# a dataset name.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Returns 0 on success, 1 on failure.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction verify_prop_src # child_dataset property expected_src
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset target=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset prop=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset expected=$3
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy prop_src=`get_prop_src $prop $target`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy #
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # Rather than just checking if $prop_src == $expected
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # we first determine what value $expected should have.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # This allows us to catch the case where a property
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # has a source of "local" but we expected it to be
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # "default"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy #
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $expected == "default" ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $prop_src != $expected ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_note "Property $prop of $target has source"\
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy " $prop_src rather than $expected"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy return 1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy elif [[ $expected == "local" ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $prop_src != $expected ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_note "Property $prop of $target has source"\
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy " $prop_src rather than $expected"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy return 1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy elif [[ $prop_src != "inherited from $expected" ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_note "Property $prop of $expected has source $prop_src"\
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy " rather than 'inherited from $expected'"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy return 1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy return 0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Simple function to set a property to a
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# specified value and verify it has changed
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# correctly.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction set_n_verify_prop #property value dataset
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset prop=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset prop_val=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset dataset=$3
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zfs set $prop=$prop_val $dataset
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy check_val=`get_prop $prop $dataset`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $check_val != $prop_val ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "Property $prop of $dataset has value $check_val"\
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy " rather than $prop_val"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}