]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monmap, crimson: unify handling of mon_host and most_host_override. 42994/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 31 Aug 2021 13:50:56 +0000 (13:50 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 31 Aug 2021 13:50:59 +0000 (13:50 +0000)
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 <rzarzyns@redhat.com>
src/mon/MonMap.cc
src/mon/MonMap.h

index 06ce6af28238124e218c0904f21ee29f8a1fecaf..491fdbb6e1102ef327314380dcf756442684fdbf 100644 (file)
@@ -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<std::string>("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<std::string>("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<std::string>("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<std::string>("mon_host_override"),
+                               for_mkfs)) {
+    return make_ready_future<>();
   }
 
   // file?
index 0516d188249585cb941574cc02546a5fd5eeec24..ad189e29b060453e9eefc65818f889e754e476bf 100644 (file)
@@ -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);