From 3a91b8ac03f96520f8b70a40e125aa1d8072efb0 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Tue, 31 Aug 2021 13:50:56 +0000 Subject: [PATCH] monmap, crimson: unify handling of mon_host and most_host_override. This commit unifies the code for `mon_host` and `mon_host_override` handling but only in the `WITH_SEASTAR` domain. The next step is to extend to to the classical world but there is a subtle difference in error handling. Signed-off-by: Radoslaw Zarzynski --- src/mon/MonMap.cc | 36 ++++++++++++++++++------------------ src/mon/MonMap.h | 2 ++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc index 06ce6af2823..491fdbb6e11 100644 --- a/src/mon/MonMap.cc +++ b/src/mon/MonMap.cc @@ -787,22 +787,30 @@ seastar::future<> MonMap::init_with_dns_srv(bool for_mkfs, const std::string& na }); } -seastar::future<> MonMap::build_monmap(const crimson::common::ConfigProxy& conf, - bool for_mkfs) +bool MonMap::maybe_init_with_mon_host(const std::string& mon_host, + const bool for_mkfs) { - // -m foo? - if (const auto mon_host = conf.get_val("mon_host"); - !mon_host.empty()) { + if (!mon_host.empty()) { if (auto ret = init_with_ips(mon_host, for_mkfs, "noname-"); ret == 0) { - return make_ready_future<>(); + return true; } // TODO: resolve_addrs() is a blocking call if (auto ret = init_with_hosts(mon_host, for_mkfs, "noname-"); ret == 0) { - return make_ready_future<>(); + return true; } else { throw std::runtime_error(cpp_strerror(ret)); } } + return false; +} + +seastar::future<> MonMap::build_monmap(const crimson::common::ConfigProxy& conf, + bool for_mkfs) +{ + // -m foo? + if (maybe_init_with_mon_host(conf.get_val("mon_host"), for_mkfs)) { + return make_ready_future<>(); + } // What monitors are in the config file? ostringstream errout; @@ -824,17 +832,9 @@ seastar::future<> MonMap::build_monmap(const crimson::common::ConfigProxy& conf, seastar::future<> MonMap::build_initial(const crimson::common::ConfigProxy& conf, bool for_mkfs) { // mon_host_override? - if (auto mon_host_override = conf.get_val("mon_host_override"); - !mon_host_override.empty()) { - if (auto ret = init_with_ips(mon_host_override, for_mkfs, "noname-"); ret == 0) { - return make_ready_future<>(); - } - // TODO: resolve_addrs() is a blocking call - if (auto ret = init_with_hosts(mon_host_override, for_mkfs, "noname-"); ret == 0) { - return make_ready_future<>(); - } else { - throw std::runtime_error(cpp_strerror(ret)); - } + if (maybe_init_with_mon_host(conf.get_val("mon_host_override"), + for_mkfs)) { + return make_ready_future<>(); } // file? diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index 0516d188249..ad189e29b06 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -529,6 +529,8 @@ protected: seastar::future<> build_monmap(const crimson::common::ConfigProxy& conf, bool for_mkfs); /// initialize monmap by resolving given service name seastar::future<> init_with_dns_srv(bool for_mkfs, const std::string& name); + /// initialize monmap with `mon_host` or `mon_host_override` + bool maybe_init_with_mon_host(const std::string& mon_host, bool for_mkfs); #else /// read from encoded monmap file int init_with_monmap(const std::string& monmap, std::ostream& errout); -- 2.39.5