From b796b3026b271456731a607751bb651afc1451c4 Mon Sep 17 00:00:00 2001 From: sageweil Date: Thu, 15 Feb 2007 22:28:29 +0000 Subject: [PATCH] move ip parsing into config.o, generic --bind option for all build targets git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1098 29311d96-e01e-0410-9327-a35deaab8ce9 --- branches/sage/cephmds2/cmon.cc | 4 +- branches/sage/cephmds2/config.cc | 54 ++++++++++++++++++- branches/sage/cephmds2/config.h | 9 ++++ branches/sage/cephmds2/mkmonmap.cc | 47 +--------------- branches/sage/cephmds2/msg/SimpleMessenger.cc | 37 ++++++++----- branches/sage/cephmds2/msg/SimpleMessenger.h | 2 +- 6 files changed, 90 insertions(+), 63 deletions(-) diff --git a/branches/sage/cephmds2/cmon.cc b/branches/sage/cephmds2/cmon.cc index a49b1789865d5..442b584f02abd 100644 --- a/branches/sage/cephmds2/cmon.cc +++ b/branches/sage/cephmds2/cmon.cc @@ -105,9 +105,7 @@ int main(int argc, char **argv) // bind to a specific port cout << "starting mon" << whoami << " at " << monmap.get_inst(whoami) << endl; - tcpaddr_t addr; - monmap.get_inst(whoami).addr.make_addr(addr); - rank.set_listen_addr(addr); + g_my_addr = monmap.get_inst(whoami).addr; rank.start_rank(); } diff --git a/branches/sage/cephmds2/config.cc b/branches/sage/cephmds2/config.cc index caaa35f5aaa5c..44f886630588b 100644 --- a/branches/sage/cephmds2/config.cc +++ b/branches/sage/cephmds2/config.cc @@ -51,6 +51,8 @@ FileLayout g_OSD_MDLogLayout( 1<<20, 1, 1<<20, 2 ); // 1M objects std::map g_fake_osd_down; std::map g_fake_osd_out; +entity_addr_t g_my_addr; + md_config_t g_debug_after_conf; md_config_t g_conf = { @@ -347,12 +349,62 @@ void vec_to_argv(std::vector& args, argv[argc++] = args[i]; } +bool parse_ip_port(const char *s, entity_addr_t& a) +{ + int count = 0; // digit count + int off = 0; + + while (1) { + // parse the #. + int val = 0; + int numdigits = 0; + + while (*s >= '0' && *s <= '9') { + int digit = *s - '0'; + //cout << "digit " << digit << endl; + val *= 10; + val += digit; + numdigits++; + s++; off++; + } + //cout << "val " << val << endl; + + if (numdigits == 0) { + cerr << "no digits at off " << off << endl; + return false; // no digits + } + if (count < 3 && *s != '.') { + cerr << "should period at " << off << endl; + return false; // should have 3 periods + } + if (count == 3 && *s != ':') { + cerr << "expected : at " << off << endl; + return false; // then a colon + } + s++; off++; + + if (count <= 3) + a.ipq[count] = val; + else + a.port = val; + + count++; + if (count == 5) break; + } + + return true; +} + + + void parse_config_options(std::vector& args) { std::vector nargs; for (unsigned i=0; i g_fake_osd_out; #define OSD_REP_SPLAY 1 #define OSD_REP_CHAIN 2 + +#include "msg/msg_types.h" + +extern entity_addr_t g_my_addr; + struct md_config_t { int num_mon; int num_mds; @@ -300,4 +305,8 @@ void vec_to_argv(std::vector& args, void parse_config_options(std::vector& args); +extern bool parse_ip_port(const char *s, entity_addr_t& addr); + + + #endif diff --git a/branches/sage/cephmds2/mkmonmap.cc b/branches/sage/cephmds2/mkmonmap.cc index e11057c7ac720..1ec4c808d6204 100644 --- a/branches/sage/cephmds2/mkmonmap.cc +++ b/branches/sage/cephmds2/mkmonmap.cc @@ -25,48 +25,7 @@ using namespace std; #include "mon/MonMap.h" -bool parse_ip_port(const char *s, tcpaddr_t& tcpaddr) -{ - unsigned char addr[4]; - int port = 0; - - int count = 0; // digit count - - while (1) { - // parse the #. - int val = 0; - int numdigits = 0; - - while (*s >= '0' && *s <= '9') { - int digit = *s - '0'; - //cout << "digit " << digit << endl; - val *= 10; - val += digit; - numdigits++; - s++; - } - //cout << "val " << val << endl; - - if (numdigits == 0) return false; // no digits - if (count < 3 && *s != '.') return false; // should have 3 periods - if (count == 3 && *s != ':') return false; // then a colon - s++; - - if (count <= 3) - addr[count] = val; - else - port = val; - - count++; - if (count == 5) break; - } - - // copy into inst - memcpy((char*)&tcpaddr.sin_addr.s_addr, (char*)addr, 4); - tcpaddr.sin_port = port; - return true; -} int main(int argc, char **argv) @@ -83,13 +42,11 @@ int main(int argc, char **argv) outfn = args[++i]; else { // parse ip:port - tcpaddr_t addr; - if (!parse_ip_port(args[i], addr)) { + entity_inst_t inst; + if (!parse_ip_port(args[i], inst.addr)) { cerr << "mkmonmap: invalid ip:port '" << args[i] << "'" << endl; return -1; } - entity_inst_t inst; - inst.addr.set_addr(addr); inst.name = MSG_ADDR_MON(monmap.num_mon); cout << "mkmonmap: adding " << inst << endl; monmap.add_mon(inst); diff --git a/branches/sage/cephmds2/msg/SimpleMessenger.cc b/branches/sage/cephmds2/msg/SimpleMessenger.cc index 04bc38fa3dcdb..f5d0195ae3e6d 100644 --- a/branches/sage/cephmds2/msg/SimpleMessenger.cc +++ b/branches/sage/cephmds2/msg/SimpleMessenger.cc @@ -49,6 +49,9 @@ int Rank::Accepter::start() // bind to a socket dout(10) << "accepter.start binding to listen " << endl; + // use whatever user specified.. + g_my_addr.make_addr(rank.listen_addr); + /* socket creation */ listen_sd = socket(AF_INET,SOCK_STREAM,0); assert(listen_sd > 0); @@ -77,20 +80,27 @@ int Rank::Accepter::start() struct hostent *myhostname = gethostbyname( host ); - // fill in rank.listen_addr - memset(&rank.listen_addr, 0, sizeof(rank.listen_addr)); - - rank.listen_addr.sin_family = myhostname->h_addrtype; - memcpy((char *) &rank.listen_addr.sin_addr.s_addr, - myhostname->h_addr_list[0], - myhostname->h_length); - rank.listen_addr.sin_port = myport; + // figure out my_addr + if (g_my_addr.port > 0) { + // user specified it, easy. + rank.my_addr = g_my_addr; + } else { + // try to figure out what ip i can be reached out + memset(&rank.listen_addr, 0, sizeof(rank.listen_addr)); + + // look up my hostname. blech! this sucks. + rank.listen_addr.sin_family = myhostname->h_addrtype; + memcpy((char *) &rank.listen_addr.sin_addr.s_addr, + myhostname->h_addr_list[0], + myhostname->h_length); + rank.listen_addr.sin_port = myport; + rank.my_addr.set_addr(rank.listen_addr); + } - // fill in rank.my_addr - rank.my_addr.set_addr(rank.listen_addr); - rank.my_addr.nonce = getpid(); + // set a nonce + rank.my_addr.nonce = getpid(); // FIXME: pid might not be best choice here. - dout(10) << "accepter.start listening at " << rank.my_addr << endl; + dout(10) << "accepter.start my addr is " << rank.my_addr << endl; // start thread create(); @@ -667,13 +677,14 @@ Rank::~Rank() { } +/* void Rank::set_listen_addr(tcpaddr_t& a) { dout(10) << "set_listen_addr " << a << endl; memcpy((char*)&listen_addr.sin_addr.s_addr, (char*)&a.sin_addr.s_addr, 4); listen_addr.sin_port = a.sin_port; } - +*/ void Rank::_submit_single_dispatch(Message *m) { diff --git a/branches/sage/cephmds2/msg/SimpleMessenger.h b/branches/sage/cephmds2/msg/SimpleMessenger.h index 968d66a11fcf9..9e2ba28131e8f 100644 --- a/branches/sage/cephmds2/msg/SimpleMessenger.h +++ b/branches/sage/cephmds2/msg/SimpleMessenger.h @@ -265,7 +265,7 @@ public: Rank(); ~Rank(); - void set_listen_addr(tcpaddr_t& a); + //void set_listen_addr(tcpaddr_t& a); int start_rank(); void wait(); -- 2.39.5