Skip to content

Commit 6287b51

Browse files
sagigrimbergChristoph Hellwig
authored andcommitted
nvme-core: optionally poll sync commands
Pass poll bool to indicate that we need it to poll. This prepares us for polling support in nvmf since connect is an I/O that will be queued and has to be polled in order to complete. If poll is passed, we call nvme_execute_rq_polled which sends the requests and polls for its completion. Signed-off-by: Sagi Grimberg <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 7b7ab78 commit 6287b51

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

drivers/nvme/host/core.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -724,14 +724,39 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
724724
}
725725
EXPORT_SYMBOL_GPL(nvme_setup_cmd);
726726

727+
static void nvme_end_sync_rq(struct request *rq, blk_status_t error)
728+
{
729+
struct completion *waiting = rq->end_io_data;
730+
731+
rq->end_io_data = NULL;
732+
complete(waiting);
733+
}
734+
735+
static void nvme_execute_rq_polled(struct request_queue *q,
736+
struct gendisk *bd_disk, struct request *rq, int at_head)
737+
{
738+
DECLARE_COMPLETION_ONSTACK(wait);
739+
740+
WARN_ON_ONCE(!test_bit(QUEUE_FLAG_POLL, &q->queue_flags));
741+
742+
rq->cmd_flags |= REQ_HIPRI;
743+
rq->end_io_data = &wait;
744+
blk_execute_rq_nowait(q, bd_disk, rq, at_head, nvme_end_sync_rq);
745+
746+
while (!completion_done(&wait)) {
747+
blk_poll(q, request_to_qc_t(rq->mq_hctx, rq), true);
748+
cond_resched();
749+
}
750+
}
751+
727752
/*
728753
* Returns 0 on success. If the result is negative, it's a Linux error code;
729754
* if the result is positive, it's an NVM Express status code
730755
*/
731756
int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
732757
union nvme_result *result, void *buffer, unsigned bufflen,
733758
unsigned timeout, int qid, int at_head,
734-
blk_mq_req_flags_t flags)
759+
blk_mq_req_flags_t flags, bool poll)
735760
{
736761
struct request *req;
737762
int ret;
@@ -748,7 +773,10 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
748773
goto out;
749774
}
750775

751-
blk_execute_rq(req->q, NULL, req, at_head);
776+
if (poll)
777+
nvme_execute_rq_polled(req->q, NULL, req, at_head);
778+
else
779+
blk_execute_rq(req->q, NULL, req, at_head);
752780
if (result)
753781
*result = nvme_req(req)->result;
754782
if (nvme_req(req)->flags & NVME_REQ_CANCELLED)
@@ -765,7 +793,7 @@ int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
765793
void *buffer, unsigned bufflen)
766794
{
767795
return __nvme_submit_sync_cmd(q, cmd, NULL, buffer, bufflen, 0,
768-
NVME_QID_ANY, 0, 0);
796+
NVME_QID_ANY, 0, 0, false);
769797
}
770798
EXPORT_SYMBOL_GPL(nvme_submit_sync_cmd);
771799

@@ -1084,7 +1112,7 @@ static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword
10841112
c.features.dword11 = cpu_to_le32(dword11);
10851113

10861114
ret = __nvme_submit_sync_cmd(dev->admin_q, &c, &res,
1087-
buffer, buflen, 0, NVME_QID_ANY, 0, 0);
1115+
buffer, buflen, 0, NVME_QID_ANY, 0, 0, false);
10881116
if (ret >= 0 && result)
10891117
*result = le32_to_cpu(res.u32);
10901118
return ret;
@@ -1727,7 +1755,7 @@ int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
17271755
cmd.common.cdw11 = cpu_to_le32(len);
17281756

17291757
return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len,
1730-
ADMIN_TIMEOUT, NVME_QID_ANY, 1, 0);
1758+
ADMIN_TIMEOUT, NVME_QID_ANY, 1, 0, false);
17311759
}
17321760
EXPORT_SYMBOL_GPL(nvme_sec_submit);
17331761
#endif /* CONFIG_BLK_SED_OPAL */

drivers/nvme/host/fabrics.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int nvmf_reg_read32(struct nvme_ctrl *ctrl, u32 off, u32 *val)
159159
cmd.prop_get.offset = cpu_to_le32(off);
160160

161161
ret = __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, &res, NULL, 0, 0,
162-
NVME_QID_ANY, 0, 0);
162+
NVME_QID_ANY, 0, 0, false);
163163

164164
if (ret >= 0)
165165
*val = le64_to_cpu(res.u64);
@@ -206,7 +206,7 @@ int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val)
206206
cmd.prop_get.offset = cpu_to_le32(off);
207207

208208
ret = __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, &res, NULL, 0, 0,
209-
NVME_QID_ANY, 0, 0);
209+
NVME_QID_ANY, 0, 0, false);
210210

211211
if (ret >= 0)
212212
*val = le64_to_cpu(res.u64);
@@ -252,7 +252,7 @@ int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val)
252252
cmd.prop_set.value = cpu_to_le64(val);
253253

254254
ret = __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, NULL, 0, 0,
255-
NVME_QID_ANY, 0, 0);
255+
NVME_QID_ANY, 0, 0, false);
256256
if (unlikely(ret))
257257
dev_err(ctrl->device,
258258
"Property Set error: %d, offset %#x\n",
@@ -406,7 +406,7 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl)
406406

407407
ret = __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, &res,
408408
data, sizeof(*data), 0, NVME_QID_ANY, 1,
409-
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
409+
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT, false);
410410
if (ret) {
411411
nvmf_log_connect_error(ctrl, ret, le32_to_cpu(res.u32),
412412
&cmd, data);
@@ -468,7 +468,7 @@ int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid)
468468

469469
ret = __nvme_submit_sync_cmd(ctrl->connect_q, &cmd, &res,
470470
data, sizeof(*data), 0, qid, 1,
471-
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
471+
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT, false);
472472
if (ret) {
473473
nvmf_log_connect_error(ctrl, ret, le32_to_cpu(res.u32),
474474
&cmd, data);

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
447447
int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
448448
union nvme_result *result, void *buffer, unsigned bufflen,
449449
unsigned timeout, int qid, int at_head,
450-
blk_mq_req_flags_t flags);
450+
blk_mq_req_flags_t flags, bool poll);
451451
int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count);
452452
void nvme_stop_keep_alive(struct nvme_ctrl *ctrl);
453453
int nvme_reset_ctrl(struct nvme_ctrl *ctrl);

0 commit comments

Comments
 (0)