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
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.
12 # Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
15 . $STF_SUITE/tests/functional/cli_root/zpool_reopen/zpool_reopen.cfg
18 # Clear labels on the given disks
20 function clear_labels #disks
23 if ( is_loop_device $disk ) || ( is_mpath_device $disk ); then
24 zpool labelclear -f /dev/$disk
26 zpool labelclear -f /dev/${disk}1
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.
36 function set_removed_disk
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]}
45 log_fail "No drives that supports removal"
50 # Generate random file of the given size in MiB
52 function generate_random_file #path size_mb
56 file_write -o create -f $path -b 1048576 -s0 -c $size_mb -d R
60 # Wait until specific event or timeout occur.
62 # The passed function is executed with pool name as argument
63 # with an interval of 1 second until it succeeds or until the
65 # It returns 1 on timeout or 0 otherwise.
67 function wait_for_action #pool timeout function
73 while [ $timeout -gt 0 ]; do
75 if ( $func $pool ); then
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
90 function wait_for_resilver_start #pool timeout
92 wait_for_action $1 $2 is_pool_resilvering
96 function wait_for_resilver_end #pool timeout
98 wait_for_action $1 $2 is_pool_resilvered
102 function wait_for_scrub_end #pool timeout
104 wait_for_action $1 $2 is_pool_scrubbed
109 # Check if scan action has been restarted on the given pool
112 function is_scan_restarted #pool
115 zpool history -i $pool | grep -q "scan aborted, restarting"
119 function is_deferred_scan_started #pool
122 zpool history -i $pool | grep -q "starting deferred resilver"