| 579 | } |
| 580 | |
| 581 | int MonClient::authenticate(double timeout) |
| 582 | { |
| 583 | std::unique_lock lock{monc_lock}; |
| 584 | |
| 585 | if (active_con) { |
| 586 | ldout(cct, 5) << "already authenticated" << dendl; |
| 587 | return 0; |
| 588 | } |
| 589 | sub.want("monmap", monmap.get_epoch() ? monmap.get_epoch() + 1 : 0, 0); |
| 590 | sub.want("config", 0, 0); |
| 591 | if (!_opened()) |
| 592 | _reopen_session(); |
| 593 | |
| 594 | auto until = ceph::mono_clock::now(); |
| 595 | until += ceph::make_timespan(timeout); |
| 596 | if (timeout > 0.0) |
| 597 | ldout(cct, 10) << "authenticate will time out at " << until << dendl; |
| 598 | while (!active_con && authenticate_err >= 0) { |
| 599 | if (timeout > 0.0) { |
| 600 | auto r = auth_cond.wait_until(lock, until); |
| 601 | if (r == std::cv_status::timeout && !active_con) { |
| 602 | ldout(cct, 0) << "authenticate timed out after " << timeout << dendl; |
| 603 | authenticate_err = -ETIMEDOUT; |
| 604 | } |
| 605 | } else { |
| 606 | auth_cond.wait(lock); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (active_con) { |
| 611 | ldout(cct, 5) << __func__ << " success, global_id " |
| 612 | << active_con->get_global_id() << dendl; |
| 613 | // active_con should not have been set if there was an error |
| 614 | ceph_assert(authenticate_err >= 0); |
| 615 | authenticated = true; |
| 616 | } |
| 617 | |
| 618 | if (authenticate_err < 0 && auth_registry.no_keyring_disabled_cephx()) { |
| 619 | lderr(cct) << __func__ << " NOTE: no keyring found; disabled cephx authentication" << dendl; |
| 620 | } |
| 621 | |
| 622 | return authenticate_err; |
| 623 | } |
| 624 | |
| 625 | int MonClient::call( |
| 626 | std::string_view command, |
no test coverage detected