Commit e559398f authored by Christoph Hellwig's avatar Christoph Hellwig

nvme: remove nvme_alloc_request and nvme_alloc_request_qid

Just open code the allocation + initialization in the callers.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarKeith Busch <kbusch@kernel.org>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
parent b739e137
...@@ -639,13 +639,8 @@ static inline void nvme_clear_nvme_request(struct request *req) ...@@ -639,13 +639,8 @@ static inline void nvme_clear_nvme_request(struct request *req)
req->rq_flags |= RQF_DONTPREP; req->rq_flags |= RQF_DONTPREP;
} }
static inline unsigned int nvme_req_op(struct nvme_command *cmd) /* initialize a passthrough request */
{ void nvme_init_request(struct request *req, struct nvme_command *cmd)
return nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
}
static inline void nvme_init_request(struct request *req,
struct nvme_command *cmd)
{ {
if (req->q->queuedata) if (req->q->queuedata)
req->timeout = NVME_IO_TIMEOUT; req->timeout = NVME_IO_TIMEOUT;
...@@ -661,30 +656,7 @@ static inline void nvme_init_request(struct request *req, ...@@ -661,30 +656,7 @@ static inline void nvme_init_request(struct request *req,
nvme_clear_nvme_request(req); nvme_clear_nvme_request(req);
memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd)); memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd));
} }
EXPORT_SYMBOL_GPL(nvme_init_request);
struct request *nvme_alloc_request(struct request_queue *q,
struct nvme_command *cmd, blk_mq_req_flags_t flags)
{
struct request *req;
req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
if (!IS_ERR(req))
nvme_init_request(req, cmd);
return req;
}
EXPORT_SYMBOL_GPL(nvme_alloc_request);
static struct request *nvme_alloc_request_qid(struct request_queue *q,
struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid)
{
struct request *req;
req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
qid ? qid - 1 : 0);
if (!IS_ERR(req))
nvme_init_request(req, cmd);
return req;
}
/* /*
* For something we're not in a state to send to the device the default action * For something we're not in a state to send to the device the default action
...@@ -1110,11 +1082,14 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, ...@@ -1110,11 +1082,14 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
int ret; int ret;
if (qid == NVME_QID_ANY) if (qid == NVME_QID_ANY)
req = nvme_alloc_request(q, cmd, flags); req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
else else
req = nvme_alloc_request_qid(q, cmd, flags, qid); req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
qid ? qid - 1 : 0);
if (IS_ERR(req)) if (IS_ERR(req))
return PTR_ERR(req); return PTR_ERR(req);
nvme_init_request(req, cmd);
if (timeout) if (timeout)
req->timeout = timeout; req->timeout = timeout;
...@@ -1304,14 +1279,15 @@ static void nvme_keep_alive_work(struct work_struct *work) ...@@ -1304,14 +1279,15 @@ static void nvme_keep_alive_work(struct work_struct *work)
return; return;
} }
rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd, rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd),
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT); BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
/* allocation failure, reset the controller */ /* allocation failure, reset the controller */
dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq)); dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq));
nvme_reset_ctrl(ctrl); nvme_reset_ctrl(ctrl);
return; return;
} }
nvme_init_request(rq, &ctrl->ka_cmd);
rq->timeout = ctrl->kato * HZ; rq->timeout = ctrl->kato * HZ;
rq->end_io_data = ctrl; rq->end_io_data = ctrl;
......
...@@ -66,9 +66,10 @@ static int nvme_submit_user_cmd(struct request_queue *q, ...@@ -66,9 +66,10 @@ static int nvme_submit_user_cmd(struct request_queue *q,
void *meta = NULL; void *meta = NULL;
int ret; int ret;
req = nvme_alloc_request(q, cmd, 0); req = blk_mq_alloc_request(q, nvme_req_op(cmd), 0);
if (IS_ERR(req)) if (IS_ERR(req))
return PTR_ERR(req); return PTR_ERR(req);
nvme_init_request(req, cmd);
if (timeout) if (timeout)
req->timeout = timeout; req->timeout = timeout;
......
...@@ -698,9 +698,13 @@ void nvme_wait_freeze(struct nvme_ctrl *ctrl); ...@@ -698,9 +698,13 @@ void nvme_wait_freeze(struct nvme_ctrl *ctrl);
int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout); int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
void nvme_start_freeze(struct nvme_ctrl *ctrl); void nvme_start_freeze(struct nvme_ctrl *ctrl);
static inline unsigned int nvme_req_op(struct nvme_command *cmd)
{
return nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
}
#define NVME_QID_ANY -1 #define NVME_QID_ANY -1
struct request *nvme_alloc_request(struct request_queue *q, void nvme_init_request(struct request *req, struct nvme_command *cmd);
struct nvme_command *cmd, blk_mq_req_flags_t flags);
void nvme_cleanup_cmd(struct request *req); void nvme_cleanup_cmd(struct request *req);
blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req); blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req);
blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl, blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,
......
...@@ -424,8 +424,9 @@ static int nvme_init_hctx(struct blk_mq_hw_ctx *hctx, void *data, ...@@ -424,8 +424,9 @@ static int nvme_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
return 0; return 0;
} }
static int nvme_init_request(struct blk_mq_tag_set *set, struct request *req, static int nvme_pci_init_request(struct blk_mq_tag_set *set,
unsigned int hctx_idx, unsigned int numa_node) struct request *req, unsigned int hctx_idx,
unsigned int numa_node)
{ {
struct nvme_dev *dev = set->driver_data; struct nvme_dev *dev = set->driver_data;
struct nvme_iod *iod = blk_mq_rq_to_pdu(req); struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
...@@ -1428,12 +1429,13 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) ...@@ -1428,12 +1429,13 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
"I/O %d QID %d timeout, aborting\n", "I/O %d QID %d timeout, aborting\n",
req->tag, nvmeq->qid); req->tag, nvmeq->qid);
abort_req = nvme_alloc_request(dev->ctrl.admin_q, &cmd, abort_req = blk_mq_alloc_request(dev->ctrl.admin_q, nvme_req_op(&cmd),
BLK_MQ_REQ_NOWAIT); BLK_MQ_REQ_NOWAIT);
if (IS_ERR(abort_req)) { if (IS_ERR(abort_req)) {
atomic_inc(&dev->ctrl.abort_limit); atomic_inc(&dev->ctrl.abort_limit);
return BLK_EH_RESET_TIMER; return BLK_EH_RESET_TIMER;
} }
nvme_init_request(abort_req, &cmd);
abort_req->end_io_data = NULL; abort_req->end_io_data = NULL;
blk_execute_rq_nowait(abort_req, false, abort_endio); blk_execute_rq_nowait(abort_req, false, abort_endio);
...@@ -1722,7 +1724,7 @@ static const struct blk_mq_ops nvme_mq_admin_ops = { ...@@ -1722,7 +1724,7 @@ static const struct blk_mq_ops nvme_mq_admin_ops = {
.queue_rq = nvme_queue_rq, .queue_rq = nvme_queue_rq,
.complete = nvme_pci_complete_rq, .complete = nvme_pci_complete_rq,
.init_hctx = nvme_admin_init_hctx, .init_hctx = nvme_admin_init_hctx,
.init_request = nvme_init_request, .init_request = nvme_pci_init_request,
.timeout = nvme_timeout, .timeout = nvme_timeout,
}; };
...@@ -1732,7 +1734,7 @@ static const struct blk_mq_ops nvme_mq_ops = { ...@@ -1732,7 +1734,7 @@ static const struct blk_mq_ops nvme_mq_ops = {
.complete = nvme_pci_complete_rq, .complete = nvme_pci_complete_rq,
.commit_rqs = nvme_commit_rqs, .commit_rqs = nvme_commit_rqs,
.init_hctx = nvme_init_hctx, .init_hctx = nvme_init_hctx,
.init_request = nvme_init_request, .init_request = nvme_pci_init_request,
.map_queues = nvme_pci_map_queues, .map_queues = nvme_pci_map_queues,
.timeout = nvme_timeout, .timeout = nvme_timeout,
.poll = nvme_poll, .poll = nvme_poll,
...@@ -2475,9 +2477,10 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode) ...@@ -2475,9 +2477,10 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode)
cmd.delete_queue.opcode = opcode; cmd.delete_queue.opcode = opcode;
cmd.delete_queue.qid = cpu_to_le16(nvmeq->qid); cmd.delete_queue.qid = cpu_to_le16(nvmeq->qid);
req = nvme_alloc_request(q, &cmd, BLK_MQ_REQ_NOWAIT); req = blk_mq_alloc_request(q, nvme_req_op(&cmd), BLK_MQ_REQ_NOWAIT);
if (IS_ERR(req)) if (IS_ERR(req))
return PTR_ERR(req); return PTR_ERR(req);
nvme_init_request(req, &cmd);
req->end_io_data = nvmeq; req->end_io_data = nvmeq;
......
...@@ -254,11 +254,12 @@ static void nvmet_passthru_execute_cmd(struct nvmet_req *req) ...@@ -254,11 +254,12 @@ static void nvmet_passthru_execute_cmd(struct nvmet_req *req)
timeout = nvmet_req_subsys(req)->admin_timeout; timeout = nvmet_req_subsys(req)->admin_timeout;
} }
rq = nvme_alloc_request(q, req->cmd, 0); rq = blk_mq_alloc_request(q, nvme_req_op(req->cmd), 0);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
status = NVME_SC_INTERNAL; status = NVME_SC_INTERNAL;
goto out_put_ns; goto out_put_ns;
} }
nvme_init_request(rq, req->cmd);
if (timeout) if (timeout)
rq->timeout = timeout; rq->timeout = timeout;
......
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