Skip to contentSkip to conversation

basic RMEDIA support for nvme host

RFC PATCH Superseded Wang Yugui 5 participants 15 messages Jul 23, 2024 – Aug 12, 2024

Subsystems (2)
lore
Share & tools
lore

Wang Yugui

author
#0 lore raw

RFC PATCH 1/1 basic RMEDIA support for nvme host

Rotational media(RMEDIA) support is added the NVMe 2.0 specification. We firstly add Rotational media(RMEDIA) support to nvme host, then we can add the support to nvme target later if the backstore is a Rotational media(RMEDIA) block device.

---
 drivers/nvme/host/core.c | 5 +++++
 include/linux/nvme.h     | 1 +
 2 files changed, 6 insertions(+)
drivers/nvme/host/core.c +5 -0
index 19917253ba7b..f4c41bf70b19 100644
@@ -40,6 +40,7 @@ struct nvme_ns_info {
 	bool is_readonly;
 	bool is_ready;
 	bool is_removed;
+	bool is_rmedia;
 };
 
 unsigned int admin_timeout = 60;
@@ -1622,6 +1623,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,
 		info->is_shared = id->nmic & NVME_NS_NMIC_SHARED;
 		info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
 		info->is_ready = id->nstat & NVME_NSTAT_NRDY;
+		info->is_rmedia = id->nsfeat & NVME_INDEP_NS_FEAT_RMEDIA;
 	}
 	kfree(id);
 	return ret;
@@ -2164,6 +2166,9 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 	else
 		lim.features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA);
 
