Skip to content

Commit a5b1cd6

Browse files
Christoph Hellwigkeithbusch
authored andcommitted
nvme: move a few things out of nvme_update_disk_info
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> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 8f03cfa commit a5b1cd6

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

drivers/nvme/host/core.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,21 +1965,22 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
19651965
blk_queue_write_cache(q, vwc, vwc);
19661966
}
19671967

1968-
static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk,
1969-
struct nvme_ns_head *head, struct nvme_id_ns *id)
1968+
static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id)
19701969
{
1971-
sector_t capacity = nvme_lba_to_sect(head, le64_to_cpu(id->nsze));
1970+
struct gendisk *disk = ns->disk;
1971+
struct nvme_ns_head *head = ns->head;
19721972
u32 bs = 1U << head->lba_shift;
19731973
u32 atomic_bs, phys_bs, io_opt = 0;
1974+
bool valid = true;
19741975

19751976
/*
19761977
* The block layer can't support LBA sizes larger than the page size
19771978
* or smaller than a sector size yet, so catch this early and don't
19781979
* allow block I/O.
19791980
*/
19801981
if (head->lba_shift > PAGE_SHIFT || head->lba_shift < SECTOR_SHIFT) {
1981-
capacity = 0;
19821982
bs = (1 << 9);
1983+
valid = false;
19831984
}
19841985

19851986
atomic_bs = phys_bs = bs;
@@ -1992,7 +1993,7 @@ static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk,
19921993
if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf)
19931994
atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs;
19941995
else
1995-
atomic_bs = (1 + ctrl->subsys->awupf) * bs;
1996+
atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs;
19961997
}
19971998

19981999
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,
20122013
blk_queue_io_min(disk->queue, phys_bs);
20132014
blk_queue_io_opt(disk->queue, io_opt);
20142015

2015-
/*
2016-
* Register a metadata profile for PI, or the plain non-integrity NVMe
2017-
* metadata masquerading as Type 0 if supported, otherwise reject block
2018-
* I/O to namespaces with metadata except when the namespace supports
2019-
* PI, as it can strip/insert in that case.
2020-
*/
2021-
if (!nvme_init_integrity(disk, head))
2022-
capacity = 0;
2023-
2024-
set_capacity_and_notify(disk, capacity);
2025-
2026-
nvme_config_discard(ctrl, disk, head);
2016+
nvme_config_discard(ns->ctrl, disk, head);
20272017

2028-
if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
2018+
if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
20292019
blk_queue_max_write_zeroes_sectors(disk->queue, UINT_MAX);
20302020
else
20312021
blk_queue_max_write_zeroes_sectors(disk->queue,
2032-
ctrl->max_zeroes_sectors);
2022+
ns->ctrl->max_zeroes_sectors);
2023+
return valid;
20332024
}
20342025

20352026
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,
21032094
struct nvme_ns_info *info)
21042095
{
21052096
struct nvme_id_ns *id;
2097+
sector_t capacity;
21062098
unsigned lbaf;
21072099
int ret;
21082100

@@ -2121,6 +2113,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
21212113
lbaf = nvme_lbaf_index(id->flbas);
21222114
ns->head->lba_shift = id->lbaf[lbaf].ds;
21232115
ns->head->nuse = le64_to_cpu(id->nuse);
2116+
capacity = nvme_lba_to_sect(ns->head, le64_to_cpu(id->nsze));
2117+
21242118
nvme_set_queue_limits(ns->ctrl, ns->queue);
21252119

21262120
ret = nvme_configure_metadata(ns->ctrl, ns->head, id);
@@ -2129,7 +2123,19 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
21292123
goto out;
21302124
}
21312125
nvme_set_chunk_sectors(ns, id);
2132-
nvme_update_disk_info(ns->ctrl, ns->disk, ns->head, id);
2126+
if (!nvme_update_disk_info(ns, id))
2127+
capacity = 0;
2128+
2129+
/*
2130+
* Register a metadata profile for PI, or the plain non-integrity NVMe
2131+
* metadata masquerading as Type 0 if supported, otherwise reject block
2132+
* I/O to namespaces with metadata except when the namespace supports
2133+
* PI, as it can strip/insert in that case.
2134+
*/
2135+
if (!nvme_init_integrity(ns->disk, ns->head))
2136+
capacity = 0;
2137+
2138+
set_capacity_and_notify(ns->disk, capacity);
21332139

21342140
if (ns->head->ids.csi == NVME_CSI_ZNS) {
21352141
ret = nvme_update_zone_info(ns, lbaf);

0 commit comments

Comments
 (0)