Skip to content

mgr: override OSD hostname with CRUSH physical host in all metadata paths - #66757

Merged
SrinivasaBharath merged 2 commits into
ceph:mainfrom
senolcolak:wip-v2-mgr-inventory-crush-host
Jul 29, 2026
Merged

SrinivasaBharath merged 2 commits into
ceph:mainfrom
senolcolak:wip-v2-mgr-inventory-crush-host

Conversation

@senolcolak

@senolcolak senolcolak commented Dec 29, 2025 •

Copy link
Copy Markdown
Contributor

Problem

In containerized Ceph deployments (e.g. Rook/OCS), OSD daemons report the
pod or container hostname. The CRUSH map records the physical host. This
mismatch causes ceph device ls to show pod names instead of physical
hosts, breaking host-based device correlation.

Fixes: https://tracker.ceph.com/issues/73080

What was wrong with the previous version

The original patch inserted _override_osd_crush_hostname() inside
if (m->service_daemon) in handle_open. OSDs connect with
service_daemon = false, so that branch is never reached for OSD daemons —
the override was dead code.

In addition, the handle_update insertion called with_osdmap (which
acquires Objecter::rwlock) while holding state->lock, introducing a
new lock ordering state->lock → Objecter::rwlock not present elsewhere.
And setting state->hostname directly before update_metadata would
corrupt the by_server index, because _erase reads dm->hostname at
call time to locate the entry to remove.

Solution

Move the override to the three paths where OSD metadata actually flows:

  1. MetadataUpdate::finish — async mon metadata fetch (primary path,
    runs in Ceph finisher thread). CRUSH resolution happens before taking
    state->lock to preserve lock ordering. The CRUSH hostname is injected
    via m["hostname"] so DaemonStateIndex::update_metadata / set_metadata
    picks it up correctly, keeping the by_server index consistent.

  2. Mgr::load_all_metadata — OSD bulk-load at startup/failover.

  3. All five MetadataUpdate construction sites are updated to pass
    cluster_state to the new 3-argument constructor.

A static free function crush_hostname_for_osd(ClusterState&, int) in
Mgr.cc calls cluster_state.with_osdmap and returns the CRUSH "host"
bucket name for the OSD, or an empty string when absent. The override is a
no-op when the OSD is absent from CRUSH or the OSD map is not yet loaded.

Testing

Verify in a Rook/containerized environment:

  1. ceph device ls shows physical hostnames, not pod names
  2. ceph osd metadata <id> shows correct hostname field
  3. No regression on bare-metal (CRUSH host = reported hostname → no-op)
  4. mgr failover correctly restores hostnames via load_all_metadata

@senolcolak
senolcolak requested a review from a team as a code owner December 29, 2025 20:05
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

14 similar comments
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@rzarzynski

Copy link
Copy Markdown
Contributor

@adk3798, @travisn: does this seem fine from the orchestrators' perspective?

@travisn

travisn commented Jan 8, 2026

Copy link
Copy Markdown
Member

When running in Rook on Tentacle v20.2.0, I don't see any OSDs under ceph device ls:

% ceph osd tree

ID  CLASS  WEIGHT   TYPE NAME          STATUS  REWEIGHT  PRI-AFF
-1         0.11728  root default                                
-3         0.11728      host minikube                           
 0    hdd  0.03909          osd.0          up   1.00000  1.00000
 1    hdd  0.03909          osd.1          up   1.00000  1.00000
 2    hdd  0.03909          osd.2          up   1.00000  1.00000

% ceph device ls

DEVICE  HOST:DEV  DAEMONS  WEAR  LIFE EXPECTANCY

Is something else needed to enable the ceph device tracking?

If the devices aren't even listed, not sure this change will help. But if you have a test ceph image with the changes, I could try it out.

@senolcolak

senolcolak commented Jan 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for checking @travisn . The purpose of this patch is not to enable device tracking, in our clusters it’s already enabled. The issue is the hostname source.

