Skip to content

Commit 31b3f02

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 31b3f02

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

nvme.c

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

34613461
if (devname) {
34623462
int subsys_num;
3463+
struct stat st;
3464+
char path[512];
3465+
3466+
sprintf(path, "/dev/%s", devname);
3467+
if (stat(path, &st) != 0) {
3468+
nvme_show_error("%s does not exist", path);
3469+
return -EINVAL;
3470+
}
34633471

34643472
if (sscanf(devname, "nvme%dn%d", &subsys_num, &nsid) != 2) {
34653473
nvme_show_error("Invalid device name %s", devname);

0 commit comments

Comments
 (0)