]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/monc: add start() method
authorKefu Chai <kchai@redhat.com>
Fri, 21 Dec 2018 10:30:37 +0000 (18:30 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 18 Jan 2019 04:30:15 +0000 (12:30 +0800)
to boot strap mon::Client once seastar and msgr is ready. this allows us
to allocate mon::Client on stack.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/mon/MonClient.cc
src/crimson/mon/MonClient.h
src/test/crimson/test_monc.cc

index e4bd870650561b057cfdeab478583dabae3db0ab..2d1dde9768fe4c9c58e909afcce313f1b5658259 100644 (file)
@@ -7,6 +7,7 @@
 #include <seastar/util/log.hh>
 
 #include "auth/AuthClientHandler.h"
+#include "auth/AuthMethodList.h"
 #include "auth/RotatingKeyRing.h"
 
 #include "crimson/auth/KeyRing.h"
@@ -226,8 +227,9 @@ bool Connection::is_my_peer(const entity_addr_t& addr) const
 ceph::net::ConnectionRef Connection::get_conn() {
   return conn;
 }
+
 namespace {
-AuthMethodList create_auth_methods(uint32_t entity_type)
+auto create_auth_methods(uint32_t entity_type)
 {
   auto& conf = ceph::common::local_conf();
   std::string method;
@@ -242,14 +244,13 @@ AuthMethodList create_auth_methods(uint32_t entity_type)
   } else {
     method = conf.get_val<std::string>("auth_client_required");
   }
-  return AuthMethodList(nullptr, method);
+  return std::make_unique<AuthMethodList>(nullptr, method);
 }
 }
 
 Client::Client(ceph::net::Messenger& messenger)
   // currently, crimson is OSD-only
-  : auth_methods{create_auth_methods(CEPH_ENTITY_TYPE_OSD)},
-    want_keys{CEPH_ENTITY_TYPE_MON |
+  : want_keys{CEPH_ENTITY_TYPE_MON |
               CEPH_ENTITY_TYPE_OSD |
               CEPH_ENTITY_TYPE_MGR},
     timer{[this] { tick(); }},
@@ -259,16 +260,20 @@ Client::Client(ceph::net::Messenger& messenger)
 Client::Client(Client&&) = default;
 Client::~Client() = default;
 
-void Client::set_name(const EntityName& name)
-{
-  entity_name = name;
+seastar::future<> Client::start() {
+  entity_name = ceph::common::local_conf()->name;
   // should always be OSD, though
-  auth_methods = create_auth_methods(name.get_type());
+  auth_methods = create_auth_methods(entity_name.get_type());
+  return load_keyring().then([this] {
+    return monmap.build_initial(ceph::common::local_conf(), false);
+  }).then([this] {
+    return authenticate();
+  });
 }
 
 seastar::future<> Client::load_keyring()
 {
-  if (!auth_methods.is_supported_auth(CEPH_AUTH_CEPHX)) {
+  if (!auth_methods->is_supported_auth(CEPH_AUTH_CEPHX)) {
     return seastar::now();
   } else {
     return ceph::auth::load_from_keyring(&keyring).then([](KeyRing* keyring) {
@@ -465,11 +470,6 @@ std::vector<unsigned> Client::get_random_mons(unsigned n) const
   }
 }
 
-seastar::future<> Client::build_initial_map()
-{
-  return monmap.build_initial(ceph::common::local_conf(), false);
-}
-
 seastar::future<> Client::authenticate()
 {
   return reopen_session(-1);
@@ -477,9 +477,7 @@ seastar::future<> Client::authenticate()
 
 seastar::future<> Client::stop()
 {
-  return tick_gate.close().finally([this] {
-    return timer.cancel();
-  }).then([this] {
+  return tick_gate.close().then([this] {
     if (active_con) {
       return active_con->close();
     } else {
@@ -507,7 +505,7 @@ seastar::future<> Client::reopen_session(int rank)
     auto& mc = pending_conns.emplace_back(conn, &keyring);
     return mc.authenticate(
       monmap.get_epoch(), entity_name,
-      auth_methods, want_keys).handle_exception([conn](auto ep) {
+      *auth_methods, want_keys).handle_exception([conn](auto ep) {
       return conn->close().then([ep = std::move(ep)] {
         std::rethrow_exception(ep);
       });
index 49fa9201bdf739b9d94de4fe57de3bc6fddbb90a..c47f9e4ded99a95496d29be9cc5f9bee17a868d9 100644 (file)
@@ -9,7 +9,6 @@
 #include <seastar/core/lowres_clock.hh>
 #include <seastar/core/timer.hh>
 
-#include "auth/AuthMethodList.h"
 #include "auth/KeyRing.h"
 
 #include "crimson/net/Dispatcher.h"
@@ -24,6 +23,7 @@ namespace ceph::net {
   class Messenger;
 }
 
+class AuthMethodList;
 class MAuthReply;
 struct MMonMap;
 struct MMonSubscribeAck;
@@ -39,7 +39,7 @@ class Connection;
 class Client : public ceph::net::Dispatcher {
   EntityName entity_name;
   KeyRing keyring;
-  AuthMethodList auth_methods;
+  std::unique_ptr<AuthMethodList> auth_methods;
   const uint32_t want_keys;
 
   MonMap monmap;
@@ -68,12 +68,9 @@ public:
   Client(ceph::net::Messenger& messenger);
   Client(Client&&);
   ~Client();
-  void set_name(const EntityName& name);
-
-  seastar::future<> load_keyring();
-  seastar::future<> build_initial_map();
-  seastar::future<> authenticate();
+  seastar::future<> start();
   seastar::future<> stop();
+
   get_version_t get_version(const std::string& map);
   command_result_t run_command(const std::vector<std::string>& cmd,
                               const bufferlist& bl);
@@ -96,6 +93,9 @@ private:
   seastar::future<> handle_config(Ref<MConfig> m);
 
 private:
+  seastar::future<> load_keyring();
+  seastar::future<> authenticate();
+
   bool is_hunting() const;
   seastar::future<> reopen_session(int rank);
   std::vector<unsigned> get_random_mons(unsigned n) const;
index 78f71e43a675a0ac9be1040278fb4819df670dac..c6c5f548a02220065e6783e72dd7b3fde86bd4b2 100644 (file)
@@ -36,16 +36,11 @@ static seastar::future<> test_monc()
       }
       return seastar::do_with(MonClient{msgr},
                               [&msgr](auto& monc) {
-        monc.set_name(ceph::common::local_conf()->name);
-        return monc.build_initial_map().then([&monc] {
-          return monc.load_keyring();
-        }).then([&msgr, &monc] {
-          return msgr.start(&monc);
-        }).then([&monc] {
+        return msgr.start(&monc).then([&monc] {
           return seastar::with_timeout(
             seastar::lowres_clock::now() + std::chrono::seconds{10},
-            monc.authenticate());
-        }).finally([&monc] {
+            monc.start());
+        }).then([&monc] {
           return monc.stop();
         });
       }).finally([&msgr] {