]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/vdev_zaps/vdev_zaps_004_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / vdev_zaps / vdev_zaps_004_pos.ksh
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
34 log_assert "Per-vdev ZAPs are transferred properly on attach/detach"
35
36 DISK=${DISKS%% *}
37 log_must zpool create -f $TESTPOOL $DISK
38
39 # Make the pool.
40 conf="$TESTDIR/vz004"
41 log_must zdb -PC $TESTPOOL > $conf
42 assert_has_sentinel "$conf"
43 orig_top=$(get_top_vd_zap $DISK $conf)
44 orig_leaf=$(get_leaf_vd_zap $DISK $conf)
45 assert_zap_common $TESTPOOL $DISK "top" $orig_top
46
47 #
48 # Attach a disk.
49 #
50
51 disk2=$(echo $DISKS | awk '{print $2}')
52 log_must zpool attach $TESTPOOL $DISK $disk2
53 log_must zdb -PC $TESTPOOL > $conf
54
55 # Ensure top-level ZAP was transferred successfully.
56 new_top=$(get_top_vd_zap "type: 'mirror'" $conf)
57 if [[ "$new_top" -ne "$orig_top" ]]; then
58         log_fail "Top-level ZAP wasn't transferred successfully on attach."
59 fi
60
61 # Ensure leaf ZAP of original disk was transferred successfully.
62 new_leaf=$(get_leaf_vd_zap $DISK $conf)
63 if [[ "$new_leaf" -ne "$orig_leaf" ]]; then
64         log_fail "$DISK used to have leaf-level ZAP $orig_leaf, now has "\
65                 "$new_leaf"
66 fi
67 # Ensure original disk no longer has top-level ZAP.
68 dsk1_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.
72 dsk2_top=$(get_top_vd_zap $disk2 $conf)
73 dsk2_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
81 log_must zpool detach $TESTPOOL $DISK
82 log_must zdb -PC $TESTPOOL > $conf
83
84 final_top=$(get_top_vd_zap $disk2 $conf)
85 final_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
94 log_pass