From befce7ca99bb54d35a9c8113707e24ec1adba3b6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 12:36:09 +0000 Subject: [PATCH 1/2] Initial plan From 0da083436f456dfd6c561c24ebc670490caecc84 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 12:44:16 +0000 Subject: [PATCH 2/2] libnvme: fix nvme_scan_topology to handle missing NVMe sysfs dirs gracefully 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 <1050803+igaw@users.noreply.github.com> --- libnvme/src/nvme/tree.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 8cdc1321ef..90e64dce48 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -282,9 +282,14 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void * ctrls.num = nvme_scan_ctrls(&ctrls.ents); if (ctrls.num < 0) { - nvme_msg(ctx, LOG_DEBUG, "failed to scan ctrls: %s\n", - nvme_strerror(-ctrls.num)); - return ctrls.num; + int err = errno; + + if (err != ENOENT) { + nvme_msg(ctx, LOG_DEBUG, "failed to scan ctrls: %s\n", + strerror(err)); + return -err; + } + ctrls.num = 0; } for (i = 0; i < ctrls.num; i++) { @@ -300,9 +305,14 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void * subsys.num = nvme_scan_subsystems(&subsys.ents); if (subsys.num < 0) { - nvme_msg(ctx, LOG_DEBUG, "failed to scan subsystems: %s\n", - nvme_strerror(-subsys.num)); - return subsys.num; + int err = errno; + + if (err != ENOENT) { + nvme_msg(ctx, LOG_DEBUG, "failed to scan subsystems: %s\n", + strerror(err)); + return -err; + } + subsys.num = 0; } for (i = 0; i < subsys.num; i++) {