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) 2021 by vStack. All rights reserved.
16#
17
18. $STF_SUITE/include/libtest.shlib
19. $STF_SUITE/include/blkdev.shlib
20
21#
22# Description:
23# zdb -l will report corrupted labels checksums
24#
25# Strategy:
26# 1. Create pool with some number of vdevs and export it
27# 2. Corrupt label 0 and label 1, check that corrupted labels are reported
28# 3. Check that pool still be imported correctly
29# 4. Corrupt all labels, check that all corrupted labels are reported
30# 5. Check that pool cannot be imported
31#
32
33log_assert "Verify zdb -l will report corrupted labels checksums"
34log_onexit cleanup
35
36VIRTUAL_DISK=$TEST_BASE_DIR/disk
37
38function cleanup
39{
40	poolexists $TESTPOOL && log_must destroy_pool $TESTPOOL
41	[[ -f $VIRTUAL_DISK ]] && log_must rm $VIRTUAL_DISK
42}
43
44verify_runnable "global"
45
46log_must truncate -s $(($MINVDEVSIZE * 8)) $VIRTUAL_DISK
47
48log_must zpool create $TESTPOOL $VIRTUAL_DISK
49log_must zpool export $TESTPOOL
50
51corrupt_label_checksum 0 $VIRTUAL_DISK
52corrupt_label_checksum 1 $VIRTUAL_DISK
53
54msg_count=$(zdb -l $VIRTUAL_DISK | grep -c '(Bad label cksum)')
55[ $msg_count -ne 1 ] && \
56    log_fail "zdb -l produces an incorrect number of corrupted labels."
57
58msg_count=$(zdb -lll $VIRTUAL_DISK | grep -c '(Bad label cksum)')
59[ $msg_count -ne 2 ] && \
60    log_fail "zdb -l produces an incorrect number of corrupted labels."
61
62log_must zpool import $TESTPOOL -d $TEST_BASE_DIR
63log_must zpool export $TESTPOOL
64
65corrupt_label_checksum 0 $VIRTUAL_DISK
66corrupt_label_checksum 1 $VIRTUAL_DISK
67corrupt_label_checksum 2 $VIRTUAL_DISK
68corrupt_label_checksum 3 $VIRTUAL_DISK
69
70msg_count=$(zdb -lll $VIRTUAL_DISK | grep -c '(Bad label cksum)')
71[ $msg_count -ne 4 ] && \
72    log_fail "zdb -l produces an incorrect number of corrupted labels."
73
74log_mustnot zpool import $TESTPOOL -d $TEST_BASE_DIR
75
76cleanup
77
78log_pass "zdb -l bad cksum report is correct."
79