@@ -1451,9 +1451,9 @@ static ctrl_match_t _candidate_init(struct nvme_global_ctx *ctx,
14511451 return _match_ctrl ;
14521452}
14531453
1454- static nvme_ctrl_t __nvme_lookup_ctrl (nvme_subsystem_t s ,
1455- struct nvmf_context * fctx ,
1456- nvme_ctrl_t p )
1454+ static nvme_ctrl_t __nvme_ctrl_find (nvme_subsystem_t s ,
1455+ struct nvmf_context * fctx ,
1456+ nvme_ctrl_t p )
14571457{
14581458 struct candidate_args candidate = {};
14591459 struct nvme_ctrl * c , * matching_c = NULL ;
@@ -1503,37 +1503,35 @@ __public bool nvme_ctrl_match_config(struct nvme_ctrl *c, const char *transport,
15031503
15041504nvme_ctrl_t nvme_ctrl_find (nvme_subsystem_t s , struct nvmf_context * fctx )
15051505{
1506- return __nvme_lookup_ctrl (s , fctx , NULL /*p*/ );
1506+ return __nvme_ctrl_find (s , fctx , NULL /*p*/ );
15071507}
15081508
1509- nvme_ctrl_t nvme_lookup_ctrl (nvme_subsystem_t s , const char * transport ,
1510- const char * traddr , const char * host_traddr ,
1511- const char * host_iface , const char * trsvcid ,
1512- nvme_ctrl_t p )
1509+ nvme_ctrl_t __nvme_lookup_ctrl (nvme_subsystem_t s ,
1510+ struct nvmf_context * fctx ,
1511+ nvme_ctrl_t p )
15131512{
15141513 struct nvme_global_ctx * ctx ;
15151514 struct nvme_ctrl * c ;
1515+ const char * subsysnqn = fctx -> subsysnqn ;
15161516 int ret ;
15171517
1518- if (!s || !transport )
1518+ if (!s || !fctx -> transport )
15191519 return NULL ;
15201520
1521- struct nvmf_context fctx = {
1522- .transport = transport ,
1523- .traddr = traddr ,
1524- .host_traddr = host_traddr ,
1525- .host_iface = host_iface ,
1526- .trsvcid = trsvcid ,
1527- .subsysnqn = NULL ,
1528- };
1529-
1530- c = __nvme_lookup_ctrl (s , & fctx , p );
1531- if (c )
1521+ /* Clear out subsysnqn; might be different for discovery subsystems */
1522+ fctx -> subsysnqn = NULL ;
1523+ c = __nvme_ctrl_find (s , fctx , p );
1524+ if (c ) {
1525+ fctx -> subsysnqn = subsysnqn ;
15321526 return c ;
1527+ }
15331528
15341529 ctx = s -> h ? s -> h -> ctx : NULL ;
1535- fctx .subsysnqn = s -> subsysnqn ;
1536- ret = _nvme_create_ctrl (ctx , & fctx , & c );
1530+ /* Set the NQN to the subsystem the controller should be created in */
1531+ fctx -> subsysnqn = s -> subsysnqn ;
1532+ ret = _nvme_create_ctrl (ctx , fctx , & c );
1533+ /* And restore NQN to avoid issues with repetitive calls */
1534+ fctx -> subsysnqn = subsysnqn ;
15371535 if (ret )
15381536 return NULL ;
15391537
@@ -1543,6 +1541,26 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
15431541 return c ;
15441542}
15451543
1544+ nvme_ctrl_t nvme_lookup_ctrl (nvme_subsystem_t s , const char * transport ,
1545+ const char * traddr , const char * host_traddr ,
1546+ const char * host_iface , const char * trsvcid ,
1547+ nvme_ctrl_t p )
1548+ {
1549+ if (!s || !transport )
1550+ return NULL ;
1551+
1552+ struct nvmf_context fctx = {
1553+ .transport = transport ,
1554+ .traddr = traddr ,
1555+ .host_traddr = host_traddr ,
1556+ .host_iface = host_iface ,
1557+ .trsvcid = trsvcid ,
1558+ .subsysnqn = NULL ,
1559+ };
1560+
1561+ return __nvme_lookup_ctrl (s , & fctx , p );
1562+ }
1563+
15461564static int nvme_ctrl_scan_paths (struct nvme_global_ctx * ctx , struct nvme_ctrl * c )
15471565{
15481566 _cleanup_dirents_ struct dirents paths = {};
@@ -1893,8 +1911,14 @@ int nvme_ctrl_alloc(struct nvme_global_ctx *ctx, nvme_subsystem_t s,
18931911skip_address :
18941912 p = NULL ;
18951913 do {
1896- c = nvme_lookup_ctrl (s , transport , traddr ,
1897- host_traddr , host_iface , trsvcid , p );
1914+ struct nvmf_context fctx = {
1915+ .transport = transport ,
1916+ .traddr = traddr ,
1917+ .host_traddr = host_traddr ,
1918+ .host_iface = host_iface ,
1919+ .trsvcid = trsvcid ,
1920+ };
1921+ c = __nvme_lookup_ctrl (s , & fctx , p );
18981922 if (c ) {
18991923 if (!c -> name )
19001924 break ;
0 commit comments