]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_reopen/zpool_reopen.shlib
Defer new resilvers until the current one ends
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_reopen / zpool_reopen.shlib
1 #
2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
5 # 1.0 of the CDDL.
6 #
7 # A full copy of the text of the CDDL should have accompanied this
8 # source.  A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
10 #
11 #
12 # Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
13 #
14
15 . $STF_SUITE/tests/functional/cli_root/zpool_reopen/zpool_reopen.cfg
16
17 #
18 # Clear labels on the given disks
19 #
20 function clear_labels #disks
21 {
22         for disk in $@; do
23                 if ( is_loop_device $disk ) || ( is_mpath_device $disk ); then
24                         zpool labelclear -f /dev/$disk
25                 else
26                         zpool labelclear -f /dev/${disk}1
27                 fi
28         done
29 }
30
31 #
32 # Set the REMOVED_DISK and REMOVED_DISK_ID constants for device
33 # used for re-plugging. When the disk is loop device use the
34 # scsi_debug emulated drive. Otherwise use the real drive.
35 #
36 function set_removed_disk
37 {
38         if is_loop_device $DISK1; then
39                 export REMOVED_DISK=$(get_debug_device)
40                 export REMOVED_DISK_ID=$(get_persistent_disk_name $REMOVED_DISK)
41         elif ( is_real_device $DISK1 ) || ( is_mpath_device $DISK1 ); then
42                 export REMOVED_DISK="$DISK1"
43                 export REMOVED_DISK_ID=${devs_id[0]}
44         else
45                 log_fail "No drives that supports removal"
46         fi
47 }
48
49 #
50 # Generate random file of the given size in MiB
51 #
52 function generate_random_file #path size_mb
53 {
54         typeset path=$1
55         typeset -i size_mb=$2
56         file_write -o create -f $path -b 1048576 -s0 -c $size_mb -d R
57 }
58
59 #
60 # Wait until specific event or timeout occur.
61 #
62 # The passed function is executed with pool name as argument
63 # with an interval of 1 second until it succeeds or until the
64 # timeout occurs.
65 # It returns 1 on timeout or 0 otherwise.
66 #
67 function wait_for_action #pool timeout function
68 {
69         typeset pool=$1
70         typeset -i timeout=$2
71         typeset func=$3
72
73         while [ $timeout -gt 0 ]; do
74                 (( --timeout ))
75                 if ( $func $pool ); then
76                         return 0
77                 fi
78                 sleep 1
79         done
80
81         return 1
82 }
83
84 #
85 # Helpers for wait_for_action function:
86 # wait_for_resilver_start - wait until resilver is started
87 # wait_for_resilver_end - wait until resilver is finished
88 # wait_for_scrub_end - wait until scrub is finished
89 #
90 function wait_for_resilver_start #pool timeout
91 {
92         wait_for_action $1 $2 is_pool_resilvering
93         return $?
94 }
95
96 function wait_for_resilver_end #pool timeout
97 {
98         wait_for_action $1 $2 is_pool_resilvered
99         return $?
100 }
101
102 function wait_for_scrub_end #pool timeout
103 {
104         wait_for_action $1 $2 is_pool_scrubbed
105         return $?
106 }
107
108 #
109 # Check if scan action has been restarted on the given pool
110 #
111
112 function is_scan_restarted #pool
113 {
114         typeset pool=$1
115         zpool history -i $pool | grep -q "scan aborted, restarting"
116         return $?
117 }
118
119 function is_deferred_scan_started #pool
120 {
121         typeset pool=$1
122         zpool history -i $pool | grep -q "starting deferred resilver"
123         return $?
124 }