From d2ee4c1bba8928940e1db7d36e2a5dceb6427074 Mon Sep 17 00:00:00 2001 From: Mohit Agrawal Date: Fri, 15 Nov 2024 10:40:09 +0530 Subject: [PATCH] crimson: Set device class during spawn of a crimson osd 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 --- src/crimson/os/alienstore/alien_store.cc | 13 +++++++++ src/crimson/os/alienstore/alien_store.h | 1 + src/crimson/os/cyanstore/cyan_store.cc | 6 +++++ src/crimson/os/cyanstore/cyan_store.h | 2 ++ src/crimson/os/futurized_store.h | 1 + src/crimson/os/seastore/seastore.cc | 7 +++++ src/crimson/os/seastore/seastore.h | 4 +++ src/crimson/osd/osd.cc | 34 ++++++++++++++++++++++++ src/crimson/osd/osd.h | 1 + 9 files changed, 69 insertions(+) diff --git a/src/crimson/os/alienstore/alien_store.cc b/src/crimson/os/alienstore/alien_store.cc index 3fd2bb1fd157..f390823a8a09 100644 --- a/src/crimson/os/alienstore/alien_store.cc +++ b/src/crimson/os/alienstore/alien_store.cc @@ -590,6 +590,19 @@ seastar::future AlienStore::stat( }); } +seastar::future 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(device_class); + }); + }); +} + auto AlienStore::omap_get_header(CollectionRef ch, const ghobject_t& oid) -> get_attr_errorator::future diff --git a/src/crimson/os/alienstore/alien_store.h b/src/crimson/os/alienstore/alien_store.h index d36f449afd81..853585dac9cf 100644 --- a/src/crimson/os/alienstore/alien_store.h +++ b/src/crimson/os/alienstore/alien_store.h @@ -98,6 +98,7 @@ public: seastar::future stat( CollectionRef, const ghobject_t&) final; + seastar::future get_default_device_class() final; get_attr_errorator::future omap_get_header( CollectionRef, const ghobject_t&) final; diff --git a/src/crimson/os/cyanstore/cyan_store.cc b/src/crimson/os/cyanstore/cyan_store.cc index 7b945e5aa150..3f861a9271f8 100644 --- a/src/crimson/os/cyanstore/cyan_store.cc +++ b/src/crimson/os/cyanstore/cyan_store.cc @@ -143,6 +143,12 @@ CyanStore::list_collections() }); } +seastar::future +CyanStore::get_default_device_class() +{ + return seastar::make_ready_future(""); +} + CyanStore::mount_ertr::future<> CyanStore::Shard::mount() { static const char read_file_errmsg[]{"read_file"}; diff --git a/src/crimson/os/cyanstore/cyan_store.h b/src/crimson/os/cyanstore/cyan_store.h index 99583d07d36a..e9394991bc2c 100644 --- a/src/crimson/os/cyanstore/cyan_store.h +++ b/src/crimson/os/cyanstore/cyan_store.h @@ -221,6 +221,8 @@ public: seastar::future> list_collections() final; + seastar::future get_default_device_class() final; + private: seastar::sharded shard_stores; const std::string path; diff --git a/src/crimson/os/futurized_store.h b/src/crimson/os/futurized_store.h index 0dca695ba3a1..51ef2331014d 100644 --- a/src/crimson/os/futurized_store.h +++ b/src/crimson/os/futurized_store.h @@ -203,6 +203,7 @@ public: using coll_core_t = std::pair; virtual seastar::future> list_collections() = 0; + virtual seastar::future get_default_device_class() = 0; protected: const core_id_t primary_core; }; diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index d90edbb20dbe..2bf55d5cde76 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -2721,6 +2721,13 @@ SeaStore::read_meta(const std::string& key) ); } +seastar::future SeaStore::get_default_device_class() +{ + using crimson::common::get_conf; + std::string type = get_conf("seastore_main_device_type"); + return seastar::make_ready_future(type); +} + uuid_d SeaStore::Shard::get_fsid() const { return device->get_meta().seastore_id; diff --git a/src/crimson/os/seastore/seastore.h b/src/crimson/os/seastore/seastore.h index 185072744f2d..fd7e177da63b 100644 --- a/src/crimson/os/seastore/seastore.h +++ b/src/crimson/os/seastore/seastore.h @@ -191,6 +191,8 @@ public: seastar::future<> write_meta(const std::string& key, const std::string& value); + seastar::future get_default_device_class(); + store_statfs_t stat() const; uuid_d get_fsid() const; @@ -567,6 +569,8 @@ public: seastar::future> list_collections() final; + seastar::future get_default_device_class() final; + FuturizedStore::Shard& get_sharded_store() final { return shard_stores.local(); } diff --git a/src/crimson/osd/osd.cc b/src/crimson/osd/osd.cc index 34ad97ceb068..0f19bfd7145f 100644 --- a/src/crimson/osd/osd.cc +++ b/src/crimson/osd/osd.cc @@ -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("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); diff --git a/src/crimson/osd/osd.h b/src/crimson/osd/osd.h index d7d54d5d2c3c..1a84ccd6a3f1 100644 --- a/src/crimson/osd/osd.h +++ b/src/crimson/osd/osd.h @@ -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); -- 2.47.3