Skip to content

Commit

Permalink
Fix parsing for nvme-subsystem devices
Browse files Browse the repository at this point in the history
nvme-subsystem devices have a link that looks like:
  ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1

However, the current code expects an additional /nvme0/ component, i.e.:
  ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0/nvme0n1

Fix this by adding a seprate branch for parsing nvme-subsystem devices.

Resolves github issue #157.

Signed-off-by: dann frazier <dann.frazier@canonical.com>
  • Loading branch information
dannf committed Aug 17, 2020
1 parent 36297ad commit 1d76781
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/linux-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static ssize_t
parse_nvme(struct device *dev, const char *path, const char *root UNUSED)
{
const char *current = path;
int rc;
int i, rc;
int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition;
uint8_t *filebuf = NULL;
int pos0 = -1, pos1 = -1, pos2 = -1;
Expand All @@ -64,7 +64,7 @@ parse_nvme(struct device *dev, const char *path, const char *root UNUSED)
/*
* in this case, *any* of these is okay.
*/
for (int i = 0; subdirs[i].name; i++) {
for (i = 0; subdirs[i].name; i++) {
debug("searching for %s", subdirs[i].name);
pos0 = tosser0 = pos1 = -1;
rc = sscanf(current, subdirs[i].fmt, &pos0, &pos1, &pos2);
Expand All @@ -77,19 +77,32 @@ parse_nvme(struct device *dev, const char *path, const char *root UNUSED)
}
}

debug("searching for nvme0/nvme0n1 or nvme0/nvme0n1/nvme0n1p1");
rc = sscanf(current, "%nnvme%d/nvme%dn%d%n/nvme%dn%dp%d%n",
&pos0, &tosser0, &ctrl_id, &ns_id, &pos1,
&tosser1, &tosser2, &partition, &pos2);
debug("current:'%s' rc:%d pos0:%d pos1:%d pos2:%d\n", current, rc, pos0, pos1, pos2);
dbgmk(" ", pos0, MAX(pos1,pos2));
/*
* If it isn't of that form, it's not one of our nvme devices.
*/
if (rc != 3 && rc != 6)
return 0;
if (rc == 3)
pos2 = pos1;
if (!subdirs[i].name)
return 0;

if (!strncmp("nvme-subsysN/", subdirs[i].name, 13)) {
debug("searching for nvme0n1");
rc = sscanf(current, "%nnvme%dn%d%n",
&pos0, &ctrl_id, &ns_id, &pos1);
debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
dbgmk(" ", pos0, pos1);
if (rc != 2)
return 0;
} else {
debug("searching for nvme0/nvme0n1 or nvme0/nvme0n1/nvme0n1p1");
rc = sscanf(current, "%nnvme%d/nvme%dn%d%n/nvme%dn%dp%d%n",
&pos0, &tosser0, &ctrl_id, &ns_id, &pos1,
&tosser1, &tosser2, &partition, &pos2);
debug("current:'%s' rc:%d pos0:%d pos1:%d pos2:%d\n", current, rc, pos0, pos1, pos2);
dbgmk(" ", pos0, MAX(pos1,pos2));
/*
* If it isn't of that form, it's not one of our nvme devices.
*/
if (rc != 3 && rc != 6)
return 0;
if (rc == 3)
pos2 = pos1;
}

dev->nvme_info.ctrl_id = ctrl_id;
dev->nvme_info.ns_id = ns_id;
Expand Down

0 comments on commit 1d76781

Please sign in to comment.