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