Commit b2702aaa authored by Chaitanya Kulkarni's avatar Chaitanya Kulkarni Committed by Christoph Hellwig

nvme: lift the file open code from nvme_ctrl_get_by_path

Lift opening the file open/close code from nvme_ctrl_get_by_path into
the caller, just keeping a simple nvme_ctrl_from_file() helper.
Signed-off-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
[hch: refactored a bit, split the bug fixes into a separate prep patch]
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarLogan Gunthorpe <logang@deltatee.com>
parent 163090c1
...@@ -4668,28 +4668,13 @@ void nvme_sync_queues(struct nvme_ctrl *ctrl) ...@@ -4668,28 +4668,13 @@ void nvme_sync_queues(struct nvme_ctrl *ctrl)
} }
EXPORT_SYMBOL_GPL(nvme_sync_queues); EXPORT_SYMBOL_GPL(nvme_sync_queues);
struct nvme_ctrl *nvme_ctrl_get_by_path(const char *path) struct nvme_ctrl *nvme_ctrl_from_file(struct file *file)
{ {
struct nvme_ctrl *ctrl; if (file->f_op != &nvme_dev_fops)
struct file *f; return NULL;
return file->private_data;
f = filp_open(path, O_RDWR, 0);
if (IS_ERR(f))
return ERR_CAST(f);
if (f->f_op != &nvme_dev_fops) {
ctrl = ERR_PTR(-EINVAL);
goto out_close;
}
ctrl = f->private_data;
nvme_get_ctrl(ctrl);
out_close:
filp_close(f, NULL);
return ctrl;
} }
EXPORT_SYMBOL_NS_GPL(nvme_ctrl_get_by_path, NVME_TARGET_PASSTHRU); EXPORT_SYMBOL_NS_GPL(nvme_ctrl_from_file, NVME_TARGET_PASSTHRU);
/* /*
* Check we didn't inadvertently grow the command structure sizes: * Check we didn't inadvertently grow the command structure sizes:
......
...@@ -822,7 +822,7 @@ static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { } ...@@ -822,7 +822,7 @@ static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { }
u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
u8 opcode); u8 opcode);
void nvme_execute_passthru_rq(struct request *rq); void nvme_execute_passthru_rq(struct request *rq);
struct nvme_ctrl *nvme_ctrl_get_by_path(const char *path); struct nvme_ctrl *nvme_ctrl_from_file(struct file *file);
struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid); struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid);
void nvme_put_ns(struct nvme_ns *ns); void nvme_put_ns(struct nvme_ns *ns);
......
...@@ -474,6 +474,7 @@ u16 nvmet_parse_passthru_admin_cmd(struct nvmet_req *req) ...@@ -474,6 +474,7 @@ u16 nvmet_parse_passthru_admin_cmd(struct nvmet_req *req)
int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys) int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys)
{ {
struct nvme_ctrl *ctrl; struct nvme_ctrl *ctrl;
struct file *file;
int ret = -EINVAL; int ret = -EINVAL;
void *old; void *old;
...@@ -488,24 +489,29 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys) ...@@ -488,24 +489,29 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys)
goto out_unlock; goto out_unlock;
} }
ctrl = nvme_ctrl_get_by_path(subsys->passthru_ctrl_path); file = filp_open(subsys->passthru_ctrl_path, O_RDWR, 0);
if (IS_ERR(ctrl)) { if (IS_ERR(file)) {
ret = PTR_ERR(ctrl); ret = PTR_ERR(file);
goto out_unlock;
}
ctrl = nvme_ctrl_from_file(file);
if (!ctrl) {
pr_err("failed to open nvme controller %s\n", pr_err("failed to open nvme controller %s\n",
subsys->passthru_ctrl_path); subsys->passthru_ctrl_path);
goto out_unlock; goto out_put_file;
} }
old = xa_cmpxchg(&passthru_subsystems, ctrl->cntlid, NULL, old = xa_cmpxchg(&passthru_subsystems, ctrl->cntlid, NULL,
subsys, GFP_KERNEL); subsys, GFP_KERNEL);
if (xa_is_err(old)) { if (xa_is_err(old)) {
ret = xa_err(old); ret = xa_err(old);
goto out_put_ctrl; goto out_put_file;
} }
if (old) if (old)
goto out_put_ctrl; goto out_put_file;
subsys->passthru_ctrl = ctrl; subsys->passthru_ctrl = ctrl;
subsys->ver = ctrl->vs; subsys->ver = ctrl->vs;
...@@ -516,13 +522,12 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys) ...@@ -516,13 +522,12 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys)
NVME_TERTIARY(subsys->ver)); NVME_TERTIARY(subsys->ver));
subsys->ver = NVME_VS(1, 2, 1); subsys->ver = NVME_VS(1, 2, 1);
} }
nvme_get_ctrl(ctrl);
__module_get(subsys->passthru_ctrl->ops->module); __module_get(subsys->passthru_ctrl->ops->module);
mutex_unlock(&subsys->lock); ret = 0;
return 0;
out_put_ctrl: out_put_file:
nvme_put_ctrl(ctrl); filp_close(file, NULL);
out_unlock: out_unlock:
mutex_unlock(&subsys->lock); mutex_unlock(&subsys->lock);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment