ZTS: Add helper for disk device check

Replace `test -b` and equivalents with `is_disk_device`, so that `-c`
is used instead on FreeBSD which has no block cache layer for devices.

Reviewed-by: Richard Elling <Richard.Elling@RichardElling.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
Closes #9795
This commit is contained in:
Ryan Moeller
2020-01-03 12:10:17 -05:00
committed by Brian Behlendorf
parent d7164b27be
commit 665684d721
7 changed files with 46 additions and 24 deletions
@@ -26,7 +26,7 @@ verify_runnable "global"
DISK1=${DISKS%% *}
typeset -i max_discard=0
if [[ -b $DEV_RDSKDIR/$DISK1 ]]; then
if is_disk_device $DEV_RDSKDIR/$DISK1; then
max_discard=$(lsblk -Dbn $DEV_RDSKDIR/$DISK1 | awk '{ print $4; exit }')
fi
@@ -76,23 +76,23 @@ log_must diff <(echo ${contents//$recv_mnt/}) \
log_must zfs redact $sendvol@snap book2 $clonevol@snap
log_must eval "zfs send --redact book2 $sendvol@snap >$stream"
log_must eval "zfs receive $recvvol <$stream"
[[ -b $recv_vol_file ]] && log_fail "Volume device file should not exist."
is_disk_device $recv_vol_file && log_fail "Volume device file should not exist."
log_must set_tunable32 zfs_allow_redacted_dataset_mount 1
log_must zpool export $POOL2
log_must zpool import $POOL2
udevadm settle
# The device file isn't guaranteed to show up right away.
if [[ ! -b $recv_vol_file ]]; then
if ! is_disk_device $recv_vol_file; then
udevadm settle
for t in 10 5 3 2 1; do
log_note "Polling $t seconds for device file."
udevadm settle
sleep $t
[[ -b $recv_vol_file ]] && break
is_disk_device $recv_vol_file && break
done
fi
[[ -b $recv_vol_file ]] || log_fail "Volume device file should exist."
is_disk_device $recv_vol_file || log_fail "Volume device file should exist."
log_must dd if=/dev/urandom of=$send_mnt/dir1/contents1 bs=512 count=2
log_must rm $send_mnt/dir1/dir2/empty
@@ -44,13 +44,13 @@ sleep 10
log_must zpool export $POOL
log_must zpool import $POOL
udevadm settle
if [[ ! -b $send_file ]]; then
if ! is_disk_device $send_file; then
udevadm settle
for t in 10 5 3 2 1; do
log_note "Polling $t seconds for device file."
udevadm settle
sleep $t
[[ -b $send_file ]] && break
is_disk_device $send_file && break
done
fi
log_must dd if=/dev/urandom of=$send_file bs=8k count=64
@@ -66,13 +66,13 @@ sleep 10
log_must zpool export $POOL2
log_must zpool import $POOL2
udevadm settle
if [[ ! -b $recv_file ]]; then
if ! is_disk_device $recv_file; then
udevadm settle
for t in 10 5 3 2 1; do
log_note "Polling $t seconds for device file."
udevadm settle
sleep $t
[[ -b $recv_file ]] && break
is_disk_device $recv_file && break
done
fi
log_must dd if=$send_file of=$tmpdir/send.dd bs=8k count=64
@@ -89,13 +89,13 @@ sleep 10
log_must zpool export $POOL2
log_must zpool import $POOL2
udevadm settle
if [[ ! -b $recv_file ]]; then
if ! is_disk_device $recv_file; then
udevadm settle
for t in 10 5 3 2 1; do
log_note "Polling $t seconds for device file."
udevadm settle
sleep $t
[[ -b $recv_file ]] && break
is_disk_device $recv_file && break
done
fi
log_must dd if=$send_file of=$tmpdir/send.dd bs=8k count=32 skip=32
@@ -30,7 +30,7 @@ else
DISK1=${DISKS%% *}
typeset -i max_discard=0
if [[ -b $DEV_RDSKDIR/$DISK1 ]]; then
if is_disk_device $DEV_RDSKDIR/$DISK1; then
max_discard=$(lsblk -Dbn $DEV_RDSKDIR/$DISK1 | awk '{ print $4; exit }')
fi
@@ -80,7 +80,7 @@ function blockdev_exists # device
# that can affect device nodes
for i in {1..3}; do
udev_wait
[[ -b "$device" ]] && return 0
is_disk_device "$device" && return 0
done
log_fail "$device does not exist as a block device"
}
@@ -127,17 +127,17 @@ function verify_partition # device
{
typeset device="$1"
if [[ ! -b "$device" ]]; then
if ! is_disk_device "$device"; then
log_fail "$device is not a block device"
fi
# create a small dummy partition
set_partition 0 1 1m $device
# verify we can access the partition on the device
devname="$(readlink -f "$device")"
if is_linux; then
[[ -b "$devname""p1" ]]
if is_linux || is_freebsd; then
is_disk_device "$devname""p1"
else
[[ -b "$devname""s0" ]]
is_disk_device "$devname""s0"
fi
return $?
}