fix(megaraid): rescan SCSI bus after creating a virtual drive#86
Merged
Conversation
storcli's "add vd" returns before the kernel has a block device for the new volume. The megaraid_sas driver only auto-announces the first few VDs created in rapid succession; later ones exist on the controller but have no /dev node (and therefore no /dev/disk/by-id symlink) until the SCSI bus is explicitly rescanned. createLV could then fail with "failed to compute permanent path" once several volumes were created back to back. Force a targeted rescan of the megaraid_sas SCSI hosts after "add vd" and poll findNewLogicalVolume until the new volume's device node is discovered, bounded by a timeout. Only megaraid_sas hosts are scanned to avoid the multi-second link-down timeouts of empty SATA ports.
Contributor
|
Per review: try findNewLogicalVolume first and only force a SCSI bus rescan when it fails, instead of rescanning before every attempt. A volume the kernel discovers on its own now resolves on the first attempt with no rescan and no side effect on the SCSI bus; the rescan stays a targeted remedy for volumes whose device node has not appeared yet.
Contributor
|
TeddyAndrieux
approved these changes
Jul 20, 2026
The settle timeout and interval were unexported while the test lives in an external package (megaraid_test), so its comment claiming tests could shrink them was wrong: the retry test slept a real second, and a future timeout-path test would sleep for a full minute. Export NewVolumeSettleTimeout / NewVolumeSettleInterval (matching the CustomRescanSCSIHosts / CustomFileExists seams) and shrink them in the retry test so it runs without real wall-clock delay.
Contributor
|
LGTM — clean fix for a real production race. The retry loop, targeted SCSI rescan, and test seam all follow the existing patterns (CustomFileExists / CustomEvalSymlinks). Error handling properly surfaces rescan failures on timeout via lastRescanErr. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Creating several MegaRAID virtual drives back to back could fail with:
createLVresolves the freshly created volume through its/dev/disk/by-id/wwn-0x<naa>symlink. When many volumes are created in a row, that symlink was sometimes missing at resolution time and appeared a few seconds later, so the call failed non-deterministically.Root cause
Not a udev latency issue. Instrumenting the sequence showed:
storcli add vdreturns before the OS has a block device for the volume.megaraid_sasdriver auto-announces new VDs via async events, but only for the first few created in rapid succession. After that, VDs exist on the controller with no/dev/sdXat all.by-idsymlink appears in the same instant, soudevadm settleis a no-op here (it returned in single-digit ms every time).Measured per-volume discovery latency: ~1s for the first volumes (auto discovery), then no discovery until an explicit SCSI bus rescan, after which the device and its symlink appear together.
Fix
After
add vd, force a targeted SCSI bus rescan and pollfindNewLogicalVolumeuntil the new volume resolves (bounded by a 60s timeout, 1s interval):- - -only to hosts whoseproc_nameismegaraid_sas. Scanning every host walks empty SATA ports and adds multi-secondlink downtimeouts, so it is deliberately scoped to the MegaRAID hosts.CustomRescanSCSIHostsis a package-level seam (likeCustomFileExists) so the sysfs side effect can be stubbed in tests.Testing
TestCreateLVForcesRescanAndSettles: reproduces the failure on the first resolution attempt (matches the exact production error chain via the single-driveComputePathsfallback), verifiescreateLVretries after a rescan and returns the volume, and asserts a rescan was triggered.go build ./..., fullgo test ./...,go vet ./...andgolangci-lintall clean.