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
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.
17 # Copyright (c) 2015, 2016 by Delphix. All rights reserved.
20 function get_conf_section # regex conf
22 typeset dsk_line next_vd_line conf section
26 dsk_line=$(grep -n "$regex" "$conf" | awk -F: '{print $1}')
27 if [[ -z "$dsk_line" ]]; then
30 next_vd_line=$(tail -n +$dsk_line "$conf" | \
31 grep -n "children\[" | awk -F: '{print $1}' | head -n 1)
33 if [[ -n "$next_vd_line" ]]; then
34 section=$(cat "$conf" | sed "1,${dsk_line}d" | head -n \
35 $(($next_vd_line - 2)))
38 section=$(tail -n +$dsk_line "$conf")
43 function get_leaf_vd_zap # dsk conf
45 typeset section=$(get_conf_section "$1" "$2")
46 echo "$section" | egrep \
47 "com.delphix:vdev_zap_leaf: [0-9]+" | awk '{print $2}'
50 function get_top_vd_zap # dsk conf
52 typeset section=$(get_conf_section "$1" "$2")
53 echo "$section" | egrep \
54 "com.delphix:vdev_zap_top: [0-9]+" | awk '{print $2}'
57 function assert_has_sentinel # conf
59 res=$(grep "com.delphix:has_per_vdev_zaps" "$1")
60 [[ -z "$res" ]] && log_fail "Pool missing ZAP feature sentinel value"
63 function assert_zap_common # pool vd lvl zapobj
70 if [[ -z "$zapobj" ]]; then
71 log_fail "$vd on $pool has no $lvl ZAP in config"
72 elif [[ -z "$(zdb -d $pool $zapobj | grep 'zap')" ]]; then
73 log_fail "$vd on $pool has no $lvl ZAP in MOS"
77 function assert_top_zap # pool vd conf
83 top_zap=$(get_top_vd_zap "$vd" $conf)
84 assert_zap_common $pool "$vd" "top" $top_zap
87 function assert_leaf_zap # pool vd conf
93 leaf_zap=$(get_leaf_vd_zap "$vd" $conf)
94 assert_zap_common $pool "$vd" "leaf" $leaf_zap
98 # Code common to setup/teardown for each test.
103 if datasetexists $TESTPOOL ; then
104 log_must zpool destroy -f $TESTPOOL
106 if [[ -e $conf ]]; then
107 log_must rm -f "$conf"
109 if [[ -e $POOL2 ]]; then
110 log_must zpool destroy -f $POOL2