Skip to content

Commit ffe93ae

Browse files
buzzingwiresbehlendorf
authored andcommitted
Add typesets to zhack label repair test scripts
As a quality assurance measure, `typeset` is added to local variable declarations to actually enforce their intended scope. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: buzzingwires <[email protected]> Closes #17732
1 parent 1d2d812 commit ffe93ae

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

tests/zfs-tests/tests/functional/cli_root/zhack/library.kshlib

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ VIRTUAL_MIRROR_DEVICE=
100100

101101
function cleanup_lo
102102
{
103-
L_DEVICE="$1"
103+
typeset L_DEVICE="$1"
104104

105105
if [[ -e $L_DEVICE ]]; then
106106
if is_linux; then
@@ -136,9 +136,9 @@ function get_devsize
136136

137137
function pick_logop
138138
{
139-
L_SHOULD_SUCCEED="$1"
139+
typeset L_SHOULD_SUCCEED="$1"
140140

141-
l_logop="log_mustnot"
141+
typeset l_logop="log_mustnot"
142142
if [ "$L_SHOULD_SUCCEED" == true ]; then
143143
l_logop="log_must"
144144
fi
@@ -148,7 +148,9 @@ function pick_logop
148148

149149
function check_dataset
150150
{
151-
L_SHOULD_SUCCEED="$1"
151+
typeset L_SHOULD_SUCCEED="$1"
152+
153+
typeset L_LOGOP=
152154
L_LOGOP="$(pick_logop "$L_SHOULD_SUCCEED")"
153155

154156
"$L_LOGOP" mounted "$TESTPOOL"/"$TESTFS"
@@ -175,7 +177,8 @@ function setup_dataset
175177

176178
function force_transactions
177179
{
178-
L_TIMES="$1"
180+
typeset L_TIMES="$1"
181+
typeset i=
179182
for ((i=0; i < L_TIMES; i++))
180183
do
181184
touch "$TESTDIR"/"test" || return $?
@@ -186,7 +189,7 @@ function force_transactions
186189

187190
function get_practical_size
188191
{
189-
L_SIZE="$1"
192+
typeset L_SIZE="$1"
190193

191194
if [ "$((L_SIZE % LABEL_SIZE))" -ne 0 ]; then
192195
echo "$(((L_SIZE / LABEL_SIZE) * LABEL_SIZE))"
@@ -197,10 +200,11 @@ function get_practical_size
197200

198201
function corrupt_sized_label_checksum
199202
{
200-
L_SIZE="$1"
201-
L_LABEL="$2"
202-
L_DEVICE="$3"
203+
typeset L_SIZE="$1"
204+
typeset L_LABEL="$2"
205+
typeset L_DEVICE="$3"
203206

207+
typeset L_PRACTICAL_SIZE=
204208
L_PRACTICAL_SIZE="$(get_practical_size "$L_SIZE")"
205209

206210
typeset -a L_OFFSETS=("$LABEL_CKSUM_START" \
@@ -215,8 +219,8 @@ function corrupt_sized_label_checksum
215219

216220
function corrupt_labels
217221
{
218-
L_SIZE="$1"
219-
L_DISK="$2"
222+
typeset L_SIZE="$1"
223+
typeset L_DISK="$2"
220224

221225
corrupt_sized_label_checksum "$L_SIZE" 0 "$L_DISK"
222226
corrupt_sized_label_checksum "$L_SIZE" 1 "$L_DISK"
@@ -226,11 +230,14 @@ function corrupt_labels
226230

227231
function try_import_and_repair
228232
{
229-
L_REPAIR_SHOULD_SUCCEED="$1"
230-
L_IMPORT_SHOULD_SUCCEED="$2"
231-
L_OP="$3"
232-
L_POOLDISK="$4"
233+
typeset L_REPAIR_SHOULD_SUCCEED="$1"
234+
typeset L_IMPORT_SHOULD_SUCCEED="$2"
235+
typeset L_OP="$3"
236+
typeset L_POOLDISK="$4"
237+
238+
typeset L_REPAIR_LOGOP=
233239
L_REPAIR_LOGOP="$(pick_logop "$L_REPAIR_SHOULD_SUCCEED")"
240+
typeset L_IMPORT_LOGOP=
234241
L_IMPORT_LOGOP="$(pick_logop "$L_IMPORT_SHOULD_SUCCEED")"
235242

236243
log_mustnot zpool import "$TESTPOOL" -d "$L_POOLDISK"
@@ -244,10 +251,10 @@ function try_import_and_repair
244251

245252
function prepare_vdev
246253
{
247-
L_SIZE="$1"
248-
L_BACKFILE="$2"
254+
typeset L_SIZE="$1"
255+
typeset L_BACKFILE="$2"
249256

250-
l_devname=
257+
typeset l_devname=
251258
if truncate -s "$L_SIZE" "$L_BACKFILE"; then
252259
if is_linux; then
253260
l_devname="$(losetup -f "$L_BACKFILE" --show)"
@@ -262,7 +269,7 @@ function prepare_vdev
262269

263270
function run_test_one
264271
{
265-
L_SIZE="$1"
272+
typeset L_SIZE="$1"
266273

267274
VIRTUAL_DEVICE="$(prepare_vdev "$L_SIZE" "$VIRTUAL_DISK")"
268275
log_must test -e "$VIRTUAL_DEVICE"
@@ -289,7 +296,7 @@ function run_test_one
289296

290297
function make_mirrored_pool
291298
{
292-
L_SIZE="$1"
299+
typeset L_SIZE="$1"
293300

294301
VIRTUAL_DEVICE="$(prepare_vdev "$L_SIZE" "$VIRTUAL_DISK")"
295302
log_must test -e "$VIRTUAL_DEVICE"
@@ -313,7 +320,7 @@ function export_and_cleanup_vdisk
313320

314321
function run_test_two
315322
{
316-
L_SIZE="$1"
323+
typeset L_SIZE="$1"
317324

318325
make_mirrored_pool "$L_SIZE"
319326

@@ -334,7 +341,7 @@ function run_test_two
334341

335342
function run_test_three
336343
{
337-
L_SIZE="$1"
344+
typeset L_SIZE="$1"
338345

339346
make_mirrored_pool "$L_SIZE"
340347

@@ -359,7 +366,7 @@ function run_test_three
359366

360367
function run_test_four
361368
{
362-
L_SIZE="$1"
369+
typeset L_SIZE="$1"
363370

364371
make_mirrored_pool "$L_SIZE"
365372

0 commit comments

Comments
 (0)