Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tokunori Ikegami <ikegami.t@gmail.com>
To: linux-nvme@lists.infradead.org
Cc: Tokunori Ikegami <ikegami.t@gmail.com>
Subject: [PATCH] nvme-sysfs: add 'lbaf_index' ns attribute
Date: Sun, 22 Sep 2024 14:38:18 +0900	[thread overview]
Message-ID: <20240922053850.5494-1-ikegami.t@gmail.com> (raw)

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@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



             reply	other threads:[~2024-09-22  5:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-22  5:38 Tokunori Ikegami [this message]
2024-09-22 15:29 ` [PATCH] nvme-sysfs: add 'lbaf_index' ns attribute Keith Busch
2024-09-22 18:44   ` Tokunori Ikegami

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=20240922053850.5494-1-ikegami.t@gmail.com \
    --to=ikegami.t@gmail.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