Skip to content

libnvme: replace manual accessor functions with auto-generated ones#3168

Closed
martin-belanger wants to merge 2 commits intolinux-nvme:masterfrom
martin-belanger:use-generated-accessors
Closed

libnvme: replace manual accessor functions with auto-generated ones#3168
martin-belanger wants to merge 2 commits intolinux-nvme:masterfrom
martin-belanger:use-generated-accessors

Conversation

@martin-belanger
Copy link

@martin-belanger martin-belanger commented Mar 11, 2026

@igaw - This is the big change to use the generated accessor functions instead of the functions written manually in tree.h/tree.c.

Remove hand-written getter/setter implementations from tree.c and tree.h for nvme_host, nvme_subsystem, and nvme_ctrl structs, replacing them with automatically generated equivalents produced by generate-accessors.

Supporting changes:

  • Rename structs-to-include.txt to generate-accessors-include.list for clarity and consistency with the new generate-accessors-exclude.list
  • Add generate-accessors-exclude.list to suppress generation for members that have custom accessor logic (pdc_enabled, state, address, etc.)
  • Introduce SET_FMT/GET_FMT macros in generate-accessors.c to make the naming convention (nvme_foo_get/nvme_foo_set) configurable in one place
  • Wire accessors_dep into libnvme_dep and libnvme_test_dep, and add ccan_dep into accessors_dep, so dependents get the correct include paths
  • Include <nvme/accessors.h> from libnvme.h to expose the generated API

Martin Belanger added 2 commits March 11, 2026 10:50
Remove hand-written getter/setter implementations from tree.c and tree.h
for nvme_host, nvme_subsystem, and nvme_ctrl structs, replacing them with
automatically generated equivalents produced by generate-accessors.

Supporting changes:
- Rename structs-to-include.txt to generate-accessors-include.list for
  clarity and consistency with the new generate-accessors-exclude.list
- Add generate-accessors-exclude.list to suppress generation for members
  that have custom accessor logic (pdc_enabled, state, address, etc.)
- Introduce SET_FMT/GET_FMT macros in generate-accessors.c to make the
  naming convention (nvme_foo_get/nvme_foo_set) configurable in one place
- Wire accessors_dep into libnvme_dep and libnvme_test_dep, and add
  ccan_dep into accessors_dep, so dependents get the correct include paths
- Include <nvme/accessors.h> from libnvme.h to expose the generated API

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also add your Copyright statement here? It seems it is necessary to fully 'best open source practice'. Yeah, we have some more files to decorated ...

Copy link
Author

Choose a reason for hiding this comment

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

Will do

* @h: Host for which the key should be returned
*
* Return: DH-HMAC-CHAP host key or NULL if not set
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am pondering if it's worth trying to create documentation or not. Most these getter/setters do not have any meaning full documentation but sometime like here (DH-HMAC-CHAP) is helping. Also I know that tab completion etc present with the documentation when someone is coding. Though we have to balance it with our effort here.

I suppose the most important thing is good names of the function and arguments.

Copy link
Author

Choose a reason for hiding this comment

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

Generating the documentation is something that could be done with a good AI tool.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, though I wonder how to intergrate into the workflow. I suppose with pre-build headers it's a bit easier.

@igaw
Copy link
Collaborator

igaw commented Mar 12, 2026

One idea we discussed in the chat is to generate the headers not during build time. Instead doing it by hand when necessary, which would allow us to ship the generated headers and make reading the source code a bit simpler. I don't expect that we are going to have so many new accessors all the time. WDYT?

@martin-belanger
Copy link
Author

One idea we discussed in the chat is to generate the headers not during build time. Instead doing it by hand when necessary, which would allow us to ship the generated headers and make reading the source code a bit simpler. I don't expect that we are going to have so many new accessors all the time. WDYT?

I would prefer to generate the accessors by hand. This is similar to having pre-built documentation. Hey, we could have a special meson target to generate the accessor functions. This also give us more flexibility with the libnvme.ld / accessors.ld file.

@martin-belanger
Copy link
Author

Closing PR since we're going to use a different approach with pre-built accessors.

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.

3 participants