1#!/bin/ksh -p
2
3#
4# CDDL HEADER START
5#
6# This file and its contents are supplied under the terms of the
7# Common Development and Distribution License ("CDDL"), version 1.0.
8# You may only use this file in accordance with the terms of version
9# 1.0 of the CDDL.
10#
11# A full copy of the text of the CDDL should have accompanied this
12# source.  A copy of the CDDL is also available via the Internet at
13# http://www.illumos.org/license/CDDL.
14#
15# CDDL HEADER END
16#
17
18#
19# Copyright (c) 2024 by Lawrence Livermore National Security, LLC.
20#
21
22. $STF_SUITE/include/libtest.shlib
23
24#
25# DESCRIPTION:
26# Verify 'zpool status -e' only shows unhealthy devices.
27#
28# STRATEGY:
29# 1. Create zpool
30# 2. Force DEGRADE, FAULT, or inject slow IOs for vdevs
31# 3. Verify vdevs are reported correctly with -e and -s
32# 4. Verify parents are reported as DEGRADED
33# 5. Verify healthy children are not reported
34#
35
36function cleanup
37{
38	log_must set_tunable64 ZIO_SLOW_IO_MS $OLD_SLOW_IO
39	zinject -c all
40	poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
41	log_must rm -f $all_vdevs
42}
43
44log_assert "Verify 'zpool status -e'"
45
46log_onexit cleanup
47
48all_vdevs=$(echo $TESTDIR/vdev{1..6})
49log_must mkdir -p $TESTDIR
50log_must truncate -s $MINVDEVSIZE $all_vdevs
51
52OLD_SLOW_IO=$(get_tunable ZIO_SLOW_IO_MS)
53
54for raid_type in "draid2:3d:6c:1s" "raidz2"; do
55
56	log_must zpool create -f $TESTPOOL2 $raid_type $all_vdevs
57
58	# Check DEGRADED vdevs are shown.
59	log_must check_vdev_state $TESTPOOL2 $TESTDIR/vdev4 "ONLINE"
60	log_must zinject -d $TESTDIR/vdev4 -A degrade $TESTPOOL2
61	log_must eval "zpool status -e $TESTPOOL2 | grep $TESTDIR/vdev4 | grep DEGRADED"
62
63	# Check FAULTED vdevs are shown.
64	log_must check_vdev_state $TESTPOOL2 $TESTDIR/vdev5 "ONLINE"
65	log_must zinject -d $TESTDIR/vdev5 -A fault $TESTPOOL2
66	log_must eval "zpool status -e $TESTPOOL2 | grep $TESTDIR/vdev5 | grep FAULTED"
67
68	# Check no ONLINE vdevs are shown
69	log_mustnot eval "zpool status -e $TESTPOOL2 | grep ONLINE"
70
71	# Check no ONLINE slow vdevs are show.  Then mark IOs greater than
72	# 10ms slow, delay IOs 20ms to vdev6, check slow IOs.
73	log_must check_vdev_state $TESTPOOL2 $TESTDIR/vdev6 "ONLINE"
74	log_mustnot eval "zpool status -es $TESTPOOL2 | grep ONLINE"
75
76	log_must set_tunable64 ZIO_SLOW_IO_MS 10
77	log_must zinject -d $TESTDIR/vdev6 -D20:100 $TESTPOOL2
78	log_must mkfile 1048576 /$TESTPOOL2/testfile
79	sync_pool $TESTPOOL2
80	log_must set_tunable64 ZIO_SLOW_IO_MS $OLD_SLOW_IO
81
82	# Check vdev6 slow IOs are only shown when requested with -s.
83	log_mustnot eval "zpool status -e $TESTPOOL2 | grep $TESTDIR/vdev6 | grep ONLINE"
84	log_must eval "zpool status -es $TESTPOOL2 | grep $TESTDIR/vdev6 | grep ONLINE"
85
86	# Pool level and top-vdev level status must be DEGRADED.
87	log_must eval "zpool status -e $TESTPOOL2 | grep $TESTPOOL2 | grep DEGRADED"
88	log_must eval "zpool status -e $TESTPOOL2 | grep $raid_type | grep DEGRADED"
89
90	# Check that healthy vdevs[1-3] aren't shown with -e.
91	log_must check_vdev_state $TESTPOOL2 $TESTDIR/vdev1 "ONLINE"
92	log_must check_vdev_state $TESTPOOL2 $TESTDIR/vdev2 "ONLINE"
93	log_must check_vdev_state $TESTPOOL2 $TESTDIR/vdev3 "ONLINE"
94	log_mustnot eval "zpool status -es $TESTPOOL2 | grep $TESTDIR/vdev1 | grep ONLINE"
95	log_mustnot eval "zpool status -es $TESTPOOL2 | grep $TESTDIR/vdev2 | grep ONLINE"
96	log_mustnot eval "zpool status -es $TESTPOOL2 | grep $TESTDIR/vdev3 | grep ONLINE"
97
98	log_must zinject -c all
99	log_must zpool status -es $TESTPOOL2
100
101	zpool destroy $TESTPOOL2
102done
103
104log_pass "Verify zpool status -e shows only unhealthy vdevs"
105