]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/mgr/client: partial move to coroutines
authorMatan Breizman <mbreizma@redhat.com>
Sun, 2 Mar 2025 10:48:37 +0000 (10:48 +0000)
committerMatan Breizman <mbreizma@redhat.com>
Tue, 4 Mar 2025 13:23:34 +0000 (13:23 +0000)
Avoid moving capturing lambdas to coroutines.
Specifically lambdas which are passed to dispatch_in_background.

See: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rcoro-capture

Signed-off-by: Matan Breizman <mbreizma@redhat.com>
src/crimson/mgr/client.cc

index 9c813767a99751d5b82de29f9e5840e62cd21bbb..6e800cf12cbdb68a35fc4d324986780c10184ced 100644 (file)
@@ -8,6 +8,7 @@
 #include "crimson/common/log.h"
 #include "crimson/net/Connection.h"
 #include "crimson/net/Messenger.h"
+#include "crimson/common/coroutine.h"
 #include "messages/MMgrConfigure.h"
 #include "messages/MMgrMap.h"
 #include "messages/MMgrOpen.h"
@@ -35,7 +36,7 @@ seastar::future<> Client::start()
 {
   LOG_PREFIX(Client::start);
   DEBUGDPP("", *this);
-  return seastar::now();
+  co_return;
 }
 
 seastar::future<> Client::stop()
@@ -43,12 +44,11 @@ seastar::future<> Client::stop()
   LOG_PREFIX(Client::stop);
   DEBUGDPP("", *this);
   report_timer.cancel();
-  auto fut = gates.close_all();
   if (conn) {
     DEBUGDPP("marking down", *this);
     conn->mark_down();
   }
-  return fut;
+  co_await gates.close_all();
 }
 
 std::optional<seastar::future<>>
@@ -124,24 +124,24 @@ seastar::future<> Client::reconnect()
   }
   if (!mgrmap.get_available()) {
     WARNDPP("No active mgr available yet", *this);
-    return seastar::now();
+    co_return;
   }
   auto retry_interval = std::chrono::duration<double>(
     local_conf().get_val<double>("mgr_connect_retry_interval"));
   auto a_while = std::chrono::duration_cast<seastar::steady_clock_type::duration>(
     retry_interval);
   DEBUGDPP("reconnecting in {} seconds", *this, retry_interval);
-  return seastar::sleep(a_while).then([this, FNAME] {
-    auto peer = mgrmap.get_active_addrs().pick_addr(msgr.get_myaddr().get_type());
-    if (peer == entity_addr_t{}) {
-      // crimson msgr only uses the first bound addr
-      ERRORDPP("mgr.{} does not have an addr compatible with me",
-               *this, mgrmap.get_active_name());
-      return;
-    }
-    conn = msgr.connect(peer, CEPH_ENTITY_TYPE_MGR);
-    DEBUGDPP("reconnected successfully", *this);
-  });
+  co_await seastar::sleep(a_while);
+
+  auto peer = mgrmap.get_active_addrs().pick_addr(msgr.get_myaddr().get_type());
+  if (peer == entity_addr_t{}) {
+    // crimson msgr only uses the first bound addr
+    ERRORDPP("mgr.{} does not have an addr compatible with me",
+             *this, mgrmap.get_active_name());
+    co_return;
+  }
+  conn = msgr.connect(peer, CEPH_ENTITY_TYPE_MGR);
+  DEBUGDPP("reconnected successfully", *this);
 }
 
 seastar::future<> Client::handle_mgr_map(crimson::net::ConnectionRef,
@@ -150,13 +150,9 @@ seastar::future<> Client::handle_mgr_map(crimson::net::ConnectionRef,
   LOG_PREFIX(Client::handle_mgr_map);
   DEBUGDPP("", *this);
   mgrmap = m->get_map();
-  if (!conn) {
-    return reconnect();
-  } else if (conn->get_peer_addr() !=
-             mgrmap.get_active_addrs().legacy_addr()) {
-    return reconnect();
-  } else {
-    return seastar::now();
+  if (!conn || conn->get_peer_addr() !=
+               mgrmap.get_active_addrs().legacy_addr()) {
+    co_await reconnect();
   }
 }
 
@@ -178,9 +174,8 @@ seastar::future<> Client::handle_mgr_conf(crimson::net::ConnectionRef,
   }
   if (!m->osd_perf_metric_queries.empty()) {
     ceph_assert(set_perf_queries_cb);
-    return set_perf_queries_cb(m->osd_perf_metric_queries);
+    co_await set_perf_queries_cb(m->osd_perf_metric_queries);
   }
-  return seastar::now();
 }
 
 void Client::report()