]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: Set device class during spawn of a crimson osd 60747/head
authorMohit Agrawal <moagrawa@redhat.com>
Fri, 15 Nov 2024 05:10:09 +0000 (10:40 +0530)
committerMohit Agrawal <moagrawa@redhat.com>
Tue, 19 Nov 2024 09:32:28 +0000 (15:02 +0530)
Implement a wrapper for different backend storage to
set device_class during spawn of a process.

Fixes: https://tracker.ceph.com/issues/66627
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
src/crimson/os/alienstore/alien_store.cc
src/crimson/os/alienstore/alien_store.h
src/crimson/os/cyanstore/cyan_store.cc
src/crimson/os/cyanstore/cyan_store.h
src/crimson/os/futurized_store.h
src/crimson/os/seastore/seastore.cc
src/crimson/os/seastore/seastore.h
src/crimson/osd/osd.cc
src/crimson/osd/osd.h

index 3fd2bb1fd1572675d0609eeb273f22f0e99e3e51..f390823a8a09e76d280f74bbd67f6c61fc61ad1f 100644 (file)
@@ -590,6 +590,19 @@ seastar::future<struct stat> AlienStore::stat(
   });
 }
 
+seastar::future<std::string> AlienStore::get_default_device_class()
+{
+  logger().debug("{}", __func__);
+  assert(tp);
+  return op_gates.simple_dispatch("get_default_device_class", [=, this] {
+    return tp->submit([=, this] {
+      return store->get_default_device_class();
+    }).then([] (std::string device_class) {
+      return seastar::make_ready_future<std::string>(device_class);
+    });
+  });
+}
+
 auto AlienStore::omap_get_header(CollectionRef ch,
                                  const ghobject_t& oid)
   -> get_attr_errorator::future<ceph::bufferlist>
index d36f449afd81ef88ecebfd493c798fd583c2e8fc..853585dac9cf214ff32ea28b9d70f4ab423ed874 100644 (file)
@@ -98,6 +98,7 @@ public:
   seastar::future<struct stat> stat(
     CollectionRef,
     const ghobject_t&) final;
+  seastar::future<std::string> get_default_device_class() final;
   get_attr_errorator::future<ceph::bufferlist> omap_get_header(
     CollectionRef,
     const ghobject_t&) final;
index 7b945e5aa150290e9e5b64c78ab065dbfbc30bca..3f861a9271f8341c4189ed172b8ec945c39548f5 100644 (file)
@@ -143,6 +143,12 @@ CyanStore::list_collections()
   });
 }
 
+seastar::future<std::string>
+CyanStore::get_default_device_class()
+{
+  return seastar::make_ready_future<std::string>("");
+}
+
 CyanStore::mount_ertr::future<> CyanStore::Shard::mount()
 {
   static const char read_file_errmsg[]{"read_file"};
index 99583d07d36a78bb17f828693dddf4b3e6253404..e9394991bc2c23d03ba264dc0e33c232dba8481e 100644 (file)
@@ -221,6 +221,8 @@ public:
 
   seastar::future<std::vector<coll_core_t>> list_collections() final;
 
+  seastar::future<std::string> get_default_device_class() final;
+
 private:
   seastar::sharded<CyanStore::Shard> shard_stores;
   const std::string path;
index 0dca695ba3a1edd56f1571149eb11a0ce65edb8c..51ef2331014ddf3e296bf3543eb577287a2d54bb 100644 (file)
@@ -203,6 +203,7 @@ public:
   using coll_core_t = std::pair<coll_t, core_id_t>;
   virtual seastar::future<std::vector<coll_core_t>> list_collections() = 0;
 
+  virtual seastar::future<std::string> get_default_device_class() = 0;
 protected:
   const core_id_t primary_core;
 };
index d90edbb20dbe26de7eed8becc99f7fede54bc86a..2bf55d5cde7699b276eb1dd4bbd7c39b318b4ca5 100644 (file)
@@ -2721,6 +2721,13 @@ SeaStore::read_meta(const std::string& key)
   );
 }
 
+seastar::future<std::string> SeaStore::get_default_device_class()
+{
+  using crimson::common::get_conf;
+  std::string type = get_conf<std::string>("seastore_main_device_type");
+  return seastar::make_ready_future<std::string>(type);
+}
+
 uuid_d SeaStore::Shard::get_fsid() const
 {
   return device->get_meta().seastore_id;
index 185072744f2d86703a169ea51343c8e3d7b50ea4..fd7e177da63bcb1337450100f2bd63e886213517 100644 (file)
@@ -191,6 +191,8 @@ public:
     seastar::future<> write_meta(const std::string& key,
                                  const std::string& value);
 
+    seastar::future<std::string> get_default_device_class();
+
     store_statfs_t stat() const;
 
     uuid_d get_fsid() const;
@@ -567,6 +569,8 @@ public:
 
   seastar::future<std::vector<coll_core_t>> list_collections() final;
 
+  seastar::future<std::string> get_default_device_class() final;
+
   FuturizedStore::Shard& get_sharded_store() final {
     return shard_stores.local();
   }
index 34ad97ceb068a7d61c6411914b46b4422ba258f3..0f19bfd7145f601241380e25158f58950eaf8f04 100644 (file)
@@ -504,6 +504,8 @@ seastar::future<> OSD::start()
   }).then_unpack([this] {
     return _add_me_to_crush();
   }).then([this] {
+    return _add_device_class();
+   }).then([this] {
     monc->sub_want("osd_pg_creates", last_pg_create_epoch, 0);
     monc->sub_want("mgrmap", 0, 0);
     monc->sub_want("osdmap", 0, 0);
@@ -608,6 +610,38 @@ seastar::future<> OSD::_send_boot()
   return monc->send_message(std::move(m));
 }
 
+seastar::future<> OSD::_add_device_class()
+{
+  LOG_PREFIX(OSD::_add_device_class);
+  if (!local_conf().get_val<bool>("osd_class_update_on_start")) {
+    co_return;
+  }
+
+  std::string device_class = co_await store.get_default_device_class();
+  if (device_class.empty()) {
+    WARN("Device class is empty; skipping crush update.");
+    co_return;
+  }
+
+  INFO("device_class is {} ", device_class);
+
+  std::string cmd = fmt::format(
+    R"({{"prefix": "osd crush set-device-class", "class": "{}", "ids": ["{}"]}})",
+    device_class, stringify(whoami)
+  );
+
+  auto [code, message, out] = co_await monc->run_command(std::move(cmd), {});
+  if (code) {
+    // to be caught by crimson/osd/main.cc
+    WARN("fail to set device_class : {} ({})", message, code);
+    throw std::runtime_error("fail to set device_class");
+  } else {
+    INFO("device_class was set: {}", message);
+  }
+
+  co_return;
+}
+
 seastar::future<> OSD::_add_me_to_crush()
 {
   LOG_PREFIX(OSD::_add_me_to_crush);
index d7d54d5d2c3c365244b13178ab7e3149706966de..1a84ccd6a3f18011b79e114bba02a37ceeea1643 100644 (file)
@@ -188,6 +188,7 @@ private:
   seastar::future<> _preboot(version_t oldest_osdmap, version_t newest_osdmap);
   seastar::future<> _send_boot();
   seastar::future<> _add_me_to_crush();
+  seastar::future<> _add_device_class();
 
   seastar::future<> osdmap_subscribe(version_t epoch, bool force_request);