From 3eb55b9706c5d4eb8c771205849e05a11ba34528 Mon Sep 17 00:00:00 2001 From: Dan van der Ster Date: Thu, 19 Jun 2025 16:56:33 -0700 Subject: [PATCH] OSD: check crush weight at startup Signed-off-by: Dan van der Ster --- src/osd/OSD.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ src/osd/OSD.h | 1 + 2 files changed, 43 insertions(+) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 9f2b59744a758..11885d20beab3 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -4151,6 +4151,8 @@ int OSD::init() maybe_override_options_for_qos(); maybe_override_max_osd_capacity_for_qos(); + check_crush_weight(); + return 0; out: @@ -4942,6 +4944,46 @@ int OSD::mon_cmd_maybe_osd_create(string &cmd) return 0; } +int OSD::check_crush_weight() +{ + OSDMapRef osdmap = get_osdmap(); + + if (!osdmap->crush->item_exists(whoami)) { + dout(1) << "osd." << whoami << " is not in CRUSH map" << dendl; + return 0; + } + + // 1. Current weight from the CRUSH map + double crush_weight = osdmap->crush->get_item_weightf(whoami); + + // 2. Correct weight based on total size (TiB) and scaling factor + struct store_statfs_t st; + osd_alert_list_t alerts; + int r = store->statfs(&st, &alerts); + if (r < 0) { + derr << "statfs: " << cpp_strerror(r) << dendl; + return r; + } + + double expected_weight = std::max(.00001, + g_conf().get_val("osd_crush_scaling_factor") * + double(st.total) / + double(1ull << 40 /* TiB */)); + + // 3. Compare with limited precision (to avoid float noise) + if (std::abs(crush_weight - expected_weight) > 0.0001) { + dout(1) << "osd." << whoami << " CRUSH weight mismatch: " + << "CRUSH = " << crush_weight + << ", expected = " << expected_weight << dendl; + } else { + dout(2) << "osd." << whoami << " CRUSH weight matches: " + << "CRUSH = " << crush_weight + << ", expected = " << expected_weight << dendl; + } + + return 0; +} + int OSD::update_crush_location() { if (!cct->_conf->osd_crush_update_on_start) { diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 84f70c86a405d..056deba9f1acf 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -2025,6 +2025,7 @@ private: int mon_cmd_maybe_osd_create(std::string &cmd); int update_crush_device_class(); int update_crush_location(); + int check_crush_weight(); static int write_meta(CephContext *cct, ObjectStore *store, -- 2.39.5