Skip to content

Commit 3422bdc

Browse files
ikegami-tigaw
authored andcommitted
nvme: check chardev for resets and rescan
Also change nvme_verify_chr() to return -EINVAL from -ENOTBLK. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent a241c19 commit 3422bdc

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

libnvme/src/nvme/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int nvme_verify_chr(struct nvme_transport_handle *hdl)
3838
return -errno;
3939

4040
if (!S_ISCHR(nvme_stat.st_mode))
41-
return -ENOTBLK;
41+
return -EINVAL;
4242
return 0;
4343
}
4444

nvme.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5349,6 +5349,11 @@ static int subsystem_reset(int argc, char **argv, struct command *acmd, struct p
53495349
if (err)
53505350
return err;
53515351

5352+
if (!nvme_transport_handle_is_chardev(hdl)) {
5353+
nvme_show_error("Only character device is allowed");
5354+
return -EINVAL;
5355+
}
5356+
53525357
err = nvme_subsystem_reset(hdl);
53535358
if (err < 0) {
53545359
if (errno == ENOTTY)
@@ -5375,6 +5380,11 @@ static int reset(int argc, char **argv, struct command *acmd, struct plugin *plu
53755380
if (err)
53765381
return err;
53775382

5383+
if (!nvme_transport_handle_is_chardev(hdl)) {
5384+
nvme_show_error("Only character device is allowed");
5385+
return -EINVAL;
5386+
}
5387+
53785388
err = nvme_ctrl_reset(hdl);
53795389
if (err < 0)
53805390
nvme_show_error("Reset: %s", nvme_strerror(err));
@@ -5399,6 +5409,11 @@ static int ns_rescan(int argc, char **argv, struct command *acmd, struct plugin
53995409
if (err)
54005410
return err;
54015411

5412+
if (!nvme_transport_handle_is_chardev(hdl)) {
5413+
nvme_show_error("Only character device is allowed");
5414+
return -EINVAL;
5415+
}
5416+
54025417
err = validate_output_format(nvme_cfg.output_format, &flags);
54035418
if (err < 0) {
54045419
nvme_show_error("Invalid output format");

0 commit comments

Comments
 (0)