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 configurations
23#
24# Strategy:
25# 1. Create a pool with two vdevs
26# 2. Copy label 1 from the first vdev to the second vdev
27# 3. Collect zdb -l output for both vdevs
28# 4. Verify that the correct number of configs is dumped for each
29#
30
31log_assert "Verify zdb does not produce redundant dumps of configurations"
32log_onexit cleanup
33
34function cleanup
35{
36	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
37	if is_freebsd ; then
38		log_must sysctl kern.geom.debugflags=$saved_debugflags
39	fi
40}
41
42if is_freebsd ; then
43	# FreeBSD won't allow writing to an in-use device without this set
44	saved_debugflags=$(sysctl -n kern.geom.debugflags)
45	log_must sysctl kern.geom.debugflags=16
46fi
47
48verify_runnable "global"
49verify_disk_count "$DISKS" 2
50
51config_count=(1 2)
52set -A DISK $DISKS
53
54default_mirror_setup_noexit $DISKS
55
56DEVS=$(get_pool_devices ${TESTPOOL} ${DEV_RDSKDIR})
57log_note "$DEVS"
58[[ -n $DEVS ]] && set -A DISK $DEVS
59
60log_must dd if=/dev/${DISK[0]} of=/dev/${DISK[1]} bs=1K count=256 conv=notrunc
61
62for x in 0 1 ; do
63	config_count=$(zdb -l $DEV_RDSKDIR/${DISK[$x]} | grep -c features_for_read) ||
64		log_fail "failed to get config_count from DISK[$x]"
65	log_note "vdev $x: message_count $config_count"
66	[ $config_count -ne ${config_count[$x]} ] && \
67		log_fail "zdb produces an incorrect number of configuration dumps."
68done
69
70cleanup
71
72log_pass "zdb produces unique dumps of configurations."
73