Skip to content

Commit 9419e71

Browse files
igawkeithbusch
authored andcommitted
nvme: move ns id info to struct nvme_ns_head
Move the namesapce info to struct nvme_ns_head, because it's the same for all associated namespaces. Note: with multipathing enabled the PI information is shared between all paths. If a path is using a different PI configuration it will overwrite the previous settings. This is obviously not correct and such configuration will be rejected in future. For the time being we expect a correctly configured storage. Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Daniel Wagner <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 4ba8b3f commit 9419e71

File tree

5 files changed

+69
-66
lines changed

5 files changed

+69
-66
lines changed

drivers/nvme/host/core.c

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ static void nvme_log_error(struct request *req)
312312
struct nvme_request *nr = nvme_req(req);
313313

314314
if (ns) {
315-
pr_err_ratelimited("%s: %s(0x%x) @ LBA %llu, %llu blocks, %s (sct 0x%x / sc 0x%x) %s%s\n",
315+
pr_err_ratelimited("%s: %s(0x%x) @ LBA %llu, %u blocks, %s (sct 0x%x / sc 0x%x) %s%s\n",
316316
ns->disk ? ns->disk->disk_name : "?",
317317
nvme_get_opcode_str(nr->cmd->common.opcode),
318318
nr->cmd->common.opcode,
319-
(unsigned long long)nvme_sect_to_lba(ns, blk_rq_pos(req)),
320-
(unsigned long long)blk_rq_bytes(req) >> ns->lba_shift,
319+
nvme_sect_to_lba(ns, blk_rq_pos(req)),
320+
blk_rq_bytes(req) >> ns->head->lba_shift,
321321
nvme_get_error_status_str(nr->status),
322322
nr->status >> 8 & 7, /* Status Code Type */
323323
nr->status & 0xff, /* Status Code */
@@ -792,7 +792,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
792792

793793
if (queue_max_discard_segments(req->q) == 1) {
794794
u64 slba = nvme_sect_to_lba(ns, blk_rq_pos(req));
795-
u32 nlb = blk_rq_sectors(req) >> (ns->lba_shift - 9);
795+
u32 nlb = blk_rq_sectors(req) >> (ns->head->lba_shift - 9);
796796

797797
range[0].cattr = cpu_to_le32(0);
798798
range[0].nlb = cpu_to_le32(nlb);
@@ -801,7 +801,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
801801
} else {
802802
__rq_for_each_bio(bio, req) {
803803
u64 slba = nvme_sect_to_lba(ns, bio->bi_iter.bi_sector);
804-
u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift;
804+
u32 nlb = bio->bi_iter.bi_size >> ns->head->lba_shift;
805805

806806
if (n < segments) {
807807
range[n].cattr = cpu_to_le32(0);
@@ -839,7 +839,7 @@ static void nvme_set_ref_tag(struct nvme_ns *ns, struct nvme_command *cmnd,
839839
u64 ref48;
840840

841841
/* both rw and write zeroes share the same reftag format */
842-
switch (ns->guard_type) {
842+
switch (ns->head->guard_type) {
843843
case NVME_NVM_NS_16B_GUARD:
844844
cmnd->rw.reftag = cpu_to_le32(t10_pi_ref_tag(req));
845845
break;
@@ -869,15 +869,16 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
869869
cmnd->write_zeroes.slba =
870870
cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req)));
871871
cmnd->write_zeroes.length =
872-
cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1);
872+
cpu_to_le16((blk_rq_bytes(req) >> ns->head->lba_shift) - 1);
873873

874-
if (!(req->cmd_flags & REQ_NOUNMAP) && (ns->features & NVME_NS_DEAC))
874+
if (!(req->cmd_flags & REQ_NOUNMAP) &&
875+
(ns->head->features & NVME_NS_DEAC))
875876
cmnd->write_zeroes.control |= cpu_to_le16(NVME_WZ_DEAC);
876877

877878
if (nvme_ns_has_pi(ns)) {
878879
cmnd->write_zeroes.control |= cpu_to_le16(NVME_RW_PRINFO_PRACT);
879880

880-
switch (ns->pi_type) {
881+
switch (ns->head->pi_type) {
881882
case NVME_NS_DPS_PI_TYPE1:
882883
case NVME_NS_DPS_PI_TYPE2:
883884
nvme_set_ref_tag(ns, cmnd, req);
@@ -910,12 +911,13 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
910911
cmnd->rw.cdw3 = 0;
911912
cmnd->rw.metadata = 0;
912913
cmnd->rw.slba = cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req)));
913-
cmnd->rw.length = cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1);
914+
cmnd->rw.length =
915+
cpu_to_le16((blk_rq_bytes(req) >> ns->head->lba_shift) - 1);
914916
cmnd->rw.reftag = 0;
915917
cmnd->rw.apptag = 0;
916918
cmnd->rw.appmask = 0;
917919

918-
if (ns->ms) {
920+
if (ns->head->ms) {
919921
/*
920922
* If formated with metadata, the block layer always provides a
921923
* metadata buffer if CONFIG_BLK_DEV_INTEGRITY is enabled. Else
@@ -928,7 +930,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
928930
control |= NVME_RW_PRINFO_PRACT;
929931
}
930932

931-
switch (ns->pi_type) {
933+
switch (ns->head->pi_type) {
932934
case NVME_NS_DPS_PI_TYPE3:
933935
control |= NVME_RW_PRINFO_PRCHK_GUARD;
934936
break;
@@ -1663,9 +1665,9 @@ static void nvme_init_integrity(struct gendisk *disk, struct nvme_ns *ns,
16631665
{
16641666
struct blk_integrity integrity = { };
16651667

1666-
switch (ns->pi_type) {
1668+
switch (ns->head->pi_type) {
16671669
case NVME_NS_DPS_PI_TYPE3:
1668-
switch (ns->guard_type) {
1670+
switch (ns->head->guard_type) {
16691671
case NVME_NVM_NS_16B_GUARD:
16701672
integrity.profile = &t10_pi_type3_crc;
16711673
integrity.tag_size = sizeof(u16) + sizeof(u32);
@@ -1683,7 +1685,7 @@ static void nvme_init_integrity(struct gendisk *disk, struct nvme_ns *ns,
16831685
break;
16841686
case NVME_NS_DPS_PI_TYPE1:
16851687
case NVME_NS_DPS_PI_TYPE2:
1686-
switch (ns->guard_type) {
1688+
switch (ns->head->guard_type) {
16871689
case NVME_NVM_NS_16B_GUARD:
16881690
integrity.profile = &t10_pi_type1_crc;
16891691
integrity.tag_size = sizeof(u16);
@@ -1704,7 +1706,7 @@ static void nvme_init_integrity(struct gendisk *disk, struct nvme_ns *ns,
17041706
break;
17051707
}
17061708

1707-
integrity.tuple_size = ns->ms;
1709+
integrity.tuple_size = ns->head->ms;
17081710
blk_integrity_register(disk, &integrity);
17091711
blk_queue_max_integrity_segments(disk->queue, max_integrity_segments);
17101712
}
@@ -1763,11 +1765,11 @@ static int nvme_init_ms(struct nvme_ns *ns, struct nvme_id_ns *id)
17631765
int ret = 0;
17641766
u32 elbaf;
17651767

1766-
ns->pi_size = 0;
1767-
ns->ms = le16_to_cpu(id->lbaf[lbaf].ms);
1768+
ns->head->pi_size = 0;
1769+
ns->head->ms = le16_to_cpu(id->lbaf[lbaf].ms);
17681770
if (!(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) {
1769-
ns->pi_size = sizeof(struct t10_pi_tuple);
1770-
ns->guard_type = NVME_NVM_NS_16B_GUARD;
1771+
ns->head->pi_size = sizeof(struct t10_pi_tuple);
1772+
ns->head->guard_type = NVME_NVM_NS_16B_GUARD;
17711773
goto set_pi;
17721774
}
17731775

@@ -1790,13 +1792,13 @@ static int nvme_init_ms(struct nvme_ns *ns, struct nvme_id_ns *id)
17901792
if (nvme_elbaf_sts(elbaf))
17911793
goto free_data;
17921794

1793-
ns->guard_type = nvme_elbaf_guard_type(elbaf);
1794-
switch (ns->guard_type) {
1795+
ns->head->guard_type = nvme_elbaf_guard_type(elbaf);
1796+
switch (ns->head->guard_type) {
17951797
case NVME_NVM_NS_64B_GUARD:
1796-
ns->pi_size = sizeof(struct crc64_pi_tuple);
1798+
ns->head->pi_size = sizeof(struct crc64_pi_tuple);
17971799
break;
17981800
case NVME_NVM_NS_16B_GUARD:
1799-
ns->pi_size = sizeof(struct t10_pi_tuple);
1801+
ns->head->pi_size = sizeof(struct t10_pi_tuple);
18001802
break;
18011803
default:
18021804
break;
@@ -1805,10 +1807,10 @@ static int nvme_init_ms(struct nvme_ns *ns, struct nvme_id_ns *id)
18051807
free_data:
18061808
kfree(nvm);
18071809
set_pi:
1808-
if (ns->pi_size && (first || ns->ms == ns->pi_size))
1809-
ns->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
1810+
if (ns->head->pi_size && (first || ns->head->ms == ns->head->pi_size))
1811+
ns->head->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
18101812
else
1811-
ns->pi_type = 0;
1813+
ns->head->pi_type = 0;
18121814

18131815
return ret;
18141816
}
@@ -1822,8 +1824,8 @@ static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
18221824
if (ret)
18231825
return ret;
18241826

1825-
ns->features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS);
1826-
if (!ns->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED))
1827+
ns->head->features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS);
1828+
if (!ns->head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED))
18271829
return 0;
18281830

18291831
if (ctrl->ops->flags & NVME_F_FABRICS) {
@@ -1835,7 +1837,7 @@ static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
18351837
if (WARN_ON_ONCE(!(id->flbas & NVME_NS_FLBAS_META_EXT)))
18361838
return 0;
18371839

1838-
ns->features |= NVME_NS_EXT_LBAS;
1840+
ns->head->features |= NVME_NS_EXT_LBAS;
18391841

18401842
/*
18411843
* The current fabrics transport drivers support namespace
@@ -1847,7 +1849,7 @@ static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
18471849
* gain the ability to use other metadata formats.
18481850
*/
18491851
if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns))
1850-
ns->features |= NVME_NS_METADATA_SUPPORTED;
1852+
ns->head->features |= NVME_NS_METADATA_SUPPORTED;
18511853
} else {
18521854
/*
18531855
* For PCIe controllers, we can't easily remap the separate
@@ -1856,9 +1858,9 @@ static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
18561858
* We allow extended LBAs for the passthrough interface, though.
18571859
*/
18581860
if (id->flbas & NVME_NS_FLBAS_META_EXT)
1859-
ns->features |= NVME_NS_EXT_LBAS;
1861+
ns->head->features |= NVME_NS_EXT_LBAS;
18601862
else
1861-
ns->features |= NVME_NS_METADATA_SUPPORTED;
1863+
ns->head->features |= NVME_NS_METADATA_SUPPORTED;
18621864
}
18631865
return 0;
18641866
}
@@ -1885,14 +1887,14 @@ static void nvme_update_disk_info(struct gendisk *disk,
18851887
struct nvme_ns *ns, struct nvme_id_ns *id)
18861888
{
18871889
sector_t capacity = nvme_lba_to_sect(ns, le64_to_cpu(id->nsze));
1888-
u32 bs = 1U << ns->lba_shift;
1890+
u32 bs = 1U << ns->head->lba_shift;
18891891
u32 atomic_bs, phys_bs, io_opt = 0;
18901892

18911893
/*
18921894
* The block layer can't support LBA sizes larger than the page size
18931895
* yet, so catch this early and don't allow block I/O.
18941896
*/
1895-
if (ns->lba_shift > PAGE_SHIFT) {
1897+
if (ns->head->lba_shift > PAGE_SHIFT) {
18961898
capacity = 0;
18971899
bs = (1 << 9);
18981900
}
@@ -1935,9 +1937,9 @@ static void nvme_update_disk_info(struct gendisk *disk,
19351937
* I/O to namespaces with metadata except when the namespace supports
19361938
* PI, as it can strip/insert in that case.
19371939
*/
1938-
if (ns->ms) {
1940+
if (ns->head->ms) {
19391941
if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
1940-
(ns->features & NVME_NS_METADATA_SUPPORTED))
1942+
(ns->head->features & NVME_NS_METADATA_SUPPORTED))
19411943
nvme_init_integrity(disk, ns,
19421944
ns->ctrl->max_integrity_segments);
19431945
else if (!nvme_ns_has_pi(ns))
@@ -2031,7 +2033,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
20312033

20322034
blk_mq_freeze_queue(ns->disk->queue);
20332035
lbaf = nvme_lbaf_index(id->flbas);
2034-
ns->lba_shift = id->lbaf[lbaf].ds;
2036+
ns->head->lba_shift = id->lbaf[lbaf].ds;
20352037
nvme_set_queue_limits(ns->ctrl, ns->queue);
20362038

20372039
ret = nvme_configure_metadata(ns, id);
@@ -2057,7 +2059,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
20572059
* do not return zeroes.
20582060
*/
20592061
if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3)))
2060-
ns->features |= NVME_NS_DEAC;
2062+
ns->head->features |= NVME_NS_DEAC;
20612063
set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info));
20622064
set_bit(NVME_NS_READY, &ns->flags);
20632065
blk_mq_unfreeze_queue(ns->disk->queue);