+	if(info->is_rmedia)
+		lim.lim.features |= BLK_FEAT_ROTATIONAL;
+
 	/*
 	 * Register a metadata profile for PI, or the plain non-integrity NVMe
 	 * metadata masquerading as Type 0 if supported, otherwise reject block
include/linux/nvme.h +1 -0
index c12a329dd463..2c259d126f80 100644
@@ -546,6 +546,7 @@ enum {
 	NVME_NS_FEAT_THIN	= 1 << 0,
 	NVME_NS_FEAT_ATOMICS	= 1 << 1,
 	NVME_NS_FEAT_IO_OPT	= 1 << 4,
+	NVME_INDEP_NS_FEAT_RMEDIA = 1 << 4,
 	NVME_NS_ATTR_RO		= 1 << 0,
 	NVME_NS_FLBAS_LBA_MASK	= 0xf,
 	NVME_NS_FLBAS_LBA_UMASK	= 0x60,
Signature · 1 line
2.36.2
author
#1 lore raw

RFC PATCH v2 1/1 nvme: basic RMEDIA support for host

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We firstly add Rotational media(RMEDIA) support to nvme host, then we can add the support to nvme target later if the backstore is a Rotational media(RMEDIA) block device.

---
 drivers/nvme/host/core.c      | 5 +++++
 drivers/nvme/host/multipath.c | 3 +++
 drivers/nvme/host/nvme.h      | 1 +
 include/linux/nvme.h          | 1 +
 4 files changed, 10 insertions(+)
drivers/nvme/host/core.c +5 -0
index 19917253ba7b..f4c41bf70b19 100644
@@ -40,6 +40,7 @@ struct nvme_ns_info {
 	bool is_readonly;
 	bool is_ready;
 	bool is_removed;
+	bool is_rmedia;
 };
 
 unsigned int admin_timeout = 60;
@@ -1622,6 +1623,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,
 		info->is_shared = id->nmic & NVME_NS_NMIC_SHARED;
 		info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
 		info->is_ready = id->nstat & NVME_NSTAT_NRDY;
+		info->is_rmedia = id->nsfeat & NVME_INDEP_NS_FEAT_RMEDIA;
 	}
 	kfree(id);
 	return ret;
@@ -3613,6 +3618,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
 	head->ns_id = info->nsid;
 	head->ids = info->ids;
 	head->shared = info->is_shared;
+	head->rmedia = info->is_rmedia;
 	ratelimit_state_init(&head->rs_nuse, 5 * HZ, 1);
 	ratelimit_set_flags(&head->rs_nuse, RATELIMIT_MSG_ON_RELEASE);
 	kref_init(&head->ref);
@@ -3816,6 +3816,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
 
 	if (ctrl->opts && ctrl->opts->data_digest)
 		lim.features |= BLK_FEAT_STABLE_WRITES;
+	if (info->is_rmedia)
+		lim.features |= BLK_FEAT_ROTATIONAL;
 	if (ctrl->ops->supports_pci_p2pdma &&
 	    ctrl->ops->supports_pci_p2pdma(ctrl))
 		lim.features |= BLK_FEAT_PCI_P2PDMA;
drivers/nvme/host/multipath.c +3 -0
index 91d9eb3c22ef..a3cd6525d24d 100644
@@ -626,6 +626,9 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
 	head->disk->private_data = head;
 	sprintf(head->disk->disk_name, "nvme%dn%d",
 			ctrl->subsys->instance, head->instance);
+
+	if(head->rmedia)
+		lim.features |= BLK_FEAT_ROTATIONAL;
 	return 0;
 }
 
drivers/nvme/host/nvme.h +1 -0
index f900e44243ae..9f2789c44249 100644
@@ -465,6 +465,7 @@ struct nvme_ns_head {
 	struct list_head	entry;
 	struct kref		ref;
 	bool			shared;
+	bool			rmedia;
 	bool			passthru_err_log_enabled;
 	int			instance;
 	struct nvme_effects_log *effects;
include/linux/nvme.h +1 -0
index c12a329dd463..2c259d126f80 100644
@@ -546,6 +546,7 @@ enum {
 	NVME_NS_FEAT_THIN	= 1 << 0,
 	NVME_NS_FEAT_ATOMICS	= 1 << 1,
 	NVME_NS_FEAT_IO_OPT	= 1 << 4,
+	NVME_INDEP_NS_FEAT_RMEDIA = 1 << 4,
 	NVME_NS_ATTR_RO		= 1 << 0,
 	NVME_NS_FLBAS_LBA_MASK	= 0xf,
 	NVME_NS_FLBAS_LBA_UMASK	= 0x60,
Signature · 1 line
2.36.2
#2 lore raw

Re: [PATCH RFC v2] nvme: basic RMEDIA support for host

Quoted 4 lines · Wang Yugui

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We firstly add Rotational media(RMEDIA) support to nvme host, then we can add the support to nvme target later if the backstore is a Rotational media(RMEDIA) block device.

Why not do that now in another patch, at least for the loop target ? Given that they are not that many NVMe-HDD out there, that would be nice to have to test this.

Quoted 84 lines
---
 drivers/nvme/host/core.c      | 5 +++++
 drivers/nvme/host/multipath.c | 3 +++
 drivers/nvme/host/nvme.h      | 1 +
 include/linux/nvme.h          | 1 +
 4 files changed, 10 insertions(+)
drivers/nvme/host/core.c +5 -0
index 19917253ba7b..f4c41bf70b19 100644
@@ -40,6 +40,7 @@ struct nvme_ns_info {
 	bool is_readonly;
 	bool is_ready;
 	bool is_removed;
+	bool is_rmedia;
 };
 
 unsigned int admin_timeout = 60;
@@ -1622,6 +1623,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,
 		info->is_shared = id->nmic & NVME_NS_NMIC_SHARED;
 		info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
 		info->is_ready = id->nstat & NVME_NSTAT_NRDY;
+		info->is_rmedia = id->nsfeat & NVME_INDEP_NS_FEAT_RMEDIA;
 	}
 	kfree(id);
 	return ret;
@@ -3613,6 +3618,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
 	head->ns_id = info->nsid;
 	head->ids = info->ids;
 	head->shared = info->is_shared;
+	head->rmedia = info->is_rmedia;
 	ratelimit_state_init(&head->rs_nuse, 5 * HZ, 1);
 	ratelimit_set_flags(&head->rs_nuse, RATELIMIT_MSG_ON_RELEASE);
 	kref_init(&head->ref);
@@ -3816,6 +3816,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
 
 	if (ctrl->opts && ctrl->opts->data_digest)
 		lim.features |= BLK_FEAT_STABLE_WRITES;
+	if (info->is_rmedia)
+		lim.features |= BLK_FEAT_ROTATIONAL;
 	if (ctrl->ops->supports_pci_p2pdma &&
 	    ctrl->ops->supports_pci_p2pdma(ctrl))
 		lim.features |= BLK_FEAT_PCI_P2PDMA;
drivers/nvme/host/multipath.c +3 -0
index 91d9eb3c22ef..a3cd6525d24d 100644
@@ -626,6 +626,9 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
 	head->disk->private_data = head;
 	sprintf(head->disk->disk_name, "nvme%dn%d",
 			ctrl->subsys->instance, head->instance);
+
+	if(head->rmedia)
+		lim.features |= BLK_FEAT_ROTATIONAL;
 	return 0;
 }
 
drivers/nvme/host/nvme.h +1 -0
index f900e44243ae..9f2789c44249 100644
@@ -465,6 +465,7 @@ struct nvme_ns_head {
 	struct list_head	entry;
 	struct kref		ref;
 	bool			shared;
+	bool			rmedia;
 	bool			passthru_err_log_enabled;
 	int			instance;
 	struct nvme_effects_log *effects;
include/linux/nvme.h +1 -0
index c12a329dd463..2c259d126f80 100644
@@ -546,6 +546,7 @@ enum {
 	NVME_NS_FEAT_THIN	= 1 << 0,
 	NVME_NS_FEAT_ATOMICS	= 1 << 1,
 	NVME_NS_FEAT_IO_OPT	= 1 << 4,
+	NVME_INDEP_NS_FEAT_RMEDIA = 1 << 4,
 	NVME_NS_ATTR_RO		= 1 << 0,
 	NVME_NS_FLBAS_LBA_MASK	= 0xf,
 	NVME_NS_FLBAS_LBA_UMASK	= 0x60,
Signature · 2 lines
Damien Le Moal
Western Digital Research
author
#3 lore raw

Re: [PATCH RFC v2] nvme: basic RMEDIA support for host

Hi,

Quoted 8 lines · Wang Yugui
Quoted 4 lines

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We firstly add Rotational media(RMEDIA) support to nvme host, then we can add the support to nvme target later if the backstore is a Rotational media(RMEDIA) block device.

Why not do that now in another patch, at least for the loop target ? Given that they are not that many NVMe-HDD out there, that would be nice to have to test this.

Just because yet not enough skill/time now.

Best Regards
Wang Yugui ([email protected])
2024/07/25

#4 lore raw

Re: [PATCH RFC v2] nvme: basic RMEDIA support for host

In reply to Damien Le Moal
Quoted 3 lines · Damien Le Moal

Why not do that now in another patch, at least for the loop target ? Given that they are not that many NVMe-HDD out there, that would be nice to have to test this.

The code would be in the bdev backend, so it applies to all transport equally. And yes, I'd love to see a patch for that to, but I don't want to gate a simple flag check on it.

#5 lore raw

Re: [PATCH RFC v2] nvme: basic RMEDIA support for host

Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Damien Le Moal

Why not do that now in another patch, at least for the loop target ? Given that they are not that many NVMe-HDD out there, that would be nice to have to test this.

The code would be in the bdev backend, so it applies to all transport equally. And yes, I'd love to see a patch for that to, but I don't want to gate a simple flag check on it.

OK. Will look into it then. I have the setup to test this anyway.

That said, while setting only the rotational media bit should be fairly easy, I am worried about spec compliance as setting that flag to 1 mandates support for endurance groups as well. Do we care about this ? I am tempted to say no but not following the specs is generally a dangerous path we do not want to follow...

Signature · 2 lines
Damien Le Moal
Western Digital Research
#6 lore raw

Re: [PATCH RFC v2] nvme: basic RMEDIA support for host

Quoted 10 lines · Damien Le Moal
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Damien Le Moal

Why not do that now in another patch, at least for the loop target ? Given that they are not that many NVMe-HDD out there, that would be nice to have to test this.

The code would be in the bdev backend, so it applies to all transport equally. And yes, I'd love to see a patch for that to, but I don't want to gate a simple flag check on it.

Quoted 7 lines

OK. Will look into it then. I have the setup to test this anyway.

That said, while setting only the rotational media bit should be fairly easy, I am worried about spec compliance as setting that flag to 1 mandates support for endurance groups as well. Do we care about this ? I am tempted to say no but not following the specs is generally a dangerous path we do not want to follow...

I'd got for the usual minimal-viable implementation way like adding static logpages for the endurance group information (with just a single endurance group '1') and for endurance group event aggregate (with no events :-).

Shouldn't blow up the code _that_ much.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
#7 lore raw

Re: [PATCH RFC v2] nvme: basic RMEDIA support for host

In reply to Wang Yugui
Quoted 4 lines · Wang Yugui

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We firstly add Rotational media(RMEDIA) support to nvme host, then we can add the support to nvme target later if the backstore is a Rotational media(RMEDIA) block device.

I'd reword this a bit:

Subject: nvme: add support for the rotational media flag

Add support for the rotational media (RMEDIA) flag in the NVMe 2.0 specification by propagating it to the block layer BLK_FEAT_ROTATIONAL flag.

drivers/nvme/host/core.c struct nvme_ns_info { · line 43

Quoted 1 line
drivers/nvme/host/core.c +1 -0
+	bool is_rmedia;

I'd stick to the Linux 'rotational' terminology here, i.e. is_rotational.

drivers/nvme/host/multipath.c int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head) · line 630

Quoted 1 line
drivers/nvme/host/multipath.c +1 -0
+	if(head->rmedia)

missing whitespace after the if here.

But as blk_stack_limits inherits BLK_FEAT_ROTATIONAL I think this shouldn't even be needed at all.

author
#8 lore raw

RFC PATCH v3 1/1 nvme: basic RMEDIA support for host

In reply to Wang Yugui

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We add Rotational media(RMEDIA) basic support to nvme host firstly.

---
changelog of RFC v3
- rename var based on comments.
change is_rmedia to is_rotational;
but keep RMEDIA of NVME_INDEP_NS_FEAT_RMEDIA to match NVME spec 2.0.

 drivers/nvme/host/core.c      | 5 +++++
 drivers/nvme/host/multipath.c | 3 +++
 drivers/nvme/host/nvme.h      | 1 +
 include/linux/nvme.h          | 1 +
 4 files changed, 10 insertions(+)
drivers/nvme/host/core.c +5 -0
index 19917253ba7b..f4c41bf70b19 100644
@@ -40,6 +40,7 @@ struct nvme_ns_info {
 	bool is_readonly;
 	bool is_ready;
 	bool is_removed;
+	bool is_rotational;
 };
 
 unsigned int admin_timeout = 60;
@@ -1622,6 +1623,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,
 		info->is_shared = id->nmic & NVME_NS_NMIC_SHARED;
 		info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
 		info->is_ready = id->nstat & NVME_NSTAT_NRDY;
+		info->is_rotational = id->nsfeat & NVME_INDEP_NS_FEAT_RMEDIA;
 	}
 	kfree(id);
 	return ret;
@@ -3613,6 +3618,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
 	head->ns_id = info->nsid;
 	head->ids = info->ids;
 	head->shared = info->is_shared;
+	head->rotational = info->is_rotational;
 	ratelimit_state_init(&head->rs_nuse, 5 * HZ, 1);
 	ratelimit_set_flags(&head->rs_nuse, RATELIMIT_MSG_ON_RELEASE);
 	kref_init(&head->ref);
@@ -3816,6 +3816,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
 
 	if (ctrl->opts && ctrl->opts->data_digest)
 		lim.features |= BLK_FEAT_STABLE_WRITES;
+	if (info->is_rotational)
+		lim.features |= BLK_FEAT_ROTATIONAL;
 	if (ctrl->ops->supports_pci_p2pdma &&
 	    ctrl->ops->supports_pci_p2pdma(ctrl))
 		lim.features |= BLK_FEAT_PCI_P2PDMA;
drivers/nvme/host/multipath.c +3 -0
index 91d9eb3c22ef..a3cd6525d24d 100644
@@ -626,6 +626,9 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
 	head->disk->private_data = head;
 	sprintf(head->disk->disk_name, "nvme%dn%d",
 			ctrl->subsys->instance, head->instance);
+
+	if (head->rotational)
+		lim.features |= BLK_FEAT_ROTATIONAL;
 	return 0;
 }
 
drivers/nvme/host/nvme.h +1 -0
index f900e44243ae..9f2789c44249 100644
@@ -465,6 +465,7 @@ struct nvme_ns_head {
 	struct list_head	entry;
 	struct kref		ref;
 	bool			shared;
+	bool			rotational;
 	bool			passthru_err_log_enabled;
 	int			instance;
 	struct nvme_effects_log *effects;
include/linux/nvme.h +1 -0
index c12a329dd463..2c259d126f80 100644
@@ -546,6 +546,7 @@ enum {
 	NVME_NS_FEAT_THIN	= 1 << 0,
 	NVME_NS_FEAT_ATOMICS	= 1 << 1,
 	NVME_NS_FEAT_IO_OPT	= 1 << 4,
+	NVME_INDEP_NS_FEAT_RMEDIA = 1 << 4,
 	NVME_NS_ATTR_RO		= 1 << 0,
 	NVME_NS_FLBAS_LBA_MASK	= 0xf,
 	NVME_NS_FLBAS_LBA_UMASK	= 0x60,
Signature · 1 line
2.36.2
author
#9 lore raw

RFC PATCH 1/1 nvmet: basic RMEDIA support for target

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We add Rotational media(RMEDIA) basic support to nvme target.

---
 drivers/nvme/target/admin-cmd.c   | 50 +++++++++++++++++++++++++++++++
 drivers/nvme/target/core.c        |  2 ++
 drivers/nvme/target/io-cmd-bdev.c |  1 +
 drivers/nvme/target/nvmet.h       |  1 +
 4 files changed, 54 insertions(+)
drivers/nvme/target/admin-cmd.c +50 -0
index f7e1156ac7ec..20a28102f8a0 100644
@@ -489,6 +489,53 @@ 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;
+	}
+
+	/* 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);
+	}
+
+	/*
+	 * 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->anagrpid = cpu_to_le32(req->ns->anagrpid);
+
+	if (req->ns->readonly)
+		id->nsattr |= NVME_NS_ATTR_RO;
+
+	id->nstat |= NVME_NSTAT_NRDY;
+
+	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 +724,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:
drivers/nvme/target/core.c +2 -0
index ed2424f8a396..2790fedb593b 100644
@@ -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);
 }
drivers/nvme/target/io-cmd-bdev.c +1 -0
index 0bda83d0fc3e..d15ad1a864bc 100644
@@ -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);
 
drivers/nvme/target/nvmet.h +1 -0
index 190f55e6d753..86eeeadf3787 100644
@@ -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;
Signature · 1 line
2.36.2
maintainer
#10 lore raw

Re: [PATCH RFC] nvmet: basic RMEDIA support for target

Quoted 97 lines · Wang Yugui

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We add Rotational media(RMEDIA) basic support to nvme target.

---
  drivers/nvme/target/admin-cmd.c   | 50 +++++++++++++++++++++++++++++++
  drivers/nvme/target/core.c        |  2 ++
  drivers/nvme/target/io-cmd-bdev.c |  1 +
  drivers/nvme/target/nvmet.h       |  1 +
  4 files changed, 54 insertions(+)
drivers/nvme/target/admin-cmd.c +50 -0
index f7e1156ac7ec..20a28102f8a0 100644
@@ -489,6 +489,53 @@ 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;
+	}
+
+	/* 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);
+	}
+
+	/*
+	 * 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->anagrpid = cpu_to_le32(req->ns->anagrpid);
+
+	if (req->ns->readonly)
+		id->nsattr |= NVME_NS_ATTR_RO;
+
+	id->nstat |= NVME_NSTAT_NRDY;
+
+	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 +724,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:
drivers/nvme/target/core.c +2 -0
index ed2424f8a396..2790fedb593b 100644
@@ -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);
  }
drivers/nvme/target/io-cmd-bdev.c +0 -0
index 0bda83d0fc3e..d15ad1a864bc 100644

drivers/nvme/target/io-cmd-bdev.c int nvmet_bdev_ns_enable(struct nvmet_ns *ns) · line 107

Quoted 4 lines
drivers/nvme/target/io-cmd-bdev.c +1 -0
@@ -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);

Shouldn't this be !bdev_nonrot(ns->bdev) ?

author
#11 lore raw

Re: [PATCH RFC] nvmet: basic RMEDIA support for target

Hi,

Quoted 94 lines · Wang Yugui
Quoted 92 lines

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We add Rotational media(RMEDIA) basic support to nvme target.

---
  drivers/nvme/target/admin-cmd.c   | 50 +++++++++++++++++++++++++++++++
  drivers/nvme/target/core.c        |  2 ++
  drivers/nvme/target/io-cmd-bdev.c |  1 +
  drivers/nvme/target/nvmet.h       |  1 +
  4 files changed, 54 insertions(+)
drivers/nvme/target/admin-cmd.c +49 -0
index f7e1156ac7ec..20a28102f8a0 100644
@@ -489,6 +489,53 @@ 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;
+	}
+
+	/* 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);
+	}
+
+	/*
+	 * 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->anagrpid = cpu_to_le32(req->ns->anagrpid);
+
+	if (req->ns->readonly)
+		id->nsattr |= NVME_NS_ATTR_RO;
+
+	id->nstat |= NVME_NSTAT_NRDY;
+
+	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 +724,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:
drivers/nvme/target/core.c +1 -0
index ed2424f8a396..2790fedb593b 100644
@@ -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);
  }
drivers/nvme/target/io-cmd-bdev.c +0 -0
index 0bda83d0fc3e..d15ad1a864bc 100644
Quoted 8 lines

drivers/nvme/target/io-cmd-bdev.c int nvmet_bdev_ns_enable(struct nvmet_ns *ns) · line 106

Quoted 6 lines
drivers/nvme/target/io-cmd-bdev.c +1 -0
@@ -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);

Shouldn't this be !bdev_nonrot(ns->bdev) ?

You are right. It will be fixed in next version.

Thanks a lot.

Best Regards
Wang Yugui ([email protected])
2024/08/06

author
#12 lore raw

RFC PATCH v2 1/1 nvmet: basic RMEDIA support for target

In reply to Wang Yugui

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We add Rotational media(RMEDIA) basic support to nvme target.

---
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, 46 insertions(+)
drivers/nvme/target/admin-cmd.c +42 -0
index f7e1156ac7ec..20a28102f8a0 100644
@@ -489,6 +489,45 @@ 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;
+
+	if (!req->ns){
+		goto done;
+	}
+
+	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:
drivers/nvme/target/core.c +2 -0
index ed2424f8a396..2790fedb593b 100644
@@ -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);
 }
drivers/nvme/target/io-cmd-bdev.c +1 -0
index 0bda83d0fc3e..d15ad1a864bc 100644
@@ -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);
 
drivers/nvme/target/nvmet.h +1 -0
index 190f55e6d753..86eeeadf3787 100644
@@ -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;
Signature · 1 line
2.36.2
author
#13 lore raw

RFC PATCH v3 1/1 nvmet: basic RMEDIA support for target

In reply to Wang Yugui

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We add Rotational media(RMEDIA) basic support to nvme target.

---
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(+)
drivers/nvme/target/admin-cmd.c +51 -0
index f7e1156ac7ec..20a28102f8a0 100644
@@ -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:
drivers/nvme/target/core.c +2 -0
index ed2424f8a396..2790fedb593b 100644
@@ -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);
 }
drivers/nvme/target/io-cmd-bdev.c +1 -0
index 0bda83d0fc3e..d15ad1a864bc 100644
@@ -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);
 
drivers/nvme/target/nvmet.h +1 -0
index 190f55e6d753..86eeeadf3787 100644
@@ -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;
Signature · 1 line
2.36.2
maintainer
#14 lore raw

Re: [PATCH RFC v3] nvmet: basic RMEDIA support for target

Quoted 30 lines · Wang Yugui

Rotational media(RMEDIA) support is added to the NVMe 2.0 specification. We add Rotational media(RMEDIA) basic support to nvme target.

---
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(+)
drivers/nvme/target/admin-cmd.c +5 -0
index f7e1156ac7ec..20a28102f8a0 100644
@@ -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;
+

drivers/nvme/target/admin-cmd.c static void nvmet_execute_identify_ctrl(struct nvmet_req *req) · line 506

Quoted 10 lines
drivers/nvme/target/admin-cmd.c +10 -0
+	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.
+	 */