We run Rook on Gardener. Worker nodes get ephemeral hostnames on every redeploy. CRUSH host names are stable. To give you an idea:

  • ceph osd tree -> stable hostnames
  • ceph device ls -> ephemeral hostnames

This breaks our automation (wipeout / redeploy) because device mapping by host becomes inconsistent after a redeploy.

The patch makes ceph device ls use the CRUSH host value (if available) instead of the transient daemon hostname, so both views stay aligned. This fixes the mismatch without changing anything else in the device tracking logic.

To give you an idea.
ceph osd tree:


host node-a
├─ osd.0
├─ osd.1
└─ osd.2

ceph device ls (ephemeral hostname):


DEVICE  HOSTNAME                       OSD
sda     ip-10-42-5-23.cluster1.internal     0
sdb     ip-10-42-5-23.cluster1.internal     1
sdc     ip-10-42-5-23.cluster1.internal     2

After Gardener redeploy (same disks, new hostname):


DEVICE  HOSTNAME                        OSD
sda     ip-10-55-14-101.cluster1.internal    0
...

Result: node-a is not equal to ip-10-55-14-101.cluster1.internal -> automation breaks and it is invalid.

@travisn

travisn commented Jan 9, 2026

Copy link
Copy Markdown
Member

@senolcolak Thanks, the change makes sense from your description. To clarify my previous question, I was just trying to see the results of ceph device ls in my test cluster (on the latest Ceph, without your changes), and it didn't show any results, it was just empty. Any idea why it would be empty in my test cluster? Maybe I'm missing some config to get ceph device ls working with Rook?

@senolcolak

Copy link
Copy Markdown
Contributor Author

@senolcolak Thanks, the change makes sense from your description. To clarify my previous question, I was just trying to see the results of ceph device ls in my test cluster (on the latest Ceph, without your changes), and it didn't show any results, it was just empty. Any idea why it would be empty in my test cluster? Maybe I'm missing some config to get ceph device ls working with Rook?

I assume you are using the minikube deployment on your own laptop(test vm) so there is no real OSD devices attached. Since the OSDs are backed by virtual devices/files(HostPath) instead of physical disks, they don't expose the hardware metrics (like SMART data) that ceph device ls looks for.

@travisn

travisn commented Jan 9, 2026

Copy link
Copy Markdown
Member

Ok makes sense that it requires the SMART devices, not just virtual devices. The changes LGTM then.

@rzarzynski

Copy link
Copy Markdown
Contributor

Thank you, @travisn! Would you mind to approve?

@adk3798: any objection to move forward?

@senolcolak
senolcolak force-pushed the wip-v2-mgr-inventory-crush-host branch from 644dd80 to 0d96230 Compare March 31, 2026 21:23
@rzarzynski

Copy link
Copy Markdown
Contributor

jenkins test make check arm64

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

@senolcolak -If this PR requires re-testing, please add the needs-qa label accordingly.

@senolcolak

Copy link
Copy Markdown
Contributor Author

Hi @rzarzynski
all checks are green now. Is this ready to merge, or is anything else needed from my side?

…aths

In containerized deployments (e.g. Rook), OSD daemons report the
pod/container hostname. The CRUSH map records the physical host.
This mismatch causes 'ceph device ls' to show pod names instead of
physical hosts, breaking host-based device correlation.

Fix by deriving the CRUSH host bucket name for each OSD and substituting
it as the canonical hostname in all three metadata paths:
- MetadataUpdate::finish (async mon metadata fetch, primary path)
- Mgr::load_all_metadata OSD bulk-load (startup/failover)
- DaemonServer::fetch_missing_metadata (via MetadataUpdate)

The override is a no-op when the OSD is absent from CRUSH or when the
OSD map is not yet available.

