[PATCH] nvme-sysfs: add 'lbaf_index' ns attribute
Tokunori Ikegami
ikegami.t at gmail.com
Sat Sep 21 22:38:18 PDT 2024
The lbaf_index attriute is needed for the format NVM command.
This is to reduce the identify commands to get the information.
Signed-off-by: Tokunori Ikegami <ikegami.t at gmail.com>
---
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(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index ca9959a8fb9e..2cc9876322e6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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));
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 313a4f978a2c..fb1d7c812135 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -483,6 +483,7 @@ struct nvme_ns_head {
u64 zsze;
#endif
unsigned long features;
+ u8 lbaf_index;
struct ratelimit_state rs_nuse;
diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index eb345551d6fe..108b6eda07dc 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -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,
--
2.43.0
More information about the Linux-nvme
mailing list