]>
Commit | Line | Data |
---|---|---|
3c9e0d67 OF |
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) 2017 by Lawrence Livermore National Security, LLC. | |
16 | # | |
17 | ||
18 | . $STF_SUITE/include/libtest.shlib | |
19 | ||
20 | # | |
21 | # Description: | |
22 | # zdb will not produce redundant dumps of uberblocks | |
23 | # | |
24 | # Strategy: | |
25 | # 1. Create a pool with two vdevs, A and B | |
26 | # 2. Offline vdev A | |
27 | # 3. Do some I/O | |
28 | # 4. Export the pool | |
29 | # 5. Copy label 1 from vdev A to vdev B | |
30 | # 6. Collect zdb -lu output for vdev B | |
31 | # 7. Verify labels 0 and 1 have unique Uberblocks, but 2 and 3 have none | |
32 | # | |
33 | ||
34 | log_assert "Verify zdb produces unique dumps of uberblocks" | |
35 | log_onexit cleanup | |
36 | ||
37 | function cleanup | |
38 | { | |
39 | datasetexists $TESTPOOL && destroy_pool $TESTPOOL | |
40 | for DISK in $DISKS; do | |
c1d9abf9 | 41 | zpool labelclear -f $DEV_RDSKDIR/$DISK |
3c9e0d67 | 42 | done |
7839c4b5 MM |
43 | if is_freebsd ; then |
44 | log_must sysctl kern.geom.debugflags=$saved_debugflags | |
45 | fi | |
3c9e0d67 OF |
46 | } |
47 | ||
7839c4b5 MM |
48 | if is_freebsd ; then |
49 | # FreeBSD won't allow writing to an in-use device without this set | |
50 | saved_debugflags=$(sysctl -n kern.geom.debugflags) | |
51 | log_must sysctl kern.geom.debugflags=16 | |
52 | fi | |
53 | ||
3c9e0d67 OF |
54 | verify_runnable "global" |
55 | verify_disk_count "$DISKS" 2 | |
56 | set -A DISK $DISKS | |
7839c4b5 MM |
57 | if is_freebsd ; then |
58 | WHOLE_DISK=/dev/${DISK[0]} | |
59 | else | |
60 | WHOLE_DISK=${DISK[0]} | |
61 | fi | |
3c9e0d67 OF |
62 | |
63 | default_mirror_setup_noexit $DISKS | |
8e5d1484 PZ |
64 | DEVS=$(get_pool_devices ${TESTPOOL} ${DEV_RDSKDIR}) |
65 | [[ -n $DEVS ]] && set -A DISK $DEVS | |
66 | ||
67 | log_must zpool offline $TESTPOOL ${WHOLE_DISK} | |
c1d9abf9 JWK |
68 | log_must dd if=/dev/urandom of=$TESTDIR/testfile bs=1K count=2 |
69 | log_must zpool export $TESTPOOL | |
8e5d1484 | 70 | |
c1d9abf9 | 71 | log_must dd if=$DEV_RDSKDIR/${DISK[0]} of=$DEV_RDSKDIR/${DISK[1]} bs=1K count=256 conv=notrunc |
3c9e0d67 | 72 | |
7839c4b5 MM |
73 | if is_freebsd; then |
74 | DISK1="/dev/${DISK[1]}" | |
75 | else | |
76 | DISK1="${DISK[1]}" | |
77 | fi | |
78 | ||
79 | ubs=$(zdb -lu ${DISK1} | grep -e LABEL -e Uberblock -e 'labels = ') | |
3c9e0d67 OF |
80 | log_note "vdev 1: ubs $ubs" |
81 | ||
7839c4b5 | 82 | ub_dump_counts=$(zdb -lu ${DISK1} | \ |
c1d9abf9 | 83 | awk ' /LABEL/ {label=$NF; blocks[label]=0}; |
3c9e0d67 OF |
84 | /Uberblock/ {blocks[label]++}; |
85 | END {print blocks[0],blocks[1],blocks[2],blocks[3]}') | |
86 | (( $? != 0)) && log_fail "failed to get ub_dump_counts from DISK[1]" | |
87 | log_note "vdev 1: ub_dump_counts $ub_dump_counts" | |
88 | ||
89 | set -A dump_count $ub_dump_counts | |
90 | for label in 0 1 2 3; do | |
91 | if [[ $label -lt 2 ]]; then | |
92 | [[ ${dump_count[$label]} -eq 0 ]] && \ | |
93 | log_fail "zdb incorrectly dumps duplicate uberblocks" | |
94 | else | |
95 | [[ ${dump_count[$label]} -ne 0 ]] && \ | |
96 | log_fail "zdb incorrectly dumps duplicate uberblocks" | |
97 | fi | |
98 | done | |
99 | ||
100 | cleanup | |
101 | ||
102 | log_pass "zdb produces unique dumps of uberblocks" |