From: Adam C. Emerson Date: Fri, 29 Mar 2019 00:40:33 +0000 (-0400) Subject: mon: Update MonClient to work without using namespace X-Git-Tag: v15.0.0~19^2~106 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5475f67bf66d1d7faf20b91dd6e629051996a0e9;p=ceph-ci.git mon: Update MonClient to work without using namespace Signed-off-by: Adam C. Emerson --- diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 2c36868c13c..390a9bf4eb0 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -55,6 +55,8 @@ #undef dout_prefix #define dout_prefix *_dout << "monclient" << (_hunting() ? "(hunting)":"") << ": " +using std::string; + MonClient::MonClient(CephContext *cct_) : Dispatcher(cct_), AuthServer(cct_), @@ -80,7 +82,7 @@ MonClient::~MonClient() int MonClient::build_initial_monmap() { ldout(cct, 10) << __func__ << dendl; - int r = monmap.build_initial(cct, false, cerr); + int r = monmap.build_initial(cct, false, std::cerr); ldout(cct,10) << "monmap:\n"; monmap.print(*_dout); *_dout << dendl; @@ -685,7 +687,7 @@ MonConnection& MonClient::_add_conn(unsigned rank, uint64_t global_id) auto peer = monmap.get_addrs(rank); auto conn = messenger->connect_to_mon(peer); MonConnection mc(cct, conn, global_id, &auth_registry); - auto inserted = pending_cons.insert(make_pair(peer, move(mc))); + auto inserted = pending_cons.insert(std::make_pair(peer, std::move(mc))); ldout(cct, 10) << "picked mon." << monmap.get_name(rank) << " con " << conn << " addr " << peer @@ -697,22 +699,25 @@ void MonClient::_add_conns(uint64_t global_id) { // collect the next batch of candidates who are listed right next to the ones // already tried - auto get_next_batch = [this]() -> vector { - multimap ranks_by_priority; - boost::copy(monmap.mon_info | boost::adaptors::filtered([this](auto& info) { - auto rank = monmap.get_rank(info.first); - return tried.count(rank) == 0; - }) | boost::adaptors::transformed([this](auto& info) { - auto rank = monmap.get_rank(info.first); - return make_pair(info.second.priority, rank); - }), std::inserter(ranks_by_priority, end(ranks_by_priority))); + auto get_next_batch = [this]() -> std::vector { + std::multimap ranks_by_priority; + boost::copy( + monmap.mon_info | boost::adaptors::filtered( + [this](auto& info) { + auto rank = monmap.get_rank(info.first); + return tried.count(rank) == 0; + }) | boost::adaptors::transformed( + [this](auto& info) { + auto rank = monmap.get_rank(info.first); + return std::make_pair(info.second.priority, rank); + }), std::inserter(ranks_by_priority, end(ranks_by_priority))); if (ranks_by_priority.empty()) { return {}; } // only choose the monitors with lowest priority auto cands = boost::make_iterator_range( ranks_by_priority.equal_range(ranks_by_priority.begin()->first)); - vector ranks; + std::vector ranks; boost::range::copy(cands | boost::adaptors::map_values, std::back_inserter(ranks)); return ranks; @@ -724,7 +729,7 @@ void MonClient::_add_conns(uint64_t global_id) } ceph_assert(!ranks.empty()); if (ranks.size() > 1) { - vector weights; + std::vector weights; for (auto i : ranks) { auto rank_name = monmap.get_name(i); weights.push_back(monmap.get_weight(rank_name)); @@ -1083,9 +1088,7 @@ void MonClient::_send_command(MonCommand *r) void MonClient::_resend_mon_commands() { // resend any requests - for (map::iterator p = mon_commands.begin(); - p != mon_commands.end(); - ++p) { + for (auto p = mon_commands.begin(); p != mon_commands.end(); ++p) { _send_command(p->second); } } @@ -1099,7 +1102,7 @@ void MonClient::handle_mon_command_ack(MMonCommandAck *ack) r = mon_commands.begin()->second; ldout(cct, 10) << __func__ << " has tid 0, assuming it is " << r->tid << dendl; } else { - map::iterator p = mon_commands.find(tid); + auto p = mon_commands.find(tid); if (p == mon_commands.end()) { ldout(cct, 10) << __func__ << " " << ack->get_tid() << " not found" << dendl; ack->put(); @@ -1119,7 +1122,7 @@ int MonClient::_cancel_mon_command(uint64_t tid) { ceph_assert(monc_lock.is_locked()); - map::iterator it = mon_commands.find(tid); + auto it = mon_commands.find(tid); if (it == mon_commands.end()) { ldout(cct, 10) << __func__ << " tid " << tid << " dne" << dendl; return -ENOENT; @@ -1145,10 +1148,10 @@ void MonClient::_finish_command(MonCommand *r, int ret, string rs) delete r; } -void MonClient::start_mon_command(const vector& cmd, - const bufferlist& inbl, - bufferlist *outbl, string *outs, - Context *onfinish) +void MonClient::start_mon_command(const std::vector& cmd, + const ceph::buffer::list& inbl, + ceph::buffer::list *outbl, string *outs, + Context *onfinish) { std::lock_guard l(monc_lock); if (!initialized || stopping) { @@ -1180,10 +1183,10 @@ void MonClient::start_mon_command(const vector& cmd, } void MonClient::start_mon_command(const string &mon_name, - const vector& cmd, - const bufferlist& inbl, - bufferlist *outbl, string *outs, - Context *onfinish) + const std::vector& cmd, + const ceph::buffer::list& inbl, + ceph::buffer::list *outbl, string *outs, + Context *onfinish) { std::lock_guard l(monc_lock); if (!initialized || stopping) { @@ -1202,10 +1205,10 @@ void MonClient::start_mon_command(const string &mon_name, } void MonClient::start_mon_command(int rank, - const vector& cmd, - const bufferlist& inbl, - bufferlist *outbl, string *outs, - Context *onfinish) + const std::vector& cmd, + const ceph::buffer::list& inbl, + ceph::buffer::list *outbl, string *outs, + Context *onfinish) { std::lock_guard l(monc_lock); if (!initialized || stopping) { @@ -1240,7 +1243,7 @@ void MonClient::get_version(string map, version_t *newest, version_t *oldest, Co void MonClient::handle_get_version_reply(MMonGetVersionReply* m) { ceph_assert(monc_lock.is_locked()); - map::iterator iter = version_requests.find(m->handle); + auto iter = version_requests.find(m->handle); if (iter == version_requests.end()) { ldout(cct, 0) << __func__ << " version request with handle " << m->handle << " not found" << dendl; @@ -1263,7 +1266,7 @@ int MonClient::get_auth_request( AuthConnectionMeta *auth_meta, uint32_t *auth_method, std::vector *preferred_modes, - bufferlist *bl) + ceph::buffer::list *bl) { std::lock_guard l(monc_lock); ldout(cct,10) << __func__ << " con " << con << " auth_method " << *auth_method @@ -1304,8 +1307,8 @@ int MonClient::get_auth_request( int MonClient::handle_auth_reply_more( Connection *con, AuthConnectionMeta *auth_meta, - const bufferlist& bl, - bufferlist *reply) + const ceph::buffer::list& bl, + ceph::buffer::list *reply) { std::lock_guard l(monc_lock); @@ -1333,7 +1336,7 @@ int MonClient::handle_auth_done( AuthConnectionMeta *auth_meta, uint64_t global_id, uint32_t con_mode, - const bufferlist& bl, + const ceph::buffer::list& bl, CryptoKey *session_key, std::string *connection_secret) { @@ -1423,8 +1426,8 @@ int MonClient::handle_auth_request( AuthConnectionMeta *auth_meta, bool more, uint32_t auth_method, - const bufferlist& payload, - bufferlist *reply) + const ceph::buffer::list& payload, + ceph::buffer::list *reply) { auth_meta->auth_mode = payload[0]; if (auth_meta->auth_mode < AUTH_MODE_AUTHORIZER || @@ -1500,6 +1503,7 @@ bool MonConnection::have_session() const void MonConnection::start(epoch_t epoch, const EntityName& entity_name) { + using ceph::encode; auth_start = ceph_clock_now(); if (con->get_peer_addr().is_msgr2()) { @@ -1522,7 +1526,7 @@ void MonConnection::start(epoch_t epoch, m->monmap_epoch = epoch; __u8 struct_v = 1; encode(struct_v, m->auth_payload); - vector auth_supported; + std::vector auth_supported; auth_registry->get_supported_methods(con->get_peer_type(), &auth_supported); encode(auth_supported, m->auth_payload); encode(entity_name, m->auth_payload); @@ -1533,14 +1537,15 @@ void MonConnection::start(epoch_t epoch, int MonConnection::get_auth_request( uint32_t *method, std::vector *preferred_modes, - bufferlist *bl, + ceph::buffer::list *bl, const EntityName& entity_name, uint32_t want_keys, RotatingKeyRing* keyring) { + using ceph::encode; // choose method if (auth_method < 0) { - vector as; + std::vector as; auth_registry->get_supported_methods(con->get_peer_type(), &as); if (as.empty()) { return -EACCES; @@ -1575,8 +1580,8 @@ int MonConnection::get_auth_request( int MonConnection::handle_auth_reply_more( AuthConnectionMeta *auth_meta, - const bufferlist& bl, - bufferlist *reply) + const ceph::buffer::list& bl, + ceph::buffer::list *reply) { ldout(cct, 10) << __func__ << " payload " << bl.length() << dendl; ldout(cct, 30) << __func__ << " got\n"; @@ -1606,7 +1611,7 @@ int MonConnection::handle_auth_reply_more( int MonConnection::handle_auth_done( AuthConnectionMeta *auth_meta, uint64_t new_global_id, - const bufferlist& bl, + const ceph::buffer::list& bl, CryptoKey *session_key, std::string *connection_secret) { @@ -1634,7 +1639,7 @@ int MonConnection::handle_auth_bad_method( ldout(cct,10) << __func__ << " old_auth_method " << old_auth_method << " result " << cpp_strerror(result) << " allowed_methods " << allowed_methods << dendl; - vector auth_supported; + std::vector auth_supported; auth_registry->get_supported_methods(con->get_peer_type(), &auth_supported); auto p = std::find(auth_supported.begin(), auth_supported.end(), old_auth_method); diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index 3e3f2b0214c..cdccf1668bf 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -75,18 +75,18 @@ public: int get_auth_request( uint32_t *method, std::vector *preferred_modes, - bufferlist *out, + ceph::buffer::list *out, const EntityName& entity_name, uint32_t want_keys, RotatingKeyRing* keyring); int handle_auth_reply_more( AuthConnectionMeta *auth_meta, - const bufferlist& bl, - bufferlist *reply); + const ceph::buffer::list& bl, + ceph::buffer::list *reply); int handle_auth_done( AuthConnectionMeta *auth_meta, uint64_t global_id, - const bufferlist& bl, + const ceph::buffer::list& bl, CryptoKey *session_key, std::string *connection_secret); int handle_auth_bad_method( @@ -135,14 +135,14 @@ struct MonClientPinger : public Dispatcher, Mutex lock; Cond ping_recvd_cond; - string *result; + std::string *result; bool done; RotatingKeyRing *keyring; std::unique_ptr mc; MonClientPinger(CephContext *cct_, RotatingKeyRing *keyring, - string *res_) : + std::string *res_) : Dispatcher(cct_), lock("MonClientPinger::lock"), result(res_), @@ -165,11 +165,12 @@ struct MonClientPinger : public Dispatcher, } bool ms_dispatch(Message *m) override { + using ceph::decode; std::lock_guard l(lock); if (m->get_type() != CEPH_MSG_PING) return false; - bufferlist &payload = m->get_payload(); + ceph::buffer::list &payload = m->get_payload(); if (result && payload.length() > 0) { auto p = std::cbegin(payload); decode(*result, p); @@ -196,15 +197,15 @@ struct MonClientPinger : public Dispatcher, AuthConnectionMeta *auth_meta, uint32_t *auth_method, std::vector *preferred_modes, - bufferlist *bl) override { + ceph::buffer::list *bl) override { return mc->get_auth_request(auth_method, preferred_modes, bl, cct->_conf->name, 0, keyring); } int handle_auth_reply_more( Connection *con, AuthConnectionMeta *auth_meta, - const bufferlist& bl, - bufferlist *reply) override { + const ceph::buffer::list& bl, + ceph::buffer::list *reply) override { return mc->handle_auth_reply_more(auth_meta, bl, reply); } int handle_auth_done( @@ -212,7 +213,7 @@ struct MonClientPinger : public Dispatcher, AuthConnectionMeta *auth_meta, uint64_t global_id, uint32_t con_mode, - const bufferlist& bl, + const ceph::buffer::list& bl, CryptoKey *session_key, std::string *connection_secret) override { return mc->handle_auth_done(auth_meta, global_id, bl, @@ -236,7 +237,7 @@ class MonClient : public Dispatcher, public AuthServer /* for mgr, osd, mds */ { public: MonMap monmap; - map config_mgr; + std::map config_mgr; private: Messenger *messenger; @@ -287,7 +288,7 @@ private: int authenticate_err = 0; bool authenticated = false; - list waiting_for_session; + std::list waiting_for_session; utime_t last_rotating_renew_sent; std::unique_ptr session_established_context; bool had_a_connection; @@ -323,18 +324,18 @@ public: AuthConnectionMeta *auth_meta, uint32_t *method, std::vector *preferred_modes, - bufferlist *bl) override; + ceph::buffer::list *bl) override; int handle_auth_reply_more( Connection *con, AuthConnectionMeta *auth_meta, - const bufferlist& bl, - bufferlist *reply) override; + const ceph::buffer::list& bl, + ceph::buffer::list *reply) override; int handle_auth_done( Connection *con, AuthConnectionMeta *auth_meta, uint64_t global_id, uint32_t con_mode, - const bufferlist& bl, + const ceph::buffer::list& bl, CryptoKey *session_key, std::string *connection_secret) override; int handle_auth_bad_method( @@ -350,8 +351,8 @@ public: AuthConnectionMeta *auth_meta, bool more, uint32_t auth_method, - const bufferlist& bl, - bufferlist *reply); + const ceph::buffer::list& bl, + ceph::buffer::list *reply); void set_entity_name(EntityName name) { entity_name = name; } void set_handle_authentication_dispatcher(Dispatcher *d) { @@ -384,19 +385,19 @@ public: std::lock_guard l(monc_lock); _renew_subs(); } - bool sub_want(string what, version_t start, unsigned flags) { + bool sub_want(std::string what, version_t start, unsigned flags) { std::lock_guard l(monc_lock); return sub.want(what, start, flags); } - void sub_got(string what, version_t have) { + void sub_got(std::string what, version_t have) { std::lock_guard l(monc_lock); sub.got(what, have); } - void sub_unwant(string what) { + void sub_unwant(std::string what) { std::lock_guard l(monc_lock); sub.unwant(what); } - bool sub_want_increment(string what, version_t start, unsigned flags) { + bool sub_want_increment(std::string what, version_t start, unsigned flags) { std::lock_guard l(monc_lock); return sub.inc_want(what, start, flags); } @@ -445,7 +446,7 @@ public: * -ETIMEDOUT if monitor didn't reply before timeout * expired (default: conf->client_mount_timeout). */ - int ping_monitor(const string &mon_id, string *result_reply); + int ping_monitor(const std::string &mon_id, std::string *result_reply); void send_mon_message(Message *m) { std::lock_guard l(monc_lock); @@ -499,13 +500,13 @@ private: uint64_t last_mon_command_tid; struct MonCommand { - string target_name; + std::string target_name; int target_rank; uint64_t tid; - vector cmd; - bufferlist inbl; - bufferlist *poutbl; - string *prs; + std::vector cmd; + ceph::buffer::list inbl; + ceph::buffer::list *poutbl; + std::string *prs; int *prval; Context *onfinish, *ontimeout; @@ -515,40 +516,40 @@ private: poutbl(NULL), prs(NULL), prval(NULL), onfinish(NULL), ontimeout(NULL) {} }; - map mon_commands; + std::map mon_commands; void _send_command(MonCommand *r); void _resend_mon_commands(); int _cancel_mon_command(uint64_t tid); - void _finish_command(MonCommand *r, int ret, string rs); + void _finish_command(MonCommand *r, int ret, std::string rs); void _finish_auth(); void handle_mon_command_ack(MMonCommandAck *ack); public: - void start_mon_command(const vector& cmd, const bufferlist& inbl, - bufferlist *outbl, string *outs, + void start_mon_command(const std::vector& cmd, const ceph::buffer::list& inbl, + ceph::buffer::list *outbl, std::string *outs, Context *onfinish); void start_mon_command(int mon_rank, - const vector& cmd, const bufferlist& inbl, - bufferlist *outbl, string *outs, - Context *onfinish); - void start_mon_command(const string &mon_name, ///< mon name, with mon. prefix - const vector& cmd, const bufferlist& inbl, - bufferlist *outbl, string *outs, - Context *onfinish); + const std::vector& cmd, const ceph::buffer::list& inbl, + ceph::buffer::list *outbl, std::string *outs, + Context *onfinish); + void start_mon_command(const std::string &mon_name, ///< mon name, with mon. prefix + const std::vector& cmd, const ceph::buffer::list& inbl, + ceph::buffer::list *outbl, std::string *outs, + Context *onfinish); // version requests public: /** * get latest known version(s) of cluster map * - * @param map string name of map (e.g., 'osdmap') + * @param map std::string name of map (e.g., 'osdmap') * @param newest pointer where newest map version will be stored * @param oldest pointer where oldest map version will be stored * @param onfinish context that will be triggered on completion * @return (via context) 0 on success, -EAGAIN if we need to resubmit our request */ - void get_version(string map, version_t *newest, version_t *oldest, Context *onfinish); + void get_version(std::string map, version_t *newest, version_t *oldest, Context *onfinish); /** * Run a callback within our lock, with a reference * to the MonMap @@ -573,7 +574,7 @@ private: version_req_d(Context *con, version_t *n, version_t *o) : context(con),newest(n), oldest(o) {} }; - map version_requests; + std::map version_requests; ceph_tid_t version_req_id; void handle_get_version_reply(MMonGetVersionReply* m);