1e4c795beSTom Caputi#!/bin/ksh -p
2e4c795beSTom Caputi#
3e4c795beSTom Caputi# CDDL HEADER START
4e4c795beSTom Caputi#
5e4c795beSTom Caputi# The contents of this file are subject to the terms of the
6e4c795beSTom Caputi# Common Development and Distribution License (the "License").
7e4c795beSTom Caputi# You may not use this file except in compliance with the License.
8e4c795beSTom Caputi#
9e4c795beSTom Caputi# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10e4c795beSTom Caputi# or http://www.opensolaris.org/os/licensing.
11e4c795beSTom Caputi# See the License for the specific language governing permissions
12e4c795beSTom Caputi# and limitations under the License.
13e4c795beSTom Caputi#
14e4c795beSTom Caputi# When distributing Covered Code, include this CDDL HEADER in each
15e4c795beSTom Caputi# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16e4c795beSTom Caputi# If applicable, add the following below this CDDL HEADER, with the
17e4c795beSTom Caputi# fields enclosed by brackets "[]" replaced with your own identifying
18e4c795beSTom Caputi# information: Portions Copyright [yyyy] [name of copyright owner]
19e4c795beSTom Caputi#
20e4c795beSTom Caputi# CDDL HEADER END
21e4c795beSTom Caputi#
22e4c795beSTom Caputi
23e4c795beSTom Caputi#
24e4c795beSTom Caputi# Copyright (c) 2018 Datto Inc.
25e4c795beSTom Caputi#
26e4c795beSTom Caputi
27e4c795beSTom Caputi. $STF_SUITE/include/libtest.shlib
28e4c795beSTom Caputi. $STF_SUITE/tests/functional/cli_root/zpool_reopen/zpool_reopen.shlib
29e4c795beSTom Caputi. $STF_SUITE/tests/functional/cli_root/zpool_resilver/zpool_resilver.cfg
30e4c795beSTom Caputi
31e4c795beSTom Caputi#
32e4c795beSTom Caputi# DESCRIPTION:
33e4c795beSTom Caputi#	"Verify 'zpool resilver' restarts in-progress resilvers"
34e4c795beSTom Caputi#
35e4c795beSTom Caputi# STRATEGY:
36e4c795beSTom Caputi#	1. Write some data and detatch the first drive so it has resilver
37e4c795beSTom Caputi#	   work to do
38e4c795beSTom Caputi#	2. Repeat the process with a second disk
39e4c795beSTom Caputi#	3. Reattach the drives, causing the second drive's resilver to be
40e4c795beSTom Caputi#	   deferred
41e4c795beSTom Caputi#	4. Manually restart the resilver with all drives
42e4c795beSTom Caputi#
43e4c795beSTom Caputi
44e4c795beSTom Caputiverify_runnable "global"
45e4c795beSTom Caputi
46e4c795beSTom Caputifunction cleanup
47e4c795beSTom Caputi{
48e4c795beSTom Caputi	log_must set_tunable32 zfs_scan_suspend_progress 0
49e4c795beSTom Caputi	log_must rm -f $mntpnt/biggerfile1
50e4c795beSTom Caputi	log_must rm -f $mntpnt/biggerfile2
51e4c795beSTom Caputi}
52e4c795beSTom Caputi
53e4c795beSTom Caputilog_onexit cleanup
54e4c795beSTom Caputi
55e4c795beSTom Caputilog_assert "Verify 'zpool resilver' restarts in-progress resilvers"
56e4c795beSTom Caputi
57e4c795beSTom Caputimntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
58e4c795beSTom Caputi
59e4c795beSTom Caputi# 1. Write some data and detatch the first drive so it has resilver work to do
60e4c795beSTom Caputilog_must file_write -b 524288 -c 1024 -o create -d 0 -f $mntpnt/biggerfile1
61*09fbbb7dSAllan Judesync_all_pools
62e4c795beSTom Caputilog_must zpool detach $TESTPOOL $DISK2
63e4c795beSTom Caputi
64e4c795beSTom Caputi# 2. Repeat the process with a second disk
65e4c795beSTom Caputilog_must file_write -b 524288 -c 1024 -o create -d 0 -f $mntpnt/biggerfile2
66*09fbbb7dSAllan Judesync_all_pools
67e4c795beSTom Caputilog_must zpool detach $TESTPOOL $DISK3
68e4c795beSTom Caputi
69e4c795beSTom Caputi# 3. Reattach the drives, causing the second drive's resilver to be deferred
70e4c795beSTom Caputilog_must set_tunable32 zfs_scan_suspend_progress 1
71e4c795beSTom Caputi
72e4c795beSTom Caputilog_must zpool attach $TESTPOOL $DISK1 $DISK2
73e4c795beSTom Caputilog_must is_pool_resilvering $TESTPOOL true
74e4c795beSTom Caputi
75e4c795beSTom Caputilog_must zpool attach $TESTPOOL $DISK1 $DISK3
76e4c795beSTom Caputilog_must is_pool_resilvering $TESTPOOL true
77e4c795beSTom Caputi
78e4c795beSTom Caputi# 4. Manually restart the resilver with all drives
79e4c795beSTom Caputilog_must zpool resilver $TESTPOOL
80e4c795beSTom Caputilog_must is_deferred_scan_started $TESTPOOL
81e4c795beSTom Caputilog_must set_tunable32 zfs_scan_suspend_progress 0
82e4c795beSTom Caputilog_must wait_for_resilver_end $TESTPOOL $MAXTIMEOUT
83e4c795beSTom Caputilog_must check_state $TESTPOOL "$DISK2" "online"
84e4c795beSTom Caputilog_must check_state $TESTPOOL "$DISK3" "online"
85e4c795beSTom Caputi
86e4c795beSTom Caputilog_pass "Verified 'zpool resilver' restarts in-progress resilvers"
87