Skip to content

common,osd,rgw: fill in the Darwin side of the compatibility layer - #71888

Open
dvanders wants to merge 10 commits into
ceph:mainfrom
dvanders:wip-macos-6-darwin-compat
Open

dvanders wants to merge 10 commits into
ceph:mainfrom
dvanders:wip-macos-6-darwin-compat

Conversation

@dvanders

@dvanders dvanders commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Split out of #71232, which reviewers asked to see in smaller batches.
Based on main; independent of the other six. The macOS build also needs
@tchaikov's #72482 (endian macros) and #72484 (unversioned object class
libraries).

src/include/compat.h and friends already carry a Darwin branch; it is
just missing pieces. This fills them in, and fixes a few things that are
not additions:

  • compat.h: the definitions the Darwin branch was missing, the fadvise
    fallback, and ENOKEY; numa.h including it for cpu_set_t
  • compat.cc: __STDC_WANT_LIB_EXT1__ defined before the first
    <string.h>, not after
  • blkdev.cc: the three helpers the Darwin branch does not define
  • tcp_info.cc: stubbed, as on Windows — Darwin's
    struct tcp_connection_info shares no fields with Linux' tcp_info
  • admin_socket.cc: the raise hook gated on a new HAVE_TIMER_CREATE
    rather than on !WIN32, since POSIX per-process timers are what it
    actually needs; where they are absent, raise --after fails with
    -ENOTSUP (as on Windows) and the corresponding tests are skipped
  • auth/Crypto.cc: the /dev/urandom fallback opened in the right
    namespace
  • rgw_file: two reads of the stat timespecs going through the same
    HAVE_STAT_ST_MTIMESPEC_TV_NSEC guard the writes in the same file
    already use

The entity_addr_t encoding fix on the BSDs that was here has been
dropped in favour of @wjwithagen's #71445, which fixes it the same way.
Likewise the Darwin endian fallbacks and a ClassHandler.cc change to skip
versioned libcls_*.dylib names, in favour of #72482 and #72484, which
remove the need for them.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

@wjwithagen

Copy link
Copy Markdown
Member

Hi Dan,

You might want to checkout:
#71445

Which has more or less the same functioning, but at the suggestion of @tchaikov
It was compressed to even less code.
So you might have a look at that, and when you think it is oke, give it a thumbs up.

@dvanders
dvanders force-pushed the wip-macos-6-darwin-compat branch from 9f07560 to b9509b3 Compare September 23, 2026 06:05
@dvanders dvanders changed the title common,osd,rgw,msg: fill in the Darwin side of the compatibility layer common,osd,rgw: fill in the Darwin side of the compatibility layer Sep 23, 2026
@dvanders

Copy link
Copy Markdown
Contributor Author

You might want to checkout: #71445

Which has more or less the same functioning, but at the suggestion of @tchaikov It was compressed to even less code. So you might have a look at that, and when you think it is oke, give it a thumbs up.

Agreed, #71445 is the same encode fix and further along, so I've dropped mine from here. I left one comment there about the matching check in decode().

@dvanders
dvanders force-pushed the wip-macos-6-darwin-compat branch from b9509b3 to b22f615 Compare October 1, 2026 22:15
@dvanders

dvanders commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main, no changes. @tchaikov @wjwithagen could you take a look at the common/compat commits? Several touch the shared BSD/Darwin branches. @mattbenjamin, the one rgw_file commit is a small guard fix for the stat timespec reads.

@dvanders

dvanders commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

@wjwithagen wjwithagen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Runs on FreeBSD..

Comment thread cmake/modules/CephChecks.cmake Resolved
@wjwithagen

Copy link
Copy Markdown
Member

LGTM for FreeBSD

