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 while scrub is running.
23# Checks if re-plugged device is fully resilvered.
24#
25# STRATEGY:
26# 1. Create a pool
27# 2. Remove a disk.
28# 3. Write a test file to the pool and calculate its checksum.
29# 4. Execute scrub.
30# 5. "Plug back" disk.
31# 6. Reopen a pool.
32# 7. Check if scrub scan is replaced by resilver.
33# 8. Put another device offline and check if the test file checksum is correct.
34#
35# NOTES:
36#	A 250ms delay is added to make sure that the scrub is running while
37#	the reopen kicks the resilver.
38#
39
40verify_runnable "global"
41
42function cleanup
43{
44	log_must zinject -c all
45	# bring back removed disk online for further tests
46	insert_disk $REMOVED_DISK $scsi_host
47	poolexists $TESTPOOL && destroy_pool $TESTPOOL
48}
49
50log_assert "Testing zpool reopen with pool name as argument"
51log_onexit cleanup
52
53set_removed_disk
54scsi_host=$(get_scsi_host $REMOVED_DISK)
55
56# 1. Create a pool
57default_mirror_setup_noexit $REMOVED_DISK_ID $DISK2
58# 2. Remove a disk.
59remove_disk $REMOVED_DISK
60
61log_must zpool reopen $TESTPOOL
62log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "unavail"
63
64# 3. Write a test file to the pool and calculate its checksum.
65TESTFILE=/$TESTPOOL/data
66log_must generate_random_file /$TESTPOOL/data $LARGE_FILE_SIZE
67TESTFILE_MD5=$(md5digest $TESTFILE)
68
69# 4. Execute scrub.
70# add delay to I/O requests for remaining disk in pool
71log_must zinject -d $DISK2 -D250:1 $TESTPOOL
72log_must zpool scrub $TESTPOOL
73
74# 5. "Plug back" disk.
75insert_disk $REMOVED_DISK $scsi_host
76# 6. Reopen a pool.
77log_must zpool reopen $TESTPOOL
78log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "online"
79# 7. Check if scrub scan is replaced by resilver.
80# the scrub operation has to be running while reopen is executed
81log_must is_pool_scrubbing $TESTPOOL true
82# remove delay from disk
83log_must zinject -c all
84# the scrub will be replaced by resilver, wait until it ends
85log_must wait_for_resilver_end $TESTPOOL $MAXTIMEOUT
86# check if the scrub scan has been interrupted by resilver
87log_must is_scan_restarted $TESTPOOL
88
89# 8. Put another device offline and check if the test file checksum is correct.
90log_must zpool offline $TESTPOOL $DISK2
91CHECK_MD5=$(md5digest $TESTFILE)
92[[ $CHECK_MD5 == $TESTFILE_MD5 ]] || \
93    log_fail "Checksums differ ($CHECK_MD5 != $TESTFILE_MD5)"
94log_must zpool online $TESTPOOL $DISK2
95sleep 1
96
97# clean up
98log_must zpool destroy $TESTPOOL
99
100log_pass "Zpool reopen test successful"
101