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" 43orig_top=$(get_top_vd_zap $DISK $conf) 44orig_leaf=$(get_leaf_vd_zap $DISK $conf) 45assert_zap_common $TESTPOOL $DISK "top" $orig_top 46 47# 48# Attach a disk. 49# 50 51read -r _ disk2 _ <<<"$DISKS" 52log_must zpool attach $TESTPOOL $DISK $disk2 53log_must zpool wait -t resilver $TESTPOOL 54log_must eval "zdb -PC $TESTPOOL > $conf" 55 56# Ensure top-level ZAP was transferred successfully. 57new_top=$(get_top_vd_zap "type: 'mirror'" $conf) 58if [[ "$new_top" -ne "$orig_top" ]]; then 59 log_fail "Top-level ZAP wasn't transferred successfully on attach." 60fi 61 62# Ensure leaf ZAP of original disk was transferred successfully. 63new_leaf=$(get_leaf_vd_zap $DISK $conf) 64if [[ "$new_leaf" -ne "$orig_leaf" ]]; then 65 log_fail "$DISK used to have leaf-level ZAP $orig_leaf, now has "\ 66 "$new_leaf" 67fi 68# Ensure original disk no longer has top-level ZAP. 69dsk1_top=$(get_top_vd_zap $DISK $conf) 70[[ -n "$dsk1_top" ]] && log_fail "$DISK has top-level ZAP, but is only leaf." 71 72# Ensure attached disk got a leaf-level ZAP but not a top-level ZAP. 73dsk2_top=$(get_top_vd_zap $disk2 $conf) 74dsk2_leaf=$(get_leaf_vd_zap $disk2 $conf) 75[[ -n "$dsk2_top" ]] && log_fail "Attached disk $disk2 has top ZAP." 76[[ -z "$dsk2_leaf" ]] && log_fail "Attached disk $disk2 has no leaf ZAP." 77 78# 79# Detach original disk. 80# 81 82log_must zpool detach $TESTPOOL $DISK 83log_must eval "zdb -PC $TESTPOOL > $conf" 84 85final_top=$(get_top_vd_zap $disk2 $conf) 86final_leaf=$(get_leaf_vd_zap $disk2 $conf) 87# Make sure top ZAP was successfully transferred. 88[[ "$final_top" -ne "$orig_top" ]] && log_fail "Lost top-level ZAP when "\ 89 "promoting $disk2 (expected $orig_top, found $final_top)" 90 91# Make sure leaf ZAP was successfully transferred. 92[[ "$final_leaf" -ne "$dsk2_leaf" ]] && log_fail "$disk2 lost its leaf ZAP "\ 93 "on promotion (expected $dsk2_leaf, got $final_leaf)" 94 95log_pass 96