1#!/bin/ksh
2
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
14#
15# Copyright (c) 2015 by Delphix. All rights reserved.
16#
17
18#
19# Description:
20# Verify that per-vdev ZAPs are properly transferred on attach/detach.
21#
22# Strategy:
23# 1. Create a pool with one disk. Verify that it has a top and leaf ZAP.
24# 2. Attach a disk.
25# 3. Verify that top-level and leaf-level ZAPs were transferred properly.
26# 4. Verify that the newly-attached disk has a leaf ZAP.
27# 5. Detach the original disk.
28# 6. Verify that top-level and leaf-level ZAPs were transferred properly.
29#
30
31. $STF_SUITE/include/libtest.shlib
32. $STF_SUITE/tests/functional/vdev_zaps/vdev_zaps.kshlib
33
34log_assert "Per-vdev ZAPs are transferred properly on attach/detach"
35
36DISK=${DISKS%% *}
37log_must zpool create -f $TESTPOOL $DISK
38
39# Make the pool.
40conf="$TESTDIR/vz004"
41log_must eval "zdb -PC $TESTPOOL > $conf"
42assert_has_sentinel "$conf"
43assert_root_zap $TESTPOOL "$conf"
44orig_top=$(get_top_vd_zap $DISK $conf)
45orig_leaf=$(get_leaf_vd_zap $DISK $conf)
46assert_zap_common $TESTPOOL $DISK "top" $orig_top
47
48#
49# Attach a disk.
50#
51
52read -r _ disk2 _ <<<"$DISKS"
53log_must zpool attach $TESTPOOL $DISK $disk2
54log_must zpool wait -t resilver $TESTPOOL
55log_must eval "zdb -PC $TESTPOOL > $conf"
56
57# Ensure top-level ZAP was transferred successfully.
58new_top=$(get_top_vd_zap "type: 'mirror'" $conf)
59if [[ "$new_top" -ne "$orig_top" ]]; then
60        log_fail "Top-level ZAP wasn't transferred successfully on attach."
61fi
62
63# Ensure leaf ZAP of original disk was transferred successfully.
64new_leaf=$(get_leaf_vd_zap $DISK $conf)
65if [[ "$new_leaf" -ne "$orig_leaf" ]]; then
66        log_fail "$DISK used to have leaf-level ZAP $orig_leaf, now has "\
67                "$new_leaf"
68fi
69# Ensure original disk no longer has top-level ZAP.
70dsk1_top=$(get_top_vd_zap $DISK $conf)
71[[ -n "$dsk1_top" ]] && log_fail "$DISK has top-level ZAP, but is only leaf."
72
73# Ensure attached disk got a leaf-level ZAP but not a top-level ZAP.
74dsk2_top=$(get_top_vd_zap $disk2 $conf)
75dsk2_leaf=$(get_leaf_vd_zap $disk2 $conf)
76[[ -n "$dsk2_top" ]] && log_fail "Attached disk $disk2 has top ZAP."
77[[ -z "$dsk2_leaf" ]] && log_fail "Attached disk $disk2 has no leaf ZAP."
78
79#
80# Detach original disk.
81#
82
83log_must zpool detach $TESTPOOL $DISK
84log_must eval "zdb -PC $TESTPOOL > $conf"
85
86final_top=$(get_top_vd_zap $disk2 $conf)
87final_leaf=$(get_leaf_vd_zap $disk2 $conf)
88# Make sure top ZAP was successfully transferred.
89[[ "$final_top" -ne "$orig_top" ]] && log_fail "Lost top-level ZAP when "\
90        "promoting $disk2 (expected $orig_top, found $final_top)"
91
92# Make sure leaf ZAP was successfully transferred.
93[[ "$final_leaf" -ne "$dsk2_leaf" ]] && log_fail "$disk2 lost its leaf ZAP "\
94        "on promotion (expected $dsk2_leaf, got $final_leaf)"
95
96log_pass
97