Fixes: https://tracker.ceph.com/issues/73080
Signed-off-by: senol.colak <[email protected]>
@senolcolak
senolcolak marked this pull request as draft May 27, 2026 20:57
@senolcolak
senolcolak force-pushed the wip-v2-mgr-inventory-crush-host branch from 0d96230 to dcd9c5b Compare May 27, 2026 22:19
@senolcolak senolcolak changed the title mgr/DaemonServer: prefer CRUSH hostname for OSD inventory mgr: override OSD hostname with CRUSH physical host in all metadata paths May 27, 2026
@senolcolak

Copy link
Copy Markdown
Contributor Author

this patch needs to run tests against gardener shoots.

@senolcolak
senolcolak marked this pull request as ready for review May 28, 2026 14:56

@zoorpha zoorpha left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overall: LGTM — the v2 rework is a significant improvement over v1. The dead-code issue is fixed, lock ordering is preserved, and the by_server index consistency concern from the previous iteration is properly addressed. The approach is sound and the comments explaining the locking rationale are excellent.

I have a few minor suggestions below. Nothing blocking, but worth addressing before merge.


1. Redundant state->hostname assignment in the new-daemon path

In MetadataUpdate::finish(), the !daemon_state.exists(key) branch sets state->hostname three times:

state->hostname = daemon_meta.at("hostname").get_str();  // reported hostname
// ...
state->hostname = crush_host;                            // CRUSH override
// ...
state->set_metadata(m);                                  // sets it again from m

Because DaemonState::set_metadata() updates hostname from the map when "hostname" is present, the middle assignment is redundant in the OSD-with-CRUSH-host case. Consider simplifying to:

// For non-OSDs or OSDs without a CRUSH host, preserve the reported hostname
if (key.type != "osd" || crush_host.empty()) {
    m["hostname"] = daemon_meta.at("hostname").get_str();
} else {
    m["hostname"] = crush_host;
}
state->set_metadata(m);

This removes the direct state->hostname assignments entirely and lets set_metadata own the field.


2. Add automated test coverage

The PR description lists manual Rook verification steps, which is great for the final check, but core mgr metadata indexing changes should have some automated coverage. Two suggestions:

A. Unit test for crush_hostname_for_osd and by_server consistency

The crush_hostname_for_osd helper is currently static in Mgr.cc, so it's invisible to src/test/mgr/. Could you either:

  • Move it to ClusterState as a public method (e.g., ClusterState::get_crush_hostname_for_osd(int)), or
  • Declare it in Mgr.h and make it non-static?

Then we can add a unittest_mgr_clusterstate test that builds a CrushWrapper, injects it into an OSDMap, and asserts the helper returns the correct "host" bucket. We should also test that DaemonStateIndex::update_metadata correctly migrates the by_server index when the hostname changes.

B. Integration test without containers

You don't need a real Rook cluster to verify this. A simple vstart or teuthology test can manufacture the mismatch by moving an OSD to a synthetic CRUSH host:

ceph osd crush move osd.0 host=fake-container-name
# ... verify ceph osd metadata 0 shows hostname=fake-container-name

This exercises the exact code path (CRUSH host ≠ reported hostname) without any container infrastructure. I'd suggest adding either:

  • A shell workunit under qa/workunits/mgr/, or
  • A Python teuthology task under qa/tasks/mgr/ that performs the CRUSH move, fails the mgr, and asserts ceph osd metadata 0 | jq -r '.hostname'.

3. Nit: load_all_metadata dout(4) behavior change

Not a bug, just an FYI: in load_all_metadata, the log line now prints the post-override hostname rather than the raw reported hostname. This is the correct behavior, but if anyone is debugging metadata issues they may notice the difference after this patch.


Thanks for the careful rework — the locking comments in MetadataUpdate::finish are particularly good and will save future maintainers a lot of head-scratching.

