Skip to content

tests: fix S_IFMT undeclared at statx.c #17294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025

Conversation

jlsalvador
Copy link
Contributor

S_IFMT is declared in sys/stat.h, but we cannot include this header because it redeclares the statx function with different argument types. Therefore, we define S_IFMT ourselves, in the same way as the other definitions.

Closes: #17293

Motivation and Context

OpenZFS 2.3.2 fails to compile with musl libc due to S_IFMT not being defined. This issue did not exist in 2.3.1.

The breaking change was introduced in commit 6503f8c, which added a new test command (tests/zfs-tests/cmd/statx). Unfortunately, on some systems (notably musl), including <sys/stat.h> redefines the statx function with incompatible argument types, making it unusable.

To avoid including <sys/stat.h> while still using S_IFMT, we define S_IFMT manually if it is not already defined.

Description

Define S_IFMT as 0170000 if it is not already defined. This value is consistent across major libc implementations, including musl, glibc, and uClibc.

How Has This Been Tested?

Compiling OpenZFS 2.3.2 with this patch using glibc, musl and uClibc.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

`S_IFMT` is declared in `sys/stat.h`, but we cannot include this header
because it redeclares the `statx` function with different argument
types. Therefore, we define `S_IFMT` ourselves, in the same way as the
other definitions.

Closes: #17293

Signed-off-by: José Luis Salvador Rufo <[email protected]>
@robn
Copy link
Member

robn commented May 2, 2025

Looks right, just waiting to see what the test robots make of it.

@amotin amotin added the Status: Accepted Ready to integrate (reviewed, tested) label May 2, 2025
@amotin amotin merged commit 634c172 into openzfs:master May 2, 2025
23 of 24 checks passed
@jlsalvador jlsalvador deleted the fix-musl-S_IFMT branch May 2, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MUSL can not compiles OpenZFS 2.3.2 because of S_IFMT
4 participants