-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zed.d/pool_import-led.sh: fix for current zpool scripts (and a few bonus touchups) #11935
Conversation
b5eff1a
to
e8463f1
Compare
97d4941
to
8703d77
Compare
8703d77
to
d5e39f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fairly certain this script was working but let's definitely make sure. cc: @tonyhutter.
3315496
to
053fe28
Compare
Added fix for #11954, too |
cmd/zed/zed.d/zed-functions.sh
Outdated
if [ -n "$guid" ] ; then | ||
$ZPOOL get -H -ovalue,name guid | awk '$1=='"$guid"' {print $2}' | ||
fi | ||
$ZPOOL get -H -ovalue,name guid | awk '$1 == '"$1"' {print $2; exit}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropping the printf
would mean this function no longer accepts the GUID as either decimal or hex. We should keep that functionality even though the only callers we provide all pass $ZEVENT_POOL_GUID
. Others may have written their own scripts which depend on this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
urgh, this worked in my tests because GAWK supports hex integers as an extension, but MAWK (and, presumably, POSIX AWK) doesn't seem to
updated to retain the printf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to retain the printf
I don't see the printf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
odd, coulda swore i added it back when i made the comment. ah well, it's definitely here now
053fe28
to
ced0cfc
Compare
I'll take a look at this |
Ah, my travel down report-issue-lane started with looking at statechange-led and wondering how/why the fallback process of all pool devices was supposed to work. I have a patch that generalizes the led-handling so statechange-led can light the locate led for OFFLINE devices as well, but I'll hold off on that until this gets landed. Let me know if this needs more testers, as we have enclosures with blinkenlights... |
Spoke too soon - as @nabijaczleweli points out in #11964, removing the |
What other fix? I already wrote one, it's right here. Should be as simple as copying this version into your /etc, exporting an OK pool, futzing with the fault led states, and importing it again to validate it resets them (hopefully; if not, it's trivial to run this branch of the ZEDLET in isolation). |
@nabijaczleweli this simplified patch uses diff --git a/cmd/zed/zed.d/statechange-led.sh b/cmd/zed/zed.d/statechange-led.sh
index e656e125d..4b25a55f9 100755
--- a/cmd/zed/zed.d/statechange-led.sh
+++ b/cmd/zed/zed.d/statechange-led.sh
@@ -115,17 +115,24 @@ 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=')
+
+ # The output will be the vdevs only (from "grep '/dev/'"):
+ #
+ # U45 ONLINE 0 0 0 /dev/sdk 0
+ # U46 ONLINE 0 0 0 /dev/sdm 0
+ # U47 ONLINE 0 0 0 /dev/sdn 0
+ # U50 ONLINE 0 0 0 /dev/sdbn 0
+ #
+ out="$(ZPOOL_SCRIPTS_AS_ROOT=1 $ZPOOL status -c upath,fault_led $pool | grep '/dev/')"
#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')
- vdev_enc_sysfs_path=$(echo "$tmp" | awk -F ',' '{print $2}')
- current_val=$(echo "$tmp" | awk -F ',' '{print $1}')
+ # Get dev name (like 'sda')
+ dev=$(basename $(echo "$therest" | awk '{print $(NF-1)}'))
+ vdev_enc_sysfs_path=$(realpath /sys/class/block/$dev/device/enclosure_device*)
+ current_val=$(echo "$therest" | awk '{print $NF}')
if [ "$current_val" != "0" ] ; then
current_val=1
@@ -171,7 +178,7 @@ if [ -n "$ZEVENT_VDEV_ENC_SYSFS_PATH" ] && [ -n "$ZEVENT_VDEV_STATE_STR" ] ; the
vdev=$(basename "$ZEVENT_VDEV_PATH")
check_and_set_led "$ZEVENT_VDEV_ENC_SYSFS_PATH/fault" "$val"
else
- # Process the entire pool
+ # Process the entire pool (needed for pool_import-led.sh)
poolname=$(zed_guid_to_pool "$ZEVENT_POOL_GUID")
process_pool "$poolname"
fi |
For example, this would happily return "/dev/(null)" for /dev/sda1 Signed-off-by: Ahelenia Ziemiańska <[email protected]>
ec630dc
to
207d721
Compare
cmd/zed/zed.d/statechange-led.sh
Outdated
@@ -1,21 +1,21 @@ | |||
#!/bin/sh | |||
# | |||
# Turn off/on the VDEV's enclosure fault LEDs when the pool's state changes. | |||
# Turn off/on vdevs' enclosure fault LEDs when their pools' state changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The grammar was correct before. VDEV is an acronym for "Virtual Device" or "Virtual Disk" and acronyms are typically capitalized. "VDEV's" was also correct since it's the possessive form of the noun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script toggles enclosure fault LEDs on multiple vdevs at the point when a particular vdev's pool experiences a state change, or "toggles vdevs' enclosure fault LEDs when their pool's state changes"
vdev is not an acronym (that'd be "VD"), but, rather, a shorthand-turned-object-class for "virtual device" as ZFS implements it (some would call this a "normal noun"), confer zpoolconcepts(8), or zpoolprops(8), or zpool-status(8), or
# Turn a vdev's fault LED on if it becomes FAULTED, DEGRADED or UNAVAIL. | ||
# Turn its LED off when it's back ONLINE again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can manipulate many fault LEDs at a time and describes a general rule, also making terminology consistent with the rest
@@ -66,11 +68,11 @@ check_and_set_led() | |||
# If another process is accessing the LED when we attempt to update it, | |||
# the update will be lost so retry until the LED actually changes or we | |||
# timeout. | |||
for _ in $(seq 1 5); do | |||
for _ in 1 2 3 4 5; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted: seq is a very spotty GNU extension (and also not checked for at the top), so when not available this resolves to for _ in ; do
which I assume you can guess why is less than optimal. (Plus, it's literally five numbers, do you really need to spawn a process for it?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has checkbashisms said that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I've misremembered apparently, according to FreeBSD's seq(1) it's had a tumultuous history (as ported from GNU shellutils and/or P9) and should be available on most recent fully-configured UNIXes, but I've also definitely used systems without it in recent years.
Plus, if the portability to small systems doesn't appeal to you, then the performance gains of not using a process to generate 5 numbers that are, in sum, shorter than the process substitution definitely will.
and dunno, haven't run checkbashisms, but it probably won't
c2f2f6f
to
b77749a
Compare
Also minor clean-up with folding state_to_val() into a case, unrolling the lesser-available seq into numbers, ignoring vdev states we don't care about, and documentation comments Signed-off-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11934
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11954
b77749a
to
66c0a07
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-tested statechange-led.sh with your latest push and works as expected. Thanks for sticking with this! 👍
Also minor clean-up with folding state_to_val() into a case, unrolling the lesser-available seq into numbers, ignoring vdev states we don't care about, and documentation comments Signed-off-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11934 Closes #11935
Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11935
Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11935
Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11935 Closes #11954
For example, this would happily return "/dev/(null)" for /dev/sda1 Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11935
Also minor clean-up with folding state_to_val() into a case, unrolling the lesser-available seq into numbers, ignoring vdev states we don't care about, and documentation comments Signed-off-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11934 Closes openzfs#11935
Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11935
Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11935
Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11935 Closes openzfs#11954
For example, this would happily return "/dev/(null)" for /dev/sda1 Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11935
Also minor clean-up with folding state_to_val() into a case, unrolling the lesser-available seq into numbers, ignoring vdev states we don't care about, and documentation comments Signed-off-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11934 Closes openzfs#11935
Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11935
Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11935
Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11935 Closes openzfs#11954
Also minor clean-up with folding state_to_val() into a case, unrolling the lesser-available seq into numbers, ignoring vdev states we don't care about, and documentation comments Signed-off-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11934 Closes openzfs#11935
Also minor clean-up with folding state_to_val() into a case, unrolling the lesser-available seq into numbers, ignoring vdev states we don't care about, and documentation comments Signed-off-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11934 Closes openzfs#11935
Also minor clean-up with folding state_to_val() into a case, unrolling the lesser-available seq into numbers, ignoring vdev states we don't care about, and documentation comments Signed-off-by: Tony Hutter <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#11934 Closes openzfs#11935
Motivation and Context
#11934 and a few others I noticed
Description
I mean, it's what it says on the tins.
How Has This Been Tested?
Looked at it, and tested on fake data, but I don't have a system with SES enclosures, so it'd be great if someone who does could run statechange-led.sh on pool import :)
The rest should be relative non-brainers.
Types of changes
Checklist:
Signed-off-by
.