mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
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:
committed by
Brian Behlendorf
parent
d7164b27be
commit
665684d721
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user