@@ -378,6 +378,12 @@ __public int libnvmf_context_set_device(struct libnvmf_context *fctx, const char
378378 return 0 ;
379379}
380380
381+ __public struct libnvme_fabrics_config * libnvmf_ctrl_get_config (
382+ libnvme_ctrl_t c )
383+ {
384+ return & c -> cfg ;
385+ }
386+
381387/*
382388 * Derived from Linux's supported options (the opt_tokens table)
383389 * when the mechanism to report supported options was added (f18ee3d988157).
@@ -414,7 +420,7 @@ static const struct libnvme_fabric_options default_supported_options = {
414420static void merge_config (libnvme_ctrl_t c ,
415421 const struct libnvme_fabrics_config * cfg )
416422{
417- struct libnvme_fabrics_config * ctrl_cfg = libnvme_ctrl_get_config (c );
423+ struct libnvme_fabrics_config * ctrl_cfg = libnvmf_ctrl_get_config (c );
418424
419425 MERGE_CFG_OPTION (ctrl_cfg , cfg , nr_io_queues , 0 );
420426 MERGE_CFG_OPTION (ctrl_cfg , cfg , nr_write_queues , 0 );
@@ -440,7 +446,7 @@ static void merge_config(libnvme_ctrl_t c,
440446 if ((n)->o != d) (c)->o = (n)->o
441447__public void libnvmf_update_config (libnvme_ctrl_t c , const struct libnvme_fabrics_config * cfg )
442448{
443- struct libnvme_fabrics_config * ctrl_cfg = libnvme_ctrl_get_config (c );
449+ struct libnvme_fabrics_config * ctrl_cfg = libnvmf_ctrl_get_config (c );
444450
445451 UPDATE_CFG_OPTION (ctrl_cfg , cfg , nr_io_queues , 0 );
446452 UPDATE_CFG_OPTION (ctrl_cfg , cfg , nr_write_queues , 0 );
@@ -744,7 +750,7 @@ static bool traddr_is_hostname(struct libnvme_global_ctx *ctx, libnvme_ctrl_t c)
744750
745751static int build_options (libnvme_host_t h , libnvme_ctrl_t c , char * * argstr )
746752{
747- struct libnvme_fabrics_config * cfg = libnvme_ctrl_get_config (c );
753+ struct libnvme_fabrics_config * cfg = libnvmf_ctrl_get_config (c );
748754 const char * transport = libnvme_ctrl_get_transport (c );
749755 const char * hostnqn , * hostid , * hostkey , * ctrlkey = NULL ;
750756 bool discover = false, discovery_nqn = false;
@@ -1057,6 +1063,24 @@ static const char *lookup_context(struct libnvme_global_ctx *ctx, libnvme_ctrl_t
10571063 return NULL ;
10581064}
10591065
1066+ __public int libnvmf_create_ctrl (struct libnvme_global_ctx * ctx ,
1067+ const char * subsysnqn , const char * transport ,
1068+ const char * traddr , const char * host_traddr ,
1069+ const char * host_iface , const char * trsvcid ,
1070+ libnvme_ctrl_t * cp )
1071+ {
1072+ struct libnvmf_context fctx = {
1073+ .transport = transport ,
1074+ .traddr = traddr ,
1075+ .host_traddr = host_traddr ,
1076+ .host_iface = host_iface ,
1077+ .trsvcid = trsvcid ,
1078+ .subsysnqn = subsysnqn ,
1079+ };
1080+
1081+ return _libnvme_create_ctrl (ctx , & fctx , cp );
1082+ }
1083+
10601084__public int libnvmf_add_ctrl (libnvme_host_t h , libnvme_ctrl_t c ,
10611085 const struct libnvmf_context * fctx )
10621086{
@@ -1085,7 +1109,7 @@ __public int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c,
10851109 if (fc ) {
10861110 const char * key ;
10871111
1088- merge_config (c , libnvme_ctrl_get_config (fc ));
1112+ merge_config (c , libnvmf_ctrl_get_config (fc ));
10891113 /*
10901114 * An authentication key might already been set
10911115 * in @cfg, so ensure to update @c with the correct
@@ -1169,6 +1193,24 @@ __public int libnvmf_connect_ctrl(libnvme_ctrl_t c)
11691193 return 0 ;
11701194}
11711195
1196+ __public int libnvmf_disconnect_ctrl (libnvme_ctrl_t c )
1197+ {
1198+ struct libnvme_global_ctx * ctx = c -> s && c -> s -> h ? c -> s -> h -> ctx : NULL ;
1199+ int ret ;
1200+
1201+ ret = libnvme_set_attr (libnvme_ctrl_get_sysfs_dir (c ),
1202+ "delete_controller" , "1" );
1203+ if (ret < 0 ) {
1204+ libnvme_msg (ctx , LIBNVME_LOG_ERR ,
1205+ "%s: failed to disconnect, error %d\n" , c -> name , errno );
1206+ return ret ;
1207+ }
1208+ libnvme_msg (ctx , LIBNVME_LOG_INFO , "%s: %s disconnected\n" ,
1209+ c -> name , c -> subsysnqn );
1210+ nvme_deconfigure_ctrl (c );
1211+ return 0 ;
1212+ }
1213+
11721214static void nvmf_update_tls_concat (struct nvmf_disc_log_entry * e ,
11731215 libnvme_ctrl_t c , libnvme_host_t h )
11741216{
@@ -2112,7 +2154,7 @@ static int _nvmf_discovery(struct libnvme_global_ctx *ctx,
21122154 _nvmf_discovery (ctx , & nfctx , true, child );
21132155
21142156 if (child && disconnect ) {
2115- libnvme_disconnect_ctrl (child );
2157+ libnvmf_disconnect_ctrl (child );
21162158 libnvme_free_ctrl (child );
21172159 }
21182160 } else if (err == - ENVME_CONNECT_ALREADY ) {
@@ -2237,7 +2279,7 @@ static int nvmf_create_discovery_ctrl(struct libnvme_global_ctx *ctx,
22372279 libnvme_msg (ctx , LIBNVME_LOG_ERR ,
22382280 "failed to identify controller, error %s\n" ,
22392281 libnvme_strerror (- ret ));
2240- libnvme_disconnect_ctrl (c );
2282+ libnvmf_disconnect_ctrl (c );
22412283 libnvme_free_ctrl (c );
22422284 return ret ;
22432285 }
@@ -2251,7 +2293,7 @@ static int nvmf_create_discovery_ctrl(struct libnvme_global_ctx *ctx,
22512293 * The subsysnqn is not the well-known name. Prefer the unique
22522294 * subsysnqn over the well-known one.
22532295 */
2254- libnvme_disconnect_ctrl (c );
2296+ libnvmf_disconnect_ctrl (c );
22552297 libnvme_free_ctrl (c );
22562298
22572299 fctx -> subsysnqn = id -> subnqn ;
@@ -2332,7 +2374,7 @@ int _discovery_config_json(struct libnvme_global_ctx *ctx,
23322374
23332375 _nvmf_discovery (ctx , & nfctx , connect , cn );
23342376 if (!(fctx -> persistent || is_persistent_discovery_ctrl (h , cn )))
2335- ret = libnvme_disconnect_ctrl (cn );
2377+ ret = libnvmf_disconnect_ctrl (cn );
23362378 libnvme_free_ctrl (cn );
23372379
23382380 return ret ;
@@ -2486,7 +2528,7 @@ __public int libnvmf_discovery_config_file(struct libnvme_global_ctx *ctx,
24862528 _nvmf_discovery (ctx , & nfctx , connect , c );
24872529 if (!(nfctx .persistent ||
24882530 is_persistent_discovery_ctrl (h , c )))
2489- err = libnvme_disconnect_ctrl (c );
2531+ err = libnvmf_disconnect_ctrl (c );
24902532 libnvme_free_ctrl (c );
24912533 } while (!err );
24922534
@@ -2741,7 +2783,7 @@ static int nbft_discovery(struct libnvme_global_ctx *ctx,
27412783 if (ret )
27422784 continue ;
27432785 nbft_discovery (ctx , & nfctx , dd , h , child );
2744- libnvme_disconnect_ctrl (child );
2786+ libnvmf_disconnect_ctrl (child );
27452787 libnvme_free_ctrl (child );
27462788 } else {
27472789 ret = nbft_connect (ctx , & nfctx , h , e , NULL );
@@ -2983,7 +3025,7 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx,
29833025
29843026 rr = nbft_discovery (ctx , & nfctx , * dd , h , c );
29853027 if (!persistent )
2986- libnvme_disconnect_ctrl (c );
3028+ libnvmf_disconnect_ctrl (c );
29873029 libnvme_free_ctrl (c );
29883030 if (rr == - ENOMEM ) {
29893031 ret = rr ;
@@ -3085,7 +3127,7 @@ __public int libnvmf_discovery(struct libnvme_global_ctx *ctx, struct libnvmf_co
30853127
30863128 ret = _nvmf_discovery (ctx , fctx , connect , c );
30873129 if (!(fctx -> persistent || is_persistent_discovery_ctrl (h , c )))
3088- libnvme_disconnect_ctrl (c );
3130+ libnvmf_disconnect_ctrl (c );
30893131 libnvme_free_ctrl (c );
30903132
30913133 return ret ;
0 commit comments