From a37d19dc9b06d9bc7a8f6443fe99c9bb3631b23b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 28 Nov 2018 21:00:33 +0800 Subject: [PATCH] crimson/monc: set name using a setter * set entity_name using a setter not pass it to constructor, because the entity_name is retrieved in seastar's app.run() by ConfigProxy, while it'd be simpler if we can instantiate mon::Client in main() as a local variable, instead of managing it on heap using a smart pointer. so we cannot pass the entity_name as a parameter of ctor. * also cleanup the #include's, as they are included already in the header. Signed-off-by: Kefu Chai --- src/crimson/mon/MonClient.cc | 16 ++++++++++------ src/crimson/mon/MonClient.h | 7 ++++--- src/test/crimson/test_monc.cc | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/crimson/mon/MonClient.cc b/src/crimson/mon/MonClient.cc index b56b07a0cd1..e4bd8706505 100644 --- a/src/crimson/mon/MonClient.cc +++ b/src/crimson/mon/MonClient.cc @@ -7,8 +7,6 @@ #include #include "auth/AuthClientHandler.h" -#include "auth/AuthMethodList.h" -#include "auth/KeyRing.h" #include "auth/RotatingKeyRing.h" #include "crimson/auth/KeyRing.h" @@ -248,10 +246,9 @@ AuthMethodList create_auth_methods(uint32_t entity_type) } } -Client::Client(const EntityName& name, - ceph::net::Messenger& messenger) - : entity_name{name}, - auth_methods{create_auth_methods(entity_name.get_type())}, +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 | CEPH_ENTITY_TYPE_OSD | CEPH_ENTITY_TYPE_MGR}, @@ -262,6 +259,13 @@ Client::Client(const EntityName& name, Client::Client(Client&&) = default; Client::~Client() = default; +void Client::set_name(const EntityName& name) +{ + entity_name = name; + // should always be OSD, though + auth_methods = create_auth_methods(name.get_type()); +} + seastar::future<> Client::load_keyring() { if (!auth_methods.is_supported_auth(CEPH_AUTH_CEPHX)) { diff --git a/src/crimson/mon/MonClient.h b/src/crimson/mon/MonClient.h index cc291f7510a..49fa9201bdf 100644 --- a/src/crimson/mon/MonClient.h +++ b/src/crimson/mon/MonClient.h @@ -37,7 +37,7 @@ namespace ceph::mon { class Connection; class Client : public ceph::net::Dispatcher { - const EntityName entity_name; + EntityName entity_name; KeyRing keyring; AuthMethodList auth_methods; const uint32_t want_keys; @@ -65,10 +65,11 @@ class Client : public ceph::net::Dispatcher { MonSub sub; public: - Client(const EntityName& name, - ceph::net::Messenger& messenger); + 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(); diff --git a/src/test/crimson/test_monc.cc b/src/test/crimson/test_monc.cc index de6c4681869..9fe541b42e3 100644 --- a/src/test/crimson/test_monc.cc +++ b/src/test/crimson/test_monc.cc @@ -32,8 +32,9 @@ static seastar::future<> test_monc() if (conf->ms_crc_header) { msgr.set_crc_header(); } - return seastar::do_with(MonClient{conf->name, msgr}, + 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] { -- 2.39.5