@@ -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 )
@@ -348,6 +330,17 @@ static void already_connected(struct nvme_host *host,
348330 nvmf_trtype_str (entry -> trtype ), entry -> traddr , entry -> trsvcid );
349331}
350332
333+ static bool nvmf_decide_retry (struct nvmf_discovery_ctx * dctx , int err ,
334+ void * user_data )
335+ {
336+ if (err == - EAGAIN || (err == - EINTR && !nvme_sigint_received )) {
337+ print_debug ("nvmf_add_ctrl returned '%s'\n" , strerror (- err ));
338+ return true;
339+ }
340+
341+ return false;
342+ }
343+
351344static int create_discovery_log_ctx (struct nvme_global_ctx * ctx ,
352345 bool persistent ,
353346 struct nvme_fabrics_config * defcfg ,
@@ -376,6 +369,10 @@ static int create_discovery_log_ctx(struct nvme_global_ctx *ctx,
376369 if (err )
377370 goto err ;
378371
372+ err = nvmf_discovery_ctx_decide_retry_set (dctx , nvmf_decide_retry );
373+ if (err )
374+ goto err ;
375+
379376 err = nvmf_discovery_ctx_persistent_set (dctx , persistent );
380377 if (err )
381378 goto err ;
@@ -503,144 +500,6 @@ static int discover_from_conf_file(struct nvme_global_ctx *ctx, nvme_host_t h,
503500 return ret ;
504501}
505502
506- static int _discover_from_json_config_file (struct nvme_global_ctx * ctx ,
507- nvme_host_t h , nvme_ctrl_t c ,
508- const char * desc , bool connect ,
509- const struct nvme_fabrics_config * defcfg ,
510- nvme_print_flags_t flags , bool force )
511- {
512- _cleanup_free_ struct nvmf_discovery_ctx * dctx = NULL ;
513- const char * transport , * traddr , * host_traddr ;
514- const char * host_iface , * trsvcid , * subsysnqn ;
515- struct nvme_fabrics_config cfg ;
516- nvme_ctrl_t cn ;
517- int ret = 0 ;
518-
519- transport = nvme_ctrl_get_transport (c );
520- traddr = nvme_ctrl_get_traddr (c );
521- host_traddr = nvme_ctrl_get_host_traddr (c );
522- host_iface = nvme_ctrl_get_host_iface (c );
523-
524- if (!transport && !traddr )
525- return 0 ;
526-
527- /* ignore none fabric transports */
528- if (strcmp (transport , "tcp" ) &&
529- strcmp (transport , "rdma" ) &&
530- strcmp (transport , "fc" ))
531- return 0 ;
532-
533- /* ignore if no host_traddr for fc */
534- if (!strcmp (transport , "fc" )) {
535- if (!host_traddr ) {
536- fprintf (stderr , "host_traddr required for fc\n" );
537- return 0 ;
538- }
539- }
540-
541- /* ignore if host_iface set for any transport other than tcp */
542- if (!strcmp (transport , "rdma" ) || !strcmp (transport , "fc" )) {
543- if (host_iface ) {
544- fprintf (stderr ,
545- "host_iface not permitted for rdma or fc\n" );
546- return 0 ;
547- }
548- }
549-
550- trsvcid = nvme_ctrl_get_trsvcid (c );
551- if (!trsvcid || !strcmp (trsvcid , "" ))
552- trsvcid = nvmf_get_default_trsvcid (transport , true);
553-
554- if (force )
555- subsysnqn = nvme_ctrl_get_subsysnqn (c );
556- else
557- subsysnqn = NVME_DISC_SUBSYS_NAME ;
558-
559- if (nvme_ctrl_is_persistent (c ))
560- persistent = true;
561-
562- memcpy (& cfg , defcfg , sizeof (cfg ));
563-
564- struct tr_config trcfg = {
565- .subsysnqn = subsysnqn ,
566- .transport = transport ,
567- .traddr = traddr ,
568- .host_traddr = host_traddr ,
569- .host_iface = host_iface ,
570- .trsvcid = trsvcid ,
571- };
572-
573- struct cb_discovery_log_data dld = {
574- .flags = flags ,
575- .raw = raw ,
576- };
577- ret = create_discovery_log_ctx (ctx , true, & cfg , & dld , & dctx );
578-
579- if (!force ) {
580- cn = lookup_ctrl (h , & trcfg );
581- if (cn ) {
582- nvmf_discovery (ctx , dctx , connect , cn );
583- return 0 ;
584- }
585- }
586-
587- ret = nvmf_create_discover_ctrl (ctx , h , & cfg , & trcfg , & cn );
588- if (ret )
589- return 0 ;
590-
591- nvmf_discovery_ctx_persistent_set (dctx , persistent );
592- nvmf_discovery (ctx , dctx , connect , cn );
593- if (!(persistent || is_persistent_discovery_ctrl (h , cn )))
594- ret = nvme_disconnect_ctrl (cn );
595- nvme_free_ctrl (cn );
596-
597- return ret ;
598- }
599-
600- static int discover_from_json_config_file (struct nvme_global_ctx * ctx ,
601- const char * hostnqn ,
602- const char * hostid , const char * desc ,
603- bool connect ,
604- const struct nvme_fabrics_config * defcfg ,
605- nvme_print_flags_t flags , bool force )
606- {
607- const char * hnqn , * hid ;
608- nvme_host_t h ;
609- nvme_subsystem_t s ;
610- nvme_ctrl_t c ;
611- int ret = 0 , err ;
612-
613- nvme_for_each_host (ctx , h ) {
614- nvme_for_each_subsystem (h , s ) {
615- hnqn = nvme_host_get_hostnqn (h );
616- if (hostnqn && hnqn && strcmp (hostnqn , hnqn ))
617- continue ;
618- hid = nvme_host_get_hostid (h );
619- if (hostid && hid && strcmp (hostid , hid ))
620- continue ;
621-
622- nvme_subsystem_for_each_ctrl (s , c ) {
623- err = _discover_from_json_config_file (
624- ctx , h , c , desc , connect , defcfg ,
625- flags , force );
626-
627- if (err ) {
628- fprintf (stderr ,
629- "failed to connect to hostnqn=%s,nqn=%s,%s\n" ,
630- nvme_host_get_hostnqn (h ),
631- nvme_subsystem_get_name (s ),
632- nvme_ctrl_get_address (c ));
633-
634- if (!ret )
635- ret = err ;
636- }
637- }
638- }
639- }
640-
641- return ret ;
642- }
643-
644503static int nvme_read_volatile_config (struct nvme_global_ctx * ctx )
645504{
646505 char * filename , * ext ;
@@ -784,7 +643,18 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
784643 if (hostkey )
785644 nvme_host_set_dhchap_key (h , hostkey );
786645
646+ struct cb_discovery_log_data dld = {
647+ .flags = flags ,
648+ .raw = raw ,
649+ };
650+
651+ ret = create_discovery_log_ctx (ctx , persistent , & cfg , & dld , & dctx );
652+ if (ret )
653+ return ret ;
654+
787655 if (!device && !transport && !traddr ) {
656+ nvmf_discovery_ctx_persistent_set (dctx , true);
657+
788658 if (!nonbft )
789659 ret = discover_from_nbft (ctx , hostnqn , hostid ,
790660 hnqn , hid , desc , connect ,
@@ -793,9 +663,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
793663 goto out_free ;
794664
795665 if (json_config )
796- ret = discover_from_json_config_file (ctx , hostnqn , hostid ,
797- desc , connect , & cfg ,
798- flags , force );
666+ ret = nvmf_discovery_config_json (ctx , dctx ,
667+ hostnqn , hostid , connect , force );
799668 if (ret || access (PATH_NVMF_DISC , F_OK ))
800669 goto out_free ;
801670
@@ -884,14 +753,6 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
884753 }
885754 }
886755
887- struct cb_discovery_log_data dld = {
888- .flags = flags ,
889- .raw = raw ,
890- };
891- ret = create_discovery_log_ctx (ctx , persistent , & cfg , & dld , & dctx );
892- if (ret )
893- return ret ;
894-
895756 ret = nvmf_discovery (ctx , dctx , connect , c );
896757 if (!(persistent || is_persistent_discovery_ctrl (h , c )))
897758 nvme_disconnect_ctrl (c );
0 commit comments