1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14
15#
16# Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
17#
18
19. $STF_SUITE/tests/functional/cli_root/zpool_reopen/zpool_reopen.shlib
20
21#
22# DESCRIPTION:
23# Test zpool reopen -n while resilver is running.
24# Checks if the resilver is restarted.
25#
26# STRATEGY:
27# 1. Create a pool
28# 2. Remove a disk.
29# 3. Write test file to pool.
30# 4. "Plug back" disk.
31# 5. Reopen a pool and wait until resilvering is started.
32# 6. Reopen a pool again with -n flag.
33# 7. Wait until resilvering is finished and check if it was restarted.
34#
35# NOTES:
36#	A 25ms delay is added to make sure that the resilver is running while
37#	the reopen is invoked.
38#
39
40verify_runnable "global"
41
42function cleanup
43{
44	log_must zinject -c all
45	insert_disk $REMOVED_DISK $scsi_host
46	poolexists $TESTPOOL && destroy_pool $TESTPOOL
47}
48
49log_assert "Testing zpool reopen with pool name as argument"
50log_onexit cleanup
51
52set_removed_disk
53scsi_host=$(get_scsi_host $REMOVED_DISK)
54
55# 1. Create a pool
56default_mirror_setup_noexit $REMOVED_DISK_ID $DISK2
57# 2. Remove a disk.
58remove_disk $REMOVED_DISK
59
60log_must zpool reopen $TESTPOOL
61log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "unavail"
62# 3. Write test file to pool.
63log_must generate_random_file /$TESTPOOL/data $LARGE_FILE_SIZE
64sync_pool $TESTPOOL
65# 4. "Plug back" disk.
66insert_disk $REMOVED_DISK $scsi_host
67
68# 5. Reopen a pool and wait until resilvering is started.
69log_must zpool reopen $TESTPOOL
70log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "online"
71# add delay to I/O requests for the reopened disk
72log_must zinject -d $REMOVED_DISK_ID -D25:1 $TESTPOOL
73# wait until resilver starts
74log_must wait_for_resilver_start $TESTPOOL $MAXTIMEOUT
75
76# 6. Reopen a pool again with -n flag.
77log_must zpool reopen -n $TESTPOOL
78
79# 7. Wait until resilvering is finished and check if it was restarted.
80log_must wait_for_resilver_end $TESTPOOL $MAXTIMEOUT
81# remove delay from disk
82log_must zinject -c all
83log_mustnot is_scan_restarted $TESTPOOL
84
85# clean up
86log_must zpool destroy $TESTPOOL
87
88log_pass "Zpool reopen test successful"
89