f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
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# 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# 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# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/inheritance/inherit.kshlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Test that properties are correctly inherited using 'zfs set',
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 'zfs inherit' and 'zfs inherit -r'.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1) Read a configX.cfg file and create the specified datasets
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 2) Read a stateX.cfg file and execute the commands within it
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and verify that the properties have the correct values
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 3) Repeat steps 1-2 for each configX and stateX files found.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "Test properties are inherited correctly"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Simple function to create specified datasets.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset type=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Function to walk through all the properties in a
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# dataset, setting them to a 'local' value if required.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i i=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # Though the effect of '-' and 'default' is the same we
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # call them out via a log_note to aid in debugging the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_note "Leaving properties for $dataset unchanged."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_note "Leaving properties for $dataset at default values."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_note "Setting properties for $dataset to local values."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "Unrecognised init code $init_code"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# We enter this function either to update the recordsize value
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# in the default array, or to update the local value array.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction update_recordsize { #dataset init_code
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # First need to find where the recordsize property is
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy [[ ${prop[idx]} == "recordsize" ]] && break
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $init_code == "-" || $init_code == "default" ]]; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set recordsize=$record_val $dataset
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The mountpoint property is slightly different from other properties and
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# so is handled here. For all other properties if they are set to a specific
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# value at a higher level in the data hierarchy (i.e. checksum=on) then that
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# value propogates down the hierarchy unchanged, with the source field being
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# set to 'inherited from <higher dataset>'.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The mountpoint property is different in that while the value propogates
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# down the hierarchy, the value at each level is determined by a combination
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# of the top-level value and the current level in the hierarchy.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# For example consider the case where we have a pool (called pool1), containing
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# a dataset (ctr) which in turn contains a filesystem (fs). If we set the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# mountpoint of the pool to '/mnt2' then the mountpoints for the dataset and
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# filesystem are '/mnt2/ctr' and /mnt2/ctr/fs' respectively, with the 'source'
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# field being set to 'inherited from pool1'.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# So at the filesystem level to calculate what our mountpoint property should
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# be set to we walk back up the hierarchy sampling the mountpoint property at
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# each level and forming up the expected mountpoint value piece by piece until
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# we reach the level specified in the 'source' field, which in this example is
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# the top-level pool.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # Extract mount points specific to datasets
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy elif [[ $dataset == "TESTPOOL/TESTCTR" ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # Walk back up the hierarchy building up the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while [[ $src != $dataset ]]; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Simple function to verify that a property has the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# expected value.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction verify_prop_val #property dataset src index
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # mountpoint property is handled as a special case
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy exp_val=`get_mntpt_val $dataset $src $idx`
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # We are inheriting the value from somewhere
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $prop_val != $exp_val ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # After putback PSARC/2008/231 Apr,09,2008,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # the default value of aclinherit has changed to be
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # but the old interface of 'secure' still exist
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "$prop of $dataset is [$prop_val] rather "\
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Function to read the configX.cfg files and create the specified
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# dataset hierarchy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while read name type init ; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Function to check an exit flag, calling log_fail if that exit flag
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# is non-zero. Can be used from code that runs in a tight loop, which
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# would otherwise result in a lot of journal output.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction check_failure { # int status, error message to use
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $exit_flag -ne 0 ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Main function. Executes the commands specified in the stateX.cfg
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# files and then verifies that all the properties have the correct
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# values and 'source' fields.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i i=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i j=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while IFS=: read target op; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # The user can if they wish specify that no
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # operation be performed (by specifying '-'
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # verify that the dataset hierarchy has been
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # configX.cfg file (which includes 'set'ting
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # properties at a higher level and checking
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # that they propogate down to the lower levels.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # check_failure, rather than log_must - this
b021ac0b78f8df3d9c421783d9a323723df84925Matthew Ahrens# Note that we keep this list relatively short so that this test doesn't
b021ac0b78f8df3d9c421783d9a323723df84925Matthew Ahrens# time out (after taking more than 10 minutes).
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Note except for the mountpoint default value (which is handled in
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# the routine itself), each property specified in the 'prop' array
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# above must have a corresponding entry in the two arrays below.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Global flag indicating whether the default record size had been
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyset -A config_files $(ls $STF_SUITE/tests/functional/inheritance/config*[1-9]*.cfg)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyset -A state_files $(ls $STF_SUITE/tests/functional/inheritance/state*.cfg)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Global list of datasets created.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif [[ ${#config_files[*]} != ${#state_files[*]} ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "Must have the same number of config files " \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy " (${#config_files[*]}) and state files ${#state_files[*]}"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_note "Testing configuration ${config_files[k]}"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "Properties correctly inherited as expected"