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 while scrub is running.
24# Checks if re-plugged device is fully resilvered.
25#
26# STRATEGY:
27# 1. Create a pool
28# 2. Remove a disk.
29# 3. Write a test file to the pool and calculate its checksum.
30# 4. Execute scrub.
31# 5. "Plug back" disk.
32# 6. Reopen a pool.
33# 7. Check if scrub scan is replaced by resilver.
34# 8. Put another device offline and check if the test file checksum is correct.
35#
36# NOTES:
37#	A 250ms delay is added to make sure that the scrub is running while
38#	the reopen kicks the resilver.
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
61
62log_must zpool reopen $TESTPOOL
63log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "unavail"
64
65# 3. Write a test file to the pool and calculate its checksum.
66TESTFILE=/$TESTPOOL/data
67log_must generate_random_file /$TESTPOOL/data $LARGE_FILE_SIZE
68sync_pool $TESTPOOL
69TESTFILE_MD5=$(xxh128digest $TESTFILE)
70
71# 4. Execute scrub.
72# add delay to I/O requests for remaining disk in pool
73log_must zinject -d $DISK2 -D250:1 $TESTPOOL
74log_must zpool scrub $TESTPOOL
75
76# 5. "Plug back" disk.
77insert_disk $REMOVED_DISK $scsi_host
78# 6. Reopen a pool.
79log_must zpool reopen $TESTPOOL
80log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "online"
81# 7. Check if scrub scan is replaced by resilver.
82# the scrub operation has to be running while reopen is executed
83log_must is_pool_scrubbing $TESTPOOL true
84# remove delay from disk
85log_must zinject -c all
86# the scrub will be replaced by resilver, wait until it ends
87log_must wait_for_resilver_end $TESTPOOL $MAXTIMEOUT
88# check if the scrub scan has been interrupted by resilver
89log_must is_scan_restarted $TESTPOOL
90
91# 8. Put another device offline and check if the test file checksum is correct.
92log_must zpool offline $TESTPOOL $DISK2
93CHECK_MD5=$(xxh128digest $TESTFILE)
94[[ $CHECK_MD5 == $TESTFILE_MD5 ]] || \
95    log_fail "Checksums differ ($CHECK_MD5 != $TESTFILE_MD5)"
96log_must zpool online $TESTPOOL $DISK2
97sleep 1
98
99# clean up
100log_must zpool destroy $TESTPOOL
101
102log_pass "Zpool reopen test successful"
103