@dvanders
dvanders force-pushed the wip-macos-6-darwin-compat branch from b22f615 to 4fbff92 Compare October 6, 2026 23:18
static std::optional<Killer> arm(CephContext* m_cct, int signal_to_send, double delay)
{
#ifndef WIN32
#ifdef HAVE_TIMER_CREATE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

might want to update the #ifdef at line 1028 as well, otherwise -EAGAIN is returned.

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 catch, thanks. That early return is now #ifndef HAVE_TIMER_CREATE, so platforms without POSIX timers get -ENOTSUP and a message saying why (as Windows already did), rather than -EAGAIN from a timer that couldn't be armed. Folded into "common: gate the admin socket raise hook on POSIX timer support". Checked on macOS: ceph daemon osd.0 raise SIGHUP --after 5 now returns (45) Operation not supported with '--after' needs POSIX per-process timers, which this platform lacks.

Comment thread src/include/compat.h
#endif
#ifndef ENOKEY
#define ENOKEY 126
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the commit message reads:

The fscrypt paths return -ENOKEY for a missing key, and fuse_ll.cc maps it in cephfs_errno_to_system_errno. Darwin has no such errno, so the translation unit does not compile there at all.

but please note, the fuse_ll.cc entry is already behind #if defined(ENOKEY). i think the uses that break the build are Client.cc, FSCrypt.cc and rgw_sal_posix.cc. could you please help confirm and update the message to name those instead?

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.

Confirmed: fuse_ll.cc is guarded, and the uses that break the build are Client.cc (3), FSCrypt.cc and rgw_sal_posix.cc, plus the tests test/common/test_keyring.cc and test/libcephfs/fscrypt.cc. The commit message names those now, and notes that the guarded fuse_ll.cc entry now applies on Darwin too.

Comment thread src/include/compat.h Resolved
Comment thread src/rgw/rgw_file_int.h Resolved
Comment thread src/osd/ClassHandler.cc Resolved
compat.h only forward declared cpu_set_t on Darwin, which is not enough for
the callers that have to declare one - OSD::numa_cpu_set is a member, and
OSDMonitor has a local.  Define it, shaped like the Windows shim further down
the file; numa.cc's non-Linux stubs never inspect the value.

PROCPREFIX was defined for Linux and FreeBSD only, so the /proc readers in
common/util.cc and common/MemoryModel.h did not compile anywhere else.  Darwin
has no procfs; define it empty so they build and fail at runtime instead, which
they already handle.

off64_t goes next to the existing lseek64 shim.  Darwin's off_t is already 64
bits wide, and include/types.h has the same typedef for callers that include
it instead.

numa.h has to include compat.h to see cpu_set_t, as it already does on
Windows.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
memset_s() is only declared when __STDC_WANT_LIB_EXT1__ is defined before
<string.h> is first included.  compat.cc did define it, but only just above
its own #include <string.h>, by which point include/compat.h at the top of the
file had already pulled <string.h> in and the include guard made the second one
a no-op.  ceph_memzero_s() then failed to compile wherever HAVE_MEMSET_S was
set.

Move the feature macro above the first include.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
Darwin has no Linux struct tcp_info and none of the TCP_* connection state
constants; it exposes connection statistics as struct tcp_connection_info via
TCP_CONNECTION_INFO, which shares no fields with the Linux structure.

Reuse the stub the Windows build already uses.  Mapping the Darwin structure
onto the same formatter keys would be a reasonable follow-up.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
block_device_run_smartctl(), block_device_get_metrics() and
block_device_run_nvme() are defined in the Linux, FreeBSD and generic branches
of blkdev.cc, but not in the Darwin one, so anything linking libmon or libosd
failed with undefined symbols.

Add the same -EOPNOTSUPP stubs the generic branch uses.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
The rgw needs posix_fadvise(2), which Darwin does not have.  The call is
purely advisory - it hints the page cache and nothing more - so ignoring
it is a faithful degradation, and it is what the bundled RocksDB already
does on this platform.  Keep the Linux numbering for the POSIX_FADV_*
values, because they reach the callers through configuration options
(rgw_d3n_l1_fadvise, rgw_d4n_l1_fadvise) rather than as literals.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
The fscrypt code in the client (Client.cc, FSCrypt.cc) and the RGW POSIX
driver (rgw_sal_posix.cc) return -ENOKEY for a missing key, and the
fscrypt and keyring tests expect it.  Darwin has no such errno, so those
translation units do not compile there.  (fuse_ll.cc already guards its
entry in cephfs_errno_to_system_errno with #if defined(ENOKEY); with the
define, that entry now applies on Darwin too.)

Define it beside the EUCLEAN, EREMOTEIO and EKEYREJECTED fallbacks that
are already in the Darwin block, keeping the Linux value 126 the way
those keep theirs - the value matters, because it is what arrives over
the wire and what common/darwin_errno.cc converts from.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
RaiseHook arms a POSIX per-process timer to deliver a delayed signal.  The
code was gated on !WIN32, but Windows is not the only platform without
timer_create(2) - Darwin does not implement POSIX timers either.

Probe for timer_create() and gate on that.  _POSIX_TIMERS is not a usable
proxy: Darwin defines it as -1, which per POSIX means the feature is declared
but unsupported.

Refuse "raise --after" with -ENOTSUP wherever the timer is not built,
as Windows already did, rather than failing to arm it and returning
-EAGAIN.

acconfig.h has to be included explicitly, because admin_socket.h does not pull
it in and the macro would otherwise be invisible everywhere, quietly disabling
the hook on platforms that do support timers.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
The four AdminSocketRaise tests that exercise "raise --after" were skipped on
Windows only.  The asok raise hook now builds its delayed path only when
HAVE_TIMER_CREATE, since Darwin, like Windows, does not implement the POSIX
per-process timers, and there the tests hang until they time out.

Skip on the same condition the hook is compiled under, and keep the WIN32
check in StopCont, which additionally needs SIGSTOP and SIGCONT.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
The !HAVE_GETENTROPY && !_WIN32 branch defines the CryptoRandom members
without opening namespace TOPNSPC::auth, while the #endif that follows all
three branches closes it.  The branch therefore cannot compile.

Both of the other branches open the namespace, and no platform built in CI
takes this one, so the mistake went unnoticed.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
rgw_file_int.h already spells the timespec members both ways where it writes
them, under HAVE_STAT_ST_MTIMESPEC_TV_NSEC, because Darwin calls them
st_atimespec rather than st_atim.  The two places that read them were missed
and name the Linux members directly.

Use the same guard, so the file is consistent with itself.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Dan van der Ster <[email protected]>
@dvanders
dvanders force-pushed the wip-macos-6-darwin-compat branch from 4fbff92 to c8705e8 Compare October 9, 2026 05:10
@dvanders

dvanders commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@tchaikov your five comments from 8 October are answered in c8705e8; two of the threads are still open on your side. Is this ready for needs-qa?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants