@@ -504,6 +504,8 @@ seastar::future<> OSD::start()
504504 }).then_unpack ([this ] {
505505 return _add_me_to_crush ();
506506 }).then ([this ] {
507+ return _add_device_class ();
508+ }).then ([this ] {
507509 monc->sub_want (" osd_pg_creates" , last_pg_create_epoch, 0 );
508510 monc->sub_want (" mgrmap" , 0 , 0 );
509511 monc->sub_want (" osdmap" , 0 , 0 );
@@ -608,6 +610,38 @@ seastar::future<> OSD::_send_boot()
608610 return monc->send_message (std::move (m));
609611}
610612
613+ seastar::future<> OSD::_add_device_class ()
614+ {
615+ LOG_PREFIX (OSD::_add_device_class);
616+ if (!local_conf ().get_val <bool >(" osd_class_update_on_start" )) {
617+ co_return ;
618+ }
619+
620+ std::string device_class = co_await store.get_default_device_class ();
621+ if (device_class.empty ()) {
622+ WARN (" Device class is empty; skipping crush update." );
623+ co_return ;
624+ }
625+
626+ INFO (" device_class is {} " , device_class);
627+
628+ std::string cmd = fmt::format (
629+ R"( {{"prefix": "osd crush set-device-class", "class": "{}", "ids": ["{}"]}})" ,
630+ device_class, stringify (whoami)
631+ );
632+
633+ auto [code, message, out] = co_await monc->run_command (std::move (cmd), {});
634+ if (code) {
635+ // to be caught by crimson/osd/main.cc
636+ WARN (" fail to set device_class : {} ({})" , message, code);
637+ throw std::runtime_error (" fail to set device_class" );
638+ } else {
639+ INFO (" device_class was set: {}" , message);
640+ }
641+
642+ co_return ;
643+ }
644+
611645seastar::future<> OSD::_add_me_to_crush ()
612646{
613647 LOG_PREFIX (OSD::_add_me_to_crush);
0 commit comments