@@ -1855,32 +1855,26 @@ static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid,
1855
1855
return ret ;
1856
1856
}
1857
1857
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 )
1860
1860
{
1861
1861
bool first = id -> dps & NVME_NS_DPS_PI_FIRST ;
1862
1862
unsigned lbaf = nvme_lbaf_index (id -> flbas );
1863
- struct nvme_id_ns_nvm * nvm ;
1864
- int ret = 0 ;
1865
1863
u32 elbaf ;
1866
1864
1867
1865
head -> pi_size = 0 ;
1868
1866
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 )) {
1870
1868
head -> pi_size = sizeof (struct t10_pi_tuple );
1871
1869
head -> guard_type = NVME_NVM_NS_16B_GUARD ;
1872
1870
goto set_pi ;
1873
1871
}
1874
1872
1875
- ret = nvme_identify_ns_nvm (ctrl , head -> ns_id , & nvm );
1876
- if (ret )
1877
- goto set_pi ;
1878
-
1879
1873
elbaf = le32_to_cpu (nvm -> elbaf [lbaf ]);
1880
1874
1881
1875
/* no support for storage tag formats right now */
1882
1876
if (nvme_elbaf_sts (elbaf ))
1883
- goto free_data ;
1877
+ goto set_pi ;
1884
1878
1885
1879
head -> guard_type = nvme_elbaf_guard_type (elbaf );
1886
1880
switch (head -> guard_type ) {
@@ -1894,8 +1888,6 @@ static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
1894
1888
break ;
1895
1889
}
1896
1890
1897
- free_data :
1898
- kfree (nvm );
1899
1891
set_pi :
1900
1892
if (head -> pi_size && head -> ms >= head -> pi_size )
1901
1893
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,
1906
1898
head -> pi_offset = 0 ;
1907
1899
else
1908
1900
head -> pi_offset = head -> ms - head -> pi_size ;
1909
-
1910
- return ret ;
1911
1901
}
1912
1902
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 )
1915
1906
{
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 );
1921
1908
1922
1909
head -> features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS );
1923
1910
if (!head -> ms || !(ctrl -> ops -> flags & NVME_F_METADATA_SUPPORTED ))
1924
- return 0 ;
1911
+ return ;
1925
1912
1926
1913
if (ctrl -> ops -> flags & NVME_F_FABRICS ) {
1927
1914
/*
@@ -1930,7 +1917,7 @@ static int nvme_configure_metadata(struct nvme_ctrl *ctrl,
1930
1917
* remap the separate metadata buffer from the block layer.
1931
1918
*/
1932
1919
if (WARN_ON_ONCE (!(id -> flbas & NVME_NS_FLBAS_META_EXT )))
1933
- return 0 ;
1920
+ return ;
1934
1921
1935
1922
head -> features |= NVME_NS_EXT_LBAS ;
1936
1923
@@ -1957,7 +1944,6 @@ static int nvme_configure_metadata(struct nvme_ctrl *ctrl,
1957
1944
else
1958
1945
head -> features |= NVME_NS_METADATA_SUPPORTED ;
1959
1946
}
1960
- return 0 ;
1961
1947
}
1962
1948
1963
1949
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,
2092
2078
struct nvme_ns_info * info )
2093
2079
{
2094
2080
bool vwc = ns -> ctrl -> vwc & NVME_CTRL_VWC_PRESENT ;
2081
+ struct nvme_id_ns_nvm * nvm = NULL ;
2095
2082
struct nvme_id_ns * id ;
2096
2083
sector_t capacity ;
2097
2084
unsigned lbaf ;
@@ -2108,19 +2095,20 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
2108
2095
goto out ;
2109
2096
}
2110
2097
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
+
2111
2104
blk_mq_freeze_queue (ns -> disk -> queue );
2112
2105
lbaf = nvme_lbaf_index (id -> flbas );
2113
2106
ns -> head -> lba_shift = id -> lbaf [lbaf ].ds ;
2114
2107
ns -> head -> nuse = le64_to_cpu (id -> nuse );
2115
2108
capacity = nvme_lba_to_sect (ns -> head , le64_to_cpu (id -> nsze ));
2116
2109
2117
2110
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 );
2124
2112
nvme_set_chunk_sectors (ns , id );
2125
2113
if (!nvme_update_disk_info (ns , id ))
2126
2114
capacity = 0 ;
@@ -2165,6 +2153,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
2165
2153
2166
2154
ret = 0 ;
2167
2155
out :
2156
+ kfree (nvm );
2168
2157
kfree (id );
2169
2158
return ret ;
2170
2159
}
0 commit comments