Skip to contentSkip to conversation

libnvme : record the nvme pci adapter physical slot

PATCH In review Nilay Shroff 2 participants 2 messages Mar 21, 2024 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnvme : record the nvme pci adapter physical slot

There is a subtle bug in the nvme controller physical slot lookup code due to which the readdir() prematurely aborts the lookup and hence libnvme fails to record the pci slot address of the nvme controller. This patch helps to fix this issue.

---
Hi all,

The "nvme list -v" command displays very usefule information which includes NVMe subsystem, controllers and namespaces. The output also displays the phsical slot name of the controller. However, I found that the slot information printed in the output is always empty. Further debugging, I found that there is a subtle bug in the nvme controller slot lookup code causing the observed symptom. This patch helps fix it.

Wihout the patch (slot is empty):

# nvme list -v -o json
{
  "Devices":[
    {
      "HostNQN":"nqn.2014-08.org.nvmexpress:uuid:12b49f6e-0276-4746-b10c-56815b7e6dc2",
      "Subsystems":[
        {
          "Subsystem":"nvme-subsys0",
          "SubsystemNQN":"nqn.1994-11.com.samsung:nvme:PM1735:2.5-inch:S6EUNA0R500358",
          "Controllers":[
            {
              "Controller":"nvme0",
              "Serial number":"S6EUNA0R500358",
              "Model number":"1.6TB NVMe Gen4 U.2 SSD",
              "Firmware":"REV.SN49",
              "Transport":"pcie",
              "Address":"0018:01:00.0",
              "Slot":"",
              "Namespaces":[
              ],
              "Paths":[
                {
                  "Path":"nvme0c0n1",
                  "ANAState":"optimized"
                }
              ]
            }
          ],
          "Namespaces":[
            {
              "Namespace":"nvme0n1",
              "Generic":"ng0n1",
              "NSID":1,
              "UsedBytes":1600321314816,
              "MaximumLBA":390703446,
              "PhysicalSize":1600321314816,
              "SectorSize":4096
            }
          ]
        }
      ]
    }
  ]
}

With the patch applied (slot contains the correct value):
#nvme list -v -o json
{
"Devices":[

    {
      "HostNQN":"nqn.2014-08.org.nvmexpress:uuid:12b49f6e-0276-4746-b10c-56815b7e6dc2",
      "Subsystems":[
        {
          "Subsystem":"nvme-subsys0",
          "SubsystemNQN":"nqn.1994-11.com.samsung:nvme:PM1735:2.5-inch:S6EUNA0R500358",
          "Controllers":[
            {
              "Controller":"nvme0",
              "SerialNumber":"S6EUNA0R500358",
              "ModelNumber":"1.6TB NVMe Gen4 U.2 SSD",
              "Firmware":"REV.SN49",
              "Transport":"pcie",
              "Address":"0018:01:00.0",
              "Slot":"U78D4.ND0.WZS0021-P1-C8",
              "Namespaces":[
              ],
              "Paths":[
                {
                  "Path":"nvme0c0n1",
                  "ANAState":"optimized"
                }
              ]
            }
          ],
          "Namespaces":[
            {
              "NameSpace":"nvme0n1",
              "Generic":"ng0n1",
              "NSID":1,
              "UsedBytes":1600321314816,
              "MaximumLBA":3125627568,
              "PhysicalSize":12802570518528,
              "SectorSize":4096
            }
          ]
        }
      ]
    }

]
}

Thanks,
--Nilay

---
 src/nvme/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/nvme/tree.c +1 -1
index de6ce879..584e3f6a 100644
@@ -1729,7 +1729,7 @@ static char *nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address)
 	}
 
 	target_addr = strndup(address, 10);
-	while (!(entry = readdir(slots_dir))) {
+	while ((entry = readdir(slots_dir))) {
 		if (entry->d_type == DT_DIR &&
 		    strncmp(entry->d_name, ".", 1) != 0 &&
 		    strncmp(entry->d_name, "..", 2) != 0) {
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · Nilay Shroff

There is a subtle bug in the nvme controller physical slot lookup code due to which the readdir() prematurely aborts the lookup and hence libnvme fails to record the pci slot address of the nvme controller. This patch helps to fix this issue.

Patch applied. Thanks!