From: Kefu Chai Date: Fri, 21 Dec 2018 10:30:37 +0000 (+0800) Subject: crimson/monc: add start() method X-Git-Tag: v14.1.0~356^2~16 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=90361af7e3daebd04fbff079dcf85f7342136827;p=ceph-ci.git crimson/monc: add start() method 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 --- diff --git a/src/crimson/mon/MonClient.cc b/src/crimson/mon/MonClient.cc index e4bd8706505..2d1dde9768f 100644 --- a/src/crimson/mon/MonClient.cc +++ b/src/crimson/mon/MonClient.cc @@ -7,6 +7,7 @@ #include #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("auth_client_required"); } - return AuthMethodList(nullptr, method); + return std::make_unique(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 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); }); diff --git a/src/crimson/mon/MonClient.h b/src/crimson/mon/MonClient.h index 49fa9201bdf..c47f9e4ded9 100644 --- a/src/crimson/mon/MonClient.h +++ b/src/crimson/mon/MonClient.h @@ -9,7 +9,6 @@ #include #include -#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 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& cmd, const bufferlist& bl); @@ -96,6 +93,9 @@ private: seastar::future<> handle_config(Ref m); private: + seastar::future<> load_keyring(); + seastar::future<> authenticate(); + bool is_hunting() const; seastar::future<> reopen_session(int rank); std::vector get_random_mons(unsigned n) const; diff --git a/src/test/crimson/test_monc.cc b/src/test/crimson/test_monc.cc index 78f71e43a67..c6c5f548a02 100644 --- a/src/test/crimson/test_monc.cc +++ b/src/test/crimson/test_monc.cc @@ -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] {