Fix slot discovery for bare numeric sysfs directories
This commit is contained in:
@@ -71,12 +71,13 @@ def list_slots(enclosure_id: str) -> list[dict]:
|
||||
|
||||
slots = []
|
||||
for entry in sorted(enc_dir.iterdir()):
|
||||
# Slot entries are directories like "Slot 00", "Slot 01", etc.
|
||||
# Some enclosures use "Disk" or "ArrayDevice" prefixes.
|
||||
if not entry.is_dir():
|
||||
continue
|
||||
name = entry.name
|
||||
slot_num = _parse_slot_number(name)
|
||||
|
||||
# Determine if this is a drive slot element.
|
||||
# Some enclosures use named dirs ("Slot 00", "Disk 1", "ArrayDevice00"),
|
||||
# others use bare numeric dirs ("0", "1", "2") with a "type" file.
|
||||
slot_num = _parse_slot_number(entry)
|
||||
if slot_num is None:
|
||||
continue
|
||||
|
||||
@@ -93,7 +94,7 @@ def list_slots(enclosure_id: str) -> list[dict]:
|
||||
else:
|
||||
# Also check the 'status' file — "not installed" means empty
|
||||
status = _read_sysfs(entry / "status")
|
||||
if status and status != "not installed":
|
||||
if status and status not in ("not installed", ""):
|
||||
populated = True
|
||||
|
||||
slots.append({
|
||||
@@ -105,9 +106,27 @@ def list_slots(enclosure_id: str) -> list[dict]:
|
||||
return slots
|
||||
|
||||
|
||||
def _parse_slot_number(name: str) -> int | None:
|
||||
"""Extract the slot number from a sysfs slot directory name."""
|
||||
# Handles "Slot 00", "Slot00", "Disk 1", "ArrayDevice00", etc.
|
||||
def _parse_slot_number(entry: Path) -> int | None:
|
||||
"""Extract the slot number from a sysfs slot directory.
|
||||
|
||||
Handles multiple naming conventions:
|
||||
- Bare numeric dirs ("0", "1") with type=device and a slot file
|
||||
- Named dirs ("Slot 00", "Slot00", "Disk 1", "ArrayDevice00")
|
||||
"""
|
||||
name = entry.name
|
||||
|
||||
# Bare numeric directory — check the type file to confirm it's a device slot
|
||||
if name.isdigit():
|
||||
entry_type = _read_sysfs(entry / "type")
|
||||
if entry_type not in ("device", "disk"):
|
||||
return None
|
||||
# Prefer the 'slot' file for the actual slot number
|
||||
slot_val = _read_sysfs(entry / "slot")
|
||||
if slot_val.isdigit():
|
||||
return int(slot_val)
|
||||
return int(name)
|
||||
|
||||
# Named directory prefixes
|
||||
for prefix in ("Slot ", "Slot", "Disk ", "Disk", "ArrayDevice", "SLOT "):
|
||||
if name.startswith(prefix):
|
||||
num_str = name[len(prefix):].strip()
|
||||
|
||||
Reference in New Issue
Block a user