Skip to content

Commit b325953

Browse files
hreineckeigaw
authored andcommitted
examples/discover-loop.py: actually implement a discovery loop
As we now have resource tracking we can implement a discovery loop in python without leaving stale controllers around. Signed-off-by: Hannes Reinecke <hare@suse.de>
1 parent 89c132d commit b325953

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

examples/discover-loop.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ def disc_supp_str(dlp_supp_opts):
1616
}
1717
return [txt for msk, txt in d.items() if dlp_supp_opts & msk]
1818

19-
def discover(host, ctrl):
19+
def discover(host, ctrl, iteration):
20+
# Only 8 levels of indirection are supported
21+
if iteration > 8:
22+
return
23+
2024
try:
2125
ctrl.connect(host)
2226
except Exception as e:
2327
print(f'Failed to connect: {e}')
2428
return
2529

26-
print(f'{ctrl.name} connected to subsys {ctrl.subsystem}')
30+
print(f'{ctrl.name} connected to {ctrl.subsystem}')
2731

2832
slp = ctrl.supported_log_pages()
2933
try:
@@ -41,7 +45,14 @@ def discover(host, ctrl):
4145
return
4246

4347
for dlpe in disc_log:
44-
print(f'log entry {dlpe["portid"]}: {dlpe["subtype"]} {dlpe["subnqn"]}')
48+
if dlpe['subtype'] == 'nvme':
49+
print(f'{iteration}: {dlpe["subtype"]} {dlpe["subnqn"]}')
50+
continue
51+
if dlpe['subtype'] == 'discovery' and dlpe['subnqn'] == nvme.NVME_DISC_SUBSYS_NAME:
52+
continue
53+
print(f'{iteration}: {dlpe["subtype"]} {dlpe["subnqn"]}')
54+
with nvme.ctrl(root, subsysnqn=dlpe['subnqn'], transport=dlpe['trtype'], traddr=dlpe['traddr'], trsvcid=dlpe['trsvcid']) as new_ctrl:
55+
discover(host, new_ctrl, iteration + 1)
4556

4657
root = nvme.root()
4758
host = nvme.host(root)
@@ -52,7 +63,7 @@ def discover(host, ctrl):
5263
trsvcid = '4420'
5364

5465
with nvme.ctrl(root, subsysnqn=subsysnqn, transport=transport, traddr=traddr, trsvcid=trsvcid) as ctrl:
55-
discover(host, ctrl)
66+
discover(host, ctrl, 0)
5667

5768
for s in host.subsystems():
5869
for c in s.controllers():

0 commit comments

Comments
 (0)