1# 2# CDDL HEADER START 3# 4# This file and its contents are supplied under the terms of the 5# Common Development and Distribution License ("CDDL"), version 1.0. 6# You may only use this file in accordance with the terms of version 7# 1.0 of the CDDL. 8# 9# A full copy of the text of the CDDL should have accompanied this 10# source. A copy of the CDDL is also available via the Internet at 11# http://www.illumos.org/license/CDDL. 12# 13# CDDL HEADER END 14# 15 16# 17# Copyright (c) 2015, 2016 by Delphix. All rights reserved. 18# 19 20function get_conf_section # regex conf 21{ 22 typeset regex="$1" 23 typeset conf="$2" 24 25 awk -v r="$1" '$0 ~ r, 0 {if($0 ~ r) next; if(/children\[/) exit; print}' "$conf" 26} 27 28function get_leaf_vd_zap # dsk conf 29{ 30 get_conf_section "$1" "$2" | awk '/com.delphix:vdev_zap_leaf: [0-9]+/ {print $2}' 31} 32 33function get_top_vd_zap # dsk conf 34{ 35 get_conf_section "$1" "$2" | awk '/com.delphix:vdev_zap_top: [0-9]+/ {print $2}' 36} 37 38function assert_has_sentinel # conf 39{ 40 log_must grep -q "com.delphix:has_per_vdev_zaps" "$1" 41} 42 43function assert_zap_common # pool vd lvl zapobj 44{ 45 typeset pool=$1 46 typeset vd="$2" 47 typeset lvl=$3 48 typeset zapobj=$4 49 50 if [ -z "$zapobj" ]; then 51 log_fail "$vd on $pool has no $lvl ZAP in config" 52 elif ! zdb -d $pool $zapobj | grep -q 'zap'; then 53 log_fail "$vd on $pool has no $lvl ZAP in MOS" 54 fi 55} 56 57function assert_top_zap # pool vd conf 58{ 59 typeset pool=$1 60 typeset vd="$2" 61 typeset conf=$3 62 63 top_zap=$(get_top_vd_zap "$vd" $conf) 64 assert_zap_common $pool "$vd" "top" $top_zap 65} 66 67function assert_leaf_zap # pool vd conf 68{ 69 typeset pool=$1 70 typeset vd="$2" 71 typeset conf=$3 72 73 leaf_zap=$(get_leaf_vd_zap "$vd" $conf) 74 assert_zap_common $pool "$vd" "leaf" $leaf_zap 75} 76 77# 78# Code common to setup/teardown for each test. 79# 80 81function cleanup 82{ 83 datasetexists $TESTPOOL && log_must zpool destroy -f $TESTPOOL 84 [ -e $conf ] && log_must rm -f "$conf" 85 poolexists $POOL2 && log_must zpool destroy -f $POOL2 86} 87 88log_onexit cleanup 89