@@ -318,24 +318,6 @@ static void cb_discovery_log(struct nvmf_discovery_ctx *dctx,
318318 nvme_show_discovery_log (log , numrec , dld -> flags );
319319}
320320
321- char * nvmf_get_default_trsvcid (const char * transport , bool discovery_ctrl )
322- {
323- if (!transport )
324- return NULL ;
325- if (!strcmp (transport , "tcp" )) {
326- if (discovery_ctrl )
327- /* Default port for NVMe/TCP discovery controllers */
328- return stringify (NVME_DISC_IP_PORT );
329- /* Default port for NVMe/TCP io controllers */
330- return stringify (NVME_RDMA_IP_PORT );
331- } else if (!strcmp (transport , "rdma" )) {
332- /* Default port for NVMe/RDMA controllers */
333- return stringify (NVME_RDMA_IP_PORT );
334- }
335-
336- return NULL ;
337- }
338-
339321static void already_connected (struct nvme_host * host ,
340322 struct nvmf_disc_log_entry * entry ,
341323 void * user_data )
@@ -349,6 +331,17 @@ static void already_connected(struct nvme_host *host,
349331 nvmf_trtype_str (entry -> trtype ), entry -> traddr , entry -> trsvcid );
350332}
351333
334+ static bool nvmf_decide_retry (struct nvmf_discovery_ctx * dctx , int err ,
335+ void * user_data )
336+ {
337+ if (err == - EAGAIN || (err == - EINTR && !nvme_sigint_received )) {
338+ print_debug ("nvmf_add_ctrl returned '%s'\n" , strerror (- err ));
339+ return true;
340+ }
341+
342+ return false;
343+ }
344+
352345static int create_discovery_log_ctx (struct nvme_global_ctx * ctx ,
353346 bool persistent ,
354347 struct nvme_fabrics_config * defcfg ,
@@ -377,6 +370,10 @@ static int create_discovery_log_ctx(struct nvme_global_ctx *ctx,
377370 if (err )
378371 goto err ;
379372
373+ err = nvmf_discovery_ctx_decide_retry_set (dctx , nvmf_decide_retry );
374+ if (err )
375+ goto err ;
376+
380377 err = nvmf_discovery_ctx_persistent_set (dctx , persistent );
381378 if (err )
382379 goto err ;
@@ -504,144 +501,6 @@ static int discover_from_conf_file(struct nvme_global_ctx *ctx, nvme_host_t h,
504501 return ret ;
505502}
506503
507- static int _discover_from_json_config_file (struct nvme_global_ctx * ctx ,
508- nvme_host_t h , nvme_ctrl_t c ,
509- const char * desc , bool connect ,
510- const struct nvme_fabrics_config * defcfg ,
511- nvme_print_flags_t flags , bool force )
512- {
513- _cleanup_free_ struct nvmf_discovery_ctx * dctx = NULL ;
514- const char * transport , * traddr , * host_traddr ;
515- const char * host_iface , * trsvcid , * subsysnqn ;
516- struct nvme_fabrics_config cfg ;
517- nvme_ctrl_t cn ;
518- int ret = 0 ;
519-
520- transport = nvme_ctrl_get_transport (c );
521- traddr = nvme_ctrl_get_traddr (c );
522- host_traddr = nvme_ctrl_get_host_traddr (c );
523- host_iface = nvme_ctrl_get_host_iface (c );
524-
525- if (!transport && !traddr )
526- return 0 ;
527-
528- /* ignore none fabric transports */
529- if (strcmp (transport , "tcp" ) &&
530- strcmp (transport , "rdma" ) &&
531- strcmp (transport , "fc" ))
532- return 0 ;
533-
534- /* ignore if no host_traddr for fc */
535- if (!strcmp (transport , "fc" )) {
536- if (!host_traddr ) {
537- fprintf (stderr , "host_traddr required for fc\n" );
538- return 0 ;
539- }
540- }
541-
542- /* ignore if host_iface set for any transport other than tcp */
543- if (!strcmp (transport , "rdma" ) || !strcmp (transport , "fc" )) {
544- if (host_iface ) {
545- fprintf (stderr ,
546- "host_iface not permitted for rdma or fc\n" );
547- return 0 ;
548- }
549- }
550-
551- trsvcid = nvme_ctrl_get_trsvcid (c );
552- if (!trsvcid || !strcmp (trsvcid , "" ))
553- trsvcid = nvmf_get_default_trsvcid (transport , true);
554-
555- if (force )
556- subsysnqn = nvme_ctrl_get_subsysnqn (c );
557- else
558- subsysnqn = NVME_DISC_SUBSYS_NAME ;
559-
560- if (nvme_ctrl_is_persistent (c ))
561- persistent = true;
562-
563- memcpy (& cfg , defcfg , sizeof (cfg ));
564-
565- struct tr_config trcfg = {
566- .subsysnqn = subsysnqn ,
567- .transport = transport ,
568- .traddr = traddr ,
569- .host_traddr = host_traddr ,
570- .host_iface = host_iface ,
571- .trsvcid = trsvcid ,
572- };
573-
574- struct cb_discovery_log_data dld = {
575- .flags = flags ,
576- .raw = raw ,
577- };
578- ret = create_discovery_log_ctx (ctx , true, & cfg , & dld , & dctx );
579-
580- if (!force ) {
581- cn = lookup_ctrl (h , & trcfg );
582- if (cn ) {
583- nvmf_discovery (ctx , dctx , connect , cn );
584- return 0 ;
585- }
586- }
587-
588- ret = nvmf_create_discover_ctrl (ctx , h , & cfg , & trcfg , & cn );
589- if (ret )
590- return 0 ;
591-
592- nvmf_discovery_ctx_persistent_set (dctx , persistent );
593- nvmf_discovery (ctx , dctx , connect , cn );
594- if (!(persistent || is_persistent_discovery_ctrl (h , cn )))
595- ret = nvme_disconnect_ctrl (cn );
596- nvme_free_ctrl (cn );
597-
598- return ret ;
599- }
600-
601- static int discover_from_json_config_file (struct nvme_global_ctx * ctx ,
602- const char * hostnqn ,
603- const char * hostid , const char * desc ,
604- bool connect ,
605- const struct nvme_fabrics_config * defcfg ,
606- nvme_print_flags_t flags , bool force )
607- {
608- const char * hnqn , * hid ;
609- nvme_host_t h ;
610- nvme_subsystem_t s ;
611- nvme_ctrl_t c ;
612- int ret = 0 , err ;
613-
614- nvme_for_each_host (ctx , h ) {
615- nvme_for_each_subsystem (h , s ) {
616- hnqn = nvme_host_get_hostnqn (h );
617- if (hostnqn && hnqn && strcmp (hostnqn , hnqn ))
618- continue ;
619- hid = nvme_host_get_hostid (h );
620- if (hostid && hid && strcmp (hostid , hid ))
621- continue ;
622-
623- nvme_subsystem_for_each_ctrl (s , c ) {
624- err = _discover_from_json_config_file (
625- ctx , h , c , desc , connect , defcfg ,
626- flags , force );
627-
628- if (err ) {
629- fprintf (stderr ,
630- "failed to connect to hostnqn=%s,nqn=%s,%s\n" ,
631- nvme_host_get_hostnqn (h ),
632- nvme_subsystem_get_name (s ),
633- nvme_ctrl_get_address (c ));
634-
635- if (!ret )
636- ret = err ;
637- }
638- }
639- }
640- }
641-
642- return ret ;
643- }
644-
645504static int nvme_read_volatile_config (struct nvme_global_ctx * ctx )
646505{
647506 char * filename , * ext ;
@@ -785,7 +644,18 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
785644 if (hostkey )
786645 nvme_host_set_dhchap_key (h , hostkey );
787646
647+ struct cb_discovery_log_data dld = {
648+ .flags = flags ,
649+ .raw = raw ,
650+ };
651+
652+ ret = create_discovery_log_ctx (ctx , persistent , & cfg , & dld , & dctx );
653+ if (ret )
654+ return ret ;
655+
788656 if (!device && !transport && !traddr ) {
657+ nvmf_discovery_ctx_persistent_set (dctx , true);
658+
789659 if (!nonbft )
790660 ret = discover_from_nbft (ctx , hostnqn , hostid ,
791661 hnqn , hid , desc , connect ,
@@ -794,9 +664,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
794664 goto out_free ;
795665
796666 if (json_config )
797- ret = discover_from_json_config_file (ctx , hostnqn , hostid ,
798- desc , connect , & cfg ,
799- flags , force );
667+ ret = nvmf_discovery_config_json (ctx , dctx ,
668+ hostnqn , hostid , connect , force );
800669 if (ret || access (PATH_NVMF_DISC , F_OK ))
801670 goto out_free ;
802671
@@ -885,14 +754,6 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
885754 }
886755 }
887756
888- struct cb_discovery_log_data dld = {
889- .flags = flags ,
890- .raw = raw ,
891- };
892- ret = create_discovery_log_ctx (ctx , persistent , & cfg , & dld , & dctx );
893- if (ret )
894- return ret ;
895-
896757 ret = nvmf_discovery (ctx , dctx , connect , c );
897758 if (!(persistent || is_persistent_discovery_ctrl (h , c )))
898759 nvme_disconnect_ctrl (c );
0 commit comments