]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
examples: LID supported must be shifted right by 16
authorMartin Belanger <martin.belanger@dell.com>
Wed, 28 Sep 2022 12:57:33 +0000 (08:57 -0400)
committerMartin Belanger <martin.belanger@dell.com>
Wed, 28 Sep 2022 12:57:33 +0000 (08:57 -0400)
To access the LID Specific Field (see Base specs) the values
from the Get Supported Log pages must be shifted right by 16.
The example code was missing the shift.

Also added better exception handling example.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
examples/discover-loop.py
libnvme/README.md

index 9b007c922a37eaac4ac8b5820277867a0576ab6a..09a976becd680f4d30e5bdd3b51b635cf4d03727 100644 (file)
@@ -21,13 +21,13 @@ import sys
 import pprint
 from libnvme import nvme
 
-def disc_supp_str(disc_log_page_support):
+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 disc_log_page_support & msk]
+    return [txt for msk, txt in d.items() if dlp_supp_opts & msk]
 
 r = nvme.root()
 h = nvme.host(r)
@@ -40,11 +40,16 @@ except Exception as e:
 print("connected to %s subsys %s" % (c.name, c.subsystem.name))
 
 slp = c.supported_log_pages()
-disc_log_page_support = slp[nvme.NVME_LOG_LID_DISCOVER] if slp is not None else 0
-print(f"LID {nvme.NVME_LOG_LID_DISCOVER}h (Discovery), supports: {disc_supp_str(disc_log_page_support)}")
 
 try:
-    lsp = nvme.NVMF_LOG_DISC_LSP_PLEO if disc_log_page_support & nvme.NVMF_LOG_DISC_LID_PLEOS else 0
+    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:
index 9071c36291a0403a9545087cdf5318a5c9ae1d9e..31957155e4635c82904b7ea2fdaf910e9bfb6991 100644 (file)
@@ -10,13 +10,13 @@ import sys
 import pprint
 from libnvme import nvme
 
-def disc_supp_str(disc_log_page_support):
-    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)",
+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 d.items() if disc_log_page_support & msk]
+    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
@@ -40,15 +40,15 @@ except Exception as e:
     sys.exit(f'Failed to connect: {e}')
 
 supported_log_pages = ctrl.supported_log_pages()
-if supported_log_pages is not None:
-    disc_log_page_support = supported_log_pages[nvme.NVME_LOG_LID_DISCOVER]
-    print(f"LID {nvme.NVME_LOG_LID_DISCOVER:02x}h (Discovery), supports: {disc_supp_str(disc_log_page_support)}")
+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:
-    if disc_log_page_support and (disc_log_page_support & nvme.NVMF_LOG_DISC_LID_PLEOS):
-        lsp = nvme.NVMF_LOG_DISC_LSP_PLEO
-    else:
-        lsp = 0
+    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: