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}
37function get_root_vd_zap # conf
38{
39        awk '/com.klarasystems:vdev_zap_root: [0-9]+/ {print $2}' "$1"
40}
41
42function assert_has_sentinel # conf
43{
44        log_must grep -q "com.delphix:has_per_vdev_zaps" "$1"
45}
46
47function assert_zap_common # pool vd lvl zapobj
48{
49        typeset pool=$1
50        typeset vd="$2"
51        typeset lvl=$3
52        typeset zapobj=$4
53
54        if [ -z "$zapobj" ]; then
55                log_fail "$vd on $pool has no $lvl ZAP in config"
56        elif ! zdb -d $pool $zapobj | grep -q 'zap'; then
57                log_fail "$vd on $pool has no $lvl ZAP in MOS"
58        fi
59}
60
61function assert_root_zap # pool conf
62{
63        typeset pool=$1
64        typeset conf=$2
65
66        root_zap=$(get_root_vd_zap $conf)
67        assert_zap_common $pool "root vdev" "root" $root_zap
68}
69
70function assert_top_zap # pool vd conf
71{
72        typeset pool=$1
73        typeset vd="$2"
74        typeset conf=$3
75
76        top_zap=$(get_top_vd_zap "$vd" $conf)
77        assert_zap_common $pool "$vd" "top" $top_zap
78}
79
80function assert_leaf_zap # pool vd conf
81{
82        typeset pool=$1
83        typeset vd="$2"
84        typeset conf=$3
85
86        leaf_zap=$(get_leaf_vd_zap "$vd" $conf)
87        assert_zap_common $pool "$vd" "leaf" $leaf_zap
88}
89
90#
91# Code common to setup/teardown for each test.
92#
93
94function cleanup
95{
96        datasetexists $TESTPOOL && log_must zpool destroy -f $TESTPOOL
97        [ -e $conf ] && log_must rm -f "$conf"
98        poolexists $POOL2 && log_must zpool destroy -f $POOL2
99}
100
101log_onexit cleanup
102