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