Jlmunn/platform compatibility refactor#3289
Closed
jimmunn wants to merge 130 commits intolinux-nvme:masterfrom
Closed
Jlmunn/platform compatibility refactor#3289jimmunn wants to merge 130 commits intolinux-nvme:masterfrom
jimmunn wants to merge 130 commits intolinux-nvme:masterfrom
Conversation
Upstream sync into mingw
* feat: Windows cross-platform support for libnvme Added libnvme build support for Windows. - Added platform-specific include files for Linux/Windows. - Added BUILD.md with detailed build instructions for Linux and Windows - Added ENVIRONMENT.md with environment setup guide for both platforms - Fix format string warnings in nbft.c (use %u instead of %zd for MinGW compatibility) - Add forward declarations in windows-stubs.c to fix struct warnings - Skipping generate-accessors for now. Needs to be ported for Windows. - Note: leaving asprintf warning in generate-accessors.c since it is present in the master branch as well. Co-authored-by: Broc Going <[email protected]> Co-authored-by: bbusacker <[email protected]> Co-authored-by: Brandon Capener <[email protected]> Co-authored-by: Copilot <[email protected]>
Add Micron build files.
* add tests kdoc and uuid * Update libnvme/scripts/kernel-doc-check.ps1 no perl found error message Co-authored-by: Broc Going <[email protected]> --------- Co-authored-by: Broc Going <[email protected]>
* Merge origin/master into mingw * add guards around the incoming upstream MIN macro
…inux-nvme#38) * Merge origin/master into mingw * Initial plan * Fix circular dependency in platform_linux.h by removing cleanup.h include Co-authored-by: bbusacker_micron <[email protected]> * use the code base standard for initializing variables --------- Co-authored-by: Brandon Capener <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: bbusacker_micron <[email protected]>
* docs: Add comprehensive TODO.md for Windows port status
- Document all excluded plugins with priority ratings
- Detail critical missing device I/O functionality
- List implementable stubs (global context, dry-run, host NQN)
- Clarify fabrics string converters not needed (require Linux kernel)
- Add implementation phases and effort estimates
- Minor cleanup: nvme-rpmb.c whitespace
* feat: Add Windows support for nvme-cli
Enable compilation and linking of nvme-cli on Windows using MinGW-W64.
The build succeeds and produces a functional nvme.exe with help system
and 19 vendor plugins. Device I/O operations are stubbed (see TODO.md).
Core Changes:
- Expanded Windows POSIX compatibility layer in platform/windows.h/.c
* dirent emulation (opendir/readdir/closedir)
* POSIX functions: getline, strsep, reallocarray, gmtime_r
* Signal handling: sigaction, sigemptyset
* Memory mapping stubs: mmap, munmap, madvise
* DLL loading: dlopen/dlsym/dlclose wrappers
* mkdir wrapper, readlink stub, open_memstream stub
* Fabrics/RPMB command stubs (commands registered but unsupported)
- Add platform/types.h stub that defines Windows equivalents to linux/types.h.
- Extend libnvme/src/nvme/windows-stubs.c with 120+ stub functions
* Keyring/TLS functions (nvme_read_key, nvme_insert_tls_key_*, etc.)
* Fabrics string converters (nvmf_trtype_str, nvmf_sectype_str, etc.)
* Tree/topology functions (nvme_scan_topology, nvme_create_root, etc.)
* Device operations (nvme_open, nvme_close)
* Host NQN generation (nvmf_hostnqn_generate*)
* NBFT, global context, path properties
Build System Changes:
- Update meson.build to exclude fabrics.c and nvme-rpmb.c on Windows
- Add windows-stubs.c to Windows-specific sources
- Add Windows library dependencies (ws2_32, wsock32, kernel32, iphlpapi)
- Conditional link args (-ldl on Linux only)
- Update plugins/meson.build:
* 19 cross-platform plugins enabled (including micron)
* 10 Linux-only plugins excluded (huawei, ibm, netapp, sandisk,
scaleflux, wdc, ymtc, zns, lm)
Code Modifications:
- Changed #include of linux/includes.h to platform/includes.h accross the project.
- Add min/max macro guards in common.h to prevent Windows conflicts
Known Limitations:
- All device I/O operations are stubbed (ioctl returns -ENOSYS)
- Cannot open NVMe devices or enumerate devices
- fabrics and rpmb commands print 'not supported on Windows'
- See TODO.md for detailed implementation roadmap
* Fix Windows compilation warnings
- plugins/intel/intel-nvme.c: Use uintptr_t for pointer-to-int casts for 64-bit compatibility
- plugins/micron/micron-nvme.c: Guard min macro definition to avoid redefinition warnings
- plugins/micron/micron-nvme.c: Replace %T with %H:%M:%S in strftime for Windows compatibility
- nvme-print-stdout.c: Fix array-bounds warnings with proper union-based type conversion
* Consolidate Windows platform headers
Reorganizes Windows compatibility layer for cleaner separation between
OS-level abstractions (libnvme) and application-specific code (nvme-cli).
OS-level abstractions (libnvme platform layer):
- Created libnvme/src/nvme/platform/platform_windows.h
* Windows-specific includes (winsock2.h, windows.h, dirent.h)
* POSIX compatibility: getline, strsep, reallocarray, readlink,
open_memstream, fnmatch
* Signal handling: sigaction, sigemptyset
* Error codes: ENAVAIL, EREMOTEIO, EDQUOT, ENOTBLK, etc.
* ioctl constants: BLKBSZSET, BLKRRPART
* Mode_t typedef and mkdir wrapper macro
- Created libnvme/src/nvme/platform/platform_windows.c
* POSIX function implementations for Windows compatibility
* Added exports to libnvme.map for DLL symbol visibility
Application-level stubs (nvme-cli layer):
- Created windows-stubs.c
* Application-specific stubs: fabrics_discovery, fabrics_connect,
fabrics_disconnect, fabrics_config, fabrics_dim, rpmb_cmd_option
Combined platform-specific support for both nvme-cli and libnvme and restructured and renamed some of the platform-specific files.
- Moved nvme/platform/*.* into platform/*.* and removed platform_ from file names.
- Moved Windows-specific linux/types.h into platform/types.h and fixed it to support linux. Updated references to linux/types.h to use platform/types.h.
* Fixed warnings on Windows.
* PATH_MAX is used for some buffers in micron-nvme.c where it is assumed to be larger than 1024. On Windows it is 260. On Linux it is typically 4096. Using 4096.
- Fixed possible underflow error during size comparison.
---------
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Broc Going <[email protected]>
Co-authored-by: Brandon Capener <[email protected]>
Co-authored-by: Brandon Busacker <[email protected]>
Add workflow to auto-merge master into mingw
Merge commits from master into mingw
Use personal access token (PAT) so workflow can push the merge.
…w-tweaks More tweaks to file
Remove --strict from call to checkpatch.pl to match upstream behavior.
…ed platform/types.h (linux-nvme#96) Recent upstream changes removed the need for platform/types.h and made MI and Fabrics only compile if supported, which they aren't on windows. Cleaning up our Windows support based on these changes. - Removed platform/types.h - Removed platform/includes.h support that is no longer needed - Removed functionality only used by MI and fabrics - Removed endian and log support that is not needed due to upstream refactoring - Removed MI and Fabrics stubs - Restored nbft.c to match master since it only builds with fabrics
Explicitly including tree.h for definitions found there.
- Removed platform/includes usage where possible. - Restored default includes where possible. - Removed unneeded support from platform/windows.h
- Added nvme/stdlib.h - Renamed platform_aligned_free to aligned_free - Updated code to use new header - Removed stdlib compatiblity from windows.h and linux.h
- Added nvme/unistd.h and nvme/malloc.h - Updated code to use new headers instead of platform/includes.h - Removed malloc.h and unistd.h compatibility from windows.h
Only lib-windows.c and ocp-nvme.c used libnvme_fstat, and ocp-nvme.c was easily refactored to use the existing libnvme_transport_handle_is_blkdev check instead. - Refactored ocp-nvme.c to not need libnvme_fsat - Removed public libnvme_fstat - Made implementation in lib-windows.c private and renamed.
- Added HAVE_MMAP definition. - Made mmap usage dependent on HAVE_MMAP. - Removed mmap compatibility from platform.h
NAME_MAX is only used in micron-nvme.c. Moved there instead of adding global compatibility support.
Moved stdio compatibility into nvme/stdio.h and removed it from platform/windows.h
- Moved missing error code definitions to util.c where they are used. - Refactored ENAVAIL usage in nvme.c to use a custom, local error code definition, since it was being used as an internal flag anyway. - Removed ifaddrs struct (not needed). - Cleaned up build warnings in ocp-nvme.c
Only used in one place. Define there.
Defined _POSIX_THREAD_SAFE_FUNCTIONS to enable built-in gmtime_r implementation, and removed windows.h implementation.
libnvme-wrap.c isn't actually used for anything. Instead of adding dlsym support for an unused file, just excluding from the Windows build.
- Moved mkdir compatibility into nvme/mkdir.h and added to plugins that used mkdir. - Enabled plugins building on Windows.
Moved signal.h compatibility into nvme/signal.h
- Removed unneeded includes. - Added gethostname support to nvme/unistd.h
Moved libnvme-specific compatibility types, definitions, and methods into new nvme/lib-compat.h and removed platform/*.h. Also cleaned up and standardized formatting of compatibility headers.
Removed __libnvme_free from private.h. It was only used by fabrics, which isn't supported on Windows, and in cleanup.h. Removed __libnvme_free implementation from util.c Directly calling aligned_free instead. This allows us to get rid of the private.h include in cleanup.h, better matching the recent upstream refactoring.
Contributor
Author
|
Accidentally applied this PR to upstream instead of branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Testing server build.