Skip to contentSkip to conversation

nvme-sysfs: add 'fna' attribute

PATCH In review Tokunori Ikegami 2 participants 3 messages Sep 21, 2024 – Sep 22, 2024 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-sysfs: add 'fna' attribute

The fna attriute is needed for the format NVM command.

---
 drivers/nvme/host/core.c  |  1 +
 drivers/nvme/host/nvme.h  |  1 +
 drivers/nvme/host/sysfs.c | 13 +++++++++++++
 3 files changed, 15 insertions(+)
drivers/nvme/host/core.c +1 -0
index ca9959a8fb9e..0ecb7cbabbed 100644
@@ -3302,6 +3302,7 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
 	ctrl->cctemp = le16_to_cpu(id->cctemp);
 
 	atomic_set(&ctrl->abort_limit, id->acl + 1);
+	ctrl->fna = id->fna;
 	ctrl->vwc = id->vwc;
 	if (id->mdts)
 		max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts);
drivers/nvme/host/nvme.h +1 -0
index 313a4f978a2c..3df0fbaadb04 100644
@@ -328,6 +328,7 @@ struct nvme_ctrl {
 	u16 sqsize;
 	u32 max_namespaces;
 	atomic_t abort_limit;
+	u8 fna;
 	u8 vwc;
 	u32 vs;
 	u32 sgls;
drivers/nvme/host/sysfs.c +13 -0
index eb345551d6fe..816a869306df 100644
@@ -546,6 +546,18 @@ static ssize_t dctype_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(dctype);
 
+static ssize_t fna_show(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	if (ctrl->fna)
+		return sysfs_emit(buf, "%02x\n", ctrl->fna);
+
+	return 0;
+}
+static DEVICE_ATTR_RO(fna);
+
 #ifdef CONFIG_NVME_HOST_AUTH
 static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -687,6 +699,7 @@ static struct attribute *nvme_dev_attrs[] = {
 	&dev_attr_kato.attr,
 	&dev_attr_cntrltype.attr,
 	&dev_attr_dctype.attr,
+	&dev_attr_fna.attr,
 #ifdef CONFIG_NVME_HOST_AUTH
 	&dev_attr_dhchap_secret.attr,
 	&dev_attr_dhchap_ctrl_secret.attr,
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 1 line · Tokunori Ikegami

The fna attriute is needed for the format NVM command.

At least for multi-namespace subsystems, I would agree knowing this value is important to understand the potentially undesired reprecussions of running a format command, but that logic ought to just go in tooling. And the meaning of the reported value here is not immediately obvious to a typical user without the spec in front of you, so I'm a little skeptical on exporting this attribute.

nvme-cli already checks this on a format request, at least. You probably are not formatting very frequently anyway, so avoiding an identify command for such a low frequency event seems a bit overkill to me.

#2 lore raw

There are many identify commands fields so if the nvme driver can be kept the field values seems can be reduced to run many identify commands. Thank you.

Quoted 10 lines · Keith Busch

At least for multi-namespace subsystems, I would agree knowing this value is important to understand the potentially undesired reprecussions of running a format command, but that logic ought to just go in tooling. And the meaning of the reported value here is not immediately obvious to a typical user without the spec in front of you, so I'm a little skeptical on exporting this attribute.

nvme-cli already checks this on a format request, at least. You probably are not formatting very frequently anyway, so avoiding an identify command for such a low frequency event seems a bit overkill to me.