@@ -783,7 +783,8 @@ static int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id)
783
783
return error ;
784
784
}
785
785
786
- static int nvme_identify_ns_descs (struct nvme_ns * ns , unsigned nsid )
786
+ static int nvme_identify_ns_descs (struct nvme_ctrl * ctrl , unsigned nsid ,
787
+ u8 * eui64 , u8 * nguid , uuid_t * uuid )
787
788
{
788
789
struct nvme_command c = { };
789
790
int status ;
@@ -799,7 +800,7 @@ static int nvme_identify_ns_descs(struct nvme_ns *ns, unsigned nsid)
799
800
if (!data )
800
801
return - ENOMEM ;
801
802
802
- status = nvme_submit_sync_cmd (ns -> ctrl -> admin_q , & c , data ,
803
+ status = nvme_submit_sync_cmd (ctrl -> admin_q , & c , data ,
803
804
NVME_IDENTIFY_DATA_SIZE );
804
805
if (status )
805
806
goto free_data ;
@@ -813,33 +814,33 @@ static int nvme_identify_ns_descs(struct nvme_ns *ns, unsigned nsid)
813
814
switch (cur -> nidt ) {
814
815
case NVME_NIDT_EUI64 :
815
816
if (cur -> nidl != NVME_NIDT_EUI64_LEN ) {
816
- dev_warn (ns -> ctrl -> device ,
817
+ dev_warn (ctrl -> device ,
817
818
"ctrl returned bogus length: %d for NVME_NIDT_EUI64\n" ,
818
819
cur -> nidl );
819
820
goto free_data ;
820
821
}
821
822
len = NVME_NIDT_EUI64_LEN ;
822
- memcpy (ns -> eui , data + pos + sizeof (* cur ), len );
823
+ memcpy (eui64 , data + pos + sizeof (* cur ), len );
823
824
break ;
824
825
case NVME_NIDT_NGUID :
825
826
if (cur -> nidl != NVME_NIDT_NGUID_LEN ) {
826
- dev_warn (ns -> ctrl -> device ,
827
+ dev_warn (ctrl -> device ,
827
828
"ctrl returned bogus length: %d for NVME_NIDT_NGUID\n" ,
828
829
cur -> nidl );
829
830
goto free_data ;
830
831
}
831
832
len = NVME_NIDT_NGUID_LEN ;
832
- memcpy (ns -> nguid , data + pos + sizeof (* cur ), len );
833
+ memcpy (nguid , data + pos + sizeof (* cur ), len );
833
834
break ;
834
835
case NVME_NIDT_UUID :
835
836
if (cur -> nidl != NVME_NIDT_UUID_LEN ) {
836
- dev_warn (ns -> ctrl -> device ,
837
+ dev_warn (ctrl -> device ,
837
838
"ctrl returned bogus length: %d for NVME_NIDT_UUID\n" ,
838
839
cur -> nidl );
839
840
goto free_data ;
840
841
}
841
842
len = NVME_NIDT_UUID_LEN ;
842
- uuid_copy (& ns -> uuid , data + pos + sizeof (* cur ));
843
+ uuid_copy (uuid , data + pos + sizeof (* cur ));
843
844
break ;
844
845
default :
845
846
/* Skip unnkown types */
@@ -864,9 +865,10 @@ static int nvme_identify_ns_list(struct nvme_ctrl *dev, unsigned nsid, __le32 *n
864
865
return nvme_submit_sync_cmd (dev -> admin_q , & c , ns_list , 0x1000 );
865
866
}
866
867
867
- static int nvme_identify_ns (struct nvme_ctrl * dev , unsigned nsid ,
868
- struct nvme_id_ns * * id )
868
+ static struct nvme_id_ns * nvme_identify_ns (struct nvme_ctrl * ctrl ,
869
+ unsigned nsid )
869
870
{
871
+ struct nvme_id_ns * id ;
870
872
struct nvme_command c = { };
871
873
int error ;
872
874
@@ -875,15 +877,18 @@ static int nvme_identify_ns(struct nvme_ctrl *dev, unsigned nsid,
875
877
c .identify .nsid = cpu_to_le32 (nsid );
876
878
c .identify .cns = NVME_ID_CNS_NS ;
877
879
878
- * id = kmalloc (sizeof (struct nvme_id_ns ), GFP_KERNEL );
879
- if (!* id )
880
- return - ENOMEM ;
880
+ id = kmalloc (sizeof (* id ), GFP_KERNEL );
881
+ if (!id )
882
+ return NULL ;
881
883
882
- error = nvme_submit_sync_cmd (dev -> admin_q , & c , * id ,
883
- sizeof (struct nvme_id_ns ));
884
- if (error )
885
- kfree (* id );
886
- return error ;
884
+ error = nvme_submit_sync_cmd (ctrl -> admin_q , & c , id , sizeof (* id ));
885
+ if (error ) {
886
+ dev_warn (ctrl -> device , "Identify namespace failed\n" );
887
+ kfree (id );
888
+ return NULL ;
889
+ }
890
+
891
+ return id ;
887
892
}
888
893
889
894
static int nvme_set_features (struct nvme_ctrl * dev , unsigned fid , unsigned dword11 ,
@@ -1174,32 +1179,21 @@ static void nvme_config_discard(struct nvme_ns *ns)
1174
1179
blk_queue_max_write_zeroes_sectors (ns -> queue , UINT_MAX );
1175
1180
}
1176
1181
1177
- static int nvme_revalidate_ns (struct nvme_ns * ns , struct nvme_id_ns * * id )
1182
+ static void nvme_report_ns_ids (struct nvme_ctrl * ctrl , unsigned int nsid ,
1183
+ struct nvme_id_ns * id , u8 * eui64 , u8 * nguid , uuid_t * uuid )
1178
1184
{
1179
- if (nvme_identify_ns (ns -> ctrl , ns -> ns_id , id )) {
1180
- dev_warn (ns -> ctrl -> device , "Identify namespace failed\n" );
1181
- return - ENODEV ;
1182
- }
1183
-
1184
- if ((* id )-> ncap == 0 ) {
1185
- kfree (* id );
1186
- return - ENODEV ;
1187
- }
1188
-
1189
- if (ns -> ctrl -> vs >= NVME_VS (1 , 1 , 0 ))
1190
- memcpy (ns -> eui , (* id )-> eui64 , sizeof (ns -> eui ));
1191
- if (ns -> ctrl -> vs >= NVME_VS (1 , 2 , 0 ))
1192
- memcpy (ns -> nguid , (* id )-> nguid , sizeof (ns -> nguid ));
1193
- if (ns -> ctrl -> vs >= NVME_VS (1 , 3 , 0 )) {
1185
+ if (ctrl -> vs >= NVME_VS (1 , 1 , 0 ))
1186
+ memcpy (eui64 , id -> eui64 , sizeof (id -> eui64 ));
1187
+ if (ctrl -> vs >= NVME_VS (1 , 2 , 0 ))
1188
+ memcpy (nguid , id -> nguid , sizeof (id -> nguid ));
1189
+ if (ctrl -> vs >= NVME_VS (1 , 3 , 0 )) {
1194
1190
/* Don't treat error as fatal we potentially
1195
1191
* already have a NGUID or EUI-64
1196
1192
*/
1197
- if (nvme_identify_ns_descs (ns , ns -> ns_id ))
1198
- dev_warn (ns -> ctrl -> device ,
1193
+ if (nvme_identify_ns_descs (ctrl , nsid , eui64 , nguid , uuid ))
1194
+ dev_warn (ctrl -> device ,
1199
1195
"%s: Identify Descriptors failed\n" , __func__ );
1200
1196
}
1201
-
1202
- return 0 ;
1203
1197
}
1204
1198
1205
1199
static void __nvme_revalidate_disk (struct gendisk * disk , struct nvme_id_ns * id )
@@ -1240,22 +1234,28 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
1240
1234
static int nvme_revalidate_disk (struct gendisk * disk )
1241
1235
{
1242
1236
struct nvme_ns * ns = disk -> private_data ;
1243
- struct nvme_id_ns * id = NULL ;
1244
- int ret ;
1237
+ struct nvme_ctrl * ctrl = ns -> ctrl ;
1238
+ struct nvme_id_ns * id ;
1239
+ int ret = 0 ;
1245
1240
1246
1241
if (test_bit (NVME_NS_DEAD , & ns -> flags )) {
1247
1242
set_capacity (disk , 0 );
1248
1243
return - ENODEV ;
1249
1244
}
1250
1245
1251
- ret = nvme_revalidate_ns ( ns , & id );
1252
- if (ret )
1253
- return ret ;
1246
+ id = nvme_identify_ns ( ctrl , ns -> ns_id );
1247
+ if (! id )
1248
+ return - ENODEV ;
1254
1249
1255
- __nvme_revalidate_disk (disk , id );
1256
- kfree (id );
1250
+ if (id -> ncap == 0 ) {
1251
+ ret = - ENODEV ;
1252
+ goto out ;
1253
+ }
1257
1254
1258
- return 0 ;
1255
+ nvme_report_ns_ids (ctrl , ns -> ns_id , id , ns -> eui , ns -> nguid , & ns -> uuid );
1256
+ out :
1257
+ kfree (id );
1258
+ return ret ;
1259
1259
}
1260
1260
1261
1261
static char nvme_pr_type (enum pr_type type )
@@ -2361,9 +2361,15 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
2361
2361
2362
2362
sprintf (disk_name , "nvme%dn%d" , ctrl -> instance , ns -> instance );
2363
2363
2364
- if (nvme_revalidate_ns (ns , & id ))
2364
+ id = nvme_identify_ns (ctrl , nsid );
2365
+ if (!id )
2365
2366
goto out_free_queue ;
2366
2367
2368
+ if (id -> ncap == 0 )
2369
+ goto out_free_id ;
2370
+
2371
+ nvme_report_ns_ids (ctrl , ns -> ns_id , id , ns -> eui , ns -> nguid , & ns -> uuid );
2372
+
2367
2373
if (nvme_nvm_ns_supported (ns , id ) &&
2368
2374
nvme_nvm_register (ns , disk_name , node )) {
2369
2375
dev_warn (ctrl -> device , "%s: LightNVM init failure\n" , __func__ );
0 commit comments