Workaround broken VDEV_UPATH
Sometimes, for reasons I haven't looked into yet, VDEV_UPATH gets set to /dev/(null), breaking all these scripts. It'd be nice to have a fallback case to avoid total failure. Reviewed-by: Tony Hutter <hutter2@llnl.gov> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rich Ercolani <rincebrain@gmail.com> Closes #13436
This commit is contained in:
parent
a30927f763
commit
ecaccf764a
|
@ -15,6 +15,15 @@ if [ "$1" = "-h" ] ; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Sometimes, UPATH ends up /dev/(null).
|
||||||
|
# That should be corrected, but for now...
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
if [ ! -b "$VDEV_UPATH" ]; then
|
||||||
|
somepath="${VDEV_PATH}"
|
||||||
|
else
|
||||||
|
somepath="${VDEV_UPATH}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$script" = "iostat-1s" ] ; then
|
if [ "$script" = "iostat-1s" ] ; then
|
||||||
# Do a single one-second sample
|
# Do a single one-second sample
|
||||||
interval=1
|
interval=1
|
||||||
|
@ -27,8 +36,7 @@ elif [ "$script" = "iostat-10s" ] ; then
|
||||||
brief="yes"
|
brief="yes"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2154
|
if [ -f "$somepath" ] ; then
|
||||||
if [ -f "$VDEV_UPATH" ] ; then
|
|
||||||
# We're a file-based vdev, iostat doesn't work on us. Do nothing.
|
# We're a file-based vdev, iostat doesn't work on us. Do nothing.
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
@ -37,13 +45,13 @@ if [ "$(uname)" = "FreeBSD" ]; then
|
||||||
out=$(iostat -dKx \
|
out=$(iostat -dKx \
|
||||||
${interval:+"-w $interval"} \
|
${interval:+"-w $interval"} \
|
||||||
${interval:+"-c 1"} \
|
${interval:+"-c 1"} \
|
||||||
"$VDEV_UPATH" | tail -n 2)
|
"$somepath" | tail -n 2)
|
||||||
else
|
else
|
||||||
out=$(iostat -kx \
|
out=$(iostat -kx \
|
||||||
${brief:+"-y"} \
|
${brief:+"-y"} \
|
||||||
${interval:+"$interval"} \
|
${interval:+"$interval"} \
|
||||||
${interval:+"1"} \
|
${interval:+"1"} \
|
||||||
"$VDEV_UPATH" | grep -v '^$' | tail -n 2)
|
"$somepath" | grep -v '^$' | tail -n 2)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -61,21 +61,29 @@ else
|
||||||
list=$(echo "$script" | tr '[:upper:]' '[:lower:]')
|
list=$(echo "$script" | tr '[:upper:]' '[:lower:]')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Sometimes, UPATH ends up /dev/(null).
|
||||||
|
# That should be corrected, but for now...
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
if [ ! -b "$VDEV_UPATH" ]; then
|
||||||
|
somepath="${VDEV_PATH}"
|
||||||
|
else
|
||||||
|
somepath="${VDEV_UPATH}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Older versions of lsblk don't support all these values (like SERIAL).
|
# Older versions of lsblk don't support all these values (like SERIAL).
|
||||||
for i in $list ; do
|
for i in $list ; do
|
||||||
|
|
||||||
# Special case: Looking up the size of a file-based vdev can't
|
# Special case: Looking up the size of a file-based vdev can't
|
||||||
# be done with lsblk.
|
# be done with lsblk.
|
||||||
# shellcheck disable=SC2154
|
if [ "$i" = "size" ] && [ -f "$somepath" ] ; then
|
||||||
if [ "$i" = "size" ] && [ -f "$VDEV_UPATH" ] ; then
|
size=$(du -h --apparent-size "$somepath" | cut -f 1)
|
||||||
size=$(du -h --apparent-size "$VDEV_UPATH" | cut -f 1)
|
|
||||||
echo "size=$size"
|
echo "size=$size"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
val=""
|
val=""
|
||||||
if val=$(eval "lsblk -dl -n -o $i $VDEV_UPATH 2>/dev/null") ; then
|
if val=$(eval "lsblk -dl -n -o $i $somepath 2>/dev/null") ; then
|
||||||
# Remove leading/trailing whitespace from value
|
# Remove leading/trailing whitespace from value
|
||||||
val=$(echo "$val" | sed -e 's/^[[:space:]]*//' \
|
val=$(echo "$val" | sed -e 's/^[[:space:]]*//' \
|
||||||
-e 's/[[:space:]]*$//')
|
-e 's/[[:space:]]*$//')
|
||||||
|
|
|
@ -69,8 +69,16 @@ if [ "$1" = "-h" ] ; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Sometimes, UPATH ends up /dev/(null).
|
||||||
|
# That should be corrected, but for now...
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
if [ -b "$VDEV_UPATH" ] && PATH="/usr/sbin:$PATH" command -v smartctl > /dev/null || [ -n "$samples" ] ; then
|
if [ ! -b "$VDEV_UPATH" ]; then
|
||||||
|
somepath="${VDEV_PATH}"
|
||||||
|
else
|
||||||
|
somepath="${VDEV_UPATH}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -b "$somepath" ] && PATH="/usr/sbin:$PATH" command -v smartctl > /dev/null || [ -n "$samples" ] ; then
|
||||||
if [ -n "$samples" ] ; then
|
if [ -n "$samples" ] ; then
|
||||||
# cat a smartctl output text file instead of running smartctl
|
# cat a smartctl output text file instead of running smartctl
|
||||||
# on a vdev (only used for developer testing).
|
# on a vdev (only used for developer testing).
|
||||||
|
@ -78,7 +86,7 @@ if [ -b "$VDEV_UPATH" ] && PATH="/usr/sbin:$PATH" command -v smartctl > /dev/nul
|
||||||
echo "file=$file"
|
echo "file=$file"
|
||||||
raw_out=$(cat "$samples/$file")
|
raw_out=$(cat "$samples/$file")
|
||||||
else
|
else
|
||||||
raw_out=$(sudo smartctl -a "$VDEV_UPATH")
|
raw_out=$(sudo smartctl -a "$somepath")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# What kind of drive are we? Look for the right line in smartctl:
|
# What kind of drive are we? Look for the right line in smartctl:
|
||||||
|
|
Loading…
Reference in New Issue