From: Christoph Hellwig <hch@lst.de>
To: Hector Martin <marcan@marcan.st>, Sven Peter <sven@svenpeter.dev>,
Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
James Smart <james.smart@broadcom.com>,
Chaitanya Kulkarni <kch@nvidia.com>
Cc: Alyssa Rosenzweig <alyssa@rosenzweig.io>,
asahi@lists.linux.dev, linux-nvme@lists.infradead.org
Subject: [PATCH 12/16] nvme: don't query identify data in configure_metadata
Date: Mon, 4 Mar 2024 07:04:56 -0700 [thread overview]
Message-ID: <20240304140500.78583-13-hch@lst.de> (raw)
In-Reply-To: <20240304140500.78583-1-hch@lst.de>
Move reading the Identify Namespace Data Structure, NVM Command Set out
of configure_metadata into the caller. This allows doing the identify
call outside the frozen I/O queues, and prepares for using data from
the Identify data structure for other purposes.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/host/core.c | 49 ++++++++++++++++------------------------
1 file changed, 19 insertions(+), 30 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9abcc389f0f3ae..a742fa10dd3091 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1855,32 +1855,26 @@ static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid,
return ret;
}
-static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
- struct nvme_id_ns *id)
+static void nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
+ struct nvme_id_ns *id, struct nvme_id_ns_nvm *nvm)
{
bool first = id->dps & NVME_NS_DPS_PI_FIRST;
unsigned lbaf = nvme_lbaf_index(id->flbas);
- struct nvme_id_ns_nvm *nvm;
- int ret = 0;
u32 elbaf;
head->pi_size = 0;
head->ms = le16_to_cpu(id->lbaf[lbaf].ms);
- if (!(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) {
+ if (!nvm || !(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) {
head->pi_size = sizeof(struct t10_pi_tuple);
head->guard_type = NVME_NVM_NS_16B_GUARD;
goto set_pi;
}
- ret = nvme_identify_ns_nvm(ctrl, head->ns_id, &nvm);
- if (ret)
- goto set_pi;
-
elbaf = le32_to_cpu(nvm->elbaf[lbaf]);
/* no support for storage tag formats right now */
if (nvme_elbaf_sts(elbaf))
- goto free_data;
+ goto set_pi;
head->guard_type = nvme_elbaf_guard_type(elbaf);
switch (head->guard_type) {
@@ -1894,8 +1888,6 @@ static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
break;
}
-free_data:
- kfree(nvm);
set_pi:
if (head->pi_size && head->ms >= head->pi_size)
head->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
@@ -1906,22 +1898,17 @@ static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
head->pi_offset = 0;
else
head->pi_offset = head->ms - head->pi_size;
-
- return ret;
}
-static int nvme_configure_metadata(struct nvme_ctrl *ctrl,
- struct nvme_ns_head *head, struct nvme_id_ns *id)
+static void nvme_configure_metadata(struct nvme_ctrl *ctrl,
+ struct nvme_ns_head *head, struct nvme_id_ns *id,
+ struct nvme_id_ns_nvm *nvm)
{
- int ret;
-
- ret = nvme_init_ms(ctrl, head, id);
- if (ret)
- return ret;
+ nvme_init_ms(ctrl, head, id, nvm);
head->features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS);
if (!head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED))
- return 0;
+ return;
if (ctrl->ops->flags & NVME_F_FABRICS) {
/*
@@ -1930,7 +1917,7 @@ static int nvme_configure_metadata(struct nvme_ctrl *ctrl,
* remap the separate metadata buffer from the block layer.
*/
if (WARN_ON_ONCE(!(id->flbas & NVME_NS_FLBAS_META_EXT)))
- return 0;
+ return;
head->features |= NVME_NS_EXT_LBAS;
@@ -1957,7 +1944,6 @@ static int nvme_configure_metadata(struct nvme_ctrl *ctrl,
else
head->features |= NVME_NS_METADATA_SUPPORTED;
}
- return 0;
}
static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl)
@@ -2092,6 +2078,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
struct nvme_ns_info *info)
{
bool vwc = ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT;
+ struct nvme_id_ns_nvm *nvm = NULL;
struct nvme_id_ns *id;
sector_t capacity;
unsigned lbaf;
@@ -2108,6 +2095,12 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
goto out;
}
+ if (ns->ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) {
+ ret = nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm);
+ if (ret < 0)
+ goto out;
+ }
+
blk_mq_freeze_queue(ns->disk->queue);
lbaf = nvme_lbaf_index(id->flbas);
ns->head->lba_shift = id->lbaf[lbaf].ds;
@@ -2115,12 +2108,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
capacity = nvme_lba_to_sect(ns->head, le64_to_cpu(id->nsze));
nvme_set_queue_limits(ns->ctrl, ns->queue);
-
- ret = nvme_configure_metadata(ns->ctrl, ns->head, id);
- if (ret < 0) {
- blk_mq_unfreeze_queue(ns->disk->queue);
- goto out;
- }
+ nvme_configure_metadata(ns->ctrl, ns->head, id, nvm);
nvme_set_chunk_sectors(ns, id);
if (!nvme_update_disk_info(ns, id))
capacity = 0;
@@ -2165,6 +2153,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
ret = 0;
out:
+ kfree(nvm);
kfree(id);
return ret;
}
--
2.39.2
next prev parent reply other threads:[~2024-03-04 15:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-04 14:04 convert nvme to atomic queue limits updates v2 Christoph Hellwig
2024-03-04 14:04 ` [PATCH 01/16] nvme: set max_hw_sectors unconditionally Christoph Hellwig
2024-03-04 15:56 ` John Garry
2024-03-04 14:04 ` [PATCH 02/16] nvme: move NVME_QUIRK_DEALLOCATE_ZEROES out of nvme_config_discard Christoph Hellwig
2024-03-04 14:04 ` [PATCH 03/16] nvme: remove nvme_revalidate_zones Christoph Hellwig
2024-03-04 14:04 ` [PATCH 04/16] nvme: move max_integrity_segments handling out of nvme_init_integrity Christoph Hellwig
2024-03-04 14:04 ` [PATCH 05/16] nvme: cleanup the nvme_init_integrity calling conventions Christoph Hellwig
2024-03-04 14:04 ` [PATCH 06/16] nvme: move blk_integrity_unregister into nvme_init_integrity Christoph Hellwig
2024-03-04 14:04 ` [PATCH 07/16] nvme: don't use nvme_update_disk_info for the multipath disk Christoph Hellwig
2024-03-04 14:04 ` [PATCH 08/16] nvme: move a few things out of nvme_update_disk_info Christoph Hellwig
2024-03-04 14:04 ` [PATCH 09/16] nvme: move setting the write cache flags out of nvme_set_queue_limits Christoph Hellwig
2024-03-04 14:04 ` [PATCH 10/16] nvme: move common logic into nvme_update_ns_info Christoph Hellwig
2024-03-04 14:04 ` [PATCH 11/16] nvme: split out a nvme_identify_ns_nvm helper Christoph Hellwig
2024-03-04 14:04 ` Christoph Hellwig [this message]
2024-03-04 14:04 ` [PATCH 13/16] nvme: cleanup nvme_configure_metadata Christoph Hellwig
2024-03-04 14:04 ` [PATCH 14/16] nvme: use the atomic queue limits update API Christoph Hellwig
2024-03-26 10:24 ` Kanchan Joshi
2024-03-26 14:52 ` Christoph Hellwig
2024-03-04 14:04 ` [PATCH 15/16] nvme-multipath: pass queue_limits to blk_alloc_disk Christoph Hellwig
2024-03-04 14:05 ` [PATCH 16/16] nvme-multipath: use atomic queue limits API for stacking limits Christoph Hellwig
2024-03-04 16:27 ` convert nvme to atomic queue limits updates v2 Keith Busch
2024-03-07 8:39 ` Sagi Grimberg
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=20240304140500.78583-13-hch@lst.de \
--to=hch@lst.de \
--cc=alyssa@rosenzweig.io \
--cc=asahi@lists.linux.dev \
--cc=james.smart@broadcom.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-nvme@lists.infradead.org \
--cc=marcan@marcan.st \
--cc=sagi@grimberg.me \
--cc=sven@svenpeter.dev \
/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