Skip to content

python, swig: add missing controller attributes#970

Merged
igaw merged 1 commit intolinux-nvme:masterfrom
martin-belanger:ctrl-dhchap-rm-immutable
Mar 14, 2025
Merged

python, swig: add missing controller attributes#970
igaw merged 1 commit intolinux-nvme:masterfrom
martin-belanger:ctrl-dhchap-rm-immutable

Conversation

@martin-belanger
Copy link
Copy Markdown
Contributor

Found that some controller attributes (e.g. tls_key) were missing from the SWIG wrapper code. Also found that for some of the attributes, SWIG was generating code that accessed to attributes directly instead of using the getter/setter methods.

For example, SWIG would generate code like this:

name = c->name;

Instead of that:

name = nvme_ctrl_get_name(c);

This may have been OK in most cases, but the Python code should really use the getter/setter methods instead of accessing the controller object directly.

SWIG is a weird beast to tame. For example, all the setter/getter methods must exactly match the syntax:

[class][member][set|get] (e.g. nvme_ctrl_traddr_get)

However, most of the libnvme functions follow this syntax:

[class][set|get][member] (e.g. nvme_ctrl_get_traddr)

The trick to force SWIG to use the setter/getter methods is to define the attributes in a %extend block and provide explicit translation methods for all the setter/getter methods.

Found that some controller attributes (e.g. tls_key) were missing
from the SWIG wrapper code. Also found that for some of the
attributes, SWIG was generating code that accessed to attributes
directly instead of using the getter/setter methods.

For example, SWIG would generate code like this:

  name = c->name;

Instead of that:

  name = nvme_ctrl_get_name(c);

This may have been OK in most cases, but the Python code should
really use the getter/setter methods instead of accessing the
controller object directly.

SWIG is a weird beast to tame. For example, all the setter/getter
methods must exactly match the syntax:

  [class]_[member]_[set|get] (e.g. nvme_ctrl_traddr_get)

However, most of the libnvme functions follow this syntax:

  [class]_[set|get]_[member] (e.g. nvme_ctrl_get_traddr)

The trick to force SWIG to use the setter/getter methods is to
define the attributes in a %extend block and provide explicit
translation methods for all the setter/getter methods.

Signed-off-by: Martin Belanger <[email protected]>
@martin-belanger martin-belanger force-pushed the ctrl-dhchap-rm-immutable branch from 21acb6d to 1fb6316 Compare March 14, 2025 01:27
@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Mar 14, 2025

Just to understand it, these [class][member][set|get] function wont be visible in the Python code? It's just internal stuff?

@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Mar 14, 2025

BTW, we should keep this in mind: #206

@martin-belanger
Copy link
Copy Markdown
Contributor Author

Just to understand it, these [class][member][set|get] function wont be visible in the Python code? It's just internal stuff?

Yes. It's all internal. The interface has not changed. From the Python code, everything is accessed as a property just like before, but internally the setter/getter methods will now be invoked instead of directly accessing the class members.

@igaw igaw merged commit 1a4d092 into linux-nvme:master Mar 14, 2025
15 checks passed
@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Mar 14, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants