Skip to content

Commit e559398

Browse files
author
Christoph Hellwig
committed
nvme: remove nvme_alloc_request and nvme_alloc_request_qid
Just open code the allocation + initialization in the callers. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
1 parent b739e13 commit e559398

5 files changed

Lines changed: 31 additions & 46 deletions

File tree

drivers/nvme/host/core.c

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,8 @@ static inline void nvme_clear_nvme_request(struct request *req)
639639
req->rq_flags |= RQF_DONTPREP;
640640
}
641641

642-
static inline unsigned int nvme_req_op(struct nvme_command *cmd)
643-
{
644-
return nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
645-
}
646-
647-
static inline void nvme_init_request(struct request *req,
648-
struct nvme_command *cmd)
642+
/* initialize a passthrough request */
643+
void nvme_init_request(struct request *req, struct nvme_command *cmd)
649644
{
650645
if (req->q->queuedata)
651646
req->timeout = NVME_IO_TIMEOUT;
@@ -661,30 +656,7 @@ static inline void nvme_init_request(struct request *req,
661656
nvme_clear_nvme_request(req);
662657
memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd));
663658
}
664-
665-
struct request *nvme_alloc_request(struct request_queue *q,
666-
struct nvme_command *cmd, blk_mq_req_flags_t flags)
667-
{
668-
struct request *req;
669-
670-
req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
671-
if (!IS_ERR(req))
672-
nvme_init_request(req, cmd);
673-
return req;
674-
}
675-
EXPORT_SYMBOL_GPL(nvme_alloc_request);
676-
677-
static struct request *nvme_alloc_request_qid(struct request_queue *q,
678-
struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid)
679-
{
680-
struct request *req;
681-
682-
req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
683-
qid ? qid - 1 : 0);
684-
if (!IS_ERR(req))
685-
nvme_init_request(req, cmd);
686-
return req;
687-
}
659+
EXPORT_SYMBOL_GPL(nvme_init_request);
688660

689661
/*
690662
* 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,
11101082
int ret;
11111083

11121084
if (qid == NVME_QID_ANY)
1113-
req = nvme_alloc_request(q, cmd, flags);
1085+
req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
11141086
else
1115-
req = nvme_alloc_request_qid(q, cmd, flags, qid);
1087+
req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
1088+
qid ? qid - 1 : 0);
1089+
11161090
if (IS_ERR(req))
11171091
return PTR_ERR(req);
1092+
nvme_init_request(req, cmd);
11181093

11191094
if (timeout)
11201095
req->timeout = timeout;
@@ -1304,14 +1279,15 @@ static void nvme_keep_alive_work(struct work_struct *work)
13041279
return;
13051280
}
13061281

1307-
rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
1308-
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
1282+
rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd),
1283+
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
13091284
if (IS_ERR(rq)) {
13101285
/* allocation failure, reset the controller */
13111286
dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq));
13121287
nvme_reset_ctrl(ctrl);
13131288
return;
13141289
}
1290+
nvme_init_request(rq, &ctrl->ka_cmd);
13151291

13161292
rq->timeout = ctrl->kato * HZ;
13171293
rq->end_io_data = ctrl;

drivers/nvme/host/ioctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ static int nvme_submit_user_cmd(struct request_queue *q,
6666
void *meta = NULL;
6767
int ret;
6868

69-
req = nvme_alloc_request(q, cmd, 0);
69+
req = blk_mq_alloc_request(q, nvme_req_op(cmd), 0);
7070
if (IS_ERR(req))
7171
return PTR_ERR(req);
72+
nvme_init_request(req, cmd);
7273

7374
if (timeout)
7475
req->timeout = timeout;

drivers/nvme/host/nvme.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,13 @@ void nvme_wait_freeze(struct nvme_ctrl *ctrl);
698698
int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
699699
void nvme_start_freeze(struct nvme_ctrl *ctrl);
700700

701+
static inline unsigned int nvme_req_op(struct nvme_command *cmd)
702+
{
703+
return nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
704+
}
705+
701706
#define NVME_QID_ANY -1
702-
struct request *nvme_alloc_request(struct request_queue *q,
703-
struct nvme_command *cmd, blk_mq_req_flags_t flags);
707+
void nvme_init_request(struct request *req, struct nvme_command *cmd);
704708
void nvme_cleanup_cmd(struct request *req);
705709
blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req);
706710
blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,

