Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 51 additions & 15 deletions libnvme/nvme.i
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@ PyObject *hostid_from_file();
#include "fabrics.h"
#define STR_OR_NONE(str) (!(str) ? "None" : str)

struct nvme_host * nvme_first_host(struct nvme_root * r);
struct nvme_host * nvme_next_host(struct nvme_root * r, struct nvme_host * h);
struct nvme_subsystem * nvme_first_subsystem(struct nvme_host * h);
struct nvme_subsystem * nvme_next_subsystem(struct nvme_host * h, struct nvme_subsystem * s);
struct nvme_ctrl * nvme_subsystem_first_ctrl(struct nvme_subsystem * s);
struct nvme_ctrl * nvme_subsystem_next_ctrl(struct nvme_subsystem * s, struct nvme_ctrl * c);
struct nvme_ns * nvme_subsystem_first_ns(struct nvme_subsystem * s);
struct nvme_ns * nvme_subsystem_next_ns(struct nvme_subsystem * s, struct nvme_ns * n);
struct nvme_ns * nvme_ctrl_first_ns(struct nvme_ctrl * c);
struct nvme_ns * nvme_ctrl_next_ns(struct nvme_ctrl * c, struct nvme_ns * n);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these deceleration necessary? I see we include tree.h right above.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that python-sigsegv-during-gc fails without these deceleration. I think I don't understand how the SWIG compiler works :)


struct nvme_root {
%immutable config_file;
%immutable application;
Expand Down Expand Up @@ -544,9 +555,14 @@ struct nvme_ns {
else if (!strcmp(level, "emerg")) log_level = LOG_EMERG;
nvme_init_logging($self, log_level, false, false);
}
struct nvme_host *hosts() {
return nvme_first_host($self);
}
%pythoncode %{
def hosts(self):
"""Iterator over all host objects"""
h = nvme_first_host(self)
while h:
yield h
h = nvme_next_host(self, h)
%}
void refresh_topology() {
nvme_refresh_topology($self);
}
Expand Down Expand Up @@ -620,9 +636,14 @@ struct nvme_ns {
};
return ret;
}
struct nvme_subsystem* subsystems() {
return nvme_first_subsystem($self);
}
%pythoncode %{
def subsystems(self):
"""Iterator over all subsystem objects"""
s = nvme_first_subsystem(self)
while s:
yield s
s = nvme_next_subsystem(self, s)
%}
}

%{
Expand Down Expand Up @@ -692,12 +713,22 @@ struct nvme_ns {
};
return ret;
}
struct nvme_ctrl *controllers() {
return nvme_subsystem_first_ctrl($self);
}
struct nvme_ns *namespaces() {
return nvme_subsystem_first_ns($self);
}
%pythoncode %{
def controllers(self):
"""Iterator over all controller objects"""
c = nvme_subsystem_first_ctrl(self)
while c:
yield c
c = nvme_subsystem_next_ctrl(self, c)
%}
%pythoncode %{
def namespaces(self):
"""Iterator over all namespace objects"""
ns = nvme_subsystem_first_ns(self)
while ns:
yield ns
ns = nvme_subsystem_next_ns(self, ns)
%}
%immutable name;
const char *name;
%immutable host;
Expand Down Expand Up @@ -898,9 +929,14 @@ struct nvme_ns {
};
return ret;
}
struct nvme_ns* namespaces() {
return nvme_ctrl_first_ns($self);
}
%pythoncode %{
def namespaces(self):
"""Iterator over all namespace objects"""
ns = nvme_ctrl_first_ns(self)
while ns:
yield ns
ns = nvme_ctrl_next_ns(self, ns)
%}
}

%{
Expand Down
9 changes: 4 additions & 5 deletions libnvme/tests/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
host = nvme.host(root)
print(f'host: {host}')

subsystem = host.subsystems()
print(f'subsystem: {subsystem}')

ctrls = []
for i in range(10):
ctrl = nvme.ctrl(
Expand All @@ -25,8 +22,10 @@
ctrls.append(ctrl)
print(f'ctrl {i}: {ctrl}')

ns = subsystem.namespaces() if subsystem is not None else None
print(f'ns: {ns}')
for s in host.subsystems():
print(f'subsystem: {s}')
for ns in s.namespaces():
print(f'ns: {ns}')

# Deleting objects in the following order would create a segmentation
# fault if it weren't for the %pythonappend in nvme.i. This test is to
Expand Down