From: Wang Yugui <wangyugui@e16-tech.com>
To: linux-nvme@lists.infradead.org
Cc: Wang Yugui <wangyugui@e16-tech.com>
Subject: [PATCH RFC v3] nvmet: basic RMEDIA support for target
Date: Tue, 6 Aug 2024 20:40:25 +0800 [thread overview]
Message-ID: <20240806124026.43168-1-wangyugui@e16-tech.com> (raw)
In-Reply-To: <20240806004928.27605-1-wangyugui@e16-tech.com>
Rotational media(RMEDIA) support is added to the NVMe 2.0 specification.
We add Rotational media(RMEDIA) basic support to nvme target.
Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>
---
changelog of PATCH RFC v3
- restore the process nvmet_req_find_ns() dropped in v2
changelog of PATCH RFC v2
- change 'bdev_nonrot(ns->bdev)' to '!bdev_nonrot(ns->bdev)' based on comment.
- add some support for 'nvme cmdset-ind-id-ns'
drivers/nvme/target/admin-cmd.c | 42 +++++++++++++++++++++++++++++++
drivers/nvme/target/core.c | 2 ++
drivers/nvme/target/io-cmd-bdev.c | 1 +
drivers/nvme/target/nvmet.h | 1 +
4 files changed, 55 insertions(+)
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index f7e1156ac7ec..20a28102f8a0 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -489,6 +489,54 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
nvmet_req_complete(req, status);
}
+static void nvmet_execute_identify_indep(struct nvmet_req *req)
+{
+ struct nvme_id_ns_cs_indep *id;
+ u16 status;
+
+ id = kzalloc(sizeof(*id), GFP_KERNEL);
+ if (!id) {
+ status = NVME_SC_INTERNAL;
+ goto out;
+ }
+
+ /*
+ * Our namespace might always be shared. Not just with other
+ * controllers, but also with any other user of the block device.
+ */
+ id->nmic |= NVME_NS_NMIC_SHARED;
+
+ id->nstat |= NVME_NSTAT_NRDY;
+
+ /* return an all zeroed buffer if we can't find an active namespace */
+ status = nvmet_req_find_ns(req);
+ if (status) {
+ status = 0;
+ goto done;
+ }
+
+ if (nvmet_ns_revalidate(req->ns)) {
+ mutex_lock(&req->ns->subsys->lock);
+ nvmet_ns_changed(req->ns->subsys, req->ns->nsid);
+ mutex_unlock(&req->ns->subsys->lock);
+ }
+
+ id->anagrpid = cpu_to_le32(req->ns->anagrpid);
+
+ if (req->ns->readonly)
+ id->nsattr |= NVME_NS_ATTR_RO;
+
+ if (req->ns->rotational)
+ id->nsfeat |= NVME_INDEP_NS_FEAT_RMEDIA;
+
+done:
+ if (!status)
+ status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id));
+ kfree(id);
+out:
+ nvmet_req_complete(req, status);
+}
+
static void nvmet_execute_identify_ns(struct nvmet_req *req)
{
struct nvme_id_ns *id;
@@ -706,6 +745,9 @@ static void nvmet_execute_identify(struct nvmet_req *req)
break;
}
break;
+ case NVME_ID_CNS_NS_CS_INDEP:
+ nvmet_execute_identify_indep(req);
+ return;
case NVME_ID_CNS_CS_CTRL:
switch (req->cmd->identify.csi) {
case NVME_CSI_NVM:
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index ed2424f8a396..2790fedb593b 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -1254,6 +1254,8 @@ static void nvmet_init_cap(struct nvmet_ctrl *ctrl)
else
ctrl->cap |= ctrl->port->max_queue_size - 1;
+ ctrl->cap |= NVME_CAP_CRMS_CRIMS;
+
if (nvmet_is_passthru_subsys(ctrl->subsys))
nvmet_passthrough_override_cap(ctrl);
}
diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index 0bda83d0fc3e..d15ad1a864bc 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -104,6 +104,7 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
ns->pi_type = 0;
ns->metadata_size = 0;
+ ns->rotational = !bdev_nonrot(ns->bdev);
if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY))
nvmet_bdev_ns_enable_integrity(ns);
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 190f55e6d753..86eeeadf3787 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -62,6 +62,7 @@ struct nvmet_ns {
struct block_device *bdev;
struct file *file;
bool readonly;
+ bool rotational;
u32 nsid;
u32 blksize_shift;
loff_t size;
--
2.36.2
next prev parent reply other threads:[~2024-08-06 12:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-23 23:24 [PATCH RFC] basic RMEDIA support for nvme host Wang Yugui
2024-07-24 12:30 ` [PATCH RFC v2] nvme: basic RMEDIA support for host Wang Yugui
2024-07-25 0:43 ` Damien Le Moal
2024-07-25 1:56 ` Wang Yugui
2024-07-25 14:10 ` Christoph Hellwig
2024-07-25 22:59 ` Damien Le Moal
2024-08-12 14:28 ` Hannes Reinecke
2024-07-25 14:09 ` Christoph Hellwig
2024-08-06 0:48 ` [PATCH RFC v3] " Wang Yugui
2024-08-06 0:49 ` [PATCH RFC] nvmet: basic RMEDIA support for target Wang Yugui
2024-08-06 8:11 ` Sagi Grimberg
2024-08-06 9:08 ` Wang Yugui
2024-08-06 9:42 ` [PATCH RFC v2] " Wang Yugui
2024-08-06 12:40 ` Wang Yugui [this message]
2024-08-07 12:14 ` [PATCH RFC v3] " 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=20240806124026.43168-1-wangyugui@e16-tech.com \
--to=wangyugui@e16-tech.com \
--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