Skip to content

compat: Adds more platform compatibility headers and mem compatibility.#3310

Draft
bgoing-micron-oss wants to merge 1 commit into
linux-nvme:masterfrom
Micron-TPG-OSS:bgoing/additional-compatibility-includes
Draft

compat: Adds more platform compatibility headers and mem compatibility.#3310
bgoing-micron-oss wants to merge 1 commit into
linux-nvme:masterfrom
Micron-TPG-OSS:bgoing/additional-compatibility-includes

Conversation

@bgoing-micron-oss
Copy link
Copy Markdown
Contributor

  • Adds compatibility headers that provides functionality missing from Windows headers and cross-platform compatibility macros.
  • Adds memory management compatibility for aligned memory allocation and freeing. Windows has a seprate aligned free that needs to be used for aligned memory.

@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Apr 27, 2026

I'll try find some time to dive into these patches soon but I need to prepare for next week LSFMM and am not completely done with my POC yet.

Comment thread libnvme/src/nvme/mkdir.h
#include <direct.h>

/* Windows mkdir doesn't take the mode parameter */
#define mkdir(path, mode) _mkdir(path)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is no user of mkdir in the library. The only users are in the plugins, thus we should not add this helper here.

Copy link
Copy Markdown
Contributor Author

@bgoing-micron-oss bgoing-micron-oss May 12, 2026

Choose a reason for hiding this comment

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

Thanks for the feedback. Do you have a recommendation for where you would like to see this type of compatibility definition if not here? It is used across multiple plugins, and there isn't currently a pattern for shared utilities or definitions specifically for plugins.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So my aim is first to analyze if we can replace/rewrite the code so we don't need any special wrappers. If not possible, a wrapper has to be placed to the library (private if possible). If only nvme-cli is using it we should add something there. Generally, I am looking for the smallest impact radius.

Not sure yet how to handle this one but it looks like only the plugins are using mkdir and I wonder what these plugins are doing...

Anyway, I am running out of steam for today.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since this are no users in the library, I ignore this problem for now. First goal so sort out all the problems in the library

Comment thread libnvme/src/nvme/stdio.h Outdated
fputs(buffer, stderr);
else if (fd == STDOUT_FILENO)
fputs(buffer, stdout);
return result;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fd could be also a normal file descriptor. Let's not worry about this and just replace dprintf with asprintf and write.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Are you referring to using asprintf and write here in a compatibility implementation, or in log.c, which is the one place it is currently used?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IIRC, I picked dprintf just because it was simplest. Since we arleady use apsrintf in this function to format the message I don't see why not to use one more time. The final message can then just written out using the write command (with retry on EINTR etc).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've got this covered in my next PR based on this work.

Comment thread libnvme/src/nvme/stdio.h Outdated
}

/* open_memstream workaround for Windows - returns a temporary file instead */
static inline FILE *open_memstream(char **ptr, size_t *sizeloc)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've refactored the only user of this function so it doesn't use open_memstream anymore.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

and it's back with the new nvme top feature. Let's see what we have to do with this one. Maybe we have to make this feature an compile time option in the beginning because I don't think I am able to cheat with this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks like the new nvme top feature is very linux-specific, and will require a separate effort to port, if possible. Making it a compile-time option for now sounds like a good idea.

Comment thread libnvme/src/nvme/signal.h
* Simplified signal handling using Windows signal() function
* This is sufficient for handling SIGINT with no mask or flags.
*/
static inline int sigaction(int signum, const struct sigaction *act,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The library itself doesn't do any signal stuff which also makes sense, a library should never interfere with this API. So we should take this to nvme-cli. I think we have to implement util/sighdl.h so it's portable, thus we might need to either introduce util/signhdl-linux.c/util/signhdl-win.c or have some ifdefery there.

Comment thread libnvme/src/nvme/unistd.h
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@igaw I should have noticed during my review yesterday, but these got pulled into mem-win.c. Only getpagesize is used there, so it doesn't do any good to have the others there. gethostname, fsync, and getpagesize are still all used elsewhere in the code, which is why they were in a unistd compatibility header. Do you have concerns about handling compatibility in this way? I do see that most of the uses, particularly of fsync, are within nvme-cli, not libnvme, but since it was used across both this seemed like a good way to handle it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I really want to avoid exposing compatibility functions in the public library API as much as possible. There are dragons there (been there, done that). So my plan is to go through each function and figure out what the options are.

  • fsync: used only in nvme-cli, so it should go there somewhere
  • getpagesize: there are only a few callsites left, let's review them and see what is really necessary
  • gethostname: looks like this one is only used for fabrics. that means we should move it to new util-fabrics.c

Ideally, every change improves the code base for all users and avoids complex indirection and other difficult abstractions to handle.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@igaw What do you think of common.h as a potential home for things like fsync, getpagesize and mkdir that are used across nvme-cli and plugins? It seems to align with the mmio compatibility methods that are already there, and is already included everywhere those methods are needed.

- Adds compatibility headers that provides functionality missing from
Windows headers and adds cross-platform compatibility macros.

Signed-off-by: Broc Going <bgoing@micron.com>
@bgoing-micron-oss bgoing-micron-oss force-pushed the bgoing/additional-compatibility-includes branch from b7b325c to f4730b4 Compare May 14, 2026 16:28
@bgoing-micron-oss bgoing-micron-oss marked this pull request as draft May 14, 2026 16:28
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