raid: parse storcli64/storcli2's actual per-slot drive JSON shape
RAID Controller Management showed "No drives detected" for a live
SAS3808-iMR controller even though storcli64 clearly enumerates its
drives. Root cause: the "eall/sall show all J" drive-listing parser
(collector/raid.go and its webui/raid_mgmt.go duplicate) assumed
drives are reported as a single "Drive Information" array, but real
storcli64/storcli2 output nests each drive under its own dynamically
named key ("Drive /c0/e69/s0", paired with a "... - Detailed
Information" key) — confirmed against a live techdump/storcli64-drives.json
capture. The assumed shape was never actually produced by the tool, so
this affected every storcli64/storcli2 controller, not just Tri-Mode
ones (the storcli2 fallback added in b7f015c never got a chance to
mask it in practice, since storcli2 itself reports zero controllers on
this hardware — a separate, unrelated tool-side gap).
Both parsers now read "Response Data" as a raw key map and pull drives
from either shape, so older storcli output using the array form still
works alongside the real per-slot form.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
2d84ddb577
commit
4e306ff78c
@@ -72,17 +72,7 @@ func detectLSIControllers() []raidControllerInfo {
|
||||
|
||||
var driveDoc struct {
|
||||
Controllers []struct {
|
||||
ResponseData struct {
|
||||
DriveInformation []struct {
|
||||
EIDSlt string `json:"EID:Slt"`
|
||||
State string `json:"State"`
|
||||
Size string `json:"Size"`
|
||||
Intf string `json:"Intf"`
|
||||
Med string `json:"Med"`
|
||||
Model string `json:"Model"`
|
||||
SN string `json:"SN"`
|
||||
} `json:"Drive Information"`
|
||||
} `json:"Response Data"`
|
||||
ResponseData map[string]json.RawMessage `json:"Response Data"`
|
||||
} `json:"Controllers"`
|
||||
}
|
||||
if len(driveOut) > 0 {
|
||||
@@ -105,22 +95,8 @@ func detectLSIControllers() []raidControllerInfo {
|
||||
}
|
||||
|
||||
if i < len(driveDoc.Controllers) {
|
||||
for _, d := range driveDoc.Controllers[i].ResponseData.DriveInformation {
|
||||
info := raidDriveInfo{
|
||||
Slot: strings.TrimSpace(d.EIDSlt),
|
||||
Model: strings.TrimSpace(d.Model),
|
||||
State: strings.TrimSpace(d.State),
|
||||
SizeGB: raidParseHumanSizeGB(d.Size),
|
||||
Serial: strings.TrimSpace(d.SN),
|
||||
}
|
||||
ctrl.AllDrives = append(ctrl.AllDrives, info)
|
||||
switch strings.TrimSpace(d.State) {
|
||||
case "Frgn":
|
||||
ctrl.ForeignDrives = append(ctrl.ForeignDrives, info)
|
||||
case "UGood", "JBOD":
|
||||
ctrl.FreeDrives = append(ctrl.FreeDrives, info)
|
||||
}
|
||||
}
|
||||
ctrl.AllDrives, ctrl.ForeignDrives, ctrl.FreeDrives = classifyStorcliDrives(
|
||||
parseStorcliResponseDataDrives(driveDoc.Controllers[i].ResponseData))
|
||||
}
|
||||
|
||||
controllers = append(controllers, ctrl)
|
||||
@@ -128,15 +104,78 @@ func detectLSIControllers() []raidControllerInfo {
|
||||
return controllers
|
||||
}
|
||||
|
||||
// storcliDriveJSON is the per-drive record shape storcli64/storcli2 emit,
|
||||
// whether nested in a "Drive Information" array or a per-slot "Drive
|
||||
// /cX/eY/sZ" key (see parseStorcliResponseDataDrives).
|
||||
type storcliDriveJSON struct {
|
||||
EIDSlt string `json:"EID:Slt"`
|
||||
State string `json:"State"`
|
||||
Size string `json:"Size"`
|
||||
Model string `json:"Model"`
|
||||
SN string `json:"SN"`
|
||||
}
|
||||
|
||||
// storcliDrivePerSlotKeyRe matches "Response Data" keys like "Drive /c0/e69/s0".
|
||||
// Real storcli64/storcli2 "eall/sall show all J" output nests each drive under
|
||||
// its own dynamically-named key instead of a shared "Drive Information" array
|
||||
// — confirmed against a live SAS3808-iMR dump that has no "Drive Information"
|
||||
// key at all. Must not match the paired "... - Detailed Information" key.
|
||||
var storcliDrivePerSlotKeyRe = regexp.MustCompile(`^Drive /c\d+/e\d+/s\d+$`)
|
||||
|
||||
// parseStorcliResponseDataDrives extracts drive records from one controller's
|
||||
// "Response Data" object, supporting both the legacy "Drive Information"
|
||||
// array shape and the per-slot dynamic-key shape.
|
||||
func parseStorcliResponseDataDrives(responseData map[string]json.RawMessage) []storcliDriveJSON {
|
||||
var drives []storcliDriveJSON
|
||||
appendList := func(raw json.RawMessage) {
|
||||
var list []storcliDriveJSON
|
||||
if err := json.Unmarshal(raw, &list); err != nil {
|
||||
return
|
||||
}
|
||||
drives = append(drives, list...)
|
||||
}
|
||||
if raw, ok := responseData["Drive Information"]; ok {
|
||||
appendList(raw)
|
||||
}
|
||||
for key, raw := range responseData {
|
||||
if storcliDrivePerSlotKeyRe.MatchString(key) {
|
||||
appendList(raw)
|
||||
}
|
||||
}
|
||||
return drives
|
||||
}
|
||||
|
||||
func classifyStorcliDrives(drives []storcliDriveJSON) (all, foreign, free []raidDriveInfo) {
|
||||
for _, d := range drives {
|
||||
info := raidDriveInfo{
|
||||
Slot: strings.TrimSpace(d.EIDSlt),
|
||||
Model: strings.TrimSpace(d.Model),
|
||||
State: strings.TrimSpace(d.State),
|
||||
SizeGB: raidParseHumanSizeGB(d.Size),
|
||||
Serial: strings.TrimSpace(d.SN),
|
||||
}
|
||||
all = append(all, info)
|
||||
switch strings.TrimSpace(d.State) {
|
||||
case "Frgn":
|
||||
foreign = append(foreign, info)
|
||||
case "UGood", "JBOD":
|
||||
free = append(free, info)
|
||||
}
|
||||
}
|
||||
return all, foreign, free
|
||||
}
|
||||
|
||||
// --- LSI/storcli2 detection (Tri-Mode controllers, e.g. SAS3808-iMR/9500) ---
|
||||
//
|
||||
// storcli2 is a separate tool/JSON schema from storcli64, required for
|
||||
// Broadcom's Tri-Mode MegaRAID line. storcli64 can still enumerate a Tri-Mode
|
||||
// controller at a basic level (hence it shows up once via detectLSIControllers)
|
||||
// but its drive-listing JSON parser finds no "Drive Information" for these
|
||||
// controllers, silently reporting zero drives — this is the storcli2 path
|
||||
// that actually understands them, run as an additional source alongside
|
||||
// storcli64/VROC rather than a replacement.
|
||||
// storcli2 is Broadcom's separate tool/JSON schema for the Tri-Mode MegaRAID
|
||||
// line; on hardware where it works, storcli64 can still enumerate the same
|
||||
// controller at a basic level (hence it may also show up via
|
||||
// detectLSIControllers), so this is run as an additional source alongside
|
||||
// storcli64/VROC rather than a replacement. On at least one confirmed
|
||||
// SAS3808-iMR system, storcli2 itself reports zero controllers even though
|
||||
// storcli64 sees the controller and its drives fine — a separate,
|
||||
// tool-side gap this webui can't work around beyond reporting nothing here
|
||||
// and relying on detectLSIControllers.
|
||||
func detectStorcli2Controllers() []raidControllerInfo {
|
||||
sysOut, err := exec.Command("storcli2", "show", "all", "J").Output()
|
||||
if err != nil {
|
||||
@@ -182,49 +221,22 @@ func detectStorcli2Controllers() []raidControllerInfo {
|
||||
return controllers
|
||||
}
|
||||
|
||||
// parseStorcli2DriveInformation parses a single controller's
|
||||
// "storcli2 /cX/eall/sall show all J" output. The "Drive Information" array
|
||||
// shape matches storcli64's schema (confirmed against Broadcom's published
|
||||
// drive-info-schema.json), so the same field set applies.
|
||||
// parseStorcli2DriveInformation parses a single controller's "storcli2
|
||||
// /cX/eall/sall show all J" output, which uses the same "Response Data"
|
||||
// shape as storcli64 (see parseStorcliResponseDataDrives).
|
||||
func parseStorcli2DriveInformation(raw []byte) (all, foreign, free []raidDriveInfo) {
|
||||
if len(raw) == 0 {
|
||||
return nil, nil, nil
|
||||
}
|
||||
var doc struct {
|
||||
Controllers []struct {
|
||||
ResponseData struct {
|
||||
DriveInformation []struct {
|
||||
EIDSlt string `json:"EID:Slt"`
|
||||
State string `json:"State"`
|
||||
Size string `json:"Size"`
|
||||
Intf string `json:"Intf"`
|
||||
Med string `json:"Med"`
|
||||
Model string `json:"Model"`
|
||||
SN string `json:"SN"`
|
||||
} `json:"Drive Information"`
|
||||
} `json:"Response Data"`
|
||||
ResponseData map[string]json.RawMessage `json:"Response Data"`
|
||||
} `json:"Controllers"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &doc); err != nil || len(doc.Controllers) == 0 {
|
||||
return nil, nil, nil
|
||||
}
|
||||
for _, d := range doc.Controllers[0].ResponseData.DriveInformation {
|
||||
info := raidDriveInfo{
|
||||
Slot: strings.TrimSpace(d.EIDSlt),
|
||||
Model: strings.TrimSpace(d.Model),
|
||||
State: strings.TrimSpace(d.State),
|
||||
SizeGB: raidParseHumanSizeGB(d.Size),
|
||||
Serial: strings.TrimSpace(d.SN),
|
||||
}
|
||||
all = append(all, info)
|
||||
switch strings.TrimSpace(d.State) {
|
||||
case "Frgn":
|
||||
foreign = append(foreign, info)
|
||||
case "UGood", "JBOD":
|
||||
free = append(free, info)
|
||||
}
|
||||
}
|
||||
return all, foreign, free
|
||||
return classifyStorcliDrives(parseStorcliResponseDataDrives(doc.Controllers[0].ResponseData))
|
||||
}
|
||||
|
||||
// --- VROC/mdadm detection ---
|
||||
|
||||
Reference in New Issue
Block a user