]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_reopen/zpool_reopen_004_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_reopen / zpool_reopen_004_pos.ksh
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
41 verify_runnable "global"
42
43 function 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
51 log_assert "Testing zpool reopen with pool name as argument"
52 log_onexit cleanup
53
54 set_removed_disk
55 scsi_host=$(get_scsi_host $REMOVED_DISK)
56
57 # 1. Create a pool
58 default_mirror_setup_noexit $REMOVED_DISK_ID $DISK2
59 # 2. Remove a disk.
60 remove_disk $REMOVED_DISK
61 log_must zpool reopen -n $TESTPOOL
62 log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "unavail"
63 # 3. Write test file to pool.
64 log_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
67 log_must zinject -d $DISK2 -D125:1 $TESTPOOL
68 log_must zpool scrub $TESTPOOL
69 # 5. "Plug back" disk.
70 insert_disk $REMOVED_DISK $scsi_host
71 # 6. Reopen a pool with an -n flag.
72 log_must zpool reopen -n $TESTPOOL
73 log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "online"
74 # remove delay from disk
75 log_must zinject -c all
76 # 7. Check if scrub scan is NOT replaced by resilver.
77 log_must wait_for_scrub_end $TESTPOOL $MAXTIMEOUT
78 log_must is_deferred_scan_started $TESTPOOL
79
80 # 8. Check if trying to put device to offline fails because of no valid
81 #    replicas.
82 log_must wait_for_resilver_end $TESTPOOL $MAXTIMEOUT
83 log_must zpool offline $TESTPOOL $DISK2
84
85 # clean up
86 log_must zpool destroy $TESTPOOL
87
88 log_pass "Zpool reopen test successful"