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 scrub is running.
24# Checks if re-plugged device is NOT resilvered.
25#
26# STRATEGY:
27# 1. Create a pool
28# 2. Remove a disk.
29# 3. Write test file to pool.
30# 4. Execute scrub.
31# 5. "Plug back" disk.
32# 6. Reopen a pool with an -n flag.
33# 7. Check if resilver was deferred.
34# 8. Check if trying to put device to offline fails because of no valid
35#    replicas.
36#
37# NOTES:
38#	A 125ms delay is added to make sure that the scrub is running while
39#	the reopen is invoked.
40#
41
42verify_runnable "global"
43
44function cleanup
45{
46	log_must zinject -c all
47	# bring back removed disk online for further tests
48	insert_disk $REMOVED_DISK $scsi_host
49	poolexists $TESTPOOL && destroy_pool $TESTPOOL
50	# Since the disk was offline during destroy, remove the label
51	zpool labelclear $DISK2 -f
52}
53
54log_assert "Testing zpool reopen with pool name as argument"
55log_onexit cleanup
56
57set_removed_disk
58scsi_host=$(get_scsi_host $REMOVED_DISK)
59
60# 1. Create a pool
61default_mirror_setup_noexit $REMOVED_DISK_ID $DISK2
62# 2. Remove a disk.
63remove_disk $REMOVED_DISK
64log_must zpool reopen -n $TESTPOOL
65log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "unavail"
66# 3. Write test file to pool.
67log_must generate_random_file /$TESTPOOL/data $LARGE_FILE_SIZE
68sync_pool $TESTPOOL
69# 4. Execute scrub.
70# add delay to I/O requests for remaining disk in pool
71log_must zinject -d $DISK2 -D125:1 $TESTPOOL
72log_must zpool scrub $TESTPOOL
73# 5. "Plug back" disk.
74insert_disk $REMOVED_DISK $scsi_host
75# 6. Reopen a pool with an -n flag.
76log_must zpool reopen -n $TESTPOOL
77log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "online"
78# remove delay from disk
79log_must zinject -c all
80# 7. Check if scrub scan is NOT replaced by resilver.
81log_must wait_for_scrub_end $TESTPOOL $MAXTIMEOUT
82log_must is_deferred_scan_started $TESTPOOL
83
84# 8. Check if trying to put device to offline fails because of no valid
85#    replicas.
86log_must wait_for_resilver_end $TESTPOOL $MAXTIMEOUT
87log_must zpool offline $TESTPOOL $DISK2
88
89# clean up
90log_must zpool destroy $TESTPOOL
91
92log_pass "Zpool reopen test successful"
93