Commit 6d31e3ba authored by Chaitanya Kulkarni's avatar Chaitanya Kulkarni Committed by Jens Axboe

nvme: add support for the Write Zeroes command

Allow write zeroes operations (REQ_OP_WRITE_ZEROES) on the block
device, if the device supports optional command bit set for write
zeroes. Add support to setup write zeroes command. Set maximum possible
write zeroes sectors in one write zeroes command according to
nvme write zeroes command definition.
Signed-off-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@hgst.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 3b7c33b2
...@@ -272,6 +272,21 @@ static inline int nvme_setup_discard(struct nvme_ns *ns, struct request *req, ...@@ -272,6 +272,21 @@ static inline int nvme_setup_discard(struct nvme_ns *ns, struct request *req,
return BLK_MQ_RQ_QUEUE_OK; return BLK_MQ_RQ_QUEUE_OK;
} }
static inline void nvme_setup_write_zeroes(struct nvme_ns *ns,
struct request *req, struct nvme_command *cmnd)
{
struct nvme_write_zeroes_cmd *write_zeroes = &cmnd->write_zeroes;
memset(cmnd, 0, sizeof(*cmnd));
write_zeroes->opcode = nvme_cmd_write_zeroes;
write_zeroes->nsid = cpu_to_le32(ns->ns_id);
write_zeroes->slba =
cpu_to_le64(nvme_block_nr(ns, blk_rq_pos(req)));
write_zeroes->length =
cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1);
write_zeroes->control = 0;
}
static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req, static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req,
struct nvme_command *cmnd) struct nvme_command *cmnd)
{ {
...@@ -325,6 +340,8 @@ int nvme_setup_cmd(struct nvme_ns *ns, struct request *req, ...@@ -325,6 +340,8 @@ int nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
nvme_setup_flush(ns, cmd); nvme_setup_flush(ns, cmd);
else if (req_op(req) == REQ_OP_DISCARD) else if (req_op(req) == REQ_OP_DISCARD)
ret = nvme_setup_discard(ns, req, cmd); ret = nvme_setup_discard(ns, req, cmd);
else if (req_op(req) == REQ_OP_WRITE_ZEROES)
nvme_setup_write_zeroes(ns, req, cmd);
else else
nvme_setup_rw(ns, req, cmd); nvme_setup_rw(ns, req, cmd);
...@@ -943,6 +960,10 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) ...@@ -943,6 +960,10 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
if (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM) if (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM)
nvme_config_discard(ns); nvme_config_discard(ns);
if (ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES)
blk_queue_max_write_zeroes_sectors(ns->queue,
((u32)(USHRT_MAX + 1) * bs) >> 9);
blk_mq_unfreeze_queue(disk->queue); blk_mq_unfreeze_queue(disk->queue);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment