1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License (the "License"). 6# You may not use this file except in compliance with the License. 7# 8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9# or https://opensource.org/licenses/CDDL-1.0. 10# See the License for the specific language governing permissions 11# and limitations under the License. 12# 13# When distributing Covered Code, include this CDDL HEADER in each 14# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15# If applicable, add the following below this CDDL HEADER, with the 16# fields enclosed by brackets "[]" replaced with your own identifying 17# information: Portions Copyright [yyyy] [name of copyright owner] 18# 19# CDDL HEADER END 20# 21 22# 23# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26 27# 28# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 29# 30 31. $STF_SUITE/include/libtest.shlib 32. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.cfg 33 34# 35# Given a pool vdevs list, create the pool,verify the created pool, 36# and destroy the pool 37# $1, pool name 38# $2, pool type, mirror, raidz, or none 39# $3, vdevs list 40# 41function create_pool_test 42{ 43 typeset pool=$1 44 typeset keywd=$2 45 typeset vdevs 46 eval "typeset -a diskarray=($3)" 47 48 for vdevs in "${diskarray[@]}"; do 49 create_pool $pool $keywd $vdevs 50 log_must poolexists $pool 51 destroy_pool $pool 52 done 53} 54 55# 56# Create a file for storage pool vdev 57# $1, file size 58# 59function create_blockfile 60{ 61 typeset size=$1 62 typeset file=$(mktemp) 63 truncate -s $size $file 64 echo $file 65} 66 67# 68# Find the storage device in /etc/vfstab 69# 70function find_vfstab_dev 71{ 72 if is_illumos; then 73 vfstab="/etc/vfstab" 74 else 75 vfstab="/etc/fstab" 76 fi 77 78 awk -v pat="^${DEV_DSKDIR}" '$0 ~ pat {sub(/:$/, "", $1); print $1}' $vfstab 79} 80 81# 82# Save the system current dump device configuration 83# 84function save_dump_dev 85{ 86 if is_illumos; then 87 dumpadm | grep "Dump device" | cut -f2 -d : | awk '{print $1}' 88 fi 89} 90 91# 92# Verify a pools enabled features match the provided feature set. 93# $1, pool name 94# $2, feature set(s) 95# 96# check_feature_set $TESTPOOL set1 set2 set3 ... 97# 98function check_feature_set 99{ 100 typeset pool=$1 101 typeset feature_set=$2 102 shift 103 104 for set in "$@"; do 105 if test -e "$ZPOOL_COMPAT_DIR/$set"; then 106 file="$ZPOOL_COMPAT_DIR/$set" 107 else 108 log_fail "Missing feature file: $ZPOOL_COMPAT_DIR/$set" 109 fi 110 done 111 112 # 113 # Create a temporary file which contains all features which are 114 # common to the listed feature sets. This is used for comparison 115 # below to determine which features should be enabled. 116 # 117 typeset tmpfile=$(mktemp) 118 119 while read line; do 120 typeset flag=1 121 122 if [[ "$line" == "#*" ]]; then 123 continue 124 fi 125 126 for set in "$@"; do 127 if ! grep -q "$line" $ZPOOL_COMPAT_DIR/$set; then 128 flag=0 129 break; 130 fi 131 done 132 133 if [[ $flag -eq 1 ]]; then 134 echo "$line" >>$tmpfile 135 fi 136 done <"$file" 137 138 # 139 # Verify every enabled feature appears in the merged feature set. 140 # Verify every disabled feature does not. 141 # 142 for feature in $(zpool get all $pool | \ 143 awk '$2 ~ /feature@/ { print $2 }'); do 144 state=$(get_pool_prop $feature $pool) 145 name=$(cut -d'@' -f2 <<<"$feature") 146 147 if [[ "$state" = "enabled" || "$state" = "active" ]]; then 148 if ! grep -q $name $tmpfile; then 149 cat $tmpfile 150 rm -f $tmpfile 151 log_fail "Enabled feature $name not " \ 152 "in feature set file" 153 fi 154 elif [[ "$state" = "disabled" ]]; then 155 if grep -q $name $tmpfile; then 156 cat $tmpfile 157 rm -f $tmpfile 158 log_fail "Disabled feature $name is " \ 159 "in feature set file" 160 fi 161 else 162 rm -f $tmpfile 163 log_fail "Feature $name in unknown state $state" 164 fi 165 done 166 167 log_note "Checked all features" 168 169 rm -f $tmpfile 170} 171