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
67sync_pool $TESTPOOL
68TESTFILE_MD5=$(md5digest $TESTFILE)
69
70# 4. Execute scrub.
71# add delay to I/O requests for remaining disk in pool
72log_must zinject -d $DISK2 -D250:1 $TESTPOOL
73log_must zpool scrub $TESTPOOL
74
75# 5. "Plug back" disk.
76insert_disk $REMOVED_DISK $scsi_host
77# 6. Reopen a pool.
78log_must zpool reopen $TESTPOOL
79log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "online"
80# 7. Check if scrub scan is replaced by resilver.
81# the scrub operation has to be running while reopen is executed
82log_must is_pool_scrubbing $TESTPOOL true
83# remove delay from disk
84log_must zinject -c all
85# the scrub will be replaced by resilver, wait until it ends
86log_must wait_for_resilver_end $TESTPOOL $MAXTIMEOUT
87# check if the scrub scan has been interrupted by resilver
88log_must is_scan_restarted $TESTPOOL
89
90# 8. Put another device offline and check if the test file checksum is correct.
91log_must zpool offline $TESTPOOL $DISK2
92CHECK_MD5=$(md5digest $TESTFILE)
93[[ $CHECK_MD5 == $TESTFILE_MD5 ]] || \
94    log_fail "Checksums differ ($CHECK_MD5 != $TESTFILE_MD5)"
95log_must zpool online $TESTPOOL $DISK2
96sleep 1
97
98# clean up
99log_must zpool destroy $TESTPOOL
100
101log_pass "Zpool reopen test successful"
102