#undef dout_prefix
#define dout_prefix *_dout << "monclient" << (_hunting() ? "(hunting)":"") << ": "
+using std::string;
+
MonClient::MonClient(CephContext *cct_) :
Dispatcher(cct_),
AuthServer(cct_),
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;
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
{
// collect the next batch of candidates who are listed right next to the ones
// already tried
- auto get_next_batch = [this]() -> vector<unsigned> {
- multimap<uint16_t, unsigned> 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<unsigned> {
+ std::multimap<uint16_t, unsigned> 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<unsigned> ranks;
+ std::vector<unsigned> ranks;
boost::range::copy(cands | boost::adaptors::map_values,
std::back_inserter(ranks));
return ranks;
}
ceph_assert(!ranks.empty());
if (ranks.size() > 1) {
- vector<uint16_t> weights;
+ std::vector<uint16_t> weights;
for (auto i : ranks) {
auto rank_name = monmap.get_name(i);
weights.push_back(monmap.get_weight(rank_name));
void MonClient::_resend_mon_commands()
{
// resend any requests
- for (map<uint64_t,MonCommand*>::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);
}
}
r = mon_commands.begin()->second;
ldout(cct, 10) << __func__ << " has tid 0, assuming it is " << r->tid << dendl;
} else {
- map<uint64_t,MonCommand*>::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();
{
ceph_assert(monc_lock.is_locked());
- map<ceph_tid_t, MonCommand*>::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;
delete r;
}
-void MonClient::start_mon_command(const vector<string>& cmd,
- const bufferlist& inbl,
- bufferlist *outbl, string *outs,
- Context *onfinish)
+void MonClient::start_mon_command(const std::vector<string>& cmd,
+ const ceph::buffer::list& inbl,
+ ceph::buffer::list *outbl, string *outs,
+ Context *onfinish)
{
std::lock_guard l(monc_lock);
if (!initialized || stopping) {
}
void MonClient::start_mon_command(const string &mon_name,
- const vector<string>& cmd,
- const bufferlist& inbl,
- bufferlist *outbl, string *outs,
- Context *onfinish)
+ const std::vector<string>& cmd,
+ const ceph::buffer::list& inbl,
+ ceph::buffer::list *outbl, string *outs,
+ Context *onfinish)
{
std::lock_guard l(monc_lock);
if (!initialized || stopping) {
}
void MonClient::start_mon_command(int rank,
- const vector<string>& cmd,
- const bufferlist& inbl,
- bufferlist *outbl, string *outs,
- Context *onfinish)
+ const std::vector<string>& cmd,
+ const ceph::buffer::list& inbl,
+ ceph::buffer::list *outbl, string *outs,
+ Context *onfinish)
{
std::lock_guard l(monc_lock);
if (!initialized || stopping) {
void MonClient::handle_get_version_reply(MMonGetVersionReply* m)
{
ceph_assert(monc_lock.is_locked());
- map<ceph_tid_t, version_req_d*>::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;
AuthConnectionMeta *auth_meta,
uint32_t *auth_method,
std::vector<uint32_t> *preferred_modes,
- bufferlist *bl)
+ ceph::buffer::list *bl)
{
std::lock_guard l(monc_lock);
ldout(cct,10) << __func__ << " con " << con << " auth_method " << *auth_method
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);
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)
{
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 ||
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()) {
m->monmap_epoch = epoch;
__u8 struct_v = 1;
encode(struct_v, m->auth_payload);
- vector<uint32_t> auth_supported;
+ std::vector<uint32_t> 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);
int MonConnection::get_auth_request(
uint32_t *method,
std::vector<uint32_t> *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<uint32_t> as;
+ std::vector<uint32_t> as;
auth_registry->get_supported_methods(con->get_peer_type(), &as);
if (as.empty()) {
return -EACCES;
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";
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)
{
ldout(cct,10) << __func__ << " old_auth_method " << old_auth_method
<< " result " << cpp_strerror(result)
<< " allowed_methods " << allowed_methods << dendl;
- vector<uint32_t> auth_supported;
+ std::vector<uint32_t> 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);
int get_auth_request(
uint32_t *method,
std::vector<uint32_t> *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(
Mutex lock;
Cond ping_recvd_cond;
- string *result;
+ std::string *result;
bool done;
RotatingKeyRing *keyring;
std::unique_ptr<MonConnection> mc;
MonClientPinger(CephContext *cct_,
RotatingKeyRing *keyring,
- string *res_) :
+ std::string *res_) :
Dispatcher(cct_),
lock("MonClientPinger::lock"),
result(res_),
}
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);
AuthConnectionMeta *auth_meta,
uint32_t *auth_method,
std::vector<uint32_t> *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(
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,
public AuthServer /* for mgr, osd, mds */ {
public:
MonMap monmap;
- map<string,string> config_mgr;
+ std::map<std::string,std::string> config_mgr;
private:
Messenger *messenger;
int authenticate_err = 0;
bool authenticated = false;
- list<Message*> waiting_for_session;
+ std::list<Message*> waiting_for_session;
utime_t last_rotating_renew_sent;
std::unique_ptr<Context> session_established_context;
bool had_a_connection;
AuthConnectionMeta *auth_meta,
uint32_t *method,
std::vector<uint32_t> *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(
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) {
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);
}
* -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);
uint64_t last_mon_command_tid;
struct MonCommand {
- string target_name;
+ std::string target_name;
int target_rank;
uint64_t tid;
- vector<string> cmd;
- bufferlist inbl;
- bufferlist *poutbl;
- string *prs;
+ std::vector<std::string> cmd;
+ ceph::buffer::list inbl;
+ ceph::buffer::list *poutbl;
+ std::string *prs;
int *prval;
Context *onfinish, *ontimeout;
poutbl(NULL), prs(NULL), prval(NULL), onfinish(NULL), ontimeout(NULL)
{}
};
- map<uint64_t,MonCommand*> mon_commands;
+ std::map<uint64_t,MonCommand*> 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<string>& cmd, const bufferlist& inbl,
- bufferlist *outbl, string *outs,
+ void start_mon_command(const std::vector<std::string>& cmd, const ceph::buffer::list& inbl,
+ ceph::buffer::list *outbl, std::string *outs,
Context *onfinish);
void start_mon_command(int mon_rank,
- const vector<string>& 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<string>& cmd, const bufferlist& inbl,
- bufferlist *outbl, string *outs,
- Context *onfinish);
+ const std::vector<std::string>& 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<std::string>& 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
version_req_d(Context *con, version_t *n, version_t *o) : context(con),newest(n), oldest(o) {}
};
- map<ceph_tid_t, version_req_d*> version_requests;
+ std::map<ceph_tid_t, version_req_d*> version_requests;
ceph_tid_t version_req_id;
void handle_get_version_reply(MMonGetVersionReply* m);