Skip to content

Commit f4b9e6c

Browse files
keithbuschChristoph Hellwig
authored andcommitted
nvme: use driver pdu command for passthrough
All nvme transport drivers preallocate an nvme command for each request. Assume to use that command for nvme_setup_cmd() instead of requiring drivers pass a pointer to it. All nvme drivers must initialize the generic nvme_request 'cmd' to point to the transport's preallocated nvme_command. The generic nvme_request cmd pointer had previously been used only as a temporary copy for passthrough commands. Since it now points to the command that gets dispatched, passthrough commands must directly set it up prior to executing the request. Signed-off-by: Keith Busch <[email protected]> Reviewed-by: Jens Axboe <[email protected]> Reviewed-by: Himanshu Madhani <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent af7fae8 commit f4b9e6c

File tree

7 files changed

+25
-23
lines changed

7 files changed

+25
-23
lines changed

drivers/nvme/host/core.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,9 @@ EXPORT_SYMBOL_NS_GPL(nvme_put_ns, NVME_TARGET_PASSTHRU);
575575

576576
static inline void nvme_clear_nvme_request(struct request *req)
577577
{
578+
struct nvme_command *cmd = nvme_req(req)->cmd;
579+
580+
memset(cmd, 0, sizeof(*cmd));
578581
nvme_req(req)->retries = 0;
579582
nvme_req(req)->flags = 0;
580583
req->rq_flags |= RQF_DONTPREP;
@@ -593,9 +596,12 @@ static inline void nvme_init_request(struct request *req,
593596
else /* no queuedata implies admin queue */
594597
req->timeout = NVME_ADMIN_TIMEOUT;
595598

599+
/* passthru commands should let the driver set the SGL flags */
600+
cmd->common.flags &= ~NVME_CMD_SGL_ALL;
601+
596602
req->cmd_flags |= REQ_FAILFAST_DRIVER;
597603
nvme_clear_nvme_request(req);
598-
nvme_req(req)->cmd = cmd;
604+
memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd));
599605
}
600606

601607
struct request *nvme_alloc_request(struct request_queue *q,
@@ -724,14 +730,6 @@ static void nvme_assign_write_stream(struct nvme_ctrl *ctrl,
724730
req->q->write_hints[streamid] += blk_rq_bytes(req) >> 9;
725731
}
726732

727-
static inline void nvme_setup_passthrough(struct request *req,
728-
struct nvme_command *cmd)
729-
{
730-
memcpy(cmd, nvme_req(req)->cmd, sizeof(*cmd));
731-
/* passthru commands should let the driver set the SGL flags */
732-
cmd->common.flags &= ~NVME_CMD_SGL_ALL;
733-
}
734-
735733
static inline void nvme_setup_flush(struct nvme_ns *ns,
736734
struct nvme_command *cmnd)
737735
{
@@ -886,19 +884,18 @@ void nvme_cleanup_cmd(struct request *req)
886884
}
887885
EXPORT_SYMBOL_GPL(nvme_cleanup_cmd);
888886

889-
blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
890-
struct nvme_command *cmd)
887+
blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req)
891888
{
889+
struct nvme_command *cmd = nvme_req(req)->cmd;
892890
blk_status_t ret = BLK_STS_OK;
893891

894892
if (!(req->rq_flags & RQF_DONTPREP))
895893
nvme_clear_nvme_request(req);
896894

897-
memset(cmd, 0, sizeof(*cmd));
898895
switch (req_op(req)) {
899896
case REQ_OP_DRV_IN:
900897
case REQ_OP_DRV_OUT:
901-
nvme_setup_passthrough(req, cmd);
898+
/* these are setup prior to execution in nvme_init_request() */
902899
break;
903900
case REQ_OP_FLUSH:
904901
nvme_setup_flush(ns, cmd);

drivers/nvme/host/fc.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,7 @@ nvme_fc_init_request(struct blk_mq_tag_set *set, struct request *rq,
21282128
op->op.fcp_req.first_sgl = op->sgl;
21292129
op->op.fcp_req.private = &op->priv[0];
21302130
nvme_req(rq)->ctrl = &ctrl->ctrl;
2131+
nvme_req(rq)->cmd = &op->op.cmd_iu.sqe;
21312132
return res;
21322133
}
21332134

@@ -2759,8 +2760,6 @@ nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,
27592760
struct nvme_fc_ctrl *ctrl = queue->ctrl;
27602761
struct request *rq = bd->rq;
27612762
struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
2762-
struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu;
2763-
struct nvme_command *sqe = &cmdiu->sqe;
27642763
enum nvmefc_fcp_datadir io_dir;
27652764
bool queue_ready = test_bit(NVME_FC_Q_LIVE, &queue->flags);
27662765
u32 data_len;
@@ -2770,7 +2769,7 @@ nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,
27702769
!nvmf_check_ready(&queue->ctrl->ctrl, rq, queue_ready))
27712770
return nvmf_fail_nonready_command(&queue->ctrl->ctrl, rq);
27722771

2773-
ret = nvme_setup_cmd(ns, rq, sqe);
2772+
ret = nvme_setup_cmd(ns, rq);
27742773
if (ret)
27752774
return ret;
27762775

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,7 @@ void nvme_start_freeze(struct nvme_ctrl *ctrl);
623623
struct request *nvme_alloc_request(struct request_queue *q,
624624
struct nvme_command *cmd, blk_mq_req_flags_t flags);
625625
void nvme_cleanup_cmd(struct request *req);
626-
blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
627-
struct nvme_command *cmd);
626+
blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req);
628627
int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
629628
void *buf, unsigned bufflen);
630629
int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,

