Skip to content

Conversation

@martin-belanger
Copy link

@martin-belanger martin-belanger commented Oct 28, 2025

This adds the ability to automatically generate accessor functions (setter/getter functions) by parsing structs definitions in header files. Two files are generated: [accessors.c, accessors.h].

Fixes: #54

ikegami-t and others added 30 commits October 27, 2025 18:28
Just added only functions frequently used in nvme-cli.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
[wagi: - addded documentation]
Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Replace the struct args approach by providing init function for
initializing the passthru commands. This reduces the dependency between
callside and library.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
ikegami-t and others added 10 commits October 27, 2025 18:29
Refactore so we maintain nvme_get_log_partial easier.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
Since the following warnings output.

$ ./scripts/kernel-doc-check test/zns.c
test/zns.c:3: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
test/zns.c:10: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
examples/mi-mctp.c:3: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
Since checked by kernel-doc-check then the warning message output.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
To fix the warning message below.
  test/mi.c:3: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
The api-types.h include file provided struct args definition. These are
all gone. But some basic types have been added in the meantime, which
need to be present when using the types.h header.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
As we have renamed nvme_root to nvme_global_ctx, the Python bindings
example needs to be adjusted to reflect the refactoring.

Signed-off-by: Dennis Maisenbacher <dennis.maisenbacher@wdc.com>
The error handling has changed from returning -1 and errno set to just
returing the error code. Negative values are internal errors, e.g.
-ENOMEM. Positive values are status code from the transport.

Signed-off-by: Dennis Maisenbacher <dennis.maisenbacher@wdc.com>
This is to resolve the build warnings below.

In function ‘nvme_init_app_tag’,
    inlined from ‘test_verify’ at ../test/ioctl/misc.c:961:2:
