]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
OSD: check crush weight at startup
authorDan van der Ster <dan.vanderster@clyso.com>
Thu, 19 Jun 2025 23:56:33 +0000 (16:56 -0700)
committerDan van der Ster <dan.vanderster@clyso.com>
Fri, 20 Jun 2025 20:31:23 +0000 (13:31 -0700)
Signed-off-by: Dan van der Ster <dan.vanderster@clyso.com>
src/osd/OSD.cc
src/osd/OSD.h

index 9f2b59744a7584af05ca3684f0d847a8bf0a3d82..11885d20beab314ea01af79acb03495db5f7e861 100644 (file)
@@ -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<double>("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) {
index 84f70c86a405d0e0802c731d78be427a9dd0c378..056deba9f1acfff0994227c05a126fbf7f9ee95c 100644 (file)
@@ -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,