Skip to content

Commit

Permalink
ZTS: Wait for scsi_debug.ko
Browse files Browse the repository at this point in the history
It may take a few moments for scsi_debug devices to be reported by the
lsscsi command.  Wait for up to 30 seconds before reporting this as a
failure to help avoid false positives in the CI.  Additionally, when
inserting a drive poll to ensure it's available.

Signed-off-by: Brian Behlendorf <[email protected]>
  • Loading branch information
behlendorf committed Apr 12, 2022
1 parent e28352c commit dc34a5b
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions tests/zfs-tests/include/blkdev.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,40 @@ function insert_disk #disk scsi_host
typeset disk=$1
typeset scsi_host=$2
on_off_disk $disk "online" $scsi_host
block_device_wait
block_device_wait $disk
}

#
# Wait for the scsi_debug kmod to be ready.
#
function scsi_debug_wait
{
for i in {1..30}; do
if lsscsi | grep -q scsi_debug; then
return
fi

sleep 1
done
log_fail "scsi_debug module install failed"
}

#
# Get scsi_debug device name.
# Returns basename of scsi_debug device (for example "sdb").
#
function get_debug_device
{
for i in {1..30}; do
val=$(lsscsi | awk '/scsi_debug/ {print $6; exit}' | cut -d/ -f3)

# lsscsi can take time to settle
if [ "$val" != "-" ]; then
break
fi
sleep 1
done
echo "$val"
}

#
Expand Down Expand Up @@ -442,10 +475,8 @@ function load_scsi_debug # dev_size_mb add_host num_tgts max_luns blksz
log_must modprobe scsi_debug dev_size_mb=$devsize \
add_host=$hosts num_tgts=$tgts max_luns=$luns \
sector_size=$sector physblk_exp=$blkexp
block_device_wait
if ! lsscsi | grep -q scsi_debug; then
log_fail "scsi_debug module install failed"
fi
scsi_debug_wait
block_device_wait /dev/$(get_debug_device)
fi
fi
}
Expand All @@ -458,24 +489,6 @@ function unload_scsi_debug
log_must_retry "in use" 5 modprobe -r scsi_debug
}

#
# Get scsi_debug device name.
# Returns basename of scsi_debug device (for example "sdb").
#
function get_debug_device
{
for i in {1..10} ; do
val=$(lsscsi | awk '/scsi_debug/ {print $6; exit}' | cut -d/ -f3)

# lsscsi can take time to settle
if [ "$val" != "-" ] ; then
break
fi
sleep 1
done
echo "$val"
}

#
# Get actual devices used by the pool (i.e. linux sdb1 not sdb).
#
Expand Down

0 comments on commit dc34a5b

Please sign in to comment.