Skip to content

Conversation

@GenericRikka
Copy link

Summary

This PR makes mpifileutils build on FreeBSD (and generally non-Linux platforms) by guarding Linux-only APIs/headers and providing small compatibility fallbacks.

These changes were developed while preparing the FreeBSD ports package and are intended to be upstreamable, minimal, and low-risk for Linux behavior.

Key changes

  • Guard Linux-only headers/APIs behind __linux__ (e.g. <sys/sysinfo.h>, <linux/fiemap.h>, FS_IOC_FIEMAP).
  • Use syscall(SYS_getdents) on Linux, and getdents(2) wrapper on non-Linux in mfu_flist_walk.
  • Avoid the Linux xattr API on non-Linux builds:
    • only include <sys/xattr.h> on Linux
    • non-Linux xattr code paths either compile out or return ENOTSUP (so core functionality remains available)
  • FreeBSD/non-Linux portability fixes:
    • stat64/lstat64 compatibility mapping where needed
    • HOST_NAME_MAX fallback
    • missing macro fallbacks (S_ISLNK, POSIX_FADV_SEQUENTIAL, O_LARGEFILE if absent)
    • fix one errno logging format issue

Platform impact

  • Linux: behavior should remain unchanged (Linux-only fast paths remain enabled).
  • Non-Linux (FreeBSD/BSD): builds successfully; Linux-only features like fiemap sparse copying and Linux xattr preservation are disabled until a native implementation is added.

Testing

  • Built and packaged via FreeBSD ports tooling (poudriere testport / stage-qa / plist checks).
  • Local build tests on FreeBSD with MPI (OpenMPI/MPICH).

References

These are the core FreeBSD portability changes extracted from the FreeBSD ports tree work. The port currently is still under review.
Port PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291679
Port review: https://reviews.freebsd.org/D54230

The Patches:
 - Add FreeBSD compatibility for stat64/lstat64 by mapping them to stat/lstat (which are 64 bit by default on FreeBSD)
 - Include missing system headers in the path/parameter helper so struct stat and related macros are consistently available
 - Fix MFU_LOG(... "errno=%d %s" ...) callsites in mfu_util.c to actually pass both errno and strerrno(errno) (prevents format/argument mismatch and undefined behavior)
 - Include <fcntl.h> in mfu_util.c for file/flag-related definitions used by the code on non-Linux systems
- Use getdents(2) wrapper on non-Linux instead of SYS_getdents syscall
  in mfu_flist_walk.

- Make FIEMAP-based extent discovery Linux-only in mfu_flist_copy and
  fall back to normal copy on non-Linux when SEEK_DATA/SEEK_HOLE does
  not provide extents.

No behavior changes on linux intended; this unblocks part of the building process of mpifileutils on FreeBSD.
Make the bzip2 compression/decompression code build on FreeBSD and other
non-Linux platforms by isolating Linux-only libcircle pieces and keeping
a portable fallback.

- Keep the existing libcircle-based implementation on Linux.
- Guard Linux-only includes/assumptions (e.g. sysinfo / libcircle headers).
- Provide a non-Linux fallback for the libcircle entry points that forwards
  to the portable static bzip2 implementation.
- Keep the public interfaces consistent while enabling non-Linux builds.

No behavior change intended on Linux; non-Linux builds use the static path
instead of libcircle.
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.

1 participant