Skip to content

Commit f783f44

Browse files
lsgunthChristoph Hellwig
authored andcommitted
nvme: introduce nvme_ctrl_get_by_path()
nvme_ctrl_get_by_path() is analogous to blkdev_get_by_path() except it gets a struct nvme_ctrl from the path to its char dev (/dev/nvme0). It makes use of filp_open() to open the file and uses the private data to obtain a pointer to the struct nvme_ctrl. If the fops of the file do not match, -EINVAL is returned. The purpose of this function is to support NVMe-OF target passthru and is exported under the NVME_TARGET_PASSTHRU namespace. Signed-off-by: Logan Gunthorpe <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Max Gurtovoy <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 17365ae commit f783f44

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

drivers/nvme/host/core.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4590,6 +4590,29 @@ void nvme_sync_queues(struct nvme_ctrl *ctrl)
45904590
}
45914591
EXPORT_SYMBOL_GPL(nvme_sync_queues);
45924592

4593+
struct nvme_ctrl *nvme_ctrl_get_by_path(const char *path)
4594+
{
4595+
struct nvme_ctrl *ctrl;
4596+
struct file *f;
4597+
4598+
f = filp_open(path, O_RDWR, 0);
4599+
if (IS_ERR(f))
4600+
return ERR_CAST(f);
4601+
4602+
if (f->f_op != &nvme_dev_fops) {
4603+
ctrl = ERR_PTR(-EINVAL);
4604+
goto out_close;
4605+
}
4606+
4607+
ctrl = f->private_data;
4608+
nvme_get_ctrl(ctrl);
4609+
4610+
out_close:
4611+
filp_close(f, NULL);
4612+
return ctrl;
4613+
}
4614+
EXPORT_SYMBOL_NS_GPL(nvme_ctrl_get_by_path, NVME_TARGET_PASSTHRU);
4615+
45934616
/*
45944617
* Check we didn't inadvertently grow the command structure sizes:
45954618
*/

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,5 +793,6 @@ static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { }
793793
u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
794794
u8 opcode);
795795
void nvme_execute_passthru_rq(struct request *rq);
796+
struct nvme_ctrl *nvme_ctrl_get_by_path(const char *path);
796797

797798
#endif /* _NVME_H */

0 commit comments

Comments
 (0)