]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/cli_root/zdb/zdb_004_pos.ksh
2b4057aa76bb594fb0feec602af18aa0806c5abd
[mirror_zfs-debian.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 #
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
41 zpool labelclear -f $DEV_RDSKDIR/$DISK
42 done
43 }
44
45 verify_runnable "global"
46 verify_disk_count "$DISKS" 2
47 set -A DISK $DISKS
48
49 default_mirror_setup_noexit $DISKS
50 log_must zpool offline $TESTPOOL ${DISK[0]}
51 log_must dd if=/dev/urandom of=$TESTDIR/testfile bs=1K count=2
52 log_must zpool export $TESTPOOL
53 log_must dd if=$DEV_RDSKDIR/${DISK[0]} of=$DEV_RDSKDIR/${DISK[1]} bs=1K count=256 conv=notrunc
54
55 ubs=$(zdb -lu $DEV_RDSKDIR/${DISK[1]} | grep -e LABEL -e Uberblock -e 'labels = ')
56 log_note "vdev 1: ubs $ubs"
57
58 ub_dump_counts=$(zdb -lu $DEV_RDSKDIR/${DISK[1]} | \
59 awk ' /LABEL/ {label=$NF; blocks[label]=0};
60 /Uberblock/ {blocks[label]++};
61 END {print blocks[0],blocks[1],blocks[2],blocks[3]}')
62 (( $? != 0)) && log_fail "failed to get ub_dump_counts from DISK[1]"
63 log_note "vdev 1: ub_dump_counts $ub_dump_counts"
64
65 set -A dump_count $ub_dump_counts
66 for label in 0 1 2 3; do
67 if [[ $label -lt 2 ]]; then
68 [[ ${dump_count[$label]} -eq 0 ]] && \
69 log_fail "zdb incorrectly dumps duplicate uberblocks"
70 else
71 [[ ${dump_count[$label]} -ne 0 ]] && \
72 log_fail "zdb incorrectly dumps duplicate uberblocks"
73 fi
74 done
75
76 cleanup
77
78 log_pass "zdb produces unique dumps of uberblocks"