summaryrefslogtreecommitdiffstats
path: root/examples/discover-loop.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-05 18:17:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-05 18:17:32 +0000
commitb0dc2feab3271dbcb42df6e6d8a37138a90c44a1 (patch)
treeae02f159c125f183b2adae47fdf0e64357bf76a8 /examples/discover-loop.py
parentReleasing debian version 1.1-2. (diff)
downloadlibnvme-b0dc2feab3271dbcb42df6e6d8a37138a90c44a1.tar.xz
libnvme-b0dc2feab3271dbcb42df6e6d8a37138a90c44a1.zip
Merging upstream version 1.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/discover-loop.py')
-rw-r--r--examples/discover-loop.py45
1 files changed, 37 insertions, 8 deletions
diff --git a/examples/discover-loop.py b/examples/discover-loop.py
index 22c51e6..09a976b 100644
--- a/examples/discover-loop.py
+++ b/examples/discover-loop.py
@@ -17,20 +17,49 @@ License for the specific language governing permissions and limitations
under the License.
'''
+import sys
+import pprint
from libnvme import nvme
+
+def disc_supp_str(dlp_supp_opts):
+ d = {
+ nvme.NVMF_LOG_DISC_LID_EXTDLPES: "Extended Discovery Log Page Entry Supported (EXTDLPES)",
+ nvme.NVMF_LOG_DISC_LID_PLEOS: "Port Local Entries Only Supported (PLEOS)",
+ nvme.NVMF_LOG_DISC_LID_ALLSUBES: "All NVM Subsystem Entries Supported (ALLSUBES)",
+ }
+ return [txt for msk, txt in d.items() if dlp_supp_opts & msk]
+
r = nvme.root()
h = nvme.host(r)
-c = nvme.ctrl(nvme.NVME_DISC_SUBSYS_NAME, 'loop')
+c = nvme.ctrl(r, nvme.NVME_DISC_SUBSYS_NAME, 'loop')
try:
c.connect(h)
-except:
- sys.exit("Failed to connect!")
+except Exception as e:
+ sys.exit(f'Failed to connect: {e}')
print("connected to %s subsys %s" % (c.name, c.subsystem.name))
+
+slp = c.supported_log_pages()
+
+try:
+ dlp_supp_opts = slp[nvme.NVME_LOG_LID_DISCOVER] >> 16
+except (TypeError, IndexError):
+ dlp_supp_opts = 0
+
+print(f"LID {nvme.NVME_LOG_LID_DISCOVER}h (Discovery), supports: {disc_supp_str(dlp_supp_opts)}")
+
+try:
+ lsp = nvme.NVMF_LOG_DISC_LSP_PLEO if dlp_supp_opts & nvme.NVMF_LOG_DISC_LID_PLEOS else 0
+ d = c.discover(lsp=lsp)
+ print(pprint.pformat(d))
+except Exception as e:
+ sys.exit(f'Failed to discover: {e}')
+
try:
- d = c.discover()
- print (d)
-except:
- print("Failed to discover!")
- pass
c.disconnect()
+except Exception as e:
+ sys.exit(f'Failed to disconnect: {e}')
+
+c = None
+h = None
+r = None