]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonMap: adjust build_initial behavior for mkfs vs probe
authorSage Weil <sage@redhat.com>
Tue, 11 Dec 2018 03:32:39 +0000 (21:32 -0600)
committerSage Weil <sage@redhat.com>
Thu, 3 Jan 2019 17:17:31 +0000 (11:17 -0600)
For the mkfs case, interpret an ambiguous port as a v2 address.  For probe,
try both.

Signed-off-by: Sage Weil <sage@redhat.com>
src/ceph_mon.cc
src/crimson/mon/MonClient.cc
src/krbd.cc
src/mon/MonClient.cc
src/mon/MonMap.cc
src/mon/MonMap.h
src/test/mon/MonMap.cc
src/tools/ceph_monstore_tool.cc
src/tools/monmaptool.cc

index 0df665d5e62b02c2e8bb22842e3e21afc6432d49..e47cf22cc8c6d87e563b66a5c9de11c037a01d68 100644 (file)
@@ -372,7 +372,7 @@ int main(int argc, const char **argv)
       }      
     } else {
       ostringstream oss;
-      int err = monmap.build_initial(g_ceph_context, oss);
+      int err = monmap.build_initial(g_ceph_context, true, oss);
       if (oss.tellp())
         derr << oss.str() << dendl;
       if (err < 0) {
@@ -673,7 +673,7 @@ int main(int argc, const char **argv)
     } else {
       MonMap tmpmap;
       ostringstream oss;
-      int err = tmpmap.build_initial(g_ceph_context, oss);
+      int err = tmpmap.build_initial(g_ceph_context, true, oss);
       if (oss.tellp())
         derr << oss.str() << dendl;
       if (err < 0) {
index 8817abc193dd6265cda22855d4b44efd10ec037a..0ba52e16f9e3b8b9415fee4f673ef52df0682a74 100644 (file)
@@ -463,7 +463,7 @@ std::vector<unsigned> Client::get_random_mons(unsigned n) const
 
 seastar::future<> Client::build_initial_map()
 {
-  return monmap.build_initial(ceph::common::local_conf());
+  return monmap.build_initial(ceph::common::local_conf(), false);
 }
 
 seastar::future<> Client::authenticate()
index d9fa1727d6db90ba94ca3ce81fa5fdef08a64b84..88da074664db18280d46f956cf8a6f68fa59241c 100644 (file)
@@ -162,7 +162,7 @@ static int build_map_buf(CephContext *cct, const krbd_spec& spec,
   int r;
 
   MonMap monmap;
-  r = monmap.build_initial(cct, cerr);
+  r = monmap.build_initial(cct, false, cerr);
   if (r < 0)
     return r;
 
index f4587b777ef0d10314d14f99fc4568c2227a0e5d..2055ddbce8f6cf97a88319e7dc9c95b66198965a 100644 (file)
@@ -73,7 +73,7 @@ MonClient::~MonClient()
 int MonClient::build_initial_monmap()
 {
   ldout(cct, 10) << __func__ << dendl;
-  return monmap.build_initial(cct, cerr);
+  return monmap.build_initial(cct, false, cerr);
 }
 
 int MonClient::get_monmap()
index 5ce5a93e41a4f252634cb7fd594203ec4dbbfb9d..f5478e2612869b082daa02f1410d5ccd64c51eae 100644 (file)
@@ -408,10 +408,13 @@ void MonMap::_add_ambiguous_addr(const string& name,
 }
 
 int MonMap::init_with_ips(const std::string& ips,
+                         bool for_mkfs,
                          const std::string &prefix)
 {
   vector<entity_addr_t> addrs;
-  if (!parse_ip_port_vec(ips.c_str(), addrs, entity_addr_t::TYPE_ANY)) {
+  if (!parse_ip_port_vec(
+       ips.c_str(), addrs,
+       for_mkfs ? entity_addr_t::TYPE_MSGR2 : entity_addr_t::TYPE_ANY)) {
     return -EINVAL;
   }
   if (addrs.empty())
@@ -428,6 +431,7 @@ int MonMap::init_with_ips(const std::string& ips,
 }
 
 int MonMap::init_with_hosts(const std::string& hostlist,
+                           bool for_mkfs,
                            const std::string& prefix)
 {
   // maybe they passed us a DNS-resolvable name
@@ -436,7 +440,9 @@ int MonMap::init_with_hosts(const std::string& hostlist,
     return -EINVAL;
 
   vector<entity_addr_t> addrs;
-  bool success = parse_ip_port_vec(hosts, addrs, entity_addr_t::TYPE_ANY);
+  bool success = parse_ip_port_vec(
+    hosts, addrs,
+    for_mkfs ? entity_addr_t::TYPE_MSGR2 : entity_addr_t::TYPE_ANY);
   free(hosts);
   if (!success)
     return -EINVAL;
@@ -593,7 +599,7 @@ future<> MonMap::read_monmap(const std::string& monmap)
   });
 }
 
-future<> MonMap::init_with_dns_srv(const std::string& name)
+future<> MonMap::init_with_dns_srv(bool for_mkfs, const std::string& name)
 {
   string domain;
   string service = name;
@@ -612,7 +618,7 @@ future<> MonMap::init_with_dns_srv(const std::string& name)
        // the resolved address does not contain ceph specific info like nonce
        // nonce or msgr proto (legacy, msgr2), so set entity_addr_t manually
        entity_addr_t addr;
-       addr.set_type(entity_addr_t::TYPE_LEGACY);
+       addr.set_type(entity_addr_t::TYPE_ANY);
        addr.set_family(int(a.in_family()));
        addr.set_port(record.port);
        switch (a.in_family()) {
@@ -623,7 +629,7 @@ future<> MonMap::init_with_dns_srv(const std::string& name)
          addr.in6_addr().sin6_addr = a;
          break;
        }
-       add(mon_info_t{record.target, addr, record.priority});
+       _add_ambiguous_addr(record.target, addr, record.priority);
       });
     });
   }).handle_exception_type([](const std::system_error& e) {
@@ -632,7 +638,8 @@ future<> MonMap::init_with_dns_srv(const std::string& name)
   });
 }
 
