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