The previous patch only injected hostname into the metadata map for OSDs
that were placed under a CRUSH host bucket. For mds/mgr/mon daemons and
for OSDs absent from CRUSH, the original 'state->hostname = ...' line
was removed without a replacement, so update_metadata received a map
with no 'hostname' key. DaemonState::set_metadata only updates
state->hostname when the map carries it, so a daemon restarting on a
different host would be re-inserted in by_server under its stale
hostname.

Always seed m["hostname"] from the metadata-reported hostname, then
prefer the CRUSH host when available. Apply the same shape to the
new-daemon branch so set_metadata uniformly drives state->hostname,
removing the redundant direct assignment.

Reported-by: code review on PR ceph#66757
Signed-off-by: senol.colak <[email protected]>
@senolcolak

Copy link
Copy Markdown
Contributor Author

Hi @rzarzynski, @adk3798, @SrinivasaBharath — small follow-up commit on top of the previously approved dcd9c5b:

  • ec59888 — src/mgr/Mgr.cc only, +11/-10

It closes a by_server index gap in the v2 patch: daemon_meta.erase("hostname") was unconditional, but the re-insertion only happened when a CRUSH host bucket was found. For mds/mgr/mon daemons and for OSDs not placed under a host bucket, m ended up without a hostname key, so DaemonState::set_metadata() left state->hostname untouched and _insert re-keyed by_server under a stale value. Fix: m["hostname"] = !crush_host.empty() ? crush_host : reported_hostname. Lock ordering and OSD-with-CRUSH-host behavior are unchanged.

Since QA last ran against dcd9c5b, could a maintainer add the needs-qa label so the metadata path gets re-validated against ec59888?

Thanks for the patience on this one.

@rzarzynski rzarzynski added needs-qa and removed TESTED labels Jun 1, 2026
@rzarzynski

Copy link
Copy Markdown
Contributor

Let's retest it!

@shraddhaag

Copy link
Copy Markdown
Contributor

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

jenkins test make check arm64

@SrinivasaBharath
SrinivasaBharath merged commit bfebe2e into ceph:main Jul 29, 2026
4 checks passed
@github-actions

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I have resolved the following tracker ticket due to the merge of this PR:

No backports are pending for the ticket. If this is incorrect, please update the tracker
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/30419662832

@senolcolak
senolcolak deleted the wip-v2-mgr-inventory-crush-host branch July 29, 2026 09:56
guits pushed a commit to guits/ceph that referenced this pull request Jul 29, 2026
The previous patch only injected hostname into the metadata map for OSDs
that were placed under a CRUSH host bucket. For mds/mgr/mon daemons and
for OSDs absent from CRUSH, the original 'state->hostname = ...' line
was removed without a replacement, so update_metadata received a map
with no 'hostname' key. DaemonState::set_metadata only updates
state->hostname when the map carries it, so a daemon restarting on a
different host would be re-inserted in by_server under its stale
hostname.

Always seed m["hostname"] from the metadata-reported hostname, then
prefer the CRUSH host when available. Apply the same shape to the
new-daemon branch so set_metadata uniformly drives state->hostname,
removing the redundant direct assignment.

Reported-by: code review on PR ceph#66757
Signed-off-by: senol.colak <[email protected]>
AnuragRaut08 pushed a commit to AnuragRaut08/ceph that referenced this pull request Sep 30, 2026
The previous patch only injected hostname into the metadata map for OSDs
that were placed under a CRUSH host bucket. For mds/mgr/mon daemons and
for OSDs absent from CRUSH, the original 'state->hostname = ...' line
was removed without a replacement, so update_metadata received a map
with no 'hostname' key. DaemonState::set_metadata only updates
state->hostname when the map carries it, so a daemon restarting on a
different host would be re-inserted in by_server under its stale
hostname.

Always seed m["hostname"] from the metadata-reported hostname, then
prefer the CRUSH host when available. Apply the same shape to the
new-daemon branch so set_metadata uniformly drives state->hostname,
removing the redundant direct assignment.

Reported-by: code review on PR ceph#66757
Signed-off-by: senol.colak <[email protected]>
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.

9 participants