Non useful comment. especially the other users part...

drivers/nvme/target/admin-cmd.c static void nvmet_execute_identify_ctrl(struct nvmet_req *req) · line 508

Quoted 2 lines
drivers/nvme/target/admin-cmd.c +2 -0
+	id->nmic |= NVME_NS_NMIC_SHARED;
+

unneeded newline.

drivers/nvme/target/admin-cmd.c static void nvmet_execute_identify_ctrl(struct nvmet_req *req) · line 516

Quoted 8 lines
drivers/nvme/target/admin-cmd.c +8 -0
+	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;
+	}

I think this should move up to be first...

drivers/nvme/target/admin-cmd.c static void nvmet_execute_identify_ctrl(struct nvmet_req *req) · line 522

Quoted 6 lines
drivers/nvme/target/admin-cmd.c +6 -0
+
+	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);
+	}

This should move down to be last.

Quoted 67 lines
drivers/nvme/target/admin-cmd.c +20 -0
+
+	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:
drivers/nvme/target/core.c +2 -0
index ed2424f8a396..2790fedb593b 100644
@@ -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);
  }
drivers/nvme/target/io-cmd-bdev.c +1 -0
index 0bda83d0fc3e..d15ad1a864bc 100644
@@ -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);
 
drivers/nvme/target/nvmet.h +1 -0
index 190f55e6d753..86eeeadf3787 100644
@@ -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;