Skip to content

fix(block/darwin): don't fail on ambiguous ioreg node matches - #475

Merged
jaypipes merged 1 commit into
jaypipes:mainfrom
mdevils:fix/darwin-ioreg-ambiguous-match
Sep 26, 2026
Merged

jaypipes merged 1 commit into
jaypipes:mainfrom
mdevils:fix/darwin-ioreg-ambiguous-match

Conversation

@mdevils

@mdevils mdevils commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

getIoregPlist looks up an ioreg node by base name (ioreg -n <name>) and errored if that returned anything other than exactly one match. Node names aren't guaranteed unique across the device tree, so this failed whenever two devices shared a name.

Observed reliably in a macOS virtualization environment (GitHub Actions' macOS runners), where block storage shows up as multiple AppleVirtIOStorageDevice nodes:

get block devices: ioreg unmarshal resulted in 2 I/O device tree nodes for path
"IODeviceTree:/arm-io/pcie@30000000/pci106b,1a00@5/AppleVirtIOStorageDevice" (expected 1)

The same failure mode is reachable on real hardware too (e.g. two identically-named Thunderbolt NVMe enclosures), just less commonly hit.

Fix

Rather than guessing (e.g. taking the first match), this resolves the ambiguity properly:

  1. Walk the IODeviceTree registry plane, following the known full path (DeviceTreePath, e.g. arm-io@10F00000/ans@77400000/...), to find the exact target node and its IORegistryEntryID.
  2. IORegistryEntryID is a property of the underlying kernel object, so it's identical no matter which registry plane the object is viewed through (verified against real hardware: the same ID shows up whether queried via -p IODeviceTree or the default plane).
  3. Use that ID to pick the correct entry out of the (possibly ambiguous) name-based match, instead of the first/arbitrary one.

Device tree path segments are reconstructed as IORegistryEntryName + @ + IORegistryEntryLocation (Open Firmware "name@unit-address" convention), which matches DeviceTreePath's format exactly.

Also handles disks with no real device tree entry (synthesized/virtual volumes reporting DeviceTreePath: "IODeviceTree:/") by skipping them, matching the original behavior for that case.

Test plan

  • Added TestFindEntryID, which builds a tree with two identically-named nodes at different paths and confirms each resolves to its own distinct, correct IORegistryEntryID -- directly reproducing the ambiguity that broke CI.
  • go build ./..., go vet ./pkg/block/..., existing TestStorageControllerFromPlist still passes.
  • Manually verified ghw.Block() against real hardware (M-series MacBook Pro): all fields (including Vendor, previously always empty due to a decode-target mismatch) come back identical to before this change.

getIoregPlist matches ioreg nodes by base name only, not full device
tree path, and errored whenever more than one node shared a name.
This is reachable on real hardware (e.g. two identically-named
Thunderbolt NVMe enclosures) and observed reliably under macOS
virtualization, where storage shows up as multiple
AppleVirtIOStorageDevice nodes.

Fix by walking the IODeviceTree registry plane by the known full
path to find the target node's IORegistryEntryID -- a property of
the underlying kernel object, so it's the same no matter which
plane it's viewed through -- then using that ID to pick the correct
candidate out of the (possibly ambiguous) name-based match, instead
of guessing.

Signed-off-by: Marat Dulin <github-commit@maratd.com>
@mdevils
mdevils force-pushed the fix/darwin-ioreg-ambiguous-match branch from 2aac5c2 to 69ce5aa Compare September 23, 2026 08:43

@jaypipes jaypipes left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Awesome, thank you for the great contribution @mdevils :) Appreciated!

@jaypipes
jaypipes merged commit 72c0c98 into jaypipes:main Sep 26, 2026
15 checks passed
joshuar pushed a commit to joshuar/go-hass-agent that referenced this pull request Sep 26, 2026
Picks up jaypipes/ghw#475, which #960 was waiting on. Without it
test-macos fails on GitHub's runners with an ambiguous ioreg match.
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