libnvme: fix nvme_scan_topology() treating missing NVMe sysfs dirs as fatal#3153
Closed
libnvme: fix nvme_scan_topology() treating missing NVMe sysfs dirs as fatal#3153
Conversation
…cefully When no NVMe devices are present, /sys/class/nvme and /sys/class/nvme-subsystem directories may not exist. scandir() returns -1 with errno=ENOENT in this case. Previously, nvme_scan_topology() treated this as a fatal error, causing nvme_scan() to fail and the Python global_ctx() constructor to return NULL. Fix: treat ENOENT from scandir as "no devices found" (0 entries) rather than an error. Only treat other errno values as actual failures. Also fix error messages to use strerror(errno) instead of nvme_strerror(-ctrls.num) which was computing the wrong error code. This fixes the python-create-ctrl-object and python-sigsegv-during-gc tests that fail when no NVMe devices are present in the test environment. Co-authored-by: igaw <[email protected]>
Copilot
AI
changed the title
[WIP] Fix nvme-cli test failure in create-ctrl-object
libnvme: fix nvme_scan_topology() treating missing NVMe sysfs dirs as fatal
Mar 10, 2026
Collaborator
|
Proper fix is #3156 |
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.
nvme_scan_topology()failed when/sys/class/nvmeor/sys/class/nvme-subsystemdidn't exist (i.e., no NVMe devices present), causingnvme_scan()to propagate the error and the Pythonglobal_ctx()constructor to returnNULL— breaking thepython-create-ctrl-objectandpython-sigsegv-during-gctests.Root cause
nvme_scan_ctrls()andnvme_scan_subsystems()wrapscandir(), which returns-1witherrno=ENOENTwhen the target directory doesn't exist. The prior code unconditionally treated any negative return as fatal:Fix
errnoimmediately after each failingscandircallENOENTas zero entries — a missing sysfs directory is a valid "no devices" state, not an errorerrnovaluesstrerror(err)instead ofnvme_strerror(-ctrls.num)which was deriving a nonsensical error code✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.