nvmet: implement valid sqhd values in completions
authorJames Smart <jsmart2021@gmail.com>
Mon, 18 Sep 2017 16:08:29 +0000 (09:08 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 25 Sep 2017 14:56:05 +0000 (08:56 -0600)
To support sqhd, for initiators that are following the spec and
paying attention to sqhd vs their sqtail values:

- add sqhd to struct nvmet_sq
- initialize sqhd to 0 in nvmet_sq_setup
- rather than propagate the 0's-based qsize value from the connect message
  which requires a +1 in every sqhd update, and as nothing else references
  it, convert to 1's-based value in nvmt_sq/cq_setup() calls.
- validate connect message sqsize being non-zero per spec.
- updated assign sqhd for every completion that goes back.

Also remove handling the NULL sq case in __nvmet_req_complete, as it can't
happen with the current code.

Signed-off-by: James Smart <james.smart@broadcom.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Max Gurtovoy <maxg@mellanox.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/nvme/target/core.c
drivers/nvme/target/fabrics-cmd.c
drivers/nvme/target/nvmet.h

index 7c23eaf8e5639c14b5824fad26bdd4d6642e45b1..c2a768a94235dcbb7bdd6f794ebde833c0d8e755 100644 (file)
@@ -390,10 +390,9 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status)
        if (status)
                nvmet_set_status(req, status);
 
-       /* XXX: need to fill in something useful for sq_head */
-       req->rsp->sq_head = 0;
-       if (likely(req->sq)) /* may happen during early failure */
-               req->rsp->sq_id = cpu_to_le16(req->sq->qid);
+       req->sq->sqhd = (req->sq->sqhd + 1) % req->sq->size;
+       req->rsp->sq_head = cpu_to_le16(req->sq->sqhd);
+       req->rsp->sq_id = cpu_to_le16(req->sq->qid);
        req->rsp->command_id = req->cmd->common.command_id;
 
        if (req->ns)
@@ -420,6 +419,7 @@ void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq,
 void nvmet_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq,
                u16 qid, u16 size)
 {
+       sq->sqhd = 0;
        sq->qid = qid;
        sq->size = size;
 
index 859a66725291d62bbf6f12a06b8486a9c5edbcc2..db3bf6b8bf9ee63581661310aa98820a7341445b 100644 (file)
@@ -109,9 +109,14 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
                pr_warn("queue already connected!\n");
                return NVME_SC_CONNECT_CTRL_BUSY | NVME_SC_DNR;
        }
+       if (!sqsize) {
+               pr_warn("queue size zero!\n");
+               return NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
+       }
 
-       nvmet_cq_setup(ctrl, req->cq, qid, sqsize);
-       nvmet_sq_setup(ctrl, req->sq, qid, sqsize);
+       /* note: convert queue size from 0's-based value to 1's-based value */
+       nvmet_cq_setup(ctrl, req->cq, qid, sqsize + 1);
+       nvmet_sq_setup(ctrl, req->sq, qid, sqsize + 1);
        return 0;
 }
 
index 7d261ab894f47b56addb93fe95beee8fda37b8d3..7b8e20adf76029f293569688e8a5c71013c6393d 100644 (file)
@@ -74,6 +74,7 @@ struct nvmet_sq {
        struct percpu_ref       ref;
        u16                     qid;
        u16                     size;
+       u16                     sqhd;
        struct completion       free_done;
        struct completion       confirm_done;
 };