diff options
author | Fedor Uporov <[email protected]> | 2021-11-10 11:22:00 -0800 |
---|---|---|
committer | GitHub <[email protected]> | 2021-11-10 12:22:00 -0700 |
commit | 2a9c572059e9401001bd168465aa521d83e16b32 (patch) | |
tree | 1514117aff657f219290ece1346dc14d93f3fc63 /tests/zfs-tests | |
parent | 6c8f03232aa98e950bfe187f9ff53d3541687b50 (diff) |
zdb: Report bad label checksum
In case if all label checksums will be invalid on any vdev, the pool
will become unimportable. From other side zdb with -l option will not
provide any useful information why it happened. Add notifications
about corrupted label checksums.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Signed-off-by: Fedor Uporov <[email protected]>
Closes #2509
Closes #12685
Diffstat (limited to 'tests/zfs-tests')
-rw-r--r-- | tests/zfs-tests/include/blkdev.shlib | 13 | ||||
-rw-r--r-- | tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am | 1 | ||||
-rwxr-xr-x | tests/zfs-tests/tests/functional/cli_root/zdb/zdb_label_checksum.ksh | 78 |
3 files changed, 92 insertions, 0 deletions
diff --git a/tests/zfs-tests/include/blkdev.shlib b/tests/zfs-tests/include/blkdev.shlib index bf7095290..18fc6b352 100644 --- a/tests/zfs-tests/include/blkdev.shlib +++ b/tests/zfs-tests/include/blkdev.shlib @@ -652,3 +652,16 @@ function corrupt_blocks_at_level # input_file corrupt_level # This is necessary for pools made of loop devices. sync } + +function corrupt_label_checksum # label_number vdev_path +{ + typeset label_size=$((256*1024)) + typeset vdev_size=$(stat_size ${2}) + typeset -a offsets=("$((128*1024 - 32))" \ + "$(($label_size + (128*1024 - 32)))" \ + "$(($vdev_size - $label_size - (128*1024 + 32)))" \ + "$(($vdev_size - (128*1024 + 32)))") + + dd if=/dev/urandom of=${2} seek=${offsets[$1]} bs=1 count=32 \ + conv=notrunc +} diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am index d84a3dfc7..c1d4bf5a4 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am @@ -14,6 +14,7 @@ dist_pkgdata_SCRIPTS = \ zdb_object_range_neg.ksh \ zdb_object_range_pos.ksh \ zdb_display_block.ksh \ + zdb_label_checksum.ksh \ zdb_objset_id.ksh \ zdb_recover.ksh \ zdb_recover_2.ksh diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_label_checksum.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_label_checksum.ksh new file mode 100755 index 000000000..6cc156041 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_label_checksum.ksh @@ -0,0 +1,78 @@ +#!/bin/ksh + +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2021 by vStack. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/include/blkdev.shlib + +# +# Description: +# zdb -l will report corrupted labels checksums +# +# Strategy: +# 1. Create pool with some number of vdevs and export it +# 2. Corrupt label 0 and label 1, check that corrupted labels are reported +# 3. Check that pool still be imported correctly +# 4. Corrupt all labels, check that all corrupted labels are reported +# 5. Check that pool cannot be imported +# + +log_assert "Verify zdb -l will report corrupted labels checksums" +log_onexit cleanup + +VIRTUAL_DISK=$TEST_BASE_DIR/disk + +function cleanup +{ + poolexists $TESTPOOL && log_must destroy_pool $TESTPOOL + [[ -f $VIRTUAL_DISK ]] && log_must rm $VIRTUAL_DISK +} + +verify_runnable "global" + +log_must truncate -s $(($MINVDEVSIZE * 8)) $VIRTUAL_DISK + +log_must zpool create $TESTPOOL $VIRTUAL_DISK +log_must zpool export $TESTPOOL + +corrupt_label_checksum 0 $VIRTUAL_DISK +corrupt_label_checksum 1 $VIRTUAL_DISK + +msg_count=$(zdb -l $VIRTUAL_DISK | grep -c '(Bad label cksum)') +[ $msg_count -ne 1 ] && \ + log_fail "zdb -l produces an incorrect number of corrupted labels." + +msg_count=$(zdb -lll $VIRTUAL_DISK | grep -c '(Bad label cksum)') +[ $msg_count -ne 2 ] && \ + log_fail "zdb -l produces an incorrect number of corrupted labels." + +log_must zpool import $TESTPOOL -d $TEST_BASE_DIR +log_must zpool export $TESTPOOL + +corrupt_label_checksum 0 $VIRTUAL_DISK +corrupt_label_checksum 1 $VIRTUAL_DISK +corrupt_label_checksum 2 $VIRTUAL_DISK +corrupt_label_checksum 3 $VIRTUAL_DISK + +msg_count=$(zdb -lll $VIRTUAL_DISK | grep -c '(Bad label cksum)') +[ $msg_count -ne 4 ] && \ + log_fail "zdb -l produces an incorrect number of corrupted labels." + +log_mustnot zpool import $TESTPOOL -d $TEST_BASE_DIR + +cleanup + +log_pass "zdb -l bad cksum report is correct." |