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 = []
|
slots = []
|
||||||
for entry in sorted(enc_dir.iterdir()):
|
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():
|
if not entry.is_dir():
|
||||||
continue
|
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:
|
if slot_num is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -93,7 +94,7 @@ def list_slots(enclosure_id: str) -> list[dict]:
|
|||||||
else:
|
else:
|
||||||
# Also check the 'status' file — "not installed" means empty
|
# Also check the 'status' file — "not installed" means empty
|
||||||
status = _read_sysfs(entry / "status")
|
status = _read_sysfs(entry / "status")
|
||||||
if status and status != "not installed":
|
if status and status not in ("not installed", ""):
|
||||||
populated = True
|
populated = True
|
||||||
|
|
||||||
slots.append({
|
slots.append({
|
||||||
@@ -105,9 +106,27 @@ def list_slots(enclosure_id: str) -> list[dict]:
|
|||||||
return slots
|
return slots
|
||||||
|
|
||||||
|
|
||||||
def _parse_slot_number(name: str) -> int | None:
|
def _parse_slot_number(entry: Path) -> int | None:
|
||||||
"""Extract the slot number from a sysfs slot directory name."""
|
"""Extract the slot number from a sysfs slot directory.
|
||||||
# Handles "Slot 00", "Slot00", "Disk 1", "ArrayDevice00", etc.
|
|
||||||
|
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 "):
|
for prefix in ("Slot ", "Slot", "Disk ", "Disk", "ArrayDevice", "SLOT "):
|
||||||
if name.startswith(prefix):
|
if name.startswith(prefix):
|
||||||
num_str = name[len(prefix):].strip()
|
num_str = name[len(prefix):].strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user