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