From: Sage Weil Date: Wed, 4 Mar 2009 00:02:10 +0000 (-0800) Subject: config: no more .ceph_monmap; parse cluster.conf for mon addrs X-Git-Tag: v0.7~45 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=af870763f3b81d7f85226fee34fd9dce66d74b58;p=ceph.git config: no more .ceph_monmap; parse cluster.conf for mon addrs Look for cluster.conf in /etc/ceph/cluster.conf, then ./cluster.conf. Make vstart.sh generate a cluster.conf. No more .ceph_monmap default.. only look for monmap file is specified on command line. --- diff --git a/src/common/ConfUtils.h b/src/common/ConfUtils.h index f37c71c43171b..e5c00c659a3b0 100644 --- a/src/common/ConfUtils.h +++ b/src/common/ConfUtils.h @@ -87,6 +87,7 @@ public: ~ConfFile(); const SectionList& get_section_list() { return sections_list; } + const char *get_filename() { return filename; } int parse(); int read(const char *section, const char *var, int *val, int def_val); diff --git a/src/config.cc b/src/config.cc index d1769a5cb6adb..2e32585040e14 100644 --- a/src/config.cc +++ b/src/config.cc @@ -232,7 +232,7 @@ void vec_to_argv(std::vector& args, argv[argc++] = args[i]; } -bool parse_ip_port(const char *s, entity_addr_t& a) +bool parse_ip_port(const char *s, entity_addr_t& a, const char **end) { int count = 0; // digit count int off = 0; @@ -256,7 +256,7 @@ bool parse_ip_port(const char *s, entity_addr_t& a) return false; // no digits } if (count < 3 && *s != '.') { - cerr << "should period at " << off << std::endl; + cerr << "should be period at " << off << std::endl; return false; // should have 3 periods } s++; off++; @@ -270,6 +270,8 @@ bool parse_ip_port(const char *s, entity_addr_t& a) if (count == 4 && *(s-1) != ':') break; if (count == 5) break; } + if (end) + *end = s; return true; } @@ -342,7 +344,7 @@ static struct config_option config_optionsp[] = { OPTION(global, num_mds, 0, INT, 1), OPTION(global, num_osd, 0, INT, 4), OPTION(global, num_client, 0, INT, 1), - OPTION(mon, monmap_file, 0, STR, ".ceph_monmap"), + OPTION(mon, monmap_file, 'M', STR, 0), OPTION(mon, mon_host, 'm', STR, 0), OPTION(global, daemonize, 'd', BOOL, false), OPTION(global, logger, 0, BOOL, true), @@ -354,7 +356,8 @@ static struct config_option config_optionsp[] = { OPTION(global, log_sym_dir, 0, STR, INSTALL_PREFIX "/var/log/ceph"), // if daemonize == true OPTION(global, log_to_stdout, 0, BOOL, true), OPTION(global, pid_file, 'p', STR, 0), - OPTION(global, conf_file, 'c', STR, INSTALL_PREFIX "etc/ceph/ceph.conf"), + OPTION(global, conf_file, 'c', STR, INSTALL_PREFIX "/etc/ceph/ceph.conf"), + OPTION(global, cluster_conf_file, 'C', STR, INSTALL_PREFIX "/etc/ceph/cluster.conf"), OPTION(global, dump_conf, 0, BOOL, false), OPTION(global, chdir_root, 0, BOOL, true), // chdir("/") after daemonizing. if true, we generate absolute paths as needed. OPTION(global, fake_clock, 0, BOOL, false), @@ -754,6 +757,10 @@ void parse_startup_config_options(std::vector& args) if (CMD_EQ("conf_file", 'c')) { SAFE_SET_ARG_VAL(&g_conf.conf_file, STR); + } else if (CMD_EQ("cluster_conf_file", 'C')) { + SAFE_SET_ARG_VAL(&g_conf.cluster_conf_file, STR); + } else if (CMD_EQ("monmap_file", 'M')) { + SAFE_SET_ARG_VAL(&g_conf.monmap_file, STR); } else if (CMD_EQ("dump_conf", 0)) { SET_BOOL_ARG_VAL(&g_conf.dump_conf); } else if (CMD_EQ("bind", 0)) { diff --git a/src/config.h b/src/config.h index ec5a50743ad5c..0bccd15a5acff 100644 --- a/src/config.h +++ b/src/config.h @@ -65,6 +65,7 @@ struct md_config_t { const char *pid_file; const char *conf_file; + const char *cluster_conf_file; bool dump_conf; bool chdir_root; @@ -354,7 +355,7 @@ void parse_startup_config_options(std::vector& args); void parse_config_options(std::vector& args); void parse_config_option_string(string& s); -extern bool parse_ip_port(const char *s, entity_addr_t& addr); +extern bool parse_ip_port(const char *s, entity_addr_t& addr, const char **end=0); class ConfFile; diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 97a5872dbbcc4..6571d0e9ba199 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -2,6 +2,7 @@ #include "msg/SimpleMessenger.h" #include "messages/MMonGetMap.h" #include "messages/MMonMap.h" +#include "common/ConfUtils.h" #include "MonClient.h" #include "MonMap.h" @@ -17,11 +18,25 @@ bufferlist monmap_bl; int MonClient::probe_mon(MonMap *pmonmap) { - entity_addr_t monaddr; - parse_ip_port(g_conf.mon_host, monaddr); + vector monaddrs; + + const char *p = g_conf.mon_host; + const char *end = p + strlen(p); + while (p < end) { + entity_addr_t a; + if (parse_ip_port(p, a, &p)) { + monaddrs.push_back(a); + } else { + break; + } + } + if (monaddrs.empty()) { + cerr << "couldn't parse ip:port(s) from '" << g_conf.mon_host << "'" << std::endl; + return -1; + } rank.bind(); - dout(1) << " connecting to monitor at " << monaddr << " ..." << dendl; + dout(1) << " connecting to monitor(s) at " << monaddrs << " ..." << dendl; Messenger *msgr = rank.register_entity(entity_name_t::CLIENT(-1)); msgr->set_dispatcher(this); @@ -29,11 +44,14 @@ int MonClient::probe_mon(MonMap *pmonmap) rank.start(true); // do not daemonize! int attempt = 10; + int i = 0; monmap_lock.Lock(); + srand(getpid()); while (monmap_bl.length() == 0) { - dout(10) << "querying " << monaddr << dendl; + i = rand() % monaddrs.size(); + dout(10) << "querying " << monaddrs[i] << dendl; entity_inst_t mi; - mi.addr = monaddr; + mi.addr = monaddrs[i]; mi.name = entity_name_t::MON(0); // FIXME HRM! msgr->send_message(new MMonGetMap, mi); @@ -47,8 +65,8 @@ int MonClient::probe_mon(MonMap *pmonmap) if (monmap_bl.length()) { pmonmap->decode(monmap_bl); - dout(2) << "get_monmap got monmap from " << monaddr << " fsid " << pmonmap->fsid << dendl; - cout << "[got monmap from " << monaddr << " fsid " << pmonmap->fsid << "]" << std::endl; + dout(2) << "get_monmap got monmap from " << monaddrs[i] << " fsid " << pmonmap->fsid << dendl; + cout << "[got monmap from " << monaddrs[i] << " fsid " << pmonmap->fsid << "]" << std::endl; } msgr->shutdown(); msgr->destroy(); @@ -57,28 +75,60 @@ int MonClient::probe_mon(MonMap *pmonmap) if (monmap_bl.length()) return 0; - cerr << "unable to fetch monmap from " << monaddr + cerr << "unable to fetch monmap from " << monaddrs << ": " << strerror(errno) << std::endl; return -1; // failed } int MonClient::get_monmap(MonMap *pmonmap) { + static string monstr; + + if (!g_conf.mon_host) { + // cluster conf? + ConfFile a(g_conf.cluster_conf_file); + ConfFile b("cluster.conf"); + ConfFile *c = 0; + + if (a.parse()) + c = &a; + else if (b.parse()) + c = &b; + if (c) { + for (int i=0; i<15; i++) { + char *val = 0; + char monname[10]; + sprintf(monname, "mon%d", i); + c->read(monname, "mon addr", &val, 0); + if (!val || !val[0]) + break; + + if (monstr.length()) + monstr += ","; + monstr += val; + } + g_conf.mon_host = monstr.c_str(); + } + } + // probe? if (g_conf.mon_host && probe_mon(pmonmap) == 0) return 0; - // file? - const char *monmap_fn = g_conf.monmap_file; - int r = pmonmap->read(monmap_fn); - if (r >= 0) { - cout << "[opened monmap at " << monmap_fn << " fsid " << pmonmap->fsid << "]" << std::endl; - return 0; + if (g_conf.monmap_file) { + // file? + const char *monmap_fn = g_conf.monmap_file; + int r = pmonmap->read(monmap_fn); + if (r >= 0) { + cout << "[opened monmap at " << monmap_fn << " fsid " << pmonmap->fsid << "]" << std::endl; + return 0; + } + + cerr << "unable to read monmap from " << monmap_fn << ": " << strerror(errno) << std::endl; } - cerr << "unable to read monmap from " << monmap_fn - << ": " << strerror(errno) << std::endl; + cerr << "must specify monitor address (-m monaddr) or cluster conf (-C cluster.conf) or monmap file (-M monmap)" << std::endl; return -1; } diff --git a/src/vstart.sh b/src/vstart.sh index 0df42bf184319..c3cd9badb821c 100755 --- a/src/vstart.sh +++ b/src/vstart.sh @@ -15,6 +15,7 @@ valgrind="" MON_ADDR="" conf="workingdir.conf" +clusterconf="cluster.conf" usage="usage: $0 [option]... [mon] [mds] [osd]\n" usage=$usage"options:\n" @@ -130,6 +131,7 @@ if [ $start_mon -eq 1 ]; then fi if [ $new -eq 1 ]; then + echo "; generated by vstart.sh on `date`" > $clusterconf if [ `echo $IP | grep '^127\\.'` ] then echo @@ -145,6 +147,8 @@ if [ $start_mon -eq 1 ]; then for f in `seq 0 $((CEPH_NUM_MON-1))` do str=$str" --add $IP:$(($CEPH_PORT+$f))" + echo "[mon$f]" >> $clusterconf + echo " mon addr = $IP:$(($CEPH_PORT+$f))" >> $clusterconf done str=$str" --print .ceph_monmap" echo $str