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
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.
17 # Copyright (c) 2014, 2017 by Delphix. All rights reserved.
20 export REMOVEDISK=${DISKS%% *}
21 export NOTREMOVEDISK=${DISKS##* }
24 # Waits for the pool to finish a removal.
26 function wait_for_removal # pool
31 log_must zpool wait -t remove $pool
34 # The pool state changes before the TXG finishes syncing; wait for
35 # the removal to be completed on disk.
39 log_must is_pool_removed $pool
44 # Removes the specified disk from its respective pool and
45 # runs the callback while the removal is in progress.
47 # This function is mainly used to test how other operations
48 # interact with device removal. After the callback is done,
49 # the removal is unpaused and we wait for it to finish.
53 # attempt_during_removal $TESTPOOL $DISK dd if=/dev/urandom \
54 # of=/$TESTPOOL/file count=1
56 function attempt_during_removal # pool disk callback [args]
63 log_onexit_push set_tunable32 REMOVAL_SUSPEND_PROGRESS 0
64 set_tunable32 REMOVAL_SUSPEND_PROGRESS 1
66 log_must zpool remove $pool $disk
69 # We want to make sure that the removal started
70 # before issuing the callback.
73 log_must is_pool_removing $pool
75 log_must $callback "$@"
78 # Ensure that we still haven't finished the removal
81 log_must is_pool_removing $pool
83 set_tunable32 REMOVAL_SUSPEND_PROGRESS 0
86 log_must wait_for_removal $pool
87 log_mustnot vdevs_in_pool $pool $disk
91 function indirect_vdev_mapping_size # pool
94 zdb -P $pool | grep 'indirect vdev' | \
95 sed -E 's/.*\(([0-9]+) in memory\).*/\1/g'
98 function random_write # file write_size
101 typeset block_size=$2
102 typeset file_size=$(stat_size $file 2>/dev/null)
103 typeset nblocks=$((file_size / block_size))
105 [[ -w $file ]] || return 1
107 dd if=/dev/urandom of=$file conv=notrunc \
108 bs=$block_size count=1 seek=$((RANDOM % nblocks)) >/dev/null 2>&1
111 function start_random_writer # file
115 log_note "Starting writer for $file"
116 # This will fail when we destroy the pool.
117 while random_write $file $((2**12)); do
120 log_note "Stopping writer for $file"
124 function test_removal_with_operation # callback [args]
127 # To ensure that the removal takes a while, we fragment the pool
128 # by writing random blocks and continue to do during the removal.
130 log_must mkfile 1g $TESTDIR/$TESTFILE0
131 for i in $(seq $((2**10))); do
132 random_write $TESTDIR/$TESTFILE0 $((2**12)) || \
133 log_fail "Could not write to $TESTDIR/$TESTFILE0."
135 start_random_writer $TESTDIR/$TESTFILE0 1g
138 log_must attempt_during_removal $TESTPOOL $REMOVEDISK "$@"
139 log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK
140 log_must zdb -cd $TESTPOOL
145 verify_pool $TESTPOOL
149 # Kill the background job use by the test_removal_with_operation function.
151 function test_removal_with_operation_kill