drivers/nvme/host/ioctl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
224224
return -EINVAL;
225225
}
226226

227-
length = (io.nblocks + 1) << ns->lba_shift;
227+
length = (io.nblocks + 1) << ns->head->lba_shift;
228228

229229
if ((io.control & NVME_RW_PRINFO_PRACT) &&
230-
ns->ms == sizeof(struct t10_pi_tuple)) {
230+
ns->head->ms == sizeof(struct t10_pi_tuple)) {
231231
/*
232232
* Protection information is stripped/inserted by the
233233
* controller.
@@ -237,11 +237,11 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
237237
meta_len = 0;
238238
metadata = NULL;
239239
} else {
240-
meta_len = (io.nblocks + 1) * ns->ms;
240+
meta_len = (io.nblocks + 1) * ns->head->ms;
241241
metadata = nvme_to_user_ptr(io.metadata);
242242
}
243243

244-
if (ns->features & NVME_NS_EXT_LBAS) {
244+
if (ns->head->features & NVME_NS_EXT_LBAS) {
245245
length += meta_len;
246246
meta_len = 0;
247247
} else if (meta_len) {

drivers/nvme/host/nvme.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,17 @@ struct nvme_ns_head {
446446
bool shared;
447447
int instance;
448448
struct nvme_effects_log *effects;
449+
int lba_shift;
450+
u16 ms;
451+
u16 pi_size;
452+
u16 sgs;
453+
u32 sws;
454+
u8 pi_type;
455+
u8 guard_type;
456+
#ifdef CONFIG_BLK_DEV_ZONED
457+
u64 zsze;
458+
#endif
459+
unsigned long features;
449460

450461
struct cdev cdev;
451462
struct device cdev_device;
@@ -487,17 +498,6 @@ struct nvme_ns {
487498
struct kref kref;
488499
struct nvme_ns_head *head;
489500

490-
int lba_shift;
491-
u16 ms;
492-
u16 pi_size;
493-
u16 sgs;
494-
u32 sws;
495-
u8 pi_type;
496-
u8 guard_type;
497-
#ifdef CONFIG_BLK_DEV_ZONED
498-
u64 zsze;
499-
#endif
500-
unsigned long features;
501501
unsigned long flags;
502502
#define NVME_NS_REMOVING 0
503503
#define NVME_NS_ANA_PENDING 2
@@ -514,7 +514,7 @@ struct nvme_ns {
514514
/* NVMe ns supports metadata actions by the controller (generate/strip) */
515515
static inline bool nvme_ns_has_pi(struct nvme_ns *ns)
516516
{
517-
return ns->pi_type && ns->ms == ns->pi_size;
517+
return ns->head->pi_type && ns->head->ms == ns->head->pi_size;
518518
}
519519

520520
struct nvme_ctrl_ops {
@@ -648,15 +648,15 @@ static inline int nvme_reset_subsystem(struct nvme_ctrl *ctrl)
648648
*/
649649
static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector)
650650
{
651-
return sector >> (ns->lba_shift - SECTOR_SHIFT);
651+
return sector >> (ns->head->lba_shift - SECTOR_SHIFT);
652652
}
653653

654654
/*
655655
* Convert a device logical block number to a 512B sector number.
656656
*/
657657
static inline sector_t nvme_lba_to_sect(struct nvme_ns *ns, u64 lba)
658658
{
659-
return lba << (ns->lba_shift - SECTOR_SHIFT);
659+
return lba << (ns->head->lba_shift - SECTOR_SHIFT);
660660
}
661661

662662
/*

drivers/nvme/host/rdma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ static int nvme_rdma_map_sg_pi(struct nvme_rdma_queue *queue,
14181418
goto mr_put;
14191419

14201420
nvme_rdma_set_sig_attrs(blk_get_integrity(bio->bi_bdev->bd_disk), c,
1421-
req->mr->sig_attrs, ns->pi_type);
1421+
req->mr->sig_attrs, ns->head->pi_type);
14221422
nvme_rdma_set_prot_checks(c, &req->mr->sig_attrs->check_mask);
14231423

14241424
ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey));

0 commit comments

Comments
 (0)