From bf886e1766d053f449ead13ebdc33660b404b8a7 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 11 May 2008 16:54:53 -0700 Subject: [PATCH] auto-detect ip for all non-monitor components from initial exchange with monitor --- src/TODO | 2 -- src/mon/MDSMonitor.cc | 6 ++++ src/mon/Monitor.cc | 6 ++++ src/mon/OSDMonitor.cc | 6 ++++ src/msg/SimpleMessenger.cc | 63 +++++++------------------------------- src/msg/SimpleMessenger.h | 3 +- src/start.sh | 4 +-- src/vstart.sh | 6 ++-- 8 files changed, 36 insertions(+), 60 deletions(-) diff --git a/src/TODO b/src/TODO index a9d665543a877..6f14518c99324 100644 --- a/src/TODO +++ b/src/TODO @@ -9,7 +9,6 @@ big items - cas - meta vs data crush rules -- ip-less startup for userspace items - use libuuid userspace client @@ -26,7 +25,6 @@ userspace client kernel client - direct mds requests intelligently -- readdir on large directories - flush caps on sync, fsync, etc. - do we need to block? - timeout mds session close on umount diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index fb189fac25f93..e67c5eb97b9db 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -218,6 +218,12 @@ bool MDSMonitor::preprocess_beacon(MMDSBeacon *m) goto out; } + // first time we've seen it? + if (m->get_mds_inst().addr.ipaddr.sin_addr.s_addr == htonl(INADDR_ANY)) { + m->get_mds_inst() = m->get_source_inst(); + m->clear_payload(); + } + dout(12) << "preprocess_beacon " << *m << " from " << m->get_mds_inst() << dendl; diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 1a36ddef67172..3a15a5311afdd 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -199,6 +199,12 @@ void Monitor::handle_command(MMonCommand *m) return; } + // first time we've seen it? + if (m->inst.addr.ipaddr.sin_addr.s_addr == htonl(INADDR_ANY)) { + m->inst = m->get_source_inst(); + m->clear_payload(); + } + dout(0) << "handle_command " << *m << dendl; string rs; if (!m->cmd.empty()) { diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index f96a5785893a7..df552ef08227e 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -467,6 +467,12 @@ bool OSDMonitor::preprocess_boot(MOSDBoot *m) return true; } + // first time we've seen it? + if (m->inst.addr.ipaddr.sin_addr.s_addr == htonl(INADDR_ANY)) { + m->inst = m->get_source_inst(); + m->clear_payload(); + } + assert(m->inst.name.is_osd()); int from = m->inst.name.num(); diff --git a/src/msg/SimpleMessenger.cc b/src/msg/SimpleMessenger.cc index 65b5cf080ae4d..72ea9c2562eb0 100644 --- a/src/msg/SimpleMessenger.cc +++ b/src/msg/SimpleMessenger.cc @@ -92,36 +92,6 @@ int Rank::Accepter::bind(int64_t force_nonce) // bind to a socket dout(10) << "accepter.bind" << dendl; - char hostname[100]; - memset(hostname, 0, 100); - gethostname(hostname, 100); - dout(2) << "accepter.bind my hostname is " << hostname << dendl; - - // is there a .ceph_hosts file? - if (g_conf.ms_hosts) { - ifstream fh; - fh.open(g_conf.ms_hosts); - if (fh.is_open()) { - while (1) { - string line; - getline(fh, line); - if (fh.eof()) break; - if (line[0] == '#' || line[0] == ';') continue; - int ospace = line.find(" "); - if (!ospace) continue; - string host = line.substr(0, ospace); - string addr = line.substr(ospace+1); - dout(15) << g_conf.ms_hosts << ": host '" << host << "' -> '" << addr << "'" << dendl; - if (host == hostname) { - parse_ip_port(addr.c_str(), g_my_addr); - dout(1) << g_conf.ms_hosts << ": my addr is " << g_my_addr << dendl; - break; - } - } - fh.close(); - } - } - // use whatever user specified (if anything) sockaddr_in listen_addr = g_my_addr.ipaddr; @@ -158,28 +128,9 @@ int Rank::Accepter::bind(int64_t force_nonce) return -errno; } - // figure out my_addr - if (g_my_addr != entity_addr_t()) { - // user specified it, easy peasy. - rank.rank_addr = g_my_addr; - } else { - // my IP is... HELP! - struct hostent *myhostname = gethostbyname(hostname); - if (!myhostname) { - derr(0) << "accepter.bind unable to resolve hostname '" << hostname - << "', please specify your ip with --bind x.x.x.x" - << dendl; - return -1; - } - - // look up my hostname. - listen_addr.sin_family = myhostname->h_addrtype; - memcpy((char*)&listen_addr.sin_addr.s_addr, - myhostname->h_addr_list[0], - myhostname->h_length); - rank.rank_addr.ipaddr = listen_addr; - rank.rank_addr.set_port(0); - } + rank.rank_addr = g_my_addr; + if (rank.rank_addr != entity_addr_t()) + rank.need_addr = false; if (rank.rank_addr.get_port() == 0) { entity_addr_t tmp; tmp.ipaddr = listen_addr; @@ -1405,6 +1356,14 @@ void Rank::Pipe::reader() if (erank < rank.max_local && rank.local[erank]) { // find entity entity = rank.local[erank]; + + // first message? + if (rank.need_addr) { + entity->_myinst.addr = rank.rank_addr = m->get_dest_inst().addr; + dout(0) << "reader my rank addr is " << rank.rank_addr << dendl; + rank.need_addr = false; + } + } else { derr(0) << "reader got message " << *m << " for " << m->get_dest() << ", which isn't local" << dendl; } diff --git a/src/msg/SimpleMessenger.h b/src/msg/SimpleMessenger.h index f3afb8da11f4b..a5b9e5f30622f 100644 --- a/src/msg/SimpleMessenger.h +++ b/src/msg/SimpleMessenger.h @@ -320,6 +320,7 @@ private: bool started; // where i listen + bool need_addr; entity_addr_t rank_addr; // local @@ -344,7 +345,7 @@ private: void reaper(); public: - Rank() : started(false), + Rank() : started(false), need_addr(true), max_local(0), num_local(0) { } ~Rank() { } diff --git a/src/start.sh b/src/start.sh index 1709d8456dfd4..fbffd92babf00 100755 --- a/src/start.sh +++ b/src/start.sh @@ -27,7 +27,7 @@ $CEPH_BIN/monmaptool --create --clobber --add $IP:12345 --print .ceph_monmap $CEPH_BIN/mkmonfs --clobber mondata/mon0 --mon 0 --monmap .ceph_monmap # shared args -ARGS="-d --bind $IP" +ARGS="-d" # start monitor $CEPH_BIN/cmon $ARGS mondata/mon0 --debug_mon 10 --debug_ms 1 @@ -44,7 +44,7 @@ do done # mds -$CEPH_BIN/cmds $ARGS # --debug_ms 1 #--debug_mds 20 --debug_ms 20 +$CEPH_BIN/cmds $ARGS # --debug_ms 1 #--debug_mds 20 --debug_ms 20 echo "started. stop.sh to stop. see out/* (e.g. 'tail -f out/????') for debug output." diff --git a/src/vstart.sh b/src/vstart.sh index 865fc9c26d554..0abc0595d10ae 100755 --- a/src/vstart.sh +++ b/src/vstart.sh @@ -8,7 +8,7 @@ rm out/* # figure machine's ip HOSTNAME=`hostname` -IP=`host $HOSTNAME | cut -d ' ' -f 4` +IP=`host $HOSTNAME | grep $HOSTNAME | cut -d ' ' -f 4` [ "$CEPH_BIN" == "" ] && CEPH_BIN=. echo hostname $HOSTNAME @@ -27,7 +27,7 @@ $CEPH_BIN/monmaptool --create --clobber --add $IP:12345 --print .ceph_monmap $CEPH_BIN/mkmonfs --clobber mondata/mon0 --mon 0 --monmap .ceph_monmap # shared args -ARGS="-d --bind $IP" +ARGS="-d" # start monitor $CEPH_BIN/cmon $ARGS mondata/mon0 --debug_mon 10 --debug_ms 1 @@ -43,7 +43,7 @@ do done # mds -$CEPH_BIN/cmds $ARGS --debug_ms 1 --debug_mds 20 #--debug_ms 20 +$CEPH_BIN/cmds $ARGS --debug_ms 1 --debug_mds 20 --mds_thrash_fragments 1 #--debug_ms 20 echo "started. stop.sh to stop. see out/* (e.g. 'tail -f out/????') for debug output." -- 2.39.5