diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:40:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:40:20 +0000 |
commit | 2dba2525fb35dcfc79aad5bdf6c92e790d69635c (patch) | |
tree | ac8ac7d3960922094733bac6d9a5300da7171c56 /libnvme/README.md | |
parent | Initial commit. (diff) | |
download | libnvme-2dba2525fb35dcfc79aad5bdf6c92e790d69635c.tar.xz libnvme-2dba2525fb35dcfc79aad5bdf6c92e790d69635c.zip |
Adding upstream version 1.3.upstream/1.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnvme/README.md')
-rw-r--r-- | libnvme/README.md | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/libnvme/README.md b/libnvme/README.md new file mode 100644 index 0000000..3195715 --- /dev/null +++ b/libnvme/README.md @@ -0,0 +1,66 @@ +# Python bindings for libnvme + +We use [SWIG](http://www.swig.org/) to generate Python bindings for libnvme. + +## How to use + +```python +#!/usr/bin/env python3 +import sys +import pprint +from libnvme import nvme + +def disc_supp_str(dlp_supp_opts): + bitmap = { + nvme.NVMF_LOG_DISC_LID_EXTDLPES: "EXTDLPES", + nvme.NVMF_LOG_DISC_LID_PLEOS: "PLEOS", + nvme.NVMF_LOG_DISC_LID_ALLSUBES: "ALLSUBES", + } + return [txt for msk, txt in bitmap.items() if dlp_supp_opts & msk] + +root = nvme.root() # This is a singleton +root.log_level('debug') # Optional: extra debug info + +host = nvme.host(root) # This "may be" a singleton. +subsysnqn = [string] # e.g. nvme.NVME_DISC_SUBSYS_NAME, ... +transport = [string] # One of: 'tcp', 'rdma', 'fc', 'loop'. +traddr = [IPv4 or IPv6] # e.g. '192.168.10.10', 'fd2e:853b:3cad:e135:506a:65ee:29f2:1b18', ... +trsvcid = [string] # e.g. '8009', '4420', ... +host_iface = [interface] # e.g. 'eth1', ens256', ... +ctrl = nvme.ctrl(root, subsysnqn=subsysnqn, transport=transport, traddr=traddr, trsvcid=trsvcid, host_iface=host_iface) + +try: + cfg = { + 'hdr_digest': True, # Enable header digests + 'data_digest': False, # Disable data digests + } + ctrl.connect(host, cfg) + print(f"connected to {ctrl.name} subsys {ctrl.subsystem.name}") +except Exception as e: + sys.exit(f'Failed to connect: {e}') + +supported_log_pages = ctrl.supported_log_pages() +try: + # Get the supported options for the Get Discovery Log Page command + dlp_supp_opts = supported_log_pages[nvme.NVME_LOG_LID_DISCOVER] >> 16 +except (TypeError, IndexError): + dlp_supp_opts = 0 + +print(f"LID {nvme.NVME_LOG_LID_DISCOVER:02x}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 + log_pages = ctrl.discover(lsp=lsp) + print(pprint.pformat(log_pages)) +except Exception as e: + sys.exit(f'Failed to retrieve log pages: {e}') + +try: + ctrl.disconnect() +except Exception as e: + sys.exit(f'Failed to disconnect: {e}') + +ctrl = None +host = None +root = None +``` + |