Skip to content

nvme-cli: clean up and order includes across all source files#9

Closed
Copilot wants to merge 4 commits intomasterfrom
copilot/review-includes-nvme-files
Closed

nvme-cli: clean up and order includes across all source files#9
Copilot wants to merge 4 commits intomasterfrom
copilot/review-includes-nvme-files

Conversation

Copy link

Copilot AI commented Mar 4, 2026

Review of #include directives across all .c and .h files in the entire repository — removing duplicates and unused headers, and ordering all includes per the commonly recommended convention.

Duplicate includes removed

  • mi.c: <stdlib.h> included twice consecutively
  • generate-accessors.c: <string.h> and <stdio.h> each included twice (once near the top, once mid-block)

Unused includes removed

File Header Reason
ioctl.c <inttypes.h> No PRI format macros used; <stdint.h> already included directly for uintptr_t
ioctl.c <sys/time.h> No timeval / gettimeofday usage
base64.c <sys/types.h> Only uint32_t used, covered by <stdint.h>
log.c <sys/types.h> No POSIX types used; getpid() pulled in via <unistd.h>
sandisk-utils.h / wdc-utils.h <unistd.h> (second copy) Duplicate include

Include ordering applied across all files

The following ordering convention is now applied consistently across all affected .c and .h files:

  1. Standard/POSIX headers (alphabetical)
  2. System headers with path prefix: sys/, arpa/, linux/, net/, asm/ (alphabetical)
  3. Third-party library headers: ccan, dbus, json, keyutils, liburing, openssl (alphabetical)
  4. Project public headers: <libnvme.h>, <libnvme-mi.h>, <nvme/...>
  5. Local/private headers: "..."

Files covered

