diff options
Diffstat (limited to 'cmd')
-rwxr-xr-x | cmd/zed/zed.d/statechange-led.sh | 46 | ||||
-rwxr-xr-x | cmd/zed/zed.d/statechange-notify.sh | 4 | ||||
-rw-r--r-- | cmd/zed/zed.d/zed-functions.sh | 11 |
3 files changed, 39 insertions, 22 deletions
diff --git a/cmd/zed/zed.d/statechange-led.sh b/cmd/zed/zed.d/statechange-led.sh index 7a8c1fde9..c1a1bd92d 100755 --- a/cmd/zed/zed.d/statechange-led.sh +++ b/cmd/zed/zed.d/statechange-led.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # Turn off/on the VDEV's enclosure fault LEDs when the pool's state changes. # @@ -24,6 +24,7 @@ # 2: enclosure leds administratively disabled # 3: The led sysfs path passed from ZFS does not exist # 4: $ZPOOL not set +# 5: awk is not installed [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc" . "${ZED_ZEDLET_DIR}/zed-functions.sh" @@ -37,6 +38,7 @@ if [ "${ZED_USE_ENCLOSURE_LEDS}" != "1" ] ; then fi zed_check_cmd "$ZPOOL" || exit 4 +zed_check_cmd awk || exit 5 # Global used in set_led debug print vdev="" @@ -52,7 +54,7 @@ vdev="" # Return # 0 on success, 3 on missing sysfs path # -function check_and_set_led +check_and_set_led() { file="$1" val="$2" @@ -86,12 +88,13 @@ function check_and_set_led done } -function state_to_val { +state_to_val() +{ state="$1" - if [ "$state" == "FAULTED" ] || [ "$state" == "DEGRADED" ] || \ - [ "$state" == "UNAVAIL" ] ; then + if [ "$state" = "FAULTED" ] || [ "$state" = "DEGRADED" ] || \ + [ "$state" = "UNAVAIL" ] ; then echo 1 - elif [ "$state" == "ONLINE" ] ; then + elif [ "$state" = "ONLINE" ] ; then echo 0 fi } @@ -107,19 +110,26 @@ function state_to_val { # Return # 0 on success, 3 on missing sysfs path # -function process_pool +process_pool() { pool="$1" rc=0 # Lookup all the current LED values and paths in parallel + #shellcheck disable=SC2016 cmd='echo led_token=$(cat "$VDEV_ENC_SYSFS_PATH/fault"),"$VDEV_ENC_SYSFS_PATH",' out=$($ZPOOL status -vc "$cmd" "$pool" | grep 'led_token=') - while read -r vdev state read write chksum therest ; do + #shellcheck disable=SC2034 + echo "$out" | while read -r vdev state read write chksum therest; do # Read out current LED value and path tmp=$(echo "$therest" | sed 's/^.*led_token=//g') - IFS="," read -r current_val vdev_enc_sysfs_path <<< "$tmp" + vdev_enc_sysfs_path=$(echo "$tmp" | awk -F ',' '{print $2}') + current_val=$(echo "$tmp" | awk -F ',' '{print $1}') + + if [ "$current_val" != "0" ] ; then + current_val=1 + fi if [ -z "$vdev_enc_sysfs_path" ] ; then # Skip anything with no sysfs LED entries @@ -127,6 +137,7 @@ function process_pool fi if [ ! -e "$vdev_enc_sysfs_path/fault" ] ; then + #shellcheck disable=SC2030 rc=1 zed_log_msg "vdev $vdev '$file/fault' doesn't exist" continue; @@ -134,17 +145,19 @@ function process_pool val=$(state_to_val "$state") - if [ "$current_val" == "$val" ] ; then + if [ "$current_val" = "$val" ] ; then # LED is already set correctly continue; fi - check_and_set_led "$vdev_enc_sysfs_path/fault" "$val" - (( rc |= $? )) + if ! check_and_set_led "$vdev_enc_sysfs_path/fault" "$val"; then + rc=1 + fi - done <<< "$out" + done - if [ "$rc" == "0" ] ; then + #shellcheck disable=SC2031 + if [ "$rc" = "0" ] ; then return 0 else # We didn't see a sysfs entry that we wanted to set @@ -155,9 +168,10 @@ function process_pool if [ ! -z "$ZEVENT_VDEV_ENC_SYSFS_PATH" ] && [ ! -z "$ZEVENT_VDEV_STATE_STR" ] ; then # Got a statechange for an individual VDEV val=$(state_to_val "$ZEVENT_VDEV_STATE_STR") - vdev="$(basename $ZEVENT_VDEV_PATH)" + vdev=$(basename "$ZEVENT_VDEV_PATH") check_and_set_led "$ZEVENT_VDEV_ENC_SYSFS_PATH/fault" "$val" else # Process the entire pool - process_pool "$(zed_guid_to_pool $ZEVENT_POOL_GUID)" + poolname=$(zed_guid_to_pool "$ZEVENT_POOL_GUID") + process_pool "$poolname" fi diff --git a/cmd/zed/zed.d/statechange-notify.sh b/cmd/zed/zed.d/statechange-notify.sh index eba4ef9d8..f46080a03 100755 --- a/cmd/zed/zed.d/statechange-notify.sh +++ b/cmd/zed/zed.d/statechange-notify.sh @@ -39,10 +39,10 @@ umask 077 note_subject="ZFS device fault for pool ${ZEVENT_POOL_GUID} on $(hostname)" note_pathname="${TMPDIR:="/tmp"}/$(basename -- "$0").${ZEVENT_EID}.$$" { - if [ "${ZEVENT_VDEV_STATE_STR}" == "FAULTED" ] ; then + if [ "${ZEVENT_VDEV_STATE_STR}" = "FAULTED" ] ; then echo "The number of I/O errors associated with a ZFS device exceeded" echo "acceptable levels. ZFS has marked the device as faulted." - elif [ "${ZEVENT_VDEV_STATE_STR}" == "DEGRADED" ] ; then + elif [ "${ZEVENT_VDEV_STATE_STR}" = "DEGRADED" ] ; then echo "The number of checksum errors associated with a ZFS device" echo "exceeded acceptable levels. ZFS has marked the device as" echo "degraded." diff --git a/cmd/zed/zed.d/zed-functions.sh b/cmd/zed/zed.d/zed-functions.sh index d234fb48a..b7de5104f 100644 --- a/cmd/zed/zed.d/zed-functions.sh +++ b/cmd/zed/zed.d/zed-functions.sh @@ -1,3 +1,5 @@ +#!/bin/sh +# shellcheck disable=SC2039 # zed-functions.sh # # ZED helper functions for use in ZEDLETs @@ -126,6 +128,7 @@ zed_lock() # eval "exec ${fd}> '${lockfile}'" err="$(flock --exclusive "${fd}" 2>&1)" + # shellcheck disable=SC2181 if [ $? -ne 0 ]; then zed_log_err "failed to lock \"${lockfile}\": ${err}" fi @@ -162,8 +165,8 @@ zed_unlock() fi # Release the lock and close the file descriptor. - # err="$(flock --unlock "${fd}" 2>&1)" + # shellcheck disable=SC2181 if [ $? -ne 0 ]; then zed_log_err "failed to unlock \"${lockfile}\": ${err}" fi @@ -424,14 +427,14 @@ zed_rate_limit() # Return # Pool name # -function zed_guid_to_pool +zed_guid_to_pool() { if [ -z "$1" ] ; then return fi - guid=$(printf "%llu" $1) + guid=$(printf "%llu" "$1") if [ ! -z "$guid" ] ; then - $ZPOOL get -H -ovalue,name guid | awk '$1=='$guid' {print $2}' + $ZPOOL get -H -ovalue,name guid | awk '$1=='"$guid"' {print $2}' fi } |