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 http://www.opensolaris.org/os/licensing.
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#
25# Copyright (c) 2023 Hewlett Packard Enterprise Development LP.
26#
27
28. $STF_SUITE/include/libtest.shlib
29. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
30
31#
32# DESCRIPTION:
33#	Verify 'zpool clear' doesn't cause concurrent resilvers
34#
35# STRATEGY:
36#	1. Create N(10) virtual disk files.
37#	2. Create draid pool based on the virtual disk files.
38#	3. Fill the filesystem with directories and files.
39#	4. Force-fault 2 vdevs and verify distributed spare is kicked in.
40#	5. Free the distributed spare by replacing the faulty drive.
41#	6. Run zpool clear and verify that it does not initiate 2 resilvers
42#	   concurrently while distributed spare gets kicked in.
43#
44
45verify_runnable "global"
46
47typeset -ir devs=10
48typeset -ir nparity=1
49typeset -ir ndata=8
50typeset -ir dspare=1
51
52function cleanup
53{
54	poolexists "$TESTPOOL" && destroy_pool "$TESTPOOL"
55
56	for i in {0..$devs}; do
57		log_must rm -f "$BASEDIR/vdev$i"
58	done
59
60	for dir in $BASEDIR; do
61		if [[ -d $dir ]]; then
62			log_must rm -rf $dir
63		fi
64	done
65
66	zed_stop
67	zed_cleanup
68}
69
70log_assert "Verify zpool clear on draid pool doesn't cause concurrent resilvers"
71log_onexit cleanup
72
73setup_test_env $TESTPOOL draid${nparity}:${ndata}d:${dspare}s $devs
74
75# ZED needed for sequential resilver
76zed_setup
77log_must zed_start
78
79log_must zpool offline -f $TESTPOOL $BASEDIR/vdev5
80log_must wait_vdev_state  $TESTPOOL draid1-0-0 "ONLINE" 60
81log_must zpool wait -t resilver $TESTPOOL
82log_must zpool offline -f $TESTPOOL $BASEDIR/vdev6
83
84log_must zpool labelclear -f $BASEDIR/vdev5
85log_must zpool labelclear -f $BASEDIR/vdev6
86
87log_must zpool replace -w $TESTPOOL $BASEDIR/vdev5
88sync_pool $TESTPOOL
89
90log_must zpool events -c
91log_must zpool clear $TESTPOOL
92log_must wait_vdev_state  $TESTPOOL draid1-0-0 "ONLINE" 60
93log_must zpool wait -t resilver $TESTPOOL
94log_must zpool wait -t scrub $TESTPOOL
95
96nof_resilver=$(zpool events | grep -c resilver_start)
97if [ $nof_resilver = 1 ] ; then
98	log_must verify_pool $TESTPOOL
99	log_pass "zpool clear on draid pool doesn't cause concurrent resilvers"
100else
101	log_fail "FAIL: sequential and healing resilver initiated concurrently"
102fi
103