libnvme/src/nvme/ (22 files): Notable fixes include lib.c (system headers after local includes), no-json.c (<errno.h> after <libnvme.h>), cmds.h (standard headers after project headers), private.h (ccan before sys/), ioctl.c (conditional <liburing.h> inside standard block), linux.c (<fcntl.h> and <unistd.h> grouped with sys/*).

libnvme/test/: Fixed group violations (project/local headers before standard) in test.c, zns.c; ordering fixes across mi.c, mi-mctp.c, mock-ifaddrs.c, psk.c, register.c, test-util.c, tree.c, uriparser.c, uuid.c, and all config/, ioctl/, nbft/ test files.

libnvme/examples/: Fixed group violations (ccan/dbus after project headers) in all 6 example files.

Top-level nvme-cli: Major structural fix in nvme.c (project headers before standard); group and ordering fixes in fabrics.c, logging.c, nvme-models.c, nvme-print.c, nvme-print-stdout.c, nvme-print.h, nvme-rpmb.c, nvme.h, plugin.c.

util/: argconfig.c, base64.c, suffix.c, argconfig.h, cleanup.h, crc32.h.

unit/: All 5 unit test files.

plugins/: feat, lm, ocp (fw-activation-history, smart-extended-log, utils), solidigm (workload-tracker, log-page-dir, all telemetry/ files), seagate, sed, ymtc, sandisk/wdc utils headers.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- mi.c: remove duplicate #include <stdlib.h>
- generate-accessors.c: remove duplicate #include <string.h> and #include <stdio.h>
- ioctl.c: remove unused #include <inttypes.h> and #include <sys/time.h>
- base64.c: remove unused #include <sys/types.h>
- log.c: remove unused #include <sys/types.h>

Co-authored-by: igaw <1050803+igaw@users.noreply.github.com>
Copilot AI changed the title [WIP] Review includes in nvme source files libnvme/nvme: clean up includes in src/nvme/ source files Mar 4, 2026
Copilot finished work on behalf of igaw March 4, 2026 16:41
@igaw
Copy link
Owner

igaw commented Mar 4, 2026

@copilot while at it also order header like it is commonly recommended

Apply the commonly recommended include ordering across all files in
libnvme/src/nvme/:

1. Standard/POSIX headers (alphabetical)
2. System headers with path prefix: sys/, arpa/, linux/, net/ (alphabetical)
3. Third-party library headers: ccan, dbus, json, keyutils, liburing,
   openssl (alphabetical)
4. Project public headers: libnvme.h, libnvme-mi.h, nvme/...
5. Local/private headers: "..."

Notable structural fixes:
- lib.c: system includes were below local "private.h" includes
- no-json.c: <errno.h> was after <libnvme.h>
- cmds.h: standard headers were after project <nvme/...> headers
- private.h: ccan headers were before sys/ and poll.h/ifaddrs.h
- generate-accessors.c: sys/ headers were interspersed among standard headers
- ioctl.c: conditional <liburing.h> moved from inside standard-headers
  block to the third-party section
- linux.c: <fcntl.h> and <unistd.h> were grouped inside sys/* instead
  of standard headers

Co-authored-by: igaw <1050803+igaw@users.noreply.github.com>
Copy link
Author

Copilot AI commented Mar 4, 2026

@copilot while at it also order header like it is commonly recommended

Done in 0c04705. Applied the commonly recommended ordering across all 22 affected files in libnvme/src/nvme/:

  1. Standard/POSIX headers (alphabetical)
  2. System headers with path prefix (sys/, arpa/, linux/, net/) (alphabetical)
  3. Third-party library headers (ccan, dbus, json, keyutils, liburing, openssl) (alphabetical)
  4. Project public headers (libnvme.h, <nvme/...>)
  5. Local/private headers ("...")

The most significant structural fixes were lib.c (system headers were below local includes), no-json.c (<errno.h> after <libnvme.h>), cmds.h (standard headers after project headers), private.h (ccan before sys/), and ioctl.c (conditional <liburing.h> moved out of the standard headers block to the third-party section).

Copilot AI changed the title libnvme/nvme: clean up includes in src/nvme/ source files libnvme/nvme: clean up and order includes in src/nvme/ source files Mar 4, 2026
Copilot finished work on behalf of igaw March 4, 2026 17:32
@igaw
Copy link
Owner

igaw commented Mar 12, 2026

@copilot rebase and also check all other source code files, e.g. tests

Extend the include ordering cleanup to all C source and header files
across the whole repository, covering:

- libnvme/src/nvme/: remaining issues in util.c, cleanup.h, linux.c
- libnvme/test/: all test files (mi.c, mi-mctp.c, mock-ifaddrs.c,
  psk.c, register.c, test.c, test-util.c, tree.c, uriparser.c,
  uuid.c, zns.c, hkdf_add1.c, config/*, ioctl/misc.c, ioctl/mock.c,
  ioctl/zns.c, nbft/nbft-dump.c)
- libnvme/examples/: discover-loop.c, mi-conf.c, mi-mctp.c,
  mi-mctp-ae.c, mi-mctp-csi-test.c, telemetry-listen.c
- nvme-cli top-level: fabrics.c, logging.c, nvme-models.c,
  nvme-print.c, nvme-print-stdout.c, nvme-print.h, nvme-rpmb.c,
  nvme.c, nvme.h, plugin.c
- util/: argconfig.c, base64.c, suffix.c, argconfig.h, cleanup.h,
  crc32.h
- unit/: test-argconfig-parse.c, test-suffix-*.c, test-uint128*.c
- plugins/: feat, lm, ocp, solidigm (including telemetry/),
  seagate, sed, ymtc, sandisk/wdc utils headers

Convention applied consistently:
  1. Standard/POSIX headers (alphabetical)
  2. System headers (sys/, arpa/, linux/, net/, asm/) (alphabetical)
  3. Third-party headers (ccan, dbus, json, openssl, ...) (alphabetical)
  4. Project public headers (<libnvme.h>, <nvme/...>)
  5. Local/private headers ("...")

Also removes duplicate <unistd.h> in sandisk-utils.h and wdc-utils.h.

Co-authored-by: igaw <1050803+igaw@users.noreply.github.com>
Copy link
Author

Copilot AI commented Mar 12, 2026

@copilot rebase and also check all other source code files, e.g. tests

Done in 69436b5. Applied the include ordering convention to all source files across the entire repository:

  • libnvme/src/nvme/: remaining minor fixes (util.c, cleanup.h, linux.c)
  • libnvme/test/: 17 test files
  • libnvme/examples/: 6 example files
  • Top-level nvme-cli: fabrics.c, logging.c, nvme-models.c, nvme-print.c, nvme-print-stdout.c, nvme-print.h, nvme-rpmb.c, nvme.c, nvme.h, plugin.c
  • util/: argconfig.c, base64.c, suffix.c, argconfig.h, cleanup.h, crc32.h
  • unit/: 5 unit test files
  • plugins/: feat, lm, ocp, solidigm (including telemetry/), seagate, sed, ymtc, sandisk/wdc utils headers

Also removes duplicate <unistd.h> in sandisk-utils.h and wdc-utils.h. All 52 tests pass.

Copilot AI changed the title libnvme/nvme: clean up and order includes in src/nvme/ source files nvme-cli: clean up and order includes across all source files Mar 12, 2026
Copilot finished work on behalf of igaw March 12, 2026 08:57
@igaw igaw closed this Mar 12, 2026
@igaw igaw deleted the copilot/review-includes-nvme-files branch March 12, 2026 11:14
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