1215198a6SJoe Stein#
2215198a6SJoe Stein# CDDL HEADER START
3215198a6SJoe Stein#
4215198a6SJoe Stein# This file and its contents are supplied under the terms of the
5215198a6SJoe Stein# Common Development and Distribution License ("CDDL"), version 1.0.
6215198a6SJoe Stein# You may only use this file in accordance with the terms of version
7215198a6SJoe Stein# 1.0 of the CDDL.
8215198a6SJoe Stein#
9215198a6SJoe Stein# A full copy of the text of the CDDL should have accompanied this
10215198a6SJoe Stein# source.  A copy of the CDDL is also available via the Internet at
11215198a6SJoe Stein# http://www.illumos.org/license/CDDL.
12215198a6SJoe Stein#
13215198a6SJoe Stein# CDDL HEADER END
14215198a6SJoe Stein#
15215198a6SJoe Stein
16215198a6SJoe Stein#
17*1d32ba66SJohn Wren Kennedy# Copyright (c) 2015, 2016 by Delphix. All rights reserved.
18215198a6SJoe Stein#
19215198a6SJoe Stein
20215198a6SJoe Steinfunction get_conf_section # regex conf
21215198a6SJoe Stein{
22215198a6SJoe Stein        typeset dsk_line next_vd_line conf section
23215198a6SJoe Stein        typeset regex="$1"
24215198a6SJoe Stein        typeset conf="$2"
25215198a6SJoe Stein
26215198a6SJoe Stein        dsk_line=$(grep -n "$regex" "$conf" | awk -F: '{print $1}')
27215198a6SJoe Stein        if [[ -z "$dsk_line" ]]; then
28215198a6SJoe Stein                return
29215198a6SJoe Stein        fi
30215198a6SJoe Stein        next_vd_line=$(tail -n +$dsk_line "$conf" | \
31215198a6SJoe Stein                grep -n "children\[" | awk -F: '{print $1}' | head -n 1)
32215198a6SJoe Stein
33215198a6SJoe Stein        if [[ -n "$next_vd_line" ]]; then
34215198a6SJoe Stein                section=$(cat "$conf" | sed "1,${dsk_line}d" | head -n \
35215198a6SJoe Stein                        $(($next_vd_line - 2)))
36215198a6SJoe Stein
37215198a6SJoe Stein        else
38215198a6SJoe Stein                section=$(tail -n +$dsk_line "$conf")
39215198a6SJoe Stein        fi
40215198a6SJoe Stein        echo "$section"
41215198a6SJoe Stein}
42215198a6SJoe Stein
43215198a6SJoe Steinfunction get_leaf_vd_zap # dsk conf
44215198a6SJoe Stein{
45215198a6SJoe Stein        typeset section=$(get_conf_section "$1" "$2")
46215198a6SJoe Stein        echo "$section" | egrep \
47215198a6SJoe Stein                "com.delphix:vdev_zap_leaf: [0-9]+" | awk '{print $2}'
48215198a6SJoe Stein}
49215198a6SJoe Stein
50215198a6SJoe Steinfunction get_top_vd_zap # dsk conf
51215198a6SJoe Stein{
52215198a6SJoe Stein        typeset section=$(get_conf_section "$1" "$2")
53215198a6SJoe Stein        echo "$section" | egrep \
54215198a6SJoe Stein                "com.delphix:vdev_zap_top: [0-9]+" | awk '{print $2}'
55215198a6SJoe Stein}
56215198a6SJoe Stein
57215198a6SJoe Steinfunction assert_has_sentinel # conf
58215198a6SJoe Stein{
59215198a6SJoe Stein        res=$(grep "com.delphix:has_per_vdev_zaps" "$1")
60215198a6SJoe Stein        [[ -z "$res" ]] && log_fail "Pool missing ZAP feature sentinel value"
61215198a6SJoe Stein}
62215198a6SJoe Stein
63215198a6SJoe Steinfunction assert_zap_common # pool vd lvl zapobj
64215198a6SJoe Stein{
65215198a6SJoe Stein        typeset pool=$1
66215198a6SJoe Stein        typeset vd="$2"
67215198a6SJoe Stein        typeset lvl=$3
68215198a6SJoe Stein        typeset zapobj=$4
69215198a6SJoe Stein
70215198a6SJoe Stein        if [[ -z "$zapobj" ]]; then
71215198a6SJoe Stein                log_fail "$vd on $pool has no $lvl ZAP in config"
72215198a6SJoe Stein        elif [[ -z "$(zdb -d $pool $zapobj | grep 'zap')" ]]; then
73215198a6SJoe Stein                log_fail "$vd on $pool has no $lvl ZAP in MOS"
74215198a6SJoe Stein        fi
75215198a6SJoe Stein}
76215198a6SJoe Stein
77215198a6SJoe Steinfunction assert_top_zap # pool vd conf
78215198a6SJoe Stein{
79215198a6SJoe Stein        typeset pool=$1
80215198a6SJoe Stein        typeset vd="$2"
81215198a6SJoe Stein        typeset conf=$3
82215198a6SJoe Stein
83215198a6SJoe Stein        top_zap=$(get_top_vd_zap "$vd" $conf)
84215198a6SJoe Stein        assert_zap_common $pool "$vd" "top" $top_zap
85215198a6SJoe Stein}
86215198a6SJoe Stein
87215198a6SJoe Steinfunction assert_leaf_zap # pool vd conf
88215198a6SJoe Stein{
89215198a6SJoe Stein        typeset pool=$1
90215198a6SJoe Stein        typeset vd="$2"
91215198a6SJoe Stein        typeset conf=$3
92215198a6SJoe Stein
93215198a6SJoe Stein        leaf_zap=$(get_leaf_vd_zap "$vd" $conf)
94215198a6SJoe Stein        assert_zap_common $pool "$vd" "leaf" $leaf_zap
95215198a6SJoe Stein}
96215198a6SJoe Stein
97215198a6SJoe Stein#
98215198a6SJoe Stein# Code common to setup/teardown for each test.
99215198a6SJoe Stein#
100215198a6SJoe Stein
101215198a6SJoe Steinfunction cleanup
102215198a6SJoe Stein{
103215198a6SJoe Stein        if datasetexists $TESTPOOL ; then
104215198a6SJoe Stein                log_must zpool destroy -f $TESTPOOL
105215198a6SJoe Stein        fi
106215198a6SJoe Stein        if [[ -e $conf ]]; then
107*1d32ba66SJohn Wren Kennedy                log_must rm -f "$conf"
108215198a6SJoe Stein        fi
109215198a6SJoe Stein        if [[ -e $POOL2 ]]; then
110215198a6SJoe Stein                log_must zpool destroy -f $POOL2
111215198a6SJoe Stein        fi
112215198a6SJoe Stein}
113215198a6SJoe Stein
114215198a6SJoe Steinlog_onexit cleanup
115