1#!/bin/ksh -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright (c) 2018 by Lawrence Livermore National Security, LLC.
15# All rights reserved.
16#
17
18. $STF_SUITE/include/libtest.shlib
19. $STF_SUITE/tests/functional/fault/fault.cfg
20
21#
22# DESCRIPTION:
23# Test the scrub after resilver zedlet
24#
25# STRATEGY:
26# 1. Create a mirrored pool
27# 2. Fault a disk
28# 3. Replace the disk, starting a resilver
29# 4. Verify that a scrub happens after the resilver finishes
30#
31
32log_assert "Testing the scrub after resilver zedlet"
33
34# Backup our zed.rc
35zedrc_backup=$(zed_rc_backup)
36
37# Enable ZED_SCRUB_AFTER_RESILVER in zed.rc
38zed_rc_set ZED_SCRUB_AFTER_RESILVER 1
39
40function cleanup
41{
42	# Restore our zed.rc
43	log_must zed_rc_restore $zedrc_backup
44	default_cleanup_noexit
45	log_must zpool labelclear -f $DISK1
46}
47
48log_onexit cleanup
49
50verify_disk_count "$DISKS" 3
51default_mirror_setup_noexit $DISK1 $DISK2
52
53log_must zpool offline -f $TESTPOOL $DISK1
54
55# Write to our degraded pool so we have some data to resilver
56log_must mkfile 16M $TESTDIR/file1
57
58# Replace the failed disks, forcing a resilver
59log_must zpool replace $TESTPOOL $DISK1 $DISK3
60
61# Wait for the resilver to finish, and then the subsequent scrub to finish.
62# Waiting for the scrub has the effect of waiting for both.  Timeout after 10
63# seconds if nothing is happening.
64log_must wait_scrubbed $TESTPOOL
65log_pass "Successfully ran the scrub after resilver zedlet"
66