summaryrefslogtreecommitdiffstats
path: root/libnvme
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 /libnvme
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 'libnvme')
-rw-r--r--libnvme/README.md28
-rw-r--r--libnvme/nvme.i80
2 files changed, 85 insertions, 23 deletions
diff --git a/libnvme/README.md b/libnvme/README.md
index f61e5cc..3195715 100644
--- a/libnvme/README.md
+++ b/libnvme/README.md
@@ -10,16 +10,24 @@ 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.
-sybsysnqn = [string] # e.g. 'nqn.2014-08.org.nvmexpress.discovery', nvme.NVME_DISC_SUBSYS_NAME, ...
-transport = [string] # One of: 'tcp, 'rdma', 'fc', 'loop'.
+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(subsysnqn=subsysnqn, transport=transport, traddr=traddr, trsvcid=trsvcid, host_iface=host_iface)
+ctrl = nvme.ctrl(root, subsysnqn=subsysnqn, transport=transport, traddr=traddr, trsvcid=trsvcid, host_iface=host_iface)
try:
cfg = {
@@ -31,8 +39,17 @@ try:
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:
- log_pages = ctrl.discover()
+ 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}')
@@ -42,5 +59,8 @@ try:
except Exception as e:
sys.exit(f'Failed to disconnect: {e}')
+ctrl = None
+host = None
+root = None
```
diff --git a/libnvme/nvme.i b/libnvme/nvme.i
index 14e2415..6f20e2c 100644
--- a/libnvme/nvme.i
+++ b/libnvme/nvme.i
@@ -21,10 +21,13 @@
%{
#include <ccan/list/list.h>
+#include <ccan/endian/endian.h>
#include "nvme/tree.h"
#include "nvme/fabrics.h"
#include "nvme/private.h"
#include "nvme/log.h"
+#include "nvme/ioctl.h"
+#include "nvme/types.h"
static int host_iter_err = 0;
static int subsys_iter_err = 0;
@@ -287,7 +290,9 @@ struct nvme_host {
char *hostnqn;
char *hostid;
char *hostsymname;
- char *dhchap_key;
+ %extend {
+ char *dhchap_key;
+ }
};
struct nvme_subsystem {
@@ -314,6 +319,7 @@ struct nvme_ctrl {
%immutable subsysnqn;
%immutable traddr;
%immutable trsvcid;
+ %immutable dhchap_host_key;
%immutable dhchap_key;
%immutable cntrltype;
%immutable dctype;
@@ -332,7 +338,10 @@ struct nvme_ctrl {
char *subsysnqn;
char *traddr;
char *trsvcid;
- char *dhchap_key;
+ %extend {
+ char *dhchap_host_key:
+ char *dhchap_key;
+ }
char *cntrltype;
char *dctype;
bool discovery_ctrl;
@@ -448,6 +457,15 @@ struct nvme_ns {
}
}
+%{
+ const char *nvme_host_dhchap_key_get(struct nvme_host *h) {
+ return nvme_host_get_dhchap_key(h);
+ }
+ void nvme_host_dhchap_key_set(struct nvme_host *h, char *key) {
+ nvme_host_set_dhchap_key(h, key);
+ }
+%};
+
%extend subsystem_iter {
struct subsystem_iter *__iter__() {
return $self;
@@ -610,25 +628,46 @@ struct nvme_ns {
}
%newobject discover;
- struct nvmf_discovery_log *discover(int max_retries = 6) {
- struct nvmf_discovery_log *logp = NULL;
+ struct nvmf_discovery_log *discover(int lsp = 0, int max_retries = 6) {
+ struct nvme_get_discovery_args args = {
+ .c = $self,
+ .args_size = sizeof(args),
+ .max_retries = max_retries,
+ .result = NULL,
+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+ .lsp = lsp,
+ };
+ struct nvmf_discovery_log *logp = nvmf_get_discovery_wargs(&args);
+ if (logp == NULL)
+ discover_err = 1;
+ return logp;
+ }
+
+ %feature("autodoc", "@return: List of supported log pages") supported_log_pages;
+ PyObject * supported_log_pages(bool rae=true) {
+ struct nvme_supported_log_pages log;
+ PyObject *obj = NULL;
int ret = 0;
- ret = nvmf_get_discovery_log($self, &logp, max_retries);
+
+ ret = nvme_get_log_supported_log_pages(nvme_ctrl_get_fd($self), rae, &log);
if (ret < 0) {
- discover_err = 1;
- return NULL;
+ Py_RETURN_NONE;
}
- return logp;
+
+ obj = PyList_New(NVME_LOG_SUPPORTED_LOG_PAGES_MAX);
+ if (!obj)
+ Py_RETURN_NONE;
+
+ for (int i = 0; i < NVME_LOG_SUPPORTED_LOG_PAGES_MAX; i++)
+ PyList_SetItem(obj, i, PyLong_FromLong(le32_to_cpu(log.lid_support[i]))); /* steals ref. */
+
+ return obj;
}
- char *__str__() {
- static char tmp[1024];
- if ($self->address)
- sprintf(tmp, "nvme_ctrl(transport=%s,%s)", $self->transport,
- $self->address);
- else
- sprintf(tmp, "nvme_ctrl(transport=%s)", $self->transport);
- return tmp;
+ PyObject *__str__() {
+ return $self->address ?
+ PyUnicode_FromFormat("nvme_ctrl(transport=%s,%s)", $self->transport, $self->address) :
+ PyUnicode_FromFormat("nvme_ctrl(transport=%s)", $self->transport);
}
struct ctrl_iter __iter__() {
struct ctrl_iter ret = { .subsystem = nvme_ctrl_get_subsystem($self),
@@ -656,6 +695,12 @@ struct nvme_ns {
const char *nvme_ctrl_state_get(struct nvme_ctrl *c) {
return nvme_ctrl_get_state(c);
}
+ const char *nvme_ctrl_dhchap_key_get(struct nvme_ctrl *c) {
+ return nvme_ctrl_get_dhchap_key(c);
+ }
+ const char *nvme_ctrl_dhchap_host_key_get(struct nvme_ctrl *c) {
+ return nvme_ctrl_get_dhchap_host_key(c);
+ }
%};
%extend nvme_ns {
@@ -689,9 +734,6 @@ struct nvme_ns {
// We want to swig all the #define and enum from types.h, but none of the structs.
-%{
-#include "nvme/types.h"
-%}
#define __attribute__(x)
%rename($ignore, %$isclass) ""; // ignore all classes/structs
%rename($ignore, %$isfunction) ""; // ignore all functions