]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monmap: move build_initial() from MonClient
authorSage Weil <sage@inktank.com>
Fri, 18 May 2012 17:38:26 +0000 (10:38 -0700)
committerSage Weil <sage@inktank.com>
Fri, 18 May 2012 23:23:58 +0000 (16:23 -0700)
This belongs here, not in MonClient.

Signed-off-by: Sage Weil <sage@inktank.com>
src/ceph_mon.cc
src/mon/MonClient.cc
src/mon/MonClient.h
src/mon/MonMap.cc
src/mon/MonMap.h
src/rbd.cc

index 6ad27c2abc7cc4cffd59be320e9c22bd00ae0459..1754e211f48d0e48eb6bfbb9c2b06e889f7bbe96 100644 (file)
@@ -133,7 +133,7 @@ int main(int argc, const char **argv)
        exit(1);
       }      
     } else {
-      int err = MonClient::build_initial_monmap(g_ceph_context, monmap);
+      int err = monmap.build_initial(g_ceph_context, cerr);
       if (err < 0) {
        cerr << argv[0] << ": warning: no initial monitors; must set 'mon initial members' and use admin socket to feed hints" << std::endl;
       }
@@ -347,7 +347,7 @@ int main(int argc, const char **argv)
       ipaddr = g_conf->public_addr;
     } else {
       MonMap tmpmap;
-      int err = MonClient::build_initial_monmap(g_ceph_context, tmpmap);
+      int err = tmpmap.build_initial(g_ceph_context, cerr);
       if (err < 0) {
        cerr << argv[0] << ": error generating initial monmap: " << cpp_strerror(err) << std::endl;
        usage();
index 0a0cc515239bf0b2c24aec82b5c4644ec20c0893..c1574fcaa3423f7cdb8f8b1dc668b3fc75a22700 100644 (file)
@@ -73,98 +73,10 @@ MonClient::~MonClient()
   delete rotating_secrets;
 }
 
-/*
- * build an initial monmap with any known monitor
- * addresses.
- */
-int MonClient::build_initial_monmap(CephContext *cct, MonMap &monmap)
-{
-  const md_config_t *conf = cct->_conf;
-  // file?
-  if (!conf->monmap.empty()) {
-    int r;
-    try {
-      r = monmap.read(conf->monmap.c_str());
-    }
-    catch (const buffer::error &e) {
-      r = -EINVAL;
-    }
-    if (r >= 0)
-      return 0;
-    cerr << "unable to read/decode monmap from " << conf->monmap
-        << ": " << cpp_strerror(-r) << std::endl;
-    return r;
-  }
-
-  // fsid from conf?
-  if (!cct->_conf->fsid.is_zero()) {
-    monmap.fsid = cct->_conf->fsid;
-  }
-
-  // -m foo?
-  if (!conf->mon_host.empty()) {
-    int r = monmap.build_from_host_list(conf->mon_host, "noname-");
-    if (r < 0)
-      cerr << "unable to parse addrs in '" << conf->mon_host << "'" << std::endl;
-  }
-
-  // What monitors are in the config file?
-  std::vector <std::string> sections;
-  int ret = conf->get_all_sections(sections);
-  if (ret) {
-    cerr << "Unable to find any monitors in the configuration "
-         << "file, because there was an error listing the sections. error "
-        << ret << std::endl;
-    return -ENOENT;
-  }
-  std::vector <std::string> mon_names;
-  for (std::vector <std::string>::const_iterator s = sections.begin();
-       s != sections.end(); ++s) {
-    if ((s->substr(0, 4) == "mon.") && (s->size() > 4)) {
-      mon_names.push_back(s->substr(4));
-    }
-  }
-
-  // Find an address for each monitor in the config file.
-  for (std::vector <std::string>::const_iterator m = mon_names.begin();
-       m != mon_names.end(); ++m) {
-    std::vector <std::string> sections;
-    std::string m_name("mon");
-    m_name += ".";
-    m_name += *m;
-    sections.push_back(m_name);
-    sections.push_back("mon");
-    sections.push_back("global");
-    std::string val;
-    int res = conf->get_val_from_conf_file(sections, "mon addr", val, true);
-    if (res) {
-      cerr << "failed to get an address for mon." << *m << ": error "
-          << res << std::endl;
-      continue;
-    }
-    entity_addr_t addr;
-    if (!addr.parse(val.c_str())) {
-      cerr << "unable to parse address for mon." << *m
-          << ": addr='" << val << "'" << std::endl;
-      continue;
-    }
-    if (addr.get_port() == 0)
-      addr.set_port(CEPH_MON_PORT);    
-    monmap.add(m->c_str(), addr);
-  }
-
-  if (monmap.size() == 0) {
-    cerr << "unable to find any monitors in conf. "
-        << "please specify monitors via -m monaddr or -c ceph.conf" << std::endl;
-    return -ENOENT;
-  }
-  return 0;
-}
-
 int MonClient::build_initial_monmap()
 {
   ldout(cct, 10) << "build_initial_monmap" << dendl;
-  return build_initial_monmap(cct, monmap);
+  return monmap.build_initial(cct, cerr);
 }
 
 int MonClient::get_monmap()
index fdcdbbbf45349cb03a6e06074fb77122b6097a6c..8763950f4fb67babd0070eca1368508ab0df044c 100644 (file)
@@ -181,8 +181,6 @@ public:
     log_client = clog;
   }
 
