Skip to contentSkip to conversation

nvme-sysfs: add 'lbaf_index' ns attribute

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-sysfs: add 'lbaf_index' ns attribute

The lbaf_index attriute is needed for the format NVM command. This is to reduce the identify commands to get the information.

---
 drivers/nvme/host/core.c  | 5 +++--
 drivers/nvme/host/nvme.h  | 1 +
 drivers/nvme/host/sysfs.c | 7 +++++++
 3 files changed, 11 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +3 -2
index ca9959a8fb9e..2cc9876322e6 100644
@@ -1909,7 +1909,7 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl,
 	head->features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS);
 	head->pi_type = 0;
 	head->pi_size = 0;
-	head->ms = le16_to_cpu(id->lbaf[nvme_lbaf_index(id->flbas)].ms);
+	head->ms = le16_to_cpu(id->lbaf[head->lbaf_index].ms);
 	if (!head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED))
 		return;
 
@@ -2151,7 +2151,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 	}
 
 	blk_mq_freeze_queue(ns->disk->queue);
-	ns->head->lba_shift = id->lbaf[lbaf].ds;
+	ns->head->lbaf_index = lbaf;
+	ns->head->lba_shift = id->lbaf[ns->head->lbaf_index].ds;
 	ns->head->nuse = le64_to_cpu(id->nuse);
 	capacity = nvme_lba_to_sect(ns->head, le64_to_cpu(id->nsze));
 
drivers/nvme/host/nvme.h +1 -0
index 313a4f978a2c..fb1d7c812135 100644
@@ -483,6 +483,7 @@ struct nvme_ns_head {
 	u64			zsze;
 #endif
 	unsigned long		features;
+	u8			lbaf_index;
 
 	struct ratelimit_state	rs_nuse;
 
drivers/nvme/host/sysfs.c +7 -0
index eb345551d6fe..108b6eda07dc 100644
@@ -246,6 +246,12 @@ static ssize_t nuse_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(nuse);
 
+static ssize_t lbaf_index_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%u\n", dev_to_ns_head(dev)->lbaf_index);
+}
+static DEVICE_ATTR_RO(lbaf_index);
+
 static struct attribute *nvme_ns_attrs[] = {
 	&dev_attr_wwid.attr,
 	&dev_attr_uuid.attr,
@@ -255,6 +261,7 @@ static struct attribute *nvme_ns_attrs[] = {
 	&dev_attr_nsid.attr,
 	&dev_attr_metadata_bytes.attr,
 	&dev_attr_nuse.attr,
+	&dev_attr_lbaf_index.attr,
 #ifdef CONFIG_NVME_MULTIPATH
 	&dev_attr_ana_grpid.attr,
 	&dev_attr_ana_state.attr,
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 2 lines · Tokunori Ikegami

The lbaf_index attriute is needed for the format NVM command. This is to reduce the identify commands to get the information.

I'm not sure how knowing this is particularly useful. You'd have to run the identify namespace command anyway to understand the significance of what the index tells you.

#2 lore raw

The format command only uses the LBAF index so the attribute can be used by the command. About the LBAFs list I will do consider to add into the ns attribute, etc. if needed later. Thank you.

Quoted 6 lines · Keith Busch
Quoted 2 lines · Tokunori Ikegami

The lbaf_index attriute is needed for the format NVM command. This is to reduce the identify commands to get the information.

I'm not sure how knowing this is particularly useful. You'd have to run the identify namespace command anyway to understand the significance of what the index tells you.