-
Notifications
You must be signed in to change notification settings - Fork 24
Added md-raid support #9
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
base: master
Are you sure you want to change the base?
Conversation
@amarao, are you open to importing I could make this PR a bit more robust and readable if Let me know... |
Improvements are welcome, but, please, do not break existing scenarios. |
And re is in standard, so, yep, it's fine as long as it readable |
We cleaned up the commit, and now it will recurse arbitrary block device stacking hierarchies, such as RAID, LVM, etc. Please see the commit message and the diff for details. I believe that everything is compatible in the same way, now with an additional feature. The second commit is a minor change that default sorting output by enclosure and slot. Let me know if you have any questions or comments, and thank you for maintaining this! -Eric |
Turn LEDs on or off depending on their existence at the bottom of block device stacks. This works with pretty much any hierarchy (RAID, LVM, DM, etc) because the kernel tracks block device stacking dependencies in /sys/block/<dev>/slaves/* (which can be seen as a tree using the tool `lsblk`). For example: ] grep md9 /proc/mdstat md9 : active raid5 sdg[0] sde[6] sdj[4] sdk[3] sdf[2] sdl[1] ] encled md9 0:0:18:0/Slot11 sde fault_off locate_off 0:0:18:0/Slot08 sdf fault_off locate_off 0:0:18:0/Slot06 sdg fault_off locate_off 0:0:18:0/Slot10 sdj fault_off locate_off 0:0:18:0/Slot09 sdk fault_off locate_off 0:0:18:0/Slot07 sdl fault_off locate_off ] encled md9 locate ] encled md9 0:0:18:0/Slot11 sde fault_off LOCATE_ON 0:0:18:0/Slot08 sdf fault_off LOCATE_ON 0:0:18:0/Slot06 sdg fault_off LOCATE_ON 0:0:18:0/Slot10 sdj fault_off LOCATE_ON 0:0:18:0/Slot09 sdk fault_off LOCATE_ON 0:0:18:0/Slot07 sdl fault_off LOCATE_ON In the more complex stack shown below, /dev/bcache0 is backed by /dev/md125 and /dev/md126. Now encled can find the referenced devices at any point in the stack: ] encled md125 0:0:18:0/Slot03 sdh fault_off locate_off 0:0:18:0/Slot02 sdc fault_off locate_off ] encled md126 0:0:18:0/Slot01 sdb fault_off locate_off 0:0:18:0/Slot00 sdi fault_off locate_off ] encled bcache0 0:0:18:0/Slot03 sdh fault_off locate_off 0:0:18:0/Slot01 sdb fault_off locate_off 0:0:18:0/Slot02 sdc fault_off locate_off 0:0:18:0/Slot00 sdi fault_off locate_off Signed-off-by: Eric Wheeler <[email protected]>
Before: ENCLOSURE/SLOT DEV FAULT_LED LOCATION_LED ---------------------------------------------------- 0:0:18:0/Slot05 ---- fault_off locate_off 0:0:18:0/Slot23 ---- fault_off locate_off 0:0:18:0/Slot13 ---- fault_off locate_off 0:0:18:0/Slot03 sdh fault_off locate_off 0:0:18:0/Slot21 ---- fault_off locate_off 0:0:18:0/Slot11 sde fault_off locate_off 0:0:18:0/Slot01 sdb fault_off locate_off 0:0:18:0/Slot18 ---- fault_off locate_off 0:0:18:0/Slot08 sdf fault_off locate_off 0:0:18:0/Slot16 ---- fault_off locate_off 0:0:18:0/Slot06 sdg fault_off locate_off 0:0:18:0/Slot14 ---- fault_off locate_off 0:0:18:0/Slot04 ---- fault_off locate_off 0:0:18:0/Slot22 ---- fault_off locate_off 0:0:18:0/Slot12 ---- fault_off locate_off 0:0:18:0/Slot02 sdc fault_off locate_off 0:0:18:0/Slot20 ---- fault_off locate_off 0:0:18:0/Slot10 sdj fault_off locate_off 0:0:18:0/Slot00 sdi fault_off locate_off 0:0:18:0/Slot19 ---- fault_off locate_off 0:0:18:0/Slot09 sdk fault_off locate_off 0:0:18:0/Slot17 ---- fault_off locate_off 0:0:18:0/Slot07 sdl fault_off locate_off 0:0:18:0/Slot15 ---- fault_off locate_off After: ENCLOSURE/SLOT DEV FAULT_LED LOCATION_LED ---------------------------------------------------- 0:0:18:0/Slot00 sdi fault_off locate_off 0:0:18:0/Slot01 sdb fault_off locate_off 0:0:18:0/Slot02 sdc fault_off locate_off 0:0:18:0/Slot03 sdh fault_off locate_off 0:0:18:0/Slot04 ---- fault_off locate_off 0:0:18:0/Slot05 ---- fault_off locate_off 0:0:18:0/Slot06 sdg fault_off locate_off 0:0:18:0/Slot07 sdl fault_off locate_off 0:0:18:0/Slot08 sdf fault_off locate_off 0:0:18:0/Slot09 sdk fault_off locate_off 0:0:18:0/Slot10 sdj fault_off locate_off 0:0:18:0/Slot11 sde fault_off locate_off 0:0:18:0/Slot12 ---- fault_off locate_off 0:0:18:0/Slot13 ---- fault_off locate_off 0:0:18:0/Slot14 ---- fault_off locate_off 0:0:18:0/Slot15 ---- fault_off locate_off 0:0:18:0/Slot16 ---- fault_off locate_off 0:0:18:0/Slot17 ---- fault_off locate_off 0:0:18:0/Slot18 ---- fault_off locate_off 0:0:18:0/Slot19 ---- fault_off locate_off 0:0:18:0/Slot20 ---- fault_off locate_off 0:0:18:0/Slot21 ---- fault_off locate_off 0:0:18:0/Slot22 ---- fault_off locate_off 0:0:18:0/Slot23 ---- fault_off locate_off Signed-off-by: Eric Wheeler <[email protected]>
@@ -153,6 +160,38 @@ def list_all(): | |||
devlist.append((e, s, path, status)) | |||
return devlist | |||
|
|||
# Recursively find SCSI devices in block device stacking hierarchies | |||
# by referencing /sys/block/<dev>/slaves/* | |||
def find_parent_devs(dev_names): |
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 like this idea, but I don't like updates to the dev_names in the code. It's really hard to reason about it (it passed as argument into recursive function and is updating it's arguments).
Can you change it in a way, which does not update a function argument? A new variable like 'combined = dev_name + new_names` would do it.
Second, there is a global depth, but I don't see use of it. (debug leftovers?).
Turn LEDs on or off depending on their RAID membership
For example: