Skip to content

Commit

Permalink
nvme/rq: add nvme_rq_wait
Browse files Browse the repository at this point in the history
Add a version of nvme_rq_spin() with a timeout.

Signed-off-by: Klaus Jensen <[email protected]>
  • Loading branch information
birkelund committed May 15, 2024
1 parent 02e5a89 commit 8e8dada
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions include/vfn/nvme/rq.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,17 @@ int nvme_rq_mapv_prp(struct nvme_ctrl *ctrl, struct nvme_rq *rq, union nvme_cmd
*/
int nvme_rq_spin(struct nvme_rq *rq, struct nvme_cqe *cqe_copy);

/**
* nvme_rq_wait - Wait for completion of the command associated with the request
* tracker
* @rq: Request tracker (&struct nvme_rq)
* @cqe_copy: Output parameter to copy completion queue entry into
* @ts: Maximum time to wait for completion
*
* Like nvme_rq_spin(), but do not spin for more than @ts.
*
* Return: ``0`` on success, ``-1`` on error and set ``errno``.
*/
int nvme_rq_wait(struct nvme_rq *rq, struct nvme_cqe *cqe_copy, struct timespec *ts);

#endif /* LIBVFN_NVME_RQ_H */
11 changes: 9 additions & 2 deletions src/nvme/rq.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ int nvme_rq_mapv_prp(struct nvme_ctrl *ctrl, struct nvme_rq *rq, union nvme_cmd
return -1;
}

int nvme_rq_spin(struct nvme_rq *rq, struct nvme_cqe *cqe_copy)
int nvme_rq_wait(struct nvme_rq *rq, struct nvme_cqe *cqe_copy, struct timespec *ts)
{
struct nvme_cq *cq = rq->sq->cq;
struct nvme_cqe cqe;

nvme_cq_get_cqes(cq, &cqe, 1);
if (nvme_cq_wait_cqes(cq, &cqe, 1, ts) != 1)
return -1;

nvme_cq_update_head(cq);

if (cqe_copy)
Expand All @@ -221,3 +223,8 @@ int nvme_rq_spin(struct nvme_rq *rq, struct nvme_cqe *cqe_copy)

return 0;
}

int nvme_rq_spin(struct nvme_rq *rq, struct nvme_cqe *cqe_copy)
{
return nvme_rq_wait(rq, cqe_copy, NULL);
}

0 comments on commit 8e8dada

Please sign in to comment.