3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
14 # Copyright (c) 2018 by Delphix. All rights reserved.
17 typeset -a disk_array=($(find_disks $DISKS))
19 typeset -r DISK1=${disk_array[0]}
20 typeset -r DISK2=${disk_array[1]}
21 typeset -r DISK3=${disk_array[2]}
24 # When the condition it is waiting for becomes true, 'zpool wait' should return
25 # promptly. We want to enforce this, but any check will be racey because it will
26 # take some small but indeterminate amount of time for the waiting thread to be
27 # woken up and for the process to exit.
29 # To deal with this, we provide a grace period after the condition becomes true
30 # during which 'zpool wait' can exit. If it hasn't exited by the time the grace
31 # period expires we assume something is wrong and fail the test. While there is
32 # no value that can really be correct, the idea is we choose something large
33 # enough that it shouldn't cause issues in practice.
35 typeset -r WAIT_EXIT_GRACE=2.0
37 function add_io_delay # pool
39 for disk in $(get_disklist $1); do
40 log_must zinject -d $disk -D20:1 $1
44 function remove_io_delay
46 log_must zinject -c all
49 function proc_exists # pid
54 function proc_must_exist # pid
56 proc_exists $1 || log_fail "zpool process exited too soon"
59 function proc_must_not_exist # pid
61 proc_exists $1 && log_fail "zpool process took too long to exit"
69 function kill_if_running
72 [[ $pid ]] && proc_exists $pid && log_must kill -s TERM $pid
75 # Log a command and then start it running in the background
78 log_note "$(get_time) Starting cmd in background '$@'"
82 # Check that a background process has completed and exited with a status of 0
83 function bkgrnd_proc_succeeded
87 log_must sleep $WAIT_EXIT_GRACE
89 proc_must_not_exist $pid
90 wait $pid || log_fail "zpool process exited with status $?"
91 log_note "$(get_time) wait completed successfully"
95 # Check that 'zpool wait' returns reasonably promptly after the condition
96 # waited for becomes true, and not before.
98 function check_while_waiting
100 # The pid of the waiting process
101 typeset wait_proc_pid=$1
102 # A check that should be true while the activity is in progress
103 typeset activity_check=$2
105 log_note "$(get_time) waiting for process $wait_proc_pid using" \
106 "activity check '$activity_check'"
107 while proc_exists $wait_proc_pid && eval "$activity_check"; do
112 # If the activity being waited on is still in progress, then zpool wait
115 log_mustnot eval "$activity_check"
117 bkgrnd_proc_succeeded $wait_proc_pid
120 # Whether any vdev in the given pool is initializing
121 function is_vdev_initializing # pool
123 zpool status -i "$1" | grep 'initialized, started' >/dev/null