-seastar::future<> MonMap::build_monmap(const ceph::common::ConfigProxy& conf)
+seastar::future<> MonMap::build_monmap(const ceph::common::ConfigProxy& conf,
+                                      bool for_mkfs)
 {
   // -m foo?
   if (const auto mon_host = conf.get_val<std::string>("mon_host");
@@ -665,7 +672,7 @@ seastar::future<> MonMap::build_monmap(const ceph::common::ConfigProxy& conf)
   });
 }
 
-future<> MonMap::build_initial(const ceph::common::ConfigProxy& conf)
+future<> MonMap::build_initial(const ceph::common::ConfigProxy& conf, bool for_mkfs)
 {
   // file?
   if (const auto monmap = conf.get_val<std::string>("monmap");
@@ -677,7 +684,7 @@ future<> MonMap::build_initial(const ceph::common::ConfigProxy& conf)
         !new_fsid.is_zero()) {
       fsid = new_fsid;
     }
-    return build_monmap(conf).then([this] {
+    return build_monmap(conf, for_mkfs).then([this] {
       created = ceph_clock_now();
       last_changed = created;
       calc_legacy_ranks();
@@ -704,6 +711,7 @@ int MonMap::init_with_monmap(const std::string& monmap, std::ostream& errout)
 
 int MonMap::init_with_dns_srv(CephContext* cct,
                               std::string srv_name,
+                             bool for_mkfs,
                               std::ostream& errout)
 {
   string domain;
@@ -722,7 +730,8 @@ int MonMap::init_with_dns_srv(CephContext* cct,
            << "ceph-mon" << std::endl;
     return -1;
   } else {
-    for (const auto& record : records) {
+    for (auto& record : records) {
+      record.second.addr.set_type(entity_addr_t::TYPE_ANY);
       _add_ambiguous_addr(record.first, record.second.addr,
                          record.second.priority);
     }
@@ -730,7 +739,7 @@ int MonMap::init_with_dns_srv(CephContext* cct,
   }
 }
 
-int MonMap::build_initial(CephContext *cct, ostream& errout)
+int MonMap::build_initial(CephContext *cct, bool for_mkfs, ostream& errout)
 {
   const auto& conf = cct->_conf;
   // file?
@@ -747,9 +756,9 @@ int MonMap::build_initial(CephContext *cct, ostream& errout)
   // -m foo?
   if (const auto mon_host = conf.get_val<std::string>("mon_host");
       !mon_host.empty()) {
-    auto ret = init_with_ips(mon_host, "noname-");
+    auto ret = init_with_ips(mon_host, for_mkfs, "noname-");
     if (ret == -EINVAL) {
-      ret = init_with_hosts(mon_host, "noname-");
+      ret = init_with_hosts(mon_host, for_mkfs, "noname-");
     }
     if (ret < 0) {
       errout << "unable to parse addrs in '" << mon_host << "'"
@@ -766,7 +775,7 @@ int MonMap::build_initial(CephContext *cct, ostream& errout)
   if (size() == 0) {
     // no info found from conf options lets try use DNS SRV records
     string srv_name = conf.get_val<std::string>("mon_dns_srv_name");
-    if (auto ret = init_with_dns_srv(cct, srv_name, errout); ret < 0) {
+    if (auto ret = init_with_dns_srv(cct, srv_name, for_mkfs, errout); ret < 0) {
       return -ENOENT;
     }
   }
index d214157d034bd6a7e69ff15e34ebb7631f534a4a..7ea959e673779c338f55c0965d2cecf8942dc72d 100644 (file)
@@ -382,9 +382,9 @@ public:
    * @param errout ostream to send error messages too
    */
 #ifdef WITH_SEASTAR
-  seastar::future<> build_initial(const ceph::common::ConfigProxy& conf);
+  seastar::future<> build_initial(const ceph::common::ConfigProxy& conf, bool for_mkfs);
 #else
-  int build_initial(CephContext *cct, ostream& errout);
+  int build_initial(CephContext *cct, bool for_mkfs, ostream& errout);
 #endif
   /**
    * filter monmap given a set of initial members.
@@ -421,7 +421,8 @@ protected:
    * @return 0 for success, -errno on error
    */
   int init_with_ips(const std::string& ips,
-                        const std::string &prefix);
+                   bool for_mkfs,
+                   const std::string &prefix);
   /**
    * build a monmap from a list of hostnames
    *
@@ -432,19 +433,20 @@ protected:
    * @return 0 for success, -errno on error
    */
   int init_with_hosts(const std::string& hostlist,
-                        const std::string& prefix);
+                     bool for_mkfs,
+                     const std::string& prefix);
   int init_with_config_file(const ConfigProxy& conf, std::ostream& errout);
 #if WITH_SEASTAR
   seastar::future<> read_monmap(const std::string& monmap);
   /// try to build monmap with different settings, like
   /// mon_host, mon* sections, and mon_dns_srv_name
-  seastar::future<> build_monmap(const ceph::common::ConfigProxy& conf);
+  seastar::future<> build_monmap(const ceph::common::ConfigProxy& conf, bool for_mkfs);
   /// initialize monmap by resolving given service name
-  seastar::future<> init_with_dns_srv(const std::string& name);
+  seastar::future<> init_with_dns_srv(bool for_mkfs, const std::string& name);
 #else
   /// read from encoded monmap file
   int init_with_monmap(const std::string& monmap, std::ostream& errout);
-  int init_with_dns_srv(CephContext* cct, std::string srv_name,
+  int init_with_dns_srv(CephContext* cct, std::string srv_name, bool for_mkfs,
                        std::ostream& errout);
 #endif
 };
index 2b09f33e758dd8dd957d9ada3cffe0f1c17184fc..f3c00bfd79442746c3521ca25fed58aef47a03b6 100644 (file)
@@ -99,7 +99,7 @@ TEST_F(MonMapTest, build_initial_config_from_dns) {
   CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_MON))->get();
   cct->_conf.set_val("mon_dns_srv_name", "cephmon");
   MonMap monmap;
-  int r = monmap.build_initial(cct, std::cerr);
+  int r = monmap.build_initial(cct, false, std::cerr);
 
   ASSERT_EQ(r, 0);
   ASSERT_EQ(monmap.mon_addr.size(), (unsigned int)3);
@@ -136,7 +136,7 @@ TEST_F(MonMapTest, build_initial_config_from_dns_fail) {
   CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_MON))->get();
   // using default value of mon_dns_srv_name option
   MonMap monmap;
-  int r = monmap.build_initial(cct, std::cerr);
+  int r = monmap.build_initial(cct, false, std::cerr);
 
   ASSERT_EQ(r, -ENOENT);
   ASSERT_EQ(monmap.mon_addr.size(), (unsigned int)0);
@@ -197,7 +197,7 @@ TEST_F(MonMapTest, build_initial_config_from_dns_with_domain) {
   CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_MON))->get();
   cct->_conf.set_val("mon_dns_srv_name", "cephmon_ceph.com");
   MonMap monmap;
-  int r = monmap.build_initial(cct, std::cerr);
+  int r = monmap.build_initial(cct, false, std::cerr);
 
   ASSERT_EQ(r, 0);
   ASSERT_EQ(monmap.mon_addr.size(), (unsigned int)3);
index 97fcf03a8a4ded16f5d94369dce9dc85a7f1d2f4..59ba1422137ff1fd75c54a70fbea6a9113a08a44 100644 (file)
@@ -499,7 +499,7 @@ static int update_auth(MonitorDBStore& st, const string& keyring_path)
 static int update_mkfs(MonitorDBStore& st)
 {
   MonMap monmap;
-  int r = monmap.build_initial(g_ceph_context, cerr);
+  int r = monmap.build_initial(g_ceph_context, true, cerr);
   if (r) {
     cerr << "no initial monitors" << std::endl;
     return -EINVAL;
index 222d5b144d871d6d9203fb99d27b71bec41b80ed..7c92282234906216e0ee3d897e6da870726b651d 100644 (file)
@@ -335,7 +335,7 @@ int main(int argc, const char **argv)
   }
 
   if (generate) {
-    int r = monmap.build_initial(g_ceph_context, cerr);
+    int r = monmap.build_initial(g_ceph_context, true, cerr);
     if (r < 0)
       return r;
   }