drivers/nvme/host/pci.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ static int nvme_init_request(struct blk_mq_tag_set *set, struct request *req,
430430
iod->nvmeq = nvmeq;
431431

432432
nvme_req(req)->ctrl = &dev->ctrl;
433+
nvme_req(req)->cmd = &iod->cmd;
433434
return 0;
434435
}
435436

@@ -932,7 +933,7 @@ static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
932933
if (unlikely(!test_bit(NVMEQ_ENABLED, &nvmeq->flags)))
933934
return BLK_STS_IOERR;
934935

935-
ret = nvme_setup_cmd(ns, req, cmnd);
936+
ret = nvme_setup_cmd(ns, req);
936937
if (ret)
937938
return ret;
938939

drivers/nvme/host/rdma.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static int nvme_rdma_init_request(struct blk_mq_tag_set *set,
314314
NVME_RDMA_DATA_SGL_SIZE;
315315

316316
req->queue = queue;
317+
nvme_req(rq)->cmd = req->sqe.data;
317318

318319
return 0;
319320
}
@@ -2038,7 +2039,7 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
20382039
struct request *rq = bd->rq;
20392040
struct nvme_rdma_request *req = blk_mq_rq_to_pdu(rq);
20402041
struct nvme_rdma_qe *sqe = &req->sqe;
2041-
struct nvme_command *c = sqe->data;
2042+
struct nvme_command *c = nvme_req(rq)->cmd;
20422043
struct ib_device *dev;
20432044
bool queue_ready = test_bit(NVME_RDMA_Q_LIVE, &queue->flags);
20442045
blk_status_t ret;
@@ -2061,7 +2062,7 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
20612062
ib_dma_sync_single_for_cpu(dev, sqe->dma,
20622063
sizeof(struct nvme_command), DMA_TO_DEVICE);
20632064

2064-
ret = nvme_setup_cmd(ns, rq, c);
2065+
ret = nvme_setup_cmd(ns, rq);
20652066
if (ret)
20662067
goto unmap_qe;
20672068

drivers/nvme/host/tcp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ static int nvme_tcp_init_request(struct blk_mq_tag_set *set,
417417
{
418418
struct nvme_tcp_ctrl *ctrl = set->driver_data;
419419
struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq);
420+
struct nvme_tcp_cmd_pdu *pdu;
420421
int queue_idx = (set == &ctrl->tag_set) ? hctx_idx + 1 : 0;
421422
struct nvme_tcp_queue *queue = &ctrl->queues[queue_idx];
422423
u8 hdgst = nvme_tcp_hdgst_len(queue);
@@ -427,8 +428,10 @@ static int nvme_tcp_init_request(struct blk_mq_tag_set *set,
427428
if (!req->pdu)
428429
return -ENOMEM;
429430

431+
pdu = req->pdu;
430432
req->queue = queue;
431433
nvme_req(rq)->ctrl = &ctrl->ctrl;
434+
nvme_req(rq)->cmd = &pdu->cmd;
432435

433436
return 0;
434437
}
@@ -2259,7 +2262,7 @@ static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns *ns,
22592262
u8 hdgst = nvme_tcp_hdgst_len(queue), ddgst = 0;
22602263
blk_status_t ret;
22612264

2262-
ret = nvme_setup_cmd(ns, rq, &pdu->cmd);
2265+
ret = nvme_setup_cmd(ns, rq);
22632266
if (ret)
22642267
return ret;
22652268

drivers/nvme/target/loop.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
141141
if (!nvmf_check_ready(&queue->ctrl->ctrl, req, queue_ready))
142142
return nvmf_fail_nonready_command(&queue->ctrl->ctrl, req);
143143

144-
ret = nvme_setup_cmd(ns, req, &iod->cmd);
144+
ret = nvme_setup_cmd(ns, req);
145145
if (ret)
146146
return ret;
147147

@@ -205,8 +205,10 @@ static int nvme_loop_init_request(struct blk_mq_tag_set *set,
205205
unsigned int numa_node)
206206
{
207207
struct nvme_loop_ctrl *ctrl = set->driver_data;
208+
struct nvme_loop_iod *iod = blk_mq_rq_to_pdu(req);
208209

209210
nvme_req(req)->ctrl = &ctrl->ctrl;
211+
nvme_req(req)->cmd = &iod->cmd;
210212
return nvme_loop_init_iod(ctrl, blk_mq_rq_to_pdu(req),
211213
(set == &ctrl->tag_set) ? hctx_idx + 1 : 0);
212214
}

0 commit comments

Comments
 (0)