From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org
Subject: [PATCH 4/4] nvme: support ranged discard requests
Date: Tue, 7 Feb 2017 17:46:58 +0100 [thread overview]
Message-ID: <20170207164658.32449-5-hch@lst.de> (raw)
In-Reply-To: <20170207164658.32449-1-hch@lst.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/host/core.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index efe8ec300126..ae9254fcd9c5 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -238,26 +238,36 @@ static inline void nvme_setup_flush(struct nvme_ns *ns,
static inline int nvme_setup_discard(struct nvme_ns *ns, struct request *req,
struct nvme_command *cmnd)
{
+ unsigned short segments = blk_rq_nr_discard_segments(req), n = 0;
struct nvme_dsm_range *range;
- unsigned int nr_bytes = blk_rq_bytes(req);
+ struct bio *bio;
- range = kmalloc(sizeof(*range), GFP_ATOMIC);
+ range = kmalloc_array(segments, sizeof(*range), GFP_ATOMIC);
if (!range)
return BLK_MQ_RQ_QUEUE_BUSY;
- range->cattr = cpu_to_le32(0);
- range->nlb = cpu_to_le32(nr_bytes >> ns->lba_shift);
- range->slba = cpu_to_le64(nvme_block_nr(ns, blk_rq_pos(req)));
+ __rq_for_each_bio(bio, req) {
+ u64 slba = nvme_block_nr(ns, bio->bi_iter.bi_sector);
+ u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift;
+
+ range[n].cattr = cpu_to_le32(0);
+ range[n].nlb = cpu_to_le32(nlb);
+ range[n].slba = cpu_to_le64(slba);
+ n++;
+ }
+
+ if (WARN_ON_ONCE(n != segments))
+ return BLK_MQ_RQ_QUEUE_ERROR;
memset(cmnd, 0, sizeof(*cmnd));
cmnd->dsm.opcode = nvme_cmd_dsm;
cmnd->dsm.nsid = cpu_to_le32(ns->ns_id);
- cmnd->dsm.nr = 0;
+ cmnd->dsm.nr = segments - 1;
cmnd->dsm.attributes = cpu_to_le32(NVME_DSMGMT_AD);
req->special_vec.bv_page = virt_to_page(range);
req->special_vec.bv_offset = offset_in_page(range);
- req->special_vec.bv_len = sizeof(*range);
+ req->special_vec.bv_len = sizeof(*range) * segments;
req->rq_flags |= RQF_SPECIAL_PAYLOAD;
return BLK_MQ_RQ_QUEUE_OK;
@@ -1233,6 +1243,8 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
if (ctrl->vwc & NVME_CTRL_VWC_PRESENT)
vwc = true;
blk_queue_write_cache(q, vwc, vwc);
+ blk_queue_max_discard_segments(q,
+ PAGE_SIZE / sizeof(struct nvme_dsm_range));
}
/*
--
2.11.0
next prev parent reply other threads:[~2017-02-07 16:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-07 16:46 support for multi-range discard requests Christoph Hellwig
2017-02-07 16:46 ` [PATCH 1/4] block: move req_set_nomerge to blk.h Christoph Hellwig
2017-02-15 10:29 ` Sagi Grimberg
2017-02-07 16:46 ` [PATCH 2/4] block: enumify ELEVATOR_*_MERGE Christoph Hellwig
2017-02-15 10:31 ` Sagi Grimberg
2017-02-07 16:46 ` [PATCH 3/4] block: optionally merge discontiguous discard bios into a single request Christoph Hellwig
2017-02-08 10:54 ` Ming Lei
2017-02-08 11:57 ` Christoph Hellwig
2017-02-15 10:36 ` Sagi Grimberg
2017-02-07 16:46 ` Christoph Hellwig [this message]
2017-02-07 18:34 ` [PATCH 4/4] nvme: support ranged discard requests Keith Busch
2017-02-07 19:34 ` Christoph Hellwig
2017-02-15 10:42 ` Sagi Grimberg
-- strict thread matches above, loose matches on Subject: below --
2017-02-08 13:13 support for multi-range discard requests V2 Christoph Hellwig
2017-02-08 13:13 ` [PATCH 4/4] nvme: support ranged discard requests Christoph Hellwig
2017-02-08 13:32 ` Andrey Kuzmin
2017-02-08 13:36 ` Christoph Hellwig
2017-02-08 13:46 support for multi-range discard requests V3 Christoph Hellwig
2017-02-08 13:46 ` [PATCH 4/4] nvme: support ranged discard requests Christoph Hellwig
2017-02-15 10:45 ` Sagi Grimberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170207164658.32449-5-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox