From: Chaitanya Kulkarni <chaitanyak@nvidia.com>
To: <linux-block@vger.kernel.org>, <linux-raid@vger.kernel.org>,
<linux-nvme@lists.infradead.org>, <linux-scsi@vger.kernel.org>,
<target-devel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>,
<linux-xfs@vger.kernel.org>, <dm-devel@redhat.com>
Cc: <axboe@kernel.dk>, <agk@redhat.com>, <snitzer@redhat.com>,
<song@kernel.org>, <djwong@kernel.org>, <kbusch@kernel.org>,
<hch@lst.de>, <sagi@grimberg.me>, <jejb@linux.ibm.com>,
<martin.petersen@oracle.com>, <viro@zeniv.linux.org.uk>,
<javier@javigon.com>, <johannes.thumshirn@wdc.com>,
<bvanassche@acm.org>, <dongli.zhang@oracle.com>,
<ming.lei@redhat.com>, <osandov@fb.com>, <willy@infradead.org>,
<jefflexu@linux.alibaba.com>, <josef@toxicpanda.com>,
<clm@fb.com>, <dsterba@suse.com>, <jack@suse.com>,
<tytso@mit.edu>, <adilger.kernel@dilger.ca>, <jlayton@kernel.org>,
<idryomov@gmail.com>, <danil.kipnis@cloud.ionos.com>,
<ebiggers@google.com>, <jinpu.wang@cloud.ionos.com>,
Chaitanya Kulkarni <kch@nvidia.com>
Subject: [RFC PATCH 5/8] nvmet: add Verify emulation support for bdev-ns
Date: Wed, 3 Nov 2021 23:46:31 -0700 [thread overview]
Message-ID: <20211104064634.4481-6-chaitanyak@nvidia.com> (raw)
In-Reply-To: <20211104064634.4481-1-chaitanyak@nvidia.com>
From: Chaitanya Kulkarni <kch@nvidia.com>
Not all devices can support verify requests which can be mapped to
the controller specific command. This patch adds a way to emulate
REQ_OP_VERIFY for NVMeOF block device namespace. We add a new
workqueue to offload the emulation with the help of
__blkdev_emulate_verify().
Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
drivers/nvme/target/core.c | 12 +++++++-
drivers/nvme/target/io-cmd-bdev.c | 51 ++++++++++++++++++++++++++-----
drivers/nvme/target/nvmet.h | 3 ++
3 files changed, 57 insertions(+), 9 deletions(-)
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 8ce4d59cc9e7..8a17a6479073 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -16,6 +16,7 @@
#include "nvmet.h"
struct workqueue_struct *buffered_io_wq;
+struct workqueue_struct *verify_wq;
static const struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX];
static DEFINE_IDA(cntlid_ida);
@@ -1546,11 +1547,17 @@ static int __init nvmet_init(void)
nvmet_ana_group_enabled[NVMET_DEFAULT_ANA_GRPID] = 1;
+ verify_wq = alloc_workqueue("nvmet-verify-wq", WQ_MEM_RECLAIM, 0);
+ if (!verify_wq) {
+ error = -ENOMEM;
+ goto out;
+ }
+
buffered_io_wq = alloc_workqueue("nvmet-buffered-io-wq",
WQ_MEM_RECLAIM, 0);
if (!buffered_io_wq) {
error = -ENOMEM;
- goto out;
+ goto out_free_verify_work_queue;
}
error = nvmet_init_discovery();
@@ -1566,6 +1573,8 @@ static int __init nvmet_init(void)
nvmet_exit_discovery();
out_free_work_queue:
destroy_workqueue(buffered_io_wq);
+out_free_verify_work_queue:
+ destroy_workqueue(verify_wq);
out:
return error;
}
@@ -1576,6 +1585,7 @@ static void __exit nvmet_exit(void)
nvmet_exit_discovery();
ida_destroy(&cntlid_ida);
destroy_workqueue(buffered_io_wq);
+ destroy_workqueue(verify_wq);
BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_entry) != 1024);
BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_hdr) != 1024);
diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index 5a888cdadfea..80b8e7bfd1ae 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -433,25 +433,60 @@ static void nvmet_bdev_execute_write_zeroes(struct nvmet_req *req)
}
}
-static void nvmet_bdev_execute_verify(struct nvmet_req *req)
+static void __nvmet_req_to_verify_sectors(struct nvmet_req *req,
+ sector_t *sects, sector_t *nr_sects)
{
struct nvme_verify_cmd *verify = &req->cmd->verify;
+
+ *sects = le64_to_cpu(verify->slba) << (req->ns->blksize_shift - 9);
+ *nr_sects = (((sector_t)le16_to_cpu(verify->length) + 1) <<
+ (req->ns->blksize_shift - 9));
+}
+
+static void nvmet_bdev_emulate_verify_work(struct work_struct *w)
+{
+ struct nvmet_req *req = container_of(w, struct nvmet_req, b.work);
+ sector_t nr_sector;
+ sector_t sector;
+ int ret = 0;
+
+ __nvmet_req_to_verify_sectors(req, §or, &nr_sector);
+ if (!nr_sector)
+ goto out;
+
+ ret = blkdev_emulate_verify(req->ns->bdev, sector, nr_sector,
+ GFP_KERNEL);
+out:
+ nvmet_req_complete(req,
+ blk_to_nvme_status(req, errno_to_blk_status(ret)));
+}
+
+static void nvmet_bdev_submit_emulate_verify(struct nvmet_req *req)
+{
+ INIT_WORK(&req->b.work, nvmet_bdev_emulate_verify_work);
+ queue_work(verify_wq, &req->b.work);
+}
+
+
+static void nvmet_bdev_execute_verify(struct nvmet_req *req)
+{
struct bio *bio = NULL;
sector_t nr_sector;
sector_t sector;
- int ret;
+ int ret = 0;
if (!nvmet_check_transfer_len(req, 0))
return;
+ /* offload emulation */
if (!bdev_verify_sectors(req->ns->bdev)) {
- nvmet_req_complete(req, NVME_SC_INTERNAL | NVME_SC_DNR);
+ nvmet_bdev_submit_emulate_verify(req);
return;
}
- sector = le64_to_cpu(verify->slba) << (req->ns->blksize_shift - 9);
- nr_sector = (((sector_t)le16_to_cpu(verify->length) + 1) <<
- (req->ns->blksize_shift - 9));
+ __nvmet_req_to_verify_sectors(req, §or, &nr_sector);
+ if (!nr_sector)
+ goto out;
ret = __blkdev_issue_verify(req->ns->bdev, sector, nr_sector,
GFP_KERNEL, &bio);
@@ -459,9 +494,9 @@ static void nvmet_bdev_execute_verify(struct nvmet_req *req)
bio->bi_private = req;
bio->bi_end_io = nvmet_bio_done;
submit_bio(bio);
- } else {
- nvmet_req_complete(req, errno_to_nvme_status(req, ret));
}
+out:
+ nvmet_req_complete(req, errno_to_nvme_status(req, ret));
}
u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req)
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 8776dd1a0490..7f3f584b1e7b 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -323,6 +323,8 @@ struct nvmet_req {
union {
struct {
struct bio inline_bio;
+ /* XXX: should we take work out of union ? */
+ struct work_struct work;
} b;
struct {
bool mpool_alloc;
@@ -355,6 +357,7 @@ struct nvmet_req {
};
extern struct workqueue_struct *buffered_io_wq;
+extern struct workqueue_struct *verify_wq;
static inline void nvmet_set_result(struct nvmet_req *req, u32 result)
{
--
2.22.1
next prev parent reply other threads:[~2021-11-04 6:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-04 6:46 [RFC PATCH 0/8] block: add support for REQ_OP_VERIFY Chaitanya Kulkarni
2021-11-04 6:46 ` [RFC PATCH 1/8] " Chaitanya Kulkarni
2021-11-04 17:25 ` Darrick J. Wong
2021-11-11 8:01 ` Chaitanya Kulkarni
2021-11-04 6:46 ` [RFC PATCH 2/8] scsi: add REQ_OP_VERIFY support Chaitanya Kulkarni
2021-11-04 12:33 ` Damien Le Moal
2021-11-11 8:07 ` Chaitanya Kulkarni
2021-11-04 6:46 ` [RFC PATCH 3/8] nvme: add support for the Verify command Chaitanya Kulkarni
2021-11-04 22:44 ` Keith Busch
2021-11-11 8:09 ` Chaitanya Kulkarni
2021-11-04 6:46 ` [PATCH 4/8] nvmet: add Verify command support for bdev-ns Chaitanya Kulkarni
2021-11-04 6:46 ` Chaitanya Kulkarni [this message]
2021-11-04 6:46 ` [RFC PATCH 6/8] nvmet: add verify emulation support for file-ns Chaitanya Kulkarni
2021-11-04 6:46 ` [RFC PATCH 7/8] null_blk: add REQ_OP_VERIFY support Chaitanya Kulkarni
2021-11-04 6:46 ` [RFC PATCH 8/8] md: add support for REQ_OP_VERIFY Chaitanya Kulkarni
2021-11-11 8:13 ` Chaitanya Kulkarni
2021-11-12 15:19 ` Mike Snitzer
2021-11-04 7:14 ` [RFC PATCH 0/8] block: " Christoph Hellwig
2021-11-04 9:27 ` Chaitanya Kulkarni
2021-11-04 17:32 ` Darrick J. Wong
2021-11-04 17:34 ` Christoph Hellwig
2021-11-04 22:37 ` Keith Busch
2021-11-05 8:25 ` javier
2021-11-11 8:18 ` Chaitanya Kulkarni
2021-11-04 15:16 ` Douglas Gilbert
2021-11-11 8:27 ` Chaitanya Kulkarni
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=20211104064634.4481-6-chaitanyak@nvidia.com \
--to=chaitanyak@nvidia.com \
--cc=adilger.kernel@dilger.ca \
--cc=agk@redhat.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=clm@fb.com \
--cc=danil.kipnis@cloud.ionos.com \
--cc=djwong@kernel.org \
--cc=dm-devel@redhat.com \
--cc=dongli.zhang@oracle.com \
--cc=dsterba@suse.com \
--cc=ebiggers@google.com \
--cc=hch@lst.de \
--cc=idryomov@gmail.com \
--cc=jack@suse.com \
--cc=javier@javigon.com \
--cc=jefflexu@linux.alibaba.com \
--cc=jejb@linux.ibm.com \
--cc=jinpu.wang@cloud.ionos.com \
--cc=jlayton@kernel.org \
--cc=johannes.thumshirn@wdc.com \
--cc=josef@toxicpanda.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-raid@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=ming.lei@redhat.com \
--cc=osandov@fb.com \
--cc=sagi@grimberg.me \
--cc=snitzer@redhat.com \
--cc=song@kernel.org \
--cc=target-devel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@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