@@ -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 );
@@ -749,7 +755,7 @@ bool traddr_is_hostname(struct libnvme_global_ctx *ctx,
749755
750756static int build_options (libnvme_host_t h , libnvme_ctrl_t c , char * * argstr )
751757{
752- struct libnvme_fabrics_config * cfg = libnvme_ctrl_get_config (c );
758+ struct libnvme_fabrics_config * cfg = libnvmf_ctrl_get_config (c );
753759 const char * transport = libnvme_ctrl_get_transport (c );
754760 const char * hostnqn , * hostid , * hostkey , * ctrlkey = NULL ;
755761 bool discover = false, discovery_nqn = false;
@@ -1062,6 +1068,24 @@ static const char *lookup_context(struct libnvme_global_ctx *ctx, libnvme_ctrl_t
10621068 return NULL ;
10631069}
10641070
1071+ __public int libnvmf_create_ctrl (struct libnvme_global_ctx * ctx ,
1072+ const char * subsysnqn , const char * transport ,
1073+ const char * traddr , const char * host_traddr ,
1074+ const char * host_iface , const char * trsvcid ,
1075+ libnvme_ctrl_t * cp )
1076+ {
1077+ struct libnvmf_context fctx = {
1078+ .transport = transport ,
1079+ .traddr = traddr ,
1080+ .host_traddr = host_traddr ,
1081+ .host_iface = host_iface ,
1082+ .trsvcid = trsvcid ,
1083+ .subsysnqn = subsysnqn ,
1084+ };
1085+
1086+ return _libnvme_create_ctrl (ctx , & fctx , cp );
1087+ }
1088+
10651089__public int libnvmf_add_ctrl (libnvme_host_t h , libnvme_ctrl_t c ,
10661090 const struct libnvmf_context * fctx )
10671091{
@@ -1090,7 +1114,7 @@ __public int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c,
10901114 if (fc ) {
10911115 const char * key ;
10921116
1093- merge_config (c , libnvme_ctrl_get_config (fc ));
1117+ merge_config (c , libnvmf_ctrl_get_config (fc ));
10941118 /*
10951119 * An authentication key might already been set
10961120 * in @cfg, so ensure to update @c with the correct
@@ -1174,6 +1198,24 @@ __public int libnvmf_connect_ctrl(libnvme_ctrl_t c)
11741198 return 0 ;
11751199}
11761200
1201+ __public int libnvmf_disconnect_ctrl (libnvme_ctrl_t c )
1202+ {
1203+ struct libnvme_global_ctx * ctx = c -> s && c -> s -> h ? c -> s -> h -> ctx : NULL ;
1204+ int ret ;
1205+
1206+ ret = libnvme_set_attr (libnvme_ctrl_get_sysfs_dir (c ),
1207+ "delete_controller" , "1" );
1208+ if (ret < 0 ) {
1209+ libnvme_msg (ctx , LIBNVME_LOG_ERR ,
1210+ "%s: failed to disconnect, error %d\n" , c -> name , errno );
1211+ return ret ;
1212+ }
1213+ libnvme_msg (ctx , LIBNVME_LOG_INFO , "%s: %s disconnected\n" ,
1214+ c -> name , c -> subsysnqn );
1215+ nvme_deconfigure_ctrl (c );
1216+ return 0 ;
1217+ }
1218+
11771219static void nvmf_update_tls_concat (struct nvmf_disc_log_entry * e ,
11781220 libnvme_ctrl_t c , libnvme_host_t h )
11791221{
@@ -2117,7 +2159,7 @@ static int _nvmf_discovery(struct libnvme_global_ctx *ctx,
21172159 _nvmf_discovery (ctx , & nfctx , true, child );
21182160
21192161 if (child && disconnect ) {
2120- libnvme_disconnect_ctrl (child );
2162+ libnvmf_disconnect_ctrl (child );
21212163 libnvme_free_ctrl (child );
21222164 }
21232165 } else if (err == - ENVME_CONNECT_ALREADY ) {
@@ -2242,7 +2284,7 @@ static int nvmf_create_discovery_ctrl(struct libnvme_global_ctx *ctx,
22422284 libnvme_msg (ctx , LIBNVME_LOG_ERR ,
22432285 "failed to identify controller, error %s\n" ,
22442286 libnvme_strerror (- ret ));
2245- libnvme_disconnect_ctrl (c );
2287+ libnvmf_disconnect_ctrl (c );
22462288 libnvme_free_ctrl (c );
22472289 return ret ;
22482290 }
@@ -2256,7 +2298,7 @@ static int nvmf_create_discovery_ctrl(struct libnvme_global_ctx *ctx,
22562298 * The subsysnqn is not the well-known name. Prefer the unique
22572299 * subsysnqn over the well-known one.
22582300 */
2259- libnvme_disconnect_ctrl (c );
2301+ libnvmf_disconnect_ctrl (c );
22602302 libnvme_free_ctrl (c );
22612303
22622304 fctx -> subsysnqn = id -> subnqn ;
@@ -2337,7 +2379,7 @@ int _discovery_config_json(struct libnvme_global_ctx *ctx,
23372379
23382380 _nvmf_discovery (ctx , & nfctx , connect , cn );
23392381 if (!(fctx -> persistent || is_persistent_discovery_ctrl (h , cn )))
2340- ret = libnvme_disconnect_ctrl (cn );
2382+ ret = libnvmf_disconnect_ctrl (cn );
23412383 libnvme_free_ctrl (cn );
23422384
23432385 return ret ;
@@ -2491,7 +2533,7 @@ __public int libnvmf_discovery_config_file(struct libnvme_global_ctx *ctx,
24912533 _nvmf_discovery (ctx , & nfctx , connect , c );
24922534 if (!(nfctx .persistent ||
24932535 is_persistent_discovery_ctrl (h , c )))
2494- err = libnvme_disconnect_ctrl (c );
2536+ err = libnvmf_disconnect_ctrl (c );
24952537 libnvme_free_ctrl (c );
24962538 } while (!err );
24972539
@@ -2746,7 +2788,7 @@ static int nbft_discovery(struct libnvme_global_ctx *ctx,
27462788 if (ret )
27472789 continue ;
27482790 nbft_discovery (ctx , & nfctx , dd , h , child );
2749- libnvme_disconnect_ctrl (child );
2791+ libnvmf_disconnect_ctrl (child );
27502792 libnvme_free_ctrl (child );
27512793 } else {
27522794 ret = nbft_connect (ctx , & nfctx , h , e , NULL );
@@ -2988,7 +3030,7 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx,
29883030
29893031 rr = nbft_discovery (ctx , & nfctx , * dd , h , c );
29903032 if (!persistent )
2991- libnvme_disconnect_ctrl (c );
3033+ libnvmf_disconnect_ctrl (c );
29923034 libnvme_free_ctrl (c );
29933035 if (rr == - ENOMEM ) {
29943036 ret = rr ;
@@ -3090,7 +3132,7 @@ __public int libnvmf_discovery(struct libnvme_global_ctx *ctx, struct libnvmf_co
30903132
30913133 ret = _nvmf_discovery (ctx , fctx , connect , c );
30923134 if (!(fctx -> persistent || is_persistent_discovery_ctrl (h , c )))
3093- libnvme_disconnect_ctrl (c );
3135+ libnvmf_disconnect_ctrl (c );
30943136 libnvme_free_ctrl (c );
30953137
30963138 return ret ;
0 commit comments