nvme: move command clear into the various setup helpers
authorJens Axboe <axboe@kernel.dk>
Mon, 18 Oct 2021 12:45:06 +0000 (06:45 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 19 Oct 2021 18:40:51 +0000 (12:40 -0600)
We don't have to worry about doing extra memsets by moving it outside
the protection of RQF_DONTPREP, as nvme doesn't do partial completions.

This is in preparation for making the read/write fast path not do a full
memset of the command.

Reviewed-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/nvme/host/core.c
drivers/nvme/host/zns.c

index 3109bdf137e4b2ff52c0c744edcf9647fe6960f7..824790bed2f5b321fd1ed7e03af7e5f48f48e4de 100644 (file)
@@ -834,6 +834,7 @@ static void nvme_assign_write_stream(struct nvme_ctrl *ctrl,
 static inline void nvme_setup_flush(struct nvme_ns *ns,
                struct nvme_command *cmnd)
 {
+       memset(cmnd, 0, sizeof(*cmnd));
        cmnd->common.opcode = nvme_cmd_flush;
        cmnd->common.nsid = cpu_to_le32(ns->head->ns_id);
 }
@@ -885,6 +886,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
                return BLK_STS_IOERR;
        }
 
+       memset(cmnd, 0, sizeof(*cmnd));
        cmnd->dsm.opcode = nvme_cmd_dsm;
        cmnd->dsm.nsid = cpu_to_le32(ns->head->ns_id);
        cmnd->dsm.nr = cpu_to_le32(segments - 1);
@@ -901,6 +903,8 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
 static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
                struct request *req, struct nvme_command *cmnd)
 {
+       memset(cmnd, 0, sizeof(*cmnd));
+
        if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
                return nvme_setup_discard(ns, req, cmnd);
 
@@ -925,6 +929,8 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
        u16 control = 0;
        u32 dsmgmt = 0;
 
+       memset(cmnd, 0, sizeof(*cmnd));
+
        if (req->cmd_flags & REQ_FUA)
                control |= NVME_RW_FUA;
        if (req->cmd_flags & (REQ_FAILFAST_DEV | REQ_RAHEAD))
@@ -993,10 +999,8 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req)
        struct nvme_ctrl *ctrl = nvme_req(req)->ctrl;
        blk_status_t ret = BLK_STS_OK;
 
-       if (!(req->rq_flags & RQF_DONTPREP)) {
+       if (!(req->rq_flags & RQF_DONTPREP))
                nvme_clear_nvme_request(req);
-               memset(cmd, 0, sizeof(*cmd));
-       }
 
        switch (req_op(req)) {
        case REQ_OP_DRV_IN:
index d95010481fce0049c7cf6270791167e44a878690..bfc259e0d7b87e11b7d9c3b595e413535842c5a7 100644 (file)
@@ -233,6 +233,8 @@ out_free:
 blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, struct request *req,
                struct nvme_command *c, enum nvme_zone_mgmt_action action)
 {
+       memset(c, 0, sizeof(*c));
+
        c->zms.opcode = nvme_cmd_zone_mgmt_send;
        c->zms.nsid = cpu_to_le32(ns->head->ns_id);
        c->zms.slba = cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req)));