Then the callback is triggered when a new session is established, and the
daemon can do whatever it likes. There are no guarantees about how long it
might take to trigger, though. In particular we call the provided callback
while not holding our own lock in order to avoid deadlock. This could lead
to some funny ordering from the user's perspective if they call
reopen_session() again before getting the callback, but there's no way around
that, so they just have to use it appropriately.
Signed-off-by: Greg Farnum <greg@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
(cherry picked from commit
1a8c43474bf36bfcf2a94bf9b7e756a2a99f33fd)
want_monmap(true),
want_keys(0), global_id(0),
authenticate_err(0),
+ session_established_context(NULL),
auth(NULL),
keyring(NULL),
rotating_secrets(NULL),
MonClient::~MonClient()
{
delete auth_supported;
+ delete session_established_context;
delete auth;
delete keyring;
delete rotating_secrets;
void MonClient::handle_auth(MAuthReply *m)
{
+ Context *cb = NULL;
bufferlist::iterator p = m->result_bl.begin();
if (state == MC_STATE_NEGOTIATING) {
if (!auth || (int)m->protocol != auth->get_protocol()) {
log_client->reset_session();
send_log();
}
+ if (session_established_context) {
+ cb = session_established_context;
+ session_established_context = NULL;
+ }
}
_check_auth_tickets();
}
auth_cond.SignalAll();
+ if (cb) {
+ monc_lock.Unlock();
+ cb->complete(0);
+ monc_lock.Lock();
+ }
}
int authenticate_err;
list<Message*> waiting_for_session;
+ Context *session_established_context;
string _pick_random_mon();
void _finish_hunting();
Mutex::Locker l(monc_lock);
_send_mon_message(m);
}
- void reopen_session() {
+ /**
+ * If you specify a callback, you should not call
+ * reopen_session() again until it has been triggered. The MonClient
+ * will behave, but the first callback could be triggered after
+ * the session has been killed and the MonClient has started trying
+ * to reconnect to another monitor.
+ */
+ void reopen_session(Context *cb=NULL) {
Mutex::Locker l(monc_lock);
+ if (cb) {
+ delete session_established_context;
+ session_established_context = cb;
+ }
_reopen_session();
}