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