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