drivers/nvme/host/pci.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,9 @@ static int nvme_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
424424
return 0;
425425
}
426426

427-
static int nvme_init_request(struct blk_mq_tag_set *set, struct request *req,
428-
unsigned int hctx_idx, unsigned int numa_node)
427+
static int nvme_pci_init_request(struct blk_mq_tag_set *set,
428+
struct request *req, unsigned int hctx_idx,
429+
unsigned int numa_node)
429430
{
430431
struct nvme_dev *dev = set->driver_data;
431432
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)
14281429
"I/O %d QID %d timeout, aborting\n",
14291430
req->tag, nvmeq->qid);
14301431

1431-
abort_req = nvme_alloc_request(dev->ctrl.admin_q, &cmd,
1432-
BLK_MQ_REQ_NOWAIT);
1432+
abort_req = blk_mq_alloc_request(dev->ctrl.admin_q, nvme_req_op(&cmd),
1433+
BLK_MQ_REQ_NOWAIT);
14331434
if (IS_ERR(abort_req)) {
14341435
atomic_inc(&dev->ctrl.abort_limit);
14351436
return BLK_EH_RESET_TIMER;
14361437
}
1438+
nvme_init_request(abort_req, &cmd);
14371439

14381440
abort_req->end_io_data = NULL;
14391441
blk_execute_rq_nowait(abort_req, false, abort_endio);
@@ -1722,7 +1724,7 @@ static const struct blk_mq_ops nvme_mq_admin_ops = {
17221724
.queue_rq = nvme_queue_rq,
17231725
.complete = nvme_pci_complete_rq,
17241726
.init_hctx = nvme_admin_init_hctx,
1725-
.init_request = nvme_init_request,
1727+
.init_request = nvme_pci_init_request,
17261728
.timeout = nvme_timeout,
17271729
};
17281730

@@ -1732,7 +1734,7 @@ static const struct blk_mq_ops nvme_mq_ops = {
17321734
.complete = nvme_pci_complete_rq,
17331735
.commit_rqs = nvme_commit_rqs,
17341736
.init_hctx = nvme_init_hctx,
1735-
.init_request = nvme_init_request,
1737+
.init_request = nvme_pci_init_request,
17361738
.map_queues = nvme_pci_map_queues,
17371739
.timeout = nvme_timeout,
17381740
.poll = nvme_poll,
@@ -2475,9 +2477,10 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode)
24752477
cmd.delete_queue.opcode = opcode;
24762478
cmd.delete_queue.qid = cpu_to_le16(nvmeq->qid);
24772479

2478-
req = nvme_alloc_request(q, &cmd, BLK_MQ_REQ_NOWAIT);
2480+
req = blk_mq_alloc_request(q, nvme_req_op(&cmd), BLK_MQ_REQ_NOWAIT);
24792481
if (IS_ERR(req))
24802482
return PTR_ERR(req);
2483+
nvme_init_request(req, &cmd);
24812484

24822485
req->end_io_data = nvmeq;
24832486

drivers/nvme/target/passthru.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,12 @@ static void nvmet_passthru_execute_cmd(struct nvmet_req *req)
254254
timeout = nvmet_req_subsys(req)->admin_timeout;
255255
}
256256

257-
rq = nvme_alloc_request(q, req->cmd, 0);
257+
rq = blk_mq_alloc_request(q, nvme_req_op(req->cmd), 0);
258258
if (IS_ERR(rq)) {
259259
status = NVME_SC_INTERNAL;
260260
goto out_put_ns;
261261
}
262+
nvme_init_request(rq, req->cmd);
262263

263264
if (timeout)
264265
rq->timeout = timeout;

0 commit comments

Comments
 (0)