Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
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 10/21] nvme: move a few things out of nvme_update_disk_info
Date: Wed, 28 Feb 2024 10:12:04 -0800	[thread overview]
Message-ID: <20240228181215.873854-11-hch@lst.de> (raw)
In-Reply-To: <20240228181215.873854-1-hch@lst.de>

Move setting up the integrity profile and setting the disk capacity out
of nvme_update_disk_info to get nvme_update_disk_info into a shape where
it just sets queue_limits eventually.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/nvme/host/core.c | 46 +++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 0bf30580f29d5b..3d839945edd85d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1965,12 +1965,13 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
 	blk_queue_write_cache(q, vwc, vwc);
 }
 
-static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk,
-		struct nvme_ns_head *head, struct nvme_id_ns *id)
+static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id)
 {
-	sector_t capacity = nvme_lba_to_sect(head, le64_to_cpu(id->nsze));
+	struct gendisk *disk = ns->disk;
+	struct nvme_ns_head *head = ns->head;
 	u32 bs = 1U << head->lba_shift;
 	u32 atomic_bs, phys_bs, io_opt = 0;
+	bool valid = true;
 
 	/*
 	 * The block layer can't support LBA sizes larger than the page size
@@ -1978,8 +1979,8 @@ static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk,
 	 * allow block I/O.
 	 */
 	if (head->lba_shift > PAGE_SHIFT || head->lba_shift < SECTOR_SHIFT) {
-		capacity = 0;
 		bs = (1 << 9);
+		valid = false;
 	}
 
 	atomic_bs = phys_bs = bs;
@@ -1992,7 +1993,7 @@ static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk,
 		if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf)
 			atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs;
 		else
-			atomic_bs = (1 + ctrl->subsys->awupf) * bs;
+			atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs;
 	}
 
 	if (id->nsfeat & NVME_NS_FEAT_IO_OPT) {
@@ -2012,24 +2013,14 @@ static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk,
 	blk_queue_io_min(disk->queue, phys_bs);
 	blk_queue_io_opt(disk->queue, io_opt);
 
-	/*
-	 * Register a metadata profile for PI, or the plain non-integrity NVMe
-	 * metadata masquerading as Type 0 if supported, otherwise reject block
-	 * I/O to namespaces with metadata except when the namespace supports
-	 * PI, as it can strip/insert in that case.
-	 */
-	if (!nvme_init_integrity(disk, head))
-		capacity = 0;
-
-	set_capacity_and_notify(disk, capacity);
-
-	nvme_config_discard(ctrl, disk, head);
+	nvme_config_discard(ns->ctrl, disk, head);
 
-	if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
+	if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
 		blk_queue_max_write_zeroes_sectors(disk->queue, UINT_MAX);
 	else
 		blk_queue_max_write_zeroes_sectors(disk->queue,
-				ctrl->max_zeroes_sectors);
+				ns->ctrl->max_zeroes_sectors);
+	return valid;
 }
 
 static bool nvme_ns_is_readonly(struct nvme_ns *ns, struct nvme_ns_info *info)
@@ -2103,6 +2094,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 		struct nvme_ns_info *info)
 {
 	struct nvme_id_ns *id;
+	sector_t capacity;
 	unsigned lbaf;
 	int ret;
 
@@ -2121,6 +2113,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 	lbaf = nvme_lbaf_index(id->flbas);
 	ns->head->lba_shift = id->lbaf[lbaf].ds;
 	ns->head->nuse = le64_to_cpu(id->nuse);
+	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);
@@ -2129,7 +2123,19 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 		goto out;
 	}
 	nvme_set_chunk_sectors(ns, id);
