summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoao Eduardo Luis <joao.luis@inktank.com>2013-10-15 17:49:02 +0100
committerJoao Eduardo Luis <joao.luis@inktank.com>2013-10-16 01:42:46 +0100
commitb97dc9c72890fc1277320d886cd165248ed3b7d3 (patch)
tree289bbcef6f89415f956ddc63114ba8af38d68fe1
parent99cdd5ac113a29f8a744497281e2caee46974a1c (diff)
downloadceph-b97dc9c72890fc1277320d886cd165248ed3b7d3.tar.gz
mon: MonClient: allow pinging a monitor without authenticating first
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
-rw-r--r--src/mon/MonClient.cc59
-rw-r--r--src/mon/MonClient.h38
2 files changed, 87 insertions, 10 deletions
diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc
index 38bead8f29f..c53ec02ccf0 100644
--- a/src/mon/MonClient.cc
+++ b/src/mon/MonClient.cc
@@ -22,6 +22,7 @@
#include "messages/MAuthReply.h"
#include "messages/MMonCommand.h"
#include "messages/MMonCommandAck.h"
+#include "messages/MPing.h"
#include "messages/MMonSubscribe.h"
#include "messages/MMonSubscribeAck.h"
@@ -107,32 +108,31 @@ int MonClient::get_monmap_privately()
{
ldout(cct, 10) << "get_monmap_privately" << dendl;
Mutex::Locker l(monc_lock);
-
+
bool temp_msgr = false;
SimpleMessenger* smessenger = NULL;
if (!messenger) {
messenger = smessenger = new SimpleMessenger(cct,
entity_name_t::CLIENT(-1),
- "temp_mon_client",
- getpid());
+ "temp_mon_client", getpid());
messenger->add_dispatcher_head(this);
smessenger->start();
- temp_msgr = true;
+ temp_msgr = true;
}
-
+
int attempt = 10;
-
+
ldout(cct, 10) << "have " << monmap.epoch << " fsid " << monmap.fsid << dendl;
-
+
while (monmap.fsid.is_zero()) {
cur_mon = _pick_random_mon();
cur_con = messenger->get_connection(monmap.get_inst(cur_mon));
ldout(cct, 10) << "querying mon." << cur_mon << " " << cur_con->get_peer_addr() << dendl;
messenger->send_message(new MMonGetMap, cur_con);
-
+
if (--attempt == 0)
break;
-
+
utime_t interval;
interval.set_from_double(cct->_conf->mon_client_hunt_interval);
map_cond.WaitInterval(cct, monc_lock, interval);
@@ -153,7 +153,7 @@ int MonClient::get_monmap_privately()
messenger = 0;
monc_lock.Lock();
}
-
+
hunting = true; // reset this to true!
cur_mon.clear();
@@ -164,6 +164,45 @@ int MonClient::get_monmap_privately()
return -1;
}
+int MonClient::ping_monitor(string *result_reply)
+{
+ ldout(cct, 10) << __func__ << dendl;
+ Mutex::Locker l(monc_lock);
+
+ MonClientPinger *pinger = new MonClientPinger(cct, result_reply);
+ Messenger *smsgr = new SimpleMessenger(cct,
+ entity_name_t::CLIENT(-1),
+ "temp_ping_client", getpid());
+ smsgr->add_dispatcher_head(pinger);
+ smsgr->start();
+
+ cur_mon = _pick_random_mon();
+ cur_con = smsgr->get_connection(monmap.get_inst(cur_mon));
+ ldout(cct, 10) << __func__ << " ping mon." << cur_mon
+ << " " << cur_con->get_peer_addr() << dendl;
+ pinger->lock.Lock();
+ smsgr->send_message(new MPing, cur_con);
+
+ utime_t until = ceph_clock_now(cct);
+ until += cct->_conf->client_mount_timeout;
+ int r = pinger->ping_recvd_cond.WaitUntil(pinger->lock, until);
+ if (r == ETIMEDOUT) {
+ return -r;
+ }
+ ldout(cct,10) << __func__ << " got ping reply" << dendl;
+ pinger->lock.Unlock();
+
+ smsgr->mark_down(cur_con);
+ cur_con.reset(NULL);
+ monc_lock.Unlock();
+ smsgr->shutdown();
+ smsgr->wait();
+ delete smsgr;
+ delete pinger;
+ monc_lock.Lock();
+ cur_mon.clear();
+ return 0;
+}
bool MonClient::ms_dispatch(Message *m)
{
diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h
index 64a399a197a..7b5f6f274ba 100644
--- a/src/mon/MonClient.h
+++ b/src/mon/MonClient.h
@@ -42,6 +42,7 @@ class MMonCommandAck;
class MCommandReply;
struct MAuthReply;
class MAuthRotating;
+class MPing;
class LogClient;
class AuthSupported;
class AuthAuthorizeHandlerRegistry;
@@ -54,6 +55,42 @@ enum MonClientState {
MC_STATE_HAVE_SESSION,
};
+struct MonClientPinger : public Dispatcher {
+
+ CephContext *cct;
+ Mutex lock;
+ Cond ping_recvd_cond;
+ string *result;
+
+ MonClientPinger(CephContext *cct_, string *res_) :
+ Dispatcher(cct_),
+ cct(cct_),
+ lock("MonClientPinger::lock"),
+ result(res_)
+ { }
+
+ bool ms_dispatch(Message *m) {
+ Mutex::Locker l(lock);
+ if (m->get_type() != CEPH_MSG_PING)
+ return false;
+
+ bufferlist &payload = m->get_payload();
+ if (result && payload.length() > 0) {
+ bufferlist::iterator p = payload.begin();
+ ::decode(*result, p);
+ }
+ ping_recvd_cond.SignalAll();
+ m->put();
+ return true;
+ }
+ bool ms_handle_reset(Connection *con) {
+ Mutex::Locker l(lock);
+ ping_recvd_cond.SignalAll();
+ return true;
+ }
+ void ms_handle_remote_reset(Connection *con) {}
+};
+
class MonClient : public Dispatcher {
public:
MonMap monmap;
@@ -211,6 +248,7 @@ public:
int build_initial_monmap();
int get_monmap();
int get_monmap_privately();
+ int ping_monitor(string *result_reply);
void send_mon_message(Message *m) {
Mutex::Locker l(monc_lock);