Skip to content

Commit 23e512a

Browse files
committed
nvme: update invalid device handling for list-subsys
The list-subsys command fails to error out if one passes an invalid or non-existent ns device as part of the <device> option. One would have ideally expected the nvme_match_device_filter() to catch this, but such cases would be better handled with a simple stat check for ns device validity before proceeding to the filter in the first place. That way, the stat check can take care of ns device validity whereas the filter can focus on filtering the subsystems and controllers, ignoring checking for invalid ns devices, as logically expected in a list subsystems command. Signed-off-by: Martin George <[email protected]>
1 parent cba763f commit 23e512a

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

nvme.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,11 +3460,22 @@ static int list_subsys(int argc, char **argv, struct command *cmd,
34603460

34613461
if (devname) {
34623462
int subsys_num;
3463-
3464-
if (sscanf(devname, "nvme%dn%d", &subsys_num, &nsid) != 2) {
3465-
nvme_show_error("Invalid device name %s", devname);
3463+
struct stat st;
3464+
char path[512];
3465+
3466+
sprintf(path, "/dev/%s", devname);
3467+
if (stat(path, &st) == 0) {
3468+
if (sscanf(devname, "nvme%dn%d",
3469+
&subsys_num, &nsid) != 2) {
3470+
nvme_show_error("Invalid device name %s",
3471+
devname);
3472+
return -EINVAL;
3473+
}
3474+
} else {
3475+
nvme_show_error("%s does not exist", path);
34663476
return -EINVAL;
34673477
}
3478+
34683479
filter = nvme_match_device_filter;
34693480
}
34703481

0 commit comments

Comments
 (0)