This belongs here, not in MonClient.
Signed-off-by: Sage Weil <sage@inktank.com>
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;
}
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();
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()
log_client = clog;
}
- static int build_initial_monmap(CephContext *cct, MonMap &monmap);
-
int build_initial_monmap();
int get_monmap();
int get_monmap_privately();
#include "include/ceph_features.h"
#include "include/addr_parsing.h"
#include "common/ceph_argparse.h"
+#include "common/errno.h"
#include "common/dout.h"
}
}
}
+
+
+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;
+}
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
*
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;