xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/fault/auto_online_001_pos.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or https://opensource.org/licenses/CDDL-1.0.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright (c) 2016, 2017 by Intel Corporation. All rights reserved.
25# Copyright (c) 2019 by Delphix. All rights reserved.
26#
27
28. $STF_SUITE/include/libtest.shlib
29. $STF_SUITE/tests/functional/fault/fault.cfg
30
31#
32# DESCRIPTION:
33# Testing Fault Management Agent ZED Logic - Automated Auto-Online Test.
34#
35# STRATEGY:
36# 1. Create a pool
37# 2. Export a pool
38# 3. Offline disk
39# 4. Import pool with missing disk
40# 5. Online disk
41# 6. ZED polls for an event change for online disk to be automatically
42#    added back to the pool.
43#
44# Creates a raidz1 zpool using persistent disk path names
45# (ie not /dev/sdc).
46#
47# If loop devices are used, then a scsi_debug device is added to the pool.
48# otherwise just an sd device is used as the auto-online device.
49# Auto-online matches by devid.
50#
51verify_runnable "both"
52
53if ! is_physical_device $DISKS; then
54	log_unsupported "Unsupported disks for this test."
55fi
56
57function cleanup
58{
59	typeset disk
60
61	# Replace any disk that may have been removed at failure time.
62	for disk in $DISK1 $DISK2 $DISK3; do
63		# Skip loop devices and devices that currently exist.
64		is_loop_device $disk && continue
65		is_real_device $disk && continue
66		insert_disk $disk $(get_scsi_host $disk)
67	done
68	destroy_pool $TESTPOOL
69	unload_scsi_debug
70}
71
72log_assert "Testing automated auto-online FMA test"
73
74log_onexit cleanup
75
76# If using the default loop devices, need a scsi_debug device for auto-online
77if is_loop_device $DISK1; then
78	load_scsi_debug $SDSIZE $SDHOSTS $SDTGTS $SDLUNS '512b'
79	SDDEVICE=$(get_debug_device)
80	SDDEVICE_ID=$(get_persistent_disk_name $SDDEVICE)
81	autoonline_disks="$SDDEVICE"
82else
83	autoonline_disks="$DISK1 $DISK2 $DISK3"
84fi
85
86# Clear disk labels
87for i in {0..2}
88do
89	zpool labelclear -f /dev/disk/by-id/"${devs_id[i]}"
90done
91
92if is_loop_device $DISK1; then
93	# create a pool with one scsi_debug device and 3 loop devices
94	log_must zpool create -f $TESTPOOL raidz1 $SDDEVICE_ID $DISK1 \
95	    $DISK2 $DISK3
96elif ( is_real_device $DISK1 || is_mpath_device $DISK1 ); then
97	# else use the persistent names for sd devices
98	log_must zpool create -f $TESTPOOL raidz1 ${devs_id[0]} \
99	    ${devs_id[1]} ${devs_id[2]}
100else
101	log_fail "Disks are not supported for this test"
102fi
103
104# Add some data to the pool
105log_must mkfile $FSIZE /$TESTPOOL/data
106
107for offline_disk in $autoonline_disks
108do
109	log_must zpool export -F $TESTPOOL
110
111	host=$(get_scsi_host $offline_disk)
112
113	# Offline disk
114	remove_disk $offline_disk
115
116	# Reimport pool with drive missing
117	log_must zpool import $TESTPOOL
118	log_must check_state $TESTPOOL "" "degraded"
119
120	# Clear zpool events
121	log_must zpool events -c
122
123	# Online disk
124	insert_disk $offline_disk $host
125
126	log_note "Delay for ZED auto-online"
127	typeset -i timeout=0
128	while true; do
129		if ((timeout == $MAXTIMEOUT)); then
130			log_fail "Timeout occurred"
131		fi
132		((timeout++))
133
134		sleep 1
135		if zpool events $TESTPOOL \
136		    | grep -qF sysevent.fs.zfs.resilver_finish; then
137			log_note "Auto-online of $offline_disk is complete"
138			sleep 1
139			break
140		fi
141	done
142
143	# Validate auto-online was successful
144	log_must check_state $TESTPOOL "" "online"
145	sleep 2
146done
147log_must zpool destroy $TESTPOOL
148
149log_pass "Auto-online test successful"
150