-	nvme_update_disk_info(ns->ctrl, ns->disk, ns->head, id);
+	if (!nvme_update_disk_info(ns, id))
+		capacity = 0;
+
+	/*
+	 * Register a metadata profile for PI, or the plain non-integrity NVMe
+	 * metadata masquerading as Type 0 if supported, otherwise reject block
+	 * I/O to namespaces with metadata except when the namespace supports
+	 * PI, as it can strip/insert in that case.
+	 */
+	if (!nvme_init_integrity(ns->disk, ns->head))
+		capacity = 0;
+
+	set_capacity_and_notify(ns->disk, capacity);
 
 	if (ns->head->ids.csi == NVME_CSI_ZNS) {
 		ret = nvme_update_zone_info(ns, lbaf);
-- 
2.39.2



  parent reply	other threads:[~2024-02-28 18:12 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 18:11 convert nvme to atomic queue limits updates Christoph Hellwig
2024-02-28 18:11 ` [PATCH 01/21] block: add a queue_limits_set helper Christoph Hellwig
2024-02-28 18:11 ` [PATCH 02/21] block: add a queue_limits_stack_bdev helper Christoph Hellwig
2024-02-28 18:11 ` [PATCH 03/21] nvme: set max_hw_sectors unconditionally Christoph Hellwig
2024-02-29 10:46   ` Max Gurtovoy
2024-02-28 18:11 ` [PATCH 04/21] nvme: move NVME_QUIRK_DEALLOCATE_ZEROES out of nvme_config_discard Christoph Hellwig
2024-02-29 10:48   ` Max Gurtovoy
2024-02-28 18:11 ` [PATCH 05/21] nvme: remove nvme_revalidate_zones Christoph Hellwig
2024-02-28 23:47   ` Damien Le Moal
2024-02-28 18:12 ` [PATCH 06/21] nvme: move max_integrity_segments handling out of nvme_init_integrity Christoph Hellwig
2024-02-29 10:58   ` Max Gurtovoy
2024-02-28 18:12 ` [PATCH 07/21] nvme: cleanup the nvme_init_integrity calling conventions Christoph Hellwig
2024-02-29 12:33   ` Max Gurtovoy
2024-02-28 18:12 ` [PATCH 08/21] nvme: move blk_integrity_unregister into nvme_init_integrity Christoph Hellwig
2024-02-29 12:36   ` Max Gurtovoy
2024-02-28 18:12 ` [PATCH 09/21] nvme: don't use nvme_update_disk_info for the multipath disk Christoph Hellwig
2024-02-29 12:47   ` Max Gurtovoy
2024-02-29 13:02     ` Max Gurtovoy
2024-02-28 18:12 ` Christoph Hellwig [this message]
2024-02-28 18:12 ` [PATCH 11/21] nvme: move setting the write cache flags out of nvme_set_queue_limits Christoph Hellwig
2024-02-29 13:11   ` Max Gurtovoy
2024-02-28 18:12 ` [PATCH 12/21] nvme: move common logic into nvme_update_ns_info Christoph Hellwig
2024-02-29 13:30   ` Max Gurtovoy
2024-02-29 13:40     ` Christoph Hellwig
2024-02-28 18:12 ` [PATCH 13/21] nvme: split out a nvme_identify_ns_nvm helper Christoph Hellwig
2024-02-29 13:52   ` Max Gurtovoy
2024-02-29 13:53     ` Christoph Hellwig
2024-02-28 18:12 ` [PATCH 14/21] nvme: don't query identify data in configure_metadata Christoph Hellwig
2024-02-28 18:12 ` [PATCH 15/21] nvme: cleanup nvme_configure_metadata Christoph Hellwig
2024-02-28 18:12 ` [PATCH 16/21] nvme-rdma: initialize max_hw_sectors earlier Christoph Hellwig
2024-02-28 18:12 ` [PATCH 17/21] nvme-loop: " Christoph Hellwig
2024-02-28 18:12 ` [PATCH 18/21] nvme-fc: " Christoph Hellwig
2024-02-28 18:12 ` [PATCH 19/21] nvme-apple: " Christoph Hellwig
2024-02-28 18:12 ` [PATCH 20/21] nvme: use the atomic queue limits update API Christoph Hellwig
2024-02-28 18:12 ` [PATCH 21/21] nvme-multipath: pass queue_limits to blk_alloc_disk Christoph Hellwig
2024-03-01 16:20 ` convert nvme to atomic queue limits updates Keith Busch
2024-03-02 13:59   ` Christoph Hellwig
2024-03-02 23:21     ` Keith Busch

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=20240228181215.873854-11-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