aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Moeller <[email protected]>2020-01-03 12:10:17 -0500
committerBrian Behlendorf <[email protected]>2020-01-03 09:10:17 -0800
commit665684d721f01772f3557b952829e2a3a5c35423 (patch)
treeacddb6cc73267c6c1dd9040ce6f00ec2c0ebaf2f
parentd7164b27bee6c2837affcc42892fbd4b45dd13ff (diff)
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 <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #9795
-rw-r--r--tests/zfs-tests/include/blkdev.shlib31
-rw-r--r--tests/zfs-tests/include/libtest.shlib5
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool_trim/setup.ksh2
-rwxr-xr-xtests/zfs-tests/tests/functional/redacted_send/redacted_mounts.ksh8
-rwxr-xr-xtests/zfs-tests/tests/functional/redacted_send/redacted_volume.ksh12
-rwxr-xr-xtests/zfs-tests/tests/functional/trim/setup.ksh2
-rw-r--r--tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_common.kshlib10
7 files changed, 46 insertions, 24 deletions
diff --git a/tests/zfs-tests/include/blkdev.shlib b/tests/zfs-tests/include/blkdev.shlib
index 758af09ad..66c18b86b 100644
--- a/tests/zfs-tests/include/blkdev.shlib
+++ b/tests/zfs-tests/include/blkdev.shlib
@@ -93,11 +93,19 @@ function is_physical_device #device
device=${device#$DEV_RDSKDIR}
if is_linux; then
- [[ -b "$DEV_DSKDIR/$device" ]] && \
+ is_disk_device "$DEV_DSKDIR/$device" && \
[[ -f /sys/module/loop/parameters/max_part ]]
return $?
elif is_freebsd; then
- echo $device | grep -q -e '^a?da[0-9]*$' -e '^md[0-9]*$' > /dev/null 2>&1
+ is_disk_device "$DEV_DSKDIR/$device" && \
+ echo $device | grep -q \
+ -e '^a?da[0-9]+$' \
+ -e '^md[0-9]+$' \
+ -e '^mfid[0-9]+$' \
+ -e '^nda[0-9]+$' \
+ -e '^nvd[0-9]+$' \
+ -e '^vtbd[0-9]+$' \
+ > /dev/null 2>&1
return $?
else
echo $device | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
@@ -162,12 +170,27 @@ function is_mpath_device #disk
return $?
fi
elif is_freebsd; then
- test -b $DEV_MPATHDIR/$disk
+ is_disk_device $DEV_MPATHDIR/$disk
else
false
fi
}
+#
+# Check if the given path is the appropriate sort of device special node.
+#
+function is_disk_device #path
+{
+ typeset path=$1
+
+ if is_freebsd; then
+ # FreeBSD doesn't have block devices, only character devices.
+ test -c $path
+ else
+ test -b $path
+ fi
+}
+
# Set the slice prefix for disk partitioning depending
# on whether the device is a real, multipath, or loop device.
# Currently all disks have to be of the same type, so only
@@ -241,7 +264,7 @@ function get_device_dir #device
if [[ $device != "/" ]]; then
device=${device%/*}
fi
- if [[ -b "$DEV_DSKDIR/$device" ]]; then
+ if is_disk_device "$DEV_DSKDIR/$device"; then
device="$DEV_DSKDIR"
fi
echo $device
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib
index d6033bf30..888abdb75 100644
--- a/tests/zfs-tests/include/libtest.shlib
+++ b/tests/zfs-tests/include/libtest.shlib
@@ -2392,13 +2392,12 @@ EOF
# each case. limit the number to max_finddisksnum
count=0
for disk in $unused_candidates; do
- if [ -b $DEV_DSKDIR/${disk}s0 ]; then
- if [ $count -lt $max_finddisksnum ]; then
+ if is_disk_device $DEV_DSKDIR/${disk}s0 && \
+ [ $count -lt $max_finddisksnum ]; then
unused="$unused $disk"
# do not impose limit if $@ is provided
[[ -z $@ ]] && ((count = count + 1))
fi
- fi
done
# finally, return our disk list
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_trim/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_trim/setup.ksh
index cdcf038ad..d524c0005 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zpool_trim/setup.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_trim/setup.ksh
@@ -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
diff --git a/tests/zfs-tests/tests/functional/redacted_send/redacted_mounts.ksh b/tests/zfs-tests/tests/functional/redacted_send/redacted_mounts.ksh
index b24f5ccad..205797184 100755
--- a/tests/zfs-tests/tests/functional/redacted_send/redacted_mounts.ksh
+++ b/tests/zfs-tests/tests/functional/redacted_send/redacted_mounts.ksh
@@ -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
diff --git a/tests/zfs-tests/tests/functional/redacted_send/redacted_volume.ksh b/tests/zfs-tests/tests/functional/redacted_send/redacted_volume.ksh
index b3c519b7d..13453fa36 100755
--- a/tests/zfs-tests/tests/functional/redacted_send/redacted_volume.ksh
+++ b/tests/zfs-tests/tests/functional/redacted_send/redacted_volume.ksh
@@ -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
diff --git a/tests/zfs-tests/tests/functional/trim/setup.ksh b/tests/zfs-tests/tests/functional/trim/setup.ksh
index 3eb644690..52d57a766 100755
--- a/tests/zfs-tests/tests/functional/trim/setup.ksh
+++ b/tests/zfs-tests/tests/functional/trim/setup.ksh
@@ -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
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_common.kshlib b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_common.kshlib
index fb6d992ff..505e76ca5 100644
--- a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_common.kshlib
+++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_common.kshlib
@@ -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 $?
}