../src/nvme/ioctl.h:4514:20: warning: array subscript ‘struct nvme_passthru_cmd64[0]’ is partly outside array bounds of ‘struct nvme_passthru_cmd[1]’ [-Warray-bounds=]
 4514 |         cmd->cdw15 = NVME_FIELD_ENCODE(lbat,
      |                    ^
../test/ioctl/misc.c: In function ‘test_verify’:
../test/ioctl/misc.c:955:34: note: object ‘cmd’ of size 72
  955 |         struct nvme_passthru_cmd cmd;
      |                                  ^~~
In function ‘nvme_init_app_tag’,
    inlined from ‘test_compare’ at ../test/ioctl/misc.c:865:2:
../src/nvme/ioctl.h:4514:20: warning: array subscript ‘struct nvme_passthru_cmd64[0]’ is partly outside array bounds of ‘struct nvme_passthru_cmd[1]’ [-Warray-bounds=]
 4514 |         cmd->cdw15 = NVME_FIELD_ENCODE(lbat,
      |                    ^
../test/ioctl/misc.c: In function ‘test_compare’:
../test/ioctl/misc.c:857:34: note: object ‘cmd’ of size 72
  857 |         struct nvme_passthru_cmd cmd;
      |                                  ^~~
In function ‘nvme_init_app_tag’,
    inlined from ‘test_write’ at ../test/ioctl/misc.c:830:2:
../src/nvme/ioctl.h:4514:20: warning: array subscript ‘struct nvme_passthru_cmd64[0]’ is partly outside array bounds of ‘struct nvme_passthru_cmd[1]’ [-Warray-bounds=]
 4514 |         cmd->cdw15 = NVME_FIELD_ENCODE(lbat,
      |                    ^
../test/ioctl/misc.c: In function ‘test_write’:
../test/ioctl/misc.c:823:34: note: object ‘cmd’ of size 72
  823 |         struct nvme_passthru_cmd cmd;
      |                                  ^~~
In function ‘nvme_init_app_tag’,
    inlined from ‘test_read’ at ../test/ioctl/misc.c:794:2:
../src/nvme/ioctl.h:4514:20: warning: array subscript ‘struct nvme_passthru_cmd64[0]’ is partly outside array bounds of ‘struct nvme_passthru_cmd[1]’ [-Warray-bounds=]
 4514 |         cmd->cdw15 = NVME_FIELD_ENCODE(lbat,
      |                    ^
../test/ioctl/misc.c: In function ‘test_read’:
../test/ioctl/misc.c:787:34: note: object ‘cmd’ of size 72
  787 |         struct nvme_passthru_cmd cmd;
      |                                  ^~~
In function ‘nvme_init_app_tag’,
    inlined from ‘test_write_zeros’ at ../test/ioctl/misc.c:898:2:
../src/nvme/ioctl.h:4514:20: warning: array subscript ‘struct nvme_passthru_cmd64[0]’ is partly outside array bounds of ‘struct nvme_passthru_cmd[1]’ [-Warray-bounds=]
 4514 |         cmd->cdw15 = NVME_FIELD_ENCODE(lbat,
      |                    ^
../test/ioctl/misc.c: In function ‘test_write_zeros’:
../test/ioctl/misc.c:892:34: note: object ‘cmd’ of size 72
  892 |         struct nvme_passthru_cmd cmd;
      |                                  ^~~

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
Since the almost nvme-cli caller functions expected the base name.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
@martin-belanger martin-belanger force-pushed the add-generate-accessors branch 3 times, most recently from bd3ef32 to 30936bd Compare October 28, 2025 17:58
@martin-belanger
Copy link
Author

@igaw - Note: The remaining checkpatch errors cannot be fixed easily (or at all). I do not plan to fix them.

@igaw
Copy link

igaw commented Oct 29, 2025

I run into a build issue. I'm trying to figure out what's going on:

# ./scripts/build.sh
[...]
[18/116] Compiling C object src/libnvme.so.1.15.0.p/meson-generated_.._generated_accessors.c.o
FAILED: src/libnvme.so.1.15.0.p/meson-generated_.._generated_accessors.c.o
gcc -Isrc/libnvme.so.1.15.0.p -Isrc -I../src -I. -I.. -Iccan -I../ccan -I../src/nvme -Iinternal -I../internal -Isrc/generated -I/usr/include/json-c -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=gnu99 -O3 -fomit-frame-pointer -D_GNU_SOURCE -fPIC -include /home/wagi/work/libnvme/.build-ci/internal/config.h -include /home/wagi/work/libnvme/.build-ci/src/generated/accessor.h -MD -MQ src/libnvme.so.1.15.0.p/meson-generated_.._generated_accessors.c.o -MF src/libnvme.so.1.15.0.p/meson-generated_.._generated_accessors.c.o.d -o src/libnvme.so.1.15.0.p/meson-generated_.._generated_accessors.c.o -c src/generated/accessors.c
<command-line>: fatal error: /home/wagi/work/libnvme/.build-ci/src/generated/accessor.h: No such file or directory
compilation terminated.

I see your comments in the meson.build file but I don't understand yet what's happening...

@martin-belanger
Copy link
Author

I run into a build issue. I'm trying to figure out what's going on:

Weird. This is working fine on my computer. Let me see if I can figure it out. I suspect it's the #include in the generated code that has the wrong path.

@igaw
Copy link

igaw commented Oct 29, 2025

Maybe it's a meson version thing?

$ meson --version
1.7.2

@martin-belanger
Copy link
Author

Good point. Let me try with the same version as you.

@martin-belanger
Copy link
Author

@igaw - I just want to confirm that the setter/getter code gets generated.

Do you see any files in: /home/wagi/work/libnvme/.build-ci/src/generated/?

You should see this:

$ ls -go .build/src/generated/
total 56
-rw-rw-r-- 1 13713 Oct 29 09:32 accessor.h
-rw-rw-r-- 1 21193 Oct 29 09:32 accessors.c
-rw-rw-r-- 1 13713 Oct 29 09:32 _accessors.h

@igaw
Copy link

igaw commented Oct 29, 2025

The accessors.h is not there:

$  ls -go .build-ci/src/generated/
total 40
-rw-r--r--. 1 21193 Oct 29 15:49 accessors.c
-rw-r--r--. 1 13713 Oct 29 15:49 _accessors.h

@martin-belanger
Copy link
Author

Ah! That points to the "special" custom_target() I had to add to allow installing accessor.h in <prefix>/include/nvme/.

This gives me something to investigate further.

This adds the ability to automatically generate accessor functions
(setter/getter functions) by parsing structs definitions in header
files. Two files are generated: [accessors.c, accessors.h].

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
@igaw
Copy link

igaw commented Oct 29, 2025

Applied the patch. Thanks!

@igaw igaw closed this Oct 29, 2025
@martin-belanger martin-belanger deleted the add-generate-accessors branch October 29, 2025 18:30
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.

4 participants