-  static int build_initial_monmap(CephContext *cct, MonMap &monmap);
-
   int build_initial_monmap();
   int get_monmap();
   int get_monmap_privately();
index 47a04720626c42ee60eda3391d9a85e4448c2d19..60e47df779bddd9f0e432bca3bf4784d2cc316b0 100644 (file)
@@ -10,6 +10,7 @@
 #include "include/ceph_features.h"
 #include "include/addr_parsing.h"
 #include "common/ceph_argparse.h"
+#include "common/errno.h"
 
 #include "common/dout.h"
 
@@ -230,3 +231,88 @@ void MonMap::filter_initial_members(CephContext *cct,
     }
   }
 }
+
+
+int MonMap::build_initial(CephContext *cct, ostream& errout)
+{
+  const md_config_t *conf = cct->_conf;
+  // file?
+  if (!conf->monmap.empty()) {
+    int r;
+    try {
+      r = read(conf->monmap.c_str());
+    }
+    catch (const buffer::error &e) {
+      r = -EINVAL;
+    }
+    if (r >= 0)
+      return 0;
+    errout << "unable to read/decode monmap from " << conf->monmap
+        << ": " << cpp_strerror(-r) << std::endl;
+    return r;
+  }
+
+  // fsid from conf?
+  if (!cct->_conf->fsid.is_zero()) {
+    fsid = cct->_conf->fsid;
+  }
+
+  // -m foo?
+  if (!conf->mon_host.empty()) {
+    int r = build_from_host_list(conf->mon_host, "noname-");
+    if (r < 0)
+      errout << "unable to parse addrs in '" << conf->mon_host << "'" << std::endl;
+  }
+
+  // What monitors are in the config file?
+  std::vector <std::string> sections;
+  int ret = conf->get_all_sections(sections);
+  if (ret) {
+    errout << "Unable to find any monitors in the configuration "
+         << "file, because there was an error listing the sections. error "
+        << ret << std::endl;
+    return -ENOENT;
+  }
+  std::vector <std::string> mon_names;
+  for (std::vector <std::string>::const_iterator s = sections.begin();
+       s != sections.end(); ++s) {
+    if ((s->substr(0, 4) == "mon.") && (s->size() > 4)) {
+      mon_names.push_back(s->substr(4));
+    }
+  }
+
+  // Find an address for each monitor in the config file.
+  for (std::vector <std::string>::const_iterator m = mon_names.begin();
+       m != mon_names.end(); ++m) {
+    std::vector <std::string> sections;
+    std::string m_name("mon");
+    m_name += ".";
+    m_name += *m;
+    sections.push_back(m_name);
+    sections.push_back("mon");
+    sections.push_back("global");
+    std::string val;
+    int res = conf->get_val_from_conf_file(sections, "mon addr", val, true);
+    if (res) {
+      errout << "failed to get an address for mon." << *m << ": error "
+          << res << std::endl;
+      continue;
+    }
+    entity_addr_t addr;
+    if (!addr.parse(val.c_str())) {
+      errout << "unable to parse address for mon." << *m
+          << ": addr='" << val << "'" << std::endl;
+      continue;
+    }
+    if (addr.get_port() == 0)
+      addr.set_port(CEPH_MON_PORT);    
+    add(m->c_str(), addr);
+  }
+
+  if (size() == 0) {
+    errout << "unable to find any monitors in conf. "
+        << "please specify monitors via -m monaddr or -c ceph.conf" << std::endl;
+    return -ENOENT;
+  }
+  return 0;
+}
index ea7a257abdb4b812d14aea4cb63d9864987adb55..449700fdbb535662d5ddc9c454044b823637d746 100644 (file)
@@ -198,6 +198,21 @@ class MonMap {
   int write(const char *fn);
   int read(const char *fn);
 
+  /**
+   * build an initial bootstrap monmap from conf
+   *
+   * Build an initial bootstrap monmap from the config.  This will
+   * try, in this order:
+   *
+   *   1 monmap   -- an explicitly provided monmap
+   *   2 mon_host -- list of monitors
+   *   3 config [mon.*] sections, and 'mon addr' fields in those sections
+   *
+   * @param cct context (and associated config)
+   * @param errout ostream to send error messages too
+   */
+  int build_initial(CephContext *cct, ostream& errout);
+
   /**
    * build a monmap from a list of hosts or ips
    *
index 655d9a2918c9481295d7624424ef6632ddd149bb..8e851ada297b5ebf5f6a8305b011e88defce6978 100644 (file)
@@ -600,7 +600,7 @@ static int do_kernel_add(const char *poolname, const char *imgname,
                         const char *user)
 {
   MonMap monmap;
-  int r = MonClient::build_initial_monmap(g_ceph_context, monmap);
+  int r = monmap.build_initial(g_ceph_context, cerr);
   if (r < 0)
     return r;