[PATCH V6 5/5] nvme: centralize setting req end_io_data
Chaitanya Kulkarni
chaitanya.kulkarni at wdc.com
Wed Nov 4 15:37:36 EST 2020
The host side code allocates the request in several places using
nvme_alloc_request() and initialises the allocated request->end_io_data,
which repeats the code and will have duplicate code in the future.
Add an end_io_data request parameter which initializes the block
layer request in nvme_alloc_request(), update the respective callers
and remove the duplicate code.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
drivers/nvme/host/core.c | 12 ++++++------
drivers/nvme/host/lightnvm.c | 4 ++--
drivers/nvme/host/nvme.h | 2 +-
drivers/nvme/host/pci.c | 8 +++-----
drivers/nvme/target/passthru.c | 2 +-
5 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 29d9b5bb29b2..8bebfd64a69b 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -528,7 +528,7 @@ static inline void nvme_req_set_default_timeout(struct request *req)
struct request *nvme_alloc_request(struct request_queue *q,
struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid,
- unsigned int timeout)
+ unsigned int timeout, void *end_io_data)
{
unsigned op = nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
struct request *req;
@@ -547,6 +547,7 @@ struct request *nvme_alloc_request(struct request_queue *q,
else
nvme_req_set_default_timeout(req);
+ req->end_io_data = end_io_data;
req->cmd_flags |= REQ_FAILFAST_DRIVER;
nvme_clear_nvme_request(req);
nvme_req(req)->cmd = cmd;
@@ -911,7 +912,7 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
struct request *req;
int ret;
- req = nvme_alloc_request(q, cmd, flags, qid, timeout);
+ req = nvme_alloc_request(q, cmd, flags, qid, timeout, NULL);
if (IS_ERR(req))
return PTR_ERR(req);
@@ -1079,7 +1080,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
void *meta = NULL;
int ret;
- req = nvme_alloc_request(q, cmd, 0, NVME_QID_ANY, timeout);
+ req = nvme_alloc_request(q, cmd, 0, NVME_QID_ANY, timeout, NULL);
if (IS_ERR(req))
return PTR_ERR(req);
@@ -1153,12 +1154,11 @@ static int nvme_keep_alive(struct nvme_ctrl *ctrl)
struct request *rq;
rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
- BLK_MQ_REQ_RESERVED, NVME_QID_ANY, ctrl->kato * HZ);
+ BLK_MQ_REQ_RESERVED, NVME_QID_ANY, ctrl->kato * HZ,
+ ctrl);
if (IS_ERR(rq))
return PTR_ERR(rq);
- rq->end_io_data = ctrl;
-
blk_execute_rq_nowait(rq->q, NULL, rq, 0, nvme_keep_alive_end_io);
return 0;
diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index eabcbdd3a556..837c5e5ce3b3 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -654,7 +654,7 @@ static struct request *nvme_nvm_alloc_request(struct request_queue *q,
nvme_nvm_rqtocmd(rqd, ns, cmd);
rq = nvme_alloc_request(q, (struct nvme_command *)cmd, 0, NVME_QID_ANY,
- 0);
+ 0, NULL);
if (IS_ERR(rq))
return rq;
@@ -769,7 +769,7 @@ static int nvme_nvm_submit_user_cmd(struct request_queue *q,
int ret = 0;
rq = nvme_alloc_request(q, (struct nvme_command *)vcmd, 0, NVME_QID_ANY,
- timeout);
+ timeout, NULL);
if (IS_ERR(rq)) {
ret = -ENOMEM;
goto err_cmd;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 78f0ac0fb39b..8076b5147f3e 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -611,7 +611,7 @@ void nvme_start_freeze(struct nvme_ctrl *ctrl);
#define NVME_QID_ANY -1
struct request *nvme_alloc_request(struct request_queue *q,
struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid,
- unsigned int timeout);
+ unsigned int timeout, void *end_io_data);
void nvme_cleanup_cmd(struct request *req);
blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
struct nvme_command *cmd);
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 6089660b2a24..33a920b93601 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1304,13 +1304,13 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
req->tag, nvmeq->qid);
abort_req = nvme_alloc_request(dev->ctrl.admin_q, &cmd,
- BLK_MQ_REQ_NOWAIT, NVME_QID_ANY, NVME_ADMIN_TIMEOUT);
+ BLK_MQ_REQ_NOWAIT, NVME_QID_ANY, NVME_ADMIN_TIMEOUT,
+ NULL);
if (IS_ERR(abort_req)) {
atomic_inc(&dev->ctrl.abort_limit);
return BLK_EH_RESET_TIMER;
}
- abort_req->end_io_data = NULL;
blk_execute_rq_nowait(abort_req->q, NULL, abort_req, 0, abort_endio);
/*
@@ -2219,12 +2219,10 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode)
cmd.delete_queue.qid = cpu_to_le16(nvmeq->qid);
req = nvme_alloc_request(q, &cmd, BLK_MQ_REQ_NOWAIT, NVME_QID_ANY,
- NVME_ADMIN_TIMEOUT);
+ NVME_ADMIN_TIMEOUT, nvmeq);
if (IS_ERR(req))
return PTR_ERR(req);
- req->end_io_data = nvmeq;
-
init_completion(&nvmeq->delete_done);
blk_execute_rq_nowait(q, NULL, req, false,
opcode == nvme_admin_delete_cq ?
diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
index d099f288d296..6b76087ca421 100644
--- a/drivers/nvme/target/passthru.c
+++ b/drivers/nvme/target/passthru.c
@@ -254,7 +254,7 @@ static void nvmet_passthru_execute_cmd(struct nvmet_req *req)
}
rq = nvme_alloc_request(q, req->cmd, 0, NVME_QID_ANY,
- nvmet_passthru_req_timeout(req, q));
+ nvmet_passthru_req_timeout(req, q), NULL);
if (IS_ERR(rq)) {
status = NVME_SC_INTERNAL;
goto out_put_ns;
--
2.22.1
More information about the Linux-nvme
mailing list