Skip to content

fix: Handle JBOD/passthrough disks behind RAID controllers gracefully#138

Draft
andaaron wants to merge 1 commit intoproject-machine:mainfrom
andaaron:jbod
Draft

fix: Handle JBOD/passthrough disks behind RAID controllers gracefully#138
andaaron wants to merge 1 commit intoproject-machine:mainfrom
andaaron:jbod

Conversation

@andaaron
Copy link
Copy Markdown

@andaaron andaaron commented Apr 7, 2026

When a disk is visible through a RAID's sysfs tree but has no corresponding virtual/logical drive entry (e.g. JBOD or passthrough mode), GetDiskType previously returned a hard error that aborted disk scanning entirely. This broke ScanAllDisks on systems with mixed RAID and JBOD configurations.

Introduce ErrNotVirtualDrive sentinel so RAID drivers can signal "I queried successfully but this device isn't one of my VDs" vs a real failure. ScanDisk and GetDiskType now catch this sentinel and fall through to generic sysfs-based disk type detection instead of failing.

Changes across all three RAID drivers (megaraid, mpi3mr, smartpqi):

  • Return ErrNotVirtualDrive when controller query succeeds but the device path matches no virtual drive
  • Implement IsSysPathRAID via the new sysfs package instead of returning false unconditionally
  • Extract IsSysPathRAID and GetSysPaths into linux/sysfs package to allow driver-level use without circular imports and and allow mocking

Includes mock-based unit tests covering RAID match, JBOD fallback, wrapped sentinel detection, real errors, and multi-controller scenarios.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 22.85714% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.13%. Comparing base (83a9a74) to head (2597efa).

Files with missing lines Patch % Lines
linux/sysfs/sysfs.go 0.00% 24 Missing ⚠️
mpi3mr/storcli2.go 0.00% 13 Missing ⚠️
smartpqi/arcconf.go 0.00% 8 Missing ⚠️
linux/system.go 76.19% 3 Missing and 2 partials ⚠️
linux/util.go 0.00% 2 Missing ⚠️
megaraid/storcli.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #138      +/-   ##
==========================================
+ Coverage   49.97%   50.13%   +0.16%     
==========================================
  Files          27       28       +1     
  Lines        3666     3688      +22     
==========================================
+ Hits         1832     1849      +17     
- Misses       1621     1627       +6     
+ Partials      213      212       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

When a disk is visible through a RAID's sysfs tree but has no corresponding virtual/logical drive entry (e.g. JBOD or passthrough mode), GetDiskType previously returned a hard error that aborted disk scanning entirely. This broke ScanAllDisks on systems with mixed RAID and JBOD configurations.

Introduce ErrNotVirtualDrive sentinel so RAID drivers can signal "I queried successfully but this device isn't one of my VDs" vs a real failure. ScanDisk and GetDiskType now catch this sentinel and fall through to generic sysfs-based disk type detection instead of failing.

Changes across all three RAID drivers (megaraid, mpi3mr, smartpqi):
- Return ErrNotVirtualDrive when controller query succeeds but the device path matches no virtual drive
- Implement IsSysPathRAID via the new sysfs package instead of returning false unconditionally
- Extract IsSysPathRAID and GetSysPaths into linux/sysfs package to allow driver-level use without circular imports and and allow mocking

Includes mock-based unit tests covering RAID match, JBOD fallback, wrapped sentinel detection, real errors, and multi-controller scenarios.

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
Copy link
Copy Markdown
Collaborator

@raharper raharper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I'd like to see the storcli output of a JBOD box and integrate that into the _tests we currently have for correctly identifying disks on RAID, but not classify the disk as a RAID type.

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