* Ping the monitor with id @p mon_id and set the resulting reply in * the provided @p result_reply, if this last parameter is not NULL. * * So that we don't rely on the MonClient's default messenger, set up * during connect(), we create our own messenger to comunicate with the * specified monitor. This is advantageous in the following ways: * * - Isolate the ping procedure from the rest of
| 236 | * would be used for all pings. |
| 237 | */ |
| 238 | int MonClient::ping_monitor(const string &mon_id, string *result_reply) |
| 239 | { |
| 240 | ldout(cct, 10) << __func__ << dendl; |
| 241 | |
| 242 | string new_mon_id; |
| 243 | if (monmap.contains("noname-"+mon_id)) { |
| 244 | new_mon_id = "noname-"+mon_id; |
| 245 | } else { |
| 246 | new_mon_id = mon_id; |
| 247 | } |
| 248 | |
| 249 | if (new_mon_id.empty()) { |
| 250 | ldout(cct, 10) << __func__ << " specified mon id is empty!" << dendl; |
| 251 | return -EINVAL; |
| 252 | } else if (!monmap.contains(new_mon_id)) { |
| 253 | ldout(cct, 10) << __func__ << " no such monitor 'mon." << new_mon_id << "'" |
| 254 | << dendl; |
| 255 | return -ENOENT; |
| 256 | } |
| 257 | |
| 258 | // N.B. monc isn't initialized |
| 259 | |
| 260 | auth_registry.refresh_config(); |
| 261 | |
| 262 | KeyRing keyring; |
| 263 | keyring.from_ceph_context(cct); |
| 264 | RotatingKeyRing rkeyring(cct, cct->get_module_type(), &keyring); |
| 265 | |
| 266 | MonClientPinger *pinger = new MonClientPinger(cct, |
| 267 | &rkeyring, |
| 268 | result_reply); |
| 269 | |
| 270 | Messenger *smsgr = Messenger::create_client_messenger(cct, "temp_ping_client"); |
| 271 | smsgr->add_dispatcher_head(pinger, Dispatcher::PRIORITY_HIGH); |
| 272 | smsgr->set_auth_client(pinger); |
| 273 | smsgr->start(); |
| 274 | |
| 275 | ConnectionRef con = smsgr->connect_to_mon(monmap.get_addrs(new_mon_id)); |
| 276 | ldout(cct, 10) << __func__ << " ping mon." << new_mon_id |
| 277 | << " " << con->get_peer_addr() << dendl; |
| 278 | |
| 279 | pinger->mc.reset(new MonConnection(cct, con, 0, &auth_registry)); |
| 280 | pinger->mc->start(monmap.get_epoch(), entity_name); |
| 281 | con->send_message(new MPing); |
| 282 | |
| 283 | int ret = pinger->wait_for_reply(cct->_conf->mon_client_ping_timeout); |
| 284 | if (ret == 0) { |
| 285 | ldout(cct,10) << __func__ << " got ping reply" << dendl; |
| 286 | } else { |
| 287 | ret = -ret; |
| 288 | } |
| 289 | |
| 290 | con->mark_down(); |
| 291 | pinger->mc.reset(); |
| 292 | smsgr->shutdown(); |
| 293 | smsgr->wait(); |
| 294 | delete smsgr; |
| 295 | delete pinger; |