Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Added md-raid support #9

wants to merge 2 commits into from

Conversation

KJ7LNW
Copy link

@KJ7LNW KJ7LNW commented Mar 22, 2023

Turn LEDs on or off depending on their RAID membership

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

@KJ7LNW
Copy link
Author

KJ7LNW commented Mar 22, 2023

@amarao, are you open to importing re ?

I could make this PR a bit more robust and readable if re is acceptable.

Let me know...

@amarao
Copy link
Owner

amarao commented Mar 22, 2023

Improvements are welcome, but, please, do not break existing scenarios.

@amarao
Copy link
Owner

amarao commented Mar 22, 2023

And re is in standard, so, yep, it's fine as long as it readable

@KJ7LNW
Copy link
Author

KJ7LNW commented Mar 25, 2023

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

Eric Wheeler added 2 commits March 24, 2023 19:22
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):
Copy link
Owner

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?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants