Enumerate physical drives behind RAID via smartctl megaraid passthrough

This commit is contained in:
2026-03-07 05:32:08 +00:00
parent 98e435674c
commit 1dd40a1181
5 changed files with 171 additions and 55 deletions

View File

@@ -3,7 +3,7 @@ import json
import logging
from services.enclosure import discover_enclosures, list_slots
from services.smart import get_smart_data
from services.smart import get_smart_data, scan_megaraid_drives
from services.zfs import get_zfs_pool_map
logger = logging.getLogger(__name__)
@@ -106,6 +106,31 @@ async def get_host_drives() -> list[dict]:
"zfs_vdev": zfs_info.get("vdev"),
"zfs_state": zfs_info.get("state"),
"health_status": health_status,
"physical_drives": [],
})
# Discover physical drives behind RAID controllers
has_raid = any(r["drive_type"] == "raid" and not r["smart_supported"] for r in results)
if has_raid:
megaraid_drives = await scan_megaraid_drives()
for pd in megaraid_drives:
pd_healthy = pd.get("smart_healthy")
pd_realloc = pd.get("reallocated_sectors") or 0
pd_pending = pd.get("pending_sectors") or 0
pd_unc = pd.get("uncorrectable_errors") or 0
if pd_healthy is False:
pd["health_status"] = "error"
elif pd_realloc > 0 or pd_pending > 0 or pd_unc > 0:
pd["health_status"] = "warning"
else:
pd["health_status"] = "healthy"
pd["drive_type"] = "physical"
pd["physical_drives"] = []
# Attach to the first RAID host drive
for r in results:
if r["drive_type"] == "raid" and not r["smart_supported"]:
r["physical_drives"] = megaraid_drives
break
return results