Skip to content

Refactor/replace code for more portability (part 1)#3355

Merged
igaw merged 6 commits into
linux-nvme:masterfrom
igaw:win-dprintf-getlien
May 13, 2026
Merged

Refactor/replace code for more portability (part 1)#3355
igaw merged 6 commits into
linux-nvme:masterfrom
igaw:win-dprintf-getlien

Conversation

@igaw
Copy link
Copy Markdown
Collaborator

@igaw igaw commented May 12, 2026

A bunch of functions are not easy portable, thus try to get rid of the by either refactor/replace the code so these are not used anymore.

These are changes based on #3310

@igaw
Copy link
Copy Markdown
Collaborator Author

igaw commented May 12, 2026

@bgoing-micron-oss the next PR ontop of the memory API changes.

dprintf is not available on Windows, so open-code it using asprintf and
write.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
@igaw igaw force-pushed the win-dprintf-getlien branch from 7611781 to 4da151b Compare May 13, 2026 07:10
@igaw
Copy link
Copy Markdown
Collaborator Author

igaw commented May 13, 2026

@bjpaupor quick question on nvme-models.c You were the last one to really change something on this file back in 2021. Somewhere later we dropped to the call to open_pci_ids, basically turning the whole nvme-models.c code abandon. Do you still need this, should we revive it?

@igaw igaw force-pushed the win-dprintf-getlien branch from 4da151b to 1d74b9d Compare May 13, 2026 09:27
@igaw
Copy link
Copy Markdown
Collaborator Author

igaw commented May 13, 2026

@bjpaupor Forget it, I just brought the feature back :)

@igaw igaw force-pushed the win-dprintf-getlien branch from 1d74b9d to 85c49e9 Compare May 13, 2026 09:31
@igaw igaw requested a review from Copilot May 13, 2026 09:32
@igaw igaw changed the title Replace dprintf and getline Refactor/replace code for more portability (part 1) May 13, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve Windows portability by removing/avoiding non-portable libc APIs (dprintf, getline, open_memstream) and plumbing a device-derived “product name” into the identify controller output path.

Changes:

  • Replaced dprintf() usage in libnvme logging with a buffer + write loop approach.
  • Replaced getline() usage with fgets() in a couple of parsing/reading paths.
  • Extended the id_ctrl printing API to optionally include a derived product_name in stdout/JSON output.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
plugins/micron/micron-nvme.c Updates nvme_show_id_ctrl() call site to pass transport handle name.
nvme.c Updates nvme_show_id_ctrl() call site to pass transport handle name.
nvme-print.h Changes print_ops->id_ctrl and nvme_show_id_ctrl() signatures to carry product/device name context.
nvme-print.c Computes product_name via nvme_product_name(devname) and passes it into the print backend.
nvme-print-stdout.c Prints product_name before the controller identify output; removes open_memstream usage in effects log printing.
nvme-print-json.c Adds product_name to JSON identify-controller output.
nvme-print-binary.c Updates binary identify-controller print signature to match new print_ops.
nvme-models.h Changes nvme_product_name() to accept a device name string rather than an integer id.
nvme-models.c Replaces getline() with fgets(); adds device-name parsing to obtain controller instance id.
libnvme/src/nvme/log.c Replaces dprintf() with asprintf() + write_all() implementation.
libnvme/src/nvme/linux.c Replaces getline() with fgets() for reading product_uuid; adds additional validation.
libnvme/src/meson.build Moves nvme/log.c into unconditional sources list (now built on Windows too).
Comments suppressed due to low confidence (1)

libnvme/src/nvme/log.c:119

  • Calling perror() here introduces an unconditional stderr side effect from inside the library logging path, which can surprise consumers (and may recurse if stderr logging is also routed back into libnvme). Prefer returning silently, or reporting the failure via the existing libnvme logging mechanism/state rather than printing directly to stderr.
	if (write_all(l->fd, log, strlen(log)) < 0)
		perror("failed to write log entry");

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libnvme/src/meson.build
Comment thread libnvme/src/nvme/log.c
Comment thread libnvme/src/nvme/linux.c Outdated
Comment thread libnvme/src/nvme/linux.c
Comment thread nvme-print-stdout.c Outdated
igaw added 5 commits May 13, 2026 11:46
getline is not available on all platforms. Since the UUID input
has a fixed and well-defined format, use fgets instead.

This avoids the dynamic allocation from getline and improves
portability

Signed-off-by: Daniel Wagner <wagi@kernel.org>
stdout_effects_log_segment wants to print a header if there are any log
entries. This is done using a memstream for

- a "did anything print?" detector
- plus a temporary accumulation buffer

That's overkill here. Refactor this function with the side effect it
also portable.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
The make the port on Windows simpler replace getline with fgets.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Make the interface easier to use on the callside by asking for the
device name instead the id.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
Somewhere in the past the support to print the product name was lost.
Bring it back.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
@igaw igaw force-pushed the win-dprintf-getlien branch from 85c49e9 to 58d0db5 Compare May 13, 2026 09:48
@igaw igaw merged commit 1967498 into linux-nvme:master May 13, 2026
28 of 29 checks passed
@igaw
Copy link
Copy Markdown
Collaborator Author

igaw commented May 13, 2026

let's go with this set of changes. more to come...

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