@@ -1855,32 +1855,26 @@ static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid,
18551855 return ret ;
18561856}
18571857
1858- static int nvme_init_ms (struct nvme_ctrl * ctrl , struct nvme_ns_head * head ,
1859- struct nvme_id_ns * id )
1858+ static void nvme_init_ms (struct nvme_ctrl * ctrl , struct nvme_ns_head * head ,
1859+ struct nvme_id_ns * id , struct nvme_id_ns_nvm * nvm )
18601860{
18611861 bool first = id -> dps & NVME_NS_DPS_PI_FIRST ;
18621862 unsigned lbaf = nvme_lbaf_index (id -> flbas );
1863- struct nvme_id_ns_nvm * nvm ;
1864- int ret = 0 ;
18651863 u32 elbaf ;
18661864
18671865 head -> pi_size = 0 ;
18681866 head -> ms = le16_to_cpu (id -> lbaf [lbaf ].ms );
1869- if (!(ctrl -> ctratt & NVME_CTRL_ATTR_ELBAS )) {
1867+ if (!nvm || ! (ctrl -> ctratt & NVME_CTRL_ATTR_ELBAS )) {
18701868 head -> pi_size = sizeof (struct t10_pi_tuple );
18711869 head -> guard_type = NVME_NVM_NS_16B_GUARD ;
18721870 goto set_pi ;
18731871 }
18741872
1875- ret = nvme_identify_ns_nvm (ctrl , head -> ns_id , & nvm );
1876- if (ret )
1877- goto set_pi ;
1878-
18791873 elbaf = le32_to_cpu (nvm -> elbaf [lbaf ]);
18801874
18811875 /* no support for storage tag formats right now */
18821876 if (nvme_elbaf_sts (elbaf ))
1883- goto free_data ;
1877+ goto set_pi ;
18841878
18851879 head -> guard_type = nvme_elbaf_guard_type (elbaf );
18861880 switch (head -> guard_type ) {
@@ -1894,8 +1888,6 @@ static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
18941888 break ;
18951889 }
18961890
1897- free_data :
1898- kfree (nvm );
18991891set_pi :
19001892 if (head -> pi_size && head -> ms >= head -> pi_size )
19011893 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,
19061898 head -> pi_offset = 0 ;
19071899 else
19081900 head -> pi_offset = head -> ms - head -> pi_size ;
1909-
1910- return ret ;
19111901}
19121902
1913- static int nvme_configure_metadata (struct nvme_ctrl * ctrl ,
1914- struct nvme_ns_head * head , struct nvme_id_ns * id )
1903+ static void nvme_configure_metadata (struct nvme_ctrl * ctrl ,
1904+ struct nvme_ns_head * head , struct nvme_id_ns * id ,
1905+ struct nvme_id_ns_nvm * nvm )
19151906{
1916- int ret ;
1917-
1918- ret = nvme_init_ms (ctrl , head , id );
1919- if (ret )
1920- return ret ;
1907+ nvme_init_ms (ctrl , head , id , nvm );
19211908
19221909 head -> features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS );
19231910 if (!head -> ms || !(ctrl -> ops -> flags & NVME_F_METADATA_SUPPORTED ))
1924- return 0 ;
1911+ return ;
19251912
19261913 if (ctrl -> ops -> flags & NVME_F_FABRICS ) {
19271914 /*
@@ -1930,7 +1917,7 @@ static int nvme_configure_metadata(struct nvme_ctrl *ctrl,
19301917 * remap the separate metadata buffer from the block layer.
19311918 */
19321919 if (WARN_ON_ONCE (!(id -> flbas & NVME_NS_FLBAS_META_EXT )))
1933- return 0 ;
1920+ return ;
19341921
19351922 head -> features |= NVME_NS_EXT_LBAS ;
19361923
@@ -1957,7 +1944,6 @@ static int nvme_configure_metadata(struct nvme_ctrl *ctrl,
19571944 else
19581945 head -> features |= NVME_NS_METADATA_SUPPORTED ;
19591946 }
1960- return 0 ;
19611947}
19621948
19631949static u32 nvme_max_drv_segments (struct nvme_ctrl * ctrl )
@@ -2092,6 +2078,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
20922078 struct nvme_ns_info * info )
20932079{
20942080 bool vwc = ns -> ctrl -> vwc & NVME_CTRL_VWC_PRESENT ;
2081+ struct nvme_id_ns_nvm * nvm = NULL ;
20952082 struct nvme_id_ns * id ;
20962083 sector_t capacity ;
20972084 unsigned lbaf ;
@@ -2108,19 +2095,20 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
21082095 goto out ;
21092096 }
21102097
2098+ if (ns -> ctrl -> ctratt & NVME_CTRL_ATTR_ELBAS ) {
2099+ ret = nvme_identify_ns_nvm (ns -> ctrl , info -> nsid , & nvm );
2100+ if (ret < 0 )
2101+ goto out ;
2102+ }
2103+
21112104 blk_mq_freeze_queue (ns -> disk -> queue );
21122105 lbaf = nvme_lbaf_index (id -> flbas );
21132106 ns -> head -> lba_shift = id -> lbaf [lbaf ].ds ;
21142107 ns -> head -> nuse = le64_to_cpu (id -> nuse );
21152108 capacity = nvme_lba_to_sect (ns -> head , le64_to_cpu (id -> nsze ));
21162109
21172110 nvme_set_queue_limits (ns -> ctrl , ns -> queue );
2118-
2119- ret = nvme_configure_metadata (ns -> ctrl , ns -> head , id );
2120- if (ret < 0 ) {
2121- blk_mq_unfreeze_queue (ns -> disk -> queue );
2122- goto out ;
2123- }
2111+ nvme_configure_metadata (ns -> ctrl , ns -> head , id , nvm );
21242112 nvme_set_chunk_sectors (ns , id );
21252113 if (!nvme_update_disk_info (ns , id ))
21262114 capacity = 0 ;
@@ -2165,6 +2153,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
21652153
21662154 ret = 0 ;
21672155out :
2156+ kfree (nvm );
21682157 kfree (id );
21692158 return ret ;
21702159}
0 commit comments