libnvme: replace manual accessor functions with auto-generated ones#3168
libnvme: replace manual accessor functions with auto-generated ones#3168martin-belanger wants to merge 2 commits intolinux-nvme:masterfrom
Conversation
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 | |||
|
|
|||
There was a problem hiding this comment.
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 ...
| * @h: Host for which the key should be returned | ||
| * | ||
| * Return: DH-HMAC-CHAP host key or NULL if not set | ||
| */ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Generating the documentation is something that could be done with a good AI tool.
There was a problem hiding this comment.
Good point, though I wonder how to intergrate into the workflow. I suppose with pre-build headers it's a bit easier.
|
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 |
|
Closing PR since we're going to use a different approach with pre-built accessors. |
@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: